added icon in system tray

This commit is contained in:
Daniel Tartavel 2023-02-12 00:37:50 +01:00
parent 4ead825bad
commit a2d9f93ace
5 changed files with 192 additions and 55 deletions

View File

@ -74,96 +74,111 @@
<translation>Fenêtre principale</translation> <translation>Fenêtre principale</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="83"/> <location filename="mainwindow.ui" line="86"/>
<source>Server</source> <source>Server</source>
<oldsource>Serveur</oldsource> <oldsource>Serveur</oldsource>
<translation>Serveur</translation> <translation>Serveur</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="105"/> <location filename="mainwindow.ui" line="108"/>
<source>Enter server&apos;s URL</source> <source>Enter server&apos;s URL</source>
<translation>Entrez l&apos;adresse du serveur</translation> <translation>Entrez l&apos;adresse du serveur</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="121"/> <location filename="mainwindow.ui" line="124"/>
<source>Port</source> <source>Port</source>
<translation>Port</translation> <translation>Port</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="149"/> <location filename="mainwindow.ui" line="152"/>
<source>Enter rsync port on server</source> <source>Enter rsync port on server</source>
<translation>Entrez le port du serveur rsync</translation> <translation>Entrez le port du serveur rsync</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="186"/> <location filename="mainwindow.ui" line="189"/>
<source>Press button to connect to rsync server</source> <source>Press button to connect to rsync server</source>
<extracomment>Connect to server</extracomment> <extracomment>Connect to server</extracomment>
<translation>Cliquez pour se connecter au serveur rsync</translation> <translation>Cliquez pour se connecter au serveur rsync</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="192"/> <location filename="mainwindow.ui" line="195"/>
<source>Connection</source> <source>Connection</source>
<translation>Connexion</translation> <translation>Connexion</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="195"/> <location filename="mainwindow.ui" line="198"/>
<source>Return</source> <source>Return</source>
<translation>Retour</translation> <translation>Retour</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="221"/> <location filename="mainwindow.ui" line="224"/>
<source>Click to view the list of files of this folder</source> <source>Click to view the list of files of this folder</source>
<translation>Cliquez pour afficher la liste des documents</translation> <translation>Cliquez pour afficher la liste des documents</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="256"/> <location filename="mainwindow.ui" line="259"/>
<source>Click to add to download queue</source> <source>Click to add to download queue</source>
<translation>Cliquez pour ajouter à la file de téléchargement</translation> <translation>Cliquez pour ajouter à la file de téléchargement</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="334"/> <location filename="mainwindow.ui" line="337"/>
<source>Click on file to stop downloading</source> <source>Click on file to stop downloading</source>
<translation>Cliquez sur le document pour arrêter le téléchargement et l&apos;enlever de la file</translation> <translation>Cliquez sur le document pour arrêter le téléchargement et l&apos;enlever de la file</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="357"/> <location filename="mainwindow.ui" line="360"/>
<source>%p%</source> <source>%p%</source>
<extracomment>Downloading</extracomment> <extracomment>Downloading</extracomment>
<translation>Téléchargement</translation> <translation>Téléchargement</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="368"/> <location filename="mainwindow.ui" line="371"/>
<source>toolBar</source> <source>toolBar</source>
<translation>Barre d&apos;outils</translation> <translation>Barre d&apos;outils</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="440"/> <location filename="mainwindow.ui" line="444"/>
<source>Download</source> <source>Download</source>
<translation>Télécharger</translation> <translation>Télécharger</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="443"/> <location filename="mainwindow.ui" line="447"/>
<source>Click on menu button to download the entire folder</source> <source>Click on menu button to download the entire folder</source>
<translation>Cliquer sur le bouton droit de la souris pour télécharger le dossier entier</translation> <translation>Cliquer sur le bouton droit de la souris pour télécharger le dossier entier</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="405"/> <location filename="mainwindow.ui" line="455"/>
<location filename="mainwindow.ui" line="408"/> <source>Exit</source>
<translation>Quitter</translation>
</message>
<message>
<location filename="mainwindow.ui" line="458"/>
<source>Terminate the program</source>
<translation>Terminer le programme</translation>
</message>
<message>
<location filename="mainwindow.ui" line="461"/>
<source>Ctrl+Q</source>
<translation>Ctrl+Q</translation>
</message>
<message>
<location filename="mainwindow.ui" line="409"/>
<location filename="mainwindow.ui" line="412"/>
<source>Change save folder</source> <source>Change save folder</source>
<translation>Changer le dossier de destination</translation> <translation>Changer le dossier de destination</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="417"/> <location filename="mainwindow.ui" line="421"/>
<source>About</source> <source>About</source>
<translation>À propos</translation> <translation>À propos</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="426"/> <location filename="mainwindow.ui" line="430"/>
<source>About Qt</source> <source>About Qt</source>
<translation>À propos de Qt</translation> <translation>À propos de Qt</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="435"/> <location filename="mainwindow.ui" line="439"/>
<source>Settings</source> <source>Settings</source>
<translation>Paramètres</translation> <translation>Paramètres</translation>
</message> </message>
@ -222,123 +237,133 @@ Cliquez sur un fichier pour l&apos;ajouter dans la file de téléchargement</tra
<translation>Une liste de téléchargement existe, voulez-vous utiliser cette liste ? si non, elle sera effacée</translation> <translation>Une liste de téléchargement existe, voulez-vous utiliser cette liste ? si non, elle sera effacée</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="138"/> <location filename="mainwindow.cpp" line="125"/>
<source>&amp;Quit</source>
<translation>&amp;Quitter</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="182"/>
<source>Clicking Save button, You can save the list of downloads <source>Clicking Save button, You can save the list of downloads
</source> </source>
<translation>Vous pouvez enregistrer la liste des téléchargements en cliquant sur &quot;enregister&quot; <translation>Vous pouvez enregistrer la liste des téléchargements en cliquant sur &quot;enregister&quot;
</translation> </translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="143"/> <location filename="mainwindow.cpp" line="187"/>
<source>Exiting will stop downloading, and will clear the download queue. <source>Exiting will stop downloading, and will clear the download queue.
Do you want to exit ?</source> Do you want to exit ?</source>
<translation>Si vous sortez, les téléchargements seront arrêter. <translation>Si vous sortez, les téléchargements seront arrêter.
Voulez-vous vraiment sortir ?</translation> Voulez-vous vraiment sortir ?</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="425"/> <location filename="mainwindow.cpp" line="216"/>
<source>The program will keep running in the system tray. To terminate the program, choose &lt;b&gt;Quit&lt;/b&gt; in the context menu of the system tray entry.</source>
<translation>Le programme continue dans la boîte à miniatures. Pour quitter le programme cliquez sur l&apos;icône &lt;b&gt;Quitter&lt;/b&gt; ou dans les menu contextuel.</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="502"/>
<source>server does not exists</source> <source>server does not exists</source>
<translation>Le serveur n&apos;existe pas</translation> <translation>Le serveur n&apos;existe pas</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="452"/> <location filename="mainwindow.cpp" line="529"/>
<location filename="mainwindow.cpp" line="472"/> <location filename="mainwindow.cpp" line="549"/>
<source>Dir</source> <source>Dir</source>
<translation>dossier</translation> <translation>dossier</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="456"/> <location filename="mainwindow.cpp" line="533"/>
<location filename="mainwindow.cpp" line="540"/> <location filename="mainwindow.cpp" line="617"/>
<source>File</source> <source>File</source>
<translation>Doc</translation> <translation>Doc</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="549"/> <location filename="mainwindow.cpp" line="626"/>
<source>File is already downloaded. Do you want to reload it ? The old file will be deleted</source> <source>File is already downloaded. Do you want to reload it ? The old file will be deleted</source>
<translation>Le document est déjà téléchargé. Voulez-vous le télécharger à nouveau ? L&apos;ancien fichier sera effacé</translation> <translation>Le document est déjà téléchargé. Voulez-vous le télécharger à nouveau ? L&apos;ancien fichier sera effacé</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="584"/> <location filename="mainwindow.cpp" line="661"/>
<source>File is already downloading</source> <source>File is already downloading</source>
<translation>Le document est déjà en téléchargement</translation> <translation>Le document est déjà en téléchargement</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="628"/> <location filename="mainwindow.cpp" line="705"/>
<source>Rsync process crashed</source> <source>Rsync process crashed</source>
<translation>Le processus rsync à planté</translation> <translation>Le processus rsync à planté</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="784"/> <location filename="mainwindow.cpp" line="861"/>
<source>Version</source> <source>Version</source>
<translation>Version</translation> <translation>Version</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="785"/> <location filename="mainwindow.cpp" line="862"/>
<source>Licence</source> <source>Licence</source>
<translation>License</translation> <translation>License</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="786"/> <location filename="mainwindow.cpp" line="863"/>
<source>Author</source> <source>Author</source>
<translation>Auteur</translation> <translation>Auteur</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="787"/> <location filename="mainwindow.cpp" line="864"/>
<source>EMail</source> <source>EMail</source>
<translation>Courriel</translation> <translation>Courriel</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="788"/> <location filename="mainwindow.cpp" line="865"/>
<source>Source code</source> <source>Source code</source>
<translation>Code source</translation> <translation>Code source</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="811"/> <location filename="mainwindow.cpp" line="888"/>
<source>Since the save path is linked to service, you need to select a service before you can select a folder</source> <source>Since the save path is linked to service, you need to select a service before you can select a folder</source>
<translation>Vous devez sélectionnez un service pour pouvoir sélectionnez un dossier par défaut</translation> <translation>Vous devez sélectionnez un service pour pouvoir sélectionnez un dossier par défaut</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="816"/> <location filename="mainwindow.cpp" line="893"/>
<source>Choose folder where to save file</source> <source>Choose folder where to save file</source>
<translation>Choisissez un dossier enregistrer le document</translation> <translation>Choisissez un dossier enregistrer le document</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="702"/> <location filename="mainwindow.cpp" line="779"/>
<source>Do you want to stop downloading and delete this file from download queue ?</source> <source>Do you want to stop downloading and delete this file from download queue ?</source>
<translation>Voulez-vous arrêter le téléchargement et enlever ce fichier de la file de téléchargement ?</translation> <translation>Voulez-vous arrêter le téléchargement et enlever ce fichier de la file de téléchargement ?</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="716"/> <location filename="mainwindow.cpp" line="793"/>
<source>Do you want to delete this file from download queue ?</source> <source>Do you want to delete this file from download queue ?</source>
<translation>Voulez-vous enlever ce fichier de la file de téléchargement ?</translation> <translation>Voulez-vous enlever ce fichier de la file de téléchargement ?</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="118"/> <location filename="mainwindow.h" line="121"/>
<source>The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program.</source> <source>The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program.</source>
<translation>Le processus échoué, soit le programme est manquant, soit vous n&apos;avez pas l&apos;autorisation de l&apos;exécuter.</translation> <translation>Le processus échoué, soit le programme est manquant, soit vous n&apos;avez pas l&apos;autorisation de l&apos;exécuter.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="119"/> <location filename="mainwindow.h" line="122"/>
<source>The process crashed some time after starting successfully.</source> <source>The process crashed some time after starting successfully.</source>
<translation>Le processus à planté après avoir démarré avec succès.</translation> <translation>Le processus à planté après avoir démarré avec succès.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="120"/> <location filename="mainwindow.h" line="123"/>
<source>The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.</source> <source>The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.</source>
<translation>La fonction waitFor...() a dépassé la limite de temps, you pouvez essayer de la relancer.</translation> <translation>La fonction waitFor...() a dépassé la limite de temps, you pouvez essayer de la relancer.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="121"/> <location filename="mainwindow.h" line="124"/>
<source>An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.</source> <source>An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.</source>
<translation>Une erreur est survenue lors de l&apos;envoi des données vers le processus. Le processus est peut être arrté ou il a fermé son canal d&apos;entrée.</translation> <translation>Une erreur est survenue lors de l&apos;envoi des données vers le processus. Le processus est peut être arrté ou il a fermé son canal d&apos;entrée.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="122"/> <location filename="mainwindow.h" line="125"/>
<source>An error occurred when attempting to read from the process. For example, the process may not be running.</source> <source>An error occurred when attempting to read from the process. For example, the process may not be running.</source>
<translation>Une erreur est survenue lors de la lecturee de données, le processus est probablement arrêté.</translation> <translation>Une erreur est survenue lors de la lecturee de données, le processus est probablement arrêté.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.h" line="123"/> <location filename="mainwindow.h" line="126"/>
<source>An unknown error occurred. This is the default return value of error().</source> <source>An unknown error occurred. This is the default return value of error().</source>
<translation>Une erreur inconnue est survenue. C&apos;est la valeur de retour par défaut de error().</translation> <translation>Une erreur inconnue est survenue. C&apos;est la valeur de retour par défaut de error().</translation>
</message> </message>

Binary file not shown.

View File

@ -111,15 +111,59 @@ MainWindow::MainWindow(QWidget *parent)
} }
// load list of services // load list of services
populateList(); populateList();
initSystemTrayIcon();
}
void MainWindow::initSystemTrayIcon()
{
QMenu *trayIconMenu;
QAction * quitAction;
this->trayIcon = new QSystemTrayIcon;
this->trayIcon->setIcon(this->windowIcon());
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, &QAction::triggered, this, &MainWindow::quitApp);
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
connect(this->trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(on_trayIcon_clicked(QSystemTrayIcon::ActivationReason)));
this->trayIcon->show();
}
void MainWindow::on_trayIcon_clicked(QSystemTrayIcon::ActivationReason reason)
{
if (reason == QSystemTrayIcon::Trigger)
{
if (this->isHidden())
{
this->show();
}else
{
this->hide();
}
}
}
void MainWindow::hideWindow()
{
this->hide();
}
void MainWindow::showWindow()
{
this->show();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
QCoreApplication::quit();
} }
// Close window has been clicked void MainWindow::quitApp()
void MainWindow::closeEvent (QCloseEvent *event)
{ {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
QMessageBox::StandardButtons param; QMessageBox::StandardButtons param;
@ -144,12 +188,7 @@ void MainWindow::closeEvent (QCloseEvent *event)
param, param,
QMessageBox::No); QMessageBox::No);
if (reply == QMessageBox::No) if(reply == QMessageBox::Yes)
{
// continuing
event->ignore();
return;
}else if(reply == QMessageBox::Yes)
{ {
// emission of signal to downloading thread and stopping // emission of signal to downloading thread and stopping
emit (stopDownloading(this->downloading.process)); emit (stopDownloading(this->downloading.process));
@ -158,7 +197,45 @@ void MainWindow::closeEvent (QCloseEvent *event)
saveDownloadList(); saveDownloadList();
} }
} }
event->accept(); delete ui;
QCoreApplication::quit();
}
// Close window has been clicked
void MainWindow::closeEvent (QCloseEvent *event)
{
QMessageBox msgBox;
QCheckBox *cb = new QCheckBox("Don't show this again ?");
QAbstractButton * reply;
if (!event->spontaneous() || !isVisible())
return;
if (trayIcon->isVisible() and this->settings.value("CloseCheckbox").toBool() == false)
{
msgBox.setWindowTitle("RsyncUI");
msgBox.setInformativeText(tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
msgBox.addButton(QMessageBox::Ok);
//msgBox.addButton(QMessageBox::No);
// msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setCheckBox(cb);
msgBox.exec();
reply = msgBox.clickedButton();
// if response is yes then loading list
if (cb->isChecked())
{
this->settings.setValue("CloseCheckbox", true);
}
hide();
//event->accept();
event->ignore();
}
} }
// Populate treeview with list of files // Populate treeview with list of files
@ -569,7 +646,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
this->downloading.server = this->connexion.server; this->downloading.server = this->connexion.server;
this->downloading.service = this->connexion.service; this->downloading.service = this->connexion.service;
startDownloading(); startDownloading();
// wit 1 second to process start // wait 1 second to process start
//sleep(1); //sleep(1);
} }
@ -951,3 +1028,8 @@ void MainWindow::on_comboBox_currentIndexChanged(int index)
{ {
ui->toolBar->setToolButtonStyle((Qt::ToolButtonStyle)index); ui->toolBar->setToolButtonStyle((Qt::ToolButtonStyle)index);
} }
void MainWindow::on_actionExit_triggered()
{
quitApp();
}

View File

@ -39,6 +39,8 @@
#include <QProcess> #include <QProcess>
#include <QToolBar> #include <QToolBar>
#include <QDir> #include <QDir>
#include <QSystemTrayIcon>
#include <QMenu>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -98,6 +100,7 @@ class MainWindow : public QMainWindow
QDialog Configuration; QDialog Configuration;
Ui::Configuration config; Ui::Configuration config;
std::vector <QString> serversList; std::vector <QString> serversList;
QSystemTrayIcon * trayIcon;
QList<QString> bwUnitText { QList<QString> bwUnitText {
"KB", "KB",
"MB", "MB",
@ -139,6 +142,9 @@ class MainWindow : public QMainWindow
void saveDownloadList(); void saveDownloadList();
void loadDownloadList(); void loadDownloadList();
void download(); void download();
void initSystemTrayIcon();
void hideWindow();
void showWindow();
private slots: private slots:
@ -180,7 +186,13 @@ class MainWindow : public QMainWindow
void cancelled(QProcess *); void cancelled(QProcess *);
signals: void on_trayIcon_clicked(QSystemTrayIcon::ActivationReason reason);
void quitApp();
void on_actionExit_triggered();
signals:
void stopDownloading(QProcess *); void stopDownloading(QProcess *);
void progressSignal(int); void progressSignal(int);
void finishedSignal(bool = true); void finishedSignal(bool = true);

View File

@ -20,6 +20,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<property name="windowIcon">
<iconset theme="/usr/share/icons/RsyncUI.png"/>
</property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum> <enum>Qt::ToolButtonTextUnderIcon</enum>
</property> </property>
@ -395,6 +398,7 @@
<addaction name="action_Settings"/> <addaction name="action_Settings"/>
<addaction name="actionAbout"/> <addaction name="actionAbout"/>
<addaction name="actionAbout_Qt"/> <addaction name="actionAbout_Qt"/>
<addaction name="actionExit"/>
</widget> </widget>
<action name="DefaultSaveFolder"> <action name="DefaultSaveFolder">
<property name="icon"> <property name="icon">
@ -443,6 +447,20 @@
<string>Click on menu button to download the entire folder</string> <string>Click on menu button to download the entire folder</string>
</property> </property>
</action> </action>
<action name="actionExit">
<property name="icon">
<iconset theme="application-exit"/>
</property>
<property name="text">
<string>Exit</string>
</property>
<property name="toolTip">
<string>Terminate the program</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>