2010-09-19 10:59:32 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MainWindow.h"
|
2011-12-26 12:55:50 -05:00
|
|
|
#include "ui_MainWindow.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QShortcut>
|
2015-09-27 17:16:18 -04:00
|
|
|
#include <QTimer>
|
2012-04-11 14:35:52 -04:00
|
|
|
|
2012-07-14 13:09:28 -04:00
|
|
|
#include "autotype/AutoType.h"
|
|
|
|
#include "core/Config.h"
|
2012-07-18 14:44:28 -04:00
|
|
|
#include "core/FilePath.h"
|
2014-01-07 15:56:58 -05:00
|
|
|
#include "core/InactivityTimer.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
#include "core/Metadata.h"
|
2012-05-02 09:37:21 -04:00
|
|
|
#include "gui/AboutDialog.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "gui/DatabaseWidget.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
|
2012-08-01 04:40:18 -04:00
|
|
|
const QString MainWindow::BaseWindowTitle = "KeePassX";
|
|
|
|
|
2010-09-19 10:59:32 -04:00
|
|
|
MainWindow::MainWindow()
|
2011-12-26 12:55:50 -05:00
|
|
|
: m_ui(new Ui::MainWindow())
|
2014-11-02 04:15:44 -05:00
|
|
|
, m_trayIcon(Q_NULLPTR)
|
2010-09-19 10:59:32 -04:00
|
|
|
{
|
2011-12-26 12:55:50 -05:00
|
|
|
m_ui->setupUi(this);
|
2010-09-19 10:59:32 -04:00
|
|
|
|
2014-05-15 12:05:58 -04:00
|
|
|
m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size();
|
|
|
|
|
2014-05-17 05:38:48 -04:00
|
|
|
restoreGeometry(config()->get("GUI/MainWindowGeometry").toByteArray());
|
2014-03-22 07:21:49 -04:00
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
setWindowIcon(filePath()->applicationIcon());
|
2012-06-24 18:21:22 -04:00
|
|
|
QAction* toggleViewAction = m_ui->toolBar->toggleViewAction();
|
|
|
|
toggleViewAction->setText(tr("Show toolbar"));
|
|
|
|
m_ui->menuView->addAction(toggleViewAction);
|
2012-08-15 13:50:31 -04:00
|
|
|
bool showToolbar = config()->get("ShowToolbar").toBool();
|
|
|
|
m_ui->toolBar->setVisible(showToolbar);
|
|
|
|
connect(m_ui->toolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveToolbarState(bool)));
|
2012-01-05 16:27:08 -05:00
|
|
|
|
2012-07-23 15:12:19 -04:00
|
|
|
m_clearHistoryAction = new QAction("Clear history", m_ui->menuFile);
|
|
|
|
m_lastDatabasesActions = new QActionGroup(m_ui->menuRecentDatabases);
|
|
|
|
connect(m_clearHistoryAction, SIGNAL(triggered()), this, SLOT(clearLastDatabases()));
|
|
|
|
connect(m_lastDatabasesActions, SIGNAL(triggered(QAction*)), this, SLOT(openRecentDatabase(QAction*)));
|
|
|
|
connect(m_ui->menuRecentDatabases, SIGNAL(aboutToShow()), this, SLOT(updateLastDatabasesMenu()));
|
|
|
|
|
2012-10-23 18:15:23 -04:00
|
|
|
m_copyAdditionalAttributeActions = new QActionGroup(m_ui->menuEntryCopyAttribute);
|
|
|
|
m_actionMultiplexer.connect(m_copyAdditionalAttributeActions, SIGNAL(triggered(QAction*)),
|
|
|
|
SLOT(copyAttribute(QAction*)));
|
|
|
|
connect(m_ui->menuEntryCopyAttribute, SIGNAL(aboutToShow()),
|
|
|
|
this, SLOT(updateCopyAttributesMenu()));
|
|
|
|
|
2012-07-14 13:09:28 -04:00
|
|
|
Qt::Key globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
|
|
|
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
|
|
|
|
config()->get("GlobalAutoTypeModifiers").toInt());
|
|
|
|
if (globalAutoTypeKey > 0 && globalAutoTypeModifiers > 0) {
|
|
|
|
autoType()->registerGlobalShortcut(globalAutoTypeKey, globalAutoTypeModifiers);
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:12:10 -04:00
|
|
|
m_ui->actionEntryAutoType->setVisible(autoType()->isAvailable());
|
|
|
|
|
2014-01-07 15:56:58 -05:00
|
|
|
m_inactivityTimer = new InactivityTimer(this);
|
|
|
|
connect(m_inactivityTimer, SIGNAL(inactivityDetected()),
|
2015-07-13 15:17:11 -04:00
|
|
|
this, SLOT(lockDatabasesAfterInactivity()));
|
2014-01-07 15:56:58 -05:00
|
|
|
applySettingsChanges();
|
|
|
|
|
2012-05-15 12:16:04 -04:00
|
|
|
setShortcut(m_ui->actionDatabaseOpen, QKeySequence::Open, Qt::CTRL + Qt::Key_O);
|
|
|
|
setShortcut(m_ui->actionDatabaseSave, QKeySequence::Save, Qt::CTRL + Qt::Key_S);
|
|
|
|
setShortcut(m_ui->actionDatabaseSaveAs, QKeySequence::SaveAs);
|
|
|
|
setShortcut(m_ui->actionDatabaseClose, QKeySequence::Close, Qt::CTRL + Qt::Key_W);
|
2012-10-12 06:12:00 -04:00
|
|
|
m_ui->actionLockDatabases->setShortcut(Qt::CTRL + Qt::Key_L);
|
2012-05-15 12:16:04 -04:00
|
|
|
setShortcut(m_ui->actionQuit, QKeySequence::Quit, Qt::CTRL + Qt::Key_Q);
|
2012-05-19 05:53:32 -04:00
|
|
|
setShortcut(m_ui->actionSearch, QKeySequence::Find, Qt::CTRL + Qt::Key_F);
|
2012-07-23 15:43:46 -04:00
|
|
|
m_ui->actionEntryNew->setShortcut(Qt::CTRL + Qt::Key_N);
|
|
|
|
m_ui->actionEntryEdit->setShortcut(Qt::CTRL + Qt::Key_E);
|
|
|
|
m_ui->actionEntryDelete->setShortcut(Qt::CTRL + Qt::Key_D);
|
|
|
|
m_ui->actionEntryClone->setShortcut(Qt::CTRL + Qt::Key_K);
|
2012-05-26 10:20:32 -04:00
|
|
|
m_ui->actionEntryCopyUsername->setShortcut(Qt::CTRL + Qt::Key_B);
|
|
|
|
m_ui->actionEntryCopyPassword->setShortcut(Qt::CTRL + Qt::Key_C);
|
2012-07-12 16:35:51 -04:00
|
|
|
setShortcut(m_ui->actionEntryAutoType, QKeySequence::Paste, Qt::CTRL + Qt::Key_V);
|
2012-07-27 12:38:52 -04:00
|
|
|
m_ui->actionEntryOpenUrl->setShortcut(Qt::CTRL + Qt::Key_U);
|
2015-06-12 22:29:02 -04:00
|
|
|
m_ui->actionEntryCopyURL->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_U);
|
2012-05-15 12:16:04 -04:00
|
|
|
|
2012-08-31 05:22:59 -04:00
|
|
|
new QShortcut(Qt::CTRL + Qt::Key_M, this, SLOT(showMinimized()));
|
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionDatabaseNew->setIcon(filePath()->icon("actions", "document-new"));
|
|
|
|
m_ui->actionDatabaseOpen->setIcon(filePath()->icon("actions", "document-open"));
|
|
|
|
m_ui->actionDatabaseSave->setIcon(filePath()->icon("actions", "document-save"));
|
|
|
|
m_ui->actionDatabaseSaveAs->setIcon(filePath()->icon("actions", "document-save-as"));
|
|
|
|
m_ui->actionDatabaseClose->setIcon(filePath()->icon("actions", "document-close"));
|
|
|
|
m_ui->actionChangeDatabaseSettings->setIcon(filePath()->icon("actions", "document-edit"));
|
|
|
|
m_ui->actionChangeMasterKey->setIcon(filePath()->icon("actions", "database-change-key", false));
|
2012-10-12 06:12:00 -04:00
|
|
|
m_ui->actionLockDatabases->setIcon(filePath()->icon("actions", "document-encrypt", false));
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionQuit->setIcon(filePath()->icon("actions", "application-exit"));
|
2012-05-27 09:39:32 -04:00
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionEntryNew->setIcon(filePath()->icon("actions", "entry-new", false));
|
|
|
|
m_ui->actionEntryClone->setIcon(filePath()->icon("actions", "entry-clone", false));
|
|
|
|
m_ui->actionEntryEdit->setIcon(filePath()->icon("actions", "entry-edit", false));
|
|
|
|
m_ui->actionEntryDelete->setIcon(filePath()->icon("actions", "entry-delete", false));
|
2013-03-22 14:51:39 -04:00
|
|
|
m_ui->actionEntryAutoType->setIcon(filePath()->icon("actions", "auto-type", false));
|
2014-01-14 13:46:44 -05:00
|
|
|
m_ui->actionEntryCopyUsername->setIcon(filePath()->icon("actions", "username-copy", false));
|
|
|
|
m_ui->actionEntryCopyPassword->setIcon(filePath()->icon("actions", "password-copy", false));
|
2012-05-27 06:46:22 -04:00
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionGroupNew->setIcon(filePath()->icon("actions", "group-new", false));
|
|
|
|
m_ui->actionGroupEdit->setIcon(filePath()->icon("actions", "group-edit", false));
|
|
|
|
m_ui->actionGroupDelete->setIcon(filePath()->icon("actions", "group-delete", false));
|
2012-05-27 09:39:32 -04:00
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionSettings->setIcon(filePath()->icon("actions", "configure"));
|
2012-05-27 09:39:32 -04:00
|
|
|
|
2012-07-18 14:44:28 -04:00
|
|
|
m_ui->actionAbout->setIcon(filePath()->icon("actions", "help-about"));
|
2012-05-27 13:54:18 -04:00
|
|
|
|
2014-11-18 21:46:38 -05:00
|
|
|
m_ui->actionSearch->setIcon(filePath()->icon("actions", "system-search"));
|
2012-05-27 06:46:22 -04:00
|
|
|
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(SIGNAL(currentModeChanged(DatabaseWidget::Mode)),
|
|
|
|
this, SLOT(setMenuActionState(DatabaseWidget::Mode)));
|
|
|
|
m_actionMultiplexer.connect(SIGNAL(groupChanged()),
|
|
|
|
this, SLOT(setMenuActionState()));
|
|
|
|
m_actionMultiplexer.connect(SIGNAL(entrySelectionChanged()),
|
|
|
|
this, SLOT(setMenuActionState()));
|
|
|
|
m_actionMultiplexer.connect(SIGNAL(groupContextMenuRequested(QPoint)),
|
|
|
|
this, SLOT(showGroupContextMenu(QPoint)));
|
|
|
|
m_actionMultiplexer.connect(SIGNAL(entryContextMenuRequested(QPoint)),
|
|
|
|
this, SLOT(showEntryContextMenu(QPoint)));
|
|
|
|
|
2012-04-25 14:22:55 -04:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(tabNameChanged()),
|
|
|
|
SLOT(updateWindowTitle()));
|
|
|
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
SLOT(updateWindowTitle()));
|
2012-05-28 12:49:16 -04:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
SLOT(databaseTabChanged(int)));
|
2012-08-01 04:35:37 -04:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
SLOT(setMenuActionState()));
|
2012-05-27 05:09:52 -04:00
|
|
|
connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(setMenuActionState()));
|
2012-11-01 19:41:34 -04:00
|
|
|
connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle()));
|
2012-05-27 14:29:15 -04:00
|
|
|
connect(m_ui->settingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToDatabases()));
|
2014-01-07 15:56:58 -05:00
|
|
|
connect(m_ui->settingsWidget, SIGNAL(accepted()), SLOT(applySettingsChanges()));
|
2011-12-30 12:43:24 -05:00
|
|
|
|
2012-04-25 14:22:55 -04:00
|
|
|
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(newDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(openDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(saveDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(saveDatabaseAs()));
|
|
|
|
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(closeDatabase()));
|
|
|
|
connect(m_ui->actionChangeMasterKey, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(changeMasterKey()));
|
|
|
|
connect(m_ui->actionChangeDatabaseSettings, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(changeDatabaseSettings()));
|
2012-05-12 04:08:41 -04:00
|
|
|
connect(m_ui->actionImportKeePass1, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(importKeePass1Database()));
|
2015-07-14 16:14:34 -04:00
|
|
|
connect(m_ui->actionExportCsv, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(exportToCsv()));
|
2012-10-12 06:12:00 -04:00
|
|
|
connect(m_ui->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget,
|
|
|
|
SLOT(lockDatabases()));
|
2012-05-12 04:08:41 -04:00
|
|
|
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
|
|
|
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryNew, SIGNAL(triggered()),
|
2012-04-25 14:22:55 -04:00
|
|
|
SLOT(createEntry()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryClone, SIGNAL(triggered()),
|
2012-05-15 15:10:39 -04:00
|
|
|
SLOT(cloneEntry()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryEdit, SIGNAL(triggered()),
|
|
|
|
SLOT(switchToEntryEdit()));
|
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()),
|
2013-10-08 15:36:01 -04:00
|
|
|
SLOT(deleteEntries()));
|
2013-12-01 03:43:41 -05:00
|
|
|
|
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryCopyTitle, SIGNAL(triggered()),
|
|
|
|
SLOT(copyTitle()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()),
|
2012-05-26 10:20:32 -04:00
|
|
|
SLOT(copyUsername()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()),
|
2012-05-26 10:20:32 -04:00
|
|
|
SLOT(copyPassword()));
|
2013-12-01 03:43:41 -05:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryCopyURL, SIGNAL(triggered()),
|
|
|
|
SLOT(copyURL()));
|
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryCopyNotes, SIGNAL(triggered()),
|
|
|
|
SLOT(copyNotes()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryAutoType, SIGNAL(triggered()),
|
2012-07-12 16:35:51 -04:00
|
|
|
SLOT(performAutoType()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionEntryOpenUrl, SIGNAL(triggered()),
|
2012-07-27 12:38:52 -04:00
|
|
|
SLOT(openUrl()));
|
2012-05-12 04:08:41 -04:00
|
|
|
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionGroupNew, SIGNAL(triggered()),
|
2012-04-25 14:22:55 -04:00
|
|
|
SLOT(createGroup()));
|
2012-08-01 04:35:37 -04:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionGroupEdit, SIGNAL(triggered()),
|
|
|
|
SLOT(switchToGroupEdit()));
|
|
|
|
m_actionMultiplexer.connect(m_ui->actionGroupDelete, SIGNAL(triggered()),
|
2012-04-25 14:22:55 -04:00
|
|
|
SLOT(deleteGroup()));
|
2012-05-19 05:53:32 -04:00
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
connect(m_ui->actionSettings, SIGNAL(triggered()), SLOT(switchToSettings()));
|
|
|
|
|
|
|
|
connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog()));
|
|
|
|
|
2014-11-18 02:26:04 -05:00
|
|
|
m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()),
|
|
|
|
SLOT(openSearch()));
|
2014-11-02 04:15:44 -05:00
|
|
|
|
|
|
|
updateTrayIcon();
|
2011-12-26 12:55:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2010-09-19 10:59:32 -04:00
|
|
|
}
|
2011-11-16 12:47:17 -05:00
|
|
|
|
2012-08-01 04:40:18 -04:00
|
|
|
void MainWindow::updateLastDatabasesMenu()
|
|
|
|
{
|
2012-07-23 15:12:19 -04:00
|
|
|
m_ui->menuRecentDatabases->clear();
|
|
|
|
|
|
|
|
QStringList lastDatabases = config()->get("LastDatabases", QVariant()).toStringList();
|
|
|
|
Q_FOREACH (const QString& database, lastDatabases) {
|
|
|
|
QAction* action = m_ui->menuRecentDatabases->addAction(database);
|
|
|
|
m_lastDatabasesActions->addAction(action);
|
|
|
|
}
|
|
|
|
m_ui->menuRecentDatabases->addSeparator();
|
|
|
|
m_ui->menuRecentDatabases->addAction(m_clearHistoryAction);
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:15:23 -04:00
|
|
|
void MainWindow::updateCopyAttributesMenu()
|
|
|
|
{
|
|
|
|
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
2012-11-10 12:46:01 -05:00
|
|
|
if (!dbWidget) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-22 07:07:06 -04:00
|
|
|
|
2014-06-16 09:40:28 -04:00
|
|
|
if (dbWidget->numberOfSelectedEntries() != 1) {
|
2012-11-10 12:46:01 -05:00
|
|
|
return;
|
|
|
|
}
|
2012-10-23 18:15:23 -04:00
|
|
|
|
2013-12-01 09:41:26 -05:00
|
|
|
QList<QAction*> actions = m_ui->menuEntryCopyAttribute->actions();
|
2014-10-09 15:36:08 -04:00
|
|
|
for (int i = m_countDefaultAttributes; i < actions.size(); i++) {
|
2013-12-01 09:41:26 -05:00
|
|
|
delete actions[i];
|
2013-11-30 10:05:10 -05:00
|
|
|
}
|
|
|
|
|
2014-05-15 12:05:58 -04:00
|
|
|
Q_FOREACH (const QString& key, dbWidget->customEntryAttributes()) {
|
2012-10-23 18:15:23 -04:00
|
|
|
QAction* action = m_ui->menuEntryCopyAttribute->addAction(key);
|
|
|
|
m_copyAdditionalAttributeActions->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-23 15:12:19 -04:00
|
|
|
void MainWindow::openRecentDatabase(QAction* action)
|
|
|
|
{
|
|
|
|
openDatabase(action->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::clearLastDatabases()
|
|
|
|
{
|
|
|
|
config()->set("LastDatabases", QVariant());
|
|
|
|
}
|
|
|
|
|
2012-04-24 05:47:16 -04:00
|
|
|
void MainWindow::openDatabase(const QString& fileName, const QString& pw, const QString& keyFile)
|
|
|
|
{
|
|
|
|
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);
|
|
|
|
}
|
|
|
|
|
2012-04-24 19:32:05 -04:00
|
|
|
void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
2012-05-27 05:09:52 -04:00
|
|
|
bool inDatabaseTabWidget = (m_ui->stackedWidget->currentIndex() == 0);
|
2012-05-27 14:06:03 -04:00
|
|
|
bool inWelcomeWidget = (m_ui->stackedWidget->currentIndex() == 2);
|
2012-05-27 05:09:52 -04:00
|
|
|
|
|
|
|
if (inDatabaseTabWidget && m_ui->tabWidget->currentIndex() != -1) {
|
2012-04-16 15:28:49 -04:00
|
|
|
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
|
|
|
Q_ASSERT(dbWidget);
|
|
|
|
|
2012-04-24 19:32:05 -04:00
|
|
|
if (mode == DatabaseWidget::None) {
|
|
|
|
mode = dbWidget->currentMode();
|
2012-04-16 15:28:49 -04:00
|
|
|
}
|
|
|
|
|
2012-04-24 19:32:05 -04:00
|
|
|
switch (mode) {
|
2012-05-25 07:32:37 -04:00
|
|
|
case DatabaseWidget::ViewMode: {
|
2012-08-01 04:35:37 -04:00
|
|
|
bool inSearch = dbWidget->isInSearchMode();
|
2014-05-15 12:05:58 -04:00
|
|
|
bool singleEntrySelected = dbWidget->numberOfSelectedEntries() == 1;
|
|
|
|
bool entriesSelected = dbWidget->numberOfSelectedEntries() > 0;
|
|
|
|
bool groupSelected = dbWidget->isGroupSelected();
|
2012-08-01 04:35:37 -04:00
|
|
|
|
|
|
|
m_ui->actionEntryNew->setEnabled(!inSearch);
|
|
|
|
m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch);
|
|
|
|
m_ui->actionEntryEdit->setEnabled(singleEntrySelected);
|
2013-10-08 15:36:01 -04:00
|
|
|
m_ui->actionEntryDelete->setEnabled(entriesSelected);
|
2015-05-12 15:54:39 -04:00
|
|
|
m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTitle());
|
|
|
|
m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUsername());
|
|
|
|
m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected && dbWidget->currentEntryHasPassword());
|
|
|
|
m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl());
|
2015-06-05 12:37:22 -04:00
|
|
|
m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected && dbWidget->currentEntryHasNotes());
|
2012-10-23 18:15:23 -04:00
|
|
|
m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);
|
2012-08-01 04:35:37 -04:00
|
|
|
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected);
|
2015-05-12 15:54:39 -04:00
|
|
|
m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl());
|
2012-08-01 04:35:37 -04:00
|
|
|
m_ui->actionGroupNew->setEnabled(groupSelected);
|
|
|
|
m_ui->actionGroupEdit->setEnabled(groupSelected);
|
2014-05-15 16:56:36 -04:00
|
|
|
m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup());
|
2012-05-26 13:40:02 -04:00
|
|
|
// TODO: get checked state from db widget
|
2014-11-18 02:26:04 -05:00
|
|
|
m_ui->actionSearch->setEnabled(true);
|
2012-04-25 14:22:55 -04:00
|
|
|
m_ui->actionChangeMasterKey->setEnabled(true);
|
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(true);
|
|
|
|
m_ui->actionDatabaseSave->setEnabled(true);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(true);
|
2015-07-14 16:14:34 -04:00
|
|
|
m_ui->actionExportCsv->setEnabled(true);
|
2012-04-25 14:22:55 -04:00
|
|
|
break;
|
2012-05-25 07:32:37 -04:00
|
|
|
}
|
2012-04-25 14:22:55 -04:00
|
|
|
case DatabaseWidget::EditMode:
|
2012-10-12 06:12:00 -04:00
|
|
|
case DatabaseWidget::LockedMode:
|
2012-08-01 04:35:37 -04:00
|
|
|
Q_FOREACH (QAction* action, m_ui->menuEntries->actions()) {
|
|
|
|
action->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
|
|
|
action->setEnabled(false);
|
|
|
|
}
|
2014-05-03 02:28:56 -04:00
|
|
|
m_ui->actionEntryCopyTitle->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyUsername->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyPassword->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyURL->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyNotes->setEnabled(false);
|
2012-10-23 18:15:23 -04:00
|
|
|
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
2012-08-01 04:35:37 -04:00
|
|
|
|
2012-05-19 05:53:32 -04:00
|
|
|
m_ui->actionSearch->setEnabled(false);
|
2012-04-25 14:22:55 -04:00
|
|
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
|
|
|
m_ui->actionDatabaseSave->setEnabled(false);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
2015-07-14 16:14:34 -04:00
|
|
|
m_ui->actionExportCsv->setEnabled(false);
|
2012-04-25 14:22:55 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
}
|
|
|
|
m_ui->actionDatabaseClose->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
2012-08-01 04:35:37 -04:00
|
|
|
Q_FOREACH (QAction* action, m_ui->menuEntries->actions()) {
|
|
|
|
action->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
|
|
|
action->setEnabled(false);
|
|
|
|
}
|
2014-05-03 02:28:56 -04:00
|
|
|
m_ui->actionEntryCopyTitle->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyUsername->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyPassword->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyURL->setEnabled(false);
|
|
|
|
m_ui->actionEntryCopyNotes->setEnabled(false);
|
2012-10-23 18:15:23 -04:00
|
|
|
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
2012-08-01 04:35:37 -04:00
|
|
|
|
2012-05-19 05:53:32 -04:00
|
|
|
m_ui->actionSearch->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
2012-04-19 10:20:20 -04:00
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionDatabaseSave->setEnabled(false);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
|
|
|
|
|
|
|
m_ui->actionDatabaseClose->setEnabled(false);
|
2015-07-14 16:14:34 -04:00
|
|
|
m_ui->actionExportCsv->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
}
|
2012-05-27 05:09:52 -04:00
|
|
|
|
2012-07-23 17:50:17 -04:00
|
|
|
bool inDatabaseTabWidgetOrWelcomeWidget = inDatabaseTabWidget || inWelcomeWidget;
|
|
|
|
m_ui->actionDatabaseNew->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
|
|
|
|
m_ui->actionDatabaseOpen->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
|
|
|
|
m_ui->menuRecentDatabases->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
|
|
|
|
m_ui->actionImportKeePass1->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
|
2012-10-12 06:12:00 -04:00
|
|
|
|
|
|
|
m_ui->actionLockDatabases->setEnabled(m_ui->tabWidget->hasLockableDatabases());
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
2012-04-11 14:35:52 -04:00
|
|
|
|
2012-04-21 16:02:12 -04:00
|
|
|
void MainWindow::updateWindowTitle()
|
|
|
|
{
|
2012-11-01 20:00:50 -04:00
|
|
|
QString customWindowTitlePart;
|
2012-11-01 19:41:34 -04:00
|
|
|
int stackedWidgetIndex = m_ui->stackedWidget->currentIndex();
|
2012-11-01 20:00:50 -04:00
|
|
|
int tabWidgetIndex = m_ui->tabWidget->currentIndex();
|
|
|
|
if (stackedWidgetIndex == 0 && tabWidgetIndex != -1) {
|
|
|
|
customWindowTitlePart = m_ui->tabWidget->tabText(tabWidgetIndex);
|
|
|
|
if (m_ui->tabWidget->readOnly(tabWidgetIndex)) {
|
2012-11-02 05:15:37 -04:00
|
|
|
customWindowTitlePart.append(QString(" [%1]").arg(tr("read-only")));
|
2012-05-28 12:38:33 -04:00
|
|
|
}
|
2012-11-01 19:41:34 -04:00
|
|
|
} else if (stackedWidgetIndex == 1) {
|
2012-11-01 20:00:50 -04:00
|
|
|
customWindowTitlePart = tr("Settings");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString windowTitle;
|
|
|
|
if (customWindowTitlePart.isEmpty()) {
|
2012-11-01 19:41:34 -04:00
|
|
|
windowTitle = BaseWindowTitle;
|
2012-11-01 20:00:50 -04:00
|
|
|
} else {
|
2012-11-02 05:15:37 -04:00
|
|
|
windowTitle = QString("%1 - %2").arg(customWindowTitlePart, BaseWindowTitle);
|
2012-04-21 16:02:12 -04:00
|
|
|
}
|
2012-11-01 19:41:34 -04:00
|
|
|
|
|
|
|
setWindowTitle(windowTitle);
|
2012-04-21 16:02:12 -04:00
|
|
|
}
|
|
|
|
|
2012-05-02 09:37:21 -04:00
|
|
|
void MainWindow::showAboutDialog()
|
|
|
|
{
|
|
|
|
AboutDialog* aboutDialog = new AboutDialog(this);
|
|
|
|
aboutDialog->show();
|
|
|
|
}
|
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
void MainWindow::switchToDatabases()
|
|
|
|
{
|
2012-05-30 09:17:51 -04:00
|
|
|
if (m_ui->tabWidget->currentIndex() == -1) {
|
|
|
|
m_ui->stackedWidget->setCurrentIndex(2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->stackedWidget->setCurrentIndex(0);
|
|
|
|
}
|
2012-05-27 05:09:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::switchToSettings()
|
|
|
|
{
|
|
|
|
m_ui->settingsWidget->loadSettings();
|
|
|
|
m_ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
}
|
|
|
|
|
2012-05-28 12:49:16 -04:00
|
|
|
void MainWindow::databaseTabChanged(int tabIndex)
|
|
|
|
{
|
|
|
|
if (tabIndex != -1 && m_ui->stackedWidget->currentIndex() == 2) {
|
2012-05-30 09:17:51 -04:00
|
|
|
m_ui->stackedWidget->setCurrentIndex(0);
|
2012-05-28 12:49:16 -04:00
|
|
|
}
|
2012-05-28 12:53:39 -04:00
|
|
|
else if (tabIndex == -1 && m_ui->stackedWidget->currentIndex() == 0) {
|
|
|
|
m_ui->stackedWidget->setCurrentIndex(2);
|
|
|
|
}
|
2012-08-01 04:35:37 -04:00
|
|
|
|
|
|
|
m_actionMultiplexer.setCurrentObject(m_ui->tabWidget->currentDatabaseWidget());
|
2012-05-28 12:49:16 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:22:07 -04:00
|
|
|
void MainWindow::closeEvent(QCloseEvent* event)
|
2014-03-22 07:21:49 -04:00
|
|
|
{
|
2014-03-22 07:53:42 -04:00
|
|
|
bool accept = saveLastDatabases();
|
|
|
|
|
|
|
|
if (accept) {
|
2014-03-24 14:58:31 -04:00
|
|
|
saveWindowInformation();
|
|
|
|
|
2014-03-22 07:53:42 -04:00
|
|
|
event->accept();
|
2014-11-02 04:15:44 -05:00
|
|
|
QApplication::quit();
|
2014-03-22 07:53:42 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
2014-03-22 07:21:49 -04:00
|
|
|
}
|
|
|
|
|
2014-11-02 04:15:44 -05:00
|
|
|
void MainWindow::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if ((event->type() == QEvent::WindowStateChange) && isMinimized()
|
|
|
|
&& isTrayIconEnabled() && config()->get("GUI/MinimizeToTray").toBool())
|
|
|
|
{
|
|
|
|
event->ignore();
|
2015-09-27 17:16:18 -04:00
|
|
|
QTimer::singleShot(0, this, SLOT(hide()));
|
2014-11-02 04:15:44 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
QMainWindow::changeEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-22 07:53:42 -04:00
|
|
|
void MainWindow::saveWindowInformation()
|
2012-06-29 18:22:07 -04:00
|
|
|
{
|
2014-05-17 05:38:48 -04:00
|
|
|
config()->set("GUI/MainWindowGeometry", saveGeometry());
|
2014-03-22 07:53:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::saveLastDatabases()
|
|
|
|
{
|
|
|
|
bool accept;
|
2013-04-27 05:20:13 -04:00
|
|
|
m_openDatabases.clear();
|
2013-04-18 16:15:01 -04:00
|
|
|
bool openPreviousDatabasesOnStartup = config()->get("OpenPreviousDatabasesOnStartup").toBool();
|
|
|
|
|
|
|
|
if (openPreviousDatabasesOnStartup) {
|
2013-10-13 12:08:50 -04:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(databaseWithFileClosed(QString)),
|
|
|
|
this, SLOT(rememberOpenDatabases(QString)));
|
2013-04-18 16:15:01 -04:00
|
|
|
}
|
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
if (!m_ui->tabWidget->closeAllDatabases()) {
|
2014-03-22 07:53:42 -04:00
|
|
|
accept = false;
|
2012-04-11 14:35:52 -04:00
|
|
|
}
|
|
|
|
else {
|
2014-03-22 07:53:42 -04:00
|
|
|
accept = true;
|
2012-04-11 14:35:52 -04:00
|
|
|
}
|
2013-04-18 16:15:01 -04:00
|
|
|
|
|
|
|
if (openPreviousDatabasesOnStartup) {
|
2013-10-13 12:08:50 -04:00
|
|
|
disconnect(m_ui->tabWidget, SIGNAL(databaseWithFileClosed(QString)),
|
|
|
|
this, SLOT(rememberOpenDatabases(QString)));
|
2013-04-27 05:20:13 -04:00
|
|
|
config()->set("LastOpenedDatabases", m_openDatabases);
|
2013-03-24 18:21:59 -04:00
|
|
|
}
|
2012-05-15 12:16:04 -04:00
|
|
|
|
2014-03-22 07:53:42 -04:00
|
|
|
return accept;
|
2014-03-22 07:21:49 -04:00
|
|
|
}
|
|
|
|
|
2014-11-02 04:15:44 -05:00
|
|
|
void MainWindow::updateTrayIcon()
|
|
|
|
{
|
|
|
|
if (isTrayIconEnabled()) {
|
|
|
|
if (!m_trayIcon) {
|
|
|
|
m_trayIcon = new QSystemTrayIcon(filePath()->applicationIcon(), this);
|
|
|
|
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
|
|
|
|
|
|
QAction* actionToggle = new QAction(tr("Toggle window"), menu);
|
|
|
|
menu->addAction(actionToggle);
|
|
|
|
|
|
|
|
menu->addAction(m_ui->actionQuit);
|
|
|
|
|
|
|
|
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
SLOT(trayIconTriggered(QSystemTrayIcon::ActivationReason)));
|
|
|
|
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
|
|
|
|
|
|
|
|
m_trayIcon->setContextMenu(menu);
|
|
|
|
m_trayIcon->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (m_trayIcon) {
|
2015-07-19 15:14:08 -04:00
|
|
|
m_trayIcon->hide();
|
2014-11-02 04:15:44 -05:00
|
|
|
delete m_trayIcon;
|
|
|
|
m_trayIcon = Q_NULLPTR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 04:35:37 -04:00
|
|
|
void MainWindow::showEntryContextMenu(const QPoint& globalPos)
|
|
|
|
{
|
|
|
|
m_ui->menuEntries->popup(globalPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showGroupContextMenu(const QPoint& globalPos)
|
|
|
|
{
|
|
|
|
m_ui->menuGroups->popup(globalPos);
|
|
|
|
}
|
|
|
|
|
2012-08-15 13:50:31 -04:00
|
|
|
void MainWindow::saveToolbarState(bool value)
|
|
|
|
{
|
|
|
|
config()->set("ShowToolbar", value);
|
|
|
|
}
|
|
|
|
|
2012-05-15 12:16:04 -04:00
|
|
|
void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback)
|
|
|
|
{
|
|
|
|
if (!QKeySequence::keyBindings(standard).isEmpty()) {
|
|
|
|
action->setShortcuts(standard);
|
|
|
|
}
|
|
|
|
else if (fallback != 0) {
|
|
|
|
action->setShortcut(QKeySequence(fallback));
|
|
|
|
}
|
|
|
|
}
|
2013-03-24 18:21:59 -04:00
|
|
|
|
2013-04-27 05:20:13 -04:00
|
|
|
void MainWindow::rememberOpenDatabases(const QString& filePath)
|
2013-03-24 18:21:59 -04:00
|
|
|
{
|
2013-04-27 05:20:13 -04:00
|
|
|
m_openDatabases.append(filePath);
|
2013-03-24 18:21:59 -04:00
|
|
|
}
|
2014-01-07 15:56:58 -05:00
|
|
|
|
|
|
|
void MainWindow::applySettingsChanges()
|
|
|
|
{
|
|
|
|
int timeout = config()->get("security/lockdatabaseidlesec").toInt() * 1000;
|
|
|
|
if (timeout <= 0) {
|
|
|
|
timeout = 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_inactivityTimer->setInactivityTimeout(timeout);
|
|
|
|
if (config()->get("security/lockdatabaseidle").toBool()) {
|
|
|
|
m_inactivityTimer->activate();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_inactivityTimer->deactivate();
|
|
|
|
}
|
2014-11-02 04:15:44 -05:00
|
|
|
|
|
|
|
updateTrayIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
{
|
|
|
|
if (reason == QSystemTrayIcon::Trigger) {
|
|
|
|
toggleWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::toggleWindow()
|
|
|
|
{
|
2015-10-10 05:22:17 -04:00
|
|
|
if ((QApplication::activeWindow() == this) && isVisible() && !isMinimized()) {
|
2014-11-02 04:15:44 -05:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
else {
|
2015-10-10 05:22:17 -04:00
|
|
|
ensurePolished();
|
2015-09-27 17:16:18 -04:00
|
|
|
setWindowState(windowState() & ~Qt::WindowMinimized);
|
2014-11-02 04:15:44 -05:00
|
|
|
show();
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:17:11 -04:00
|
|
|
void MainWindow::lockDatabasesAfterInactivity()
|
|
|
|
{
|
|
|
|
// ignore event if a modal dialog is open (such as a message box or file dialog)
|
|
|
|
if (QApplication::activeModalWidget()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ui->tabWidget->lockDatabases();
|
|
|
|
}
|
|
|
|
|
2014-11-02 04:15:44 -05:00
|
|
|
bool MainWindow::isTrayIconEnabled() const
|
|
|
|
{
|
|
|
|
return config()->get("GUI/ShowTrayIcon").toBool()
|
|
|
|
&& QSystemTrayIcon::isSystemTrayAvailable();
|
2014-01-07 15:56:58 -05:00
|
|
|
}
|