Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes to MainWindow and some cleanup #2402

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ parts:
- g++
- libgcrypt20-dev
- libqt5x11extras5-dev
- libqt5svg5-dev
- qtbase5-dev
- qtsvg5-dev
- qttools5-dev
- qttools5-dev-tools
- zlib1g-dev
Expand All @@ -59,6 +59,7 @@ parts:
- libsodium23
- libxtst6
- libqt5x11extras5
- libqt5svg5
- libusb-1.0-0
- qtwayland5
override-build: |
Expand Down
18 changes: 4 additions & 14 deletions src/core/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,10 @@ void bootstrapApplication()
void restoreMainWindowState(MainWindow& mainWindow)
{
// start minimized if configured
bool minimizeOnStartup = config()->get("GUI/MinimizeOnStartup").toBool();
bool minimizeToTray = config()->get("GUI/MinimizeToTray").toBool();
#ifndef Q_OS_LINUX
if (minimizeOnStartup) {
#else
// On some Linux systems, the window should NOT be minimized and hidden (i.e. not shown), at
// the same time (which would happen if both minimize on startup and minimize to tray are set)
// since otherwise it causes problems on restore as seen on issue #1595. Hiding it is enough.
if (minimizeOnStartup && !minimizeToTray) {
#endif
mainWindow.setWindowState(Qt::WindowMinimized);
}
if (!(minimizeOnStartup && minimizeToTray)) {
mainWindow.show();
if (config()->get("GUI/MinimizeOnStartup").toBool()) {
mainWindow.showMinimized();
} else {
mainWindow.bringToFront();
}

if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
Expand Down
5 changes: 2 additions & 3 deletions src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void ApplicationSettingsWidget::loadSettings()
m_generalUi->systrayShowCheckBox->setChecked(config()->get("GUI/ShowTrayIcon").toBool());
m_generalUi->systrayDarkIconCheckBox->setChecked(config()->get("GUI/DarkTrayIcon").toBool());
m_generalUi->systrayMinimizeToTrayCheckBox->setChecked(config()->get("GUI/MinimizeToTray").toBool());
m_generalUi->systrayMinimizeOnCloseCheckBox->setChecked(config()->get("GUI/MinimizeOnClose").toBool());
m_generalUi->minimizeOnCloseCheckBox->setChecked(config()->get("GUI/MinimizeOnClose").toBool());
m_generalUi->systrayMinimizeOnStartup->setChecked(config()->get("GUI/MinimizeOnStartup").toBool());
m_generalUi->autoTypeAskCheckBox->setChecked(config()->get("security/autotypeask").toBool());

Expand Down Expand Up @@ -235,7 +235,7 @@ void ApplicationSettingsWidget::saveSettings()
config()->set("GUI/ShowTrayIcon", m_generalUi->systrayShowCheckBox->isChecked());
config()->set("GUI/DarkTrayIcon", m_generalUi->systrayDarkIconCheckBox->isChecked());
config()->set("GUI/MinimizeToTray", m_generalUi->systrayMinimizeToTrayCheckBox->isChecked());
config()->set("GUI/MinimizeOnClose", m_generalUi->systrayMinimizeOnCloseCheckBox->isChecked());
config()->set("GUI/MinimizeOnClose", m_generalUi->minimizeOnCloseCheckBox->isChecked());
config()->set("GUI/MinimizeOnStartup", m_generalUi->systrayMinimizeOnStartup->isChecked());

config()->set("security/autotypeask", m_generalUi->autoTypeAskCheckBox->isChecked());
Expand Down Expand Up @@ -299,5 +299,4 @@ void ApplicationSettingsWidget::enableSystray(bool checked)
{
m_generalUi->systrayDarkIconCheckBox->setEnabled(checked);
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked);
}
115 changes: 43 additions & 72 deletions src/gui/ApplicationSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,56 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeOnCloseCheckBox">
<property name="text">
<string>Minimize instead of app exit</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="systrayShowCheckBox">
<property name="text">
<string>Show a system tray icon</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="systrayDarkIconCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Dark system tray icon</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="systraySettings" native="true">
<layout class="QVBoxLayout" name="systrayLayout">
Expand Down Expand Up @@ -250,78 +293,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="systrayMinimizeOnCloseCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Hide window to system tray instead of app exit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="systrayDarkIconCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Dark system tray icon</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
35 changes: 9 additions & 26 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
m_previewView->hide();
connect(this, SIGNAL(pressedEntry(Entry*)), m_previewView, SLOT(setEntry(Entry*)));
connect(this, SIGNAL(pressedGroup(Group*)), m_previewView, SLOT(setGroup(Group*)));
connect(this,
SIGNAL(currentModeChanged(DatabaseWidget::Mode)),
m_previewView,
SLOT(setDatabaseMode(DatabaseWidget::Mode)));
connect(this, SIGNAL(currentModeChanged(DatabaseWidget::Mode)),
m_previewView, SLOT(setDatabaseMode(DatabaseWidget::Mode)));
connect(m_previewView, SIGNAL(errorOccurred(QString)), this, SLOT(showErrorMessage(QString)));

auto* vLayout = new QVBoxLayout(rightHandSideWidget);
Expand All @@ -138,8 +136,6 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)

rightHandSideWidget->setLayout(vLayout);

setTabOrder(m_entryView, m_groupView);

m_mainSplitter->addWidget(m_groupView);
m_mainSplitter->addWidget(rightHandSideWidget);

Expand Down Expand Up @@ -1342,29 +1338,16 @@ QStringList DatabaseWidget::customEntryAttributes() const
}

/*
* Restores the focus on the group and entry that was focused
* before the database was locked or reloaded.
* Restores the focus on the group and entry provided
*/
void DatabaseWidget::restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& entryUuid)
{
Group* restoredGroup = nullptr;
const QList<Group*> groups = m_db->rootGroup()->groupsRecursive(true);
for (Group* group : groups) {
if (group->uuid() == groupUuid) {
restoredGroup = group;
break;
}
}

if (restoredGroup != nullptr) {
m_groupView->setCurrentGroup(restoredGroup);

const QList<Entry*> entries = restoredGroup->entries();
for (Entry* entry : entries) {
if (entry->uuid() == entryUuid) {
m_entryView->setCurrentEntry(entry);
break;
}
auto group = m_db->resolveGroup(groupUuid);
if (group) {
m_groupView->setCurrentGroup(group);
auto entry = group->findEntryByUuid(entryUuid);
if (entry) {
m_entryView->setCurrentEntry(entry);
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/gui/EntryPreviewWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<ui version="4.0">
<class>EntryPreviewWidget</class>
<widget class="QWidget" name="EntryPreviewWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<height>267</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>0</number>
Expand Down Expand Up @@ -107,6 +115,9 @@
</item>
<item>
<widget class="QToolButton" name="entryTotpButton">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Generate TOTP Token</string>
</property>
Expand All @@ -120,6 +131,9 @@
</item>
<item>
<widget class="QToolButton" name="entryCloseButton">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Close</string>
</property>
Expand All @@ -135,6 +149,9 @@
</item>
<item>
<widget class="QTabWidget" name="entryTabWidget">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
Expand Down Expand Up @@ -732,6 +749,13 @@
<header>gui/widgets/ElidedLabel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>entryTotpButton</tabstop>
<tabstop>entryAutotypeTree</tabstop>
<tabstop>entryTabWidget</tabstop>
<tabstop>groupCloseButton</tabstop>
<tabstop>groupTabWidget</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
46 changes: 37 additions & 9 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ MainWindow::MainWindow()
m_ui->actionEntryCopyURL->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_U);

new QShortcut(Qt::CTRL + Qt::Key_M, this, SLOT(showMinimized()));
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_M, this, SLOT(hideWindow()));
new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(selectNextDatabaseTab()));
new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(selectNextDatabaseTab()));
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab, this, SLOT(selectPreviousDatabaseTab()));
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(selectPreviousDatabaseTab()));

m_ui->actionDatabaseNew->setIcon(filePath()->icon("actions", "document-new"));
m_ui->actionDatabaseOpen->setIcon(filePath()->icon("actions", "document-open"));
Expand Down Expand Up @@ -697,6 +702,30 @@ void MainWindow::databaseStatusChanged(DatabaseWidget*)
updateTrayIcon();
}

void MainWindow::selectNextDatabaseTab()
{
if (m_ui->stackedWidget->currentIndex() == DatabaseTabScreen) {
int index = m_ui->tabWidget->currentIndex() + 1;
if (index >= m_ui->tabWidget->count()) {
m_ui->tabWidget->setCurrentIndex(0);
} else {
m_ui->tabWidget->setCurrentIndex(index);
}
}
}

void MainWindow::selectPreviousDatabaseTab()
{
if (m_ui->stackedWidget->currentIndex() == DatabaseTabScreen) {
int index = m_ui->tabWidget->currentIndex() - 1;
if (index < 0) {
m_ui->tabWidget->setCurrentIndex(m_ui->tabWidget->count() - 1);
} else {
m_ui->tabWidget->setCurrentIndex(index);
}
}
}

void MainWindow::databaseTabChanged(int tabIndex)
{
if (tabIndex != -1 && m_ui->stackedWidget->currentIndex() == WelcomeScreen) {
Expand All @@ -716,15 +745,9 @@ void MainWindow::closeEvent(QCloseEvent* event)
return;
}

bool minimizeOnClose = isTrayIconEnabled() && config()->get("GUI/MinimizeOnClose").toBool();
if (minimizeOnClose && !m_appExitCalled) {
event->accept();
if (config()->get("GUI/MinimizeOnClose").toBool() && !m_appExitCalled) {
event->ignore();
hideWindow();

if (config()->get("security/lockdatabaseminimize").toBool()) {
m_ui->tabWidget->lockDatabases();
}

return;
}

Expand Down Expand Up @@ -908,7 +931,12 @@ void MainWindow::hideWindow()
// TODO: Add an explanation for why this is also not done on Mac (or remove the check)
setWindowState(windowState() | Qt::WindowMinimized);
#endif
QTimer::singleShot(0, this, SLOT(hide()));
// Only hide if tray icon is active, otherwise window will be gone forever
if (isTrayIconEnabled()) {
hide();
} else {
showMinimized();
}

if (config()->get("security/lockdatabaseminimize").toBool()) {
m_ui->tabWidget->lockDatabases();
Expand Down
Loading