diff --git a/sources/awesome-widget/plugin/awformatterconfig.cpp b/sources/awesome-widget/plugin/awformatterconfig.cpp index d4dd856..f2f1471 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.cpp +++ b/sources/awesome-widget/plugin/awformatterconfig.cpp @@ -20,6 +20,8 @@ #include +#include + #include "awabstractselector.h" #include "awdebug.h" #include "awformatterhelper.h" @@ -33,10 +35,13 @@ AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys) qCDebug(LOG_AW) << __PRETTY_FUNCTION__; ui->setupUi(this); + editButton = ui->buttonBox->addButton(i18n("Edit"), + QDialogButtonBox::ActionRole); init(); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(editButton, SIGNAL(clicked(bool)), this, SLOT(editFormatters())); } @@ -53,21 +58,20 @@ AWFormatterConfig::~AWFormatterConfig() void AWFormatterConfig::showDialog() { - clearSelectors(); - QHash appliedFormatters = m_helper->getFormatters(); - auto keys = initKeys(); - - for (auto key : appliedFormatters.keys()) - addSelector(keys.first, keys.second, - QPair(key, appliedFormatters[key])); - // empty one - addSelector(keys.first, keys.second, QPair()); - + // update dialog + updateDialog(); // exec dialog return execDialog(); } +void AWFormatterConfig::editFormatters() +{ + m_helper->editItems(); + updateDialog(); +} + + void AWFormatterConfig::updateUi() { QPair current @@ -108,9 +112,12 @@ void AWFormatterConfig::addSelector(const QStringList &keys, void AWFormatterConfig::clearSelectors() { - for (auto selector : m_selectors) + for (auto selector : m_selectors) { disconnect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi())); + ui->verticalLayout->removeWidget(selector); + selector->deleteLater(); + } m_selectors.clear(); } @@ -121,7 +128,7 @@ void AWFormatterConfig::execDialog() QHash data; for (auto selector : m_selectors) { QPair select = selector->current(); - if ((select.first.isEmpty()) || (select.second.isEmpty())) + if (select.first.isEmpty()) continue; data[select.first] = select.second; } @@ -133,6 +140,7 @@ void AWFormatterConfig::execDialog() case 1: default: m_helper->writeFormatters(data); + m_helper->writeFormatters(data.keys()); break; } } @@ -157,3 +165,17 @@ QPair AWFormatterConfig::initKeys() const return QPair(keys, knownFormatters); } + + +void AWFormatterConfig::updateDialog() +{ + clearSelectors(); + QHash appliedFormatters = m_helper->getFormatters(); + auto keys = initKeys(); + + for (auto key : appliedFormatters.keys()) + addSelector(keys.first, keys.second, + QPair(key, appliedFormatters[key])); + // empty one + addSelector(keys.first, keys.second, QPair()); +} diff --git a/sources/awesome-widget/plugin/awformatterconfig.h b/sources/awesome-widget/plugin/awformatterconfig.h index b04cbaa..65a6382 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.h +++ b/sources/awesome-widget/plugin/awformatterconfig.h @@ -40,9 +40,11 @@ public: Q_INVOKABLE void showDialog(); private slots: + void editFormatters(); void updateUi(); private: + QPushButton *editButton = nullptr; Ui::AWFormatterConfig *ui = nullptr; AWFormatterHelper *m_helper = nullptr; QList m_selectors; @@ -55,6 +57,7 @@ private: void execDialog(); void init(); QPair initKeys() const; + void updateDialog(); }; diff --git a/sources/awesome-widget/plugin/awformatterhelper.cpp b/sources/awesome-widget/plugin/awformatterhelper.cpp index a0349b8..37f3426 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.cpp +++ b/sources/awesome-widget/plugin/awformatterhelper.cpp @@ -90,6 +90,31 @@ QStringList AWFormatterHelper::knownFormatters() const } +bool AWFormatterHelper::writeFormatters(const QStringList keys) const +{ + qCDebug(LOG_AW) << "Remove formatters" << keys; + + QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini") + .arg(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation)); + QSettings settings(fileName, QSettings::IniFormat); + qCInfo(LOG_AW) << "Configuration file" << fileName; + + settings.beginGroup(QString("Formatters")); + QStringList foundKeys = settings.childKeys(); + for (auto key : foundKeys) { + if (keys.contains(key)) + continue; + settings.remove(key); + } + settings.endGroup(); + + settings.sync(); + + return (settings.status() == QSettings::NoError); +} + + bool AWFormatterHelper::writeFormatters( const QHash configuration) const { @@ -112,6 +137,14 @@ bool AWFormatterHelper::writeFormatters( } +void AWFormatterHelper::editItems() +{ + repaintList(); + int ret = exec(); + qCInfo(LOG_AW) << "Dialog returns" << ret; +} + + AWFormatterHelper::FormatterClass AWFormatterHelper::defineFormatterClass(const QString stringType) const { @@ -193,9 +226,14 @@ void AWFormatterHelper::initKeys() QString name = settings.value(key).toString(); qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key << "in" << settings.fileName(); + if (name.isEmpty()) { + qCInfo(LOG_AW) << "Skip empty formatter for" << key; + continue; + } if (!m_formattersClasses.contains(name)) { qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" << key; + continue; } m_formatters[key] = m_formattersClasses[name]; } diff --git a/sources/awesome-widget/plugin/awformatterhelper.h b/sources/awesome-widget/plugin/awformatterhelper.h index 657871e..5b9f349 100644 --- a/sources/awesome-widget/plugin/awformatterhelper.h +++ b/sources/awesome-widget/plugin/awformatterhelper.h @@ -38,8 +38,12 @@ public: QHash getFormatters() const; QList items() const; QStringList knownFormatters() const; + bool writeFormatters(const QStringList keys) const; bool writeFormatters(const QHash configuration) const; +public slots: + void editItems(); + private: // methods AWFormatterHelper::FormatterClass diff --git a/sources/translations/awesome-widgets.pot b/sources/translations/awesome-widgets.pot index d2da3a6..ca0a5dc 100644 --- a/sources/translations/awesome-widgets.pot +++ b/sources/translations/awesome-widgets.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -441,6 +441,9 @@ msgstr "" msgid "Network device has been changed to %1" msgstr "" +msgid "Edit" +msgstr "" + msgid "Select type" msgstr "" diff --git a/sources/translations/en.po b/sources/translations/en.po index 4d8602a..82b3a59 100644 --- a/sources/translations/en.po +++ b/sources/translations/en.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-16 14:14+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: English \n" @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<" -"=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Lokalize 2.0\n" msgid "Widget" @@ -446,6 +446,9 @@ msgstr "High GPU load" msgid "Network device has been changed to %1" msgstr "Network device has been changed to %1" +msgid "Edit" +msgstr "Edit" + msgid "Select type" msgstr "Select type" @@ -723,9 +726,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Check for updates" #~ msgstr "Check for updates" -#~ msgid "Edit" -#~ msgstr "Edit" - #~ msgid "Enable popup on mouse click" #~ msgstr "Enable popup on mouse click" diff --git a/sources/translations/es.po b/sources/translations/es.po index 3a43ac6..af5d59b 100644 --- a/sources/translations/es.po +++ b/sources/translations/es.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-03 06:47+0000\n" "Last-Translator: Ernesto Avilés Vázquez \n" "Language-Team: Spanish (http://www.transifex.com/arcanis/awesome-widgets/" @@ -449,6 +449,10 @@ msgstr "Carga alta de GPU" msgid "Network device has been changed to %1" msgstr "El dispositivo de red ha sido cambiado a %1" +#, fuzzy +msgid "Edit" +msgstr "Editar barras" + #, fuzzy msgid "Select type" msgstr "Elegir etiqueta" diff --git a/sources/translations/fr.po b/sources/translations/fr.po index 8e53115..7635fce 100644 --- a/sources/translations/fr.po +++ b/sources/translations/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:16+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: French \n" @@ -462,6 +462,10 @@ msgstr "Haute charge GPU" msgid "Network device has been changed to %1" msgstr "L'interface réseau à été changée en %1" +#, fuzzy +msgid "Edit" +msgstr "Modifiable" + #, fuzzy msgid "Select type" msgstr "Sélectionner l'étiquette" @@ -746,10 +750,6 @@ msgstr "esalexeev@gmail.com mermouy@gmail.com" #~ msgid "Update text" #~ msgstr "Mettre à jour le texte" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "Modifiable" - #~ msgid "Enable popup on mouse click" #~ msgstr "Popup lors d'un click souris" diff --git a/sources/translations/nl_NL.po b/sources/translations/nl_NL.po index eef4dba..ca5f9ec 100644 --- a/sources/translations/nl_NL.po +++ b/sources/translations/nl_NL.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-08-20 22:52+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Dutch \n" @@ -468,6 +468,9 @@ msgstr "Hoog CPU-verbruik" msgid "Network device has been changed to %1" msgstr "Het netwerkapparaat is gewijzigd naar %1" +msgid "Edit" +msgstr "Bewerken" + #, fuzzy msgid "Select type" msgstr "Sleutelwoord selecteren" @@ -746,9 +749,6 @@ msgstr "vistausss@outlook.com" #~ msgid "Exec: %1" #~ msgstr "Uitvoeren: %1" -#~ msgid "Edit" -#~ msgstr "Bewerken" - #~ msgid "Select color" #~ msgstr "Kleur selecteren" diff --git a/sources/translations/pl.po b/sources/translations/pl.po index ad911ee..8e17d6c 100644 --- a/sources/translations/pl.po +++ b/sources/translations/pl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -447,6 +447,10 @@ msgstr "Wysokie obciążenie procesora graficznego" msgid "Network device has been changed to %1" msgstr "Urządznie sieciowe zamienione na %1" +#, fuzzy +msgid "Edit" +msgstr "Edytuj paski postępu" + #, fuzzy msgid "Select type" msgstr "Wybierz znacznik" diff --git a/sources/translations/pt_BR.po b/sources/translations/pt_BR.po index b84f23e..e22880f 100644 --- a/sources/translations/pt_BR.po +++ b/sources/translations/pt_BR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:21+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -463,6 +463,9 @@ msgstr "Alta carga da GPU" msgid "Network device has been changed to %1" msgstr "O dispositivo de rede mudou para %1" +msgid "Edit" +msgstr "Editar" + #, fuzzy msgid "Select type" msgstr "Selecionar tag" @@ -737,9 +740,6 @@ msgstr "under@insicuri.net" #~ msgid "Check for updates" #~ msgstr "Checar por atualizações" -#~ msgid "Edit" -#~ msgstr "Editar" - #~ msgid "Enable popup on mouse click" #~ msgstr "Ativar popup no clique do mouse" diff --git a/sources/translations/ru.po b/sources/translations/ru.po index 7b72394..bf6c14c 100644 --- a/sources/translations/ru.po +++ b/sources/translations/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-16 14:15+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<" -"=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Lokalize 2.0\n" msgid "Widget" @@ -446,6 +446,9 @@ msgstr "Высокая загрузка GPU" msgid "Network device has been changed to %1" msgstr "Сетевое устройство было изменено на %1" +msgid "Edit" +msgstr "Править" + msgid "Select type" msgstr "Выберете тип" @@ -723,9 +726,6 @@ msgstr "esalexeev@gmail.com" #~ msgid "Check for updates" #~ msgstr "Проверить обновления" -#~ msgid "Edit" -#~ msgstr "Править" - #~ msgid "Enable popup on mouse click" #~ msgstr "Включить сообщения по клику мыши" diff --git a/sources/translations/uk.po b/sources/translations/uk.po index 5f53381..be53776 100644 --- a/sources/translations/uk.po +++ b/sources/translations/uk.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2016-05-05 17:18+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Ukrainian \n" @@ -447,6 +447,10 @@ msgstr "Високе завантаження GPU" msgid "Network device has been changed to %1" msgstr "Мережевий пристрій було змінено на %1" +#, fuzzy +msgid "Edit" +msgstr "Редагувати" + #, fuzzy msgid "Select type" msgstr "Оберіть тег" @@ -726,10 +730,6 @@ msgstr "sarumyan@i.ua" #~ msgid "Check for updates" #~ msgstr "Шукати оновлення" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "Редагувати" - #~ msgid "Enable popup on mouse click" #~ msgstr "Включити спливаючі підказки при натисканні клавіші миші" diff --git a/sources/translations/zh.po b/sources/translations/zh.po index 08a45e8..894fec4 100644 --- a/sources/translations/zh.po +++ b/sources/translations/zh.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2016-05-16 14:13+0300\n" +"POT-Creation-Date: 2016-05-16 19:35+0300\n" "PO-Revision-Date: 2015-07-31 22:24+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -448,6 +448,10 @@ msgstr "高 GPU 使用" msgid "Network device has been changed to %1" msgstr "网络设备变更为 %1" +#, fuzzy +msgid "Edit" +msgstr "可编辑的" + #, fuzzy msgid "Select type" msgstr "选择标签" @@ -722,10 +726,6 @@ msgstr "用户邮箱" #~ msgid "Update text" #~ msgstr "刷新文本" -#, fuzzy -#~ msgid "Edit" -#~ msgstr "可编辑的" - #~ msgid "Enable popup on mouse click" #~ msgstr "鼠标点击时弹出对话框"