Exporting big xslt files may need some time, so showing notifications with
the exporting condition is important.

I used the main error message bar for showing exporting updates (which can
be a little bit confusing as updates are not errors) so I added the
notification object to the main window which handles the errors and updates.

Dirk, Please review the code and tell me what do you think.

I attached the patches.

-- 
regards,
Gehad
From 15b3bb2972654a3cfe495552951de46fc1c05992 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Fri, 27 Feb 2015 03:07:25 +0200
Subject: [PATCH 3/3] Show translated String.

Translated notifications are always better.

Signed-off-by: Gehad elrobey <[email protected]>
---
 qt-ui/divelogexportdialog.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp
index ff83170..2237fb9 100644
--- a/qt-ui/divelogexportdialog.cpp
+++ b/qt-ui/divelogexportdialog.cpp
@@ -315,7 +315,7 @@ void DiveLogExportDialog::on_buttonBox_accepted()
 		// the non XSLT exports are called directly above, the XSLT based ons are called here
 		if (!stylesheet.isEmpty()) {
 			future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), ui->exportSelected->isChecked(), ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8());
-			MainWindow::instance()->getNotificationWidget()->showNotification("Exporting...", KMessageWidget::Information);
+			MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please Wait, Exporting..."), KMessageWidget::Information);
 			MainWindow::instance()->getNotificationWidget()->setFuture(future);
 		}
 	}
-- 
2.1.0

From 32a4b3a7b363564c8fed950ff6f191f2e7678032 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Fri, 27 Feb 2015 02:57:56 +0200
Subject: [PATCH 2/3] Change the references to ShowError to the new
 notification object.

Showing an Error message is better called from the Notification Object,
So for consistency old references to showError is replaced by calling
the notification object.

Signed-off-by: Gehad elrobey <[email protected]>
---
 qt-ui/mainwindow.cpp             | 15 +++++----------
 qt-ui/mainwindow.h               |  1 -
 qt-ui/profile/profilewidget2.cpp |  2 +-
 qt-ui/subsurfacewebservices.cpp  |  2 +-
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 535e4e2..3938cb0 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -242,7 +242,7 @@ MainWindow *MainWindow::instance()
 // this gets called after we download dives from a divecomputer
 void MainWindow::refreshDisplay(bool doRecreateDiveList)
 {
-	showError(get_error_string());
+	getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 	information()->reload();
 	TankInfoModel::instance()->update();
 	globe()->reload();
@@ -1244,11 +1244,11 @@ int MainWindow::file_save_as(void)
 		information()->acceptChanges();
 
 	if (save_dives(filename.toUtf8().data())) {
-		showError(get_error_string());
+		getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 		return -1;
 	}
 
-	showError(get_error_string());
+	getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 	set_filename(filename.toUtf8().data(), true);
 	setTitle(MWTF_FILENAME);
 	mark_divelist_changed(false);
@@ -1275,20 +1275,15 @@ int MainWindow::file_save(void)
 			current_def_dir.mkpath(current_def_dir.absolutePath());
 	}
 	if (save_dives(existing_filename)) {
-		showError(get_error_string());
+		getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 		return -1;
 	}
-	showError(get_error_string());
+	getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 	mark_divelist_changed(false);
 	addRecentFile(QStringList() << QString(existing_filename));
 	return 0;
 }
 
-void MainWindow::showError(QString message)
-{
-	ui.mainErrorMessage->showNotification(message, KMessageWidget::Error);
-}
-
 NotificationWidget *MainWindow::getNotificationWidget()
 {
 	return ui.mainErrorMessage;
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 2bf836b..6928e45 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -71,7 +71,6 @@ public:
 	DivePlannerWidget *divePlannerWidget();
 	PlannerSettingsWidget *divePlannerSettingsWidget();
 	LocationInformationWidget *locationInformationWidget();
-	void showError(QString message);
 	void setTitle(enum MainWindowTitleFormat format);
 
 	// Some shortcuts like "change DC" or "copy/paste dive components"
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 1de45ff..cfcd25d 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -650,7 +650,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
 	// so if we are calculation TTS / NDL then let's force that off.
 	if (measureDuration.elapsed() > 1000 && prefs.calcndltts) {
 		MainWindow::instance()->turnOffNdlTts();
-		MainWindow::instance()->showError(tr("Show NDL / TTS was disabled because of excessive processing time"));
+		MainWindow::instance()->getNotificationWidget()->showNotification(tr("Show NDL / TTS was disabled because of excessive processing time"), KMessageWidget::Error);
 	}
 }
 
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 908747b..fcb565f 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -649,7 +649,7 @@ void DivelogsDeWebServices::prepareDivesForUpload(bool selected)
 			return;
 		}
 	}
-	MainWindow::instance()->showError(get_error_string());
+	MainWindow::instance()->getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
 }
 
 void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
-- 
2.1.0

From db08a533a1ac17e7833b1ba97f2c6c2e5919e0a0 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Thu, 26 Feb 2015 16:07:39 +0200
Subject: [PATCH 1/3] Creating a Notification widget in the Main Window.

The main error message bar can be used to show exporting information and
other notification.

So a new Notification handler object is created in the main window
<NotificationWidget> that inherits <KMessageWidget> that shows different
type of notifications, ex. (Warning, Error and information)

Also this class contains a QFutureWatcher object that is set to handle
the QFuture variable returned from the exporting thread. this will allow
the UI to be updated when the thread finishes execution.

Signed-off-by: Gehad elrobey <[email protected]>
---
 qt-ui/divelogexportdialog.cpp |  6 +++++-
 qt-ui/mainwindow.cpp          | 12 ++++++------
 qt-ui/mainwindow.h            |  2 ++
 qt-ui/mainwindow.ui           |  6 +++---
 qt-ui/notificationwidget.cpp  | 37 +++++++++++++++++++++++++++++++++++++
 qt-ui/notificationwidget.h    | 31 +++++++++++++++++++++++++++++++
 subsurface.pro                |  6 ++++--
 7 files changed, 88 insertions(+), 12 deletions(-)
 create mode 100644 qt-ui/notificationwidget.cpp
 create mode 100644 qt-ui/notificationwidget.h

diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp
index 43c4155..ff83170 100644
--- a/qt-ui/divelogexportdialog.cpp
+++ b/qt-ui/divelogexportdialog.cpp
@@ -9,6 +9,7 @@
 #include "subsurfacewebservices.h"
 #include "worldmap-save.h"
 #include "save-html.h"
+#include "mainwindow.h"
 
 #define GET_UNIT(name, field, f, t)                   \
 	v = settings.value(QString(name));            \
@@ -312,8 +313,11 @@ void DiveLogExportDialog::on_buttonBox_accepted()
 		settings.setValue("LastDir", fileInfo.dir().path());
 		settings.endGroup();
 		// the non XSLT exports are called directly above, the XSLT based ons are called here
-		if (!stylesheet.isEmpty())
+		if (!stylesheet.isEmpty()) {
 			future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), ui->exportSelected->isChecked(), ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8());
+			MainWindow::instance()->getNotificationWidget()->showNotification("Exporting...", KMessageWidget::Information);
+			MainWindow::instance()->getNotificationWidget()->setFuture(future);
+		}
 	}
 }
 
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 7b20462..535e4e2 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -1286,12 +1286,12 @@ int MainWindow::file_save(void)
 
 void MainWindow::showError(QString message)
 {
-	if (message.isEmpty())
-		return;
-	ui.mainErrorMessage->setText(message);
-	ui.mainErrorMessage->setCloseButtonVisible(true);
-	ui.mainErrorMessage->setMessageType(KMessageWidget::Error);
-	ui.mainErrorMessage->animatedShow();
+	ui.mainErrorMessage->showNotification(message, KMessageWidget::Error);
+}
+
+NotificationWidget *MainWindow::getNotificationWidget()
+{
+	return ui.mainErrorMessage;
 }
 
 void MainWindow::setTitle(enum MainWindowTitleFormat format)
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 5f4567f..2bf836b 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -13,6 +13,7 @@
 #include <QUuid>
 
 #include "ui_mainwindow.h"
+#include "notificationwidget.h"
 
 struct DiveList;
 class QSortFilterProxyModel;
@@ -92,6 +93,7 @@ public:
 	void setApplicationState(const QByteArray& state);
 	void showV2Dialog();
 	QUndoStack *undoStack;
+	NotificationWidget *getNotificationWidget();
 private
 slots:
 	/* file menu action */
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index b6cd4a3..024743c 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -40,7 +40,7 @@
      </widget>
     </item>
     <item>
-     <widget class="KMessageWidget" name="mainErrorMessage" native="true"/>
+     <widget class="NotificationWidget" name="mainErrorMessage" native="true"/>
     </item>
    </layout>
   </widget>
@@ -693,9 +693,9 @@
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KMessageWidget</class>
+   <class>NotificationWidget</class>
    <extends>QWidget</extends>
-   <header>kmessagewidget.h</header>
+   <header>notificationwidget.h</header>
    <container>1</container>
   </customwidget>
   <customwidget>
diff --git a/qt-ui/notificationwidget.cpp b/qt-ui/notificationwidget.cpp
new file mode 100644
index 0000000..44e2eed
--- /dev/null
+++ b/qt-ui/notificationwidget.cpp
@@ -0,0 +1,37 @@
+#include "notificationwidget.h"
+
+NotificationWidget::NotificationWidget(QWidget *parent) : KMessageWidget(parent)
+{
+	future_watcher = new QFutureWatcher<void>();
+	connect(future_watcher, SIGNAL(finished()), this, SLOT(finish()));
+}
+
+void NotificationWidget::showNotification(QString message, KMessageWidget::MessageType type)
+{
+	if (message.isEmpty())
+		return;
+	setText(message);
+	setCloseButtonVisible(true);
+	setMessageType(type);
+	animatedShow();
+}
+
+void NotificationWidget::hideNotification()
+{
+	animatedHide();
+}
+
+void NotificationWidget::setFuture(const QFuture<void> &future)
+{
+	future_watcher->setFuture(future);
+}
+
+void NotificationWidget::finish()
+{
+	hideNotification();
+}
+
+NotificationWidget::~NotificationWidget()
+{
+	delete future_watcher;
+}
diff --git a/qt-ui/notificationwidget.h b/qt-ui/notificationwidget.h
new file mode 100644
index 0000000..7a3f93b
--- /dev/null
+++ b/qt-ui/notificationwidget.h
@@ -0,0 +1,31 @@
+#ifndef NOTIFICATIONWIDGET_H
+#define NOTIFICATIONWIDGET_H
+
+#include <QWidget>
+#include <QFutureWatcher>
+
+#include <kmessagewidget.h>
+
+namespace Ui {
+	class NotificationWidget;
+}
+
+class NotificationWidget : public KMessageWidget {
+	Q_OBJECT
+
+public:
+	explicit NotificationWidget(QWidget *parent = 0);
+	void setFuture(const QFuture<void> &future);
+	void showNotification(QString message, KMessageWidget::MessageType type);
+	void hideNotification();
+	~NotificationWidget();
+
+private:
+	QFutureWatcher<void> *future_watcher;
+
+private
+slots:
+	void finish();
+};
+
+#endif // NOTIFICATIONWIDGET_H
diff --git a/subsurface.pro b/subsurface.pro
index a9afae4..639fff6 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -111,7 +111,8 @@ HEADERS = \
 	qt-ui/statistics/yearstatistics.h \
 	qt-ui/diveshareexportdialog.h \
 	qt-ui/filtermodels.h \
-	qt-ui/undocommands.h
+	qt-ui/undocommands.h \
+	qt-ui/notificationwidget.h
 
 android: HEADERS -= \
 	qt-ui/usermanual.h \
@@ -209,7 +210,8 @@ SOURCES =  \
 	qt-ui/statistics/monthstatistics.cpp \
 	qt-ui/diveshareexportdialog.cpp \
 	qt-ui/filtermodels.cpp \
-	qt-ui/undocommands.cpp
+	qt-ui/undocommands.cpp \
+	qt-ui/notificationwidget.cpp
 
 android: SOURCES += android.cpp
 else: win32: SOURCES += windows.c
-- 
2.1.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to