Create EnterLicense dialog

This commit is contained in:
Martín Capello 2021-09-07 16:33:27 -03:00 committed by David Capello
parent 588d8027f4
commit 2639c36b2f
6 changed files with 116 additions and 19 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
<!-- Aseprite -->
<!-- Copyright (c) 2021 Igara Studio S.A. -->
<gui>
<window id="enter_license" text="@.title" expansive="false">
<window id="enter_license" text="@.title" expansive="true">
<box vertical="true">
<hbox>
<label text="@.default_message" />
@ -9,6 +9,10 @@
</hbox>
<separator text="@.license_key" left="true" horizontal="true" />
<entry id="license_key" cell_align="horizontal" magnet="true" maxsize="17" />
<hbox>
<image id="icon" icon="warning_box" visible="false" />
<label id="message" text="" expansive="true" minheight="40" />
</hbox>
<box horizontal="true">
<box horizontal="true" expansive="true" />
<box horizontal="true" homogeneous="true">

View File

@ -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

View File

@ -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

View File

@ -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;
});
}
}

View File

@ -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