Skip to content

Commit 030ec53

Browse files
author
Charles PIGNEROL
committed
Version 6.6.0. ActionCompletionNotifier class used to automatically display a notification at the end of an action.
1 parent bc16895 commit 030ec53

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
set (QT_UTIL_MAJOR_VERSION "6")
6-
set (QT_UTIL_MINOR_VERSION "5")
6+
set (QT_UTIL_MINOR_VERSION "6")
77
set (QT_UTIL_RELEASE_VERSION "0")
88
set (QT_UTIL_VERSION ${QT_UTIL_MAJOR_VERSION}.${QT_UTIL_MINOR_VERSION}.${QT_UTIL_RELEASE_VERSION})
99

src/QtUtil/QtMessageBox.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int QtMessageBox::displayQuestionMessage (QWidget* parent, const UTF8String& tit
373373
} // QtMessageBox::displayQuestionMessage
374374

375375

376-
int QtMessageBox::systemNotification (const UTF8String& appTitle, const UTF8String& message, URGENCY_LEVEL level, size_t duration) // v 6.5.0
376+
int QtMessageBox::systemNotification (const UTF8String& appTitle, const string& appIconFile, const UTF8String& message, URGENCY_LEVEL level, size_t duration) // v 6.6.0
377377
{
378378
static bool available = true;
379379
if (false == available)
@@ -400,6 +400,11 @@ int QtMessageBox::systemNotification (const UTF8String& appTitle, const UTF8Stri
400400
notifySend->getOptions ( ).addOption ("-a");
401401
notifySend->getOptions ( ).addOption (appTitle.utf8 ( ));
402402
} // if (false == appTitle.empty ( ))
403+
if (false == appIconFile.empty ( ))
404+
{
405+
notifySend->getOptions ( ).addOption ("-i");
406+
notifySend->getOptions ( ).addOption (appIconFile);
407+
} // if (false == appIconFile.empty ( ))
403408
notifySend->getOptions ( ).addOption (message.utf8 ( ));
404409
notifySend->execute (false);
405410
notifySend->wait ( );
@@ -409,3 +414,39 @@ int QtMessageBox::systemNotification (const UTF8String& appTitle, const UTF8Stri
409414

410415
return notifySend->getCompletionCode ( );
411416
} // QtMessageBox::systemNotification
417+
418+
419+
// ===========================================================================
420+
// LA CLASSE ActionCompletionNotifier
421+
// ===========================================================================
422+
423+
ActionCompletionNotifier::ActionCompletionNotifier (
424+
const UTF8String& appTitle, const string& appIconFile, const UTF8String& message, QtMessageBox::URGENCY_LEVEL level, size_t duration, size_t minimumTimeLapse)
425+
: _timer ( ), _appTitle (appTitle), _message (message), _appIconFile (appIconFile), _urgencyLevel (level), _duration (duration), _minimumTimeLapse (minimumTimeLapse)
426+
{
427+
if (0 != _minimumTimeLapse)
428+
_timer.start ( );
429+
}
430+
431+
432+
ActionCompletionNotifier::ActionCompletionNotifier (const ActionCompletionNotifier&)
433+
{
434+
assert (0 && "ActionCompletionNotifier copy constructor is not allowed.");
435+
} // ActionCompletionNotifier::ActionCompletionNotifier
436+
437+
438+
ActionCompletionNotifier& ActionCompletionNotifier::operator = (const ActionCompletionNotifier&)
439+
{
440+
assert (0 && "ActionCompletionNotifier assignment operator is not allowed.");
441+
return *this;
442+
} // ActionCompletionNotifier::operator =
443+
444+
445+
ActionCompletionNotifier::~ActionCompletionNotifier ( )
446+
{
447+
if (0 != _minimumTimeLapse)
448+
_timer.stop ( );
449+
450+
if ((0 == _minimumTimeLapse) || (_timer.duration ( ) >= _minimumTimeLapse))
451+
QtMessageBox::systemNotification (_appTitle, _appIconFile, _message, _urgencyLevel, _duration);
452+
} // ActionCompletionNotifier::~ActionCompletionNotifier

src/QtUtil/public/QtUtil/QtMessageBox.h

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef QT_MESSAGE_BOX_H
44
#define QT_MESSAGE_BOX_H
55

6+
#include <TkUtil/Timer.h>
67
#include <TkUtil/UTF8String.h>
78

89
#include <QWidget>
@@ -167,13 +168,15 @@ class QtMessageBox
167168
/**
168169
* Envoie la notification système transmise en argument. Repose sur <I>notify-send</I>. Attention, les caractères accentués semblent ne pas passer.
169170
* @param Titre de l'application
171+
* @param (Eventuel) fichier icône de l'application
170172
* @param Message à afficher
171173
* @param Niveau d'urgence
172174
* @param Durée (en millisecondes) de la notification.
173175
* @return 0 si la notification s'est bien passée, ou un code d'erreur.
174-
* @since 6.5.0
176+
* @since 6.6.0
177+
* @see ActionCompletionNotifier
175178
*/
176-
static int systemNotification (const IN_UTIL UTF8String& appTitle, const IN_UTIL UTF8String& message, URGENCY_LEVEL level = URGENCY_NORMAL, size_t duration = 5000);
179+
static int systemNotification (const IN_UTIL UTF8String& appTitle, const std::string& appIconFile, const IN_UTIL UTF8String& message, URGENCY_LEVEL level = URGENCY_NORMAL, size_t duration = 5000);
177180

178181

179182
private :
@@ -229,5 +232,46 @@ class QtMessageDialog : public QDialog
229232
}; // class QtMessageDialog
230233

231234

235+
/**
236+
* Cette classe permet d'envoyer une notification système lorsque le destructeur est appelé, et sous réserve éventuellement
237+
* qu'un certain laps de temps soit écoulé.
238+
* @see QtMessageBox::systemNotification
239+
*/
240+
class ActionCompletionNotifier
241+
{
242+
public :
243+
244+
/**
245+
* Envoie la notification système transmise en argument.
246+
* @param Titre de l'application
247+
* @param (Eventuel) fichier icône de l'application
248+
* @param Message à afficher
249+
* @param Niveau d'urgence
250+
* @param Durée (en millisecondes) de la notification.
251+
* @param Laps de temps (en secondes) à partir duquel la notification doit être envoyée.
252+
*/
253+
ActionCompletionNotifier (const IN_UTIL UTF8String& appTitle, const std::string& appIconFile, const IN_UTIL UTF8String& message, QtMessageBox::URGENCY_LEVEL level = QtMessageBox::URGENCY_NORMAL, size_t duration = 30, size_t minimumTimeLapse = 0);
254+
255+
/**
256+
* Destructeur. Envoie la notification au système.
257+
*/
258+
virtual ~ActionCompletionNotifier ( );
259+
260+
261+
private :
262+
263+
/**
264+
* Constructeur de copie / opérateur = : interdits.
265+
*/
266+
ActionCompletionNotifier (const ActionCompletionNotifier&);
267+
ActionCompletionNotifier& operator = (const ActionCompletionNotifier&);
268+
269+
/** Informations nécessaires à la notification. */
270+
IN_UTIL Timer _timer;
271+
IN_UTIL UTF8String _appTitle, _message;
272+
std::string _appIconFile;
273+
QtMessageBox::URGENCY_LEVEL _urgencyLevel;
274+
size_t _duration, _minimumTimeLapse;
275+
}; // class ActionCompletionNotifier
232276

233277
#endif // QT_MESSAGE_BOX_H

versions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 6.6.0 : 18/09/24
2+
===============
3+
4+
Classe ActionCompletionNotifier permettant d'afficher automatiquement une notification en fin d'action.
5+
Les notifications syst�mes peuvent utiliser l'ic�ne de l'application.
6+
7+
8+
19
Version 6.5.0 : 16/09/24
210
===============
311

0 commit comments

Comments
 (0)