From 2639c36b2f130a0e363db0a211e7c53fecf05bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Tue, 7 Sep 2021 16:33:27 -0300 Subject: [PATCH] Create EnterLicense dialog --- data/strings/en.ini | 1 + data/widgets/enter_license.xml | 6 ++- src/app/CMakeLists.txt | 1 + src/app/commands/cmd_enter_license.cpp | 20 +------ src/app/ui/enter_license.cpp | 74 ++++++++++++++++++++++++++ src/app/ui/enter_license.h | 33 ++++++++++++ 6 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 src/app/ui/enter_license.cpp create mode 100644 src/app/ui/enter_license.h diff --git a/data/strings/en.ini b/data/strings/en.ini index 51baa1571..e26d4a3bd 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -1074,6 +1074,7 @@ default_new_layer_name = New Layer title = Enter License default_message = If you need a license key, go to license_key = License Key +activating_message = Activating... [tileset_selector] new_tileset = New Tileset diff --git a/data/widgets/enter_license.xml b/data/widgets/enter_license.xml index 83cbb10ac..501788830 100644 --- a/data/widgets/enter_license.xml +++ b/data/widgets/enter_license.xml @@ -1,7 +1,7 @@ - + + + + diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 258fde415..77f2bda91 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -367,6 +367,7 @@ if(ENABLE_UI) ui/editor/state_with_wheel_behavior.cpp ui/editor/transform_handles.cpp ui/editor/zooming_state.cpp + ui/enter_license.cpp ui/export_file_window.cpp ui/expr_entry.cpp ui/file_list.cpp diff --git a/src/app/commands/cmd_enter_license.cpp b/src/app/commands/cmd_enter_license.cpp index 197cf6704..e41453c2a 100644 --- a/src/app/commands/cmd_enter_license.cpp +++ b/src/app/commands/cmd_enter_license.cpp @@ -4,20 +4,16 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "app/app.h" #include "app/commands/command.h" #include "app/context.h" -#include "ver/info.h" #ifdef ENABLE_DRM -#include "drm/license_manager.h" +#include "app/ui/enter_license.h" #else #include "app/i18n/strings.h" #include "ui/alert.h" #endif -#include "enter_license.xml.h" - namespace app { class EnterLicenseCommand : public Command { @@ -36,19 +32,7 @@ void EnterLicenseCommand::onExecute(Context* context) { #ifdef ENABLE_DRM // Load the window widget - app::gen::EnterLicense window; - - window.setSizeable(false); - window.licenseKey()->Change.connect([&window]() { - window.licenseKey()->setText(base::string_to_upper(window.licenseKey()->text())); - window.okButton()->setEnabled(window.licenseKey()->text().size() > 0); - }); - window.okButton()->setEnabled(false); - window.okButton()->Click.connect([&window](ui::Event&) { - drm::LicenseManager::instance()->activate(window.licenseKey()->text(), get_app_name(), get_app_version()); - window.closeWindow(nullptr); - }); - + app::EnterLicense window; // Open the window window.openWindowInForeground(); #else diff --git a/src/app/ui/enter_license.cpp b/src/app/ui/enter_license.cpp new file mode 100644 index 000000000..5f682fda2 --- /dev/null +++ b/src/app/ui/enter_license.cpp @@ -0,0 +1,74 @@ +// Aseprite +// Copyright (C) 2021 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include "app/i18n/strings.h" +#include "enter_license.h" +#include "enter_license.xml.h" +#include "ui/message.h" +#include "ui/style.h" +#include "ui/system.h" +#include "ver/info.h" + +namespace app { + +EnterLicense::EnterLicense() : m_timer(500, this), m_activationInProgress(false) +{ + for (auto& layer : message()->style()->layers()) { + layer.setAlign(layer.align() | ui::WORDWRAP); + } + setSizeable(false); + licenseKey()->Change.connect([this]() { + licenseKey()->setText(base::string_to_upper(licenseKey()->text())); + okButton()->setEnabled(licenseKey()->text().size() > 0); + }); + + okButton()->setEnabled(false); + okButton()->Click.connect([this](ui::Event&) { + icon()->setVisible(false); + message()->setText(app::Strings::instance()->enter_license_activating_message()); + layout(); + setEnabled(false); + std::string key = licenseKey()->text(); + m_activationInProgress = true; + m_activation = std::thread([this, key]() { + drm::LicenseManager::instance()->activate(key, get_app_name(), get_app_version()); + }); + }); + + m_activationFailedConn = drm::LicenseManager::instance()->ActivationFailed.connect( + [this](drm::LicenseManager::Exception& e) { onActivationFailed(e); }); + Close.connect([this]() { + m_activationFailedConn.disconnect(); + }); + + m_timer.start(); +} + +void EnterLicense::onBeforeClose(ui::CloseEvent& ev) { + if (m_activationInProgress) { + ev.cancel(); + } +} + +void EnterLicense::onActivationFailed(drm::LicenseManager::Exception& e) { + ui::execute_from_ui_thread([this, e]() { + if (m_activation.joinable()) + m_activation.join(); + setEnabled(true); + icon()->setVisible(true); + message()->setText(e.what()); + layout(); + m_activationInProgress = false; + }); +} + + +} \ No newline at end of file diff --git a/src/app/ui/enter_license.h b/src/app/ui/enter_license.h new file mode 100644 index 000000000..7d40449e6 --- /dev/null +++ b/src/app/ui/enter_license.h @@ -0,0 +1,33 @@ +// Aseprite +// Copyright (C) 2021 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifndef APP_UI_ENTER_LICENSE_H_INCLUDED +#define APP_UI_ENTER_LICENSE_H_INCLUDED +#pragma once + +#include "drm/license_manager.h" +#include "enter_license.xml.h" + +namespace app { + +class EnterLicense : public app::gen::EnterLicense { +public: + EnterLicense(); + +protected: + void onBeforeClose(ui::CloseEvent& ev) override; + void onActivationFailed(drm::LicenseManager::Exception& e); + +private: + std::thread m_activation; + ui::Timer m_timer; + bool m_activationInProgress; + obs::connection m_activationFailedConn; +}; + +} + +#endif