diff --git a/src/lib/utility/utilityString.cpp b/src/lib/utility/utilityString.cpp index 7477bada..9b206b10 100644 --- a/src/lib/utility/utilityString.cpp +++ b/src/lib/utility/utilityString.cpp @@ -168,4 +168,11 @@ namespace utility return str; } + + std::string trim(const std::string &str) + { + auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); }); + auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base(); + return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback)); + } } diff --git a/src/lib/utility/utilityString.h b/src/lib/utility/utilityString.h index da83083e..1f8b656a 100644 --- a/src/lib/utility/utilityString.h +++ b/src/lib/utility/utilityString.h @@ -39,6 +39,7 @@ namespace utility std::string replace(std::string str, const std::string& from, const std::string& to); + std::string trim(const std::string &str); template ContainerType split(const std::string& str, const std::string& delimiter) diff --git a/src/lib_gui/qt/window/QtLicense.cpp b/src/lib_gui/qt/window/QtLicense.cpp index 5e163634..e44bc75d 100644 --- a/src/lib_gui/qt/window/QtLicense.cpp +++ b/src/lib_gui/qt/window/QtLicense.cpp @@ -38,6 +38,16 @@ void QtLicense::clear() } } +void QtLicense::load() +{ + clear(); + + if (m_licenseText) + { + m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str()); + } +} + void QtLicense::setup() { setStyleSheet(( @@ -67,7 +77,6 @@ void QtLicense::setup() 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" diff --git a/src/lib_gui/qt/window/QtLicense.h b/src/lib_gui/qt/window/QtLicense.h index 3dbdbebe..1afc3f76 100644 --- a/src/lib_gui/qt/window/QtLicense.h +++ b/src/lib_gui/qt/window/QtLicense.h @@ -17,6 +17,7 @@ public: QSize sizeHint() const Q_DECL_OVERRIDE; void clear(); + void load(); virtual void setup() override; diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 06afd4d8..6cd80fbe 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -365,6 +365,7 @@ void QtMainWindow::enterLicense() connect(m_enterLicenseWindow.get(), SIGNAL(canceled()), this, SLOT(popWindow())); } + m_enterLicenseWindow->load(); pushWindow(m_enterLicenseWindow.get()); } diff --git a/src/lib_license/License.cpp b/src/lib_license/License.cpp index 775587ea..2db6add9 100644 --- a/src/lib_license/License.cpp +++ b/src/lib_license/License.cpp @@ -1,5 +1,6 @@ #include "License.h" +#include #include #include #include @@ -15,6 +16,16 @@ // #include "botan/rsa.h" // #endif +namespace +{ + std::string trim(const std::string &str) + { + auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); }); + auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base(); + return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback)); + } +} + License::License() { } @@ -119,9 +130,14 @@ bool License::load(std::istream& stream) { lines.clear(); std::string line; + while (getline(stream, line, '\n')) { - lines.push_back(line); + std::string l = trim(line); + if (l.size()) + { + lines.push_back(l); + } } if (lines.front() != BEGIN_LICENSE)