Skip to content

Commit c2b365c

Browse files
committed
[FEATURE] Add system tray notifcation for finished tasks.
Should work on all platforms and only shows when application is hidden.
1 parent 5fd933e commit c2b365c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/app/qgisapp.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#endif
5959
#include <QStatusBar>
6060
#include <QStringList>
61+
#include <QSystemTrayIcon>
6162
#include <QTcpSocket>
6263
#include <QTextStream>
6364
#include <QtGlobal>
@@ -1126,6 +1127,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
11261127
}
11271128

11281129

1130+
mTray = new QSystemTrayIcon();
1131+
mTray->setIcon( QIcon( QgsApplication::appIconPath() ) );
1132+
mTray->show();
1133+
1134+
connect( QgsApplication::taskManager(), &QgsTaskManager::statusChanged, this, &QgisApp::onTaskCompleteShowNotify );
1135+
11291136
#ifdef Q_OS_WIN
11301137
QWinTaskbarButton *taskButton = new QWinTaskbarButton( this );
11311138
taskButton->setWindow( windowHandle() );
@@ -1353,6 +1360,8 @@ QgisApp::~QgisApp()
13531360
delete QgsProject::instance();
13541361

13551362
delete mPythonUtils;
1363+
1364+
delete mTray;
13561365
}
13571366

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

11410+
void QgisApp::onTaskCompleteShowNotify( long taskId, int status )
11411+
{
11412+
if ( status == QgsTask::Complete && !this->isActiveWindow() )
11413+
{
11414+
QgsTask *task = QgsApplication::taskManager()->task( taskId );
11415+
if ( task )
11416+
{
11417+
QString description = task->description();
11418+
mTray->showMessage( "Task Complete", description );
11419+
}
11420+
}
11421+
}
11422+
1140111423
void QgisApp::onTransactionGroupsChanged()
1140211424
{
1140311425
Q_FOREACH ( QgsTransactionGroup *tg, QgsProject::instance()->transactionGroups().values() )

src/app/qgisapp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class QStringList;
3636
class QToolButton;
3737
class QTcpSocket;
3838
class QValidator;
39+
class QSystemTrayIcon;
3940

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

749750
private slots:
751+
void onTaskCompleteShowNotify( long taskId, int status );
752+
750753
void onTransactionGroupsChanged();
751754

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

1864+
QSystemTrayIcon *mTray = nullptr;
1865+
18611866
friend class TestQgisAppPython;
18621867
};
18631868

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

18701875
#endif
1871-

0 commit comments

Comments
 (0)