From 59d013ac6af0dedd9ea6259580e0143367a343eb Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Thu, 16 Apr 2015 17:12:42 +0100 Subject: [PATCH] Show fingerprint only when file exists #4526 --- src/gui/src/Fingerprint.cpp | 20 ++++++++++++++++++++ src/gui/src/Fingerprint.h | 1 + src/gui/src/MainWindow.cpp | 23 ++++++++++++----------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/gui/src/Fingerprint.cpp b/src/gui/src/Fingerprint.cpp index e120ef55..6eefdcd5 100644 --- a/src/gui/src/Fingerprint.cpp +++ b/src/gui/src/Fingerprint.cpp @@ -88,6 +88,26 @@ bool Fingerprint::exists(const QString& fingerprintText) return false; } +bool Fingerprint::localFingerprintExists() +{ + CoreInterface coreInterface; + QString profileDir = coreInterface.getProfileDir(); + + QString dirName = QString("%1/%2") + .arg(profileDir) + .arg(kDirName); + + QString path = QString("%1/%2").arg(dirName).arg(kLocalFilename); + QFile file(path); + + bool exist = false; + if (file.exists()) { + exist = true; + } + + return exist; +} + Fingerprint Fingerprint::local() { return Fingerprint(kLocalFilename); diff --git a/src/gui/src/Fingerprint.h b/src/gui/src/Fingerprint.h index 342c51bc..179afef9 100644 --- a/src/gui/src/Fingerprint.h +++ b/src/gui/src/Fingerprint.h @@ -34,6 +34,7 @@ public: static Fingerprint trustedClients(); static QString localFingerprint(); + static bool localFingerprintExists(); private: QString m_Filename; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 72f38516..9da5b94a 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -23,6 +23,7 @@ #include "MainWindow.h" #include "Fingerprint.h" +#include "PluginManager.h" #include "AboutDialog.h" #include "ServerConfigDialog.h" #include "SettingsDialog.h" @@ -133,6 +134,17 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : updateEdition(); m_pLabelPadlock->hide(); + + if (Fingerprint::localFingerprintExists()) { + m_pLabelFingerprint->setVisible(true); + m_pLabelLocalFingerprint->setVisible(true); + m_pLabelLocalFingerprint->setText( + Fingerprint::localFingerprint()); + } + else { + m_pLabelFingerprint->setVisible(false); + m_pLabelLocalFingerprint->setVisible(false); + } } MainWindow::~MainWindow() @@ -941,17 +953,6 @@ void MainWindow::setEdition(int type) } setWindowTitle(title); - - if (type == Pro) { - m_pLabelFingerprint->setVisible(true); - m_pLabelLocalFingerprint->setVisible(true); - m_pLabelLocalFingerprint->setText( - Fingerprint::localFingerprint()); - } - else { - m_pLabelFingerprint->setVisible(false); - m_pLabelLocalFingerprint->setVisible(false); - } } void MainWindow::on_m_pGroupClient_toggled(bool on)