create a static library for backend items

move backend items to template-based mechanism
This commit is contained in:
arcan1s
2015-07-26 12:58:59 +03:00
parent 3b6df44489
commit c61a5ac092
47 changed files with 608 additions and 171 deletions

View File

@ -5,7 +5,7 @@ message (STATUS "Subproject ${SUBPROJECT}")
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
# find required libaries
find_package (Qt5 REQUIRED COMPONENTS DBus Network Widgets)
find_package (Qt5 REQUIRED COMPONENTS DBus Network)
find_package (ECM 0.0.11 REQUIRED NO_MODULE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package (KF5 REQUIRED COMPONENTS Plasma Service WindowSystem)
@ -15,31 +15,25 @@ include (KDECMakeSettings)
include (KDECompilerSettings)
add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS}
${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
${Qt5Network_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
${Qt5Network_INCLUDE_DIRS})
set (KDE_INCLUDE ${Plasma_INCLUDE_DIR})
include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${KDE_INCLUDE})
file (GLOB SUBPROJECT_DESKTOP_IN *.desktop)
file (RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp
${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp)
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp)
set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h)
file (GLOB SUBPROJECT_UI *.ui)
file (GLOB SUBPROJECT_CONF *.conf)
set (SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
set (SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
set (SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
set (SUBPROJECT_UPGRADE ${CMAKE_CURRENT_SOURCE_DIR}/upgrade)
set (SUBPROJECT_WEATHER ${CMAKE_CURRENT_SOURCE_DIR}/weather)
# prepare
configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
@ -48,16 +42,11 @@ configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJEC
qt5_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER})
qt5_wrap_ui (SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
add_library (${PLUGIN_NAME} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER} ${TASK_MOC_SOURCE})
target_link_libraries (${PLUGIN_NAME} ${Plasma_LIBRARIES} KF5::WindowSystem
${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Xml_LIBRARIES})
target_link_libraries (${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Plasma_LIBRARIES} KF5::WindowSystem
${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES})
kcoreaddons_desktop_to_json (${PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
# install
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})
install (DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install (DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install (DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install (DIRECTORY ${SUBPROJECT_UPGRADE} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install (DIRECTORY ${SUBPROJECT_WEATHER} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})

View File

@ -1,235 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "abstractextitem.h"
#include <QDebug>
#include <QDir>
#include <QSettings>
#include <QStandardPaths>
#include <QTime>
#include <pdebug/pdebug.h>
#include "version.h"
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
const QStringList directories, const bool debugCmd)
: QDialog(parent),
m_fileName(desktopName),
m_dirs(directories),
debug(debugCmd)
{
m_name = m_fileName;
}
AbstractExtItem::~AbstractExtItem()
{
if (debug) qDebug() << PDEBUG;
}
int AbstractExtItem::apiVersion() const
{
if (debug) qDebug() << PDEBUG;
return m_apiVersion;
}
QString AbstractExtItem::comment() const
{
if (debug) qDebug() << PDEBUG;
return m_comment;
}
QStringList AbstractExtItem::directories() const
{
if (debug) qDebug() << PDEBUG;
return m_dirs;
}
QString AbstractExtItem::fileName() const
{
if (debug) qDebug() << PDEBUG;
return m_fileName;
}
int AbstractExtItem::interval() const
{
if (debug) qDebug() << PDEBUG;
return m_interval;
}
bool AbstractExtItem::isActive() const
{
if (debug) qDebug() << PDEBUG;
return m_active;
}
QString AbstractExtItem::name() const
{
if (debug) qDebug() << PDEBUG;
return m_name;
}
int AbstractExtItem::number() const
{
if (debug) qDebug() << PDEBUG;
return m_number;
}
QString AbstractExtItem::tag(const QString _type) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Tag type" << _type;
return QString("%1%2").arg(_type).arg(m_number);
}
void AbstractExtItem::setApiVersion(const int _apiVersion)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
m_apiVersion = _apiVersion;
}
void AbstractExtItem::setActive(const bool _state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_active = _state;
}
void AbstractExtItem::setComment(const QString _comment)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
m_comment = _comment;
}
void AbstractExtItem::setInterval(const int _interval)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
if (_interval <= 0) return;
m_interval = _interval;
}
void AbstractExtItem::setName(const QString _name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
m_name = _name;
}
void AbstractExtItem::setNumber(int _number)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
if (_number == -1) {
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
qsrand(QTime::currentTime().msec());
_number = qrand() % 1000;
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
}
m_number = _number;
}
void AbstractExtItem::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
for (int i=m_dirs.count()-1; i>=0; i--) {
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setName(settings.value(QString("Name"), m_name).toString());
setComment(settings.value(QString("Comment"), m_comment).toString());
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
settings.endGroup();
}
}
bool AbstractExtItem::tryDelete() const
{
if (debug) qDebug() << PDEBUG;
for (int i=0; i<m_dirs.count(); i++)
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
// check if exists
for (int i=0; i<m_dirs.count(); i++)
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
return true;
}
void AbstractExtItem::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Encoding"), QString("UTF-8"));
settings.setValue(QString("Name"), m_name);
settings.setValue(QString("Comment"), m_comment);
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
settings.setValue(QString("X-AW-Interval"), m_interval);
settings.setValue(QString("X-AW-Number"), m_number);
settings.endGroup();
settings.sync();
}

View File

@ -1,82 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef ABSTRACTEXTITEM_H
#define ABSTRACTEXTITEM_H
#include <QDialog>
#include <QInputDialog>
#include <QVariant>
class AbstractExtItem : public QDialog
{
Q_OBJECT
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QStringList directories READ directories)
Q_PROPERTY(QString fileName READ fileName)
Q_PROPERTY(int interval READ interval WRITE setInterval)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int number READ number WRITE setNumber)
public:
explicit AbstractExtItem(QWidget *parent = nullptr, const QString desktopName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
virtual ~AbstractExtItem();
// get methods
int apiVersion() const;
QString comment() const;
QStringList directories() const;
QString fileName() const;
int interval() const;
bool isActive() const;
QString name() const;
int number() const;
QString tag(const QString _type) const;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setActive(const bool _state = true);
void setComment(const QString _comment = QString("empty"));
void setInterval(const int _interval = 1);
void setName(const QString _name = QString("none"));
void setNumber(int _number = -1);
public slots:
virtual void readConfiguration();
virtual QVariantMap run() = 0;
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
bool tryDelete() const;
virtual void writeConfiguration() const;
private:
QString m_fileName;
QStringList m_dirs;
bool debug;
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
int m_interval = 1;
QString m_name = QString("none");
int m_number = -1;
};
#endif /* ABSTRACTEXTITEM_H */

View File

@ -1,12 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=bar3
Comment=Simple bat bar
X-AW-Value=bat
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1

View File

@ -1,12 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=bar0
Comment=Simple cpu bar
X-AW-Value=cpu
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1

View File

@ -1,12 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=bar1
Comment=Simple mem bar
X-AW-Value=mem
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1

View File

@ -1,12 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=bar2
Comment=Simple swap bar
X-AW-Value=swap
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1

View File

@ -1,223 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "extquotes.h"
#include "ui_extquotes.h"
#include <QDebug>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSettings>
#include <pdebug/pdebug.h>
#include <qreplytimeout/qreplytimeout.h>
#include "version.h"
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, quotesName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtQuotes)
{
readConfiguration();
ui->setupUi(this);
values[QString("ask")] = 0.0;
values[QString("askchg")] = 0.0;
values[QString("percaskchg")] = 0.0;
values[QString("bid")] = 0.0;
values[QString("bidchg")] = 0.0;
values[QString("percbidchg")] = 0.0;
values[QString("price")] = 0.0;
values[QString("pricechg")] = 0.0;
values[QString("percpricechg")] = 0.0;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(quotesReplyReceived(QNetworkReply *)));
}
ExtQuotes::~ExtQuotes()
{
if (debug) qDebug() << PDEBUG;
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
delete manager;
delete ui;
}
QString ExtQuotes::ticker() const
{
if (debug) qDebug() << PDEBUG;
return m_ticker;
}
void ExtQuotes::setTicker(const QString _ticker)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Ticker" << _ticker;
m_ticker = _ticker;
}
void ExtQuotes::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString());
settings.endGroup();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
setApiVersion(AWEQAPI);
writeConfiguration();
}
}
QVariantMap ExtQuotes::run()
{
if (debug) qDebug() << PDEBUG;
if ((!isActive()) || (isRunning)) return values;
if (times == 1) {
if (debug) qDebug() << PDEBUG << ":" << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 1000);
}
// update value
if (times >= interval()) times = 0;
times++;
return values;
}
int ExtQuotes::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_ticker->setText(m_ticker);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEQAPI);
setTicker(ui->lineEdit_ticker->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtQuotes::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Ticker"), m_ticker);
settings.endGroup();
settings.sync();
}
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Return code" << reply->error();
if (debug) qDebug() << PDEBUG << ":" << "Reply error message" << reply->errorString();
isRunning = false;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if (debug) qDebug() << PDEBUG << ":" << "Json parse error" << error.errorString();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
return;
}
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()[QString("query")].toMap();
jsonQuotes = jsonQuotes[QString("results")].toMap()[QString("quote")].toMap();
float value;
// ask
value = jsonQuotes[QString("Ask")].toString().toFloat();
values[QString("askchg")] = values[QString("ask")].toFloat() == 0.0 ? 0.0 :
value - values[QString("ask")].toFloat();
values[QString("percaskchg")] = 100.0 * values[QString("askchg")].toFloat() / values[QString("ask")].toFloat();
values[QString("ask")] = value;
// bid
value = jsonQuotes[QString("Bid")].toString().toFloat();
values[QString("bidchg")] = values[QString("bid")].toFloat() == 0.0 ? 0.0 :
value - values[QString("bid")].toFloat();
values[QString("percbidchg")] = 100.0 * values[QString("bidchg")].toFloat() / values[QString("bid")].toFloat();
values[QString("bid")] = value;
// last trade
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toFloat();
values[QString("pricechg")] = values[QString("price")].toFloat() == 0.0 ? 0.0 :
value - values[QString("price")].toFloat();
values[QString("percpricechg")] = 100.0 * values[QString("pricechg")].toFloat() / values[QString("price")].toFloat();
values[QString("price")] = value;
}
QString ExtQuotes::url() const
{
if (debug) qDebug() << PDEBUG;
QString apiUrl = QString(YAHOO_URL);
apiUrl.replace(QString("$TICKER"), m_ticker);
if (debug) qDebug() << PDEBUG << ":" << "API url" << apiUrl;
return apiUrl;
}

View File

@ -1,71 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTQUOTES_H
#define EXTQUOTES_H
#include <QMap>
#include <QNetworkReply>
#include "abstractextitem.h"
#define YAHOO_URL "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol=\"$TICKER\"&env=store://datatables.org/alltableswithkeys&format=json"
namespace Ui {
class ExtQuotes;
}
class ExtQuotes : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
public:
explicit ExtQuotes(QWidget *parent = nullptr, const QString quotesName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
~ExtQuotes();
// get methods
QString ticker() const;
// set methods
void setTicker(const QString _ticker = QString("EURUSD=X"));
public slots:
void readConfiguration();
QVariantMap run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void quotesReplyReceived(QNetworkReply *reply);
private:
bool debug;
QNetworkAccessManager *manager;
bool isRunning = false;
Ui::ExtQuotes *ui;
QString url() const;
// properties
QString m_ticker = QString("EURUSD=X");
// values
int times = 0;
QVariantMap values;
};
#endif /* EXTQUOTES_H */

View File

@ -1,240 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtQuotes</class>
<widget class="QDialog" name="ExtQuotes">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use YAHOO! finance ticker to get quotes for the instrument. Refer to &lt;a href=&quot;http://finance.yahoo.com/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0057ae;&quot;&gt;http://finance.yahoo.com/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_ticker">
<item>
<widget class="QLabel" name="label_ticker">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ticker</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_ticker"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_active">
<item>
<spacer name="spacer_active">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_active">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
<property name="text">
<string>Interval</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_interval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>60</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExtQuotes</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExtQuotes</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,380 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "extscript.h"
#include "ui_extscript.h"
#include <QDebug>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QSettings>
#include <QStandardPaths>
#include <QTextCodec>
#include <pdebug/pdebug.h>
#include "version.h"
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, scriptName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtScript)
{
readConfiguration();
readJsonFilters();
ui->setupUi(this);
value[QString("value")] = QString("");
process = new QProcess(this);
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
process->waitForFinished(0);
}
ExtScript::~ExtScript()
{
if (debug) qDebug() << PDEBUG;
process->kill();
delete process;
delete ui;
}
QString ExtScript::executable() const
{
if (debug) qDebug() << PDEBUG;
return m_executable;
}
QStringList ExtScript::filters() const
{
if (debug) qDebug() << PDEBUG;
return m_filters;
}
bool ExtScript::hasOutput() const
{
if (debug) qDebug() << PDEBUG;
return m_output;
}
QString ExtScript::prefix() const
{
if (debug) qDebug() << PDEBUG;
return m_prefix;
}
ExtScript::Redirect ExtScript::redirect() const
{
if (debug) qDebug() << PDEBUG;
return m_redirect;
}
QString ExtScript::strRedirect() const
{
if (debug) qDebug() << PDEBUG;
QString value;
switch (m_redirect) {
case stdout2stderr:
value = QString("stdout2stderr");
break;
case stderr2stdout:
value = QString("stderr2stdout");
break;
case nothing:
default:
value = QString("nothing");
break;
}
return value;
}
void ExtScript::setExecutable(const QString _executable)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Executable" << _executable;
m_executable = _executable;
}
void ExtScript::setFilters(const QStringList _filters)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Filters" << _filters;
for (int i=0; i<_filters.count(); i++)
updateFilter(_filters[i]);
}
void ExtScript::setHasOutput(const bool _state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_output = _state;
}
void ExtScript::setPrefix(const QString _prefix)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Prefix" << _prefix;
m_prefix = _prefix;
}
void ExtScript::setRedirect(const Redirect _redirect)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Redirect" << _redirect;
m_redirect = _redirect;
}
void ExtScript::setStrRedirect(const QString _redirect)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Redirect" << _redirect;
if (_redirect == QString("stdout2sdterr"))
m_redirect = stdout2stderr;
else if (_redirect == QString("stderr2sdtout"))
m_redirect = stderr2stdout;
else
m_redirect = nothing;
}
QString ExtScript::applyFilters(QString _value) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Value" << _value;
for (int i=0; i<m_filters.count(); i++) {
if (debug) qDebug() << PDEBUG << ":" << "Found filter" << m_filters[i];
QVariantMap filter = jsonFilters[m_filters[i]].toMap();
if (filter.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find filter in the json";
continue;
}
for (int j=0; j<filter.keys().count(); j++)
_value.replace(filter.keys()[j], filter[filter.keys()[j]].toString());
}
return _value;
}
void ExtScript::updateFilter(const QString _filter, const bool _add)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Filter" << _filter;
if (debug) qDebug() << PDEBUG << ":" << "Should be added" << _add;
if (_add) {
if (m_filters.contains(_filter)) return;
m_filters.append(_filter);
} else {
m_filters.removeOne(_filter);
}
}
void ExtScript::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), m_executable).toString());
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString());
setHasOutput(settings.value(QString("X-AW-Output"), QVariant(m_output)).toString() == QString("true"));
setStrRedirect(settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
// api == 3
setFilters(settings.value(QString("X-AW-Filters"), m_filters).toString()
.split(QChar(','), QString::SkipEmptyParts));
settings.endGroup();
}
if (!m_output)
setRedirect(stdout2stderr);
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
setApiVersion(AWESAPI);
writeConfiguration();
}
}
void ExtScript::readJsonFilters()
{
if (debug) qDebug() << PDEBUG;
QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QString("awesomewidgets/scripts/awesomewidgets-extscripts-filters.json"));
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
QFile jsonFile(fileName);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString jsonText = jsonFile.readAll();
jsonFile.close();
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
if (debug) qDebug() << PDEBUG << ":" << "Json parse error" << error.errorString();
if (error.error != QJsonParseError::NoError)
return;
jsonFilters = jsonDoc.toVariant().toMap();
if (debug) qDebug() << PDEBUG << ":" << "Filters" << jsonFilters;
}
QVariantMap ExtScript::run()
{
if (debug) qDebug() << PDEBUG;
if (!isActive()) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
QStringList cmdList;
if (!m_prefix.isEmpty()) cmdList.append(m_prefix);
cmdList.append(m_executable);
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmdList.join(QChar(' '));
process->start(cmdList.join(QChar(' ')));
} else if (times >= interval())
times = 0;
times++;
return value;
}
int ExtScript::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_command->setText(m_executable);
ui->lineEdit_prefix->setText(m_prefix);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->checkBox_output->setCheckState(m_output ? Qt::Checked : Qt::Unchecked);
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
ui->spinBox_interval->setValue(interval());
// filters
ui->checkBox_colorFilter->setCheckState(m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_linesFilter->setCheckState(m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_spaceFilter->setCheckState(m_filters.contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWESAPI);
setExecutable(ui->lineEdit_command->text());
setPrefix(ui->lineEdit_prefix->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setHasOutput(ui->checkBox_output->checkState() == Qt::Checked);
setStrRedirect(ui->comboBox_redirect->currentText());
setInterval(ui->spinBox_interval->value());
// filters
updateFilter(QString("color"), ui->checkBox_colorFilter->checkState() == Qt::Checked);
updateFilter(QString("newline"), ui->checkBox_linesFilter->checkState() == Qt::Checked);
updateFilter(QString("space"), ui->checkBox_spaceFilter->checkState() == Qt::Checked);
writeConfiguration();
return ret;
}
void ExtScript::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), m_executable);
settings.setValue(QString("X-AW-Prefix"), m_prefix);
settings.setValue(QString("X-AW-Output"), QVariant(m_output).toString());
settings.setValue(QString("X-AW-Redirect"), strRedirect());
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(',')));
settings.endGroup();
settings.sync();
}
void ExtScript::updateValue()
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardError()).trimmed();
if (debug) qDebug() << PDEBUG << ":" << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
switch (m_redirect) {
case stdout2stderr:
if (debug) qDebug() << PDEBUG << ":" << "Debug" << qdebug;
if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput;
break;
case stderr2stdout:
value[QString("value")] = QString("%1\n%2").arg(qdebug).arg(qoutput);
break;
case nothing:
default:
if (debug) qDebug() << PDEBUG << ":" << "Debug" << qdebug;
value[QString("value")] = qoutput;
break;
}
// filters
value[QString("value")] = applyFilters(value[QString("value")].toString());
}

View File

@ -1,98 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTSCRIPT_H
#define EXTSCRIPT_H
#include <QMap>
#include <QProcess>
#include "abstractextitem.h"
namespace Ui {
class ExtScript;
}
class ExtScript : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
Q_PROPERTY(QStringList filters READ filters WRITE setFilters)
Q_PROPERTY(bool output READ hasOutput WRITE setHasOutput)
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
public:
enum Redirect {
stdout2stderr = 0,
nothing,
stderr2stdout
};
explicit ExtScript(QWidget *parent = nullptr, const QString scriptName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
~ExtScript();
// get methods
QString executable() const;
QStringList filters() const;
bool hasOutput() const;
QString prefix() const;
Redirect redirect() const;
// derivatives
QString strRedirect() const;
// set methods
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setFilters(const QStringList _filters = QStringList());
void setHasOutput(const bool _state = true);
void setPrefix(const QString _prefix = QString(""));
void setRedirect(const Redirect _redirect = nothing);
void setStrRedirect(const QString _redirect = QString("nothing"));
// filters
QString applyFilters(QString _value) const;
void updateFilter(const QString _filter, const bool _add = true);
public slots:
void readConfiguration();
void readJsonFilters();
QVariantMap run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void updateValue();
private:
bool debug;
QProcess *process = nullptr;
Ui::ExtScript *ui;
// properties
QString m_executable = QString("/usr/bin/true");
QStringList m_filters = QStringList();
bool m_output = true;
QString m_prefix = QString("");
Redirect m_redirect = nothing;
// internal properties
Q_PID childProcess = 0;
QVariantMap jsonFilters = QVariantMap();
int times = 0;
QVariantMap value;
};
#endif /* EXTSCRIPT_H */

View File

@ -1,406 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtScript</class>
<widget class="QDialog" name="ExtScript">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>424</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_command">
<item>
<widget class="QLabel" name="label_command">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Command</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_command"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_prefix">
<item>
<widget class="QLabel" name="label_prefix">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Prefix</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_prefix"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_active">
<item>
<spacer name="spacer_active">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_active">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_output">
<item>
<spacer name="spacer_output">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_output">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Has output</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_redirect">
<item>
<widget class="QLabel" name="label_redirect">
<property name="text">
<string>Redirect</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_redirect">
<item>
<property name="text">
<string notr="true">stdout2stderr</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">nothing</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">stderr2stdout</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
<property name="text">
<string>Interval</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_interval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_filters">
<property name="title">
<string>Additional filters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="layout_colorFilter">
<item>
<spacer name="spacer_colorFilter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_colorFilter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Wrap colors</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_linesFilter">
<item>
<spacer name="spacer_linesFilter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_linesFilter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Wrap new lines</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_spaceFilter">
<item>
<spacer name="spacer_spaceFilter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_spaceFilter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Wrap spaces</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExtScript</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExtScript</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -57,10 +57,11 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList &args)
setMinimumPollingInterval(333);
readConfiguration();
initQuotes();
initScripts();
initUpgrade();
initWeather();
externalQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"), debug);
externalScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"), debug);
externalUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"), debug);
externalWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"), debug);
}
@ -68,10 +69,10 @@ ExtendedSysMon::~ExtendedSysMon()
{
if (debug) qDebug() << PDEBUG;
externalQuotes.clear();
externalScripts.clear();
externalUpgrade.clear();
externalWeather.clear();
delete externalQuotes;
delete externalScripts;
delete externalUpgrade;
delete externalWeather;
}
@ -128,122 +129,6 @@ QString ExtendedSysMon::getAutoMpris() const
}
void ExtendedSysMon::initQuotes()
{
if (debug) qDebug() << PDEBUG;
// create directory at $HOME and create dirs list
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));
}
}
}
void ExtendedSysMon::initScripts()
{
if (debug) qDebug() << PDEBUG;
// create directory at $HOME and create dirs list
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));
}
}
}
void ExtendedSysMon::initUpgrade()
{
if (debug) qDebug() << PDEBUG;
// create directory at $HOME and create dirs list
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));
}
}
}
void ExtendedSysMon::initWeather()
{
if (debug) qDebug() << PDEBUG;
// create directory at $HOME and create dirs list
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));
}
}
}
QStringList ExtendedSysMon::sources() const
{
if (debug) qDebug() << PDEBUG;
@ -701,8 +586,9 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
for (int i=0; i<battery.keys().count(); i++)
setData(source, battery.keys()[i], battery[battery.keys()[i]]);
} else if (source == QString("custom")) {
for (int i=0; i<externalScripts.count(); i++)
setData(source, externalScripts[i]->tag(QString("custom")), externalScripts[i]->run()[QString("value")]);
for (int i=0; i<externalScripts->items().count(); i++)
setData(source, externalScripts->items()[i]->tag(QString("custom")),
externalScripts->items()[i]->run()[QString("value")]);
} else if (source == QString("desktop")) {
QVariantMap desktop = getCurrentDesktop();
for (int i=0; i<desktop.keys().count(); i++)
@ -721,8 +607,9 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
} else if (source == QString("netdev")) {
setData(source, QString("value"), getNetworkDevice());
} else if (source == QString("pkg")) {
for (int i=0; i<externalUpgrade.count(); i++)
setData(source, externalUpgrade[i]->tag(QString("pkgcount")), externalUpgrade[i]->run()[QString("value")]);
for (int i=0; i<externalUpgrade->items().count(); i++)
setData(source, externalUpgrade->items()[i]->tag(QString("pkgcount")),
externalUpgrade->items()[i]->run()[QString("value")]);
} else if (source == QString("player")) {
QVariantMap player = getPlayerInfo(configuration[QString("PLAYER")],
configuration[QString("MPDADDRESS")],
@ -735,18 +622,20 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
for (int i=0; i<ps.keys().count(); i++)
setData(source, ps.keys()[i], ps[ps.keys()[i]]);
} else if (source == QString("quotes")) {
for (int i=0; i<externalQuotes.count(); i++) {
QVariantMap data = externalQuotes[i]->run();
for (int i=0; i<externalQuotes->items().count(); i++) {
QVariantMap data = externalQuotes->items()[i]->run();
for (int j=0; j<data.keys().count(); j++)
setData(source, externalQuotes[i]->tag(data.keys()[j]), data[data.keys()[j]]);
setData(source, externalQuotes->items()[i]->tag(data.keys()[j]),
data[data.keys()[j]]);
}
} else if (source == QString("update")) {
setData(source, QString("value"), true);
} else if (source == QString("weather")) {
for (int i=0; i<externalWeather.count(); i++) {
QVariantMap data = externalWeather[i]->run();
for (int i=0; i<externalWeather->items().count(); i++) {
QVariantMap data = externalWeather->items()[i]->run();
for (int j=0; j<data.keys().count(); j++)
setData(source, externalWeather[i]->tag(data.keys()[j]), data[data.keys()[j]]);
setData(source, externalWeather->items()[i]->tag(data.keys()[j]),
data[data.keys()[j]]);
}
}

View File

@ -20,6 +20,8 @@
#include <Plasma/DataEngine>
#include "extitemaggregator.h"
class ExtQuotes;
class ExtScript;
@ -57,19 +59,15 @@ protected:
private:
// configuration
QMap<QString, QString> configuration;
QList<ExtQuotes *> externalQuotes;
QList<ExtScript *> externalScripts;
QList<ExtUpgrade *> externalUpgrade;
QList<ExtWeather *> externalWeather;
ExtItemAggregator<ExtQuotes> *externalQuotes;
ExtItemAggregator<ExtScript> *externalScripts;
ExtItemAggregator<ExtUpgrade> *externalUpgrade;
ExtItemAggregator<ExtWeather> *externalWeather;
bool debug;
// reread configuration
QStringList getAllHdd() const;
QString getAutoGpu() const;
QString getAutoMpris() const;
void initQuotes();
void initScripts();
void initUpgrade();
void initWeather();
void readConfiguration();
QMap<QString, QString> updateConfiguration(QMap<QString, QString> rawConfig) const;
};

View File

@ -1,186 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "extupgrade.h"
#include "ui_extupgrade.h"
#include <QDebug>
#include <QDir>
#include <QSettings>
#include <QTextCodec>
#include <pdebug/pdebug.h>
#include "version.h"
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, upgradeName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtUpgrade)
{
readConfiguration();
ui->setupUi(this);
value[QString("value")] = 0;
process = new QProcess(this);
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
process->waitForFinished(0);
}
ExtUpgrade::~ExtUpgrade()
{
if (debug) qDebug() << PDEBUG;
process->kill();
delete process;
delete ui;
}
QString ExtUpgrade::executable() const
{
if (debug) qDebug() << PDEBUG;
return m_executable;
}
int ExtUpgrade::null() const
{
if (debug) qDebug() << PDEBUG;
return m_null;
}
void ExtUpgrade::setExecutable(const QString _executable)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Executable" << _executable;
m_executable = _executable;
}
void ExtUpgrade::setNull(const int _null)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Null lines" << _null;
if (_null < 0) return;
m_null = _null;
}
void ExtUpgrade::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), m_executable).toString());
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
settings.endGroup();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
setApiVersion(AWEUAPI);
writeConfiguration();
}
}
QVariantMap ExtUpgrade::run()
{
if (debug) qDebug() << PDEBUG;
if (!isActive()) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning))
process->start(QString("sh -c \"%1\"").arg(m_executable));
else if (times >= interval())
times = 0;
times++;
return value;
}
int ExtUpgrade::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_command->setText(m_executable);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_null->setValue(m_null);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEUAPI);
setExecutable(ui->lineEdit_command->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setNull(ui->spinBox_null->value());
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtUpgrade::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), m_executable);
settings.setValue(QString("X-AW-Null"), m_null);
settings.endGroup();
settings.sync();
}
void ExtUpgrade::updateValue()
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process->exitCode();
if (debug) qDebug() << PDEBUG << ":" << "Error" << process->readAllStandardError();
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
value[QString("value")] = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null;
}

View File

@ -1,70 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTUPGRADE_H
#define EXTUPGRADE_H
#include <QProcess>
#include "abstractextitem.h"
namespace Ui {
class ExtUpgrade;
}
class ExtUpgrade : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
Q_PROPERTY(int null READ null WRITE setNull)
public:
explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
~ExtUpgrade();
// get methods
QString executable() const;
int null() const;
// set methods
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setNull(const int _null = 0);
public slots:
void readConfiguration();
QVariantMap run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void updateValue();
private:
bool debug;
QProcess *process = nullptr;
Ui::ExtUpgrade *ui;
// properties
QString m_executable = QString("/usr/bin/true");
int m_null = 0;
// internal properties
int times = 0;
QVariantMap value;
};
#endif /* EXTUPGRADE_H */

View File

@ -1,251 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtUpgrade</class>
<widget class="QDialog" name="ExtUpgrade">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_command">
<item>
<widget class="QLabel" name="label_command">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Command</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_command"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_active">
<item>
<spacer name="spacer_active">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_active">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_null">
<item>
<widget class="QLabel" name="label_null">
<property name="text">
<string>Null</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_null">
<property name="minimum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
<property name="text">
<string>Interval</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_interval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>500</number>
</property>
<property name="value">
<number>3600</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExtUpgrade</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExtUpgrade</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,384 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "extweather.h"
#include "ui_extweather.h"
#include <QDebug>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSettings>
#include <pdebug/pdebug.h>
#include <qreplytimeout/qreplytimeout.h>
#include "version.h"
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, weatherName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtWeather)
{
readConfiguration();
ui->setupUi(this);
values[QString("weatherId")] = 0;
values[QString("weather")] = QString("");
values[QString("humidity")] = 0;
values[QString("pressure")] = 0.0;
values[QString("temperature")] = 0.0;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(weatherReplyReceived(QNetworkReply *)));
}
ExtWeather::~ExtWeather()
{
if (debug) qDebug() << PDEBUG;
disconnect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(weatherReplyReceived(QNetworkReply *)));
delete manager;
delete ui;
}
QString ExtWeather::weatherFromInt(const int _id) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ID" << _id;
// refer to http://openweathermap.org/weather-conditions
QString weather;
switch (_id) {
case 800:
// 01d
weather = QString("\u2600");
break;
case 801:
// 02d
weather = QString("\u26C5");
break;
case 802:
case 803:
// 03d
weather = QString("\u2601");
break;
case 804:
// 04d
weather = QString("\u2601");
break;
case 300:
case 301:
case 302:
case 310:
case 311:
case 312:
case 313:
case 314:
case 321:
case 520:
case 521:
case 522:
case 531:
// 09d
weather = QString("\u2602");
break;
case 500:
case 501:
case 502:
case 503:
case 504:
// 10d
weather = QString("\u2614");
break;
case 200:
case 201:
case 202:
case 210:
case 211:
case 212:
case 221:
case 230:
case 231:
case 232:
// 11d
weather = QString("\u2608");
break;
case 511:
case 600:
case 601:
case 602:
case 611:
case 612:
case 615:
case 616:
case 620:
case 621:
case 622:
// 13d
weather = QString("\u2603");
// weather = QString("\u26C4");
break;
case 701:
case 711:
case 721:
case 731:
case 741:
case 751:
case 761:
case 762:
case 771:
case 781:
// 50d
weather = QString("\u26C5");
break;
default:
// extreme other conditions
weather = QString("\u2604");
break;
}
return weather;
}
QString ExtWeather::city() const
{
if (debug) qDebug() << PDEBUG;
return m_city;
}
QString ExtWeather::country() const
{
if (debug) qDebug() << PDEBUG;
return m_country;
}
int ExtWeather::ts() const
{
if (debug) qDebug() << PDEBUG;
return m_ts;
}
void ExtWeather::setCity(const QString _city)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "City" << _city;
m_city = _city;
}
void ExtWeather::setCountry(const QString _country)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Country" << _country;
m_country = _country;
}
void ExtWeather::setTs(const int _ts)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Timestamp" << _ts;
m_ts = _ts;
}
void ExtWeather::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCity(settings.value(QString("X-AW-City"), m_city).toString());
setCountry(settings.value(QString("X-AW-Country"), m_country).toString());
setTs(settings.value(QString("X-AW-TS"), m_ts).toInt());
settings.endGroup();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
setApiVersion(AWEWAPI);
writeConfiguration();
}
}
QVariantMap ExtWeather::run()
{
if (debug) qDebug() << PDEBUG;
if ((!isActive()) || (isRunning)) return values;
if (times == 1) {
if (debug) qDebug() << PDEBUG << ":" << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
new QReplyTimeout(reply, 1000);
}
// update value
if (times >= interval()) times = 0;
times++;
return values;
}
int ExtWeather::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_city->setText(m_city);
ui->lineEdit_country->setText(m_country);
ui->spinBox_timestamp->setValue(m_ts);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEWAPI);
setCity(ui->lineEdit_city->text());
setCountry(ui->lineEdit_country->text());
setTs(ui->spinBox_timestamp->value());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtWeather::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-City"), m_city);
settings.setValue(QString("X-AW-Country"), m_country);
settings.setValue(QString("X-AW-TS"), m_ts);
settings.endGroup();
settings.sync();
}
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Return code" << reply->error();
if (debug) qDebug() << PDEBUG << ":" << "Reply error message" << reply->errorString();
isRunning = false;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if (debug) qDebug() << PDEBUG << ":" << "Json parse error" << error.errorString();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
return;
}
// convert to map
QVariantMap json = jsonDoc.toVariant().toMap();
if (json[QString("cod")].toInt() != 200) {
if (debug) qDebug() << PDEBUG << ":" << "Invalid return code";
return;
}
QVariantMap data;
if (m_ts == 0)
data = parseSingleJson(json);
else {
QVariantList list = json[QString("list")].toList();
data = parseSingleJson(list.count() <= m_ts ? list[m_ts-1].toMap() : list.last().toMap());
}
for (int i=0; i<data.keys().count(); i++)
values[data.keys()[i]] = data[data.keys()[i]];
}
QVariantMap ExtWeather::parseSingleJson(const QVariantMap json) const
{
if (debug) qDebug() << PDEBUG;
QVariantMap output;
// weather status
QVariantList weather = json[QString("weather")].toList();
if (weather.count() > 0) {
int _id = weather[0].toMap()[QString("id")].toInt();
output[QString("weatherId")] = _id;
output[QString("weather")] = weatherFromInt(_id);
}
// main data
QVariantMap mainWeather = json[QString("main")].toMap();
if (weather.count() > 0) {
output[QString("humidity")] = mainWeather[QString("humidity")].toFloat();
output[QString("pressure")] = mainWeather[QString("pressure")].toFloat();
output[QString("temperature")] = mainWeather[QString("temp")].toFloat();
}
return output;
}
QString ExtWeather::url(const bool isForecast) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << "Is forecast" << isForecast;
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
apiUrl.replace(QString("$CITY"), m_city);
apiUrl.replace(QString("$COUNTRY"), m_country);
if (debug) qDebug() << PDEBUG << ":" << "API url" << apiUrl;
return apiUrl;
}

View File

@ -1,82 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTWEATHER_H
#define EXTWEATHER_H
#include <QMap>
#include <QNetworkReply>
#include "abstractextitem.h"
#define OWM_URL "http://api.openweathermap.org/data/2.5/weather?q=$CITY,$COUNTRY&units=metric"
#define OWM_FORECAST_URL "http://api.openweathermap.org/data/2.5/forecast?q=$CITY,$COUNTRY&units=metric"
namespace Ui {
class ExtWeather;
}
class ExtWeather : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString city READ city WRITE setCity)
Q_PROPERTY(QString country READ country WRITE setCountry)
Q_PROPERTY(int ts READ ts WRITE setTs)
public:
explicit ExtWeather(QWidget *parent = nullptr, const QString weatherName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
~ExtWeather();
QString weatherFromInt(const int _id) const;
// get methods
QString city() const;
QString country() const;
int ts() const;
// set methods
void setCity(const QString _city = QString("London"));
void setCountry(const QString _country = QString("uk"));
void setTs(const int _ts = 0);
public slots:
void readConfiguration();
QVariantMap run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void weatherReplyReceived(QNetworkReply *reply);
private:
bool debug;
QNetworkAccessManager *manager;
bool isRunning = false;
Ui::ExtWeather *ui;
QVariantMap parseSingleJson(const QVariantMap json) const;
QString url(const bool isForecast = false) const;
// properties
QString m_city = QString("London");
QString m_country = QString("uk");
int m_ts = 0;
// values
int times = 0;
QVariantMap values;
};
#endif /* EXTWEATHER_H */

View File

@ -1,271 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtWeather</class>
<widget class="QDialog" name="ExtWeather">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_city">
<item>
<widget class="QLabel" name="label_city">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>City</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_city"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_country">
<item>
<widget class="QLabel" name="label_country">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Country</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_country"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_timestamp">
<item>
<widget class="QLabel" name="label_timestamp">
<property name="text">
<string>Timestamp</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_timestamp">
<property name="maximum">
<number>40</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_active">
<item>
<spacer name="spacer_active">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_active">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
<property name="text">
<string>Interval</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_interval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>60</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExtWeather</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExtWeather</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,454 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "graphicalitem.h"
#include "ui_graphicalitem.h"
#include <QBuffer>
#include <QColorDialog>
#include <QDebug>
#include <QDir>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QSettings>
#include <pdebug/pdebug.h>
#include "version.h"
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, desktopName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::GraphicalItem)
{
readConfiguration();
ui->setupUi(this);
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor()));
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, SLOT(changeColor()));
}
GraphicalItem::~GraphicalItem()
{
if (debug) qDebug() << PDEBUG;
delete ui;
}
QString GraphicalItem::image(const float value) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Value" << value;
if (m_bar == QString("none")) return QString("");
QColor active = stringToColor(m_activeColor);
QColor inactive = stringToColor(m_inactiveColor);
float percent = value / 100.0;
int scale[2] = {1, 1};
QPen pen = QPen();
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(Qt::NoBrush));
QGraphicsView *view = new QGraphicsView(scene);
view->setStyleSheet(QString("background: transparent"));
view->setContentsMargins(0, 0, 0, 0);
view->setFrameShape(QFrame::NoFrame);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->resize(m_width + 5.0, m_height + 5.0);
// paint
switch (m_type) {
case Vertical:
pen.setWidth(m_width);
// inactive
pen.setColor(inactive);
scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
(1.0 - percent) * m_height - 0.5 * m_width, pen);
// active
pen.setColor(active);
scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width,
0.5 * m_width, m_height + 0.5 * m_width, pen);
// scale
scale[1] = -2 * static_cast<int>(m_direction) + 1;
break;
case Circle:
QGraphicsEllipseItem *circle;
pen.setWidth(1.0);
// inactive
pen.setColor(inactive);
circle = scene->addEllipse(0.0, 0.0, m_width, m_height, pen, QBrush(inactive, Qt::SolidPattern));
circle->setSpanAngle(- (1.0 - percent) * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0 - percent * 360.0 * 16.0);
// active
pen.setColor(active);
circle = scene->addEllipse(0.0, 0.0, m_width, m_height, pen, QBrush(active, Qt::SolidPattern));
circle->setSpanAngle(- percent * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
break;
default:
pen.setWidth(m_height);
// inactive
pen.setColor(inactive);
scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height,
m_width + 0.5 * m_height, 0.5 * m_height, pen);
// active
pen.setColor(active);
scene->addLine(-0.5 * m_height, 0.5 * m_height,
percent * m_width - 0.5 * m_height, 0.5 * m_height, pen);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
break;
}
// convert
QPixmap pixmap = view->grab().transformed(QTransform().scale(scale[0], scale[1]));
QByteArray byteArray;
QBuffer buffer(&byteArray);
pixmap.save(&buffer, "PNG");
QString url = QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
delete view;
delete scene;
return url;
}
QString GraphicalItem::bar() const
{
if (debug) qDebug() << PDEBUG;
return m_bar;
}
QString GraphicalItem::activeColor() const
{
if (debug) qDebug() << PDEBUG;
return m_activeColor;
}
QString GraphicalItem::inactiveColor() const
{
if (debug) qDebug() << PDEBUG;
return m_inactiveColor;
}
GraphicalItem::Type GraphicalItem::type() const
{
if (debug) qDebug() << PDEBUG;
return m_type;
}
QString GraphicalItem::strType() const
{
if (debug) qDebug() << PDEBUG;
QString value;
switch (m_type) {
case Vertical:
value = QString("Vertical");
break;
case Circle:
value = QString("Circle");
break;
default:
value = QString("Horizontal");
break;
}\
return value;
}
GraphicalItem::Direction GraphicalItem::direction() const
{
if (debug) qDebug() << PDEBUG;
return m_direction;
}
QString GraphicalItem::strDirection() const
{
if (debug) qDebug() << PDEBUG;
QString value;
switch (m_direction) {
case RightToLeft:
value = QString("RightToLeft");
break;
default:
value = QString("LeftToRight");
break;
}
return value;
}
int GraphicalItem::height() const
{
if (debug) qDebug() << PDEBUG;
return m_height;
}
int GraphicalItem::width() const
{
if (debug) qDebug() << PDEBUG;
return m_width;
}
void GraphicalItem::setBar(const QString _bar)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Bar" << _bar;
if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) &&
(!_bar.contains(QRegExp(QString("gpu")))) &&
(!_bar.contains(QRegExp(QString("mem")))) &&
(!_bar.contains(QRegExp(QString("swap")))) &&
(!_bar.contains(QRegExp(QString("hdd[0-9].*")))) &&
(!_bar.contains(QRegExp(QString("bat.*")))))
m_bar = QString("none");
else
m_bar = _bar;
}
void GraphicalItem::setActiveColor(const QString _color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
m_activeColor = _color;
}
void GraphicalItem::setInactiveColor(const QString _color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
m_inactiveColor = _color;
}
void GraphicalItem::setType(const Type _type)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << _type;
m_type = _type;
}
void GraphicalItem::setStrType(const QString _type)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << _type;
if (_type == QString("Vertical"))
setType(Vertical);
else if (_type == QString("Circle"))
setType(Circle);
else
setType(Horizontal);
}
void GraphicalItem::setDirection(const Direction _direction)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Direction" << _direction;
m_direction = _direction;
}
void GraphicalItem::setStrDirection(const QString _direction)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Direction" << _direction;
if (_direction == QString("RightToLeft"))
setDirection(RightToLeft);
else
setDirection(LeftToRight);
}
void GraphicalItem::setHeight(const int _height)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Height" << _height;
if (_height <= 0) return;
m_height = _height;
}
void GraphicalItem::setWidth(const int _width)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Width" << _width;
if (_width <= 0) return;
m_width = _width;
}
void GraphicalItem::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
setActiveColor(settings.value(QString("X-AW-ActiveColor"), m_activeColor).toString());
setInactiveColor(settings.value(QString("X-AW-InactiveColor"), m_inactiveColor).toString());
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
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());
settings.endGroup();
}
}
QVariantMap GraphicalItem::run()
{
if (debug) qDebug() << PDEBUG;
// required by abstract class
return QVariantMap();
}
int GraphicalItem::showConfiguration(const QVariant args)
{
if (debug) qDebug() << PDEBUG;
QStringList tags = args.toStringList();
ui->label_nameValue->setText(name());
ui->lineEdit_comment->setText(comment());
ui->comboBox_value->addItems(tags);
ui->comboBox_value->addItem(m_bar);
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
ui->pushButton_activeColor->setText(m_activeColor);
ui->pushButton_inactiveColor->setText(m_inactiveColor);
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction));
ui->spinBox_height->setValue(m_height);
ui->spinBox_width->setValue(m_width);
int ret = exec();
if (ret != 1) return ret;
setName(ui->label_nameValue->text());
setComment(ui->lineEdit_comment->text());
setApiVersion(AWGIAPI);
setBar(ui->comboBox_value->currentText());
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
setStrType(ui->comboBox_type->currentText());
setStrDirection(ui->comboBox_direction->currentText());
setHeight(ui->spinBox_height->value());
setWidth(ui->spinBox_width->value());
writeConfiguration();
return ret;
}
void GraphicalItem::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
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);
settings.setValue(QString("X-AW-Type"), strType());
settings.setValue(QString("X-AW-Direction"), strDirection());
settings.setValue(QString("X-AW-Height"), m_height);
settings.setValue(QString("X-AW-Width"), m_width);
settings.endGroup();
settings.sync();
}
void GraphicalItem::changeColor()
{
if (debug) qDebug() << PDEBUG;
QColor color = stringToColor((dynamic_cast<QPushButton *>(sender()))->text());
QColor newColor = QColorDialog::getColor(color, 0, tr("Select color"),
QColorDialog::ShowAlphaChannel);
if (!newColor.isValid()) return;
QStringList colorText;
colorText.append(QString("%1").arg(newColor.red()));
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(',')));
}
QColor GraphicalItem::stringToColor(const QString _color) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
QColor qcolor;
QStringList listColor = _color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
qcolor.setRed(listColor[0].toInt());
qcolor.setGreen(listColor[1].toInt());
qcolor.setBlue(listColor[2].toInt());
qcolor.setAlpha(listColor[3].toInt());
return qcolor;
}

View File

@ -1,107 +0,0 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef GRAPHICALITEM_H
#define GRAPHICALITEM_H
#include <QColor>
#include "abstractextitem.h"
namespace Ui {
class GraphicalItem;
}
class GraphicalItem : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString bar READ bar WRITE setBar)
Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor)
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
Q_PROPERTY(Type type READ type WRITE setType)
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
Q_PROPERTY(int height READ height WRITE setHeight)
Q_PROPERTY(int width READ width WRITE setWidth)
public:
enum Direction {
LeftToRight = 0,
RightToLeft
};
enum Type {
Horizontal = 0,
Vertical,
Circle
};
explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(),
const QStringList directories = QStringList(),
const bool debugCmd = false);
~GraphicalItem();
QString image(const float value) const;
// get methods
QString bar() const;
QString activeColor() const;
QString inactiveColor() const;
Type type() const;
QString strType() const;
Direction direction() const;
QString strDirection() const;
int height() const;
int width() const;
// set methods
void setBar(const QString _bar = QString("cpu"));
void setActiveColor(const QString _color = QString("0,0,0,130"));
void setInactiveColor(const QString _color = QString("255,255,255,130"));
void setType(const Type _type = Horizontal);
void setStrType(const QString _type = QString("Horizontal"));
void setDirection(const Direction _direction = LeftToRight);
void setStrDirection(const QString _direction = QString("LeftToRight"));
void setHeight(const int _height = 100);
void setWidth(const int _width = 100);
public slots:
void readConfiguration();
QVariantMap run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void changeColor();
private:
QColor stringToColor(const QString _color) const;
QString m_fileName;
QStringList m_dirs;
bool debug;
Ui::GraphicalItem *ui;
// properties
int m_apiVersion = 0;
QString m_name = QString("none");
QString m_comment = QString("empty");
QString m_bar = QString("cpu");
QString m_activeColor = QString("0,0,0,130");
QString m_inactiveColor = QString("255,255,255,130");
Type m_type = Horizontal;
Direction m_direction = LeftToRight;
int m_height = 100;
int m_width = 100;
};
#endif /* GRAPHICALITEM_H */

View File

@ -1,293 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GraphicalItem</class>
<widget class="QDialog" name="GraphicalItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>325</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_nameValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_value">
<item>
<widget class="QLabel" name="label_value">
<property name="text">
<string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_value">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeColor">
<item>
<widget class="QLabel" name="label_activeColor">
<property name="text">
<string>Active color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_activeColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveColor">
<item>
<widget class="QLabel" name="label_inactiveColor">
<property name="text">
<string>Inactive color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_inactiveColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_type">
<item>
<widget class="QLabel" name="label_type">
<property name="text">
<string>Type</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_type">
<item>
<property name="text">
<string notr="true">Horizontal</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Vertical</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Circle</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_direction">
<item>
<widget class="QLabel" name="label_direction">
<property name="text">
<string>Direction</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_direction">
<item>
<property name="text">
<string notr="true">LeftToRight</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">RightToLeft</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_height">
<item>
<widget class="QLabel" name="label_height">
<property name="text">
<string>Height</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_height">
<property name="maximum">
<number>2000</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_width">
<item>
<widget class="QLabel" name="label_width">
<property name="text">
<string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_width">
<property name="maximum">
<number>2000</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GraphicalItem</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GraphicalItem</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=AAPL.NASDAQ
Comment=Apple Inc
X-AW-Ticker="AAPL"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=0

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=EUR/RUB
Comment=EUR/RUB
X-AW-Ticker="EURRUB=X"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=1

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=EUR/USD
Comment=EUR/USD
X-AW-Ticker="EURUSD=X"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=2

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=GOOG.NASDAQ
Comment=Google Inc
X-AW-Ticker="GOOG"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=3

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=MSFT.NASDAQ
Comment=Microsoft Corp
X-AW-Ticker="MSFT"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=4

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=RTS
Comment=RTS Index
X-AW-Ticker="RTS.RS"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=5

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=S&P
Comment=S&P 500 Index
X-AW-Ticker="^GSPC"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=6

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=USD/RUB
Comment=USD/RUB
X-AW-Ticker="USDRUB=X"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=8

View File

@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=VIX
Comment=Volatility S&P 500
X-AW-Ticker="^VIX"
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-Interval=60
X-AW-Number=7

View File

@ -1,29 +0,0 @@
{
"color": {
"\u001b[0;30m": "<span style=\"color:'#000000';\">",
"\u001b[1;30m": "<span style=\"color:'#808080';\">",
"\u001b[0;31m": "<span style=\"color:'#800000';\">",
"\u001b[1;31m": "<span style=\"color:'#ff0000';\">",
"\u001b[0;32m": "<span style=\"color:'#008000';\">",
"\u001b[1;32m": "<span style=\"color:'#00ff00';\">",
"\u001b[0;33m": "<span style=\"color:'#808000';\">",
"\u001b[1;33m": "<span style=\"color:'#ffff00';\">",
"\u001b[0;34m": "<span style=\"color:'#000080';\">",
"\u001b[1;34m": "<span style=\"color:'#0000ff';\">",
"\u001b[0;35m": "<span style=\"color:'#800080';\">",
"\u001b[1;35m": "<span style=\"color:'#ff00ff';\">",
"\u001b[0;36m": "<span style=\"color:'#008080';\">",
"\u001b[1;36m": "<span style=\"color:'#00ffff';\">",
"\u001b[0;37m": "<span style=\"color:'#c0c0c0';\">",
"\u001b[1;37m": "<span style=\"color:'#ffffff';\">",
"\u001b[0m": "</span>"
},
"newline": {
"\n": "<br>",
"\n\r": "<br>",
"\t": "&#09;"
},
"space": {
" ": "&nbsp;"
}
}

View File

@ -1,13 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=aw-get-external-ip
Comment=Custom command to get external IP
Exec=curl ip4.telize.com
X-AW-Prefix=
X-AW-Active=true
X-AW-Output=true
X-AW-Redirect=nothing
X-AW-Interval=1
X-AW-ApiVersion=3
X-AW-Number=0
X-AW-Filters=

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=default-arch
Comment=Archlinux upgrade info
Exec=pacman -Qu
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-Number=0

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=default-debian
Comment=Debian upgrade info
Exec=apt-show-versions -u -b
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-Number=1

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=default-fedora
Comment=Fedora upgrade info
Exec=yum list updates
X-AW-Active=false
X-AW-Null=3
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-Number=2

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=default-mandriva
Comment=Mandriva upgrade info
Exec=urpmq --auto-select
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-Number=3

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=default-ubuntu
Comment=Ubuntu upgrade info
Exec=aptitude search '~U'
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-Number=4

View File

@ -1,11 +0,0 @@
[Desktop Entry]
Comment=London current weather
Encoding=UTF-8
Name=London current
X-AW-Active=false
X-AW-ApiVersion=1
X-AW-City=London
X-AW-Country=uk
X-AW-Interval=3600
X-AW-Number=0
X-AW-TS=0