Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6432,6 +6432,10 @@ Expect some bugs and minor issues, this version is meant for testing purposes.</
<numerusform></numerusform>
</translation>
</message>
<message>
<source>Clear Clipboard</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ManageDatabase</name>
Expand Down
20 changes: 20 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,23 @@ MainWindow::MainWindow()
m_progressBarLabel = new QLabel(statusBar());
m_progressBarLabel->setVisible(false);
statusBar()->addPermanentWidget(m_progressBarLabel);

m_progressBar = new QProgressBar(statusBar());
m_progressBar->setVisible(false);
m_progressBar->setTextVisible(false);
m_progressBar->setMaximumWidth(100);
m_progressBar->setFixedHeight(15);
m_progressBar->setMaximum(100);
statusBar()->addPermanentWidget(m_progressBar);

m_clearClipboardButton = new QPushButton(statusBar());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how this is implemented in https://github.com/keepassxreboot/keepassxc/blob/develop/src/gui/PasswordWidget.cpp#L77 (it doesn't need a shortcut here at the moment, but one could be added in the future, or via the new shortcut editor).

Visually, I would suggest removing the button background and border, and placing the icon a bit closer to the progress bar (keep the margin, but reduce the padding). Using an Action icon like in the PasswordWidget may take care of that automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're saying, replace the QPushButton with a QAction instead?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think so

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QAction isn't working (it's not showing up), so I'll have to adjust the button styling instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with Qt myself, but Gemini gave me these instructions:

Because a QStatusBar primarily hosts widgets, you cannot add a QAction directly to it. Instead, you create a QToolButton (which is a specialized button for icons), associate your QAction with it, and then add that button to the status bar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I got something similar from Google as well. It recommended a QWidgetAction which I'll try as well. If neither works, I'll go back to styling the button. Or if @droidmonkey has any recommendations I can try those too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QToolButton is the right approach and you can style it to not have a border and background.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

m_clearClipboardButton->setText(tr("Clear Clipboard"));
m_clearClipboardButton->setObjectName("clearClipboardButton");
Comment thread
AgostonSzepessy marked this conversation as resolved.
m_clearClipboardButton->setVisible(false);
statusBar()->addPermanentWidget(m_clearClipboardButton);

connect(clipboard(), &Clipboard::updateCountdown, this, &MainWindow::updateProgressBar);
connect(m_clearClipboardButton.data(), &QPushButton::clicked, this, &MainWindow::clearClipboard);
m_actionMultiplexer.connect(SIGNAL(updateSyncProgress(int, QString)), this, SLOT(updateProgressBar(int, QString)));
m_actionMultiplexer.connect(SIGNAL(databaseSyncInProgress()), this, SLOT(disableMenuAndToolbar()));
m_actionMultiplexer.connect(SIGNAL(databaseSyncCompleted(QString)), this, SLOT(enableMenuAndToolbar()));
Expand Down Expand Up @@ -1535,6 +1544,11 @@ void MainWindow::clearSSHAgent()
#endif
}

void MainWindow::clearClipboard()
{
clipboard()->clearCopiedText();
}

void MainWindow::saveWindowInformation()
{
if (isVisible()) {
Expand Down Expand Up @@ -1633,11 +1647,17 @@ void MainWindow::updateProgressBar(int percentage, QString message)
if (percentage < 0) {
m_progressBar->setVisible(false);
m_progressBarLabel->setVisible(false);
m_clearClipboardButton->setVisible(false);
} else {
m_progressBar->setValue(percentage);
m_progressBar->setVisible(true);
m_progressBarLabel->setText(message);
m_progressBarLabel->setVisible(true);

Clipboard *cb = qobject_cast<Clipboard *>(sender());
if(cb) {
Comment thread
AgostonSzepessy marked this conversation as resolved.
Outdated
m_clearClipboardButton->setVisible(true);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QProgressBar>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QPushButton>

#include "core/SignalMultiplexer.h"
#include "gui/DatabaseWidget.h"
Expand Down Expand Up @@ -155,6 +156,7 @@ private slots:
void enableMenuAndToolbar();
void disableMenuAndToolbar();
void clearSSHAgent();
void clearClipboard();

private:
static const QString BaseWindowTitle;
Expand Down Expand Up @@ -190,6 +192,7 @@ private slots:
QPointer<QProgressBar> m_progressBar;
QPointer<QLabel> m_progressBarLabel;
QPointer<QLabel> m_statusBarLabel;
QPointer<QPushButton> m_clearClipboardButton;

Q_DISABLE_COPY(MainWindow)

Expand Down
20 changes: 20 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,26 @@ void TestGui::addCannedEntries()
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
}

void TestGui::testClearClipboard()
{
addCannedEntries();

EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QVERIFY(entryView->isVisible());

QClipboard* clipboard = QApplication::clipboard();

clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
QTRY_VERIFY(entryView->hasFocus());
QTest::keyClick(entryView, Qt::Key_C, Qt::ControlModifier);
QTRY_COMPARE(clipboard->text(), entryView->currentEntry()->password());

QPushButton *clearClipboardButton = m_mainWindow->findChild<QPushButton *>("clearClipboardButton");
QTRY_VERIFY(clearClipboardButton->isVisible());
clearClipboardButton->click();
QCOMPARE(clipboard->text(), QString());
}

void TestGui::checkDatabase(const QString& filePath, const QString& expectedDbName)
{
auto key = QSharedPointer<CompositeKey>::create();
Expand Down
1 change: 1 addition & 0 deletions tests/gui/TestGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private slots:
void testTrayRestoreHide();
void testShortcutConfig();
void testMenuActionStates();
void testClearClipboard();

private:
void addCannedEntries();
Expand Down
Loading