mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
move aw plugin to template-based system
bump graphicalitems to ApiVer 2 (add number property)
This commit is contained in:
parent
c61a5ac092
commit
983b808247
@ -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=
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QHBoxLayout>
|
||||
#include <QInputDialog>
|
||||
#include <QNetworkInterface>
|
||||
#include <QProcessEnvironment>
|
||||
@ -53,22 +52,12 @@ AWKeys::AWKeys(QObject *parent)
|
||||
debug = (debugEnv == QString("yes"));
|
||||
|
||||
// backend
|
||||
graphicalItems = new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"), debug);
|
||||
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"), debug);
|
||||
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"), debug);
|
||||
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"), debug);
|
||||
extWeather = new ExtItemAggregator<ExtWeather>(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; i<graphicalItems.count(); i++)
|
||||
graphicalItemsKeys.append(QString("%1%2").arg(graphicalItems[i]->name())
|
||||
.arg(graphicalItems[i]->bar()));
|
||||
for (int i=0; i<graphicalItems->items().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; i<extScripts.count(); i++) {
|
||||
if (extScripts[i]->tag(QString("custom")) != key) continue;
|
||||
return extScripts[i]->executable();
|
||||
for (int i=0; i<extScripts->items().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; i<extUpgrade.count(); i++) {
|
||||
if (extUpgrade[i]->tag(QString("pkgcount")) != key) continue;
|
||||
return extUpgrade[i]->executable();
|
||||
for (int i=0; i<extUpgrade->items().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; i<extQuotes.count(); i++) {
|
||||
if (extQuotes[i]->number() != key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt()) continue;
|
||||
return extQuotes[i]->ticker();
|
||||
for (int i=0; i<extQuotes->items().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; i<graphicalItems.count(); i++) {
|
||||
QListWidgetItem *item = new QListWidgetItem(graphicalItems[i]->fileName());
|
||||
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; i<extQuotes.count(); i++) {
|
||||
QListWidgetItem *item = new QListWidgetItem(extQuotes[i]->fileName());
|
||||
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; i<extScripts.count(); i++) {
|
||||
QListWidgetItem *item = new QListWidgetItem(extScripts[i]->fileName());
|
||||
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; i<extUpgrade.count(); i++) {
|
||||
QListWidgetItem *item = new QListWidgetItem(extUpgrade[i]->fileName());
|
||||
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; i<extWeather.count(); i++) {
|
||||
QListWidgetItem *item = new QListWidgetItem(extWeather[i]->fileName());
|
||||
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<QPushButton *>(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<QPushButton *>(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<QPushButton *>(button) == deleteButton) {
|
||||
if (item == nullptr) return;
|
||||
QString current = item->text();
|
||||
switch (requestedItem) {
|
||||
case RequestedExtQuotes:
|
||||
for (int i=0; i<extQuotes.count(); i++) {
|
||||
if (extQuotes[i]->fileName() != current) continue;
|
||||
if (extQuotes[i]->tryDelete()) {
|
||||
widgetDialog->takeItem(widgetDialog->row(item));
|
||||
extQuotes.clear();
|
||||
extQuotes = getExtQuotes();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtScript:
|
||||
for (int i=0; i<extScripts.count(); i++) {
|
||||
if (extScripts[i]->fileName() != current) continue;
|
||||
if (extScripts[i]->tryDelete()) {
|
||||
widgetDialog->takeItem(widgetDialog->row(item));
|
||||
extScripts.clear();
|
||||
extScripts = getExtScripts();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtUpgrade:
|
||||
for (int i=0; i<extUpgrade.count(); i++) {
|
||||
if (extUpgrade[i]->fileName() != current) continue;
|
||||
if (extUpgrade[i]->tryDelete()) {
|
||||
widgetDialog->takeItem(widgetDialog->row(item));
|
||||
extUpgrade.clear();
|
||||
extUpgrade = getExtUpgrade();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtWeather:
|
||||
for (int i=0; i<extWeather.count(); i++) {
|
||||
if (extWeather[i]->fileName() != current) continue;
|
||||
if (extWeather[i]->tryDelete()) {
|
||||
widgetDialog->takeItem(widgetDialog->row(item));
|
||||
extWeather.clear();
|
||||
extWeather = getExtWeather();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedGraphicalItem:
|
||||
for (int i=0; i<graphicalItems.count(); i++) {
|
||||
if (graphicalItems[i]->fileName() != 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; i<extQuotes.count(); i++) {
|
||||
if (extQuotes[i]->fileName() != current) continue;
|
||||
extQuotes[i]->showConfiguration();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtScript:
|
||||
for (int i=0; i<extScripts.count(); i++) {
|
||||
if (extScripts[i]->fileName() != current) continue;
|
||||
extScripts[i]->showConfiguration();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtUpgrade:
|
||||
for (int i=0; i<extUpgrade.count(); i++) {
|
||||
if (extUpgrade[i]->fileName() != current) continue;
|
||||
extUpgrade[i]->showConfiguration();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedExtWeather:
|
||||
for (int i=0; i<extWeather.count(); i++) {
|
||||
if (extWeather[i]->fileName() != current) continue;
|
||||
extWeather[i]->showConfiguration();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RequestedGraphicalItem:
|
||||
for (int i=0; i<graphicalItems.count(); i++) {
|
||||
if (graphicalItems[i]->fileName() != 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; i<graphicalItems.count(); i++)
|
||||
tagList.append(graphicalItems[i]->name());
|
||||
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; i<graphicalItems.count(); i++) {
|
||||
if ((graphicalItems[i]->fileName() != 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<int> tagList;
|
||||
for (int i=0; i<extQuotes.count(); i++)
|
||||
tagList.append(extQuotes[i]->number());
|
||||
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; i<extQuotes.count(); i++) {
|
||||
if ((extQuotes[i]->fileName() != 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<int> tagList;
|
||||
for (int i=0; i<extScripts.count(); i++)
|
||||
tagList.append(extScripts[i]->number());
|
||||
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; i<extScripts.count(); i++) {
|
||||
if ((extScripts[i]->fileName() != 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<int> tagList;
|
||||
for (int i=0; i<extUpgrade.count(); i++)
|
||||
tagList.append(extUpgrade[i]->number());
|
||||
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; i<extUpgrade.count(); i++) {
|
||||
if ((extUpgrade[i]->fileName() != 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<int> tagList;
|
||||
for (int i=0; i<extWeather.count(); i++)
|
||||
tagList.append(extWeather[i]->number());
|
||||
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; i<extWeather.count(); i++) {
|
||||
if ((extWeather[i]->fileName() != 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; i<graphicalItems.count(); i++)
|
||||
orderedKeys.append(graphicalItems[i]->name() + graphicalItems[i]->bar());
|
||||
for (int i=0; i<graphicalItems->items().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<ExtQuotes *> AWKeys::getExtQuotes()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<ExtQuotes *> 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<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalQuotes.append(new ExtQuotes(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
|
||||
return externalQuotes;
|
||||
}
|
||||
|
||||
|
||||
QList<ExtScript *> AWKeys::getExtScripts()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<ExtScript *> 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<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalScripts.append(new ExtScript(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
|
||||
return externalScripts;
|
||||
}
|
||||
|
||||
|
||||
QList<ExtUpgrade *> AWKeys::getExtUpgrade()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<ExtUpgrade *> 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<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalUpgrade.append(new ExtUpgrade(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
|
||||
return externalUpgrade;
|
||||
}
|
||||
|
||||
|
||||
QList<ExtWeather *> AWKeys::getExtWeather()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<ExtWeather *> 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<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalWeather.append(new ExtWeather(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
|
||||
return externalWeather;
|
||||
}
|
||||
|
||||
|
||||
QList<GraphicalItem *> AWKeys::getGraphicalItems()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<GraphicalItem *> 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; i<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
items.append(new GraphicalItem(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
GraphicalItem *AWKeys::getItemByTag(const QString tag) const
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
GraphicalItem *item = nullptr;
|
||||
for (int i=0; i< graphicalItems.count(); i++) {
|
||||
if ((graphicalItems[i]->name() + 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;
|
||||
}
|
||||
|
||||
|
@ -19,15 +19,13 @@
|
||||
#ifndef AWKEYS_H
|
||||
#define AWKEYS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QListWidget>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QPushButton>
|
||||
#include <QVariant>
|
||||
|
||||
#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<ExtQuotes *> getExtQuotes();
|
||||
QList<ExtScript *> getExtScripts();
|
||||
QList<ExtUpgrade *> getExtUpgrade();
|
||||
QList<ExtWeather *> getExtWeather();
|
||||
QList<GraphicalItem *> 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<GraphicalItem *> graphicalItems;
|
||||
QList<ExtQuotes *> extQuotes;
|
||||
QList<ExtScript *> extScripts;
|
||||
QList<ExtUpgrade *> extUpgrade;
|
||||
QList<ExtWeather *> extWeather;
|
||||
ExtItemAggregator<GraphicalItem> *graphicalItems;
|
||||
ExtItemAggregator<ExtQuotes> *extQuotes;
|
||||
ExtItemAggregator<ExtScript> *extScripts;
|
||||
ExtItemAggregator<ExtUpgrade> *extUpgrade;
|
||||
ExtItemAggregator<ExtWeather> *extWeather;
|
||||
QString pattern;
|
||||
QStringList foundBars, foundKeys, keys;
|
||||
QMap<QString, QString> values;
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QHBoxLayout>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
@ -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<QPushButton *>(button) == createButton)
|
||||
return createItem();
|
||||
else if (dynamic_cast<QPushButton *>(button) == deleteButton)
|
||||
else if (static_cast<QPushButton *>(button) == deleteButton)
|
||||
return deleteItem();
|
||||
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||
return editItem();
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
@ -30,7 +28,8 @@
|
||||
#include "abstractextitemaggregator.h"
|
||||
|
||||
|
||||
template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
|
||||
template <class T>
|
||||
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<T *> m_items;
|
||||
QString m_type;
|
||||
|
||||
// init method
|
||||
QList<T *> 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();
|
||||
}
|
||||
|
@ -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<QPushButton *>(sender()))->text());
|
||||
QColor newColor = QColorDialog::getColor(color, 0, tr("Select color"),
|
||||
QColor color = stringToColor((static_cast<QPushButton *>(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<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
|
||||
static_cast<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user