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)
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
FILES_MATCHING PATTERN "application-x-keepassx.png" PATTERN "application-x-keepassx.svgz")
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");
}
QIcon FilePath::trayIconLocked()
{
return icon("apps", "keepassx-locked");
}
QIcon FilePath::trayIconUnlocked()
{
return applicationIcon();
}
QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme)
{
QString combinedName = category + "/" + name;

View File

@ -28,6 +28,8 @@ public:
QString dataPath(const QString& name);
QString pluginPath(const QString& name);
QIcon applicationIcon();
QIcon trayIconLocked();
QIcon trayIconUnlocked();
QIcon icon(const QString& category, const QString& name, bool fromTheme = true);
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(databaseChanged(Database*)), SLOT(changeDatabase(Database*)));
connect(dbStruct.dbWidget, SIGNAL(unlockedDatabase()), SLOT(updateTabNameFromDbWidgetSender()));
connect(dbStruct.dbWidget, SIGNAL(unlockedDatabase()), SLOT(emitDatabaseUnlockedFromDbWidgetSender()));
}
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
@ -706,6 +707,8 @@ void DatabaseTabWidget::lockDatabases()
dbWidget->lock();
// database has changed so we can't use the db variable anymore
updateTabName(dbWidget->database());
Q_EMIT databaseLocked(dbWidget);
}
}
@ -764,6 +767,11 @@ void DatabaseTabWidget::emitActivateDatabaseChanged()
Q_EMIT activateDatabaseChanged(currentDatabaseWidget());
}
void DatabaseTabWidget::emitDatabaseUnlockedFromDbWidgetSender()
{
Q_EMIT databaseUnlocked(static_cast<DatabaseWidget*>(sender()));
}
void DatabaseTabWidget::connectDatabase(Database* newDb, Database* oldDb)
{
if (oldDb) {

View File

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

View File

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

View File

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

View File

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