ui: Show license type label in title bar: "Sourcetrail [trial, test, non-commercial]"

This commit is contained in:
Eberhard Graether
2017-07-17 15:31:06 +02:00
parent 83e5497a18
commit 4bb88a51b7
9 changed files with 78 additions and 23 deletions
+1 -1
View File
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
}
else
{
MessageEnteredLicense().dispatch();
MessageEnteredLicense(checker->getCurrentLicenseType()).dispatch();
}
if (commandLineParser.hasError() )
+19 -4
View File
@@ -106,7 +106,7 @@ void Application::loadStyle(const FilePath& colorSchemePath)
Application::Application(bool withGUI)
: m_hasGUI(withGUI)
, m_isInTrial(true)
, m_licenseType(MessageEnteredLicense::LICENSE_NONE)
{
LicenseChecker::createInstance();
}
@@ -156,7 +156,7 @@ std::shared_ptr<DialogView> Application::getDialogView()
bool Application::isInTrial() const
{
return m_isInTrial;
return m_licenseType == MessageEnteredLicense::LICENSE_NONE;
}
void Application::updateHistory(const std::vector<SearchMatch>& history)
@@ -242,7 +242,7 @@ void Application::handleMessage(MessageEnteredLicense* message)
{
MessageStatus("Found valid license key, unlocked application.").dispatch();
m_isInTrial = false;
m_licenseType = message->type;
updateTitle();
}
@@ -381,7 +381,22 @@ void Application::updateTitle()
{
if (m_hasGUI)
{
std::string title = m_isInTrial ? "Sourcetrail [Trial]" : "Sourcetrail";
std::string title = "Sourcetrail";
switch (m_licenseType)
{
case MessageEnteredLicense::LICENSE_NONE:
title += " [trial]";
break;
case MessageEnteredLicense::LICENSE_TEST:
title += " [test]";
break;
case MessageEnteredLicense::LICENSE_NON_COMMERCIAL:
title += " [non-commercial]";
break;
case MessageEnteredLicense::LICENSE_COMMERCIAL:
break;
}
if (m_project)
{
+1 -1
View File
@@ -87,7 +87,7 @@ private:
std::shared_ptr<IDECommunicationController> m_ideCommunicationController;
bool m_isInTrial;
MessageEnteredLicense::LicenseType m_licenseType;
};
#endif // APPLICATION_H
+28
View File
@@ -128,6 +128,34 @@ LicenseChecker::LicenseState LicenseChecker::checkLicenseString(const std::strin
return checkLicense(license);
}
MessageEnteredLicense::LicenseType LicenseChecker::getCurrentLicenseType() const
{
License license;
bool isLoaded = license.loadFromEncodedString(
ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath());
if (!isLoaded)
{
return MessageEnteredLicense::LICENSE_NONE;
}
LicenseState state = checkLicense(license);
if (state != LICENSE_VALID)
{
return MessageEnteredLicense::LICENSE_NONE;
}
else if (license.isTestLicense())
{
return MessageEnteredLicense::LICENSE_TEST;
}
else if (license.isNonCommercialLicenseType())
{
return MessageEnteredLicense::LICENSE_NON_COMMERCIAL;
}
return MessageEnteredLicense::LICENSE_COMMERCIAL;
}
LicenseChecker::LicenseChecker()
: m_forcedLicenseEntering(false)
{
+2
View File
@@ -34,6 +34,8 @@ public:
LicenseState checkCurrentLicense() const;
LicenseState checkLicenseString(const std::string licenseString) const;
MessageEnteredLicense::LicenseType getCurrentLicenseType() const;
private:
LicenseChecker();
LicenseChecker(const LicenseChecker&) = delete;
@@ -7,7 +7,16 @@ class MessageEnteredLicense
: public Message<MessageEnteredLicense>
{
public:
MessageEnteredLicense()
enum LicenseType
{
LICENSE_NONE,
LICENSE_TEST,
LICENSE_NON_COMMERCIAL,
LICENSE_COMMERCIAL
};
MessageEnteredLicense(LicenseType type)
: type(type)
{
setSendAsTask(false);
}
@@ -16,6 +25,8 @@ public:
{
return "MessageEnteredLicense";
}
const LicenseType type;
};
#endif // MESSAGE_ENTERED_LICENSE_H
+2 -2
View File
@@ -426,7 +426,7 @@ void QtMainWindow::enteredLicense()
m_windowStack.clearWindows();
setTrialActionsEnabled(true);
MessageEnteredLicense().dispatch();
MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch();
if (showStartWindow)
{
@@ -451,7 +451,7 @@ void QtMainWindow::showStartScreen()
if (licenseValid)
{
MessageEnteredLicense().dispatch();
MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch();
}
setTrialActionsEnabled(licenseValid);
+12 -12
View File
@@ -150,6 +150,18 @@ bool License::isTestLicense() const
return m_type == LicenseConstants::TEST_LICENSE_STRING;
}
bool License::isNonCommercialLicenseType() const
{
for ( const std::string nonCommercialLicenseType : NON_COMMERCIAL_LICENSE_TYPES)
{
if (m_type == nonCommercialLicenseType)
{
return true;
}
}
return false;
}
unsigned int License::getSeats() const
{
return m_seats;
@@ -196,18 +208,6 @@ std::string License::getLicenseInfo() const
return info;
}
bool License::isNonCommercialLicenseType() const
{
for ( const std::string nonCommercialLicenseType : NON_COMMERCIAL_LICENSE_TYPES)
{
if (m_type == nonCommercialLicenseType)
{
return true;
}
}
return false;
}
std::string License::getUser() const
{
return m_user;
+1 -2
View File
@@ -94,6 +94,7 @@ public:
bool isValid() const;
bool isExpired() const;
bool isTestLicense() const;
bool isNonCommercialLicenseType() const;
void print();
@@ -105,8 +106,6 @@ private:
bool extractData(const std::string& string, LICENSE_LINE line);
std::string removeCaption(const std::string& line, const std::string& caption) const;
bool isNonCommercialLicenseType() const;
std::string m_publicKeyFilename;
std::shared_ptr<Botan::RSA_PublicKey> m_publicKey;