Merge pull request #46 from keepassxreboot/feature/trayicon-#37

Show locked tray icon when database is locked
This commit is contained in:
Jonathan White 2016-10-19 22:45:56 -04:00 committed by GitHub
commit 62cfbf73e1
16 changed files with 43 additions and 2 deletions

View File

@ -21,7 +21,7 @@ install(FILES ${DATABASE_ICONS} DESTINATION ${DATA_INSTALL_DIR}/icons/database)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "keepassx.png" PATTERN "keepassx.svgz") FILES_MATCHING PATTERN "keepassx*.png" PATTERN "keepassx*.svgz")
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "application-x-keepassx.png" PATTERN "application-x-keepassx.svgz") FILES_MATCHING PATTERN "application-x-keepassx.png" PATTERN "application-x-keepassx.svgz")
install(FILES linux/keepassx.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) install(FILES linux/keepassx.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -90,6 +90,16 @@ QIcon FilePath::applicationIcon()
return icon("apps", "keepassx"); return icon("apps", "keepassx");
} }
QIcon FilePath::trayIconLocked()
{
return icon("apps", "keepassx-locked");
}
QIcon FilePath::trayIconUnlocked()
{
return applicationIcon();
}
QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme) QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme)
{ {
QString combinedName = category + "/" + name; QString combinedName = category + "/" + name;

View File

@ -28,6 +28,8 @@ public:
QString dataPath(const QString& name); QString dataPath(const QString& name);
QString pluginPath(const QString& name); QString pluginPath(const QString& name);
QIcon applicationIcon(); QIcon applicationIcon();
QIcon trayIconLocked();
QIcon trayIconUnlocked();
QIcon icon(const QString& category, const QString& name, bool fromTheme = true); QIcon icon(const QString& category, const QString& name, bool fromTheme = true);
QIcon onOffIcon(const QString& category, const QString& name); QIcon onOffIcon(const QString& category, const QString& name);

View File

@ -610,6 +610,7 @@ void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabaseFromSender())); connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabaseFromSender()));
connect(dbStruct.dbWidget, SIGNAL(databaseChanged(Database*)), SLOT(changeDatabase(Database*))); connect(dbStruct.dbWidget, SIGNAL(databaseChanged(Database*)), SLOT(changeDatabase(Database*)));
connect(dbStruct.dbWidget, SIGNAL(unlockedDatabase()), SLOT(updateTabNameFromDbWidgetSender())); connect(dbStruct.dbWidget, SIGNAL(unlockedDatabase()), SLOT(updateTabNameFromDbWidgetSender()));
connect(dbStruct.dbWidget, SIGNAL(unlockedDatabase()), SLOT(emitDatabaseUnlockedFromDbWidgetSender()));
} }
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget() DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
@ -706,6 +707,8 @@ void DatabaseTabWidget::lockDatabases()
dbWidget->lock(); dbWidget->lock();
// database has changed so we can't use the db variable anymore // database has changed so we can't use the db variable anymore
updateTabName(dbWidget->database()); updateTabName(dbWidget->database());
Q_EMIT databaseLocked(dbWidget);
} }
} }
@ -764,6 +767,11 @@ void DatabaseTabWidget::emitActivateDatabaseChanged()
Q_EMIT activateDatabaseChanged(currentDatabaseWidget()); Q_EMIT activateDatabaseChanged(currentDatabaseWidget());
} }
void DatabaseTabWidget::emitDatabaseUnlockedFromDbWidgetSender()
{
Q_EMIT databaseUnlocked(static_cast<DatabaseWidget*>(sender()));
}
void DatabaseTabWidget::connectDatabase(Database* newDb, Database* oldDb) void DatabaseTabWidget::connectDatabase(Database* newDb, Database* oldDb)
{ {
if (oldDb) { if (oldDb) {

View File

@ -80,6 +80,8 @@ Q_SIGNALS:
void tabNameChanged(); void tabNameChanged();
void databaseWithFileClosed(QString filePath); void databaseWithFileClosed(QString filePath);
void activateDatabaseChanged(DatabaseWidget* dbWidget); void activateDatabaseChanged(DatabaseWidget* dbWidget);
void databaseLocked(DatabaseWidget* dbWidget);
void databaseUnlocked(DatabaseWidget* dbWidget);
private Q_SLOTS: private Q_SLOTS:
void updateTabName(Database* db); void updateTabName(Database* db);
@ -89,6 +91,7 @@ private Q_SLOTS:
void toggleTabbar(); void toggleTabbar();
void changeDatabase(Database* newDb); void changeDatabase(Database* newDb);
void emitActivateDatabaseChanged(); void emitActivateDatabaseChanged();
void emitDatabaseUnlockedFromDbWidgetSender();
private: private:
bool saveDatabase(Database* db); bool saveDatabase(Database* db);

View File

@ -658,6 +658,7 @@ void DatabaseWidget::openDatabase(bool accepted)
if (accepted) { if (accepted) {
replaceDatabase(static_cast<DatabaseOpenWidget*>(sender())->database()); replaceDatabase(static_cast<DatabaseOpenWidget*>(sender())->database());
setCurrentWidget(m_mainWidget); setCurrentWidget(m_mainWidget);
Q_EMIT unlockedDatabase();
// We won't need those anymore and KeePass1OpenWidget closes // We won't need those anymore and KeePass1OpenWidget closes
// the file in its dtor. // the file in its dtor.

View File

@ -185,6 +185,10 @@ MainWindow::MainWindow()
SLOT(databaseTabChanged(int))); SLOT(databaseTabChanged(int)));
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), connect(m_ui->tabWidget, SIGNAL(currentChanged(int)),
SLOT(setMenuActionState())); SLOT(setMenuActionState()));
connect(m_ui->tabWidget, SIGNAL(databaseLocked(DatabaseWidget*)),
SLOT(databaseStatusChanged(DatabaseWidget*)));
connect(m_ui->tabWidget, SIGNAL(databaseUnlocked(DatabaseWidget*)),
SLOT(databaseStatusChanged(DatabaseWidget*)));
connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(setMenuActionState())); connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(setMenuActionState()));
connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle())); connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle()));
connect(m_ui->settingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToDatabases())); connect(m_ui->settingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToDatabases()));
@ -486,6 +490,11 @@ void MainWindow::switchToSettings()
m_ui->stackedWidget->setCurrentIndex(1); m_ui->stackedWidget->setCurrentIndex(1);
} }
void MainWindow::databaseStatusChanged(DatabaseWidget *)
{
updateTrayIcon();
}
void MainWindow::databaseTabChanged(int tabIndex) void MainWindow::databaseTabChanged(int tabIndex)
{ {
if (tabIndex != -1 && m_ui->stackedWidget->currentIndex() == 2) { if (tabIndex != -1 && m_ui->stackedWidget->currentIndex() == 2) {
@ -573,7 +582,7 @@ void MainWindow::updateTrayIcon()
{ {
if (isTrayIconEnabled()) { if (isTrayIconEnabled()) {
if (!m_trayIcon) { if (!m_trayIcon) {
m_trayIcon = new QSystemTrayIcon(filePath()->applicationIcon(), this); m_trayIcon = new QSystemTrayIcon(this);
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
@ -587,8 +596,15 @@ void MainWindow::updateTrayIcon()
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow())); connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
m_trayIcon->setContextMenu(menu); m_trayIcon->setContextMenu(menu);
m_trayIcon->setIcon(filePath()->applicationIcon());
m_trayIcon->show(); m_trayIcon->show();
} }
if (m_ui->tabWidget->hasLockableDatabases()) {
m_trayIcon->setIcon(filePath()->trayIconUnlocked());
}
else {
m_trayIcon->setIcon(filePath()->trayIconLocked());
}
} }
else { else {
if (m_trayIcon) { if (m_trayIcon) {

View File

@ -54,6 +54,7 @@ private Q_SLOTS:
void showAboutDialog(); void showAboutDialog();
void switchToDatabases(); void switchToDatabases();
void switchToSettings(); void switchToSettings();
void databaseStatusChanged(DatabaseWidget *dbWidget);
void databaseTabChanged(int tabIndex); void databaseTabChanged(int tabIndex);
void openRecentDatabase(QAction* action); void openRecentDatabase(QAction* action);
void clearLastDatabases(); void clearLastDatabases();