From 73e1bc69975c7ac948ce485a0e2feda056497ba6 Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 9 Jun 2015 22:34:21 +0200 Subject: cleaned up and added config --- mainwindow.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 11 deletions(-) (limited to 'mainwindow.cpp') diff --git a/mainwindow.cpp b/mainwindow.cpp index e625d124..d9198efb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include #include @@ -37,8 +38,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); firstRun = true; startupPhase = true; - - initTrayIcon(); } /** @@ -180,6 +179,15 @@ bool MainWindow::checkConfig() { } } + useTrayIcon = settings.value("useTrayIcon").toBool(); + hideOnClose = settings.value("hideOnClose").toBool(); + + if (useTrayIcon && tray == NULL) { + initTrayIcon(); + } else if (!useTrayIcon && tray != NULL) { + destroyTrayIcon(); + } + firstRun = false; // TODO: this needs to be before we try to access the store, @@ -254,6 +262,8 @@ void MainWindow::config() { d->hidePassword(hidePassword); d->hideContent(hideContent); d->addGPGId(addGPGId); + d->useTrayIcon(useTrayIcon); + d->hideOnClose(hideOnClose); d->setProfiles(profiles, profile); d->wizard(); // does shit @@ -270,6 +280,8 @@ void MainWindow::config() { hidePassword = d->hidePassword(); hideContent = d->hideContent(); addGPGId = d->addGPGId(); + useTrayIcon = d->useTrayIcon(); + hideOnClose = d->hideOnClose(); profiles = d->getProfiles(); QSettings &settings(getSettings()); @@ -285,6 +297,9 @@ void MainWindow::config() { settings.setValue("hidePassword", hidePassword ? "true" : "false"); settings.setValue("hideContent", hideContent ? "true" : "false"); settings.setValue("addGPGId", addGPGId ? "true" : "false"); + settings.setValue("useTrayIcon", useTrayIcon ? "true" : "false"); + settings.setValue("hideOnClose", hideOnClose ? "true" : "false"); + if (!profiles.isEmpty()) { settings.beginGroup("profiles"); settings.remove(""); @@ -313,6 +328,11 @@ void MainWindow::config() { config(); } updateEnv(); + if (useTrayIcon && tray == NULL) { + initTrayIcon(); + } else if (!useTrayIcon && tray != NULL) { + destroyTrayIcon(); + } } firstRun = false; } @@ -1109,17 +1129,45 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore))); } +/** + * @brief MainWindow::initTrayIcon + */ void MainWindow::initTrayIcon() { - if(QSystemTrayIcon::isSystemTrayAvailable() == true) { - // Setup tray icon - this->tray = new trayIcon(this); + if(tray != NULL){ + qDebug() << "Creating tray icon again?"; + return; + } + if(QSystemTrayIcon::isSystemTrayAvailable() == true) { + // Setup tray icon + this->tray = new trayIcon(this); + if(tray == NULL){ + qDebug() << "Allocating tray icon failed."; + } + } else { + qDebug() << "No tray icon for this OS possibly also not show options?"; + } +} + +/** + * @brief MainWindow::destroyTrayIcon + */ +void MainWindow::destroyTrayIcon() +{ if(tray == NULL){ - qDebug() << "Allocating tray icon failed."; - exit(1); + qDebug() << "Destroy non existing tray icon?"; + return; + } + delete this->tray; + tray = NULL; +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (hideOnClose) { + this->hide(); + event->ignore(); + } else { + event->accept(); } - qDebug() << "Ehm.."; - } else { - qDebug() << "Whut?"; - } } -- cgit v1.2.3