added icon in system tray

This commit is contained in:
2023-02-12 00:37:50 +01:00
parent 4ead825bad
commit a2d9f93ace
5 changed files with 192 additions and 55 deletions
+92 -10
View File
@@ -111,15 +111,59 @@ MainWindow::MainWindow(QWidget *parent)
}
// load list of services
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()
{
delete ui;
QCoreApplication::quit();
}
// Close window has been clicked
void MainWindow::closeEvent (QCloseEvent *event)
void MainWindow::quitApp()
{
QMessageBox::StandardButton reply;
QMessageBox::StandardButtons param;
@@ -144,12 +188,7 @@ void MainWindow::closeEvent (QCloseEvent *event)
param,
QMessageBox::No);
if (reply == QMessageBox::No)
{
// continuing
event->ignore();
return;
}else if(reply == QMessageBox::Yes)
if(reply == QMessageBox::Yes)
{
// emission of signal to downloading thread and stopping
emit (stopDownloading(this->downloading.process));
@@ -158,7 +197,45 @@ void MainWindow::closeEvent (QCloseEvent *event)
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
@@ -569,7 +646,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
this->downloading.server = this->connexion.server;
this->downloading.service = this->connexion.service;
startDownloading();
// wit 1 second to process start
// wait 1 second to process start
//sleep(1);
}
@@ -951,3 +1028,8 @@ void MainWindow::on_comboBox_currentIndexChanged(int index)
{
ui->toolBar->setToolButtonStyle((Qt::ToolButtonStyle)index);
}
void MainWindow::on_actionExit_triggered()
{
quitApp();
}