Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/settings/ksettingsonlinequotes.cpp
Show All 16 Lines | |||||
17 | 17 | | |||
18 | #include "ksettingsonlinequotes.h" | 18 | #include "ksettingsonlinequotes.h" | ||
19 | 19 | | |||
20 | // ---------------------------------------------------------------------------- | 20 | // ---------------------------------------------------------------------------- | ||
21 | // QT Includes | 21 | // QT Includes | ||
22 | 22 | | |||
23 | #include <QRegExp> | 23 | #include <QRegExp> | ||
24 | #include <QCheckBox> | 24 | #include <QCheckBox> | ||
25 | #include <QDesktopServices> | ||||
25 | 26 | | |||
26 | // ---------------------------------------------------------------------------- | 27 | // ---------------------------------------------------------------------------- | ||
27 | // KDE Includes | 28 | // KDE Includes | ||
28 | 29 | | |||
29 | #include <kconfig.h> | 30 | #include <kconfig.h> | ||
30 | #include <kglobal.h> | 31 | #include <kglobal.h> | ||
31 | #include <klocale.h> | 32 | #include <klocale.h> | ||
32 | #include <kiconloader.h> | 33 | #include <kiconloader.h> | ||
33 | #include <kguiitem.h> | 34 | #include <kguiitem.h> | ||
35 | #include <KMessageBox> | ||||
34 | 36 | | |||
35 | // ---------------------------------------------------------------------------- | 37 | // ---------------------------------------------------------------------------- | ||
36 | // Project Includes | 38 | // Project Includes | ||
37 | 39 | | |||
38 | #include "kmymoney/converter/webpricequote.h" | 40 | #include "kmymoney/converter/webpricequote.h" | ||
39 | 41 | | |||
40 | KSettingsOnlineQuotes::KSettingsOnlineQuotes(QWidget *parent) | 42 | KSettingsOnlineQuotes::KSettingsOnlineQuotes(QWidget *parent) | ||
41 | : KSettingsOnlineQuotesDecl(parent), | 43 | : KSettingsOnlineQuotesDecl(parent), | ||
42 | m_quoteInEditing(false) | 44 | m_quoteInEditing(false) | ||
43 | { | 45 | { | ||
44 | QStringList groups = WebPriceQuote::quoteSources(); | 46 | QStringList groups = WebPriceQuote::quoteSources(); | ||
45 | 47 | | |||
46 | loadList(true /*updateResetList*/); | 48 | loadList(true /*updateResetList*/); | ||
47 | 49 | | |||
48 | m_updateButton->setEnabled(false); | 50 | m_updateButton->setEnabled(false); | ||
49 | 51 | | |||
50 | KGuiItem updateButtenItem(i18nc("Accepts the entered data and stores it", "&Update"), | 52 | KGuiItem updateButtenItem(i18nc("Accepts the entered data and stores it", "&Accept"), | ||
51 | KIcon("dialog-ok"), | 53 | KIcon("dialog-ok"), | ||
52 | i18n("Accepts the entered data and stores it"), | 54 | i18n("Accepts the entered data and stores it"), | ||
53 | i18n("Use this to accept the modified data.")); | 55 | i18n("Use this to accept the modified data.")); | ||
54 | m_updateButton->setGuiItem(updateButtenItem); | 56 | m_updateButton->setGuiItem(updateButtenItem); | ||
55 | 57 | | |||
56 | KGuiItem deleteButtenItem(i18n("&Delete"), | 58 | KGuiItem deleteButtenItem(i18n("&Delete"), | ||
57 | KIcon("edit-delete"), | 59 | KIcon("edit-delete"), | ||
58 | i18n("Delete the selected source entry"), | 60 | i18n("Delete the selected source entry"), | ||
59 | i18n("Use this to delete the selected online source entry")); | 61 | i18n("Use this to delete the selected online source entry")); | ||
60 | m_deleteButton->setGuiItem(deleteButtenItem); | 62 | m_deleteButton->setGuiItem(deleteButtenItem); | ||
61 | 63 | | |||
64 | KGuiItem checkButtonItem(i18nc("Check the selected source entry", "&Check Source"), | ||||
65 | KIcon("document-edit-verify"), | ||||
66 | i18n("Check the selected source entry"), | ||||
67 | i18n("Use this to check the selected online source entry")); | ||||
68 | m_checkButton->setGuiItem(checkButtonItem); | ||||
69 | | ||||
70 | KGuiItem showButtonItem(i18nc("Show the selected source entry in a web browser", "&Show page"), | ||||
71 | KIcon("applications-internet"), | ||||
72 | i18n("Show the selected source entry in a web browser"), | ||||
73 | i18n("Use this to show the selected online source entry")); | ||||
74 | m_showButton->setGuiItem(showButtonItem); | ||||
75 | | ||||
62 | KGuiItem newButtenItem(i18nc("Create a new source entry for online quotes", "&New..."), | 76 | KGuiItem newButtenItem(i18nc("Create a new source entry for online quotes", "&New..."), | ||
63 | KIcon("document-new"), | 77 | KIcon("document-new"), | ||
64 | i18n("Create a new source entry for online quotes"), | 78 | i18n("Create a new source entry for online quotes"), | ||
65 | i18n("Use this to create a new entry for online quotes")); | 79 | i18n("Use this to create a new entry for online quotes")); | ||
66 | m_newButton->setGuiItem(newButtenItem); | 80 | m_newButton->setGuiItem(newButtenItem); | ||
67 | 81 | | |||
68 | connect(m_updateButton, SIGNAL(clicked()), this, SLOT(slotUpdateEntry())); | 82 | connect(m_updateButton, SIGNAL(clicked()), this, SLOT(slotUpdateEntry())); | ||
69 | connect(m_newButton, SIGNAL(clicked()), this, SLOT(slotNewEntry())); | 83 | connect(m_newButton, SIGNAL(clicked()), this, SLOT(slotNewEntry())); | ||
84 | connect(m_checkButton, SIGNAL(clicked()), this, SLOT(slotCheckEntry())); | ||||
85 | connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteEntry())); | ||||
86 | connect(m_showButton, SIGNAL(clicked()), this, SLOT(slotShowEntry())); | ||||
70 | 87 | | |||
71 | connect(m_quoteSourceList, SIGNAL(itemSelectionChanged()), this, SLOT(slotLoadWidgets())); | 88 | connect(m_quoteSourceList, SIGNAL(itemSelectionChanged()), this, SLOT(slotLoadWidgets())); | ||
72 | connect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotEntryRenamed(QListWidgetItem*))); | 89 | connect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotEntryRenamed(QListWidgetItem*))); | ||
73 | connect(m_quoteSourceList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotStartRename(QListWidgetItem*))); | 90 | connect(m_quoteSourceList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotStartRename(QListWidgetItem*))); | ||
74 | 91 | | |||
75 | connect(m_editURL, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | 92 | connect(m_editURL, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | ||
76 | connect(m_editSymbol, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | 93 | connect(m_editSymbol, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | ||
77 | connect(m_editDate, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | 94 | connect(m_editDate, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | ||
78 | connect(m_editDateFormat, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | 95 | connect(m_editDateFormat, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | ||
79 | connect(m_editPrice, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | 96 | connect(m_editPrice, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); | ||
80 | connect(m_skipStripping, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); | 97 | connect(m_skipStripping, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); | ||
81 | 98 | | |||
82 | // FIXME deleting a source is not yet implemented | 99 | m_logWindow->setVisible(false); | ||
83 | m_deleteButton->setEnabled(false); | | |||
84 | } | 100 | } | ||
85 | 101 | | |||
86 | void KSettingsOnlineQuotes::loadList(const bool updateResetList) | 102 | void KSettingsOnlineQuotes::loadList(const bool updateResetList) | ||
87 | { | 103 | { | ||
88 | //disconnect the slot while items are being loaded and reconnect at the end | 104 | //disconnect the slot while items are being loaded and reconnect at the end | ||
89 | disconnect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotEntryRenamed(QListWidgetItem*))); | 105 | disconnect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotEntryRenamed(QListWidgetItem*))); | ||
90 | m_quoteInEditing = false; | 106 | m_quoteInEditing = false; | ||
91 | QStringList groups = WebPriceQuote::quoteSources(); | 107 | QStringList groups = WebPriceQuote::quoteSources(); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 151 | { | |||
166 | } | 182 | } | ||
167 | 183 | | |||
168 | m_updateButton->setEnabled(false); | 184 | m_updateButton->setEnabled(false); | ||
169 | 185 | | |||
170 | } | 186 | } | ||
171 | 187 | | |||
172 | void KSettingsOnlineQuotes::slotEntryChanged() | 188 | void KSettingsOnlineQuotes::slotEntryChanged() | ||
173 | { | 189 | { | ||
190 | clearIcons(); | ||||
174 | bool modified = m_editURL->text() != m_currentItem.m_url | 191 | bool modified = m_editURL->text() != m_currentItem.m_url | ||
175 | || m_editSymbol->text() != m_currentItem.m_sym | 192 | || m_editSymbol->text() != m_currentItem.m_sym | ||
176 | || m_editDate->text() != m_currentItem.m_date | 193 | || m_editDate->text() != m_currentItem.m_date | ||
177 | || m_editDateFormat->text() != m_currentItem.m_dateformat | 194 | || m_editDateFormat->text() != m_currentItem.m_dateformat | ||
178 | || m_editPrice->text() != m_currentItem.m_price | 195 | || m_editPrice->text() != m_currentItem.m_price | ||
179 | || m_skipStripping->isChecked() != m_currentItem.m_skipStripping; | 196 | || m_skipStripping->isChecked() != m_currentItem.m_skipStripping; | ||
180 | 197 | | |||
181 | m_updateButton->setEnabled(modified); | 198 | m_updateButton->setEnabled(modified); | ||
199 | m_checkButton->setEnabled(!modified); | ||||
200 | } | ||||
201 | | ||||
202 | void KSettingsOnlineQuotes::slotDeleteEntry() | ||||
203 | { | ||||
204 | QListWidgetItem* item = m_quoteSourceList->findItems(m_currentItem.m_name, Qt::MatchExactly).at(0); | ||||
205 | if (!item) | ||||
206 | return; | ||||
207 | | ||||
208 | int ret = KMessageBox::warningContinueCancel(this, | ||||
209 | i18n("Are you sure to delete this online quote ?"), | ||||
210 | i18n("Delete online quote"), | ||||
211 | KStandardGuiItem::cont(), | ||||
212 | KStandardGuiItem::cancel(), | ||||
213 | QString("DeletingOnlineQuote")); | ||||
214 | if (ret == KMessageBox::Cancel) | ||||
215 | return; | ||||
216 | | ||||
217 | delete item; | ||||
218 | m_currentItem.remove(); | ||||
219 | slotEntryChanged(); | ||||
220 | } | ||||
221 | | ||||
222 | void KSettingsOnlineQuotes::slotShowEntry() | ||||
223 | { | ||||
224 | if (m_currentItem.m_url.contains("%2")) | ||||
225 | QDesktopServices::openUrl(m_currentItem.m_url.arg("BTC","GBP")); | ||||
226 | else | ||||
227 | QDesktopServices::openUrl(m_currentItem.m_url.arg("GBP")); | ||||
182 | } | 228 | } | ||
183 | 229 | | |||
184 | void KSettingsOnlineQuotes::slotUpdateEntry() | 230 | void KSettingsOnlineQuotes::slotUpdateEntry() | ||
185 | { | 231 | { | ||
186 | m_currentItem.m_url = m_editURL->text(); | 232 | m_currentItem.m_url = m_editURL->text(); | ||
187 | m_currentItem.m_sym = m_editSymbol->text(); | 233 | m_currentItem.m_sym = m_editSymbol->text(); | ||
188 | m_currentItem.m_date = m_editDate->text(); | 234 | m_currentItem.m_date = m_editDate->text(); | ||
189 | m_currentItem.m_dateformat = m_editDateFormat->text(); | 235 | m_currentItem.m_dateformat = m_editDateFormat->text(); | ||
190 | m_currentItem.m_price = m_editPrice->text(); | 236 | m_currentItem.m_price = m_editPrice->text(); | ||
191 | m_currentItem.m_skipStripping = m_skipStripping->isChecked(); | 237 | m_currentItem.m_skipStripping = m_skipStripping->isChecked(); | ||
192 | m_currentItem.write(); | 238 | m_currentItem.write(); | ||
239 | m_checkButton->setEnabled(true); | ||||
193 | slotEntryChanged(); | 240 | slotEntryChanged(); | ||
194 | } | 241 | } | ||
195 | 242 | | |||
196 | void KSettingsOnlineQuotes::slotNewEntry() | 243 | void KSettingsOnlineQuotes::slotNewEntry() | ||
197 | { | 244 | { | ||
198 | WebPriceQuoteSource newSource(i18n("New Quote Source")); | 245 | WebPriceQuoteSource newSource(i18n("New Quote Source")); | ||
199 | newSource.write(); | 246 | newSource.write(); | ||
200 | loadList(); | 247 | loadList(); | ||
201 | QListWidgetItem* item = m_quoteSourceList->findItems(i18n("New Quote Source"), Qt::MatchExactly).at(0); | 248 | QListWidgetItem* item = m_quoteSourceList->findItems(i18n("New Quote Source"), Qt::MatchExactly).at(0); | ||
202 | if (item) { | 249 | if (item) { | ||
203 | m_quoteSourceList->setCurrentItem(item); | 250 | m_quoteSourceList->setCurrentItem(item); | ||
204 | slotLoadWidgets(); | 251 | slotLoadWidgets(); | ||
205 | } | 252 | } | ||
206 | } | 253 | } | ||
207 | 254 | | |||
255 | void KSettingsOnlineQuotes::clearIcons() | ||||
256 | { | ||||
257 | QPixmap emptyIcon; | ||||
258 | m_urlCheckLabel->setPixmap(emptyIcon); | ||||
259 | m_dateCheckLabel->setPixmap(emptyIcon); | ||||
260 | m_priceCheckLabel->setPixmap(emptyIcon); | ||||
261 | m_symbolCheckLabel->setPixmap(emptyIcon); | ||||
tbaumgart: Can we have named constants (enums) for the states please? | |||||
sure or I can use two methos clearIcons() and setupIcons(Errors errors) habacker: sure or I can use two methos clearIcons() and setupIcons(Errors errors) | |||||
262 | m_dateFormatCheckLabel->setPixmap(emptyIcon); | ||||
263 | } | ||||
264 | | ||||
265 | void KSettingsOnlineQuotes::setupIcons(const WebPriceQuote::Errors &errors) | ||||
266 | { | ||||
267 | QPixmap okIcon(BarIcon("dialog-ok-apply")); | ||||
268 | QPixmap failIcon(BarIcon("dialog-cancel")); | ||||
269 | | ||||
270 | if (errors & WebPriceQuote::Errors::URL) | ||||
271 | m_urlCheckLabel->setPixmap(failIcon); | ||||
272 | else { | ||||
273 | m_urlCheckLabel->setPixmap(okIcon); | ||||
274 | m_symbolCheckLabel->setPixmap(errors & WebPriceQuote::Errors::Symbol ? failIcon : okIcon); | ||||
275 | m_priceCheckLabel->setPixmap(errors & WebPriceQuote::Errors::Price ? failIcon : okIcon); | ||||
276 | if (errors & WebPriceQuote::Errors::Date) | ||||
277 | m_dateCheckLabel->setPixmap(failIcon); | ||||
278 | else { | ||||
279 | m_dateCheckLabel->setPixmap(okIcon); | ||||
280 | m_dateFormatCheckLabel->setPixmap(errors & WebPriceQuote::Errors::DateFormat? failIcon : okIcon); | ||||
281 | } | ||||
282 | } | ||||
283 | } | ||||
284 | | ||||
285 | void KSettingsOnlineQuotes::slotCheckEntry() | ||||
286 | { | ||||
287 | WebPriceQuote quote; | ||||
288 | m_logWindow->setVisible(true); | ||||
289 | m_logWindow->clear(); | ||||
290 | clearIcons(); | ||||
291 | | ||||
292 | connect("e, SIGNAL(status(const QString&)), this, SLOT(slotLogStatus(const QString&))); | ||||
293 | connect("e, SIGNAL(error(const QString&)), this, SLOT(slotLogStatus(const QString&))); | ||||
294 | connect("e, SIGNAL(failed(const QString&)), this, SLOT(slotLogStatus(const QString&))); | ||||
295 | connect("e, SIGNAL(quote(const QString&, const QString&, const QString&, double)), this, SLOT(slotLogQuote(const QString&, const QString&, const QString&, double))); | ||||
296 | if (m_currentItem.m_url.contains("%2")) | ||||
297 | quote.launch("BTC > GBP", "BTC GBP", m_currentItem.m_name); | ||||
298 | else | ||||
299 | quote.launch("GBP", "GBP", m_currentItem.m_name); | ||||
If a URL contains'%2', I can trust that this is a query for a currency and otherwise a query for a security or similar? If that is the case, I cannot use "GBP" for the second case, but must use something else - Do you have a suggestion? habacker: If a URL contains'%2', I can trust that this is a query for a currency and otherwise a query… | |||||
300 | setupIcons(quote.errors()); | ||||
301 | } | ||||
302 | | ||||
303 | void KSettingsOnlineQuotes::slotLogStatus(const QString &s) | ||||
304 | { | ||||
305 | new QListWidgetItem(s, m_logWindow); | ||||
306 | m_logWindow->scrollToBottom(); | ||||
307 | } | ||||
308 | | ||||
309 | void KSettingsOnlineQuotes::slotLogQuote(const QString &id, const QString &symbol, const QString &date, double price) | ||||
310 | { | ||||
311 | slotLogStatus(QString("%1 %2 %3 %4").arg(id, symbol, date).arg(price)); | ||||
I would write this function as: void KSettingsOnlineQuotes::slotLogQuote(const QString &id, const QString &symbol, const QString &date, double price) { slotLogStatus(QString("%1 %2 %3 %4").arg(id, symbol, date).arg(price)); } It avoid code duplication. The optimizer should take care of the alleged overhead here very well. tbaumgart: I would write this function as:
```
void KSettingsOnlineQuotes::slotLogQuote(const QString &id… | |||||
habacker: will change the implementation | |||||
312 | } | ||||
313 | | ||||
208 | void KSettingsOnlineQuotes::slotStartRename(QListWidgetItem* item) | 314 | void KSettingsOnlineQuotes::slotStartRename(QListWidgetItem* item) | ||
209 | { | 315 | { | ||
210 | m_quoteInEditing = true; | 316 | m_quoteInEditing = true; | ||
211 | m_quoteSourceList->editItem(item); | 317 | m_quoteSourceList->editItem(item); | ||
212 | } | 318 | } | ||
213 | 319 | | |||
214 | void KSettingsOnlineQuotes::slotEntryRenamed(QListWidgetItem* item) | 320 | void KSettingsOnlineQuotes::slotEntryRenamed(QListWidgetItem* item) | ||
215 | { | 321 | { | ||
Show All 21 Lines |
Can we have named constants (enums) for the states please?