30 #include <QDesktopServices>
32 #include <QWebInspector>
34 #include <KComponentData>
36 #include <KIconLoader>
38 #include <KMessageBox>
39 #include <knewstuff3/downloaddialog.h>
40 #include <knewstuff3/uploaddialog.h>
42 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
44 static KLocale _locale(
"alkimia");
45 #define i18nc(context, text) ki18nc(context, text).toString(&_locale)
46 #define i18n(text) ki18n(text).toString(&_locale)
47 #define tr2i18n(text, context) ki18nc(context, text).toString(&_locale)
50 #include <ui_alkonlinequoteswidget.h>
70 Private(
bool showProfiles,
bool showUpload, QWidget *parent);
88 void slotLogQuote(
const QString &
id,
const QString &symbol,
const QDate &date,
double price);
108 , m_quoteInEditing(false)
110 , m_showProfiles(showProfiles)
111 , m_showUpload(showUpload)
112 , m_inWorkIcon(BarIcon(
"view-refresh"))
113 , m_okIcon(BarIcon(
"dialog-ok-apply"))
114 , m_failIcon(BarIcon(
"dialog-cancel"))
115 , m_webPageDialog(nullptr)
119 profilesGroupBox->setVisible(showProfiles);
120 profileDetailsBox->setVisible(showProfiles);
122 m_ghnsSource->setEnabled(showProfiles);
123 m_uploadButton->setVisible(showUpload);
124 m_urlCheckLabel->setMinimumWidth(
m_okIcon.width());
129 KGuiItem updateButtenItem(i18nc(
"Accepts the entered data and stores it",
"&Accept"),
131 i18n(
"Accepts the entered data and stores it"),
132 i18n(
"Use this to accept the modified data."));
133 m_updateButton->setGuiItem(updateButtenItem);
135 KGuiItem deleteButtenItem(i18n(
"&Delete"),
136 KIcon(
"edit-delete"),
137 i18n(
"Delete the selected source entry"),
138 i18n(
"Use this to delete the selected online source entry"));
139 m_deleteButton->setGuiItem(deleteButtenItem);
141 KGuiItem checkButtonItem(i18nc(
"Check the selected source entry",
"&Check Source"),
142 KIcon(
"document-edit-verify"),
143 i18n(
"Check the selected source entry"),
144 i18n(
"Use this to check the selected online source entry"));
145 m_checkButton->setGuiItem(checkButtonItem);
147 KGuiItem showButtonItem(i18nc(
"Show the selected source entry in a web browser",
"&Show page"),
148 KIcon(
"applications-internet"),
149 i18n(
"Show the selected source entry in a web browser"),
150 i18n(
"Use this to show the selected online source entry"));
151 m_showButton->setGuiItem(showButtonItem);
153 KGuiItem newButtenItem(i18nc(
"Create a new source entry for online quotes",
"&New..."),
154 KIcon(
"document-new"),
155 i18n(
"Create a new source entry for online quotes"),
156 i18n(
"Use this to create a new entry for online quotes"));
157 m_newButton->setGuiItem(newButtenItem);
159 connect(m_newProfile, SIGNAL(clicked()),
this, SLOT(
slotNewProfile()));
161 connect(m_profileList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotLoadProfile()));
163 connect(m_updateButton, SIGNAL(clicked()),
this, SLOT(
slotUpdateEntry()));
164 connect(m_newButton, SIGNAL(clicked()),
this, SLOT(
slotNewEntry()));
165 connect(m_checkButton, SIGNAL(clicked()),
this, SLOT(
slotCheckEntry()));
166 connect(m_deleteButton, SIGNAL(clicked()),
this, SLOT(
slotDeleteEntry()));
169 connect(m_uploadButton, SIGNAL(clicked()),
this, SLOT(
slotUploadEntry()));
171 connect(m_quoteSourceList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotLoadWidgets()));
172 connect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem *)),
this,
174 connect(m_quoteSourceList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this,
177 connect(m_editURL, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
178 connect(m_editSymbol, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
179 connect(m_editDate, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
180 connect(m_editDateFormat, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
181 connect(m_editPrice, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
182 connect(m_skipStripping, SIGNAL(toggled(
bool)),
this, SLOT(
slotEntryChanged()));
183 connect(m_ghnsSource, SIGNAL(toggled(
bool)),
this, SLOT(
slotEntryChanged()));
184 connect(m_showButton, SIGNAL(clicked()),
this, SLOT(
slotShowButton()));
186 m_checkSymbol->setText(
"ORCL");
187 m_checkSymbol2->setText(
"BTC GBP");
188 m_updateButton->setEnabled(
false);
194 m_webPageDialog->deleteLater();
203 QListWidgetItem *item =
new QListWidgetItem(
dynamic_cast<QListWidget *
>(m_profileList));
204 item->setText(profile->
name());
205 item->setFlags(item->flags() | Qt::ItemIsEditable);
207 m_profileList->setCurrentRow(0);
214 m_quoteInEditing =
false;
215 QStringList groups = m_profile->quoteSources();
217 if (updateResetList) {
220 m_quoteSourceList->blockSignals(
true);
221 m_quoteSourceList->clear();
222 QStringList::Iterator it;
223 for (it = groups.begin(); it != groups.end(); ++it) {
229 QListWidgetItem *item =
new QListWidgetItem(*it);
230 item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
231 m_quoteSourceList->addItem(item);
232 if (updateResetList) {
233 m_resetList += source;
236 m_quoteSourceList->sortItems();
238 QListWidgetItem *item =
nullptr;
239 if (!m_currentItem.name().isEmpty()) {
240 QList<QListWidgetItem*> items = m_quoteSourceList->findItems(m_currentItem.name(), Qt::MatchExactly);
241 if (items.size() > 0)
244 m_quoteSourceList->setCurrentItem(item);
247 item = m_quoteSourceList->item(0);
249 m_quoteSourceList->setCurrentItem(item);
251 m_quoteSourceList->blockSignals(
false);
258 QListWidgetItem *item =
new QListWidgetItem(
dynamic_cast<QListWidget *
>(m_profileList));
259 item->setText(QLatin1String(
"new profile"));
260 item->setFlags(item->flags() | Qt::ItemIsEditable);
265 delete m_profileList->currentItem();
276 if (!m_showProfiles) {
280 m_profile = list.first();
286 if (m_profileList->currentItem()->text() == profile->
name()) {
294 m_configFilePath->setText(m_profile->kConfigFile());
295 m_configFilePath->setVisible(visible);
296 m_configLabel->setEnabled(visible);
298 visible = m_profile->hasGHNSSupport();
299 m_GHNSConfigFilePath->setText(m_profile->hotNewStuffConfigFile());
300 m_GHNSConfigFilePath->setVisible(visible);
301 m_GHNSConfigLabel->setEnabled(visible);
303 m_GHNSDataPath->setText(m_profile->hotNewStuffReadPath().join(
" "));
304 m_GHNSDataPath->setVisible(visible);
305 m_GHNSDataLabel->setEnabled(visible);
310 m_quoteInEditing =
false;
311 QListWidgetItem *item = m_quoteSourceList->currentItem();
313 m_editURL->setEnabled(item !=
nullptr);
314 m_editSymbol->setEnabled(item !=
nullptr);
315 m_editPrice->setEnabled(item !=
nullptr);
316 m_editDate->setEnabled(item !=
nullptr);
317 m_editDateFormat->setEnabled(item !=
nullptr);
318 m_skipStripping->setEnabled(item !=
nullptr);
321 m_editSymbol->clear();
322 m_editPrice->clear();
324 m_editDateFormat->clear();
328 m_editURL->setText(m_currentItem.url());
329 m_editSymbol->setText(m_currentItem.sym());
330 m_editPrice->setText(m_currentItem.price());
331 m_editDate->setText(m_currentItem.date());
332 m_editDateFormat->setText(m_currentItem.dateformat());
333 m_skipStripping->setChecked(m_currentItem.skipStripping());
334 m_ghnsSource->setChecked(m_currentItem.isGHNS());
337 m_updateButton->setEnabled(
false);
343 bool modified = m_editURL->text() != m_currentItem.url()
344 || m_editSymbol->text() != m_currentItem.sym()
345 || m_editDate->text() != m_currentItem.date()
346 || m_editDateFormat->text() != m_currentItem.dateformat()
347 || m_editPrice->text() != m_currentItem.price()
348 || m_skipStripping->isChecked() != m_currentItem.skipStripping()
349 || m_ghnsSource->isChecked() != m_currentItem.isGHNS();
352 bool noNewEntry = m_quoteSourceList->findItems(i18n(
"New Quote Source"), Qt::MatchExactly).count() == 0;
353 m_newButton->setEnabled(hasWriteSupport && noNewEntry);
354 m_duplicateButton->setEnabled(hasWriteSupport);
355 m_deleteButton->setEnabled(!m_currentItem.isReadOnly() && !m_currentItem.isGHNS());
356 m_uploadButton->setEnabled(m_profile->hasGHNSSupport() && m_currentItem.isGHNS());
357 m_updateButton->setEnabled(modified);
358 m_checkButton->setEnabled(!modified);
359 m_checkSymbol->setEnabled(!m_currentItem.url().contains(
"%2"));
360 m_checkSymbol2->setEnabled(m_currentItem.url().contains(
"%2"));
365 QList<QListWidgetItem *> items = m_quoteSourceList->findItems(
366 m_currentItem.name(), Qt::MatchExactly);
367 if (items.isEmpty()) {
370 QListWidgetItem *item = items.at(0);
375 int ret = KMessageBox::warningContinueCancel(
this,
376 i18n(
"Are you sure to delete this online quote ?"),
377 i18n(
"Delete online quote"),
378 KStandardGuiItem::cont(),
379 KStandardGuiItem::cancel(),
380 QString(
"DeletingOnlineQuote"));
381 if (ret == KMessageBox::Cancel) {
386 m_currentItem.remove();
393 QList<QListWidgetItem *> items = m_quoteSourceList->findItems(
394 m_currentItem.name(), Qt::MatchExactly);
395 if (items.isEmpty()) {
398 QListWidgetItem *item = items.at(0);
407 m_currentItem = copy;
413 m_currentItem.setUrl(m_editURL->text());
414 m_currentItem.setSym(m_editSymbol->text());
415 m_currentItem.setDate(m_editDate->text());
416 m_currentItem.setDateformat(m_editDateFormat->text());
417 m_currentItem.setPrice(m_editPrice->text());
418 m_currentItem.setSkipStripping(m_skipStripping->isChecked());
419 m_currentItem.setGHNS(m_ghnsSource->isChecked());
420 m_currentItem.write();
421 m_checkButton->setEnabled(
true);
429 m_currentItem = newSource;
435 m_urlCheckLabel->setPixmap(m_emptyIcon);
436 m_dateCheckLabel->setPixmap(m_emptyIcon);
437 m_priceCheckLabel->setPixmap(m_emptyIcon);
438 m_symbolCheckLabel->setPixmap(m_emptyIcon);
439 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
444 m_urlCheckLabel->setPixmap(m_inWorkIcon);
445 m_dateCheckLabel->setPixmap(m_inWorkIcon);
446 m_priceCheckLabel->setPixmap(m_inWorkIcon);
447 m_symbolCheckLabel->setPixmap(m_inWorkIcon);
448 m_dateFormatCheckLabel->setPixmap(m_inWorkIcon);
455 m_urlCheckLabel->setPixmap(m_failIcon);
457 m_urlCheckLabel->setPixmap(m_okIcon);
461 m_dateCheckLabel->setPixmap(m_failIcon);
463 m_dateCheckLabel->setPixmap(m_okIcon);
464 m_dateFormatCheckLabel->setPixmap(
473 m_logWindow->setVisible(
true);
474 m_logWindow->clear();
478 connect("e, SIGNAL(status(QString)),
this, SLOT(slotLogStatus(QString)));
479 connect("e, SIGNAL(error(QString)),
this, SLOT(slotLogError(QString)));
480 connect("e, SIGNAL(failed(QString,QString)),
this, SLOT(slotLogFailed(QString,QString)));
481 connect("e, SIGNAL(quote(QString,QString,QDate,
double)),
this,
482 SLOT(slotLogQuote(QString,QString,QDate,
double)));
484 if (m_currentItem.url().contains(
"%2")) {
485 quote.
launch(m_checkSymbol2->text(), m_checkSymbol2->text(), m_currentItem.name());
487 quote.
launch(m_checkSymbol->text(), m_checkSymbol->text(), m_currentItem.name());
489 setupIcons(quote.
errors());
494 m_logWindow->append(s);
499 slotLogStatus(QString(
"<font color=\"red\"><b>") + s + QString(
"</b></font>"));
504 slotLogStatus(QString(
"%1 %2").arg(
id, symbol));
508 const QDate &date,
double price)
510 slotLogStatus(QString(
"<font color=\"green\">%1 %2 %3 %4</font>").arg(
id, symbol,
511 date.toString()).arg(
517 m_quoteInEditing =
true;
518 m_quoteSourceList->editItem(item);
524 if (m_quoteInEditing ==
false || !m_quoteSourceList->currentItem()
525 || item != m_quoteSourceList->currentItem()) {
529 m_quoteInEditing =
false;
530 QString text = item->text();
532 for (
int i = 0; i < m_quoteSourceList->count(); ++i) {
533 if (m_quoteSourceList->item(i)->text() == text) {
539 if (text.length() > 0 && nameCount == 1) {
540 m_currentItem.rename(text);
542 item->setText(m_currentItem.name());
544 m_quoteSourceList->sortItems();
545 m_newButton->setEnabled(m_quoteSourceList->findItems(i18n(
547 Qt::MatchExactly).count() == 0);
552 QString configFile = m_profile->hotNewStuffConfigFile();
554 QPointer<KNS3::DownloadDialog> dialog =
new KNS3::DownloadDialog(configFile,
this);
562 QString configFile = m_profile->hotNewStuffConfigFile();
564 QUrl url = QUrl::fromLocalFile(m_currentItem.ghnsWriteFileName());
565 qDebug() <<
"uploading file" << url;
566 QPointer<KNS3::UploadDialog> dialog =
new KNS3::UploadDialog(configFile,
this);
567 dialog->setUploadName(m_currentItem.name());
568 dialog->setUploadFile(url);
575 if (!m_webPageDialog) {
576 m_webPageDialog =
new QDialog;
577 m_webPageDialog->setWindowTitle(i18n(
"Online Quote HTML Result Window"));
578 QVBoxLayout *layout =
new QVBoxLayout;
581 layout->addWidget(webPage);
582 m_webPageDialog->setLayout(layout);
584 m_webPageDialog->show();
589 if (m_currentItem.url().contains(
"%2")) {
590 return m_currentItem.url().arg(m_checkSymbol2->text());
592 return m_currentItem.url().arg(m_checkSymbol->text());
598 ,
d(new
Private(showProfiles, showUpload, this))
609 QFrame *frame =
new QFrame;
610 frame->setLayout(
d->profilesGroupBox->layout());
616 QFrame *frame =
new QFrame;
617 frame->setLayout(
d->profileDetailsBox->layout());
623 QFrame *frame =
new QFrame;
624 frame->setLayout(
d->onlineQuotesGroupBox->layout());
630 QFrame *frame =
new QFrame;
631 frame->setLayout(
d->detailsGroupBox->layout());
637 QFrame *frame =
new QFrame;
638 frame->setLayout(
d->debugGroupBox->layout());
652 QStringList::ConstIterator it;
656 for (it = groups.constBegin(); it != groups.constEnd(); ++it) {
661 QList<AlkOnlineQuoteSource>::iterator itr;
679 #include "alkonlinequoteswidget.moc"