summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2015-06-10 01:00:44 +0200
committerAnne Jan Brouwer <brouwer@annejan.com>2015-06-10 01:00:44 +0200
commit183f5afb2c6339e78b67d2021af8b0b2b01a8b96 (patch)
tree6a729ad4e751a81cf6b9d30bac49d0d356985800
parenta105aa525e79ec79fbc7831f5980e2bc2b732c6e (diff)
parentca2886d6a84529f7f0d801e4104c77f5e62b5fb3 (diff)
merged featuresv0.8.3
-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--qtpass.pro6
-rw-r--r--trayicon.cpp84
-rw-r--r--trayicon.h39
8 files changed, 273 insertions, 3 deletions
diff --git a/dialog.cpp b/dialog.cpp
index 999378b2..4b7de9a7 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 7736dfc1..c106c09a 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>
@@ -178,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,
@@ -257,6 +267,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
@@ -273,6 +285,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());
@@ -288,6 +302,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("");
@@ -323,6 +340,11 @@ void MainWindow::config() {
} else {
ui->pushButton->show();
ui->updateButton->show();
+ }
+ if (useTrayIcon && tray == NULL) {
+ initTrayIcon();
+ } else if (!useTrayIcon && tray != NULL) {
+ destroyTrayIcon();
}
}
firstRun = false;
@@ -1119,3 +1141,51 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name)
ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore)));
}
+
+/**
+ * @brief MainWindow::initTrayIcon
+ */
+void MainWindow::initTrayIcon()
+{
+ 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() << "Destroy non existing tray icon?";
+ return;
+ }
+ delete this->tray;
+ tray = NULL;
+}
+
+/**
+ * @brief MainWindow::closeEvent
+ * @param event
+ */
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if (hideOnClose) {
+ this->hide();
+ event->ignore();
+ } else {
+ event->accept();
+ }
+}
+
diff --git a/mainwindow.h b/mainwindow.h
index 5aafd89c..e8960ef9 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -8,6 +8,7 @@
#include <QQueue>
#include <QSettings>
#include "storemodel.h"
+#include "trayicon.h"
#if SINGLE_APP
#include "singleapplication.h"
#else
@@ -46,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();
@@ -102,6 +106,9 @@ private:
QHash<QString, QString> profiles;
QString profile;
bool startupPhase;
+ trayIcon *tray = NULL;
+ bool useTrayIcon;
+ bool hideOnClose;
void updateText();
void executePass(QString, QString = QString());
void executeWrapper(QString, QString, QString = QString());
@@ -119,6 +126,8 @@ private:
void mountWebDav();
void updateEnv();
void updateProfileBox();
+ void initTrayIcon();
+ void destroyTrayIcon();
};
#endif // MAINWINDOW_H
diff --git a/qtpass.pro b/qtpass.pro
index 50881eb3..e9f668aa 100644
--- a/qtpass.pro
+++ b/qtpass.pro
@@ -29,7 +29,8 @@ SOURCES += main.cpp\
util.cpp \
usersdialog.cpp \
keygendialog.cpp \
- progressindicator.cpp
+ progressindicator.cpp \
+ trayicon.cpp
HEADERS += mainwindow.h \
dialog.h \
@@ -37,7 +38,8 @@ HEADERS += mainwindow.h \
util.h \
usersdialog.h \
keygendialog.h \
- progressindicator.h
+ progressindicator.h \
+ trayicon.h
FORMS += mainwindow.ui \
dialog.ui \
diff --git a/trayicon.cpp b/trayicon.cpp
new file mode 100644
index 00000000..8dace210
--- /dev/null
+++ b/trayicon.cpp
@@ -0,0 +1,84 @@
+#include "trayicon.h"
+
+trayIcon::trayIcon(QMainWindow *parent)
+{
+ parentwin = parent;
+
+ createActions();
+ createTrayIcon();
+
+ sysTrayIcon->setIcon(QIcon(":/artwork/icon.png"));
+
+ sysTrayIcon->show();
+
+ QObject::connect(sysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+
+}
+
+void trayIcon::setVisible(bool visible)
+{
+ if(visible == true) {
+ parentwin->show();
+ } else {
+ parentwin->hide();
+ }
+}
+
+void trayIcon::createActions()
+{
+// 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()));
+
+// 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()));
+}
+
+
+void trayIcon::createTrayIcon()
+{
+ trayIconMenu = new QMenu(this);
+// trayIconMenu->addAction(minimizeAction);
+// trayIconMenu->addAction(maximizeAction);
+// trayIconMenu->addAction(restoreAction);
+// trayIconMenu->addSeparator();
+ trayIconMenu->addAction(quitAction);
+
+ sysTrayIcon = new QSystemTrayIcon(this);
+ sysTrayIcon->setContextMenu(trayIconMenu);
+}
+
+void trayIcon::showHideParent()
+{
+ if(parentwin->isVisible() == true) {
+ parentwin->hide();
+ } else {
+ parentwin->show();
+ }
+}
+
+void trayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+ switch (reason) {
+ case QSystemTrayIcon::Trigger:
+ case QSystemTrayIcon::DoubleClick:
+ showHideParent();
+ break;
+ case QSystemTrayIcon::MiddleClick:
+ showMessage("test", "test msg", 1000);
+ break;
+ default:
+ ;
+ }
+}
+
+void trayIcon::showMessage(QString title, QString msg, int time)
+{
+ sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
+}
diff --git a/trayicon.h b/trayicon.h
new file mode 100644
index 00000000..3ad4f00d
--- /dev/null
+++ b/trayicon.h
@@ -0,0 +1,39 @@
+#ifndef TRAYICON_H
+#define TRAYICON_H
+
+#include <QApplication>
+#include <QMenu>
+#include <QAction>
+#include <QMainWindow>
+#include <QSystemTrayIcon>
+#include <QWidget>
+
+class trayIcon : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit trayIcon(QMainWindow *parent);
+ void showMessage(QString title, QString msg, int time);
+ void setVisible(bool visible);
+
+signals:
+
+public slots:
+ void showHideParent();
+ void iconActivated(QSystemTrayIcon::ActivationReason reason);
+
+private:
+ void createActions();
+ void createTrayIcon();
+
+// QAction *minimizeAction;
+// QAction *maximizeAction;
+// QAction *restoreAction;
+ QAction *quitAction;
+
+ QSystemTrayIcon *sysTrayIcon;
+ QMenu *trayIconMenu;
+ QMainWindow *parentwin;
+};
+
+#endif // TRAYICON_H