ui: Added menu action to display EULA and force accepting on Mac

This commit is contained in:
Eberhard Graether
2017-05-30 00:30:52 +02:00
parent 9256618f7c
commit bd40294a2c
10 changed files with 144 additions and 8 deletions
@@ -75,6 +75,8 @@
<check><!-- STRING: hashed path of the working directory used when entering the license key --></check>
<license><!-- STRING: the license key --></license>
</license>
<accepted_eula_version><!-- INTEGER: last accepted eula version --></accepted_eula_version>
</user>
<network>
+10
View File
@@ -380,6 +380,16 @@ bool ApplicationSettings::setRecentProjects(const std::vector<FilePath> &recentP
return setPathValues("user/recent_projects/recent_project", recentProjects);
}
int ApplicationSettings::getAcceptedEulaVersion() const
{
return getValue<int>("user/accepted_eula_version", 0);
}
void ApplicationSettings::setAcceptedEulaVersion(int version)
{
setValue<int>("user/accepted_eula_version", version);
}
int ApplicationSettings::getPluginPort() const
{
return getValue<int>("network/plugin_port", 6666);
+3
View File
@@ -110,6 +110,9 @@ public:
std::vector<FilePath> getRecentProjects() const;
bool setRecentProjects(const std::vector<FilePath>& recentProjects);
int getAcceptedEulaVersion() const;
void setAcceptedEulaVersion(int version);
// network
int getPluginPort() const;
void setPluginPort(const int pluginPort);
+2
View File
@@ -191,6 +191,8 @@ add_files(
qt/window/QtBookmarkBrowser.h
qt/window/QtBookmarkCreator.cpp
qt/window/QtBookmarkCreator.h
qt/window/QtEulaWindow.cpp
qt/window/QtEulaWindow.h
qt/window/QtIndexingDialog.cpp
qt/window/QtIndexingDialog.h
qt/window/QtKeyboardShortcuts.cpp
-5
View File
@@ -1,12 +1,7 @@
#include "qt/window/QtAboutLicense.h"
#include <QComboBox>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QTextBrowser>
#include <QTextBlock>
#include <QTextEdit>
#include "licenses.h"
+66
View File
@@ -0,0 +1,66 @@
#include "qt/window/QtEulaWindow.h"
#include <QTextEdit>
#include <QVBoxLayout>
#include <QLabel>
#include "utility/ResourcePaths.h"
#include "utility/text/TextAccess.h"
QtEulaWindow::QtEulaWindow(QWidget *parent, bool forceAccept)
: QtWindow(parent)
, m_forceAccept(forceAccept)
{
raise();
}
QSize QtEulaWindow::sizeHint() const
{
return QSize(700, 600);
}
void QtEulaWindow::populateWindow(QWidget* widget)
{
QVBoxLayout* layout = new QVBoxLayout(widget);
layout->setContentsMargins(0, 0, 0, 0);
if (m_forceAccept)
{
layout->addSpacing(5);
QLabel* label = new QLabel("Please read and agree to our End User License Agreement:");
QFont _font = label->font();
_font.setBold(true);
label->setFont(_font);
layout->addWidget(label);
}
std::shared_ptr<TextAccess> text =
TextAccess::createFromFile(FilePath(ResourcePaths::getGuiPath().str() + "installer/EULA.txt"));
QTextEdit* licenseText = new QTextEdit();
licenseText->setObjectName("textField");
licenseText->setReadOnly(true);
licenseText->setText(QString::fromStdString(text->getText()));
layout->addWidget(licenseText);
widget->setLayout(layout);
}
void QtEulaWindow::windowReady()
{
updateTitle("End User License Agreement");
if (m_forceAccept)
{
updateCloseButton("Quit");
updateNextButton("Agree");
}
else
{
updateCloseButton("Close");
setNextVisible(false);
}
setPreviousVisible(false);
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef QT_EULA_LICENSE_H
#define QT_EULA_LICENSE_H
#include "qt/window/QtWindow.h"
class QtEulaWindow
: public QtWindow
{
public:
static const int EULA_VERSION = 1;
QtEulaWindow(QWidget* parent, bool forceAccept);
QSize sizeHint() const override;
protected:
// QtWindow implementation
virtual void populateWindow(QWidget* widget) override;
virtual void windowReady() override;
private:
bool m_forceAccept;
};
#endif // QT_EULA_LICENSE_H
+33 -1
View File
@@ -22,6 +22,7 @@
#include "qt/window/project_wizzard/QtProjectWizzard.h"
#include "qt/window/QtAbout.h"
#include "qt/window/QtAboutLicense.h"
#include "qt/window/QtEulaWindow.h"
#include "qt/window/QtKeyboardShortcuts.h"
#include "qt/window/QtLicense.h"
#include "qt/window/QtPreferencesWindow.h"
@@ -333,6 +334,31 @@ void QtMainWindow::showBugtracker()
QDesktopServices::openUrl(QUrl("https://github.com/CoatiSoftware/SourcetrailBugTracker/issues"));
}
void QtMainWindow::showEula(bool forceAccept)
{
QtEulaWindow* eulaWindow = new QtEulaWindow(this, forceAccept);
m_windowStack.pushWindow(eulaWindow);
eulaWindow->setup();
if (forceAccept)
{
setEnabled(false);
eulaWindow->setEnabled(true);
connect(eulaWindow, SIGNAL(finished()), this, SLOT(acceptedEula()));
connect(eulaWindow, SIGNAL(canceled()), dynamic_cast<QApplication*>(QCoreApplication::instance()), SLOT(quit()));
}
}
void QtMainWindow::acceptedEula()
{
ApplicationSettings::getInstance()->setAcceptedEulaVersion(QtEulaWindow::EULA_VERSION);
ApplicationSettings::getInstance()->save();
setEnabled(true);
m_windowStack.popWindow();
}
void QtMainWindow::showLicenses()
{
QtAboutLicense* licenseWindow = createWindow<QtAboutLicense>();
@@ -404,11 +430,16 @@ void QtMainWindow::showStartScreen()
connect(startScreen, SIGNAL(openNewProjectDialog()), this, SLOT(newProject()));
connect(startScreen, SIGNAL(openEnterLicenseDialog()), this, SLOT(enterLicense()));
if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY)
{
forceEnterLicense(state == LicenseChecker::LICENSE_EXPIRED);
}
if (QSysInfo::macVersion() != QSysInfo::MV_None &&
ApplicationSettings::getInstance()->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION)
{
showEula(true);
}
}
void QtMainWindow::hideStartScreen()
@@ -761,6 +792,7 @@ void QtMainWindow::setupHelpMenu()
menu->addSeparator();
menu->addAction(tr("End User License Agreement"), this, SLOT(showEula()));
menu->addAction(tr("3rd Party Licences"), this, SLOT(showLicenses()));
menu->addAction(tr("&About Sourcetrail"), this, SLOT(about()));
+2
View File
@@ -83,6 +83,8 @@ public slots:
void showBugtracker();
void showDocumentation();
void showKeyboardShortcuts();
void showEula(bool forceAccept = false);
void acceptedEula();
void showLicenses();
void enterLicense();
void enteredLicense();
+2 -2
View File
@@ -533,9 +533,9 @@ std::string License::hashLocation(const std::string& location)
bool License::checkLocation(const std::string& location, const std::string& hash)
{
if (location.size() <= 0 || hash.size() <= 0)
if (!location.size() || !hash.size())
{
return "";
return false;
}
return Botan::check_passhash9(location, hash);