summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-12-19 17:03:23 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-12-20 09:53:05 -0800
commitde47937dd1b5d84ce84c668dc3508651f86ec5bb (patch)
treeb5e95d03107162b9d4a306a7c600a6d799c48a1b
parentd36e4555da1fcf46d2ecfbaae8db1b0fe1915b10 (diff)
downloadsubsurface-de47937dd1b5d84ce84c668dc3508651f86ec5bb.tar.gz
Get more descriptive error messages when uploading to divelogs.de
Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/subsurfacewebservices.cpp27
-rw-r--r--qt-ui/subsurfacewebservices.h2
2 files changed, 16 insertions, 13 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 6e58d3ad1..bcc5ae3f9 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -98,11 +98,11 @@ static void clear_table(struct dive_table *table)
table->nr = 0;
}
-bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
+bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected, QString *errorMsg)
{
static const char errPrefix[] = "divelog.de-upload:";
if (!amount_selected) {
- qDebug() << errPrefix << "no dives selected";
+ *errorMsg = tr("no dives were selected");
return false;
}
@@ -123,10 +123,14 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
return false;
}
- zip = zip_open(QFile::encodeName(tempfile), ZIP_CREATE, NULL);
+ int error_code;
+ zip = zip_open(QFile::encodeName(tempfile), ZIP_CREATE, &error_code);
if (!zip) {
- qDebug() << errPrefix << "cannot open file as zip";
+ char buffer[1024];
+ zip_error_to_str(buffer, sizeof buffer, error_code, errno);
+ *errorMsg = tr("failed to create zip file for upload: %1")
+ .arg(QString::fromLocal8Bit(buffer));
return false;
}
@@ -139,7 +143,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
continue;
f = tmpfile();
if (!f) {
- qDebug() << errPrefix << "cannot create temp file";
+ *errorMsg = tr("cannot create temporary file: %1").arg(qt_error_string());
goto error_close_zip;
}
save_dive(f, dive);
@@ -148,7 +152,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
rewind(f);
membuf = (char *)malloc(streamsize + 1);
if (!membuf || !fread(membuf, streamsize, 1, f)) {
- qDebug() << errPrefix << "memory error";
+ *errorMsg = tr("internal error: %1").arg(qt_error_string());
fclose(f);
free((void *)membuf);
goto error_close_zip;
@@ -162,7 +166,8 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
*/
xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0);
if (!doc) {
- qDebug() << errPrefix << "xml error";
+ qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
+ *errorMsg = tr("internal error");
free((void *)membuf);
goto error_close_zip;
}
@@ -549,11 +554,11 @@ void DivelogsDeWebServices::downloadDives()
void DivelogsDeWebServices::prepareDivesForUpload()
{
- QString errorText(tr("Cannot create DLD file"));
+ QString errorText;
/* generate a random filename and create/open that file with zip_open */
QString filename = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld";
- if (prepare_dives_for_divelogs(filename, true)) {
+ if (prepare_dives_for_divelogs(filename, true, &errorText)) {
QFile f(filename);
if (f.open(QIODevice::ReadOnly)) {
uploadDives((QIODevice *)&f);
@@ -561,10 +566,8 @@ void DivelogsDeWebServices::prepareDivesForUpload()
f.remove();
return;
}
- mainWindow()->showError(errorText.append(": ").append(filename));
- return;
}
- mainWindow()->showError(errorText.append("!"));
+ mainWindow()->showError(errorText);
}
void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 46cab7120..a8478d99b 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -83,7 +83,7 @@ private:
void uploadDives(QIODevice *dldContent);
explicit DivelogsDeWebServices (QWidget* parent = 0, Qt::WindowFlags f = 0);
void setStatusText(int status);
- bool prepare_dives_for_divelogs(const QString &filename, bool selected);
+ bool prepare_dives_for_divelogs(const QString &filename, bool selected, QString *errorMsg);
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
unsigned int download_dialog_parse_response(const QByteArray& length);