9#include "alkonlinequoteswidget.h"
12#include "alknewstuffwidget.h"
13#include "alkonlinequote.h"
14#include "alkonlinequotesmodel.h"
15#include "alkonlinequotesource.h"
16#include "alkonlinequotesprofile.h"
17#include "alkonlinequotesprofilemanager.h"
18#include "alkonlinequoteuploaddialog.h"
19#include "alkwebpage.h"
20#include "alkwebview.h"
24#include <QDesktopServices>
26#include <QSortFilterProxyModel>
29#include <QTreeWidgetItem>
31#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
33#include <KMessageWidget>
37#include <KComponentData>
42#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
44#define initLocale() QLocale()
47#define initLocale() KGlobal::locale()
52#include <ui_alkonlinequotedetails.h>
53#include <ui_alkonlinequoteslist.h>
54#include <ui_alkonlinequotesdebug.h>
55#include <ui_alkonlinequotesprofiledetails.h>
56#include <ui_alkonlinequotesprofiles.h>
58#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
60static KLocale _locale(TRANSLATION_DOMAIN);
61#define i18nc(context, text) ki18nc(context, text).toString(&_locale)
62#define i18n(text) ki18n(text).toString(&_locale)
63#define tr2i18n(text, context) ki18nc(context, text).toString(&_locale)
66class AlkOnlineQuotesWidget::Private
68 ,
public Ui::AlkOnlineQuoteDetailsWidget
69 ,
public Ui::AlkOnlineQuotesDebugWidget
70 ,
public Ui::AlkOnlineQuotesProfileDetailsWidget
71 ,
public Ui::AlkOnlineQuotesProfilesWidget
72 ,
public Ui::AlkOnlineQuotesListWidget
79 bool m_quoteInEditing;
80 AlkOnlineQuotesProfile *m_profile;
92#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
95 AlkOnlineQuotesModel *m_model;
96 AlkOnlineQuotesWidget *m_p;
98 Private(
bool showProfiles,
bool showUpload, AlkOnlineQuotesWidget *
parent);
102 void slotNewProfile();
103 void slotDeleteProfile();
104 void slotSelectProfile();
105 void slotLoadProfile();
107 void slotDeleteEntry();
108 void slotDuplicateEntry();
109 void slotAcceptEntry();
110 void slotCopySettingsToClipboard();
111 void slotAddReferenceButton();
113 void slotEntryChanged();
115 void slotCheckEntry();
116 void slotLogStatus(
const QString &s);
117 void slotLogError(
const QString &s);
119 void slotLogQuote(
const QString &
id,
const QString &symbol,
const QDate &date,
double price);
121 void slotInstallEntries();
122 void slotResetQuotesList();
123 void slotUploadEntry();
124 void slotShowButton();
128 void loadQuotesList(
const bool updateResetList =
false);
135 void updateButtonState();
139AlkOnlineQuotesWidget::Private::Private(
bool showProfiles,
bool showUpload, AlkOnlineQuotesWidget *parent)
141 , m_quoteInEditing(false)
143 , m_showProfiles(showProfiles)
144 , m_showUpload(showUpload)
145 , m_ghnsEditable(false)
146 , m_disableUpdate(false)
147#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
148 , m_inWorkIcon(BarIcon(
"view-refresh"))
149 , m_okIcon(BarIcon(
"dialog-ok-apply"))
150 , m_failIcon(BarIcon(
"dialog-cancel"))
152 , m_inWorkIcon(
QIcon::fromTheme(
"view-refresh").pixmap(16))
153 , m_okIcon(
QIcon::fromTheme(
"dialog-ok-apply").pixmap(16))
154 , m_failIcon(
QIcon::fromTheme(
"dialog-cancel").pixmap(16))
156 , m_webPageDialog(nullptr)
158#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
159 , m_infoMessage(nullptr)
164#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
165 static KComponentData alk(TRANSLATION_DOMAIN);
167 Ui::AlkOnlineQuoteDetailsWidget::setupUi(parent);
168 Ui::AlkOnlineQuotesDebugWidget::setupUi(parent);
169 Ui::AlkOnlineQuotesProfileDetailsWidget::setupUi(parent);
170 Ui::AlkOnlineQuotesProfilesWidget::setupUi(parent);
171 Ui::AlkOnlineQuotesListWidget::setupUi(parent);
173 if (!
QString(BUILD_KEY).isEmpty())
174 m_buildKey->setText(
QString(
"<small>alkimia version: %1</small>").arg(BUILD_KEY));
176 m_buildKey->setText(
QString());
178#ifdef BUILD_WITH_WEBENGINE
179 AlkWebView::setWebInspectorEnabled(
true);
184#ifdef BUILD_WITH_WEBKIT
185 m_webView->setWebInspectorEnabled(
true);
187 AlkOnlineQuotesProfileManager::instance().setWebView(m_webView);
188 AlkOnlineQuotesProfileManager::instance().setWebPage(m_webView->webPage());
190 profilesGroupBox->setVisible(showProfiles);
191 profileDetailsBox->setVisible(showProfiles);
192 m_showButton->setVisible(!showProfiles && AlkOnlineQuotesProfileManager::instance().webViewEnabled());
193 m_ghnsSource->setVisible(
false);
194 m_urlCheckLabel->setMinimumWidth(m_okIcon.
width());
198#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
200 groupBoxLayout->insertWidget(0, m_infoMessage);
201 m_infoMessage->
hide();
204 connect(m_newProfile, SIGNAL(clicked()),
this, SLOT(slotNewProfile()));
205 connect(m_deleteProfile, SIGNAL(clicked()),
this, SLOT(slotDeleteProfile()));
206 connect(m_profileList, SIGNAL(itemSelectionChanged()),
this, SLOT(slotLoadProfile()));
208 connect(m_cancelButton, SIGNAL(clicked()),
this, SLOT(slotLoadQuoteSource()));
209 connect(m_acceptButton, SIGNAL(clicked()),
this, SLOT(slotAcceptEntry()));
210 connect(m_copyButton, SIGNAL(clicked()),
this, SLOT(slotCopySettingsToClipboard()));
211 connect(m_addReferenceButton, SIGNAL(clicked()),
this, SLOT(slotAddReferenceButton()));
212 connect(m_newButton, SIGNAL(clicked()),
this, SLOT(slotNewEntry()));
213 connect(m_resetButton, SIGNAL(clicked()),
this, SLOT(slotResetQuotesList()));
214 connect(m_checkButton, SIGNAL(clicked()),
this, SLOT(slotCheckEntry()));
215 connect(m_deleteButton, SIGNAL(clicked()),
this, SLOT(slotDeleteEntry()));
216 connect(m_duplicateButton, SIGNAL(clicked()),
this, SLOT(slotDuplicateEntry()));
217 connect(m_installButton, SIGNAL(clicked()),
this, SLOT(slotInstallEntries()));
218 connect(m_uploadButton, SIGNAL(clicked()),
this, SLOT(slotUploadEntry()));
221 const int rowHeight = fm.height();
222#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
225 m_quoteSourceList->verticalHeader()->setDefaultSectionSize(rowHeight);
229 m_quoteSourceList->verticalHeader()->setDefaultSectionSize(rowHeight);
231 m_quoteSourceList->verticalHeader()->setVisible(
false);
232 m_quoteSourceList->setShowGrid(
false);
233 m_quoteSourceList->horizontalHeader()->setVisible(
true);
234 m_quoteSourceList->setSortingEnabled(
true);
240 connect(m_editURL, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
241 connect(m_editIdentifier, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
243 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Symbol"), AlkOnlineQuoteSource::IdSelector::Symbol);
244 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Identification number"), AlkOnlineQuoteSource::IdSelector::IdentificationNumber);
245 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Name"), AlkOnlineQuoteSource::IdSelector::Name);
246 connect(m_editIdSelector, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
248 connect(m_editDate, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
249 connect(m_editDateFormat, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
250 connect(m_editDefaultId, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
257 m_editPriceDecimalSeparator->setItemData(0, AlkOnlineQuoteSource::DecimalSeparator::Period);
258 m_editPriceDecimalSeparator->setItemData(1, AlkOnlineQuoteSource::DecimalSeparator::Comma);
259 m_editPriceDecimalSeparator->setItemData(2, AlkOnlineQuoteSource::DecimalSeparator::Legacy);
265 connect(m_editPriceDecimalSeparator, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
266 connect(m_editPrice, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
268 m_editDataFormat->addItem(
toString(AlkOnlineQuoteSource::DataFormat::StrippedHTML), AlkOnlineQuoteSource::DataFormat::StrippedHTML);
269 m_editDataFormat->addItem(
toString(AlkOnlineQuoteSource::DataFormat::HTML), AlkOnlineQuoteSource::DataFormat::HTML);
270 m_editDataFormat->addItem(
toString(AlkOnlineQuoteSource::DataFormat::CSV), AlkOnlineQuoteSource::DataFormat::CSV);
271#ifdef BUILD_WITH_WEBKIT
272 m_editDataFormat->addItem(
toString(AlkOnlineQuoteSource::DataFormat::CSS), AlkOnlineQuoteSource::DataFormat::CSS);
274 m_editDataFormat->addItem(
toString(AlkOnlineQuoteSource::DataFormat::JSON), AlkOnlineQuoteSource::DataFormat::JSON);
275 connect(m_editDataFormat, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
277 m_editDownloadType->addItem(
i18nc(
"@item:inlistbox Stock",
"Default"), AlkOnlineQuoteSource::DownloadType::Default);
278 m_editDownloadType->addItem(
i18nc(
"@item:inlistbox Stock",
"Javascript"), AlkOnlineQuoteSource::DownloadType::Javascript);
279 connect(m_editDownloadType, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
281 connect(m_ghnsSource, SIGNAL(toggled(
bool)),
this, SLOT(slotEntryChanged()));
282 connect(m_showButton, SIGNAL(clicked()),
this, SLOT(slotShowButton()));
284 m_uploadButton->setVisible(
false);
285 m_acceptButton->setEnabled(
false);
286 m_resetButton->setVisible(m_showProfiles);
290AlkOnlineQuotesWidget::Private::~Private()
293 delete m_webView->webPage();
298void AlkOnlineQuotesWidget::Private::loadProfiles()
303 for (AlkOnlineQuotesProfile *profile : list) {
305 item->
setText(profile->name());
308 m_profileList->setCurrentRow(0);
309 m_profile = AlkOnlineQuotesProfileManager::instance().profiles().
first();
310 loadQuotesList(
true);
313void AlkOnlineQuotesWidget::Private::loadQuotesList(
const bool updateResetList)
317 m_model =
new AlkOnlineQuotesModel(m_profile);
319 proxyModel->setSourceModel(m_model);
320 m_quoteSourceList->setModel(proxyModel);
322 m_model->setProfile(m_profile);
325 if (updateResetList) {
327 const QStringList groups = m_profile->quoteSources();
333 for (
const auto& quoteSourceName : groups) {
335 if (!quoteSource.isGHNS()) {
336 m_resetList.
append(quoteSource);
342 const auto index = !indexes.isEmpty() ? indexes.at(0) :
QModelIndex();
344 m_quoteSourceList->setCurrentIndex(index);
345 m_quoteSourceList->selectRow(index.row());
347 slotLoadQuoteSource(m_quoteSourceList->currentIndex());
351void AlkOnlineQuotesWidget::Private::slotNewProfile()
358void AlkOnlineQuotesWidget::Private::slotDeleteProfile()
360 delete m_profileList->currentItem();
363void AlkOnlineQuotesWidget::Private::slotSelectProfile()
368void AlkOnlineQuotesWidget::Private::slotLoadProfile()
370 m_uploadButton->setEnabled(
false);
372 if (!m_showProfiles) {
376 m_installButton->setVisible(m_profile->hasGHNSSupport());
377 m_uploadButton->setVisible(m_profile->hasGHNSSupport());
378 loadQuotesList(
true);
382 for (AlkOnlineQuotesProfile *profile : list) {
383 if (m_profileList->currentItem() && m_profileList->currentItem()->text() == profile->name()) {
385 loadQuotesList(
true);
386 m_installButton->setVisible(profile->hasGHNSSupport());
387 m_uploadButton->setVisible(profile->hasGHNSSupport());
392 bool visible = m_profile->type() != AlkOnlineQuotesProfile::Type::None;
393 m_configFilePath->setText(m_profile->kConfigFile());
394 m_configFilePath->setVisible(
visible);
395 m_configLabel->setEnabled(
visible);
397 visible = m_profile->hasGHNSSupport();
398 m_GHNSConfigFilePath->setText(m_profile->hotNewStuffConfigFile());
399 m_GHNSConfigFilePath->setVisible(
visible);
400 m_GHNSConfigLabel->setEnabled(
visible);
402 m_GHNSDataPath->setText(m_profile->hotNewStuffReadPath().
join(
" "));
403 m_GHNSDataPath->setVisible(
visible);
404 m_GHNSDataLabel->setEnabled(
visible);
407void AlkOnlineQuotesWidget::Private::slotLoadQuoteSource(
const QModelIndex &index)
411 m_quoteInEditing =
false;
413 m_disableUpdate =
true;
415 m_editIdentifier->clear();
416 m_editIdSelector->setCurrentIndex(AlkOnlineQuoteSource::IdSelector::Symbol);
417 m_editPriceDecimalSeparator->setCurrentIndex(AlkOnlineQuoteSource::DecimalSeparator::Legacy);
418 m_editPrice->clear();
420 m_editDateFormat->clear();
421 m_editDefaultId->clear();
424 if (m_quoteSourceList->currentIndex().isValid()) {
425 name = m_quoteSourceList->model()->
data(m_quoteSourceList->currentIndex(), AlkOnlineQuotesModel::NameRole).toString();
427 m_currentItem = source;
430 m_editURL->setText(source.url());
431 m_editIdentifier->setText(source.idRegex());
432 m_editIdSelector->setData<AlkOnlineQuoteSource::IdSelector>(source.idSelector());
434 m_editPrice->setText(source.priceRegex());
436 m_editDate->setText(source.dateRegex());
437 m_editDateFormat->setText(source.dateFormat());
438 m_editDefaultId->setText(source.
defaultId());
439 m_editDownloadType->setData<AlkOnlineQuoteSource::DownloadType>(source.downloadType());
440 m_ghnsSource->setChecked(source.isGHNS());
445 m_profile->type() == AlkOnlineQuotesProfile::Type::Script;
447 if (isFinanceQuoteSource || (m_currentItem.isGHNS() && !m_ghnsEditable))
450 m_editURL->setEnabled(
enabled);
451 m_editIdentifier->setEnabled(
enabled);
452 m_editIdSelector->setEnabled(
enabled);
453 m_editPriceDecimalSeparator->setEnabled(
enabled);
454 m_editPrice->setEnabled(
enabled);
455 m_editDate->setEnabled(
enabled);
456 m_editDateFormat->setEnabled(
enabled);
457 m_editDefaultId->setEnabled(
enabled);
458 m_editDownloadType->setEnabled(
enabled);
459 m_ghnsSource->setVisible(m_profile && m_profile->hasGHNSSupport());
460 m_ghnsSource->setEnabled(m_showUpload && m_profile && m_profile->hasGHNSSupport() &&
enabled);
461 m_uploadButton->setEnabled(m_showUpload && m_profile && m_profile->hasGHNSSupport());
462 m_addReferenceButton->setEnabled(m_currentItem.isGHNS());
463 m_editDataFormat->setEnabled(
enabled);
481 m_disableUpdate =
false;
486void AlkOnlineQuotesWidget::Private::slotEntryChanged()
488 if (!m_disableUpdate)
492void AlkOnlineQuotesWidget::Private::updateButtonState()
496 (m_editURL->text() != m_currentItem.url()
497 || m_editIdentifier->text() != m_currentItem.idRegex()
498 || m_editIdSelector->currentIndex() != m_editIdSelector->findData(m_currentItem.idSelector())
499 || m_editDataFormat->currentIndex() != m_editDataFormat->findData(m_currentItem.
dataFormat())
500 || m_editDate->text() != m_currentItem.dateRegex()
501 || m_editDateFormat->text() != m_currentItem.dateFormat()
502 || m_editDefaultId->text() != m_currentItem.
defaultId()
503 || m_editPriceDecimalSeparator->currentIndex() != m_editPriceDecimalSeparator->findData(m_currentItem.priceDecimalSeparator())
504 || m_editDownloadType->currentIndex() != m_editDownloadType->findData(m_currentItem.downloadType())
505 || m_editPrice->text() != m_currentItem.priceRegex()
506 || m_ghnsSource->isChecked() != m_currentItem.isGHNS());
508 bool isFinanceQuote = m_currentItem.
isFinanceQuote() || m_profile->type() == AlkOnlineQuotesProfile::Type::Script;
509 bool hasWriteSupport = (m_profile->type() != AlkOnlineQuotesProfile::Type::None && !isFinanceQuote) || m_profile->hasGHNSSupport();
510 bool isRemoteUnpublished = m_currentItem.isGHNS() && m_currentItem.profile()->GHNSFilePath(m_currentItem.name()).
isEmpty();
511 bool isDefaultSource = m_profile->defaultQuoteSources().
contains(m_currentItem.name());
512 m_newButton->setEnabled(hasWriteSupport);
513 m_cancelButton->setEnabled(modified);
514 m_duplicateButton->setEnabled(hasWriteSupport);
515 m_deleteButton->setEnabled((!m_currentItem.isReadOnly() && !m_currentItem.isGHNS() && !isDefaultSource) || isRemoteUnpublished);
516 m_uploadButton->setEnabled(m_profile->hasGHNSSupport() && m_currentItem.isGHNS() && AlkOnlineQuoteUploadDialog::isSupported());
517 m_acceptButton->setEnabled(modified);
518 m_checkButton->setEnabled(isFinanceQuote || !modified);
519 m_editIdSelector->setVisible(m_profile->type() == AlkOnlineQuotesProfile::Type::KMyMoney5);
520 m_editIdSelectorLabel->setVisible(m_profile->type() == AlkOnlineQuotesProfile::Type::KMyMoney5);
527 bool hasDateRange = source.
dataFormat() == AlkOnlineQuoteSource::CSV || source.
dataFormat() == AlkOnlineQuoteSource::JSON;
528 m_startDateLabel->setVisible(hasDateRange);
529 m_endDateLabel->setVisible(hasDateRange);
530 m_startDateEdit->setVisible(hasDateRange);
531 m_endDateEdit->setVisible(hasDateRange);
534 m_checkSymbol->setEnabled(
false);
535 m_checkSymbol->setText(
QString());
536 m_checkSymbol2->setEnabled(
true);
537 setDefaultSource(m_checkSymbol2, source.
defaultId(),
"BTC GBP");
539 m_checkSymbol->setEnabled(
true);
540 setDefaultSource(m_checkSymbol, source.
defaultId(),
"ORCL");
541 m_checkSymbol2->setEnabled(
false);
542 m_checkSymbol2->setText(
QString());
546void AlkOnlineQuotesWidget::Private::setDefaultSource(
QLineEdit* editWidget,
const QString& sourceDefaultValue,
const QString& defaultValue)
550 editWidget->
setText(!sourceDefaultValue.
isEmpty() ? sourceDefaultValue : defaultValue);
553void AlkOnlineQuotesWidget::Private::slotDeleteEntry()
555 if (!m_quoteSourceList->currentIndex().isValid())
559 i18n(
"Are you sure to delete this online quote ?"),
560 i18n(
"Delete online quote"),
563 QString(
"DeletingOnlineQuote"));
569 m_quoteSourceList->model()->removeRow(m_quoteSourceList->currentIndex().row());
573void AlkOnlineQuotesWidget::Private::slotDuplicateEntry()
575 if (!m_quoteSourceList->currentIndex().isValid())
582 m_currentItem =
copy;
586void AlkOnlineQuotesWidget::Private::slotAcceptEntry()
588 m_currentItem.setUrl(m_editURL->text());
589 m_currentItem.setIdRegex(m_editIdentifier->text());
590 m_currentItem.setIdSelector(m_editIdSelector->currentData().value<AlkOnlineQuoteSource::IdSelector>());
593 m_currentItem.setDateFormat(m_editDateFormat->text());
596 m_currentItem.setDownloadType(m_editDownloadType->currentData().value<AlkOnlineQuoteSource::DownloadType>());
597 m_currentItem.setPriceRegex(m_editPrice->text());
598 m_currentItem.setGHNS(m_ghnsSource->isChecked());
599 m_currentItem.write();
600 m_checkButton->setEnabled(
true);
605void AlkOnlineQuotesWidget::Private::slotCopySettingsToClipboard()
610 settings <<
i18nc(
"@title %1 is version info",
"Online quote settings generated with Alkimia %1").
arg(BUILD_KEY);
613 settings <<
i18nc(
"@info online quote setting",
"URL: %1").
arg(m_editURL->text());
614 settings <<
i18nc(
"@info online quote setting",
"Download mode: %1").
arg(m_editDownloadType->currentText());
615 settings <<
i18nc(
"@info online quote setting",
"Data format: %1").
arg(m_editDataFormat->currentText());
616 settings <<
i18nc(
"@info online quote setting",
"Identifier: %1").
arg(m_editIdentifier->text());
617 settings <<
i18nc(
"@info online quote setting",
"Select by: %1").
arg(m_editIdSelector->currentText());
618 settings <<
i18nc(
"@info online quote setting",
"Price: %1").
arg(m_editPrice->text());
619 settings <<
i18nc(
"@info online quote setting",
"Price decimal separator: %1").
arg(m_editPriceDecimalSeparator->currentText());
620 settings <<
i18nc(
"@info online quote setting",
"Date: %1").
arg(m_editDate->text());
621 settings <<
i18nc(
"@info online quote setting",
"Date format: %1").
arg(m_editDateFormat->text());
622 settings <<
i18nc(
"@info online quote setting",
"Default identifier: %1").
arg(m_editDefaultId->text());
623 settings <<
i18nc(
"@info online quote setting",
"Remote source: %1")
624 .
arg(m_ghnsSource->isChecked() ?
i18nc(
"@item:intext checkbox setting",
"checked") :
i18nc(
"@item:intext checkbox setting",
"not checked"));
632void AlkOnlineQuotesWidget::Private::slotAddReferenceButton()
634 if (!m_quoteSourceList->currentIndex().isValid())
637 QString newNameBase = m_currentItem.name() +
i18nc(
"@item:valuesuffix to name for a quote source reference",
".reference");
640 while(m_profile->quoteSources().
contains(newName)) {
645 copy.setReferenceName(m_currentItem.name());
647 m_currentItem =
copy;
651void AlkOnlineQuotesWidget::Private::slotNewEntry()
653 const bool newEntries = m_profile->quoteSources().
contains(
i18n(
"New Quote Source"));
657 m_currentItem = newSource;
661#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
665 i18nc(
"@info Detail that only one new entry can exist at any time",
"<b>New Quote Source</b> already exists."));
673void AlkOnlineQuotesWidget::Private::clearIcons()
675 m_urlCheckLabel->setPixmap(m_emptyIcon);
676 m_dateCheckLabel->setPixmap(m_emptyIcon);
677 m_priceCheckLabel->setPixmap(m_emptyIcon);
678 m_symbolCheckLabel->setPixmap(m_emptyIcon);
679 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
682void AlkOnlineQuotesWidget::Private::initIcons()
684 m_urlCheckLabel->setPixmap(m_inWorkIcon);
685 m_dateCheckLabel->setPixmap(m_inWorkIcon);
686 m_priceCheckLabel->setPixmap(m_inWorkIcon);
687 m_symbolCheckLabel->setPixmap(m_inWorkIcon);
688 m_dateFormatCheckLabel->setPixmap(m_inWorkIcon);
694 if (errors & AlkOnlineQuote::Errors::URL) {
695 m_urlCheckLabel->setPixmap(m_failIcon);
697 m_urlCheckLabel->setPixmap(m_okIcon);
698 m_symbolCheckLabel->setPixmap((errors & AlkOnlineQuote::Errors::Symbol) ? m_failIcon : m_okIcon);
699 m_priceCheckLabel->setPixmap((errors & AlkOnlineQuote::Errors::Price) ? m_failIcon : m_okIcon);
700 if (errors & AlkOnlineQuote::Errors::Date) {
701 m_dateCheckLabel->setPixmap(m_failIcon);
703 if (m_currentItem.dateRegex().
isEmpty()) {
704 m_dateCheckLabel->setPixmap(m_emptyIcon);
705 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
707 m_dateCheckLabel->setPixmap(m_okIcon);
708 m_dateFormatCheckLabel->setPixmap(
709 (errors & AlkOnlineQuote::Errors::DateFormat) ? m_failIcon : m_okIcon);
715void AlkOnlineQuotesWidget::Private::slotCheckEntry()
718 m_logWindow->setVisible(
true);
719 m_logWindow->clear();
721 quote.setAcceptLanguage(m_acceptLanguage);
735 if (source.
dataFormat() == AlkOnlineQuoteSource::CSV || source.
dataFormat() == AlkOnlineQuoteSource::JSON) {
736 quote.setDateRange(m_startDateEdit->date(), m_endDateEdit->date());
742 quote.launch(m_checkSymbol2->text(), m_checkSymbol2->text(), source.name());
744 quote.launch(m_checkSymbol->text(), m_checkSymbol->text(), source.name());
746 setupIcons(quote.errors());
749void AlkOnlineQuotesWidget::Private::slotLogStatus(
const QString &s)
751 m_logWindow->append(s);
754void AlkOnlineQuotesWidget::Private::slotLogError(
const QString &s)
756 slotLogStatus(
QString(
"<font color=\"red\"><b>") + s +
QString(
"</b></font>"));
759void AlkOnlineQuotesWidget::Private::slotLogFailed(
const QString &
id,
const QString &symbol)
761 slotLogStatus(
QString(
"%1 %2").arg(
id, symbol));
764void AlkOnlineQuotesWidget::Private::slotLogQuote(
const QString &
id,
const QString &symbol,
765 const QDate &date,
double price)
767 slotLogStatus(
QString(
"<font color=\"green\">%1 %2 %3 %4</font>").arg(
id, symbol,
772void AlkOnlineQuotesWidget::Private::slotLogQuotes(
const QString &
id,
const QString &symbol,
775 slotLogStatus(
QString(
"<font color=\"green\">%1 %2</font>").arg(
id, symbol));
777 slotLogStatus(
QString(
"<font color=\"green\">date price</font>"));
779 slotLogStatus(
QString(
"<font color=\"green\">%1 %2</font>")
784void AlkOnlineQuotesWidget::Private::slotInstallEntries()
786 QString configFile = m_profile->hotNewStuffConfigFile();
789 widget.init(configFile);
790 if (widget.showInstallDialog()) {
796void AlkOnlineQuotesWidget::Private::slotResetQuotesList()
801void AlkOnlineQuotesWidget::Private::slotUploadEntry()
808void AlkOnlineQuotesWidget::Private::slotShowButton()
810 if (!m_webPageDialog) {
817 m_webPageDialog->
show();
820QString AlkOnlineQuotesWidget::Private::expandedUrl()
const
826 return source.url().
arg(m_checkSymbol2->text());
828 return source.url().
arg(m_checkSymbol->text());
832AlkOnlineQuotesWidget::AlkOnlineQuotesWidget(
bool showProfiles,
bool showUpload,
QWidget *
parent)
834 , d(new Private(showProfiles, showUpload, this))
838AlkOnlineQuotesWidget::~AlkOnlineQuotesWidget()
843QWidget *AlkOnlineQuotesWidget::profilesWidget()
850QWidget *AlkOnlineQuotesWidget::profileDetailsWidget()
857QWidget *AlkOnlineQuotesWidget::onlineQuotesWidget()
864QWidget *AlkOnlineQuotesWidget::quoteDetailsWidget()
871QWidget *AlkOnlineQuotesWidget::debugWidget()
878void AlkOnlineQuotesWidget::readConfig()
882void AlkOnlineQuotesWidget::writeConfig()
886void AlkOnlineQuotesWidget::resetConfig()
900 if (!quoteSource.isGHNS()) {
901 quoteSource.remove();
907 for (itr = d->m_resetList.
begin(); itr != d->m_resetList.
end(); ++itr) {
914QString AlkOnlineQuotesWidget::acceptLanguage()
const
916 return d->m_acceptLanguage;
919void AlkOnlineQuotesWidget::setAcceptLanguage(
const QString &text)
921 d->m_acceptLanguage = text;
924bool AlkOnlineQuotesWidget::GHNSSourceEditable()
926 return d->m_ghnsEditable;
930void AlkOnlineQuotesWidget::setGHNSSourceEditable(
bool state)
932 d->m_ghnsEditable = state;
935#include "alkonlinequoteswidget.moc"
Wrapper for debug output.
const QString & defaultId() const
Return the default identifier known to work.
void setDefaultId(const QString &defaultId)
Set the default identifier, which is known to work.
bool requiresTwoIdentifier() const
Return state if this source requires two identifier.
DataFormat
Supported formats of downloaded data.
bool isReference() const
Return state if this source is a reference.
DecimalSeparator
Type of decimal separator.
AlkOnlineQuoteSource asReference() const
Return referenced quote source.
DataFormat dataFormat() const
Return the format of the downloaded data.
bool isFinanceQuote() const
Checks whether the current source is of type "Finance::Quote".
void setDataFormat(DataFormat dataFormat)
Set the format of the downloaded data.
void setDateRegex(const QString &dateRegex)
Set regular expression for parsing dates.
Hold errors reported from price quote fetching and parsing.
Retrieves a price quote from a web-based quote source.
LastPriceState
Supported values for returning prices in special cases.
The AlkWebPage class provides an object to load and view web documents to provide functionality like ...
The AlkWebView class provides a widget that is used to load and display web documents.
Q_SCRIPTABLE CaptureState status()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
ButtonCode warningContinueCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
const QList< QKeySequence > & copy()
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void setText(const QString &text, Mode mode)
QString toString(QStringView format, QCalendar cal) const const
void append(QList< T > &&value)
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
void setText(const QString &text)
const_iterator constBegin() const const
const_iterator constEnd() const const
bool contains(const Key &key) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setText(int column, const QString &text)