summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-14 11:26:07 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-14 12:36:06 -0700
commit609715ab698489588b32aa69d98fa2c5b233ef8f (patch)
treed9bfef1748deea912ce894e22c53f7920a62afec /qt-ui
parentec33a95ad04099d428275de2c6b36e7098cc943e (diff)
downloadsubsurface-609715ab698489588b32aa69d98fa2c5b233ef8f.tar.gz
Convert other users of showError() to the new world order
The "report_error()" interface is a lot simpler, although some of the C++ code uses QStrings which make them a bit annoying, especially for the varargs model. Still, even with the explicit conversion to UTF8 and "char *", the report_error() model is much nicer. This also just makes refreshDisplay() do the error reporting in the UI automatically, so a number of error paths don't even have to worry. And the multi-line model of error reporting means that it all automatically does the right thing, and reports errors for each file rather than just for the last file that failed to open. So this removes closer to a hundred lines of cruft, while being a simpler interface and doing better error reporting. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divelogimportdialog.cpp18
-rw-r--r--qt-ui/diveplanner.cpp6
-rw-r--r--qt-ui/mainwindow.cpp26
-rw-r--r--qt-ui/subsurfacewebservices.cpp28
-rw-r--r--qt-ui/subsurfacewebservices.h2
5 files changed, 25 insertions, 55 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index bff49156f..3de08b003 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -54,8 +54,6 @@ DiveLogImportDialog::~DiveLogImportDialog()
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1 : -1)
void DiveLogImportDialog::on_buttonBox_accepted()
{
- char *error = NULL;
-
if (ui->tabWidget->currentIndex() == 0) {
for (int i = 0; i < fileNames.size(); ++i) {
parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
@@ -65,13 +63,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
VALUE_IF_CHECKED(CSVstopdepth),
ui->CSVSeparator->currentIndex(),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
- ui->CSVUnits->currentIndex(),
- &error);
- if (error != NULL) {
- MainWindow::instance()->showError(error);
- free(error);
- error = NULL;
- }
+ ui->CSVUnits->currentIndex());
}
} else {
for (int i = 0; i < fileNames.size(); ++i) {
@@ -84,13 +76,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth),
VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy),
VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight),
- VALUE_IF_CHECKED(Tags),
- &error);
- if (error != NULL) {
- MainWindow::instance()->showError(error);
- free(error);
- error = NULL;
- }
+ VALUE_IF_CHECKED(Tags));
}
}
process_dives(true, false);
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index c5715f9df..27eedb586 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1414,7 +1414,6 @@ void DivePlannerPointsModel::createTemporaryPlan()
}
char *cache = NULL;
tempDive = NULL;
- const char *errorString = NULL;
struct divedatapoint *dp = NULL;
for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &stagingDive->cylinder[i];
@@ -1432,7 +1431,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
#if DEBUG_PLAN
dump_plan(&diveplan);
#endif
- plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
+ plan(&diveplan, &cache, &tempDive, isPlanner());
if (mode == ADD) {
// copy the samples and events, but don't overwrite the cylinders
copy_samples(tempDive, current_dive);
@@ -1468,10 +1467,9 @@ void DivePlannerPointsModel::createPlan()
// to not delete it later. mumble. ;p
char *cache = NULL;
tempDive = NULL;
- const char *errorString = NULL;
createTemporaryPlan();
- plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
+ plan(&diveplan, &cache, &tempDive, isPlanner());
copy_cylinders(stagingDive, tempDive);
int mean[MAX_CYLINDERS], duration[MAX_CYLINDERS];
per_cylinder_mean_depth(tempDive, select_dc(&tempDive->dc), mean, duration);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 44b02b125..069d2f2f8 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -105,6 +105,7 @@ MainWindow *MainWindow::instance()
// this gets called after we download dives from a divecomputer
void MainWindow::refreshDisplay(bool recreateDiveList)
{
+ showError(get_error_string());
ui.InfoWidget->reload();
TankInfoModel::instance()->update();
ui.globe->reload();
@@ -973,15 +974,10 @@ void MainWindow::importFiles(const QStringList fileNames)
return;
QByteArray fileNamePtr;
- char *error = NULL;
+
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
- parse_file(fileNamePtr.data(), &error);
- if (error != NULL) {
- showError(error);
- free(error);
- error = NULL;
- }
+ parse_file(fileNamePtr.data());
}
process_dives(true, false);
refreshDisplay();
@@ -992,21 +988,19 @@ void MainWindow::loadFiles(const QStringList fileNames)
if (fileNames.isEmpty())
return;
- char *error = NULL;
QByteArray fileNamePtr;
QStringList failedParses;
for (int i = 0; i < fileNames.size(); ++i) {
- fileNamePtr = QFile::encodeName(fileNames.at(i));
- parse_file(fileNamePtr.data(), &error);
- set_filename(fileNamePtr.data(), true);
- setTitle(MWTF_FILENAME);
+ int error;
- if (error != NULL) {
+ fileNamePtr = QFile::encodeName(fileNames.at(i));
+ error = parse_file(fileNamePtr.data());
+ if (!error) {
+ set_filename(fileNamePtr.data(), true);
+ setTitle(MWTF_FILENAME);
+ } else {
failedParses.append(fileNames.at(i));
- showError(error);
- free(error);
- error = NULL;
}
}
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 93b452475..707746573 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -103,11 +103,11 @@ static void clear_table(struct dive_table *table)
table->nr = 0;
}
-bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected, QString *errorMsg)
+bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
{
static const char errPrefix[] = "divelog.de-upload:";
if (!amount_selected) {
- *errorMsg = tr("no dives were selected");
+ report_error(tr("no dives were selected").toUtf8());
return false;
}
@@ -126,8 +126,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
if (!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));
+ report_error(tr("failed to create zip file for upload: %s").toUtf8(), buffer);
return false;
}
@@ -151,7 +150,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
continue;
f = tmpfile();
if (!f) {
- *errorMsg = tr("cannot create temporary file: %1").arg(qt_error_string());
+ report_error(tr("cannot create temporary file: %s").toUtf8(), qt_error_string().toUtf8().data());
goto error_close_zip;
}
save_dive(f, dive);
@@ -161,7 +160,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
membuf = (char *)malloc(streamsize + 1);
if (!membuf || (streamsize = fread(membuf, streamsize, 1, f)) == 0) {
- *errorMsg = tr("internal error: %1").arg(qt_error_string());
+ report_error(tr("internal error: %s").toUtf8(), qt_error_string().toUtf8().data());
fclose(f);
free((void *)membuf);
goto error_close_zip;
@@ -177,7 +176,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0);
if (!doc) {
qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
- *errorMsg = tr("internal error");
+ report_error(tr("internal error").toUtf8());
free((void *)membuf);
goto error_close_zip;
}
@@ -328,7 +327,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
case QDialogButtonBox::ApplyRole: {
clear_table(&gps_location_table);
QByteArray url = tr("Webservice").toLocal8Bit();
- parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL, NULL);
+ parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL);
/* now merge the data in the gps_location table into the dive_table */
if (merge_locations_into_dives()) {
@@ -580,11 +579,9 @@ void DivelogsDeWebServices::downloadDives()
void DivelogsDeWebServices::prepareDivesForUpload()
{
- 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, &errorText)) {
+ if (prepare_dives_for_divelogs(filename, true)) {
QFile f(filename);
if (f.open(QIODevice::ReadOnly)) {
uploadDives((QIODevice *)&f);
@@ -593,7 +590,7 @@ void DivelogsDeWebServices::prepareDivesForUpload()
return;
}
}
- MainWindow::instance()->showError(errorText);
+ MainWindow::instance()->showError(get_error_string());
}
void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
@@ -861,12 +858,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
break;
}
/* parse file and import dives */
- char *error = NULL;
- parse_file(QFile::encodeName(zipFile.fileName()), &error);
- if (error != NULL) {
- MainWindow::instance()->showError(error);
- free(error);
- }
+ parse_file(QFile::encodeName(zipFile.fileName()));
process_dives(true, false);
MainWindow::instance()->refreshDisplay();
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 872cf377d..175c99109 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -89,7 +89,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, QString *errorMsg);
+ bool prepare_dives_for_divelogs(const QString &filename, bool selected);
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
unsigned int download_dialog_parse_response(const QByteArray &length);