Skip to content
Permalink
Browse files

[FEATURE] Add system tray notifcation for finished tasks.

Should work on all platforms and only shows when application is hidden.
  • Loading branch information
NathanW2 committed Mar 5, 2017
1 parent 5fd933e commit c2b365c70e88c59a7873d657a1a6db465dee57fe
Showing with 27 additions and 1 deletion.
  1. +22 −0 src/app/qgisapp.cpp
  2. +5 −1 src/app/qgisapp.h
@@ -58,6 +58,7 @@
#endif
#include <QStatusBar>
#include <QStringList>
#include <QSystemTrayIcon>
#include <QTcpSocket>
#include <QTextStream>
#include <QtGlobal>
@@ -1126,6 +1127,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}


mTray = new QSystemTrayIcon();
mTray->setIcon( QIcon( QgsApplication::appIconPath() ) );
mTray->show();

connect( QgsApplication::taskManager(), &QgsTaskManager::statusChanged, this, &QgisApp::onTaskCompleteShowNotify );

#ifdef Q_OS_WIN
QWinTaskbarButton *taskButton = new QWinTaskbarButton( this );
taskButton->setWindow( windowHandle() );
@@ -1353,6 +1360,8 @@ QgisApp::~QgisApp()
delete QgsProject::instance();

delete mPythonUtils;

delete mTray;
}

void QgisApp::dragEnterEvent( QDragEnterEvent *event )
@@ -11398,6 +11407,19 @@ void QgisApp::keyPressEvent( QKeyEvent *e )
}
}

void QgisApp::onTaskCompleteShowNotify( long taskId, int status )
{
if ( status == QgsTask::Complete && !this->isActiveWindow() )
{
QgsTask *task = QgsApplication::taskManager()->task( taskId );
if ( task )
{
QString description = task->description();
mTray->showMessage( "Task Complete", description );
}
}
}

void QgisApp::onTransactionGroupsChanged()
{
Q_FOREACH ( QgsTransactionGroup *tg, QgsProject::instance()->transactionGroups().values() )
@@ -36,6 +36,7 @@ class QStringList;
class QToolButton;
class QTcpSocket;
class QValidator;
class QSystemTrayIcon;

class QgisAppInterface;
class QgisAppStyleSheet;
@@ -747,6 +748,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
#endif

private slots:
void onTaskCompleteShowNotify( long taskId, int status );

void onTransactionGroupsChanged();

void onSnappingConfigChanged();
@@ -1858,6 +1861,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );

QSystemTrayIcon *mTray = nullptr;

friend class TestQgisAppPython;
};

@@ -1868,4 +1873,3 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
#endif

#endif

4 comments on commit c2b365c

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 7, 2017

@NathanW2 , any chance we could avoid permanently showing the QGIS tray icon? Maybe only show it when there's a running task, and hide it when task is over and/or notification has been hidden?

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Mar 7, 2017

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Mar 7, 2017

@nirvn i think in the long run we should replace the qt method by libnotify for linux platforms here

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 7, 2017

@nyalldawson , yeah, agreed.

Please sign in to comment.
You can’t perform that action at this time.