Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fd0422b4 authored by Stephane Mankowski's avatar Stephane Mankowski

KPI key in settings

parent 464c67b8
......@@ -186,7 +186,7 @@ If you don't want to install Skrooge on your system, you will have to set many Q
### With coverity
export PATH=~/Telechargements/cov-analysis-linux64-2017.07/bin/:$PATH
export PATH=~/Telechargements/cov-analysis-linux64-2019.03/bin/:$PATH
make clean
cov-build --dir cov-int make -j 4
tar caf skrooge.bz2 cov-int
......
......@@ -24,6 +24,7 @@
#include <kaboutdata.h>
#include <kactioncollection.h>
#include <kpluginfactory.h>
#include <kservicetypetrader.h>
#include <qaction.h>
#include <qinputdialog.h>
......@@ -186,7 +187,43 @@ QWidget* SKGUnitPlugin::getPreferenceWidget()
SKGTRACEINFUNC(10)
auto w = new QWidget();
ui.setupUi(w);
// Get sources from.desktop file
QStringList sources;
const auto list2 = KServiceTypeTrader::self()->query(QStringLiteral("skrooge/source"));
for (const auto& service : list2) {
auto name = service->property(QStringLiteral("X-KDE-PluginInfo-Name"), QVariant::String).toString();
auto keyAPI = service->property(QStringLiteral("X-SKROOGE-keyAPI"), QVariant::Bool).toBool();
if (!sources.contains(name) && keyAPI) {
sources.push_back(name);
}
}
sources.sort();
auto nb = sources.count();
auto lwidgets = new QHash<QString, QLineEdit*>();
for (auto i = 0; i < nb; ++i) {
// Get Current value
auto ln = new QLineEdit(w);
ln->setText(m_currentBankDocument->getParameter("KEYAPI_" + sources[i]));
lwidgets->insert(sources.value(i), ln);
ui.kAPIKeyLayout->addWidget(new QLabel(sources[i] + ':', w), i, 0);
ui.kAPIKeyLayout->addWidget(ln, i, 1);
}
connect(ui.kcfg_download_on_open, &QCheckBox::toggled, ui.kcfg_download_frequency, &KComboBox::setEnabled);
connect(ui.kSave, &QPushButton::clicked, this, [ = ]() {
SKGError err;
{
SKGBEGINTRANSACTION(*m_currentBankDocument, i18nc("Noun, name of the user action", "Save API keys"), err)
foreach (auto k, lwidgets->keys()) {
m_currentBankDocument->setParameter("KEYAPI_" + k, lwidgets->value(k)->text());
}
}
// Display error
SKGMainPanel::displayErrorMessage(err);
});
return w;
}
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>334</height>
<width>596</width>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -158,6 +158,45 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="apikeysBox">
<property name="title">
<string>API Keys</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="apikeys_label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Some download sources (e.g. coinmarketcap, cryptocompare) may require an API key. So you need to request one from the source site and enter it here:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="kAPIKeyLayout">
<property name="spacing">
<number>2</number>
</property>
</layout>
</item>
<item>
<widget class="QPushButton" name="kSave">
<property name="toolTip">
<string>For security reasons, these keys are not save in setting file but in your document.</string>
</property>
<property name="text">
<string>Save in document</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -60,3 +60,4 @@ INSTALL(DIRECTORY sources DESTINATION ${KDE_INSTALL_KSERVICES5DIR} FILES_MATCHIN
INSTALL(PROGRAMS skrooge-yahoodl.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-ratesapi.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-cryptocompare.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-coinmarketcap.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
......@@ -2339,6 +2339,7 @@ SKGError SKGUnitObject::downloadUnitValue(UnitDownloadMode iMode, int iNbMaxValu
QString price;
QString date;
QString dateFormat;
QString apiKey;
QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "skrooge/quotes/" % source % ".txt");
if (fileName.isEmpty()) {
const auto list2 = KServiceTypeTrader::self()->query(QStringLiteral("skrooge/source"));
......@@ -2355,6 +2356,9 @@ SKGError SKGUnitObject::downloadUnitValue(UnitDownloadMode iMode, int iNbMaxValu
price = service->property(QStringLiteral("X-SKROOGE-price"), QVariant::String).toString().replace(QStringLiteral("%1"), code);
date = service->property(QStringLiteral("X-SKROOGE-date"), QVariant::String).toString().replace(QStringLiteral("%1"), code);
dateFormat = service->property(QStringLiteral("X-SKROOGE-dateformat"), QVariant::String).toString();
if (service->property(QStringLiteral("X-SKROOGE-keyAPI"), QVariant::Bool).toBool()) {
apiKey = getDocument()->getParameter("KEYAPI_" + source);
}
break;
}
}
......@@ -2385,7 +2389,7 @@ SKGError SKGUnitObject::downloadUnitValue(UnitDownloadMode iMode, int iNbMaxValu
path = path.replace(QStringLiteral("%2"), QDate::currentDate().toString(QStringLiteral("yyyy-MM-dd")));
path = path.replace(QStringLiteral("%3"), firstDate.toString(QStringLiteral("yyyy-MM-dd")));
path = path.replace(QStringLiteral("%4"), interval);
path = path.replace(QStringLiteral("%5"), apiKey);
SKGTRACEL(1) << "path=[" << path << "]" << endl;
SKGTRACEL(1) << "mode=[" << mode << "]" << endl;
......
......@@ -31,7 +31,7 @@ import sys
units=sys.argv[1].split('-')
req = Request('https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+units[0]+'&convert='+units[1])
req.add_header("X-CMC_PRO_API_KEY", '-'.join(units[2:]))
req.add_header("X-CMC_PRO_API_KEY", sys.argv[5])
f = urlopen(req)
print("Date,Price")
item=json.loads(f.read().decode('utf-8'))['data'][units[0]]['quote'][units[1]]
......
......@@ -31,7 +31,7 @@ import time
units=sys.argv[1].split('-')
f = urllib.request.urlopen('https://min-api.cryptocompare.com/data/v2/histoday?fsym='+units[0]+'&tsym='+units[1]+'&limit=1000&api_key='+units[2])
f = urllib.request.urlopen('https://min-api.cryptocompare.com/data/v2/histoday?fsym='+units[0]+'&tsym='+units[1]+'&limit=1000&api_key='+sys.argv[5])
print("Date,Price")
for item in json.loads(f.read().decode('utf-8'))['Data']['Data']:
print(time.strftime('%Y-%m-%d', time.gmtime(int(item["time"])))+','+str(item['close']))
......@@ -15,7 +15,7 @@ Name[pt_BR]=CoinMarketCap
Name[sv]=CoinMarketCap
Name[uk]=CoinMarketCap
Name[x-test]=xxCoinMarketCapxx
Comment=You can get the list of available quotes from <a href="https://coinmarketcap.com">CoinMarketCap</a>.<br/><br/>Then, you must create an account to get an API key.<br/>Then, enter the <expected quote>-<in the expected currency>-<the api key>. Example: if you want BTC in USD, you must enter BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment=You can get the list of available quotes from <a href="https://coinmarketcap.com">CoinMarketCap</a>.<br/><br/>Then, you must create an account to get an API key and set it in setting.<br/>Then, enter the <expected quote>-<in the expected currency>. Example: if you want BTC in USD, you must enter BTC-USD.
Comment[ca]=Podeu obtenir la llista de les cotitzacions disponibles a <a href="https://coinmarketcap.com">CoinMarketCap</a>.<br/><br/>Després, cal crear un compte per aconseguir una clau d'API.<br/>Després, introduïu la <cotització esperada>-<en la divisa esperada>-<la clau d'API>. Exemple: si voleu BTC en USD, cal introduir BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment[ca@valencia]=Podeu obtindre la llista de les cotitzacions disponibles a <a href="https://coinmarketcap.com">CoinMarketCap</a>.<br/><br/>Després, cal crear un compte per aconseguir una clau d'API.<br/>Després, introduïu la <cotització esperada>-<en la divisa esperada>-<la clau d'API>. Exemple: si voleu BTC en USD, cal introduir BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment[en_GB]=You can get the list of available quotes from <a href="https://coinmarketcap.com">CoinMarketCap</a>.<br/><br/>Then, you must create an account to get an API key.<br/>Then, enter the <expected quote>-<in the expected currency>-<the api key>. Example: if you want BTC in USD, you must enter BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
......@@ -41,16 +41,21 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=true
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
# X-SKROOGE-script=mydownloadscript %1
#This parameter is MANDATORY
X-SKROOGE-script=skrooge-coinmarketcap.py %1
X-SKROOGE-script=skrooge-coinmarketcap.py "%1" "%2" "%3" "%4" "%5"
#The mode (HTML or CSV or CSVR). In HTML mode, only one value will be extracted from downloaded page. In CSV mode, a value per line will be extracted. CSVR means CSV in reverse mode
X-SKROOGE-mode=CSV
......
......@@ -10,7 +10,7 @@ Name[pt]=Cryptocompare
Name[sv]=Cryptocompare
Name[uk]=Cryptocompare
Name[x-test]=xxCryptocomparexx
Comment=You can get the list of available quotes from <a href="https://www.cryptocompare.com/">CryptoCompare</a>.<br/>Then, you must create an account to get an API key.<br/>Then, enter the <expected quote>-<in the expected currency>-<the api key>. Example: if you want BTC in USD, you must enter BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment=You can get the list of available quotes from <a href="https://www.cryptocompare.com/">CryptoCompare</a>.<br/>Then, you must create an account to get an API key and set it in setting.<br/>Then, enter the <expected quote>-<in the expected currency>. Example: if you want BTC in USD, you must enter BTC-USD.
Comment[ca]=Podeu obtenir la llista de les cotitzacions disponibles a <a href="https://www.cryptocompare.com/">CryptoCompare</a>.<br/>Després, cal crear un compte per aconseguir una clau d'API.<br/>Després, introduïu la <cotització esperada>-<en la divisa esperada>-<la clau d'API>. Exemple: si voleu BTC en USD, cal introduir BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment[ca@valencia]=Podeu obtindre la llista de les cotitzacions disponibles a <a href="https://www.cryptocompare.com/">CryptoCompare</a>.<br/>Després, cal crear un compte per aconseguir una clau d'API.<br/>Després, introduïu la <cotització esperada>-<en la divisa esperada>-<la clau d'API>. Exemple: si voleu BTC en USD, cal introduir BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
Comment[en_GB]=You can get the list of available quotes from <a href="https://www.cryptocompare.com/">CryptoCompare</a>.<br/>Then, you must create an account to get an API key.<br/>Then, enter the <expected quote>-<in the expected currency>-<the api key>. Example: if you want BTC in USD, you must enter BTC-USD-3b415edbc7d42bd9e367dc43b415edbc7d42bd9e367dc3b415edbc7d42bd9e36.
......@@ -36,16 +36,21 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=true
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
# X-SKROOGE-script=mydownloadscript %1
#This parameter is MANDATORY
X-SKROOGE-script=skrooge-cryptocompare.py %1
X-SKROOGE-script=skrooge-cryptocompare.py "%1" "%2" "%3" "%4" "%5"
#The mode (HTML or CSV or CSVR). In HTML mode, only one value will be extracted from downloaded page. In CSV mode, a value per line will be extracted. CSVR means CSV in reverse mode
X-SKROOGE-mode=CSVR
......
......@@ -44,10 +44,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
......@@ -47,10 +47,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
......@@ -46,10 +46,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
......@@ -60,10 +60,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
......@@ -46,10 +46,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
......@@ -49,10 +49,15 @@ X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=false
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment