From 6a24fc3f63c91089380b0ed432e8eb53fd79df4c Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sun, 6 Nov 2016 22:12:03 +0300 Subject: [PATCH] more pretty about text Use generic text generation for all plasmoids --- sources/awdebug.cpp | 77 ++++++++++++++++++- sources/awdebug.h | 8 +- sources/awesome-widget/plugin/awactions.cpp | 61 +-------------- .../awesome-widget/plugin/awbugreporter.cpp | 2 +- sources/awesome-widget/plugin/awkeys.cpp | 4 +- sources/awesomewidgets/extitemaggregator.h | 4 +- sources/desktop-panel/plugin/dpadds.cpp | 66 +--------------- sources/extsysmon/extsysmon.cpp | 4 +- sources/version.h.in | 8 +- 9 files changed, 97 insertions(+), 137 deletions(-) diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 189b4ec..bbe0166 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -16,6 +16,8 @@ ***************************************************************************/ +#include + #include "awdebug.h" @@ -31,7 +33,80 @@ Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets", QtMsgType::QtWarningMsg) -const QStringList getBuildData() +QString AWDebug::getAboutText(const QString type) +{ + QString text; + if (type == QString("header")) { + text = QString(NAME); + } else if (type == QString("version")) { + text = i18n("Version %1 (build date %2)", QString(VERSION), + QString(BUILD_DATE)); + if (!QString(COMMIT_SHA).isEmpty()) + text += QString(" (%1)").arg(QString(COMMIT_SHA)); + } else if (type == QString("description")) { + text = i18n("A set of minimalistic plasmoid widgets"); + } else if (type == QString("links")) { + text = i18n("Links:") + QString(""); + } else if (type == QString("copy")) { + text = QString("© %1 %3
") + .arg(QString(DATE)) + .arg(QString(EMAIL)) + .arg(QString(AUTHOR)) + + i18n("This software is licensed under %1", QString(LICENSE)) + + QString("
"); + } else if (type == QString("translators")) { + QStringList translatorList = QString(TRANSLATORS).split(QChar(',')); + for (auto &translator : translatorList) + translator = QString("
  • %1
  • ").arg(translator); + text = i18n("Translators:") + QString(""); + } else if (type == QString("3rdparty")) { + QStringList trdPartyList + = QString(TRDPARTY_LICENSE) + .split(QChar(';'), QString::SkipEmptyParts); + for (int i = 0; i < trdPartyList.count(); i++) + trdPartyList[i] + = QString("
  • %1 (%2 license)
  • ") + .arg(trdPartyList.at(i).split(QChar(','))[0]) + .arg(trdPartyList.at(i).split(QChar(','))[1]) + .arg(trdPartyList.at(i).split(QChar(','))[2]); + text = i18n("This software uses:") + QString(""); + } else if (type == QString("thanks")) { + QStringList thanks = QString(SPECIAL_THANKS) + .split(QChar(';'), QString::SkipEmptyParts); + for (int i = 0; i < thanks.count(); i++) + thanks[i] = QString("
  • %1
  • ") + .arg(thanks.at(i).split(QChar(','))[0]) + .arg(thanks.at(i).split(QChar(','))[1]); + text = i18n("Special thanks to:") + QString(""); + } + + return text; +} + + +QStringList AWDebug::getBuildData() { QStringList metadata; metadata.append(QString("=== Awesome Widgets configuration details ===")); diff --git a/sources/awdebug.h b/sources/awdebug.h index 1f5d6ed..f24dab0 100644 --- a/sources/awdebug.h +++ b/sources/awdebug.h @@ -23,12 +23,18 @@ #include "version.h" +namespace AWDebug +{ const char LOG_FORMAT[] = "[%{time " "process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%" "{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-" "fatal}FF%{endif}][%{category}][%{function}] " "%{message}"; +QString getAboutText(const QString type); +QStringList getBuildData(); +} + Q_DECLARE_LOGGING_CATEGORY(LOG_AW) Q_DECLARE_LOGGING_CATEGORY(LOG_DBUS) @@ -37,7 +43,5 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_ESM) Q_DECLARE_LOGGING_CATEGORY(LOG_ESS) Q_DECLARE_LOGGING_CATEGORY(LOG_LIB) -const QStringList getBuildData(); - #endif /* AWDEBUG_H */ diff --git a/sources/awesome-widget/plugin/awactions.cpp b/sources/awesome-widget/plugin/awactions.cpp index e87ef7f..af3b50d 100644 --- a/sources/awesome-widget/plugin/awactions.cpp +++ b/sources/awesome-widget/plugin/awactions.cpp @@ -118,66 +118,7 @@ QString AWActions::getAboutText(const QString type) const { qCDebug(LOG_AW) << "Type" << type; - QString text; - if (type == QString("header")) { - text = QString(NAME); - } else if (type == QString("version")) { - text = i18n("Version %1 (build date %2)", QString(VERSION), - QString(BUILD_DATE)); - if (!QString(COMMIT_SHA).isEmpty()) - text += QString(" (%1)").arg(QString(COMMIT_SHA)); - } else if (type == QString("description")) { - text = i18n("A set of minimalistic plasmoid widgets"); - } else if (type == QString("links")) { - text = i18n("Links:") + QString("
    ") - + QString("%2
    ") - .arg(QString(HOMEPAGE)) - .arg(i18n("Homepage")) - + QString("%2
    ") - .arg(QString(REPOSITORY)) - .arg(i18n("Repository")) - + QString("%2
    ") - .arg(QString(BUGTRACKER)) - .arg(i18n("Bugtracker")) - + QString("%2
    ") - .arg(QString(TRANSLATION)) - .arg(i18n("Translation issue")) - + QString("%2
    ") - .arg(QString(AUR_PACKAGES)) - .arg(i18n("AUR packages")) - + QString("%2") - .arg(QString(OPENSUSE_PACKAGES)) - .arg(i18n("openSUSE packages")); - } else if (type == QString("copy")) { - text = QString("© %1 %3
    ") - .arg(QString(DATE)) - .arg(QString(EMAIL)) - .arg(QString(AUTHOR)) - + i18n("This software is licensed under %1", QString(LICENSE)) - + QString("
    "); - } else if (type == QString("translators")) { - text = i18n("Translators: %1", QString(TRANSLATORS)); - } else if (type == QString("3rdparty")) { - QStringList trdPartyList - = QString(TRDPARTY_LICENSE) - .split(QChar(';'), QString::SkipEmptyParts); - for (int i = 0; i < trdPartyList.count(); i++) - trdPartyList[i] = QString("%1 (%2 license)") - .arg(trdPartyList.at(i).split(QChar(','))[0]) - .arg(trdPartyList.at(i).split(QChar(','))[1]) - .arg(trdPartyList.at(i).split(QChar(','))[2]); - text = i18n("This software uses: %1", trdPartyList.join(QString(", "))); - } else if (type == QString("thanks")) { - QStringList thanks = QString(SPECIAL_THANKS) - .split(QChar(';'), QString::SkipEmptyParts); - for (int i = 0; i < thanks.count(); i++) - thanks[i] = QString("%1") - .arg(thanks.at(i).split(QChar(','))[0]) - .arg(thanks.at(i).split(QChar(','))[1]); - text = i18n("Special thanks to %1", thanks.join(QString(", "))); - } - - return text; + return AWDebug::getAboutText(type); } diff --git a/sources/awesome-widget/plugin/awbugreporter.cpp b/sources/awesome-widget/plugin/awbugreporter.cpp index 8d98af4..cbc8ed1 100644 --- a/sources/awesome-widget/plugin/awbugreporter.cpp +++ b/sources/awesome-widget/plugin/awbugreporter.cpp @@ -66,7 +66,7 @@ QString AWBugReporter::generateText(const QString description, output += QString("**Step to reproduce**\n\n%1\n\n").arg(reproduce); output += QString("**Expected result**\n\n%1\n\n").arg(expected); output += QString("**Version**\n\n%1\n\n") - .arg(getBuildData().join(QString("\n"))); + .arg(AWDebug::getBuildData().join(QString("\n"))); // append logs output += QString("**Logs**\n\n%1").arg(logs); diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 6a05524..e420e7b 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -38,9 +38,9 @@ AWKeys::AWKeys(QObject *parent) : QObject(parent) { - qSetMessagePattern(LOG_FORMAT); + qSetMessagePattern(AWDebug::LOG_FORMAT); qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - for (auto metadata : getBuildData()) + for (auto &metadata : AWDebug::getBuildData()) qCDebug(LOG_AW) << metadata; // thread pool diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 7549383..78fe313 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -34,9 +34,9 @@ public: explicit ExtItemAggregator(QWidget *parent, const QString type) : AbstractExtItemAggregator(parent, type) { - qSetMessagePattern(LOG_FORMAT); + qSetMessagePattern(AWDebug::LOG_FORMAT); qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - for (auto metadata : getBuildData()) + for (auto &metadata : AWDebug::getBuildData()) qCDebug(LOG_LIB) << metadata; qCDebug(LOG_LIB) << "Type" << type; diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 9161025..791c825 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -39,9 +39,9 @@ DPAdds::DPAdds(QObject *parent) : QObject(parent) { - qSetMessagePattern(LOG_FORMAT); + qSetMessagePattern(AWDebug::LOG_FORMAT); qCDebug(LOG_DP) << __PRETTY_FUNCTION__; - for (auto metadata : getBuildData()) + for (auto &metadata : AWDebug::getBuildData()) qCDebug(LOG_DP) << metadata; connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, @@ -262,67 +262,7 @@ QString DPAdds::getAboutText(const QString type) const { qCDebug(LOG_DP) << "Type" << type; - QString text; - if (type == QString("header")) { - text = QString(NAME); - } else if (type == QString("version")) { - text = i18n("Version %1 (build date %2)", QString(VERSION), - QString(BUILD_DATE)); - if (!QString(COMMIT_SHA).isEmpty()) - text += QString(" (%1)").arg(QString(COMMIT_SHA)); - } else if (type == QString("description")) { - text = i18n("A set of minimalistic plasmoid widgets"); - } else if (type == QString("links")) { - text = i18n("Links:") + QString("
    ") - + QString("%2
    ") - .arg(QString(HOMEPAGE)) - .arg(i18n("Homepage")) - + QString("%2
    ") - .arg(QString(REPOSITORY)) - .arg(i18n("Repository")) - + QString("%2
    ") - .arg(QString(BUGTRACKER)) - .arg(i18n("Bugtracker")) - + QString("%2
    ") - .arg(QString(TRANSLATION)) - .arg(i18n("Translation issue")) - + QString("%2
    ") - .arg(QString(AUR_PACKAGES)) - .arg(i18n("AUR packages")) - + QString("%2") - .arg(QString(OPENSUSE_PACKAGES)) - .arg(i18n("openSUSE packages")); - } else if (type == QString("copy")) { - text = QString("© %1 %3
    ") - .arg(QString(DATE)) - .arg(QString(EMAIL)) - .arg(QString(AUTHOR)) - + i18n("This software is licensed under %1", QString(LICENSE)) - + QString("
    "); - } else if (type == QString("translators")) { - text = i18n("Translators: %1", QString(TRANSLATORS)); - } else if (type == QString("3rdparty")) { - QStringList trdPartyList - = QString(TRDPARTY_LICENSE) - .split(QChar(';'), QString::SkipEmptyParts); - for (int i = 0; i < trdPartyList.count(); i++) - trdPartyList[i] - = QString("%1 (%2 license)") - .arg(trdPartyList.at(i).split(QChar(',')).at(0)) - .arg(trdPartyList.at(i).split(QChar(',')).at(1)) - .arg(trdPartyList.at(i).split(QChar(',')).at(2)); - text = i18n("This software uses: %1", trdPartyList.join(QString(", "))); - } else if (type == QString("thanks")) { - QStringList thanks = QString(SPECIAL_THANKS) - .split(QChar(';'), QString::SkipEmptyParts); - for (int i = 0; i < thanks.count(); i++) - thanks[i] = QString("%1") - .arg(thanks.at(i).split(QChar(','))[0]) - .arg(thanks.at(i).split(QChar(','))[1]); - text = i18n("Special thanks to %1", thanks.join(QString(", "))); - } - - return text; + return AWDebug::getAboutText(type); } diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 154289f..4b0b579 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -32,9 +32,9 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args) : Plasma::DataEngine(parent, args) { Q_UNUSED(args) - qSetMessagePattern(LOG_FORMAT); + qSetMessagePattern(AWDebug::LOG_FORMAT); qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; - for (auto metadata : getBuildData()) + for (auto &metadata : AWDebug::getBuildData()) qCDebug(LOG_ESM) << metadata; setMinimumPollingInterval(333); diff --git a/sources/version.h.in b/sources/version.h.in index 866127a..1553427 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -7,10 +7,10 @@ const char NAME[] = "Awesome Widgets"; const char VERSION[] = "@PROJECT_VERSION@"; const char COMMIT_SHA[] = "@PROJECT_COMMIT_SHA@"; const char AUTHOR[] = "@PROJECT_AUTHOR@"; -const char TRANSLATORS[] = "Ernesto Aviles Vzqz (Spanish), Mermouy (French), " - "underr (Brazillian Portuguese), Viktor Slobodyan " - "(Ukrainian), Lemueler (Chinese), Heimen Stoffels " - "(Dutch), Mariusz Kocoń (Polish)"; +const char TRANSLATORS[] = "Ernesto Aviles Vzqz (Spanish),Mermouy " + "(French),underr (Brazillian Portuguese),Viktor " + "Slobodyan (Ukrainian),Lemueler (Chinese),Heimen " + "Stoffels (Dutch), Mariusz Kocoń (Polish)"; const char EMAIL[] = "@PROJECT_CONTACT@"; const char LICENSE[] = "@PROJECT_LICENSE@"; const char TRDPARTY_LICENSE[] = "QReplyTimeout "