initial support of quotes

This commit is contained in:
arcan1s
2015-04-28 16:43:34 +03:00
parent 7ae90bf82d
commit fd8f2127d9
46 changed files with 3149 additions and 703 deletions

View File

@ -11,7 +11,7 @@ if (BUILD_KDE4)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
set (KDE_INCLUDE ${KDE4_INCLUDES})
else ()
find_package (Qt5 REQUIRED COMPONENTS DBus Network Widgets)
find_package (Qt5 REQUIRED COMPONENTS DBus Network Widgets Xml)
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)
@ -21,11 +21,9 @@ else ()
include (KDECompilerSettings)
add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS}
${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Xml_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS})
set (KDE_INCLUDE ${Plasma_INCLUDE_DIR})
endif ()
@ -43,6 +41,7 @@ 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_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
set (SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
set (SUBPROJECT_UPGRADE ${CMAKE_CURRENT_SOURCE_DIR}/upgrade)
@ -54,13 +53,14 @@ if (BUILD_KDE4)
qt4_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER})
kde4_add_ui_files (SUBPROJECT_SOURCE ${SUBPROJECT_UI})
kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE})
target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTNETWORK_LIBRARY})
target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS}
${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY})
else ()
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})
${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Xml_LIBRARIES})
kcoreaddons_desktop_to_json (${PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
endif ()
@ -72,5 +72,6 @@ else ()
endif ()
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})
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})

View File

@ -0,0 +1,319 @@
/***************************************************************************
* 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 <QDomDocument>
#include <QDomElement>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSettings>
#include <pdebug/pdebug.h>
#include "version.h"
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName, const QStringList directories, const bool debugCmd)
: QDialog(parent),
m_fileName(quotesName),
m_dirs(directories),
debug(debugCmd),
ui(new Ui::ExtQuotes)
{
m_name = m_fileName;
readConfiguration();
ui->setupUi(this);
values[QString("ask")] = 0.0;
values[QString("bid")] = 0.0;
values[QString("price")] = 0.0;
}
ExtQuotes::~ExtQuotes()
{
if (debug) qDebug() << PDEBUG;
delete ui;
}
int ExtQuotes::apiVersion()
{
if (debug) qDebug() << PDEBUG;
return m_apiVersion;
}
QString ExtQuotes::comment()
{
if (debug) qDebug() << PDEBUG;
return m_comment;
}
QString ExtQuotes::fileName()
{
if (debug) qDebug() << PDEBUG;
return m_fileName;
}
int ExtQuotes::interval()
{
if (debug) qDebug() << PDEBUG;
return m_interval;
}
bool ExtQuotes::isActive()
{
if (debug) qDebug() << PDEBUG;
return m_active;
}
QString ExtQuotes::name()
{
if (debug) qDebug() << PDEBUG;
return m_name;
}
QString ExtQuotes::ticker()
{
if (debug) qDebug() << PDEBUG;
return m_ticker;
}
void ExtQuotes::setApiVersion(const int _apiVersion)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
m_apiVersion = _apiVersion;
}
void ExtQuotes::setActive(const bool state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
m_active = state;
}
void ExtQuotes::setComment(const QString _comment)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
m_comment = _comment;
}
void ExtQuotes::setInterval(const int _interval)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
m_interval = _interval;
}
void ExtQuotes::setName(const QString _name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
m_name = _name;
}
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;
for (int i=m_dirs.count()-1; i>=0; i--) {
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
QSettings settings(m_dirs[i] + QDir::separator() + 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"), AWEQAPI).toInt());
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString());
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
settings.endGroup();
}
}
QMap<QString, float> ExtQuotes::run()
{
if (debug) qDebug() << PDEBUG;
if (!m_active) return values;
qDebug() << PDEBUG << times;
if (times == 1) {
if (debug) qDebug() << PDEBUG << ":" << "Send request";
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
manager->get(QNetworkRequest(QUrl(url())));
}
// update value
if (times >= m_interval) times = 0;
times++;
return values;
}
int ExtQuotes::showConfiguration()
{
if (debug) qDebug() << PDEBUG;
ui->lineEdit_name->setText(m_name);
ui->lineEdit_comment->setText(m_comment);
ui->lineEdit_ticker->setText(m_ticker);
if (m_active)
ui->checkBox_active->setCheckState(Qt::Checked);
else
ui->checkBox_active->setCheckState(Qt::Unchecked);
ui->spinBox_interval->setValue(m_interval);
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setApiVersion(AWEQAPI);
setTicker(ui->lineEdit_ticker->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
int ExtQuotes::tryDelete()
{
if (debug) qDebug() << PDEBUG;
for (int i=0; i<m_dirs.count(); i++)
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << m_dirs[i] + QDir::separator() + m_fileName <<
QFile::remove(m_dirs[i] + QDir::separator() + m_fileName);
// check if exists
for (int i=0; i<m_dirs.count(); i++)
if (QFile::exists(m_dirs[i] + QDir::separator() + m_fileName)) return 0;
return 1;
}
void ExtQuotes::writeConfiguration()
{
if (debug) qDebug() << PDEBUG;
QSettings settings(m_dirs[0] + QDir::separator() + 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-Ticker"), m_ticker);
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.endGroup();
settings.sync();
}
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
{
if (debug) qDebug() << PDEBUG << reply->url();
QDomDocument doc;
if (!doc.setContent(reply)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not parse answer to XML";
return;
}
QDomNodeList fields;
// ask
fields = doc.elementsByTagName(QString("Ask"));
for (int i=0; i<fields.size(); i++) {
values[QString("ask")] = fields.item(i).toElement().text().toFloat();
if (debug) qDebug() << PDEBUG << "Found ask" << values[QString("ask")];
}
// bid
fields = doc.elementsByTagName(QString("Bid"));
for (int i=0; i<fields.size(); i++) {
values[QString("bid")] = fields.item(i).toElement().text().toFloat();
if (debug) qDebug() << PDEBUG << "Found bid" << values[QString("bid")];
}
// last trade
fields = doc.elementsByTagName(QString("LastTradePriceOnly"));
for (int i=0; i<fields.size(); i++) {
values[QString("price")] = fields.item(i).toElement().text().toFloat();
if (debug) qDebug() << PDEBUG << "Found last trade" << values[QString("price")];
}
reply->deleteLater();
}
QString ExtQuotes::url()
{
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

@ -0,0 +1,92 @@
/***************************************************************************
* 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 <QDialog>
#include <QMap>
#define YAHOO_URL "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in (\"$TICKER\")&env=store://datatables.org/alltableswithkeys"
class QNetworkReply;
namespace Ui {
class ExtQuotes;
}
class ExtQuotes : public QDialog
{
Q_OBJECT
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(int interval READ interval WRITE setInterval)
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
public:
explicit ExtQuotes(QWidget *parent = 0, const QString quotesName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false);
~ExtQuotes();
// get methods
int apiVersion();
QString comment();
QString fileName();
int interval();
bool isActive();
QString name();
QString ticker();
// 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 = 0);
void setName(const QString _name = QString("none"));
void setTicker(const QString _ticker = QString("EURUSD=X"));
public slots:
void readConfiguration();
QMap<QString, float> run();
int showConfiguration();
int tryDelete();
void writeConfiguration();
private slots:
void quotesReplyReceived(QNetworkReply *reply);
private:
QString m_fileName;
QStringList m_dirs;
bool debug;
Ui::ExtQuotes *ui;
QString url();
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
int m_interval = 60;
QString m_name = QString("none");
QString m_ticker = QString("EURUSD=X");
// values
int times = 0;
QMap<QString, float> values;
};
#endif /* EXTQUOTES_H */

View File

@ -0,0 +1,219 @@
<?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>
<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

@ -308,8 +308,8 @@ QString ExtScript::run()
}
// update value
times++;
if (times >= m_interval) times = 0;
times++;
return value;
}

View File

@ -37,6 +37,7 @@
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
#include "extquotes.h"
#include "extscript.h"
#include "extupgrade.h"
#include "version.h"
@ -62,6 +63,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList &args)
setMinimumPollingInterval(333);
readConfiguration();
initQuotes();
initScripts();
initUpgrade();
}
@ -120,6 +122,45 @@ QString ExtendedSysMon::getAutoMpris()
}
void ExtendedSysMon::initQuotes()
{
if (debug) qDebug() << PDEBUG;
// create directory at $HOME and create dirs list
QString localDir;
QStringList dirs;
#ifdef BUILD_KDE4
localDir = KStandardDirs::locateLocal("data", "awesomewidgets/quotes");
if (KStandardDirs::makeDir(localDir))
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
dirs = KGlobal::dirs()->findDirs("data", "awesomewidgets/quotes");
#else
localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
QString("/awesomewidgets/quotes");
QDir localDirectory;
if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir)))
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
QString("awesomewidgets/quotes"),
QStandardPaths::LocateDirectory);
#endif /* BUILD_KDE4 */
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(0, files[j], dirs, debug));
}
}
}
void ExtendedSysMon::initScripts()
{
if (debug) qDebug() << PDEBUG;
@ -213,6 +254,7 @@ QStringList ExtendedSysMon::sources() const
source.append(QString("pkg"));
source.append(QString("player"));
source.append(QString("ps"));
source.append(QString("quotes"));
source.append(QString("update"));
if (debug) qDebug() << PDEBUG << ":" << "Sources" << source;
@ -665,7 +707,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
}
} else if (source == QString("custom")) {
for (int i=0; i<externalScripts.count(); i++)
setData(source, QString("custom") + QString::number(i), externalScripts[i]->run());
setData(source, QString("custom%1").arg(i), externalScripts[i]->run());
} else if (source == QString("desktop")) {
QMap<QString, QVariant> desktop = getCurrentDesktop();
for (int i=0; i<desktop.keys().count(); i++)
@ -686,7 +728,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
setData(source, QString("value"), getNetworkDevice());
} else if (source == QString("pkg")) {
for (int i=0; i<externalUpgrade.count(); i++)
setData(source, QString("pkgcount") + QString::number(i), externalUpgrade[i]->run());
setData(source, QString("pkgcount%1").arg(i), externalUpgrade[i]->run());
} else if (source == QString("player")) {
QMap<QString, QVariant> player = getPlayerInfo(configuration[QString("PLAYER")],
configuration[QString("MPDADDRESS")],
@ -698,6 +740,13 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
QMap<QString, QVariant> ps = getPsStats();
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++) {
QMap<QString, float> data = externalQuotes[i]->run();
setData(source, QString("ask%1").arg(i), data[QString("ask")]);
setData(source, QString("bid%1").arg(i), data[QString("bid")]);
setData(source, QString("price%1").arg(i), data[QString("price")]);
}
} else if (source == QString("update")) {
setData(source, QString("value"), true);
}

View File

@ -22,6 +22,7 @@
#include <QProcess>
class ExtQuotes;
class ExtScript;
class ExtUpgrade;
@ -55,6 +56,7 @@ protected:
private:
// configuration
QMap<QString, QString> configuration;
QList<ExtQuotes *> externalQuotes;
QList<ExtScript *> externalScripts;
QList<ExtUpgrade *> externalUpgrade;
bool debug;
@ -63,6 +65,7 @@ private:
QString getAllHdd();
QString getAutoGpu();
QString getAutoMpris();
void initQuotes();
void initScripts();
void initUpgrade();
void readConfiguration();

View File

@ -29,12 +29,12 @@
#include "version.h"
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName, const QStringList directories, const bool debugCmd) :
QDialog(parent),
m_fileName(upgradeName),
m_dirs(directories),
debug(debugCmd),
ui(new Ui::ExtUpgrade)
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName, const QStringList directories, const bool debugCmd)
: QDialog(parent),
m_fileName(upgradeName),
m_dirs(directories),
debug(debugCmd),
ui(new Ui::ExtUpgrade)
{
m_name = m_fileName;
readConfiguration();
@ -189,7 +189,7 @@ void ExtUpgrade::readConfiguration()
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"), AWESAPI).toInt());
setApiVersion(settings.value(QString("X-AW-ApiVersion"), AWEUAPI).toInt());
setExecutable(settings.value(QString("Exec"), m_executable).toString());
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
@ -215,8 +215,8 @@ int ExtUpgrade::run()
}
// update value
times++;
if (times >= m_interval) times = 0;
times++;
return value;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Encoding=UTF-8
Name=RTS
Comment=RTS Index
X-AW-Ticker=RTS.RS
X-AW-Active=true
X-AW-ApiVersion=1
X-AW-Interval=60

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ Encoding=UTF-8
Name=default-arch
Comment=Archlinux upgrade info
Exec=pacman -Qu
X-AW-Prefix=
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600

View File

@ -3,7 +3,6 @@ Encoding=UTF-8
Name=default-debian
Comment=Debian upgrade info
Exec=apt-show-versions -u -b
X-AW-Prefix=
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600

View File

@ -3,7 +3,6 @@ Encoding=UTF-8
Name=default-fedora
Comment=Fedora upgrade info
Exec=yum list updates
X-AW-Prefix=
X-AW-Active=false
X-AW-Null=3
X-AW-Interval=3600

View File

@ -3,7 +3,6 @@ Encoding=UTF-8
Name=default-mandriva
Comment=Mandriva upgrade info
Exec=urpmq --auto-select
X-AW-Prefix=
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600

View File

@ -3,7 +3,6 @@ Encoding=UTF-8
Name=default-ubuntu
Comment=Ubuntu upgrade info
Exec=aptitude search '~U'
X-AW-Prefix=
X-AW-Active=false
X-AW-Null=0
X-AW-Interval=3600