Skip to content

Commit

Permalink
Show KeePassHTTP deprecation notice three times and use MessageWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
phoerious committed Jan 19, 2018
1 parent 30f77b0 commit a6fd52d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/browser/BrowserOptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BrowserOptionDialog::BrowserOptionDialog(QWidget* parent) :
connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys()));
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));

m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning);
m_ui->warningWidget->showMessage(tr("<b>Warning:</b> The following options can be dangerous!"), MessageWidget::Warning);
m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(-1);

Expand Down
27 changes: 7 additions & 20 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QMimeData>
#include <QShortcut>
#include <QTimer>
#include <QDesktopServices>

#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS)
#include <QList>
Expand Down Expand Up @@ -78,7 +77,7 @@ class HttpPlugin: public ISettingsPage

QString name() override
{
return QObject::tr("Browser Integration (old)");
return QObject::tr("Legacy Browser Integration");
}

QIcon icon() override
Expand Down Expand Up @@ -196,7 +195,7 @@ MainWindow::MainWindow()

setWindowIcon(filePath()->applicationIcon());
m_ui->globalMessageWidget->setHidden(true);
connect(m_ui->globalMessageWidget, SIGNAL(linkActivated(const QString&)), this, SLOT(openLink(const QString&)));
connect(m_ui->globalMessageWidget, &MessageWidget::linkActivated, &MessageWidget::openHttpUrl);
connect(m_ui->globalMessageWidget, SIGNAL(showAnimationStarted()), m_ui->globalMessageWidgetContainer, SLOT(show()));
connect(m_ui->globalMessageWidget, SIGNAL(hideAnimationFinished()), m_ui->globalMessageWidgetContainer, SLOT(hide()));

Expand Down Expand Up @@ -412,7 +411,7 @@ MainWindow::MainWindow()
tr("Access error for config file %1").arg(config()->getFileName()), MessageWidget::Error);
}
#ifdef WITH_XC_HTTP
if (config()->get("Http/Enabled", false).toBool() && !config()->get("Http/DeprecationNoticeShown", false).toBool()) {
if (config()->get("Http/Enabled", false).toBool() && config()->get("Http/DeprecationNoticeShown", 0).toInt() < 3) {
// show message after tab widget dismissed all messages
connect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(showKeePassHTTPDeprecationNotice()));
}
Expand All @@ -425,30 +424,18 @@ MainWindow::~MainWindow()

void MainWindow::showKeePassHTTPDeprecationNotice()
{
int warningNum = config()->get("Http/DeprecationNoticeShown", 0).toInt();
displayGlobalMessage(tr("<p>It looks like you are using KeePassHTTP for browser integration. "
"This feature has been deprecated and will be removed in the future.<br>"
"Please switch to keepassxc-browser instead! For help with migration, "
"Please switch to KeePassXC-Browser instead! For help with migration, "
"visit our <a class=\"link\" href=\"https://keepassxc.org/docs/keepassxc-browser-migration\">"
"keepassxc-browser migration guide</a>.</p>"),
"migration guide</a> (warning %1 of 3).</p>").arg(warningNum + 1),
MessageWidget::Warning, true, -1);

// config()->set("Http/DeprecationNoticeShown", true);
config()->set("Http/DeprecationNoticeShown", warningNum + 1);
disconnect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(showKeePassHTTPDeprecationNotice()));
}

/**
* Open a link using the system's default handler.
* Links that are not HTTP(s) links are ignored.
*
* @param link link URL
*/
void MainWindow::openLink(const QString& link)
{
if (link.startsWith("http://") || link.startsWith("https://")) {
QDesktopServices::openUrl(QUrl(link));
}
}

void MainWindow::appExit()
{
m_appExitCalled = true;
Expand Down
1 change: 0 additions & 1 deletion src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private slots:
void hideTabMessage();
void handleScreenLock();
void showKeePassHTTPDeprecationNotice();
void openLink(const QString& link);

private:
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
Expand Down
17 changes: 16 additions & 1 deletion src/gui/MessageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#include "MessageWidget.h"

#include "QTimer"
#include <QTimer>
#include <QDesktopServices>
#include <QUrl>

const int MessageWidget::DefaultAutoHideTimeout = 6000;
const int MessageWidget::DisableAutoHide = -1;
Expand Down Expand Up @@ -69,3 +71,16 @@ void MessageWidget::setAutoHideTimeout(int autoHideTimeout)
m_autoHideTimer->stop();
}
}

/**
* Open a link using the system's default handler.
* Links that are not HTTP(S) links are ignored.
*
* @param link link URL
*/
void MessageWidget::openHttpUrl(const QString& link)
{
if (link.startsWith("http://") || link.startsWith("https://")) {
QDesktopServices::openUrl(QUrl(link));
}
}
1 change: 1 addition & 0 deletions src/gui/MessageWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public slots:
void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout);
void hideMessage();
void setAutoHideTimeout(int autoHideTimeout);
static void openHttpUrl(QString const& url);

private:
QTimer* m_autoHideTimer;
Expand Down
10 changes: 8 additions & 2 deletions src/http/OptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ OptionDialog::OptionDialog(QWidget *parent) :
connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys()));
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));

m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning);
m_ui->warningWidget->showMessage(tr("<b>Warning:</b> The following options can be dangerous!"), MessageWidget::Warning);
m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(MessageWidget::DisableAutoHide);

m_ui->tabWidget->setEnabled(m_ui->enableHttpServer->isChecked());
connect(m_ui->enableHttpServer, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool)));

m_ui->deprecationNotice->setOpenExternalLinks(true);
m_ui->deprecationNotice->showMessage(tr("<p>KeePassHTTP has been deprecated and will be removed in the future.<br>"
"Please switch to KeePassXC-Browser instead! For help with migration, visit "
"our <a href=\"https://keepassxc.org/docs/keepassxc-browser-migration\">"
"migration guide</a>.</p>"), MessageWidget::Warning);
m_ui->deprecationNotice->setCloseButtonVisible(false);
m_ui->deprecationNotice->setAutoHideTimeout(-1);
connect(m_ui->deprecationNotice, &MessageWidget::linkActivated, &MessageWidget::openHttpUrl);
}

OptionDialog::~OptionDialog()
Expand Down
10 changes: 3 additions & 7 deletions src/http/OptionDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="deprecationNotice">
<property name="text">
<string>&lt;p&gt;&lt;b&gt;NOTE:&lt;/b&gt; KeePassHTTP has been deprecated and will be removed in the future.&lt;br&gt;Please switch to keepassxc-browser instead! For help with migration, visit our &lt;a href=&quot;https://keepassxc.org/docs/keepassxc-browser-migration&quot;&gt;keepassxc-browser migration guide&lt;/a&gt;.&lt;/p&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableHttpServer">
<property name="toolTip">
Expand All @@ -43,6 +36,9 @@
</property>
</widget>
</item>
<item>
<widget class="MessageWidget" name="deprecationNotice" native="true"/>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
Expand Down

0 comments on commit a6fd52d

Please sign in to comment.