summaryrefslogtreecommitdiffstats
path: root/mainwindow.cpp
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2015-06-09 22:34:21 +0200
committerAnne Jan Brouwer <brouwer@annejan.com>2015-06-09 22:34:21 +0200
commit73e1bc69975c7ac948ce485a0e2feda056497ba6 (patch)
tree96236f6b138705850dd7eaefe7af7ca514a6bd6d /mainwindow.cpp
parenta259eed55ef0a8d0b3255a4be53f805aa1d859fd (diff)
cleaned up and added config
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r--mainwindow.cpp70
1 files changed, 59 insertions, 11 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp
index e625d124..d9198efb 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -11,6 +11,7 @@
#include <QTimer>
#include <QFileInfo>
#include <QQueue>
+#include <QCloseEvent>
#ifdef Q_OS_WIN
#include <windows.h>
#include <winnetwk.h>
@@ -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?";
- }
}