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
76 QString m_acceptLanguage;
77 QList<AlkOnlineQuoteSource> m_resetList;
78 AlkOnlineQuoteSource m_currentItem;
79 bool m_quoteInEditing;
80 AlkOnlineQuotesProfile *m_profile;
81 AlkWebView *m_webView;
90 QPixmap m_unknownIcon;
91 QDialog *m_webPageDialog;
92#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
93 KMessageWidget* m_infoMessage;
95 AlkOnlineQuotesModel *m_model;
96 AlkOnlineQuotesWidget *m_p;
97 AlkOnlineQuote m_quote;
99 Private(
bool showProfiles,
bool showUpload, AlkOnlineQuotesWidget *
parent);
103 void slotNewProfile();
104 void slotDeleteProfile();
105 void slotSelectProfile();
106 void slotLoadProfile();
108 void slotDeleteEntry();
109 void slotDuplicateEntry();
110 void slotAcceptEntry();
111 void slotCopySettingsToClipboard();
112 void slotAddReferenceButton();
113 void slotLoadQuoteSource(
const QModelIndex &index = QModelIndex());
114 void slotEntryChanged();
116 void slotCheckEntry();
117 void slotLogStatus(
const QString &s);
118 void slotLogError(
const QString &s);
119 void slotLogFailed(
const QString &
id,
const QString &symbol);
120 void slotLogQuote(
const QString &
id,
const QString &symbol,
const QDate &date,
double price);
121 void slotLogQuotes(
const QString &
id,
const QString &symbol,
const AlkDatePriceMap &prices);
122 void slotInstallEntries();
123 void slotResetQuotesList();
124 void slotUploadEntry();
125 void slotShowButton();
129 void loadQuotesList(
const bool updateResetList =
false);
132 void setupIcons(
const AlkOnlineQuote::Errors &errors);
133 QString singleSymbol()
const;
134 QStringList doubleSymbol()
const;
135 QString expandedUrl()
const;
136 void updateButtonState();
137 void setDefaultSource(QLineEdit* editWidget,
const QString& sourceDefaultValue,
const QString& defaultValue);
140AlkOnlineQuotesWidget::Private::Private(
bool showProfiles,
bool showUpload, AlkOnlineQuotesWidget *parent)
142 , m_quoteInEditing(false)
144 , m_showProfiles(showProfiles)
145 , m_showUpload(showUpload)
146 , m_ghnsEditable(false)
147 , m_disableUpdate(false)
148#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
149 , m_inWorkIcon(BarIcon(
"view-refresh"))
150 , m_okIcon(BarIcon(
"dialog-ok-apply"))
151 , m_failIcon(BarIcon(
"dialog-cancel"))
153 , m_inWorkIcon(
QIcon::fromTheme(
"view-refresh").pixmap(16))
154 , m_okIcon(
QIcon::fromTheme(
"dialog-ok-apply").pixmap(16))
155 , m_failIcon(
QIcon::fromTheme(
"dialog-cancel").pixmap(16))
157 , m_webPageDialog(nullptr)
159#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
160 , m_infoMessage(nullptr)
165#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
166 static KComponentData alk(TRANSLATION_DOMAIN);
168 Ui::AlkOnlineQuoteDetailsWidget::setupUi(parent);
169 Ui::AlkOnlineQuotesDebugWidget::setupUi(parent);
170 Ui::AlkOnlineQuotesProfileDetailsWidget::setupUi(parent);
171 Ui::AlkOnlineQuotesProfilesWidget::setupUi(parent);
172 Ui::AlkOnlineQuotesListWidget::setupUi(parent);
174 if (!
QString(BUILD_KEY).isEmpty())
175 m_buildKey->setText(
QString(
"<small>alkimia version: %1</small>").arg(BUILD_KEY));
177 m_buildKey->setText(
QString());
179#ifdef BUILD_WITH_WEBENGINE
180 AlkWebView::setWebInspectorEnabled(
true);
185#ifdef BUILD_WITH_WEBKIT
186 m_webView->setWebInspectorEnabled(
true);
188 AlkOnlineQuotesProfileManager::instance().setWebView(m_webView);
189 AlkOnlineQuotesProfileManager::instance().setWebPage(m_webView->webPage());
191 profilesGroupBox->setVisible(showProfiles);
192 profileDetailsBox->setVisible(showProfiles);
193 m_showButton->setVisible(!showProfiles && AlkOnlineQuotesProfileManager::instance().webViewEnabled());
194 m_ghnsSource->setVisible(
false);
195 m_urlCheckLabel->setMinimumWidth(m_okIcon.
width());
199#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
201 groupBoxLayout->insertWidget(0, m_infoMessage);
202 m_infoMessage->
hide();
205 connect(m_newProfile, SIGNAL(clicked()),
this, SLOT(slotNewProfile()));
206 connect(m_deleteProfile, SIGNAL(clicked()),
this, SLOT(slotDeleteProfile()));
207 connect(m_profileList, SIGNAL(itemSelectionChanged()),
this, SLOT(slotLoadProfile()));
209 connect(m_cancelButton, SIGNAL(clicked()),
this, SLOT(slotLoadQuoteSource()));
210 connect(m_acceptButton, SIGNAL(clicked()),
this, SLOT(slotAcceptEntry()));
211 connect(m_copyButton, SIGNAL(clicked()),
this, SLOT(slotCopySettingsToClipboard()));
212 connect(m_addReferenceButton, SIGNAL(clicked()),
this, SLOT(slotAddReferenceButton()));
213 connect(m_newButton, SIGNAL(clicked()),
this, SLOT(slotNewEntry()));
214 connect(m_resetButton, SIGNAL(clicked()),
this, SLOT(slotResetQuotesList()));
215 connect(m_checkButton, SIGNAL(clicked()),
this, SLOT(slotCheckEntry()));
216 connect(m_deleteButton, SIGNAL(clicked()),
this, SLOT(slotDeleteEntry()));
217 connect(m_duplicateButton, SIGNAL(clicked()),
this, SLOT(slotDuplicateEntry()));
218 connect(m_installButton, SIGNAL(clicked()),
this, SLOT(slotInstallEntries()));
219 connect(m_uploadButton, SIGNAL(clicked()),
this, SLOT(slotUploadEntry()));
222 const int rowHeight = fm.height();
223#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
226 m_quoteSourceList->verticalHeader()->setDefaultSectionSize(rowHeight);
230 m_quoteSourceList->verticalHeader()->setDefaultSectionSize(rowHeight);
232 m_quoteSourceList->verticalHeader()->setVisible(
false);
233 m_quoteSourceList->setShowGrid(
false);
234 m_quoteSourceList->horizontalHeader()->setVisible(
true);
235 m_quoteSourceList->setSortingEnabled(
true);
241 connect(m_editURL, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
242 connect(m_editIdentifier, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
244 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Symbol"), AlkOnlineQuoteSource::IdSelector::Symbol);
245 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Identification number"), AlkOnlineQuoteSource::IdSelector::IdentificationNumber);
246 m_editIdSelector->addItem(
i18nc(
"@item:inlistbox Stock",
"Name"), AlkOnlineQuoteSource::IdSelector::Name);
247 connect(m_editIdSelector, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
249 connect(m_editDate, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
250 connect(m_editDateFormat, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
251 connect(m_editDefaultId, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
258 m_editPriceDecimalSeparator->setItemData(0, AlkOnlineQuoteSource::DecimalSeparator::Period);
259 m_editPriceDecimalSeparator->setItemData(1, AlkOnlineQuoteSource::DecimalSeparator::Comma);
260 m_editPriceDecimalSeparator->setItemData(2, AlkOnlineQuoteSource::DecimalSeparator::Legacy);
266 connect(m_editPriceDecimalSeparator, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
267 connect(m_editPrice, SIGNAL(textChanged(
QString)),
this, SLOT(slotEntryChanged()));
269 m_editDataFormat->addItem(toString(AlkOnlineQuoteSource::DataFormat::StrippedHTML), AlkOnlineQuoteSource::DataFormat::StrippedHTML);
270 m_editDataFormat->addItem(toString(AlkOnlineQuoteSource::DataFormat::HTML), AlkOnlineQuoteSource::DataFormat::HTML);
271 m_editDataFormat->addItem(toString(AlkOnlineQuoteSource::DataFormat::CSV), AlkOnlineQuoteSource::DataFormat::CSV);
272#ifdef BUILD_WITH_WEBKIT
273 m_editDataFormat->addItem(toString(AlkOnlineQuoteSource::DataFormat::CSS), AlkOnlineQuoteSource::DataFormat::CSS);
275 m_editDataFormat->addItem(toString(AlkOnlineQuoteSource::DataFormat::JSON), AlkOnlineQuoteSource::DataFormat::JSON);
276 connect(m_editDataFormat, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
278 m_editDownloadType->addItem(
i18nc(
"@item:inlistbox Stock",
"Default"), AlkOnlineQuoteSource::DownloadType::Default);
279 m_editDownloadType->addItem(
i18nc(
"@item:inlistbox Stock",
"Javascript"), AlkOnlineQuoteSource::DownloadType::Javascript);
280 connect(m_editDownloadType, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotEntryChanged()));
282 connect(m_ghnsSource, SIGNAL(toggled(
bool)),
this, SLOT(slotEntryChanged()));
283 connect(m_showButton, SIGNAL(clicked()),
this, SLOT(slotShowButton()));
298 m_uploadButton->setVisible(
false);
299 m_acceptButton->setEnabled(
false);
300 m_resetButton->setVisible(m_showProfiles);
304AlkOnlineQuotesWidget::Private::~Private()
307 if (m_webPageDialog) {
308 m_webPageDialog->deleteLater();
310 delete m_webView->webPage();
315void AlkOnlineQuotesWidget::Private::loadProfiles()
317 AlkOnlineQuotesProfileList
list = AlkOnlineQuotesProfileManager::instance().profiles();
320 for (AlkOnlineQuotesProfile *profile : list) {
321 QListWidgetItem *item =
new QListWidgetItem(
dynamic_cast<QListWidget *
>(m_profileList));
322 item->
setText(profile->name());
325 m_profileList->setCurrentRow(0);
326 m_profile = AlkOnlineQuotesProfileManager::instance().profiles().
first();
327 loadQuotesList(
true);
330void AlkOnlineQuotesWidget::Private::loadQuotesList(
const bool updateResetList)
334 m_model =
new AlkOnlineQuotesModel(m_profile);
335 auto proxyModel =
new QSortFilterProxyModel(
this);
336 proxyModel->setSourceModel(m_model);
337 m_quoteSourceList->setModel(proxyModel);
339 m_model->setProfile(m_profile);
342 if (updateResetList) {
344 const QStringList groups = m_profile->quoteSources();
350 for (
const auto& quoteSourceName : groups) {
351 const auto quoteSource = AlkOnlineQuoteSource(quoteSourceName, m_profile);
352 if (!quoteSource.isGHNS()) {
353 m_resetList.
append(quoteSource);
359 const auto index = !indexes.isEmpty() ? indexes.at(0) : QModelIndex();
361 m_quoteSourceList->setCurrentIndex(index);
362 m_quoteSourceList->selectRow(index.row());
364 slotLoadQuoteSource(m_quoteSourceList->currentIndex());
368void AlkOnlineQuotesWidget::Private::slotNewProfile()
370 QTreeWidgetItem *item =
new QTreeWidgetItem(
dynamic_cast<QTreeWidget *
>(m_profileList));
371 item->
setText(0, QLatin1String(
"new profile"));
375void AlkOnlineQuotesWidget::Private::slotDeleteProfile()
377 delete m_profileList->currentItem();
380void AlkOnlineQuotesWidget::Private::slotSelectProfile()
385void AlkOnlineQuotesWidget::Private::slotLoadProfile()
387 m_uploadButton->setEnabled(
false);
388 const AlkOnlineQuotesProfileList
list = AlkOnlineQuotesProfileManager::instance().profiles();
389 if (!m_showProfiles) {
393 m_installButton->setVisible(m_profile->hasGHNSSupport());
394 m_uploadButton->setVisible(m_profile->hasGHNSSupport());
395 loadQuotesList(
true);
399 for (AlkOnlineQuotesProfile *profile : list) {
400 if (m_profileList->currentItem() && m_profileList->currentItem()->text() == profile->name()) {
402 loadQuotesList(
true);
403 m_installButton->setVisible(profile->hasGHNSSupport());
404 m_uploadButton->setVisible(profile->hasGHNSSupport());
409 bool visible = m_profile->type() != AlkOnlineQuotesProfile::Type::None;
410 m_configFilePath->setText(m_profile->kConfigFile());
411 m_configFilePath->setVisible(
visible);
412 m_configLabel->setEnabled(
visible);
414 visible = m_profile->hasGHNSSupport();
415 m_GHNSConfigFilePath->setText(m_profile->hotNewStuffConfigFile());
416 m_GHNSConfigFilePath->setVisible(
visible);
417 m_GHNSConfigLabel->setEnabled(
visible);
419 m_GHNSDataPath->setText(m_profile->hotNewStuffReadPath().
join(
" "));
420 m_GHNSDataPath->setVisible(
visible);
421 m_GHNSDataLabel->setEnabled(
visible);
424void AlkOnlineQuotesWidget::Private::slotLoadQuoteSource(
const QModelIndex &index)
428 m_quoteInEditing =
false;
430 m_disableUpdate =
true;
432 m_editIdentifier->clear();
433 m_editIdSelector->setCurrentIndex(AlkOnlineQuoteSource::IdSelector::Symbol);
434 m_editPriceDecimalSeparator->setCurrentIndex(AlkOnlineQuoteSource::DecimalSeparator::Legacy);
435 m_editPrice->clear();
437 m_editDateFormat->clear();
438 m_editDefaultId->clear();
441 if (m_quoteSourceList->currentIndex().isValid()) {
442 name = m_quoteSourceList->model()->
data(m_quoteSourceList->currentIndex(), AlkOnlineQuotesModel::NameRole).toString();
443 AlkOnlineQuoteSource source = AlkOnlineQuoteSource(name, m_profile);
444 m_currentItem = source;
447 m_editURL->setText(source.url());
448 m_editIdentifier->setText(source.idRegex());
449 m_editIdSelector->setData<AlkOnlineQuoteSource::IdSelector>(source.idSelector());
451 m_editPrice->setText(source.priceRegex());
453 m_editDate->setText(source.dateRegex());
454 m_editDateFormat->setText(source.dateFormat());
455 m_editDefaultId->setText(source.
defaultId());
456 m_editDownloadType->setData<AlkOnlineQuoteSource::DownloadType>(source.downloadType());
457 m_ghnsSource->setChecked(source.isGHNS());
462 m_profile->type() == AlkOnlineQuotesProfile::Type::Script;
464 if (isFinanceQuoteSource || (m_currentItem.isGHNS() && !m_ghnsEditable))
467 m_editURL->setEnabled(
enabled);
468 m_editIdentifier->setEnabled(
enabled);
469 m_editIdSelector->setEnabled(
enabled);
470 m_editPriceDecimalSeparator->setEnabled(
enabled);
471 m_editPrice->setEnabled(
enabled);
472 m_editDate->setEnabled(
enabled);
473 m_editDateFormat->setEnabled(
enabled);
474 m_editDefaultId->setEnabled(
enabled);
475 m_editDownloadType->setEnabled(
enabled);
476 m_ghnsSource->setVisible(m_profile && m_profile->hasGHNSSupport());
477 m_ghnsSource->setEnabled(m_showUpload && m_profile && m_profile->hasGHNSSupport() &&
enabled);
478 m_uploadButton->setEnabled(m_showUpload && m_profile && m_profile->hasGHNSSupport());
479 m_addReferenceButton->setEnabled(m_currentItem.isGHNS());
480 m_editDataFormat->setEnabled(
enabled);
498 m_disableUpdate =
false;
503void AlkOnlineQuotesWidget::Private::slotEntryChanged()
505 if (!m_disableUpdate)
509void AlkOnlineQuotesWidget::Private::updateButtonState()
513 (m_editURL->text() != m_currentItem.url()
514 || m_editIdentifier->text() != m_currentItem.idRegex()
515 || m_editIdSelector->currentIndex() != m_editIdSelector->findData(m_currentItem.idSelector())
516 || m_editDataFormat->currentIndex() != m_editDataFormat->findData(m_currentItem.
dataFormat())
517 || m_editDate->text() != m_currentItem.dateRegex()
518 || m_editDateFormat->text() != m_currentItem.dateFormat()
519 || m_editDefaultId->text() != m_currentItem.
defaultId()
520 || m_editPriceDecimalSeparator->currentIndex() != m_editPriceDecimalSeparator->findData(m_currentItem.priceDecimalSeparator())
521 || m_editDownloadType->currentIndex() != m_editDownloadType->findData(m_currentItem.downloadType())
522 || m_editPrice->text() != m_currentItem.priceRegex()
523 || m_ghnsSource->isChecked() != m_currentItem.isGHNS());
525 bool isFinanceQuote = m_currentItem.
isFinanceQuote() || m_profile->type() == AlkOnlineQuotesProfile::Type::Script;
526 bool hasWriteSupport = (m_profile->type() != AlkOnlineQuotesProfile::Type::None && !isFinanceQuote) || m_profile->hasGHNSSupport();
527 bool isRemoteUnpublished = m_currentItem.isGHNS() && m_currentItem.profile()->GHNSFilePath(m_currentItem.name()).
isEmpty();
528 bool isDefaultSource = m_profile->defaultQuoteSources().
contains(m_currentItem.name());
529 m_newButton->setEnabled(hasWriteSupport);
530 m_cancelButton->setEnabled(modified);
531 m_duplicateButton->setEnabled(hasWriteSupport);
532 m_deleteButton->setEnabled((!m_currentItem.isReadOnly() && !m_currentItem.isGHNS() && !isDefaultSource) || isRemoteUnpublished);
533 m_uploadButton->setEnabled(m_profile->hasGHNSSupport() && m_currentItem.isGHNS() && AlkOnlineQuoteUploadDialog::isSupported());
534 m_acceptButton->setEnabled(modified);
535 m_checkButton->setEnabled(isFinanceQuote || !modified);
536 m_editIdSelector->setVisible(m_profile->type() == AlkOnlineQuotesProfile::Type::KMyMoney5);
537 m_editIdSelectorLabel->setVisible(m_profile->type() == AlkOnlineQuotesProfile::Type::KMyMoney5);
540 AlkOnlineQuoteSource source(m_currentItem);
544 bool hasDateRange = source.
dataFormat() == AlkOnlineQuoteSource::CSV || source.
dataFormat() == AlkOnlineQuoteSource::JSON;
545 m_startDateLabel->setVisible(hasDateRange);
546 m_endDateLabel->setVisible(hasDateRange);
547 m_startDateEdit->setVisible(hasDateRange);
548 m_endDateEdit->setVisible(hasDateRange);
551 m_checkSymbol->setEnabled(
false);
552 m_checkSymbol->setText(QString());
553 m_checkSymbol2->setEnabled(
true);
554 setDefaultSource(m_checkSymbol2, source.
defaultId(),
"BTC GBP");
555 m_reverseSearchStateCheckBox->setVisible(
true);
557 m_checkSymbol->setEnabled(
true);
558 setDefaultSource(m_checkSymbol, source.
defaultId(),
"ORCL");
559 m_checkSymbol2->setEnabled(
false);
560 m_checkSymbol2->setText(QString());
561 m_reverseSearchStateCheckBox->setVisible(
false);
565void AlkOnlineQuotesWidget::Private::setDefaultSource(QLineEdit* editWidget,
const QString& sourceDefaultValue,
const QString& defaultValue)
567 QString currentValue = editWidget->
text();
569 editWidget->
setText(!sourceDefaultValue.
isEmpty() ? sourceDefaultValue : defaultValue);
572void AlkOnlineQuotesWidget::Private::slotDeleteEntry()
574 if (!m_quoteSourceList->currentIndex().isValid())
578 i18n(
"Are you sure to delete this online quote ?"),
579 i18n(
"Delete online quote"),
582 QString(
"DeletingOnlineQuote"));
588 m_quoteSourceList->model()->removeRow(m_quoteSourceList->currentIndex().row());
590 slotLoadQuoteSource(m_quoteSourceList->currentIndex());
594void AlkOnlineQuotesWidget::Private::slotDuplicateEntry()
596 if (!m_quoteSourceList->currentIndex().isValid())
599 AlkOnlineQuoteSource
copy(m_currentItem);
603 m_currentItem =
copy;
607void AlkOnlineQuotesWidget::Private::slotAcceptEntry()
609 m_currentItem.setUrl(m_editURL->text());
610 m_currentItem.setIdRegex(m_editIdentifier->text());
611 m_currentItem.setIdSelector(m_editIdSelector->currentData().value<AlkOnlineQuoteSource::IdSelector>());
614 m_currentItem.setDateFormat(m_editDateFormat->text());
617 m_currentItem.setDownloadType(m_editDownloadType->currentData().value<AlkOnlineQuoteSource::DownloadType>());
618 m_currentItem.setPriceRegex(m_editPrice->text());
619 m_currentItem.setGHNS(m_ghnsSource->isChecked());
620 m_currentItem.write();
621 m_checkButton->setEnabled(
true);
626void AlkOnlineQuotesWidget::Private::slotCopySettingsToClipboard()
630 QStringList settings;
631 settings <<
i18nc(
"@title %1 is version info",
"Online quote settings generated with Alkimia %1").
arg(BUILD_KEY);
632 settings << QString();
634 settings <<
i18nc(
"@info online quote setting",
"URL: %1").
arg(m_editURL->text());
635 settings <<
i18nc(
"@info online quote setting",
"Download mode: %1").
arg(m_editDownloadType->currentText());
636 settings <<
i18nc(
"@info online quote setting",
"Data format: %1").
arg(m_editDataFormat->currentText());
637 settings <<
i18nc(
"@info online quote setting",
"Identifier: %1").
arg(m_editIdentifier->text());
638 settings <<
i18nc(
"@info online quote setting",
"Select by: %1").
arg(m_editIdSelector->currentText());
639 settings <<
i18nc(
"@info online quote setting",
"Price: %1").
arg(m_editPrice->text());
640 settings <<
i18nc(
"@info online quote setting",
"Price decimal separator: %1").
arg(m_editPriceDecimalSeparator->currentText());
641 settings <<
i18nc(
"@info online quote setting",
"Date: %1").
arg(m_editDate->text());
642 settings <<
i18nc(
"@info online quote setting",
"Date format: %1").
arg(m_editDateFormat->text());
643 settings <<
i18nc(
"@info online quote setting",
"Default identifier: %1").
arg(m_editDefaultId->text());
644 settings <<
i18nc(
"@info online quote setting",
"Remote source: %1")
645 .
arg(m_ghnsSource->isChecked() ?
i18nc(
"@item:intext checkbox setting",
"checked") :
i18nc(
"@item:intext checkbox setting",
"not checked"));
648 settings << QString();
650 clipboard->
setText(settings.
join(QLatin1String(
"\n")));
653void AlkOnlineQuotesWidget::Private::slotAddReferenceButton()
655 if (!m_quoteSourceList->currentIndex().isValid())
658 QString newNameBase = m_currentItem.name() +
i18nc(
"@item:valuesuffix to name for a quote source reference",
".reference");
660 QString newName = newNameBase;
661 while(m_profile->quoteSources().
contains(newName)) {
662 newName = QString(
"%1%2").
arg(newNameBase).
arg(index++);
664 AlkOnlineQuoteSource
copy(newName, m_profile);
666 copy.setReferenceName(m_currentItem.name());
668 m_currentItem =
copy;
672void AlkOnlineQuotesWidget::Private::slotNewEntry()
674 const bool newEntries = m_profile->quoteSources().
contains(
i18n(
"New Quote Source"));
676 AlkOnlineQuoteSource newSource(
i18n(
"New Quote Source"), m_profile);
678 m_currentItem = newSource;
682#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
686 i18nc(
"@info Detail that only one new entry can exist at any time",
"<b>New Quote Source</b> already exists."));
694void AlkOnlineQuotesWidget::Private::clearIcons()
696 m_urlCheckLabel->setPixmap(m_emptyIcon);
697 m_dateCheckLabel->setPixmap(m_emptyIcon);
698 m_priceCheckLabel->setPixmap(m_emptyIcon);
699 m_symbolCheckLabel->setPixmap(m_emptyIcon);
700 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
703void AlkOnlineQuotesWidget::Private::initIcons()
705 m_urlCheckLabel->setPixmap(m_inWorkIcon);
706 m_dateCheckLabel->setPixmap(m_inWorkIcon);
707 m_priceCheckLabel->setPixmap(m_inWorkIcon);
708 m_symbolCheckLabel->setPixmap(m_inWorkIcon);
709 m_dateFormatCheckLabel->setPixmap(m_inWorkIcon);
712void AlkOnlineQuotesWidget::Private::setupIcons(
const AlkOnlineQuote::Errors &errors)
715 if (errors & AlkOnlineQuote::Errors::URL) {
716 m_urlCheckLabel->setPixmap(m_failIcon);
718 m_urlCheckLabel->setPixmap(m_okIcon);
719 m_symbolCheckLabel->setPixmap((errors & AlkOnlineQuote::Errors::Symbol) ? m_failIcon : m_okIcon);
720 m_priceCheckLabel->setPixmap((errors & AlkOnlineQuote::Errors::Price) ? m_failIcon : m_okIcon);
721 if (errors & AlkOnlineQuote::Errors::Date) {
722 m_dateCheckLabel->setPixmap(m_failIcon);
724 if (m_currentItem.dateRegex().
isEmpty()) {
725 m_dateCheckLabel->setPixmap(m_emptyIcon);
726 m_dateFormatCheckLabel->setPixmap(m_emptyIcon);
728 m_dateCheckLabel->setPixmap(m_okIcon);
729 m_dateFormatCheckLabel->setPixmap(
730 (errors & AlkOnlineQuote::Errors::DateFormat) ? m_failIcon : m_okIcon);
736void AlkOnlineQuotesWidget::Private::slotCheckEntry()
738 m_quote.setProfile(m_profile);
739 m_logWindow->setVisible(
true);
740 m_logWindow->clear();
747 AlkOnlineQuoteSource source(m_currentItem);
750 if (source.
dataFormat() == AlkOnlineQuoteSource::CSV || source.
dataFormat() == AlkOnlineQuoteSource::JSON) {
751 m_quote.
setDateRange(m_startDateEdit->date(), m_endDateEdit->date());
757 m_quote.
launch(m_checkSymbol2->text(), m_checkSymbol2->text(), source.name());
759 m_quote.
launch(m_checkSymbol->text(), m_checkSymbol->text(), source.name());
761 setupIcons(m_quote.
errors());
764void AlkOnlineQuotesWidget::Private::slotLogStatus(
const QString &s)
766 m_logWindow->append(s);
769void AlkOnlineQuotesWidget::Private::slotLogError(
const QString &s)
771 slotLogStatus(QString(
"<font color=\"red\"><b>") + s + QString(
"</b></font>"));
774void AlkOnlineQuotesWidget::Private::slotLogFailed(
const QString &
id,
const QString &symbol)
776 slotLogStatus(QString(
"%1 %2").arg(
id, symbol));
779void AlkOnlineQuotesWidget::Private::slotLogQuote(
const QString &
id,
const QString &symbol,
780 const QDate &date,
double price)
782 slotLogStatus(QString(
"<font color=\"green\">%1 %2 %3 %4</font>").arg(
id, symbol,
787void AlkOnlineQuotesWidget::Private::slotLogQuotes(
const QString &
id,
const QString &symbol,
788 const AlkDatePriceMap &prices)
790 slotLogStatus(QString(
"<font color=\"green\">%1 %2</font>").arg(
id, symbol));
792 slotLogStatus(QString(
"<font color=\"green\">date price</font>"));
794 slotLogStatus(QString(
"<font color=\"green\">%1 %2</font>")
795 .arg(i.key().toString(
Qt::ISODate)).arg(i.value().toDouble()));
799void AlkOnlineQuotesWidget::Private::slotInstallEntries()
801 QString configFile = m_profile->hotNewStuffConfigFile();
803 AlkNewStuffWidget widget;
804 widget.init(configFile);
805 if (widget.showInstallDialog()) {
811void AlkOnlineQuotesWidget::Private::slotResetQuotesList()
816void AlkOnlineQuotesWidget::Private::slotUploadEntry()
818 QPointer<AlkOnlineQuoteUploadDialog> dialog =
new AlkOnlineQuoteUploadDialog(m_currentItem,
false,
this);
823void AlkOnlineQuotesWidget::Private::slotShowButton()
825 if (!m_webPageDialog) {
826 m_webPageDialog =
new QDialog;
828 QVBoxLayout *
layout =
new QVBoxLayout;
829 layout->addWidget(m_webView);
832 m_webPageDialog->
show();
835QString AlkOnlineQuotesWidget::Private::expandedUrl()
const
837 AlkOnlineQuoteSource source(m_currentItem);
841 return source.url().
arg(m_checkSymbol2->text());
843 return source.url().
arg(m_checkSymbol->text());
847AlkOnlineQuotesWidget::AlkOnlineQuotesWidget(
bool showProfiles,
bool showUpload,
QWidget *
parent)
849 , d(new Private(showProfiles, showUpload, this))
853AlkOnlineQuotesWidget::~AlkOnlineQuotesWidget()
858QWidget *AlkOnlineQuotesWidget::profilesWidget()
860 QFrame *frame =
new QFrame;
861 frame->
setLayout(d->profilesGroupBox->layout());
865QWidget *AlkOnlineQuotesWidget::profileDetailsWidget()
867 QFrame *frame =
new QFrame;
868 frame->
setLayout(d->profileDetailsBox->layout());
872QWidget *AlkOnlineQuotesWidget::onlineQuotesWidget()
874 QFrame *frame =
new QFrame;
875 frame->
setLayout(d->onlineQuotesGroupBox->layout());
879QWidget *AlkOnlineQuotesWidget::quoteDetailsWidget()
881 QFrame *frame =
new QFrame;
882 frame->
setLayout(d->detailsGroupBox->layout());
886QWidget *AlkOnlineQuotesWidget::debugWidget()
888 QFrame *frame =
new QFrame;
889 frame->
setLayout(d->debugGroupBox->layout());
893void AlkOnlineQuotesWidget::readConfig()
897void AlkOnlineQuotesWidget::writeConfig()
901void AlkOnlineQuotesWidget::resetConfig()
904 QStringList groups = d->m_profile->quoteSources();
908 AlkOnlineQuoteSource quoteSource(*it, d->m_profile);
915 if (!quoteSource.isGHNS()) {
916 quoteSource.remove();
921 QList<AlkOnlineQuoteSource>::iterator itr;
922 for (itr = d->m_resetList.begin(); itr != d->m_resetList.end(); ++itr) {
929QString AlkOnlineQuotesWidget::acceptLanguage()
const
931 return d->m_acceptLanguage;
934void AlkOnlineQuotesWidget::setAcceptLanguage(
const QString &text)
936 d->m_acceptLanguage = text;
939bool AlkOnlineQuotesWidget::GHNSSourceEditable()
941 return d->m_ghnsEditable;
945void AlkOnlineQuotesWidget::setGHNSSourceEditable(
bool state)
947 d->m_ghnsEditable = state;
950#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.
void setAcceptLanguage(const QString &language)
Set accepted language the online quote should be returned for.
bool enableReverseLaunch()
Returns the status whether a search with swapped symbols should be performed after a query for a symb...
void setEnableReverseLaunch(bool state)
Set the status whether a search with swapped symbole should be performed after a query for a symbol r...
void setDateRange(const QDate &from, const QDate &to)
Defines a date range within which the data is to be retrieved.
bool launch(const QString &_symbol, const QString &_id, const QString &_source=QString())
This launches a web-based quote update for the given _symbol.
void setReturnLastPriceState(LastPriceState state)
Sets the status of the price to be returned for special date range.
LastPriceState returnLastPriceState()
Returns the status of the price to be returned for special date ranges.
const AlkOnlineQuote::Errors & errors()
If launch() returns false, this method can be used to get details about the errors that occurred.
LastPriceState
Supported values for returning prices in special cases.
@ AlwaysWhenToday
If the date range has the same start and end date, is identical to the current date,...
@ Always
If no price is available in the specified period, but older ones are available, the most current pric...
@ Off
No handling of 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...)
KIOCORE_EXPORT CopyJob * copy(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QString name(const QVariant &location)
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)
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
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)