diff --git a/sources/.kdev4/awesomewidgets.kdev4 b/sources/.kdev4/awesomewidgets.kdev4 index b97529b..ea73c1d 100644 --- a/sources/.kdev4/awesomewidgets.kdev4 +++ b/sources/.kdev4/awesomewidgets.kdev4 @@ -8,7 +8,7 @@ ProjectRootRelative=./ [CMake][CMake Build Directory 0] Build Directory Path=file:///home/arcanis/Documents/github/awesome-widgets/build -Build Type=Debug +Build Type=Release CMake Binary=file:///usr/bin/cmake Environment Profile= Extra Arguments= diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index bd99daa..7437b8f 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -53,22 +52,12 @@ AWKeys::AWKeys(QObject *parent) debug = (debugEnv == QString("yes")); // backend + graphicalItems = new ExtItemAggregator(nullptr, QString("desktops"), debug); + extQuotes = new ExtItemAggregator(nullptr, QString("quotes"), debug); + extScripts = new ExtItemAggregator(nullptr, QString("scripts"), debug); + extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade"), debug); + extWeather = new ExtItemAggregator(nullptr, QString("weather"), debug); connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate())); - - // init dialog - dialog = new QDialog(nullptr); - widgetDialog = new QListWidget(dialog); - dialogButtons = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Close, - Qt::Vertical, dialog); - copyButton = dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole); - createButton = dialogButtons->addButton(i18n("Create"), QDialogButtonBox::ActionRole); - deleteButton = dialogButtons->addButton(i18n("Remove"), QDialogButtonBox::ActionRole); - QHBoxLayout *layout = new QHBoxLayout(dialog); - layout->addWidget(widgetDialog); - layout->addWidget(dialogButtons); - dialog->setLayout(layout); - connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this, SLOT(editItemButtonPressed(QAbstractButton *))); - connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject())); } @@ -77,12 +66,12 @@ AWKeys::~AWKeys() if (debug) qDebug() << PDEBUG; delete toolTip; - delete dialog; - graphicalItems.clear(); - extScripts.clear(); - extUpgrade.clear(); - extWeather.clear(); + delete graphicalItems; + delete extQuotes; + delete extScripts; + delete extUpgrade; + delete extWeather; } @@ -91,21 +80,12 @@ void AWKeys::initKeys(const QString currentPattern) if (debug) qDebug() << PDEBUG; // clear - extQuotes.clear(); - extScripts.clear(); - extUpgrade.clear(); - graphicalItems.clear(); keys.clear(); foundBars.clear(); foundKeys.clear(); // init pattern = currentPattern; - extQuotes = getExtQuotes(); - extScripts = getExtScripts(); - extUpgrade = getExtUpgrade(); - extWeather = getExtWeather(); - graphicalItems = getGraphicalItems(); // update network and hdd list addKeyToCache(QString("Hdd")); addKeyToCache(QString("Network")); @@ -283,27 +263,27 @@ QStringList AWKeys::dictKeys(const bool sorted) const allKeys.append(QString("pstotal")); allKeys.append(QString("ps")); // package manager - for (int i=extUpgrade.count()-1; i>=0; i--) { - if (!extUpgrade[i]->isActive()) continue; - allKeys.append(extUpgrade[i]->tag(QString("pkgcount"))); + for (int i=extUpgrade->items().count()-1; i>=0; i--) { + if (!extUpgrade->items()[i]->isActive()) continue; + allKeys.append(extUpgrade->items()[i]->tag(QString("pkgcount"))); } // quotes - for (int i=extQuotes.count()-1; i>=0; i--) { - if (!extQuotes[i]->isActive()) continue; - allKeys.append(extQuotes[i]->tag(QString("ask"))); - allKeys.append(extQuotes[i]->tag(QString("askchg"))); - allKeys.append(extQuotes[i]->tag(QString("percaskchg"))); - allKeys.append(extQuotes[i]->tag(QString("bid"))); - allKeys.append(extQuotes[i]->tag(QString("bidchg"))); - allKeys.append(extQuotes[i]->tag(QString("percbidchg"))); - allKeys.append(extQuotes[i]->tag(QString("price"))); - allKeys.append(extQuotes[i]->tag(QString("pricechg"))); - allKeys.append(extQuotes[i]->tag(QString("percpricechg"))); + for (int i=extQuotes->items().count()-1; i>=0; i--) { + if (!extQuotes->items()[i]->isActive()) continue; + allKeys.append(extQuotes->items()[i]->tag(QString("ask"))); + allKeys.append(extQuotes->items()[i]->tag(QString("askchg"))); + allKeys.append(extQuotes->items()[i]->tag(QString("percaskchg"))); + allKeys.append(extQuotes->items()[i]->tag(QString("bid"))); + allKeys.append(extQuotes->items()[i]->tag(QString("bidchg"))); + allKeys.append(extQuotes->items()[i]->tag(QString("percbidchg"))); + allKeys.append(extQuotes->items()[i]->tag(QString("price"))); + allKeys.append(extQuotes->items()[i]->tag(QString("pricechg"))); + allKeys.append(extQuotes->items()[i]->tag(QString("percpricechg"))); } // custom - for (int i=extScripts.count()-1; i>=0; i--) { - if (!extScripts[i]->isActive()) continue; - allKeys.append(extScripts[i]->tag(QString("custom"))); + for (int i=extScripts->items().count()-1; i>=0; i--) { + if (!extScripts->items()[i]->isActive()) continue; + allKeys.append(extScripts->items()[i]->tag(QString("custom"))); } // desktop allKeys.append(QString("desktop")); @@ -314,20 +294,20 @@ QStringList AWKeys::dictKeys(const bool sorted) const allKeys.append(QString("la5")); allKeys.append(QString("la1")); // weather - for (int i=extWeather.count()-1; i>=0; i--) { - if (!extWeather[i]->isActive()) continue; - allKeys.append(extWeather[i]->tag(QString("weatherId"))); - allKeys.append(extWeather[i]->tag(QString("weather"))); - allKeys.append(extWeather[i]->tag(QString("humidity"))); - allKeys.append(extWeather[i]->tag(QString("pressure"))); - allKeys.append(extWeather[i]->tag(QString("temperature"))); - allKeys.append(extWeather[i]->tag(QString("timestamp"))); + for (int i=extWeather->items().count()-1; i>=0; i--) { + if (!extWeather->items()[i]->isActive()) continue; + allKeys.append(extWeather->items()[i]->tag(QString("weatherId"))); + allKeys.append(extWeather->items()[i]->tag(QString("weather"))); + allKeys.append(extWeather->items()[i]->tag(QString("humidity"))); + allKeys.append(extWeather->items()[i]->tag(QString("pressure"))); + allKeys.append(extWeather->items()[i]->tag(QString("temperature"))); + allKeys.append(extWeather->items()[i]->tag(QString("timestamp"))); } // bars QStringList graphicalItemsKeys; - for (int i=0; iname()) - .arg(graphicalItems[i]->bar())); + for (int i=0; iitems().count(); i++) + graphicalItemsKeys.append(QString("%1%2").arg(graphicalItems->items()[i]->name()) + .arg(graphicalItems->items()[i]->bar())); graphicalItemsKeys.sort(); for (int i=graphicalItemsKeys.count()-1; i>=0; i--) allKeys.append(graphicalItemsKeys[i]); @@ -713,9 +693,9 @@ QString AWKeys::infoByKey(QString key) const key.remove(QRegExp(QString("^bar[0-9]{1,}"))); if (key.startsWith(QString("custom"))) - for (int i=0; itag(QString("custom")) != key) continue; - return extScripts[i]->executable(); + for (int i=0; iitems().count(); i++) { + if (extScripts->items()[i]->tag(QString("custom")) != key) continue; + return extScripts->items()[i]->executable(); } else if (key.contains(QRegExp(QString("^hdd[rw]")))) return QString("%1").arg(diskDevices[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); @@ -726,14 +706,14 @@ QString AWKeys::infoByKey(QString key) const else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) return QString("%1").arg(networkDevices[key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) - for (int i=0; itag(QString("pkgcount")) != key) continue; - return extUpgrade[i]->executable(); + for (int i=0; iitems().count(); i++) { + if (extUpgrade->items()[i]->tag(QString("pkgcount")) != key) continue; + return extUpgrade->items()[i]->executable(); } else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) - for (int i=0; inumber() != key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt()) continue; - return extQuotes[i]->ticker(); + for (int i=0; iitems().count(); i++) { + if (extQuotes->items()[i]->number() != key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt()) continue; + return extQuotes->items()[i]->ticker(); } else if (key.startsWith(QString("temp"))) return QString("%1").arg(tempDevices[key.remove(QString("temp")).toInt()]); @@ -757,68 +737,25 @@ void AWKeys::editItem(const QString type) { if (debug) qDebug() << PDEBUG; - widgetDialog->clear(); if (type == QString("graphicalitem")) { - requestedItem = RequestedGraphicalItem; - for (int i=0; ifileName()); - QStringList tooltip; - tooltip.append(i18n("Tag: %1", graphicalItems[i]->name() + graphicalItems[i]->bar())); - tooltip.append(i18n("Comment: %1", graphicalItems[i]->comment())); - item->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(item); - } + QStringList bars; + bars.append(keys.filter((QRegExp(QString("^cpu(?!cl).*"))))); + bars.append(keys.filter((QRegExp(QString("^gpu$"))))); + bars.append(keys.filter((QRegExp(QString("^mem$"))))); + bars.append(keys.filter((QRegExp(QString("^swap$"))))); + bars.append(keys.filter((QRegExp(QString("^hdd[0-9].*"))))); + bars.append(keys.filter((QRegExp(QString("^bat.*"))))); + graphicalItems->setConfigArgs(bars); + return graphicalItems->editItems(); } else if (type == QString("extquotes")) { - requestedItem = RequestedExtQuotes; - for (int i=0; ifileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", extQuotes[i]->name())); - tooltip.append(i18n("Comment: %1", extQuotes[i]->comment())); - tooltip.append(i18n("Ticker: %1", extQuotes[i]->ticker())); - item->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(item); - } + return extQuotes->editItems(); } else if (type == QString("extscript")) { - requestedItem = RequestedExtScript; - for (int i=0; ifileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", extScripts[i]->name())); - tooltip.append(i18n("Comment: %1", extScripts[i]->comment())); - tooltip.append(i18n("Exec: %1", extScripts[i]->executable())); - item->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(item); - } + return extScripts->editItems(); } else if (type == QString("extupgrade")) { - requestedItem = RequestedExtUpgrade; - for (int i=0; ifileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", extUpgrade[i]->name())); - tooltip.append(i18n("Comment: %1", extUpgrade[i]->comment())); - tooltip.append(i18n("Exec: %1", extUpgrade[i]->executable())); - item->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(item); - } + return extUpgrade->editItems(); } else if (type == QString("extweather")) { - requestedItem = RequestedExtWeather; - for (int i=0; ifileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", extWeather[i]->name())); - tooltip.append(i18n("Comment: %1", extWeather[i]->comment())); - tooltip.append(i18n("City: %1", extWeather[i]->city())); - tooltip.append(i18n("Country: %1", extWeather[i]->country())); - tooltip.append(i18n("Time: %1", extWeather[i]->ts())); - item->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(item); - } + return extQuotes->editItems(); } - - int ret = dialog->exec(); - if (debug) qDebug() << PDEBUG << ":" << "Dialog returns" << ret; - requestedItem = Nothing; } @@ -888,463 +825,6 @@ void AWKeys::reinitKeys() } -void AWKeys::editItemButtonPressed(QAbstractButton *button) -{ - if (debug) qDebug() << PDEBUG; - - QListWidgetItem *item = widgetDialog->currentItem(); - if (dynamic_cast(button) == copyButton) { - if (item == nullptr) return; - QString current = item->text(); - switch (requestedItem) { - case RequestedExtQuotes: - copyQuotes(current); - break; - case RequestedExtScript: - copyScript(current); - break; - case RequestedExtUpgrade: - copyUpgrade(current); - break; - case RequestedExtWeather: - copyWeather(current); - break; - case RequestedGraphicalItem: - copyBar(current); - break; - case Nothing: - default: - break; - } - } else if (dynamic_cast(button) == createButton) { - switch (requestedItem) { - case RequestedExtQuotes: - copyQuotes(QString("")); - break; - case RequestedExtScript: - copyScript(QString("")); - break; - case RequestedExtUpgrade: - copyUpgrade(QString("")); - break; - case RequestedExtWeather: - copyWeather(QString("")); - break; - case RequestedGraphicalItem: - copyBar(QString("")); - break; - case Nothing: - default: - break; - } - } else if (dynamic_cast(button) == deleteButton) { - if (item == nullptr) return; - QString current = item->text(); - switch (requestedItem) { - case RequestedExtQuotes: - for (int i=0; ifileName() != current) continue; - if (extQuotes[i]->tryDelete()) { - widgetDialog->takeItem(widgetDialog->row(item)); - extQuotes.clear(); - extQuotes = getExtQuotes(); - } - break; - } - break; - case RequestedExtScript: - for (int i=0; ifileName() != current) continue; - if (extScripts[i]->tryDelete()) { - widgetDialog->takeItem(widgetDialog->row(item)); - extScripts.clear(); - extScripts = getExtScripts(); - } - break; - } - break; - case RequestedExtUpgrade: - for (int i=0; ifileName() != current) continue; - if (extUpgrade[i]->tryDelete()) { - widgetDialog->takeItem(widgetDialog->row(item)); - extUpgrade.clear(); - extUpgrade = getExtUpgrade(); - } - break; - } - break; - case RequestedExtWeather: - for (int i=0; ifileName() != current) continue; - if (extWeather[i]->tryDelete()) { - widgetDialog->takeItem(widgetDialog->row(item)); - extWeather.clear(); - extWeather = getExtWeather(); - } - break; - } - break; - case RequestedGraphicalItem: - for (int i=0; ifileName() != current) continue; - if (graphicalItems[i]->tryDelete()) { - widgetDialog->takeItem(widgetDialog->row(item)); - graphicalItems.clear(); - graphicalItems = getGraphicalItems(); - } - break; - } - break; - case Nothing: - default: - break; - } - } else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) { - if (item == nullptr) return; - QString current = item->text(); - switch (requestedItem) { - case RequestedExtQuotes: - for (int i=0; ifileName() != current) continue; - extQuotes[i]->showConfiguration(); - break; - } - break; - case RequestedExtScript: - for (int i=0; ifileName() != current) continue; - extScripts[i]->showConfiguration(); - break; - } - break; - case RequestedExtUpgrade: - for (int i=0; ifileName() != current) continue; - extUpgrade[i]->showConfiguration(); - break; - } - break; - case RequestedExtWeather: - for (int i=0; ifileName() != current) continue; - extWeather[i]->showConfiguration(); - break; - } - break; - case RequestedGraphicalItem: - for (int i=0; ifileName() != current) continue; - graphicalItems[i]->showConfiguration(); - break; - } - break; - case Nothing: - default: - break; - } - } -} - - -void AWKeys::copyBar(const QString original) -{ - if (debug) qDebug() << PDEBUG; - - QStringList tagList; - for (int i=0; iname()); - int number = 0; - while (tagList.contains(QString("bar%1").arg(number))) - number++; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/desktops"), - QStandardPaths::LocateDirectory); - bool ok; - QString name = QInputDialog::getText(nullptr, i18n("Enter file name"), - i18n("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return; - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - QStringList bars; - bars.append(keys.filter((QRegExp(QString("cpu(?!cl).*"))))); - bars.append(keys.filter((QRegExp(QString("^gpu$"))))); - bars.append(keys.filter((QRegExp(QString("^mem$"))))); - bars.append(keys.filter((QRegExp(QString("^swap$"))))); - bars.append(keys.filter((QRegExp(QString("^hdd[0-9].*"))))); - bars.append(keys.filter((QRegExp(QString("^bat.*"))))); - - int originalItem = -1; - for (int i=0; ifileName() != original) || - (graphicalItems[i]->fileName() != name)) - continue; - originalItem = i; - break; - } - GraphicalItem *item = new GraphicalItem(nullptr, name, dirs, debug); - item->setApiVersion(AWGIAPI); - item->setName(QString("bar%1").arg(number)); - if (originalItem != -1) { - item->setComment(graphicalItems[originalItem]->comment()); - item->setBar(graphicalItems[originalItem]->bar()); - item->setActiveColor(graphicalItems[originalItem]->activeColor()); - item->setInactiveColor(graphicalItems[originalItem]->inactiveColor()); - item->setType(graphicalItems[originalItem]->type()); - item->setDirection(graphicalItems[originalItem]->direction()); - item->setHeight(graphicalItems[originalItem]->height()); - item->setWidth(graphicalItems[originalItem]->width()); - } - - if (item->showConfiguration(bars) == 1) { - graphicalItems.clear(); - graphicalItems = getGraphicalItems(); - QListWidgetItem *widgetItem = new QListWidgetItem(item->fileName()); - QStringList tooltip; - tooltip.append(i18n("Tag: %1", item->name() + item->bar())); - tooltip.append(i18n("Comment: %1", item->comment())); - widgetItem->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(widgetItem); - widgetDialog->sortItems(); - } - delete item; -} - - -void AWKeys::copyQuotes(const QString original) -{ - if (debug) qDebug() << PDEBUG; - - QList tagList; - for (int i=0; inumber()); - int number = 0; - while (tagList.contains(number)) - number++; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/quotes"), - QStandardPaths::LocateDirectory); - bool ok; - QString name = QInputDialog::getText(nullptr, i18n("Enter file name"), - i18n("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return; - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - - int originalItem = -1; - for (int i=0; ifileName() != original) || - (extQuotes[i]->fileName() != name)) - continue; - originalItem = i; - break; - } - ExtQuotes *quotes = new ExtQuotes(nullptr, name, dirs, debug); - quotes->setApiVersion(AWEQAPI); - quotes->setNumber(number); - if (originalItem != -1) { - quotes->setActive(extQuotes[originalItem]->isActive()); - quotes->setComment(extQuotes[originalItem]->comment()); - quotes->setInterval(extQuotes[originalItem]->interval()); - quotes->setName(extQuotes[originalItem]->name()); - quotes->setTicker(extQuotes[originalItem]->ticker()); - } - - if (quotes->showConfiguration() == 1) { - extQuotes.clear(); - extQuotes = getExtQuotes(); - QListWidgetItem *widgetItem = new QListWidgetItem(quotes->fileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", quotes->name())); - tooltip.append(i18n("Comment: %1", quotes->comment())); - tooltip.append(i18n("Ticker: %1", quotes->ticker())); - widgetItem->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(widgetItem); - widgetDialog->sortItems(); - } - delete quotes; -} - - - -void AWKeys::copyScript(const QString original) -{ - if (debug) qDebug() << PDEBUG; - - QList tagList; - for (int i=0; inumber()); - int number = 0; - while (tagList.contains(number)) - number++; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/scripts"), - QStandardPaths::LocateDirectory); - bool ok; - QString name = QInputDialog::getText(nullptr, i18n("Enter file name"), - i18n("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return; - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - - int originalItem = -1; - for (int i=0; ifileName() != original) || - (extScripts[i]->fileName() != name)) - continue; - originalItem = i; - break; - } - ExtScript *script = new ExtScript(nullptr, name, dirs, debug); - script->setApiVersion(AWESAPI); - script->setNumber(number); - if (originalItem != -1) { - script->setActive(extScripts[originalItem]->isActive()); - script->setComment(extScripts[originalItem]->comment()); - script->setExecutable(extScripts[originalItem]->executable()); - script->setHasOutput(extScripts[originalItem]->hasOutput()); - script->setInterval(extScripts[originalItem]->interval()); - script->setName(extScripts[originalItem]->name()); - script->setPrefix(extScripts[originalItem]->prefix()); - script->setRedirect(extScripts[originalItem]->redirect()); - } - - if (script->showConfiguration() == 1) { - extScripts.clear(); - extScripts = getExtScripts(); - QListWidgetItem *widgetItem = new QListWidgetItem(script->fileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", script->name())); - tooltip.append(i18n("Comment: %1", script->comment())); - tooltip.append(i18n("Exec: %1", script->executable())); - widgetItem->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(widgetItem); - widgetDialog->sortItems(); - } - delete script; -} - - -void AWKeys::copyUpgrade(const QString original) -{ - if (debug) qDebug() << PDEBUG; - - QList tagList; - for (int i=0; inumber()); - int number = 0; - while (tagList.contains(number)) - number++; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/upgrade"), - QStandardPaths::LocateDirectory); - bool ok; - QString name = QInputDialog::getText(nullptr, i18n("Enter file name"), - i18n("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return; - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - - int originalItem = -1; - for (int i=0; ifileName() != original) || - (extUpgrade[i]->fileName() != name)) - continue; - originalItem = i; - break; - } - ExtUpgrade *upgrade = new ExtUpgrade(nullptr, name, dirs, debug); - upgrade->setApiVersion(AWEUAPI); - upgrade->setNumber(number); - if (originalItem != -1) { - upgrade->setActive(extUpgrade[originalItem]->isActive()); - upgrade->setComment(extUpgrade[originalItem]->comment()); - upgrade->setExecutable(extUpgrade[originalItem]->executable()); - upgrade->setName(extUpgrade[originalItem]->name()); - upgrade->setNull(extUpgrade[originalItem]->null()); - upgrade->setInterval(extUpgrade[originalItem]->interval()); - } - - if (upgrade->showConfiguration() == 1) { - extUpgrade.clear(); - extUpgrade = getExtUpgrade(); - QListWidgetItem *widgetItem = new QListWidgetItem(upgrade->fileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", upgrade->name())); - tooltip.append(i18n("Comment: %1", upgrade->comment())); - tooltip.append(i18n("Exec: %1", upgrade->executable())); - widgetItem->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(widgetItem); - widgetDialog->sortItems(); - } - delete upgrade; -} - - -void AWKeys::copyWeather(const QString original) -{ - if (debug) qDebug() << PDEBUG; - - QList tagList; - for (int i=0; inumber()); - int number = 0; - while (tagList.contains(number)) - number++; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/weather"), - QStandardPaths::LocateDirectory); - bool ok; - QString name = QInputDialog::getText(nullptr, i18n("Enter file name"), - i18n("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return; - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - - int originalItem = -1; - for (int i=0; ifileName() != original) || - (extWeather[i]->fileName() != name)) - continue; - originalItem = i; - break; - } - ExtWeather *weather = new ExtWeather(nullptr, name, dirs, debug); - weather->setApiVersion(AWEUAPI); - weather->setNumber(number); - if (originalItem != -1) { - weather->setActive(extWeather[originalItem]->isActive()); - weather->setComment(extWeather[originalItem]->comment()); - weather->setName(extWeather[originalItem]->name()); - weather->setInterval(extWeather[originalItem]->interval()); - weather->setCity(extWeather[originalItem]->city()); - weather->setCountry(extWeather[originalItem]->country()); - weather->setTs(extWeather[originalItem]->ts()); - } - - if (weather->showConfiguration() == 1) { - extWeather.clear(); - extWeather = getExtWeather(); - QListWidgetItem *widgetItem = new QListWidgetItem(weather->fileName()); - QStringList tooltip; - tooltip.append(i18n("Name: %1", weather->name())); - tooltip.append(i18n("Comment: %1", weather->comment())); - tooltip.append(i18n("City: %1", weather->city())); - tooltip.append(i18n("Country: %1", weather->country())); - tooltip.append(i18n("Time: %1", weather->ts())); - widgetItem->setToolTip(tooltip.join(QChar('\n'))); - widgetDialog->addItem(widgetItem); - widgetDialog->sortItems(); - } - delete weather; -} - - void AWKeys::addKeyToCache(const QString type, const QString key) { if (debug) qDebug() << PDEBUG; @@ -1464,8 +944,8 @@ QStringList AWKeys::findGraphicalItems() const if (debug) qDebug() << PDEBUG; QStringList orderedKeys; - for (int i=0; iname() + graphicalItems[i]->bar()); + for (int i=0; iitems().count(); i++) + orderedKeys.append(graphicalItems->items()[i]->name() + graphicalItems->items()[i]->bar()); orderedKeys.sort(); QStringList selectedKeys; @@ -1494,169 +974,14 @@ QStringList AWKeys::findKeys() const } -QList AWKeys::getExtQuotes() -{ - if (debug) qDebug() << PDEBUG; - - QList externalQuotes; - // create directory at $HOME - QString localDir = QString("%1/awesomewidgets/quotes") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/quotes"), - QStandardPaths::LocateDirectory); - QStringList names; - for (int i=0; i AWKeys::getExtScripts() -{ - if (debug) qDebug() << PDEBUG; - - QList externalScripts; - // create directory at $HOME - QString localDir = QString("%1/awesomewidgets/scripts") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/scripts"), - QStandardPaths::LocateDirectory); - QStringList names; - for (int i=0; i AWKeys::getExtUpgrade() -{ - if (debug) qDebug() << PDEBUG; - - QList externalUpgrade; - // create directory at $HOME - QString localDir = QString("%1/awesomewidgets/upgrade") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/upgrade"), - QStandardPaths::LocateDirectory); - QStringList names; - for (int i=0; i AWKeys::getExtWeather() -{ - if (debug) qDebug() << PDEBUG; - - QList externalWeather; - // create directory at $HOME - QString localDir = QString("%1/awesomewidgets/weather") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/weather"), - QStandardPaths::LocateDirectory); - QStringList names; - for (int i=0; i AWKeys::getGraphicalItems() -{ - if (debug) qDebug() << PDEBUG; - - QList items; - // create directory at $HOME - QString localDir = QString("%1/awesomewidgets/desktops") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if (localDirectory.mkpath(localDir)) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/desktops"), - QStandardPaths::LocateDirectory); - QStringList names; - for (int i=0; iname() + graphicalItems[i]->bar()) != tag) continue; - item = graphicalItems[i]; + for (int i=0; i< graphicalItems->items().count(); i++) { + if ((graphicalItems->items()[i]->name() + graphicalItems->items()[i]->bar()) != tag) continue; + item = graphicalItems->items()[i]; break; } diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index 959e17e..efb45d3 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -19,15 +19,13 @@ #ifndef AWKEYS_H #define AWKEYS_H -#include -#include -#include #include #include #include -#include #include +#include "extitemaggregator.h" + class AWToolTip; class ExtQuotes; @@ -40,15 +38,6 @@ class AWKeys : public QObject { Q_OBJECT - enum RequestedItem { - Nothing, - RequestedGraphicalItem, - RequestedExtQuotes, - RequestedExtScript, - RequestedExtUpgrade, - RequestedExtWeather - }; - public: AWKeys(QObject *parent = nullptr); ~AWKeys(); @@ -82,13 +71,6 @@ private slots: void dataUpdate() const; void loadKeysFromCache(); void reinitKeys(); - // editor - void editItemButtonPressed(QAbstractButton *button); - void copyBar(const QString original); - void copyQuotes(const QString original); - void copyScript(const QString original); - void copyUpgrade(const QString original); - void copyWeather(const QString original); private: // methods @@ -102,31 +84,17 @@ private: QStringList findGraphicalItems() const; QStringList findKeys() const; // get methods - QList getExtQuotes(); - QList getExtScripts(); - QList getExtUpgrade(); - QList getExtWeather(); - QList getGraphicalItems(); GraphicalItem *getItemByTag(const QString tag) const; QStringList getTimeKeys() const; AWToolTip *toolTip = nullptr; - // graphical elements - QDialog *dialog = nullptr; - QListWidget *widgetDialog = nullptr; - QDialogButtonBox *dialogButtons = nullptr; - QPushButton *copyButton = nullptr; - QPushButton *createButton = nullptr; - QPushButton *deleteButton = nullptr; - RequestedItem requestedItem = Nothing; - // variables bool debug = false; bool enablePopup = false; bool wrapNewLines = false; - QList graphicalItems; - QList extQuotes; - QList extScripts; - QList extUpgrade; - QList extWeather; + ExtItemAggregator *graphicalItems; + ExtItemAggregator *extQuotes; + ExtItemAggregator *extScripts; + ExtItemAggregator *extUpgrade; + ExtItemAggregator *extWeather; QString pattern; QStringList foundBars, foundKeys, keys; QMap values; diff --git a/sources/awesomewidgets/abstractextitemaggregator.cpp b/sources/awesomewidgets/abstractextitemaggregator.cpp index cfc7256..fd779f9 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.cpp +++ b/sources/awesomewidgets/abstractextitemaggregator.cpp @@ -19,6 +19,8 @@ #include #include +#include +#include #include @@ -42,6 +44,8 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this, SLOT(editItemButtonPressed(QAbstractButton *))); connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject())); + connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)), + this, SLOT(editItemActivated(QListWidgetItem *))); } @@ -53,6 +57,47 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator() } +QString AbstractExtItemAggregator::getName() +{ + if (debug) qDebug() << PDEBUG; + + bool ok; + QString name = QInputDialog::getText(this, tr("Enter file name"), + tr("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return QString(""); + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + + return name; +} + + +QVariant AbstractExtItemAggregator::configArgs() const +{ + if (debug) qDebug() << PDEBUG; + + return m_configArgs; +} + + +void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Configuration arguments" << _configArgs; + + m_configArgs = _configArgs; +} + + +void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item) +{ + Q_UNUSED(item) + if (debug) qDebug() << PDEBUG; + + return editItem(); +} + + void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) { if (debug) qDebug() << PDEBUG; @@ -61,7 +106,7 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) return copyItem(); else if (static_cast(button) == createButton) return createItem(); - else if (dynamic_cast(button) == deleteButton) + else if (static_cast(button) == deleteButton) return deleteItem(); else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) return editItem(); diff --git a/sources/awesomewidgets/abstractextitemaggregator.h b/sources/awesomewidgets/abstractextitemaggregator.h index d1bb0b8..c3c910e 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.h +++ b/sources/awesomewidgets/abstractextitemaggregator.h @@ -29,9 +29,12 @@ class AbstractExtItemAggregator : public QWidget { Q_OBJECT + Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs) + public: AbstractExtItemAggregator(QWidget *parent = nullptr, const bool debugCmd = false); virtual ~AbstractExtItemAggregator(); + QString getName(); // ui QDialog *dialog = nullptr; QListWidget *widgetDialog = nullptr; @@ -39,12 +42,18 @@ public: QPushButton *copyButton = nullptr; QPushButton *createButton = nullptr; QPushButton *deleteButton = nullptr; + // get methods + QVariant configArgs() const; + // set methods + void setConfigArgs(const QVariant _configArgs); private slots: + void editItemActivated(QListWidgetItem *item); void editItemButtonPressed(QAbstractButton *button); private: bool debug; + QVariant m_configArgs; // methods virtual void copyItem() = 0; virtual void createItem() = 0; diff --git a/sources/awesomewidgets/desktops/aw-bat-bar.desktop b/sources/awesomewidgets/desktops/aw-bat-bar.desktop index 71fe557..4d4e6d0 100644 --- a/sources/awesomewidgets/desktops/aw-bat-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-bat-bar.desktop @@ -9,4 +9,5 @@ X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=1 +X-AW-ApiVersion=2 +X-AW-Number=3 diff --git a/sources/awesomewidgets/desktops/aw-cpu-bar.desktop b/sources/awesomewidgets/desktops/aw-cpu-bar.desktop index b1bfe3c..e186c21 100644 --- a/sources/awesomewidgets/desktops/aw-cpu-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-cpu-bar.desktop @@ -9,4 +9,5 @@ X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=1 +X-AW-ApiVersion=2 +X-AW-Number=0 diff --git a/sources/awesomewidgets/desktops/aw-mem-bar.desktop b/sources/awesomewidgets/desktops/aw-mem-bar.desktop index da4971b..6e2ba18 100644 --- a/sources/awesomewidgets/desktops/aw-mem-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-mem-bar.desktop @@ -9,4 +9,5 @@ X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=1 +X-AW-ApiVersion=2 +X-AW-Number=1 diff --git a/sources/awesomewidgets/desktops/aw-swap-bar.desktop b/sources/awesomewidgets/desktops/aw-swap-bar.desktop index bc62658..f30bce8 100644 --- a/sources/awesomewidgets/desktops/aw-swap-bar.desktop +++ b/sources/awesomewidgets/desktops/aw-swap-bar.desktop @@ -9,4 +9,5 @@ X-AW-Type=Horizontal X-AW-Direction=LeftToRight X-AW-Height=25 X-AW-Width=100 -X-AW-ApiVersion=1 +X-AW-ApiVersion=2 +X-AW-Number=2 diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index a2a9ad8..d297cdd 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -20,8 +20,6 @@ #include #include -#include -#include #include #include @@ -30,7 +28,8 @@ #include "abstractextitemaggregator.h" -template class ExtItemAggregator : public AbstractExtItemAggregator +template +class ExtItemAggregator : public AbstractExtItemAggregator { public: explicit ExtItemAggregator(QWidget *parent, const QString type, @@ -49,20 +48,6 @@ public: m_items.clear(); } - QString getName() const - { - if (debug) qDebug() << PDEBUG; - - bool ok; - QString name = QInputDialog::getText(nullptr, tr("Enter file name"), - tr("File name"), QLineEdit::Normal, - QString(""), &ok); - if ((!ok) || (name.isEmpty())) return QString(""); - if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); - - return name; - }; - void editItems() { if (debug) qDebug() << PDEBUG; @@ -122,6 +107,7 @@ private: bool debug; QList m_items; QString m_type; + // init method QList getItems() { @@ -167,6 +153,7 @@ private: widgetDialog->addItem(item); } }; + // methods void copyItem() { @@ -178,7 +165,7 @@ private: if ((source == nullptr) || (fileName.isEmpty())) return; T *newItem = source->copy(fileName, number); - if (newItem->showConfiguration() == 1) { + if (newItem->showConfiguration(configArgs()) == 1) { initItems(); repaint(); } @@ -197,7 +184,7 @@ private: T *newItem = new T(this, fileName, dirs, debug); newItem->setNumber(number); - if (newItem->showConfiguration() == 1) { + if (newItem->showConfiguration(configArgs()) == 1) { initItems(); repaint(); } @@ -223,7 +210,7 @@ private: T *source = itemFromWidget(); if (source == nullptr) return; - if (source->showConfiguration() == 1) { + if (source->showConfiguration(configArgs()) == 1) { initItems(); repaint(); } diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 99a64e0..489823c 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -377,8 +377,16 @@ void GraphicalItem::readConfiguration() setStrDirection(settings.value(QString("X-AW-Direction"), strDirection()).toString()); setHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); setWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); + // api == 2 + if (apiVersion() < 2) setNumber(bar().remove(QString("bar")).toInt()); settings.endGroup(); } + + // update for current API + if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) { + setApiVersion(AWGIAPI); + writeConfiguration(); + } } @@ -436,7 +444,6 @@ void GraphicalItem::writeConfiguration() const if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); - settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion); settings.setValue(QString("X-AW-Value"), m_bar); settings.setValue(QString("X-AW-ActiveColor"), m_activeColor); settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor); @@ -454,8 +461,8 @@ void GraphicalItem::changeColor() { if (debug) qDebug() << PDEBUG; - QColor color = stringToColor((dynamic_cast(sender()))->text()); - QColor newColor = QColorDialog::getColor(color, 0, tr("Select color"), + QColor color = stringToColor((static_cast(sender()))->text()); + QColor newColor = QColorDialog::getColor(color, this, tr("Select color"), QColorDialog::ShowAlphaChannel); if (!newColor.isValid()) return; @@ -464,7 +471,7 @@ void GraphicalItem::changeColor() colorText.append(QString("%1").arg(newColor.green())); colorText.append(QString("%1").arg(newColor.blue())); colorText.append(QString("%1").arg(newColor.alpha())); - dynamic_cast(sender())->setText(colorText.join(QChar(','))); + static_cast(sender())->setText(colorText.join(QChar(','))); } diff --git a/sources/version.h.in b/sources/version.h.in index 6e40e3c..47f9c1b 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -10,7 +10,7 @@ #define LICENSE "@PROJECT_LICENSE@" #define TRDPARTY_LICENSE "tasks,BSD,https://github.com/mhogomchungu/tasks" // graphical items api version -#define AWGIAPI 1 +#define AWGIAPI 2 // extquotes api version #define AWEQAPI 2 // extscript api version