Skip to content

Commit

Permalink
[FEATURE] Add system tray notifcation for finished tasks.
Browse files Browse the repository at this point in the history
Should work on all platforms and only shows when application is hidden.
  • Loading branch information
NathanW2 committed Mar 5, 2017
1 parent 5fd933e commit c2b365c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -58,6 +58,7 @@
#endif
#include <QStatusBar>
#include <QStringList>
#include <QSystemTrayIcon>
#include <QTcpSocket>
#include <QTextStream>
#include <QtGlobal>
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -1353,6 +1360,8 @@ QgisApp::~QgisApp()
delete QgsProject::instance();

delete mPythonUtils;

delete mTray;
}

void QgisApp::dragEnterEvent( QDragEnterEvent *event )
Expand Down Expand Up @@ -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() )
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -36,6 +36,7 @@ class QStringList;
class QToolButton;
class QTcpSocket;
class QValidator;
class QSystemTrayIcon;

class QgisAppInterface;
class QgisAppStyleSheet;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
};

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

#endif

4 comments on commit c2b365c

@nirvn
Copy link
Contributor

@nirvn nirvn commented on c2b365c Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

@NathanW2 NathanW2 commented on c2b365c Mar 7, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nirvn
Copy link
Contributor

@nirvn nirvn commented on c2b365c Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson , yeah, agreed.

Please sign in to comment.