summaryrefslogtreecommitdiffstats
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
commitaa7b5eb10ba0bd024d972b2c0486d04e2362b98b (patch)
tree96236f6b138705850dd7eaefe7af7ca514a6bd6d
parent305627d005bfea0e45428c75c7794464a21e2183 (diff)
cleaned up and added config
-rw-r--r--dialog.cpp47
-rw-r--r--dialog.h5
-rw-r--r--dialog.ui16
-rw-r--r--mainwindow.cpp70
-rw-r--r--mainwindow.h9
-rw-r--r--trayicon.cpp20
-rw-r--r--trayicon.h6
7 files changed, 146 insertions, 27 deletions
diff --git a/dialog.cpp b/dialog.cpp
index da65c069..e5ae51ea 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -536,3 +536,50 @@ void Dialog::wizard()
//ui->gpgPath->setText(gpg);
}
+
+/**
+ * @brief Dialog::useTrayIcon
+ * @return
+ */
+bool Dialog::useTrayIcon() {
+ return ui->checkBoxUseTrayIcon->isChecked();
+}
+
+/**
+ * @brief Dialog::hideOnClose
+ * @return
+ */
+bool Dialog::hideOnClose() {
+ return ui->checkBoxHideOnClose->isEnabled() && ui->checkBoxHideOnClose->isChecked();
+}
+
+/**
+ * @brief Dialog::useTrayIcon
+ * @param useSystray
+ */
+void Dialog::useTrayIcon(bool useSystray) {
+ ui->checkBoxUseTrayIcon->setChecked(useSystray);
+ ui->checkBoxHideOnClose->setEnabled(useSystray);
+ if (!useSystray) {
+ ui->checkBoxHideOnClose->setChecked(false);
+ }
+}
+
+/**
+ * @brief Dialog::hideOnClose
+ * @param hideOnClose
+ */
+void Dialog::hideOnClose(bool hideOnClose) {
+ ui->checkBoxHideOnClose->setChecked(hideOnClose);
+}
+
+/**
+ * @brief Dialog::on_checkBoxUseTrayIcon_clicked
+ */
+void Dialog::on_checkBoxUseTrayIcon_clicked() {
+ if (ui->checkBoxUseTrayIcon->isChecked()) {
+ ui->checkBoxHideOnClose->setEnabled(true);
+ } else {
+ ui->checkBoxHideOnClose->setEnabled(false);
+ }
+}
diff --git a/dialog.h b/dialog.h
index 9499c3ea..c5a5ae73 100644
--- a/dialog.h
+++ b/dialog.h
@@ -46,6 +46,10 @@ public:
bool addGPGId();
void wizard();
void genKey(QString, QDialog *);
+ bool useTrayIcon();
+ bool hideOnClose();
+ void useTrayIcon(bool);
+ void hideOnClose(bool);
private slots:
void on_radioButtonNative_clicked();
@@ -59,6 +63,7 @@ private slots:
void on_addButton_clicked();
void on_profileTable_currentItemChanged(QTableWidgetItem*);
void on_deleteButton_clicked();
+ void on_checkBoxUseTrayIcon_clicked();
private:
QScopedPointer<Ui::Dialog> ui;
diff --git a/dialog.ui b/dialog.ui
index b69b56e9..a1168261 100644
--- a/dialog.ui
+++ b/dialog.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>491</width>
+ <width>495</width>
<height>501</height>
</rect>
</property>
@@ -269,6 +269,20 @@
</item>
</layout>
</item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="checkBoxUseTrayIcon">
+ <property name="text">
+ <string>Use TrayIcon</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="checkBoxHideOnClose">
+ <property name="text">
+ <string>Hide on close</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
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?";
- }
}
diff --git a/mainwindow.h b/mainwindow.h
index dbef6d5f..e8960ef9 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -47,6 +47,9 @@ public:
void genKey(QString, QDialog *);
void userDialog(QString = "");
+protected:
+ void closeEvent(QCloseEvent *event);
+
private slots:
void on_updateButton_clicked();
void on_pushButton_clicked();
@@ -103,7 +106,9 @@ private:
QHash<QString, QString> profiles;
QString profile;
bool startupPhase;
- trayIcon *tray;
+ trayIcon *tray = NULL;
+ bool useTrayIcon;
+ bool hideOnClose;
void updateText();
void executePass(QString, QString = QString());
void executeWrapper(QString, QString, QString = QString());
@@ -122,7 +127,7 @@ private:
void updateEnv();
void updateProfileBox();
void initTrayIcon();
-
+ void destroyTrayIcon();
};
#endif // MAINWINDOW_H
diff --git a/trayicon.cpp b/trayicon.cpp
index ed6bf4b8..8dace210 100644
--- a/trayicon.cpp
+++ b/trayicon.cpp
@@ -27,14 +27,14 @@ void trayIcon::setVisible(bool visible)
void trayIcon::createActions()
{
- minimizeAction = new QAction(tr("Mi&nimize"), this);
- connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
+// minimizeAction = new QAction(tr("Mi&nimize"), this);
+// connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
- maximizeAction = new QAction(tr("Ma&ximize"), this);
- connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
+// maximizeAction = new QAction(tr("Ma&ximize"), this);
+// connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
- restoreAction = new QAction(tr("&Restore"), this);
- connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
+// restoreAction = new QAction(tr("&Restore"), this);
+// connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
@@ -44,10 +44,10 @@ void trayIcon::createActions()
void trayIcon::createTrayIcon()
{
trayIconMenu = new QMenu(this);
- trayIconMenu->addAction(minimizeAction);
- trayIconMenu->addAction(maximizeAction);
- trayIconMenu->addAction(restoreAction);
- trayIconMenu->addSeparator();
+// trayIconMenu->addAction(minimizeAction);
+// trayIconMenu->addAction(maximizeAction);
+// trayIconMenu->addAction(restoreAction);
+// trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
sysTrayIcon = new QSystemTrayIcon(this);
diff --git a/trayicon.h b/trayicon.h
index 3daa8dfe..3ad4f00d 100644
--- a/trayicon.h
+++ b/trayicon.h
@@ -26,9 +26,9 @@ private:
void createActions();
void createTrayIcon();
- QAction *minimizeAction;
- QAction *maximizeAction;
- QAction *restoreAction;
+// QAction *minimizeAction;
+// QAction *maximizeAction;
+// QAction *restoreAction;
QAction *quitAction;
QSystemTrayIcon *sysTrayIcon;