diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f39b0a8..9c67f6ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,12 +74,13 @@ set(EIGEN_ROOT $ENV{EIGEN_DIR}) # Botan ------------------------------------------------------------------------- -include(cmake/BotanConfig.cmake) +# include(cmake/BotanConfig.cmake) -set(BOTAN_ROOT ${BOTAN_DIR}) +set(BOTAN_ROOT $ENV{BOTAN_DIR}) FIND_PACKAGE ( Threads REQUIRED ) +message(STATUS ${BOTAN_ROOT}) add_library(BOTAN STATIC ${BOTAN_ROOT}/botan_all.cpp) target_link_libraries(BOTAN ${CMAKE_THREAD_LIBS_INIT}) @@ -475,6 +476,7 @@ set_property( target_include_directories(${GEN_PROJECT_NAME} SYSTEM PUBLIC "${BOTAN_ROOT}" + ${Boost_INCLUDE_DIRS} ) target_link_libraries(${GEN_PROJECT_NAME} BOTAN ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ) diff --git a/README.md b/README.md index 25d7c3c7..847ff22a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ * Clang & LLVM (installation guide http://clang.llvm.org/docs/LibASTMatchersTutorial.html) * Boost 1.59 * Eigen 3.2.6 +* Botan 1.11.24 ##### Environment Variables @@ -18,11 +19,16 @@ * CLANG_DIR - .../clang-llvm/ * BOOST_159_DIR - .../boost_1_59_0 * EIGEN_DIR - .../eigen +* BOTAN_DIR - For Win32: * VLD_DIR - .../Visual Leak Detector * path - apped path to git.exe +###### Botan setup + +$ ./configure.py --via-amalgamation --minimized-build --enable-modules="base,ecdsa,emsa1,passhash9,rng,rsa,egd,emsa_pssr,emsa_pkcs1,x509,aes,dev_random" + ##### Settings Run setup script: diff --git a/bin/app/data/gui/license/license.css b/bin/app/data/gui/license/license.css new file mode 100644 index 00000000..ffb7b030 --- /dev/null +++ b/bin/app/data/gui/license/license.css @@ -0,0 +1,17 @@ +#licenseField { + font-family: ""; + font-size: 12pt; + height: 200px; + padding: 5px; + width: 470px; +} + +#licenseError { + color: red; +} + +QTextEdit { + background-color: rgba(255, 255, 255, 200); + border-radius: 10px; + border: 1px solid lightgrey; +} diff --git a/bin/app/data/gui/setting_window/window.css b/bin/app/data/gui/setting_window/window.css index 75c5bc12..353128b2 100644 --- a/bin/app/data/gui/setting_window/window.css +++ b/bin/app/data/gui/setting_window/window.css @@ -75,3 +75,13 @@ QLineEdit:disabled { color: white; background: #2D3F85; } + +#windowButton:disabled { + color: lightgray; +} + +QToolTip { + background-color: ; + color: ; + font-size: pt; +} diff --git a/cmake/PublicKey.h.in b/cmake/PublicKey.h.in index 304f90c1..4ffd7c7e 100644 --- a/cmake/PublicKey.h.in +++ b/cmake/PublicKey.h.in @@ -1,10 +1,10 @@ #ifndef PUBLIC_KEY_H #define PUBLIC_KEY_H -// This File(PublicKey.h) is generated with CMake +// This File(PublicKey.h) is generated with CMake #include static const std::string PublicKey = "@KEY@"; -#endif //PUBLIC_KEY_H +#endif // PUBLIC_KEY_H diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index cc6b42f7..43f7f055 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -4,5 +4,6 @@ add_files( data/parser/cxx/TaskParseCxx.cpp isTrial.cpp + LicenseChecker.h main.cpp ) diff --git a/src/app/LicenseChecker.h b/src/app/LicenseChecker.h new file mode 100644 index 00000000..3d8d7d88 --- /dev/null +++ b/src/app/LicenseChecker.h @@ -0,0 +1,78 @@ +#ifndef LICENSE_CHECKER_H +#define LICENSE_CHECKER_H + +#include "utility/messaging/MessageListener.h" +#include "utility/messaging/type/MessageLoadProject.h" +#include "utility/messaging/type/MessageStatus.h" + +#include "License.h" +#include "PublicKey.h" +#include "settings/ApplicationSettings.h" + +class LicenseChecker + : public MessageListener +{ +public: + inline void setApp(Application* app) + { + m_app = app; + if (!checkLicenseString()) + { + m_app->showLicenseScreen(); + } + } + +private: + void handleMessage(MessageLoadProject* message) + { + if (!checkLicenseString()) + { + message->cancel(); + m_app->showLicenseScreen(); + } + } + + inline bool checkLicenseString() + { + MessageStatus("preparing...", false, true).dispatch(); + + bool valid = false; + do + { + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + + std::string licenseCheck = appSettings->getLicenseCheck(); + FilePath p(""); + if (!License::checkLocation(p.absolute().str(), licenseCheck)) + { + break; + } + + std::string licenseString = appSettings->getLicenseString(); + if (licenseString.size() == 0) + { + break; + } + + License license; + bool isLoaded = license.loadFromString(licenseString); + if (!isLoaded) + { + break; + } + + license.loadPublicKeyFromString(PublicKey); + valid = license.isValid(); + + } + while (false); + + MessageStatus("ready").dispatch(); + + return valid; + } + + Application* m_app; +}; + +#endif // LICENSE_CHECKER_H diff --git a/src/app/main.cpp b/src/app/main.cpp index 606bd0c9..77ca6a68 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -9,6 +9,7 @@ #include "Application.h" #include "includes.h" // defines 'void setup(int argc, char *argv[])' +#include "LicenseChecker.h" #include "qt/commandline/QtCommandLineParser.h" #include "qt/window/QtMainWindow.h" #include "qt/window/QtSplashScreen.h" @@ -63,8 +64,13 @@ int main(int argc, char *argv[]) QtMainWindow::setWindowSettingsPath(windowSettingsPath); Application::setAppSettingsPath(appSettingsPath); + + LicenseChecker checker; + std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); + checker.setApp(app.get()); + if (splash) { delete splash; diff --git a/src/gen/License.cpp b/src/gen/License.cpp index 05dda2e8..775587ea 100644 --- a/src/gen/License.cpp +++ b/src/gen/License.cpp @@ -23,12 +23,12 @@ License::~License() { } -std::string License::getHashLine() +std::string License::getHashLine() const { return lines[4]; } -std::string License::getMessage() +std::string License::getMessage() const { std::string message = ""; for(int i = 1; i < 5; ++i) @@ -38,7 +38,7 @@ std::string License::getMessage() return message; } -std::string License::getSignature() +std::string License::getSignature() const { std::string signatue = ""; for(int i = 5; i < 12; ++i) @@ -48,11 +48,21 @@ std::string License::getSignature() return signatue; } -std::string License::getVersionLine() +std::string License::getVersionLine() const { return lines[3]; } +std::string License::getOwnerLine() const +{ + return lines[1]; +} + +std::string License::getLicenseTypeLine() const +{ + return lines[2]; +} + void License::create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, unsigned int type) { m_version = version; @@ -109,62 +119,28 @@ bool License::load(std::istream& stream) { lines.clear(); std::string line; - if(!getline(stream, line, '\n')) + while (getline(stream, line, '\n')) { - return false; + lines.push_back(line); } - if(line.compare(BEGIN_LICENSE) ) + + if (lines.front() != BEGIN_LICENSE) { std::cout << "No License Header" << std::endl; - lines.push_back(BEGIN_LICENSE); + lines.insert(lines.begin(), BEGIN_LICENSE); } - else - { - lines.push_back(line); - if(!getline(stream, line)) - { - return false; - } - } - lines.push_back(line); - for(int i = 0; i < 2; ++i) + if (lines.back() != END_LICENSE) { - if(!getline(stream, line)) - { - return false; - } - lines.push_back(line); + std::cout << "No License Footer" << std::endl; + lines.push_back(END_LICENSE); } - if(!getline(stream, line)) + + if (lines.size() != 13) { return false; } - lines.push_back(line); - //get signature - std::string signature = ""; - for(int i = 0; i < 7; ++i) - { - if(!getline(stream, line)) - { - return false; - } - signature += line; - lines.push_back(line); - } - - //check License ending - getline(stream, line); - if(line.compare(END_LICENSE)) - { - std::cout << "No License Footer" << std::endl; - lines.push_back(END_LICENSE); - } - else - { - lines.push_back(line); - } return true; } @@ -181,16 +157,6 @@ void License::print() std::cout << getLicenseString(); } -std::string License::getOwnerLine() -{ - return lines[1]; -} - -std::string License::getLicenseTypeLine() -{ - return lines[2]; -} - void License::addSignature(std::string signature) { if(lines.size() > 5) @@ -215,7 +181,7 @@ void License::addSignature(std::string signature) lines.push_back(END_LICENSE); } -bool License::isValid() +bool License::isValid() const { if(!m_publicKey) { @@ -242,7 +208,7 @@ bool License::isValid() return ok; } -std::string License::getPublicKeyFilename() +std::string License::getPublicKeyFilename() const { if(m_publicKeyFilename.empty()) { @@ -251,7 +217,8 @@ std::string License::getPublicKeyFilename() return m_publicKeyFilename; } -std::string License::getVersion() { +std::string License::getVersion() const +{ if(m_version.empty()) { return "x"; @@ -298,7 +265,7 @@ void License::setVersion(const std::string& version) } } -std::string License::getLicenseString() +std::string License::getLicenseString() const { std::stringstream license; for(std::string line : lines) @@ -308,12 +275,12 @@ std::string License::getLicenseString() return license.str(); } -bool License::checkLocation(const std::string& location, const std::string& hash) -{ - return Botan::check_passhash9(location, hash); -} - std::string License::hashLocation(const std::string& location) { return Botan::generate_passhash9(location, m_rng); } + +bool License::checkLocation(const std::string& location, const std::string& hash) +{ + return Botan::check_passhash9(location, hash); +} diff --git a/src/gen/License.h b/src/gen/License.h index fecb83e2..21c3caa6 100644 --- a/src/gen/License.h +++ b/src/gen/License.h @@ -11,28 +11,30 @@ //#include "botan/rsa.h" #endif -class License { +class License +{ public: enum LicenseType { LICENSETYPE_SINGLEUSER = 0, }; + License(); ~License(); - std::string getHashLine(); - std::string getMessage(); - std::string getSignature(); - std::string getVersionLine(); - std::string getOwnerLine(); - std::string getLicenseTypeLine(); + std::string getHashLine() const; + std::string getMessage() const; + std::string getSignature() const; + std::string getVersionLine() const; + std::string getOwnerLine() const; + std::string getLicenseTypeLine() const; - std::string getPublicKeyFilename(); - std::string getVersion(); + std::string getPublicKeyFilename() const; + std::string getVersion() const; void create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, unsigned int type = 0); - std::string getLicenseString(); + std::string getLicenseString() const; void writeToFile(std::string filename); bool load(std::istream& stream); @@ -43,15 +45,17 @@ public: bool loadPublicKeyFromString(std::string); void setVersion(const std::string&); - bool isValid(); + bool isValid() const; void print(); std::string hashLocation(const std::string&); - bool checkLocation(const std::string&, const std::string&); + static bool checkLocation(const std::string&, const std::string&); + private: void createMessage(std::string user, std::string version, unsigned int type = 0); void addSignature(std::string); + std::string m_version; std::string m_publicKeyFilename; std::shared_ptr m_publicKey; @@ -63,4 +67,4 @@ private: const std::string END_LICENSE = "-----END LICENSE-----"; }; -#endif //COATI_LICENSE_H +#endif // COATI_LICENSE_H diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index dfc88aee..3426afe8 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -111,6 +111,11 @@ void Application::saveProject(const FilePath& projectSettingsFilePath) } } +void Application::showLicenseScreen() +{ + m_mainView->showLicenseScreen(); +} + void Application::setAppSettingsPath(const std::string& appSettingsPath) { m_appSettingsPath = appSettingsPath; diff --git a/src/lib/Application.h b/src/lib/Application.h index 4869157a..8235d8d3 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -35,6 +35,7 @@ public: void loadProject(const FilePath& projectSettingsFilePath, bool forceRefresh); void refreshProject(); void saveProject(const FilePath& projectSettingsFilePath); + void showLicenseScreen(); static void setAppSettingsPath(const std::string& appSettingsPath); diff --git a/src/lib/component/view/MainView.h b/src/lib/component/view/MainView.h index 3c32698c..293dfe18 100644 --- a/src/lib/component/view/MainView.h +++ b/src/lib/component/view/MainView.h @@ -16,6 +16,7 @@ public: virtual void setTitle(const std::string& title) = 0; virtual void activateWindow() = 0; virtual void updateRecentProjectMenu() = 0; + virtual void showLicenseScreen() = 0; }; #endif // MAIN_VIEW_H diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 3811220c..f2978c94 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -163,20 +163,20 @@ int ApplicationSettings::getControlsMouseForwardButton() const std::string ApplicationSettings::getLicenseString() const { - return getValue("application/license/license:", ""); + return getValue("user/license/license", ""); } std::string ApplicationSettings::getLicenseCheck() const { - return getValue("application/license/check", ""); + return getValue("user/license/check", ""); } void ApplicationSettings::setLicenseString(const std::string& licenseString) { - setValue("application/license/license", licenseString); + setValue("user/license/license", licenseString); } void ApplicationSettings::setLicenseCheck(const std::string& hash) { - setValue("application/license/check", hash); + setValue("user/license/check", hash); } diff --git a/src/lib/utility/messaging/MessageBase.h b/src/lib/utility/messaging/MessageBase.h index 4501b701..dcefb592 100644 --- a/src/lib/utility/messaging/MessageBase.h +++ b/src/lib/utility/messaging/MessageBase.h @@ -19,6 +19,7 @@ public: : undoRedoType(UNDOTYPE_NORMAL) , m_sendAsTask(true) , m_keepContent(false) + , m_cancelled(false) { } @@ -59,6 +60,16 @@ public: return m_keepContent; } + void cancel() + { + m_cancelled = true; + } + + bool cancelled() + { + return m_cancelled; + } + virtual void print(std::ostream& os) const = 0; std::string str() const @@ -74,6 +85,7 @@ public: private: bool m_sendAsTask; bool m_keepContent; + bool m_cancelled; }; #endif // MESSAGE_BASE_H diff --git a/src/lib/utility/messaging/MessageQueue.cpp b/src/lib/utility/messaging/MessageQueue.cpp index d13f4444..fd9d36f3 100644 --- a/src/lib/utility/messaging/MessageQueue.cpp +++ b/src/lib/utility/messaging/MessageQueue.cpp @@ -241,6 +241,11 @@ void MessageQueue::sendMessage(std::shared_ptr message) listener->handleMessageBase(message.get()); m_listenersMutex.lock(); } + + if (message->cancelled()) + { + break; + } } } @@ -260,7 +265,7 @@ void MessageQueue::sendMessageAsTask(std::shared_ptr message, bool [listenerId, message]() { MessageListenerBase* listener = MessageQueue::getInstance()->getListenerById(listenerId); - if (listener) + if (listener && !message->cancelled()) { listener->handleMessageBase(message.get()); } diff --git a/src/lib_gui/qt/view/QtMainView.cpp b/src/lib_gui/qt/view/QtMainView.cpp index a64579de..ca20595f 100644 --- a/src/lib_gui/qt/view/QtMainView.cpp +++ b/src/lib_gui/qt/view/QtMainView.cpp @@ -8,6 +8,7 @@ QtMainView::QtMainView() : m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1)) , m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this)) , m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this)) + , m_showLicenseScreenFunctor(std::bind(&QtMainView::doShowLicenseScreen, this)) { m_window = std::make_shared(); m_window->show(); @@ -86,6 +87,11 @@ void QtMainView::updateRecentProjectMenu() m_updateRecentProjectMenuFunctor(); } +void QtMainView::showLicenseScreen() +{ + m_showLicenseScreenFunctor(); +} + void QtMainView::doUpdateRecentProjectMenu() { m_window->updateRecentProjectMenu(); @@ -103,3 +109,8 @@ void QtMainView::doActivateWindow() m_window->raise(); m_window->setFocus(Qt::ActiveWindowFocusReason); } + +void QtMainView::doShowLicenseScreen() +{ + m_window->forceEnterLicense(); +} diff --git a/src/lib_gui/qt/view/QtMainView.h b/src/lib_gui/qt/view/QtMainView.h index f48837ac..1549e025 100644 --- a/src/lib_gui/qt/view/QtMainView.h +++ b/src/lib_gui/qt/view/QtMainView.h @@ -37,11 +37,13 @@ public: virtual void setTitle(const std::string& title); virtual void activateWindow(); virtual void updateRecentProjectMenu(); + virtual void showLicenseScreen(); private: void doSetTitle(const std::string& title); void doActivateWindow(); void doUpdateRecentProjectMenu(); + void doShowLicenseScreen(); std::shared_ptr m_window; std::vector m_views; @@ -49,6 +51,7 @@ private: QtThreadedFunctor m_setTitleFunctor; QtThreadedFunctor<> m_activateWindowFunctor; QtThreadedFunctor<> m_updateRecentProjectMenuFunctor; + QtThreadedFunctor<> m_showLicenseScreenFunctor; }; #endif // QT_MAIN_VIEW_H diff --git a/src/lib_gui/qt/window/QtLicense.cpp b/src/lib_gui/qt/window/QtLicense.cpp index 38bfc83b..5e163634 100644 --- a/src/lib_gui/qt/window/QtLicense.cpp +++ b/src/lib_gui/qt/window/QtLicense.cpp @@ -10,42 +10,102 @@ #include "License.h" #include "PublicKey.h" - -#include "settings/ApplicationSettings.h" -#include "utility/logging/logging.h" +#include "qt/utility/utilityQt.h" +#include "settings/ApplicationSettings.h" #include "utility/file/FilePath.h" QtLicense::QtLicense(QWidget *parent) - : QtSettingsWindow(parent) + : QtSettingsWindow(parent, 68) { raise(); } QSize QtLicense::sizeHint() const { - return QSize(600,600); + return QSize(725, 550); +} + +void QtLicense::clear() +{ + if (m_licenseText) + { + m_licenseText->setText(""); + } + + if (m_errorLabel) + { + m_errorLabel->setText(" "); + } } void QtLicense::setup() { - setupForm(); + setStyleSheet(( + utility::getStyleSheet("data/gui/setting_window/window.css") + + utility::getStyleSheet("data/gui/license/license.css") + ).c_str()); - updateTitle("Enter License"); - updateDoneButton("Ok"); -} + addLogo(); -void QtLicense::populateForm(QFormLayout* layout) -{ - QLabel* licenseName = new QLabel(); - licenseName->setText( QString::fromLatin1("Enter License:")); - QFont _font = licenseName->font(); - _font.setPixelSize(36); - licenseName->setFont(_font); - layout->addWidget(licenseName); + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(25, 100, 25, 30); - m_licenseText = new QTextEdit(); - m_licenseText->setMinimumHeight(300); - layout->addWidget(m_licenseText); + QVBoxLayout* subLayout = new QVBoxLayout(); + subLayout->setContentsMargins(250, 0, 0, 0); + + QLabel* licenseName = new QLabel(this); + licenseName->setText(QString::fromLatin1("Enter Licence")); + licenseName->setObjectName("titleLabel"); + subLayout->addWidget(licenseName); + + subLayout->addSpacing(10); + + QLabel* licenseIntro = new QLabel(this); + licenseIntro->setText(QString::fromLatin1("Please enter a licence key to activate Coati:")); + licenseIntro->setObjectName("licenseIntro"); + subLayout->addWidget(licenseIntro); + + m_licenseText = new QTextEdit(this); + m_licenseText->setObjectName("licenseField"); + m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str()); + m_licenseText->setPlaceholderText( + "-----BEGIN LICENSE-----\n" + "Jane Doe\n" + "Single User License\n" + "Coati 0\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxx\n" + "-----END LICENSE-----\n" + ); + subLayout->addWidget(m_licenseText); + + m_errorLabel = new QLabel(this); + m_errorLabel->setObjectName("licenseError"); + m_errorLabel->setText(" "); + subLayout->addWidget(m_errorLabel); + + subLayout->addSpacing(10); + + QLabel* linkLabel = new QLabel(this); + linkLabel->setObjectName("linkLabel"); + linkLabel->setText("Don't have a license key yet?"); + linkLabel->setOpenExternalLinks(true); + linkLabel->setGeometry(275, 300, 300, 50); + subLayout->addWidget(linkLabel); + + layout->addLayout(subLayout); + layout->addSpacing(20); + + showButtons(layout); + updateDoneButton("Activate"); + + resize(725, 550); } void QtLicense::handleCancelButtonPress() @@ -55,29 +115,40 @@ void QtLicense::handleCancelButtonPress() void QtLicense::handleUpdateButtonPress() { - License license; - bool isLoaded = license.loadFromString(m_licenseText->toPlainText().toStdString()); - if(!isLoaded) + std::string licenseString = m_licenseText->toPlainText().toStdString(); + if (licenseString.size() == 0) { - LOG_WARNING("Failed Loading License"); + m_errorLabel->setText("No licence key was entered."); return; } + + License license; + bool isLoaded = license.loadFromString(licenseString); + if (!isLoaded) + { + m_errorLabel->setText("The entered license key is malformed."); + return; + } + license.loadPublicKeyFromString(PublicKey); license.print(); - if(license.isValid()) + if (license.isValid()) { - ApplicationSettings::getInstance()->setLicenseString(license.getLicenseString()); + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + appSettings->setLicenseString(license.getLicenseString()); FilePath p(""); - ApplicationSettings::getInstance()->setLicenseCheck(license.hashLocation(p.absolute().str())); - ApplicationSettings::getInstance()->save(); - LOG_WARNING("License saved"); + appSettings->setLicenseCheck(license.hashLocation(p.absolute().str())); + appSettings->save(); } else { - LOG_WARNING("License is not valid"); + m_errorLabel->setText("The entered license key is invalid."); + return; } + + m_errorLabel->setText(" "); + setCancelAble(true); + emit finished(); - } - diff --git a/src/lib_gui/qt/window/QtLicense.h b/src/lib_gui/qt/window/QtLicense.h index 875b2fb9..3dbdbebe 100644 --- a/src/lib_gui/qt/window/QtLicense.h +++ b/src/lib_gui/qt/window/QtLicense.h @@ -16,9 +16,9 @@ public: QtLicense(QWidget* parent = 0); QSize sizeHint() const Q_DECL_OVERRIDE; + void clear(); + virtual void setup() override; -protected: - virtual void populateForm(QFormLayout* layout) override; private slots: void handleCancelButtonPress(); @@ -29,7 +29,7 @@ private: QPushButton* m_updateButton; QTextEdit* m_licenseText; - + QLabel* m_errorLabel; }; #endif //QT_LICENSE_H diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 969dc091..06afd4d8 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -243,6 +243,16 @@ void QtMainWindow::saveLayout() settings.setValue("DOCK_LOCATIONS", this->saveState()); } +void QtMainWindow::forceEnterLicense() +{ + enterLicense(); + m_enterLicenseWindow->clear(); + m_enterLicenseWindow->setCancelAble(false); + + this->setEnabled(false); + m_enterLicenseWindow->setEnabled(true); +} + bool QtMainWindow::event(QEvent* event) { if (event->type() == QEvent::WindowActivate) @@ -297,6 +307,12 @@ void QtMainWindow::clearWindows() m_windowStack.clear(); } +void QtMainWindow::activateWindow() +{ + this->setEnabled(true); + popWindow(); +} + void QtMainWindow::about() { if (!m_aboutWindow) @@ -345,11 +361,11 @@ void QtMainWindow::enterLicense() m_enterLicenseWindow = std::make_shared(this); m_enterLicenseWindow->setup(); - connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(popWindow())); + connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(activateWindow())); connect(m_enterLicenseWindow.get(), SIGNAL(canceled()), this, SLOT(popWindow())); } - pushWindow(m_enterLicenseWindow) + pushWindow(m_enterLicenseWindow.get()); } void QtMainWindow::showStartScreen() diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index f4685865..869af972 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -83,6 +83,8 @@ public: void loadLayout(); void saveLayout(); + void forceEnterLicense(); + protected: bool event(QEvent* event); void keyPressEvent(QKeyEvent* event); @@ -92,6 +94,8 @@ public slots: void popWindow(); void clearWindows(); + void activateWindow(); + void about(); void openSettings(); void showLicenses(); diff --git a/src/lib_gui/qt/window/QtSettingsWindow.cpp b/src/lib_gui/qt/window/QtSettingsWindow.cpp index 5be9b447..1c4df82a 100644 --- a/src/lib_gui/qt/window/QtSettingsWindow.cpp +++ b/src/lib_gui/qt/window/QtSettingsWindow.cpp @@ -18,6 +18,7 @@ QtSettingsWindow::QtSettingsWindow(QWidget *parent, int displacement) , m_cancelButton(nullptr) , m_doneButton(nullptr) , m_mousePressedInWindow(false) + , m_cancelAble(true) { QSize windowSize = sizeHint(); move(parent->pos().x() + parent->width() / 2 - 250, parent->pos().y() + parent->height() / 2 - 250); @@ -60,12 +61,24 @@ QSize QtSettingsWindow::sizeHint() const return QSize(500, 500); } +void QtSettingsWindow::setCancelAble(bool cancelable) +{ + if (m_cancelButton) + { + m_cancelButton->setEnabled(cancelable); + } + + m_cancelAble = cancelable; +} + void QtSettingsWindow::keyPressEvent(QKeyEvent *event) { - if (event->key() == Qt::Key_Escape) + if (m_cancelAble && event->key() == Qt::Key_Escape) { emit canceled(); } + + QWidget::keyPressEvent(event); } void QtSettingsWindow::resizeEvent(QResizeEvent *event) @@ -139,6 +152,34 @@ void QtSettingsWindow::setupForm() form->setLayout(layout); + windowLayout->addWidget(scrollArea); + windowLayout->addSpacing(20); + + showButtons(windowLayout); + + m_window->setLayout(windowLayout); + resize(QSize(600, 620)); + + scrollArea->raise(); +} + +void QtSettingsWindow::populateForm(QFormLayout* layout) +{ +} + +void QtSettingsWindow::addLogo() +{ + QtDeviceScaledPixmap coatiLogo("data/gui/startscreen/logo.png"); + coatiLogo.scaleToWidth(200); + + QLabel* coatiLogoLabel = new QLabel(this); + coatiLogoLabel->setPixmap(coatiLogo.pixmap()); + coatiLogoLabel->resize(coatiLogo.width(), coatiLogo.height()); + coatiLogoLabel->move(30,10); +} + +void QtSettingsWindow::showButtons(QVBoxLayout* layout) +{ m_cancelButton = new QPushButton("Cancel"); m_cancelButton->setObjectName("windowButton"); m_doneButton = new QPushButton("Done"); @@ -153,18 +194,7 @@ void QtSettingsWindow::setupForm() buttons->addWidget(m_doneButton); m_buttonsLayout = buttons; - windowLayout->addWidget(scrollArea); - windowLayout->addSpacing(20); - windowLayout->addLayout(buttons); - - m_window->setLayout(windowLayout); - resize(QSize(600, 620)); - - scrollArea->raise(); -} - -void QtSettingsWindow::populateForm(QFormLayout* layout) -{ + layout->addLayout(buttons); } void QtSettingsWindow::updateTitle(QString title) diff --git a/src/lib_gui/qt/window/QtSettingsWindow.h b/src/lib_gui/qt/window/QtSettingsWindow.h index 46604658..dd3c03a6 100644 --- a/src/lib_gui/qt/window/QtSettingsWindow.h +++ b/src/lib_gui/qt/window/QtSettingsWindow.h @@ -8,6 +8,7 @@ class QFormLayout; class QLabel; class QPushButton; +class QVBoxLayout; class QtSettingsWindow : public QWidget @@ -21,6 +22,8 @@ public: virtual void setup() = 0; + void setCancelAble(bool cancelAble); + signals: void finished(); void canceled(); @@ -35,6 +38,9 @@ protected: void setupForm(); virtual void populateForm(QFormLayout* layout); + void addLogo(); + void showButtons(QVBoxLayout* layout); + void updateTitle(QString title); void updateDoneButton(QString text); void hideCancelButton(bool hidden); @@ -56,6 +62,7 @@ private: int m_displacment; QPoint m_dragPosition; bool m_mousePressedInWindow; + bool m_cancelAble; }; #endif //QT_SETTINGS_WINDOW_H diff --git a/src/lib_gui/qt/window/QtStartScreen.cpp b/src/lib_gui/qt/window/QtStartScreen.cpp index 640b5504..11aee8c8 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -35,12 +35,7 @@ void QtStartScreen::setup() { setStyleSheet(utility::getStyleSheet("data/gui/startscreen/startscreen.css").c_str()); - QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo.png"); - coati_logo.scaleToWidth(200); - QLabel* coatiLogoLabel = new QLabel(this); - coatiLogoLabel->setPixmap(coati_logo.pixmap()); - coatiLogoLabel->resize(coati_logo.width(), coati_logo.height()); - coatiLogoLabel->move(30,10); + addLogo(); if(!isTrial()) {