[Pkg-running-devel] [openambit] 74/131: Made the systemtrayicon behaves correctly with Qt5

Christian Perrier bubulle at moszumanska.debian.org
Thu Jul 17 20:19:12 UTC 2014


This is an automated email from the git hooks/post-receive script.

bubulle pushed a commit to branch master
in repository openambit.

commit 078f10dd4ff312915b6ab4a982dac9a788299297
Author: Emil Ljungdahl <emil at kratern.se>
Date:   Sat Jan 25 20:18:32 2014 +0100

    Made the systemtrayicon behaves correctly with Qt5
---
 src/openambit/devicemanager.cpp |  2 ++
 src/openambit/mainwindow.cpp    | 39 ++++++++++++++++++++++++++++-----------
 src/openambit/mainwindow.h      |  2 ++
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/openambit/devicemanager.cpp b/src/openambit/devicemanager.cpp
index 7c3578e..0187b36 100644
--- a/src/openambit/devicemanager.cpp
+++ b/src/openambit/devicemanager.cpp
@@ -32,8 +32,10 @@ DeviceManager::DeviceManager(QObject *parent) :
 
 DeviceManager::~DeviceManager()
 {
+    mutex.lock();
     delete udevListener;
     chargeTimer.stop();
+    mutex.unlock();
 }
 
 void DeviceManager::start()
diff --git a/src/openambit/mainwindow.cpp b/src/openambit/mainwindow.cpp
index e3f2b2e..6c671d8 100644
--- a/src/openambit/mainwindow.cpp
+++ b/src/openambit/mainwindow.cpp
@@ -83,10 +83,10 @@ MainWindow::MainWindow(QWidget *parent) :
     trayIconMenu->addSeparator();
     trayIconMenu->addAction(trayIconMinimizeRestoreAction);
     trayIconMenu->addAction(ui->actionE_xit);
-    trayIcon = new QSystemTrayIcon(QIcon(":/icon_disconnected"));
+    trayIcon = new QSystemTrayIcon(QIcon(":/icon_disconnected"), this);
     trayIcon->setContextMenu(trayIconMenu);
     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
-    trayIcon->show();
+    trayIcon->setVisible(true);
 
     // Setup device manager
     deviceManager = new DeviceManager();
@@ -119,6 +119,14 @@ MainWindow::~MainWindow()
 {
     deviceWorkerThread.quit();
     deviceWorkerThread.wait();
+
+    delete deviceManager;
+
+    delete trayIcon;
+    delete trayIconMinimizeRestoreAction;
+    delete trayIconSyncAction;
+    delete trayIconMenu;
+
     delete ui;
 }
 
@@ -126,7 +134,7 @@ void MainWindow::singleApplicationMsgRecv(QString msg)
 {
     if (msg == "focus") {
         // Another instance of application has asked use to gain focus, let's do so!
-        if (isMinimized()) {
+        if (isHidden()) {
             showHideWindow();
         }
         else {
@@ -140,19 +148,28 @@ void MainWindow::changeEvent(QEvent *event)
 {
     if (event->type() == QEvent::WindowStateChange) {
         if (isMinimized()) {
-            trayIconMinimizeRestoreAction->setText(tr("Restore"));
             QTimer::singleShot(0, this, SLOT(hide()));
         }
-        else {
-            trayIconMinimizeRestoreAction->setText(tr("Minimize"));
-        }
     }
     QMainWindow::changeEvent(event);
 }
 
+void MainWindow::showEvent(QShowEvent *event)
+{
+    trayIconMinimizeRestoreAction->setText(tr("Minimize"));
+    event->accept();
+}
+
+void MainWindow::hideEvent(QHideEvent *event)
+{
+    trayIconMinimizeRestoreAction->setText(tr("Restore"));
+    event->accept();
+}
+
 void MainWindow::closeEvent(QCloseEvent *event)
 {
     if (forceClose) {
+        trayIcon->setVisible(false);
         event->accept();
     }
     else {
@@ -169,7 +186,7 @@ void MainWindow::closeRequested()
 
 void MainWindow::showHideWindow()
 {
-    if (isMinimized()) {
+    if (isHidden()) {
         showNormal();
     }
     else {
@@ -298,7 +315,7 @@ void MainWindow::syncFinished(bool success)
         currentLogMessageRow->setMessage(tr("Syncronization complete"));
         currentLogMessageRow->setStatus(LogMessageRow::StatusSuccess);
         ui->verticalLayoutLogMessages->addLayout(currentLogMessageRow);
-        if (isMinimized()) {
+        if (isHidden()) {
             trayIcon->showMessage(tr("openambit"), tr("Syncronisation finished"));
         }
     }
@@ -307,7 +324,7 @@ void MainWindow::syncFinished(bool success)
         currentLogMessageRow->setMessage(tr("Syncronization failed"));
         currentLogMessageRow->setStatus(LogMessageRow::StatusFailed);
         ui->verticalLayoutLogMessages->addLayout(currentLogMessageRow);
-        if (isMinimized()) {
+        if (isHidden()) {
             trayIcon->showMessage(tr("openambit"), tr("Syncronisation failed"), QSystemTrayIcon::Critical);
         }
     }
@@ -430,7 +447,7 @@ void MainWindow::startSync()
     settings.endGroup();
 
     trayIcon->setIcon(QIcon(":/icon_syncing"));
-    if (isMinimized()) {
+    if (isHidden()) {
         trayIcon->showMessage(tr("openambit"), tr("Syncronisation started"));
     }
 
diff --git a/src/openambit/mainwindow.h b/src/openambit/mainwindow.h
index 9357d9d..496ca51 100644
--- a/src/openambit/mainwindow.h
+++ b/src/openambit/mainwindow.h
@@ -53,6 +53,8 @@ public slots:
 
 protected:
     void changeEvent(QEvent *event);
+    void showEvent(QShowEvent *event);
+    void hideEvent(QHideEvent *event);
     void closeEvent(QCloseEvent *event);
 
 private slots:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/openambit.git



More information about the Pkg-running-devel mailing list