Skip to content

Commit

Permalink
Add search help pop-up
Browse files Browse the repository at this point in the history
* Support ! modifier (same as '-')
* Create reusable PopupHelpWidget as self-contained popup that can
be positioned around a parent widget and will follow the movement
and sizing of the window
* Eliminated KEEPASSXC_MAIN_WINDOW macro and replaced with
getMainWindow() function
* Add tests to cover search help show/hide
  • Loading branch information
droidmonkey committed Nov 17, 2018
1 parent d6ffee5 commit 880c3ae
Show file tree
Hide file tree
Showing 20 changed files with 671 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ set(keepassx_SOURCES
gui/UnlockDatabaseWidget.cpp
gui/UnlockDatabaseDialog.cpp
gui/WelcomeWidget.cpp
gui/widgets/ElidedLabel.cpp
gui/csvImport/CsvImportWidget.cpp
gui/csvImport/CsvImportWizard.cpp
gui/csvImport/CsvParserModel.cpp
Expand Down Expand Up @@ -154,6 +153,8 @@ set(keepassx_SOURCES
gui/dbsettings/DatabaseSettingsWidgetEncryption.cpp
gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp
gui/settings/SettingsWidget.cpp
gui/widgets/ElidedLabel.cpp
gui/widgets/PopupHelpWidget.cpp
gui/wizard/NewDatabaseWizard.cpp
gui/wizard/NewDatabaseWizardPage.cpp
gui/wizard/NewDatabaseWizardPageMetaData.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool BrowserService::openDatabase(bool triggerUnlock)
}

if (triggerUnlock) {
KEEPASSXC_MAIN_WINDOW->bringToFront();
getMainWindow()->bringToFront();
m_bringToFrontRequested = true;
}

Expand Down Expand Up @@ -901,7 +901,7 @@ void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget)
{
if (dbWidget) {
if (m_bringToFrontRequested) {
KEEPASSXC_MAIN_WINDOW->lower();
getMainWindow()->lower();
m_bringToFrontRequested = false;
}
emit databaseUnlocked();
Expand Down
3 changes: 2 additions & 1 deletion src/core/EntrySearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ bool EntrySearcher::searchEntryImpl(const QString& searchString, Entry* entry)
found = !attachments.filter(term->regex).empty();
break;
default:
// Terms without a specific field try to match title, username, url, and notes
found = term->regex.match(entry->resolvePlaceholder(entry->title())).hasMatch() ||
term->regex.match(entry->resolvePlaceholder(entry->username())).hasMatch() ||
term->regex.match(entry->resolvePlaceholder(entry->url())).hasMatch() ||
Expand Down Expand Up @@ -139,7 +140,7 @@ QList<QSharedPointer<EntrySearcher::SearchTerm> > EntrySearcher::parseSearchTerm
term->regex = Tools::convertToRegex(term->word, !mods.contains("*"), mods.contains("+"), m_caseSensitive);

// Exclude modifier
term->exclude = mods.contains("-");
term->exclude = mods.contains("-") || mods.contains("!");

// Determine the field to search
QString field = result.captured(2);
Expand Down
11 changes: 0 additions & 11 deletions src/gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace

Application::Application(int& argc, char** argv)
: QApplication(argc, argv)
, m_mainWindow(nullptr)
#ifdef Q_OS_UNIX
, m_unixSignalNotifier(nullptr)
#endif
Expand Down Expand Up @@ -143,16 +142,6 @@ Application::~Application()
}
}

QWidget* Application::mainWindow() const
{
return m_mainWindow;
}

void Application::setMainWindow(QWidget* mainWindow)
{
m_mainWindow = mainWindow;
}

bool Application::event(QEvent* event)
{
// Handle Apple QFileOpenEvent from finder (double click on .kdbx file)
Expand Down
4 changes: 0 additions & 4 deletions src/gui/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class Application : public QApplication

public:
Application(int& argc, char** argv);
QWidget* mainWindow() const;
~Application() override;
void setMainWindow(QWidget* mainWindow);

bool event(QEvent* event) override;
bool isAlreadyRunning() const;
Expand All @@ -60,8 +58,6 @@ private slots:
void socketReadyRead();

private:
QWidget* m_mainWindow;

#if defined(Q_OS_UNIX)
/**
* Register Unix signals such as SIGINT and SIGTERM for clean shutdown.
Expand Down
5 changes: 5 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ class BrowserPlugin : public ISettingsPage

const QString MainWindow::BaseWindowTitle = "KeePassXC";

MainWindow* g_MainWindow = nullptr;
MainWindow* getMainWindow() { return g_MainWindow; }

MainWindow::MainWindow()
: m_ui(new Ui::MainWindow())
, m_trayIcon(nullptr)
, m_appExitCalled(false)
, m_appExiting(false)
{
g_MainWindow = this;

m_ui->setupUi(this);

#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
Expand Down
10 changes: 7 additions & 3 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ private slots:
bool m_appExiting;
};

#define KEEPASSXC_MAIN_WINDOW \
(qobject_cast<Application*>(qApp) ? qobject_cast<MainWindow*>(qobject_cast<Application*>(qApp)->mainWindow()) \
: nullptr)
/**
* Return instance of MainWindow created on app load
* non-gui instances will return nullptr
*
* @return MainWindow instance or nullptr
*/
MainWindow* getMainWindow();

#endif // KEEPASSX_MAINWINDOW_H
Loading

0 comments on commit 880c3ae

Please sign in to comment.