30 #include <QDesktopServices>
33 #include <KComponentData>
35 #include <KIconLoader>
37 #include <KMessageBox>
38 #include <knewstuff3/downloaddialog.h>
39 #include <knewstuff3/uploaddialog.h>
41 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
43 static KLocale _locale(
"alkimia");
44 #define i18nc(context, text) ki18nc(context, text).toString(&_locale)
45 #define i18n(text) ki18n(text).toString(&_locale)
46 #define tr2i18n(text, context) ki18nc(context, text).toString(&_locale)
49 #include <ui_alkonlinequoteswidget.h>
69 Private(
bool showProfiles,
bool showUpload, QWidget *parent);
87 void slotLogQuote(
const QString &
id,
const QString &symbol,
const QDate &date,
double price);
107 , m_quoteInEditing(false)
109 , m_showProfiles(showProfiles)
110 , m_showUpload(showUpload)
111 , m_inWorkIcon(BarIcon(
"view-refresh"))
112 , m_okIcon(BarIcon(
"dialog-ok-apply"))
113 , m_failIcon(BarIcon(
"dialog-cancel"))
114 , m_webPageDialog(nullptr)
118 profilesGroupBox->setVisible(showProfiles);
119 profileDetailsBox->setVisible(showProfiles);
121 m_ghnsSource->setEnabled(showProfiles);
122 m_uploadButton->setVisible(showUpload);
123 m_urlCheckLabel->setMinimumWidth(
m_okIcon.width());
128 KGuiItem updateButtenItem(i18nc(
"Accepts the entered data and stores it",
"&Accept"),
130 i18n(
"Accepts the entered data and stores it"),
131 i18n(
"Use this to accept the modified data."));
132 m_updateButton->setGuiItem(updateButtenItem);
134 KGuiItem deleteButtenItem(i18n(
"&Delete"),
135 KIcon(
"edit-delete"),
136 i18n(
"Delete the selected source entry"),
137 i18n(
"Use this to delete the selected online source entry"));
138 m_deleteButton->setGuiItem(deleteButtenItem);
140 KGuiItem checkButtonItem(i18nc(
"Check the selected source entry",
"&Check Source"),
141 KIcon(
"document-edit-verify"),
142 i18n(
"Check the selected source entry"),
143 i18n(
"Use this to check the selected online source entry"));
144 m_checkButton->setGuiItem(checkButtonItem);
146 KGuiItem showButtonItem(i18nc(
"Show the selected source entry in a web browser",
"&Show page"),
147 KIcon(
"applications-internet"),
148 i18n(
"Show the selected source entry in a web browser"),
149 i18n(
"Use this to show the selected online source entry"));
150 m_showButton->setGuiItem(showButtonItem);
152 KGuiItem newButtenItem(i18nc(
"Create a new source entry for online quotes",
"&New..."),
153 KIcon(
"document-new"),
154 i18n(
"Create a new source entry for online quotes"),
155 i18n(
"Use this to create a new entry for online quotes"));
156 m_newButton->setGuiItem(newButtenItem);
158 connect(m_newProfile, SIGNAL(clicked()),
this, SLOT(
slotNewProfile()));
160 connect(m_profileList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotLoadProfile()));
162 connect(m_updateButton, SIGNAL(clicked()),
this, SLOT(
slotUpdateEntry()));
163 connect(m_newButton, SIGNAL(clicked()),
this, SLOT(
slotNewEntry()));
164 connect(m_checkButton, SIGNAL(clicked()),
this, SLOT(
slotCheckEntry()));
165 connect(m_deleteButton, SIGNAL(clicked()),
this, SLOT(
slotDeleteEntry()));
168 connect(m_uploadButton, SIGNAL(clicked()),
this, SLOT(
slotUploadEntry()));
170 connect(m_quoteSourceList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotLoadWidgets()));
171 connect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem *)),
this,
173 connect(m_quoteSourceList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this,
176 connect(m_editURL, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
177 connect(m_editSymbol, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
178 connect(m_editDate, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
179 connect(m_editDateFormat, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
180 connect(m_editPrice, SIGNAL(textChanged(QString)),
this, SLOT(
slotEntryChanged()));
181 connect(m_skipStripping, SIGNAL(toggled(
bool)),
this, SLOT(
slotEntryChanged()));
182 connect(m_ghnsSource, SIGNAL(toggled(
bool)),
this, SLOT(
slotEntryChanged()));
183 connect(m_showButton, SIGNAL(clicked()),
this, SLOT(
slotShowButton()));
185 m_checkSymbol->setText(
"ORCL");
186 m_checkSymbol2->setText(
"BTC GBP");
187 m_updateButton->setEnabled(
false);
193 m_webPageDialog->deleteLater();
202 QListWidgetItem *item =
new QListWidgetItem(
dynamic_cast<QListWidget *
>(m_profileList));
203 item->setText(profile->
name());
204 item->setFlags(item->flags() | Qt::ItemIsEditable);
206 m_profileList->setCurrentRow(0);
213 m_quoteInEditing =
false;
214 QStringList groups = m_profile->quoteSources();
216 if (updateResetList) {
219 m_quoteSourceList->blockSignals(
true);
220 m_quoteSourceList->clear();
221 QStringList::Iterator it;
222 for (it = groups.begin(); it != groups.end(); ++it) {
228 QListWidgetItem *item =
new QListWidgetItem(*it);
229 item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
230 m_quoteSourceList->addItem(item);
231 if (updateResetList) {
232 m_resetList += source;
235 m_quoteSourceList->sortItems();
237 QListWidgetItem *item =
nullptr;
238 if (!m_currentItem.name().isEmpty()) {
239 QList<QListWidgetItem*> items = m_quoteSourceList->findItems(m_currentItem.name(), Qt::MatchExactly);
240 if (items.size() > 0)
243 m_quoteSourceList->setCurrentItem(item);
246 item = m_quoteSourceList->item(0);
248 m_quoteSourceList->setCurrentItem(item);
250 m_quoteSourceList->blockSignals(
false);
257 QListWidgetItem *item =
new QListWidgetItem(
dynamic_cast<QListWidget *
>(m_profileList));
258 item->setText(QLatin1String(
"new profile"));
259 item->setFlags(item->flags() | Qt::ItemIsEditable);
264 delete m_profileList->currentItem();
275 if (!m_showProfiles) {
279 m_profile = list.first();
280 m_installButton->setVisible(m_profile->hasGHNSSupport());
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();
314 bool enabled = item && !isFinanceQuoteSource;
316 m_editURL->setEnabled(enabled);
317 m_editSymbol->setEnabled(enabled);
318 m_editPrice->setEnabled(enabled);
319 m_editDate->setEnabled(enabled);
320 m_editDateFormat->setEnabled(enabled);
321 m_ghnsSource->setEnabled(!isFinanceQuoteSource);
322 m_skipStripping->setEnabled(enabled);
325 m_editSymbol->clear();
326 m_editPrice->clear();
328 m_editDateFormat->clear();
332 m_editURL->setText(m_currentItem.url());
333 m_editSymbol->setText(m_currentItem.sym());
334 m_editPrice->setText(m_currentItem.price());
335 m_editDate->setText(m_currentItem.date());
336 m_editDateFormat->setText(m_currentItem.dateformat());
337 m_skipStripping->setChecked(m_currentItem.skipStripping());
338 m_ghnsSource->setChecked(m_currentItem.isGHNS());
341 m_updateButton->setEnabled(
false);
347 bool modified = m_editURL->text() != m_currentItem.url()
348 || m_editSymbol->text() != m_currentItem.sym()
349 || m_editDate->text() != m_currentItem.date()
350 || m_editDateFormat->text() != m_currentItem.dateformat()
351 || m_editPrice->text() != m_currentItem.price()
352 || m_skipStripping->isChecked() != m_currentItem.skipStripping()
353 || m_ghnsSource->isChecked() != m_currentItem.isGHNS();
357 bool noNewEntry = m_quoteSourceList->findItems(i18n(
"New Quote Source"), Qt::MatchExactly).count() == 0 || isFinanceQuote;
358 m_newButton->setEnabled(hasWriteSupport && noNewEntry);
359 m_duplicateButton->setEnabled(hasWriteSupport);
360 m_deleteButton->setEnabled(!m_currentItem.isReadOnly() && !m_currentItem.isGHNS());
361 m_uploadButton->setEnabled(m_profile->hasGHNSSupport() && m_currentItem.isGHNS());
362 m_updateButton->setEnabled(modified);
363 m_checkButton->setEnabled(isFinanceQuote || !modified);
364 m_checkSymbol->setEnabled(!m_currentItem.url().contains(
"%2"));
365 m_checkSymbol2->setEnabled(m_currentItem.url().contains(
"%2"));
370 QList<QListWidgetItem *> items = m_quoteSourceList->findItems(
371 m_currentItem.name(), Qt::MatchExactly);
372 if (items.isEmpty()) {
375 QListWidgetItem *item = items.at(0);
380 int ret = KMessageBox::warningContinueCancel(
this,
381 i18n(
"Are you sure to delete this online quote ?"),
382 i18n(
"Delete online quote"),
383 KStandardGuiItem::cont(),
384 KStandardGuiItem::cancel(),
385 QString(
"DeletingOnlineQuote"));
386 if (ret == KMessageBox::Cancel) {
391 m_currentItem.remove();
398 QList<QListWidgetItem *> items = m_quoteSourceList->findItems(
399 m_currentItem.name(), Qt::MatchExactly);
400 if (items.isEmpty()) {
403 QListWidgetItem *item = items.at(0);
412 m_currentItem = copy;
418 m_currentItem.setUrl(m_editURL->text());
419 m_currentItem.setSym(m_editSymbol->text());
420 m_currentItem.setDate(m_editDate->text());
421 m_currentItem.setDateformat(m_editDateFormat->text());
422 m_currentItem.setPrice(m_editPrice->text());
423 m_currentItem.setSkipStripping(m_skipStripping->isChecked());
424 m_currentItem.setGHNS(m_ghnsSource->isChecked());
425 m_currentItem.write();
426 m_checkButton->setEnabled(
true);
434 m_currentItem = newSource;
440 m_urlCheckLabel->setPixmap(m_emptyIcon);
441 m_dateCheckLabel->setPixmap(m_emptyIcon);
442 m_priceCheckLabel->setPixmap(m_emptyIcon);
443 m_symbolCheckLabel->setPixmap(m_emptyIcon);
444 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
449 m_urlCheckLabel->setPixmap(m_inWorkIcon);
450 m_dateCheckLabel->setPixmap(m_inWorkIcon);
451 m_priceCheckLabel->setPixmap(m_inWorkIcon);
452 m_symbolCheckLabel->setPixmap(m_inWorkIcon);
453 m_dateFormatCheckLabel->setPixmap(m_inWorkIcon);
460 m_urlCheckLabel->setPixmap(m_failIcon);
462 m_urlCheckLabel->setPixmap(m_okIcon);
466 m_dateCheckLabel->setPixmap(m_failIcon);
468 m_dateCheckLabel->setPixmap(m_okIcon);
469 m_dateFormatCheckLabel->setPixmap(
478 m_logWindow->setVisible(
true);
479 m_logWindow->clear();
483 connect("e, SIGNAL(status(QString)),
this, SLOT(slotLogStatus(QString)));
484 connect("e, SIGNAL(error(QString)),
this, SLOT(slotLogError(QString)));
485 connect("e, SIGNAL(failed(QString,QString)),
this, SLOT(slotLogFailed(QString,QString)));
486 connect("e, SIGNAL(quote(QString,QString,QDate,
double)),
this,
487 SLOT(slotLogQuote(QString,QString,QDate,
double)));
489 if (m_currentItem.url().contains(
"%2")) {
490 quote.
launch(m_checkSymbol2->text(), m_checkSymbol2->text(), m_currentItem.name());
492 quote.
launch(m_checkSymbol->text(), m_checkSymbol->text(), m_currentItem.name());
494 setupIcons(quote.
errors());
499 m_logWindow->append(s);
504 slotLogStatus(QString(
"<font color=\"red\"><b>") + s + QString(
"</b></font>"));
509 slotLogStatus(QString(
"%1 %2").arg(
id, symbol));
513 const QDate &date,
double price)
515 slotLogStatus(QString(
"<font color=\"green\">%1 %2 %3 %4</font>").arg(
id, symbol,
516 date.toString()).arg(
522 m_quoteInEditing =
true;
523 m_quoteSourceList->editItem(item);
529 if (m_quoteInEditing ==
false || !m_quoteSourceList->currentItem()
530 || item != m_quoteSourceList->currentItem()) {
534 m_quoteInEditing =
false;
535 QString text = item->text();
537 for (
int i = 0; i < m_quoteSourceList->count(); ++i) {
538 if (m_quoteSourceList->item(i)->text() == text) {
544 if (text.length() > 0 && nameCount == 1) {
545 m_currentItem.rename(text);
547 item->setText(m_currentItem.name());
549 m_quoteSourceList->sortItems();
550 m_newButton->setEnabled(m_quoteSourceList->findItems(i18n(
552 Qt::MatchExactly).count() == 0);
557 QString configFile = m_profile->hotNewStuffConfigFile();
559 QPointer<KNS3::DownloadDialog> dialog =
new KNS3::DownloadDialog(configFile,
this);
567 QString configFile = m_profile->hotNewStuffConfigFile();
569 QUrl url = QUrl::fromLocalFile(m_currentItem.ghnsWriteFileName());
570 qDebug() <<
"uploading file" << url;
571 QPointer<KNS3::UploadDialog> dialog =
new KNS3::UploadDialog(configFile,
this);
572 dialog->setUploadName(m_currentItem.name());
573 dialog->setUploadFile(url);
580 if (!m_webPageDialog) {
581 m_webPageDialog =
new QDialog;
582 m_webPageDialog->setWindowTitle(i18n(
"Online Quote HTML Result Window"));
583 QVBoxLayout *layout =
new QVBoxLayout;
586 layout->addWidget(webPage->
widget());
587 m_webPageDialog->setLayout(layout);
589 m_webPageDialog->show();
594 if (m_currentItem.url().contains(
"%2")) {
595 return m_currentItem.url().arg(m_checkSymbol2->text());
597 return m_currentItem.url().arg(m_checkSymbol->text());
603 ,
d(new
Private(showProfiles, showUpload, this))
614 QFrame *frame =
new QFrame;
615 frame->setLayout(
d->profilesGroupBox->layout());
621 QFrame *frame =
new QFrame;
622 frame->setLayout(
d->profileDetailsBox->layout());
628 QFrame *frame =
new QFrame;
629 frame->setLayout(
d->onlineQuotesGroupBox->layout());
635 QFrame *frame =
new QFrame;
636 frame->setLayout(
d->detailsGroupBox->layout());
642 QFrame *frame =
new QFrame;
643 frame->setLayout(
d->debugGroupBox->layout());
657 QStringList::ConstIterator it;
661 for (it = groups.constBegin(); it != groups.constEnd(); ++it) {
666 QList<AlkOnlineQuoteSource>::iterator itr;
684 #include "alkonlinequoteswidget.moc"
QList< AlkOnlineQuotesProfile * > AlkOnlineQuotesProfileList
void setName(const QString &name)
bool isFinanceQuote() const
void setAcceptLanguage(const QString &language)
bool launch(const QString &_symbol, const QString &_id, const QString &_source=QString())
static AlkOnlineQuotesProfileManager & instance()
AlkOnlineQuotesProfileList profiles()
const QStringList quoteSources()
void setWebInspectorEnabled(bool enable)