diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2017-10-26 16:24:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-26 16:24:51 +0200 |
commit | a08e8a2d04821b4dcdfabe9f8e2d05a5cdac0d8d (patch) | |
tree | 463e846d897487bcaa628c7a8c03b601d4b263cd /desktop-widgets | |
parent | 2c67b387ea5571675db68c46b7879b4746571fd9 (diff) | |
parent | 405923ecfdca7993a3f6433eba4f0de0d03161f5 (diff) | |
download | subsurface-a08e8a2d04821b4dcdfabe9f8e2d05a5cdac0d8d.tar.gz |
Merge pull request #726 from Subsurface-divelog/rewriteErrorHandling
Rewrite error handling
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 50 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.h | 1 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 1 |
4 files changed, 18 insertions, 36 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 5e6bfd5f0..c12ac8934 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -983,7 +983,7 @@ void DiveListView::loadImageFromURL(QUrl url) if (image.isNull()) { // If this is not an image, maybe it's an html file and Miika can provide some xslr magic to extract images. // In this case we would call the function recursively on the list of image source urls; - MainWindow::instance()->getNotificationWidget()->showNotification(tr("%1 does not appear to be an image").arg(url.toString()), KMessageWidget::Error); + report_error(qPrintable(tr("%1 does not appear to be an image").arg(url.toString()))); return; } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index accf0b267..1afe8b262 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -86,6 +86,15 @@ extern "C" int updateProgress(const char *text) MainWindow *MainWindow::m_Instance = NULL; +extern "C" void showErrorFromC() +{ + MainWindow *mainwindow = MainWindow::instance(); + if (mainwindow) { + mainwindow->getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); + } +} + + MainWindow::MainWindow() : QMainWindow(), actionNextDive(0), actionPreviousDive(0), @@ -244,6 +253,7 @@ MainWindow::MainWindow() : QMainWindow(), setupSocialNetworkMenu(); set_git_update_cb(&updateProgress); + set_error_cb(&showErrorFromC); // Toolbar Connections related to the Profile Update SettingsObjectWrapper *sWrapper = SettingsObjectWrapper::instance(); @@ -287,7 +297,6 @@ MainWindow::MainWindow() : QMainWindow(), // now let's set up some connections connect(graphics(), &ProfileWidget2::enableToolbar ,this, &MainWindow::setEnabledToolbar); - connect(graphics(), &ProfileWidget2::showError, this, &MainWindow::showError); connect(graphics(), &ProfileWidget2::disableShortcuts, this, &MainWindow::disableShortcuts); connect(graphics(), &ProfileWidget2::enableShortcuts, this, &MainWindow::enableShortcuts); connect(graphics(), &ProfileWidget2::refreshDisplay, this, &MainWindow::refreshDisplay); @@ -429,7 +438,6 @@ MainWindow *MainWindow::instance() // this gets called after we download dives from a divecomputer void MainWindow::refreshDisplay(bool doRecreateDiveList) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); information()->reload(); TankInfoModel::instance()->update(); MapWidget::instance()->reload(); @@ -562,10 +570,9 @@ void MainWindow::on_actionCloudstorageopen_triggered() return; QString filename; - if (getCloudURL(filename)) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); + if (getCloudURL(filename)) return; - } + if (verbose) qDebug() << "Opening cloud storage from:" << filename; @@ -591,13 +598,12 @@ void MainWindow::on_actionCloudstoragesave_triggered() { QString filename; if (!dive_table.nr) { - getNotificationWidget()->showNotification(tr("Don't save an empty log to the cloud"), KMessageWidget::Error); + report_error(qPrintable(tr("Don't save an empty log to the cloud"))); return; } - if (getCloudURL(filename)) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); + if (getCloudURL(filename)) return; - } + if (verbose) qDebug() << "Saving cloud storage to:" << filename; if (information()->isEditing()) @@ -605,14 +611,11 @@ void MainWindow::on_actionCloudstoragesave_triggered() showProgressBar(); - if (save_dives(filename.toUtf8().data())) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); + if (save_dives(filename.toUtf8().data())) return; - } hideProgressBar(); - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); set_filename(filename.toUtf8().data(), true); setTitle(MWTF_FILENAME); mark_divelist_changed(false); @@ -1646,12 +1649,9 @@ int MainWindow::file_save_as(void) if (information()->isEditing()) information()->acceptChanges(); - if (save_dives(filename.toUtf8().data())) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); + if (save_dives(filename.toUtf8().data())) return -1; - } - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); set_filename(filename.toUtf8().data(), true); setTitle(MWTF_FILENAME); mark_divelist_changed(false); @@ -1683,14 +1683,12 @@ int MainWindow::file_save(void) if (is_cloud) showProgressBar(); if (save_dives(existing_filename)) { - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); if (is_cloud) hideProgressBar(); return -1; } if (is_cloud) hideProgressBar(); - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); mark_divelist_changed(false); addRecentFile(QStringList() << QString(existing_filename)); return 0; @@ -1701,11 +1699,6 @@ NotificationWidget *MainWindow::getNotificationWidget() return ui.mainErrorMessage; } -void MainWindow::showError() -{ - getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); -} - QString MainWindow::displayedFilename(QString fullFilename) { QFile f(fullFilename); @@ -1795,7 +1788,6 @@ void MainWindow::importTxtFiles(const QStringList fileNames) void MainWindow::loadFiles(const QStringList fileNames) { - bool showWarning = false; if (fileNames.isEmpty()) { refreshDisplay(); return; @@ -1812,19 +1804,11 @@ void MainWindow::loadFiles(const QStringList fileNames) if (!error) { set_filename(fileNamePtr.data(), true); setTitle(MWTF_FILENAME); - // if there were any messages, show them - QString warning = get_error_string(); - if (!warning.isEmpty()) { - showWarning = true; - getNotificationWidget()->showNotification(warning , KMessageWidget::Information); - } } else { failedParses.append(fileNames.at(i)); } } hideProgressBar(); - if (!showWarning) - getNotificationWidget()->hideNotification(); process_dives(false, false); addRecentFile(fileNames); removeRecentFile(failedParses); diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index 161a5b606..073d3cad8 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -87,7 +87,6 @@ public: QUndoStack *undoStack; NotificationWidget *getNotificationWidget(); void enableDisableCloudActions(); - void showError(); private slots: diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 6c982d27f..86554cd8c 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -735,7 +735,6 @@ void DivelogsDeWebServices::prepareDivesForUpload(bool selected) } else { report_error("Failed to create upload file %s\n", qPrintable(filename)); } - MainWindow::instance()->getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); } void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) |