File indexing completed on 2024-03-24 05:53:14
0001 /*************************************************************************** 0002 converter.cpp - d-bus service 0003 ------------------- 0004 begin : lun nov 13 11:22:05 CET 2006 0005 copyright : (C) 2006-2022 by Éric Bischoff 0006 email : bischoff@kde.org 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "converter.h" 0019 0020 #include <stdio.h> 0021 0022 #include <QDBusConnection> 0023 #include <QStringList> 0024 #include <QDebug> 0025 #include <KLocalizedString> 0026 0027 #include "table.h" 0028 0029 // Constructor 0030 CurrencyConverter::CurrencyConverter() 0031 : QObject(), 0032 serialNumber(0) 0033 { 0034 QDBusConnection::sessionBus().registerService("org.kde.curconvd"); 0035 QDBusConnection::sessionBus().registerObject("/CurrencyConverter", this, QDBusConnection::ExportScriptableSlots); 0036 0037 qDebug() << i18n("curconvd: waiting for D-Bus requests"); 0038 } 0039 0040 // Destructor 0041 CurrencyConverter::~CurrencyConverter() 0042 { 0043 QDBusConnection::sessionBus().unregisterObject("/CurrencyConverter"); 0044 QDBusConnection::sessionBus().unregisterService("org.kde.curconvd"); 0045 0046 qDebug() << i18n("curconvd: stopped waiting for D-Bus requests"); 0047 } 0048 0049 // List available data sources 0050 QStringList CurrencyConverter::DataSources() 0051 { 0052 QStringList dataSources; 0053 0054 qDebug() << "curconvd: /CurrencyConverter/DataSources()"; 0055 0056 dataSources << QString("(fixed)"); 0057 dataSources << QString("http://www.ecb.int"); 0058 // dataSources << QString("http://www.newyorkfed.org"); 0059 dataSources << QString("http://rss.timegenie.com"); 0060 0061 return dataSources; 0062 } 0063 0064 // List available rounding methods 0065 QStringList CurrencyConverter::RoundingMethods() 0066 { 0067 QStringList roundingMethods; 0068 0069 qDebug() << "curconvd: /CurrencyConverter/RoundingMethods()"; 0070 0071 roundingMethods << QString("none"); 0072 roundingMethods << QString("official rules"); 0073 roundingMethods << QString("smallest coin"); 0074 0075 return roundingMethods; 0076 } 0077 0078 // Gives the reference currency for a data source 0079 QString CurrencyConverter::ReferenceCurrency(const QString &dataSource) 0080 { 0081 QString reference; 0082 0083 qDebug() << QStringLiteral("curconvd: /CurrencyConverter/ReferenceCurrency(\"%1\")").arg(dataSource); 0084 0085 if (dataSource == "(fixed)") 0086 reference = "EUR"; 0087 else if (dataSource == "http://www.ecb.int") 0088 reference = "EUR"; 0089 // else if (dataSource == "http://www.newyorkfed.org") 0090 // reference = "USD"; 0091 else if (dataSource == "http://rss.timegenie.com") 0092 reference = "EUR"; 0093 else reference = ""; 0094 0095 return reference; 0096 } 0097 0098 // Load currencies from data source 0099 QString CurrencyConverter::LoadSource(const QString &dataSource, const QString &roundingMethod) 0100 { 0101 QString tablePath; 0102 CurrencyTable *table; 0103 0104 qDebug() << QStringLiteral("curconvd: /CurrencyConverter/LoadSource(\"%1\", \"%2\")").arg(dataSource).arg(roundingMethod); 0105 0106 tablePath = QString( "/CurrencyConverter/tables/%1" ).arg( ++serialNumber ); 0107 0108 table = new CurrencyTable(tablePath); 0109 table->loadSource(dataSource, roundingMethod); 0110 0111 return tablePath; 0112 } 0113 0114 #include "moc_converter.cpp"