Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kequitypriceupdatedlg.cpp
Context not available. | |||||
10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | 10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | ||
---|---|---|---|---|---|
11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | 11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | ||
12 | Ace Jones <acejones@users.sourceforge.net> | 12 | Ace Jones <acejones@users.sourceforge.net> | ||
13 | 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | 13 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||
14 | ***************************************************************************/ | 14 | ***************************************************************************/ | ||
15 | 15 | | |||
16 | /*************************************************************************** | 16 | /*************************************************************************** | ||
Context not available. | |||||
30 | #include <QPushButton> | 30 | #include <QPushButton> | ||
31 | #include <QTimer> | 31 | #include <QTimer> | ||
32 | #include <QList> | 32 | #include <QList> | ||
33 | #include <QPointer> | ||||
33 | 34 | | |||
34 | // ---------------------------------------------------------------------------- | 35 | // ---------------------------------------------------------------------------- | ||
35 | // KDE Includes | 36 | // KDE Includes | ||
Context not available. | |||||
46 | // ---------------------------------------------------------------------------- | 47 | // ---------------------------------------------------------------------------- | ||
47 | // Project Includes | 48 | // Project Includes | ||
48 | 49 | | |||
50 | #include "ui_kequitypriceupdatedlg.h" | ||||
51 | | ||||
49 | #include "kmymoney.h" | 52 | #include "kmymoney.h" | ||
50 | #include "mymoneyfile.h" | 53 | #include "mymoneyfile.h" | ||
51 | #include "mymoneyaccount.h" | 54 | #include "mymoneyaccount.h" | ||
52 | #include "mymoneysecurity.h" | 55 | #include "mymoneysecurity.h" | ||
53 | #include "mymoneyprice.h" | 56 | #include "mymoneyprice.h" | ||
57 | #include "webpricequote.h" | ||||
58 | #include "kequitypriceupdateconfdlg.h" | ||||
59 | #include "dialogenums.h" | ||||
54 | 60 | | |||
55 | #define WEBID_COL 0 | 61 | #define WEBID_COL 0 | ||
56 | #define NAME_COL 1 | 62 | #define NAME_COL 1 | ||
Context not available. | |||||
59 | #define KMMID_COL 4 | 65 | #define KMMID_COL 4 | ||
60 | #define SOURCE_COL 5 | 66 | #define SOURCE_COL 5 | ||
61 | 67 | | |||
62 | KEquityPriceUpdateDlg::KEquityPriceUpdateDlg(QWidget *parent, const QString& securityId) : | 68 | class KEquityPriceUpdateDlgPrivate | ||
63 | KEquityPriceUpdateDlgDecl(parent), | | |||
64 | m_fUpdateAll(false) | | |||
65 | { | 69 | { | ||
66 | QStringList headerList; | 70 | Q_DISABLE_COPY(KEquityPriceUpdateDlgPrivate) | ||
67 | headerList << i18n("ID") << i18nc("Equity name", "Name") | 71 | Q_DECLARE_PUBLIC(KEquityPriceUpdateDlg) | ||
68 | << i18n("Price") << i18n("Date"); | 72 | | ||
73 | public: | ||||
74 | KEquityPriceUpdateDlgPrivate(KEquityPriceUpdateDlg *qq) : | ||||
75 | q_ptr(qq), | ||||
76 | ui(new Ui::KEquityPriceUpdateDlg) | ||||
77 | { | ||||
78 | } | ||||
69 | 79 | | |||
70 | lvEquityList->header()->setSortIndicator(0, Qt::AscendingOrder); | 80 | ~KEquityPriceUpdateDlgPrivate() | ||
71 | lvEquityList->setColumnWidth(NAME_COL, 125); | 81 | { | ||
82 | delete ui; | ||||
83 | } | ||||
72 | 84 | | |||
73 | // This is a "get it up and running" hack. Will replace this in the future. | 85 | void init(const QString& securityId) | ||
74 | headerList << i18nc("Internal identifier", "Internal ID") | 86 | { | ||
75 | << i18nc("Online quote source", "Source"); | 87 | Q_Q(KEquityPriceUpdateDlg); | ||
76 | lvEquityList->setColumnWidth(KMMID_COL, 0); | 88 | ui->setupUi(q); | ||
89 | m_fUpdateAll = false; | ||||
90 | QStringList headerList; | ||||
91 | headerList << i18n("ID") << i18nc("Equity name", "Name") | ||||
92 | << i18n("Price") << i18n("Date"); | ||||
77 | 93 | | |||
78 | lvEquityList->setHeaderLabels(headerList); | 94 | ui->lvEquityList->header()->setSortIndicator(0, Qt::AscendingOrder); | ||
95 | ui->lvEquityList->setColumnWidth(NAME_COL, 125); | ||||
79 | 96 | | |||
80 | lvEquityList->setSelectionMode(QAbstractItemView::MultiSelection); | 97 | // This is a "get it up and running" hack. Will replace this in the future. | ||
81 | lvEquityList->setAllColumnsShowFocus(true); | 98 | headerList << i18nc("Internal identifier", "Internal ID") | ||
99 | << i18nc("Online quote source", "Source"); | ||||
100 | ui->lvEquityList->setColumnWidth(KMMID_COL, 0); | ||||
82 | 101 | | |||
83 | btnUpdateAll->setEnabled(false); | 102 | ui->lvEquityList->setHeaderLabels(headerList); | ||
84 | 103 | | |||
85 | MyMoneyFile* file = MyMoneyFile::instance(); | 104 | ui->lvEquityList->setSelectionMode(QAbstractItemView::MultiSelection); | ||
105 | ui->lvEquityList->setAllColumnsShowFocus(true); | ||||
86 | 106 | | |||
87 | // | 107 | ui->btnUpdateAll->setEnabled(false); | ||
88 | // Add each price pair that we know about | | |||
89 | // | | |||
90 | 108 | | |||
91 | // send in securityId == "XXX YYY" to get a single-shot update for XXX to YYY. | 109 | auto file = MyMoneyFile::instance(); | ||
92 | // for consistency reasons, this accepts the same delimiters as WebPriceQuote::launch() | | |||
93 | QRegExp splitrx("([0-9a-z\\.]+)[^a-z0-9]+([0-9a-z\\.]+)", Qt::CaseInsensitive); | | |||
94 | MyMoneySecurityPair currencyIds; | | |||
95 | if (splitrx.indexIn(securityId) != -1) { | | |||
96 | currencyIds = MyMoneySecurityPair(splitrx.cap(1), splitrx.cap(2)); | | |||
97 | } | | |||
98 | 110 | | |||
99 | MyMoneyPriceList prices = file->priceList(); | 111 | // | ||
100 | for (MyMoneyPriceList::ConstIterator it_price = prices.constBegin(); it_price != prices.constEnd(); ++it_price) { | 112 | // Add each price pair that we know about | ||
101 | const MyMoneySecurityPair& pair = it_price.key(); | 113 | // | ||
102 | if (file->security(pair.first).isCurrency() && (securityId.isEmpty() || (pair == currencyIds))) { | | |||
103 | const MyMoneyPriceEntries& entries = (*it_price); | | |||
104 | if (entries.count() > 0 && entries.begin().key() <= QDate::currentDate()) { | | |||
105 | addPricePair(pair); | | |||
106 | btnUpdateAll->setEnabled(true); | | |||
107 | } | | |||
108 | } | | |||
109 | } | | |||
110 | 114 | | |||
111 | // | 115 | // send in securityId == "XXX YYY" to get a single-shot update for XXX to YYY. | ||
112 | // Add each investment | 116 | // for consistency reasons, this accepts the same delimiters as WebPriceQuote::launch() | ||
113 | // | 117 | QRegExp splitrx("([0-9a-z\\.]+)[^a-z0-9]+([0-9a-z\\.]+)", Qt::CaseInsensitive); | ||
114 | 118 | MyMoneySecurityPair currencyIds; | |||
115 | QList<MyMoneySecurity> securities = file->securityList(); | 119 | if (splitrx.indexIn(securityId) != -1) { | ||
116 | for (QList<MyMoneySecurity>::const_iterator it = securities.constBegin(); it != securities.constEnd(); ++it) { | 120 | currencyIds = MyMoneySecurityPair(splitrx.cap(1), splitrx.cap(2)); | ||
117 | if (!(*it).isCurrency() | | |||
118 | && (securityId.isEmpty() || ((*it).id() == securityId)) | | |||
119 | && !(*it).value("kmm-online-source").isEmpty() | | |||
120 | ) { | | |||
121 | addInvestment(*it); | | |||
122 | btnUpdateAll->setEnabled(true); | | |||
123 | } | 121 | } | ||
124 | } | | |||
125 | | ||||
126 | // if list is empty, add the request price pair | | |||
127 | if (lvEquityList->invisibleRootItem()->childCount() == 0) { | | |||
128 | addPricePair(currencyIds, true); | | |||
129 | } | | |||
130 | 122 | | |||
131 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | 123 | MyMoneyPriceList prices = file->priceList(); | ||
132 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | 124 | for (MyMoneyPriceList::ConstIterator it_price = prices.constBegin(); it_price != prices.constEnd(); ++it_price) { | ||
133 | connect(btnUpdateSelected, SIGNAL(clicked()), this, SLOT(slotUpdateSelectedClicked())); | 125 | const MyMoneySecurityPair& pair = it_price.key(); | ||
134 | connect(btnUpdateAll, SIGNAL(clicked()), this, SLOT(slotUpdateAllClicked())); | 126 | if (file->security(pair.first).isCurrency() && (securityId.isEmpty() || (pair == currencyIds))) { | ||
127 | const MyMoneyPriceEntries& entries = (*it_price); | ||||
128 | if (entries.count() > 0 && entries.begin().key() <= QDate::currentDate()) { | ||||
129 | addPricePair(pair, false); | ||||
130 | ui->btnUpdateAll->setEnabled(true); | ||||
131 | } | ||||
132 | } | ||||
133 | } | ||||
135 | 134 | | |||
136 | connect(m_fromDate, SIGNAL(dateChanged(QDate)), this, SLOT(slotDateChanged())); | 135 | // | ||
137 | connect(m_toDate, SIGNAL(dateChanged(QDate)), this, SLOT(slotDateChanged())); | 136 | // Add each investment | ||
137 | // | ||||
138 | | ||||
139 | QList<MyMoneySecurity> securities = file->securityList(); | ||||
140 | for (QList<MyMoneySecurity>::const_iterator it = securities.constBegin(); it != securities.constEnd(); ++it) { | ||||
141 | if (!(*it).isCurrency() | ||||
142 | && (securityId.isEmpty() || ((*it).id() == securityId)) | ||||
143 | && !(*it).value("kmm-online-source").isEmpty() | ||||
144 | ) { | ||||
145 | addInvestment(*it); | ||||
146 | ui->btnUpdateAll->setEnabled(true); | ||||
147 | } | ||||
148 | } | ||||
138 | 149 | | |||
139 | connect(&m_webQuote, &WebPriceQuote::csvquote, | 150 | // if list is empty, add the request price pair | ||
140 | this, &KEquityPriceUpdateDlg::slotReceivedCSVQuote); | 151 | if (ui->lvEquityList->invisibleRootItem()->childCount() == 0) { | ||
141 | connect(&m_webQuote, SIGNAL(quote(QString,QString,QDate,double)), | 152 | addPricePair(currencyIds, true); | ||
142 | this, SLOT(slotReceivedQuote(QString,QString,QDate,double))); | 153 | } | ||
143 | connect(&m_webQuote, SIGNAL(failed(QString,QString)), | | |||
144 | this, SLOT(slotQuoteFailed(QString,QString))); | | |||
145 | connect(&m_webQuote, SIGNAL(status(QString)), | | |||
146 | this, SLOT(logStatusMessage(QString))); | | |||
147 | connect(&m_webQuote, SIGNAL(error(QString)), | | |||
148 | this, SLOT(logErrorMessage(QString))); | | |||
149 | 154 | | |||
150 | connect(lvEquityList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateSelection())); | 155 | q->connect(ui->btnUpdateSelected, &QAbstractButton::clicked, q, &KEquityPriceUpdateDlg::slotUpdateSelectedClicked); | ||
156 | q->connect(ui->btnUpdateAll, &QAbstractButton::clicked, q, &KEquityPriceUpdateDlg::slotUpdateAllClicked); | ||||
151 | 157 | | |||
152 | connect(btnConfigure, &QAbstractButton::clicked, this, &KEquityPriceUpdateDlg::slotConfigureClicked); | 158 | q->connect(ui->m_fromDate, &kMyMoneyDateInput::dateChanged, q, &KEquityPriceUpdateDlg::slotDateChanged); | ||
159 | q->connect(ui->m_toDate, &kMyMoneyDateInput::dateChanged, q, &KEquityPriceUpdateDlg::slotDateChanged); | ||||
153 | 160 | | |||
154 | if (!securityId.isEmpty()) { | 161 | q->connect(&m_webQuote, &WebPriceQuote::csvquote, | ||
155 | btnUpdateSelected->hide(); | 162 | q, &KEquityPriceUpdateDlg::slotReceivedCSVQuote); | ||
156 | btnUpdateAll->hide(); | 163 | q->connect(&m_webQuote, &WebPriceQuote::quote, | ||
157 | // delete layout1; | 164 | q, &KEquityPriceUpdateDlg::slotReceivedQuote); | ||
165 | q->connect(&m_webQuote, &WebPriceQuote::failed, | ||||
166 | q, &KEquityPriceUpdateDlg::slotQuoteFailed); | ||||
167 | q->connect(&m_webQuote, &WebPriceQuote::status, | ||||
168 | q, &KEquityPriceUpdateDlg::logStatusMessage); | ||||
169 | q->connect(&m_webQuote, &WebPriceQuote::error, | ||||
170 | q, &KEquityPriceUpdateDlg::logErrorMessage); | ||||
158 | 171 | | |||
159 | QTimer::singleShot(100, this, SLOT(slotUpdateAllClicked())); | 172 | q->connect(ui->lvEquityList, &QTreeWidget::itemSelectionChanged, q, &KEquityPriceUpdateDlg::slotUpdateSelection); | ||
160 | } | | |||
161 | 173 | | |||
162 | // Hide OK button until we have received the first update | 174 | q->connect(ui->btnConfigure, &QAbstractButton::clicked, q, &KEquityPriceUpdateDlg::slotConfigureClicked); | ||
163 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | | |||
164 | 175 | | |||
165 | slotUpdateSelection(); | 176 | if (!securityId.isEmpty()) { | ||
177 | ui->btnUpdateSelected->hide(); | ||||
178 | ui->btnUpdateAll->hide(); | ||||
179 | // delete layout1; | ||||
166 | 180 | | |||
167 | // previous versions of this dialog allowed to store a "Don't ask again" switch. | 181 | QTimer::singleShot(100, q, SLOT(slotUpdateAllClicked())); | ||
168 | // Since we don't support it anymore, we just get rid of it | 182 | } | ||
169 | KSharedConfigPtr config = KSharedConfig::openConfig(); | | |||
170 | KConfigGroup grp = config->group("Notification Messages"); | | |||
171 | grp.deleteEntry("KEquityPriceUpdateDlg::slotQuoteFailed::Price Update Failed"); | | |||
172 | grp.sync(); | | |||
173 | grp = config->group("Equity Price Update"); | | |||
174 | int policyValue = grp.readEntry("PriceUpdatingPolicy", QString().setNum(eUpdateMissingPrices)).toInt(); | | |||
175 | if (policyValue >= eUpdatingPricePolicyEnd || policyValue < eUpdateAllPrices) | | |||
176 | m_updatingPricePolicy = eUpdateMissingPrices; | | |||
177 | else | | |||
178 | m_updatingPricePolicy = static_cast<updatingPricePolicyE>(policyValue); | | |||
179 | } | | |||
180 | 183 | | |||
181 | KEquityPriceUpdateDlg::~KEquityPriceUpdateDlg() | 184 | // Hide OK button until we have received the first update | ||
182 | { | 185 | ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||
183 | KSharedConfigPtr config = KSharedConfig::openConfig(); | 186 | | ||
184 | KConfigGroup grp = config->group("Equity Price Update"); | 187 | q->slotUpdateSelection(); | ||
185 | grp.writeEntry("PriceUpdatingPolicy", static_cast<int>(m_updatingPricePolicy)); | 188 | | ||
186 | grp.sync(); | 189 | // previous versions of this dialog allowed to store a "Don't ask again" switch. | ||
187 | } | 190 | // Since we don't support it anymore, we just get rid of it | ||
191 | KSharedConfigPtr config = KSharedConfig::openConfig(); | ||||
192 | KConfigGroup grp = config->group("Notification Messages"); | ||||
193 | grp.deleteEntry("KEquityPriceUpdateDlg::slotQuoteFailed::Price Update Failed"); | ||||
194 | grp.sync(); | ||||
195 | grp = config->group("Equity Price Update"); | ||||
196 | int policyValue = grp.readEntry("PriceUpdatingPolicy", (int)eDialogs::UpdatePrice::Missing); | ||||
197 | if (policyValue > (int)eDialogs::UpdatePrice::Ask || policyValue < (int)eDialogs::UpdatePrice::All) | ||||
198 | m_updatingPricePolicy = eDialogs::UpdatePrice::Missing; | ||||
199 | else | ||||
200 | m_updatingPricePolicy = static_cast<eDialogs::UpdatePrice>(policyValue); | ||||
201 | } | ||||
188 | 202 | | |||
189 | void KEquityPriceUpdateDlg::addPricePair(const MyMoneySecurityPair& pair, bool dontCheckExistance) | 203 | void addPricePair(const MyMoneySecurityPair& pair, bool dontCheckExistance) | ||
190 | { | 204 | { | ||
191 | MyMoneyFile* file = MyMoneyFile::instance(); | 205 | auto file = MyMoneyFile::instance(); | ||
192 | 206 | | |||
193 | const QString symbol = QString::fromLatin1("%1 > %2").arg(pair.first, pair.second); | 207 | const auto symbol = QString::fromLatin1("%1 > %2").arg(pair.first, pair.second); | ||
194 | const QString id = QString::fromLatin1("%1 %2").arg(pair.first, pair.second); | 208 | const auto id = QString::fromLatin1("%1 %2").arg(pair.first, pair.second); | ||
195 | // Check that the pair does not already exist | 209 | // Check that the pair does not already exist | ||
196 | if (lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL).empty()) { | 210 | if (ui->lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL).empty()) { | ||
197 | const MyMoneyPrice &pr = file->price(pair.first, pair.second); | 211 | const MyMoneyPrice &pr = file->price(pair.first, pair.second); | ||
198 | if (pr.source() != QLatin1String("KMyMoney")) { | 212 | if (pr.source() != QLatin1String("KMyMoney")) { | ||
199 | bool keep = true; | 213 | bool keep = true; | ||
200 | if ((pair.first == file->baseCurrency().id()) | 214 | if ((pair.first == file->baseCurrency().id()) | ||
201 | || (pair.second == file->baseCurrency().id())) { | 215 | || (pair.second == file->baseCurrency().id())) { | ||
202 | const QString& foreignCurrency = file->foreignCurrency(pair.first, pair.second); | 216 | const QString& foreignCurrency = file->foreignCurrency(pair.first, pair.second); | ||
203 | // check that the foreign currency is still in use | 217 | // check that the foreign currency is still in use | ||
204 | QList<MyMoneyAccount>::const_iterator it_a; | 218 | QList<MyMoneyAccount>::const_iterator it_a; | ||
205 | QList<MyMoneyAccount> list; | 219 | QList<MyMoneyAccount> list; | ||
206 | file->accountList(list); | 220 | file->accountList(list); | ||
207 | for (it_a = list.constBegin(); !dontCheckExistance && it_a != list.constEnd(); ++it_a) { | 221 | for (it_a = list.constBegin(); !dontCheckExistance && it_a != list.constEnd(); ++it_a) { | ||
208 | // if it's an account denominated in the foreign currency | 222 | // if it's an account denominated in the foreign currency | ||
209 | // keep it | 223 | // keep it | ||
210 | if (((*it_a).currencyId() == foreignCurrency) | 224 | if (((*it_a).currencyId() == foreignCurrency) | ||
211 | && !(*it_a).isClosed()) | 225 | && !(*it_a).isClosed()) | ||
212 | break; | | |||
213 | // if it's an investment traded in the foreign currency | | |||
214 | // keep it | | |||
215 | if ((*it_a).isInvest() && !(*it_a).isClosed()) { | | |||
216 | MyMoneySecurity sec = file->security((*it_a).currencyId()); | | |||
217 | if (sec.tradingCurrency() == foreignCurrency) | | |||
218 | break; | 226 | break; | ||
227 | // if it's an investment traded in the foreign currency | ||||
228 | // keep it | ||||
229 | if ((*it_a).isInvest() && !(*it_a).isClosed()) { | ||||
230 | MyMoneySecurity sec = file->security((*it_a).currencyId()); | ||||
231 | if (sec.tradingCurrency() == foreignCurrency) | ||||
232 | break; | ||||
233 | } | ||||
234 | } | ||||
235 | // if it is in use, it_a is not equal to list.end() | ||||
236 | if (it_a == list.constEnd() && !dontCheckExistance) | ||||
237 | keep = false; | ||||
238 | } | ||||
239 | | ||||
240 | if (keep) { | ||||
241 | auto item = new QTreeWidgetItem(); | ||||
242 | item->setText(WEBID_COL, symbol); | ||||
243 | item->setText(NAME_COL, i18n("%1 units in %2", pair.first, pair.second)); | ||||
244 | if (pr.isValid()) { | ||||
245 | MyMoneySecurity fromCurrency = file->currency(pair.second); | ||||
246 | MyMoneySecurity toCurrency = file->currency(pair.first); | ||||
247 | item->setText(PRICE_COL, pr.rate(pair.second).formatMoney(fromCurrency.tradingSymbol(), toCurrency.pricePrecision())); | ||||
248 | item->setText(DATE_COL, pr.date().toString(Qt::ISODate)); | ||||
219 | } | 249 | } | ||
250 | item->setText(KMMID_COL, id); | ||||
251 | item->setText(SOURCE_COL, "Yahoo Currency"); // This string value should not be localized | ||||
252 | ui->lvEquityList->invisibleRootItem()->addChild(item); | ||||
220 | } | 253 | } | ||
221 | // if it is in use, it_a is not equal to list.end() | | |||
222 | if (it_a == list.constEnd() && !dontCheckExistance) | | |||
223 | keep = false; | | |||
224 | } | 254 | } | ||
255 | } | ||||
256 | } | ||||
257 | | ||||
258 | void addInvestment(const MyMoneySecurity& inv) | ||||
259 | { | ||||
260 | const auto id = inv.id(); | ||||
261 | // Check that the pair does not already exist | ||||
262 | if (ui->lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL).empty()) { | ||||
263 | auto file = MyMoneyFile::instance(); | ||||
264 | // check that the security is still in use | ||||
265 | QList<MyMoneyAccount>::const_iterator it_a; | ||||
266 | QList<MyMoneyAccount> list; | ||||
267 | file->accountList(list); | ||||
268 | for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { | ||||
269 | if ((*it_a).isInvest() | ||||
270 | && ((*it_a).currencyId() == inv.id()) | ||||
271 | && !(*it_a).isClosed()) | ||||
272 | break; | ||||
273 | } | ||||
274 | // if it is in use, it_a is not equal to list.end() | ||||
275 | if (it_a != list.constEnd()) { | ||||
276 | QString webID; | ||||
277 | WebPriceQuoteSource onlineSource(inv.value("kmm-online-source")); | ||||
278 | if (onlineSource.m_webIDBy == WebPriceQuoteSource::identifyBy::IdentificationNumber) | ||||
279 | webID = inv.value("kmm-security-id"); // insert ISIN number... | ||||
280 | else if (onlineSource.m_webIDBy == WebPriceQuoteSource::identifyBy::Name) | ||||
281 | webID = inv.name(); // ...or name... | ||||
282 | else | ||||
283 | webID = inv.tradingSymbol(); // ...or symbol | ||||
225 | 284 | | |||
226 | if (keep) { | | |||
227 | QTreeWidgetItem* item = new QTreeWidgetItem(); | 285 | QTreeWidgetItem* item = new QTreeWidgetItem(); | ||
228 | item->setText(WEBID_COL, symbol); | 286 | item->setForeground(WEBID_COL, KColorScheme(QPalette::Normal).foreground(KColorScheme::NormalText)); | ||
229 | item->setText(NAME_COL, i18n("%1 units in %2", pair.first, pair.second)); | 287 | if (webID.isEmpty()) { | ||
288 | webID = i18n("[No identifier]"); | ||||
289 | item->setForeground(WEBID_COL, KColorScheme(QPalette::Normal).foreground(KColorScheme::NegativeText)); | ||||
290 | } | ||||
291 | item->setText(WEBID_COL, webID); | ||||
292 | item->setText(NAME_COL, inv.name()); | ||||
293 | MyMoneySecurity currency = file->currency(inv.tradingCurrency()); | ||||
294 | const MyMoneyPrice &pr = file->price(id.toUtf8(), inv.tradingCurrency()); | ||||
230 | if (pr.isValid()) { | 295 | if (pr.isValid()) { | ||
231 | MyMoneySecurity fromCurrency = file->currency(pair.second); | 296 | item->setText(PRICE_COL, pr.rate(currency.id()).formatMoney(currency.tradingSymbol(), inv.pricePrecision())); | ||
232 | MyMoneySecurity toCurrency = file->currency(pair.first); | | |||
233 | item->setText(PRICE_COL, pr.rate(pair.second).formatMoney(fromCurrency.tradingSymbol(), toCurrency.pricePrecision())); | | |||
234 | item->setText(DATE_COL, pr.date().toString(Qt::ISODate)); | 297 | item->setText(DATE_COL, pr.date().toString(Qt::ISODate)); | ||
235 | } | 298 | } | ||
236 | item->setText(KMMID_COL, id); | 299 | item->setText(KMMID_COL, id); | ||
237 | item->setText(SOURCE_COL, "Yahoo Currency"); // This string value should not be localized | 300 | if (inv.value("kmm-online-quote-system") == "Finance::Quote") | ||
238 | lvEquityList->invisibleRootItem()->addChild(item); | 301 | item->setText(SOURCE_COL, QString("Finance::Quote %1").arg(inv.value("kmm-online-source"))); | ||
302 | else | ||||
303 | item->setText(SOURCE_COL, inv.value("kmm-online-source")); | ||||
304 | | ||||
305 | ui->lvEquityList->invisibleRootItem()->addChild(item); | ||||
306 | | ||||
307 | // If this investment is denominated in a foreign currency, ensure that | ||||
308 | // the appropriate price pair is also on the list | ||||
309 | | ||||
310 | if (currency.id() != file->baseCurrency().id()) { | ||||
311 | addPricePair(MyMoneySecurityPair(currency.id(), file->baseCurrency().id()), false); | ||||
312 | } | ||||
239 | } | 313 | } | ||
240 | } | 314 | } | ||
241 | } | 315 | } | ||
242 | } | | |||
243 | | ||||
244 | void KEquityPriceUpdateDlg::addInvestment(const MyMoneySecurity& inv) | | |||
245 | { | | |||
246 | const QString id = inv.id(); | | |||
247 | // Check that the pair does not already exist | | |||
248 | if (lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL).empty()) { | | |||
249 | MyMoneyFile* file = MyMoneyFile::instance(); | | |||
250 | // check that the security is still in use | | |||
251 | QList<MyMoneyAccount>::const_iterator it_a; | | |||
252 | QList<MyMoneyAccount> list; | | |||
253 | file->accountList(list); | | |||
254 | for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { | | |||
255 | if ((*it_a).isInvest() | | |||
256 | && ((*it_a).currencyId() == inv.id()) | | |||
257 | && !(*it_a).isClosed()) | | |||
258 | break; | | |||
259 | } | | |||
260 | // if it is in use, it_a is not equal to list.end() | | |||
261 | if (it_a != list.constEnd()) { | | |||
262 | QString webID; | | |||
263 | WebPriceQuoteSource onlineSource(inv.value("kmm-online-source")); | | |||
264 | if (onlineSource.m_webIDBy == WebPriceQuoteSource::identifyBy::IdentificationNumber) | | |||
265 | webID = inv.value("kmm-security-id"); // insert ISIN number... | | |||
266 | else if (onlineSource.m_webIDBy == WebPriceQuoteSource::identifyBy::Name) | | |||
267 | webID = inv.name(); // ...or name... | | |||
268 | else | | |||
269 | webID = inv.tradingSymbol(); // ...or symbol | | |||
270 | 316 | | |||
271 | QTreeWidgetItem* item = new QTreeWidgetItem(); | 317 | KEquityPriceUpdateDlg *q_ptr; | ||
272 | item->setForeground(WEBID_COL, KColorScheme(QPalette::Normal).foreground(KColorScheme::NormalText)); | 318 | Ui::KEquityPriceUpdateDlg *ui; | ||
273 | if (webID.isEmpty()) { | 319 | bool m_fUpdateAll; | ||
274 | webID = i18n("[No identifier]"); | 320 | eDialogs::UpdatePrice m_updatingPricePolicy; | ||
275 | item->setForeground(WEBID_COL, KColorScheme(QPalette::Normal).foreground(KColorScheme::NegativeText)); | 321 | WebPriceQuote m_webQuote; | ||
276 | } | 322 | }; | ||
277 | item->setText(WEBID_COL, webID); | | |||
278 | item->setText(NAME_COL, inv.name()); | | |||
279 | MyMoneySecurity currency = file->currency(inv.tradingCurrency()); | | |||
280 | const MyMoneyPrice &pr = file->price(id.toUtf8(), inv.tradingCurrency()); | | |||
281 | if (pr.isValid()) { | | |||
282 | item->setText(PRICE_COL, pr.rate(currency.id()).formatMoney(currency.tradingSymbol(), inv.pricePrecision())); | | |||
283 | item->setText(DATE_COL, pr.date().toString(Qt::ISODate)); | | |||
284 | } | | |||
285 | item->setText(KMMID_COL, id); | | |||
286 | if (inv.value("kmm-online-quote-system") == "Finance::Quote") | | |||
287 | item->setText(SOURCE_COL, QString("Finance::Quote %1").arg(inv.value("kmm-online-source"))); | | |||
288 | else | | |||
289 | item->setText(SOURCE_COL, inv.value("kmm-online-source")); | | |||
290 | 323 | | |||
291 | lvEquityList->invisibleRootItem()->addChild(item); | 324 | KEquityPriceUpdateDlg::KEquityPriceUpdateDlg(QWidget *parent, const QString& securityId) : | ||
325 | QDialog(parent), | ||||
326 | d_ptr(new KEquityPriceUpdateDlgPrivate(this)) | ||||
327 | { | ||||
328 | Q_D(KEquityPriceUpdateDlg); | ||||
329 | d->init(securityId); | ||||
330 | } | ||||
292 | 331 | | |||
293 | // If this investment is denominated in a foreign currency, ensure that | 332 | KEquityPriceUpdateDlg::KEquityPriceUpdateDlg(QWidget *parent) : | ||
294 | // the appropriate price pair is also on the list | 333 | KEquityPriceUpdateDlg(parent, QString()) | ||
334 | { | ||||
335 | } | ||||
295 | 336 | | |||
296 | if (currency.id() != file->baseCurrency().id()) { | 337 | KEquityPriceUpdateDlg::~KEquityPriceUpdateDlg() | ||
297 | addPricePair(MyMoneySecurityPair(currency.id(), file->baseCurrency().id())); | 338 | { | ||
298 | } | 339 | Q_D(KEquityPriceUpdateDlg); | ||
299 | } | 340 | auto config = KSharedConfig::openConfig(); | ||
300 | } | 341 | auto grp = config->group("Equity Price Update"); | ||
342 | grp.writeEntry("PriceUpdatingPolicy", static_cast<int>(d->m_updatingPricePolicy)); | ||||
343 | grp.sync(); | ||||
344 | delete d; | ||||
301 | } | 345 | } | ||
302 | 346 | | |||
303 | void KEquityPriceUpdateDlg::logErrorMessage(const QString& message) | 347 | void KEquityPriceUpdateDlg::logErrorMessage(const QString& message) | ||
Context not available. | |||||
307 | 351 | | |||
308 | void KEquityPriceUpdateDlg::logStatusMessage(const QString& message) | 352 | void KEquityPriceUpdateDlg::logStatusMessage(const QString& message) | ||
309 | { | 353 | { | ||
310 | lbStatus->append(message); | 354 | Q_D(KEquityPriceUpdateDlg); | ||
355 | d->ui->lbStatus->append(message); | ||||
311 | } | 356 | } | ||
312 | 357 | | |||
313 | MyMoneyPrice KEquityPriceUpdateDlg::price(const QString& id) const | 358 | MyMoneyPrice KEquityPriceUpdateDlg::price(const QString& id) const | ||
314 | { | 359 | { | ||
360 | Q_D(const KEquityPriceUpdateDlg); | ||||
315 | MyMoneyPrice price; | 361 | MyMoneyPrice price; | ||
316 | QTreeWidgetItem* item = 0; | 362 | QTreeWidgetItem* item = nullptr; | ||
317 | QList<QTreeWidgetItem*> foundItems = lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL); | 363 | QList<QTreeWidgetItem*> foundItems = d->ui->lvEquityList->findItems(id, Qt::MatchExactly, KMMID_COL); | ||
318 | 364 | | |||
319 | if (! foundItems.empty()) | 365 | if (! foundItems.empty()) | ||
320 | item = foundItems.at(0); | 366 | item = foundItems.at(0); | ||
Context not available. | |||||
343 | 389 | | |||
344 | void KEquityPriceUpdateDlg::storePrices() | 390 | void KEquityPriceUpdateDlg::storePrices() | ||
345 | { | 391 | { | ||
392 | Q_D(KEquityPriceUpdateDlg); | ||||
346 | // update the new prices into the equities | 393 | // update the new prices into the equities | ||
347 | 394 | | |||
348 | MyMoneyFile* file = MyMoneyFile::instance(); | 395 | auto file = MyMoneyFile::instance(); | ||
349 | QString name; | 396 | QString name; | ||
350 | 397 | | |||
351 | MyMoneyFileTransaction ft; | 398 | MyMoneyFileTransaction ft; | ||
352 | try { | 399 | try { | ||
353 | for (int i = 0; i < lvEquityList->invisibleRootItem()->childCount(); ++i) { | 400 | for (auto i = 0; i < d->ui->lvEquityList->invisibleRootItem()->childCount(); ++i) { | ||
354 | QTreeWidgetItem* item = lvEquityList->invisibleRootItem()->child(i); | 401 | QTreeWidgetItem* item = d->ui->lvEquityList->invisibleRootItem()->child(i); | ||
355 | // turn on signals before we modify the last entry in the list | 402 | // turn on signals before we modify the last entry in the list | ||
356 | file->blockSignals(i < lvEquityList->invisibleRootItem()->childCount() - 1); | 403 | file->blockSignals(i < d->ui->lvEquityList->invisibleRootItem()->childCount() - 1); | ||
357 | 404 | | |||
358 | MyMoneyMoney rate(item->text(PRICE_COL)); | 405 | MyMoneyMoney rate(item->text(PRICE_COL)); | ||
359 | if (!rate.isZero()) { | 406 | if (!rate.isZero()) { | ||
Context not available. | |||||
388 | 435 | | |||
389 | void KEquityPriceUpdateDlg::slotConfigureClicked() | 436 | void KEquityPriceUpdateDlg::slotConfigureClicked() | ||
390 | { | 437 | { | ||
391 | EquityPriceUpdateConfDlg *dlg = new EquityPriceUpdateConfDlg(m_updatingPricePolicy); | 438 | Q_D(KEquityPriceUpdateDlg); | ||
439 | QPointer<EquityPriceUpdateConfDlg> dlg = new EquityPriceUpdateConfDlg(d->m_updatingPricePolicy); | ||||
392 | if (dlg->exec() == QDialog::Accepted) | 440 | if (dlg->exec() == QDialog::Accepted) | ||
393 | m_updatingPricePolicy = dlg->policy(); | 441 | d->m_updatingPricePolicy = dlg->policy(); | ||
394 | delete dlg; | 442 | delete dlg; | ||
395 | } | 443 | } | ||
396 | 444 | | |||
397 | void KEquityPriceUpdateDlg::slotUpdateSelection() | 445 | void KEquityPriceUpdateDlg::slotUpdateSelection() | ||
398 | { | 446 | { | ||
447 | Q_D(KEquityPriceUpdateDlg); | ||||
399 | // Only enable the update button if there is a selection | 448 | // Only enable the update button if there is a selection | ||
400 | btnUpdateSelected->setEnabled(false); | 449 | d->ui->btnUpdateSelected->setEnabled(false); | ||
401 | 450 | | |||
402 | if (! lvEquityList->selectedItems().empty()) | 451 | if (! d->ui->lvEquityList->selectedItems().empty()) | ||
403 | btnUpdateSelected->setEnabled(true); | 452 | d->ui->btnUpdateSelected->setEnabled(true); | ||
404 | } | 453 | } | ||
405 | 454 | | |||
406 | void KEquityPriceUpdateDlg::slotUpdateSelectedClicked() | 455 | void KEquityPriceUpdateDlg::slotUpdateSelectedClicked() | ||
407 | { | 456 | { | ||
457 | Q_D(KEquityPriceUpdateDlg); | ||||
408 | // disable sorting while the update is running to maintain the current order of items on which | 458 | // disable sorting while the update is running to maintain the current order of items on which | ||
409 | // the update process depends and which could be changed with sorting enabled due to the updated values | 459 | // the update process depends and which could be changed with sorting enabled due to the updated values | ||
410 | lvEquityList->setSortingEnabled(false); | 460 | d->ui->lvEquityList->setSortingEnabled(false); | ||
411 | QTreeWidgetItem* item = lvEquityList->invisibleRootItem()->child(0); | 461 | auto item = d->ui->lvEquityList->invisibleRootItem()->child(0); | ||
412 | int skipCnt = 1; | 462 | auto skipCnt = 1; | ||
413 | while (item && !item->isSelected()) { | 463 | while (item && !item->isSelected()) { | ||
414 | item = lvEquityList->invisibleRootItem()->child(skipCnt); | 464 | item = d->ui->lvEquityList->invisibleRootItem()->child(skipCnt); | ||
415 | ++skipCnt; | 465 | ++skipCnt; | ||
416 | } | 466 | } | ||
417 | m_webQuote.setDate(m_fromDate->date(), m_toDate->date()); | 467 | d->m_webQuote.setDate(d->ui->m_fromDate->date(), d->ui->m_toDate->date()); | ||
418 | if (item) { | 468 | if (item) { | ||
419 | prgOnlineProgress->setMaximum(1 + lvEquityList->invisibleRootItem()->childCount()); | 469 | d->ui->prgOnlineProgress->setMaximum(1 + d->ui->lvEquityList->invisibleRootItem()->childCount()); | ||
420 | prgOnlineProgress->setValue(skipCnt); | 470 | d->ui->prgOnlineProgress->setValue(skipCnt); | ||
421 | m_webQuote.launch(item->text(WEBID_COL), item->text(KMMID_COL), item->text(SOURCE_COL)); | 471 | d->m_webQuote.launch(item->text(WEBID_COL), item->text(KMMID_COL), item->text(SOURCE_COL)); | ||
422 | 472 | | |||
423 | } else { | 473 | } else { | ||
424 | 474 | | |||
Context not available. | |||||
428 | 478 | | |||
429 | void KEquityPriceUpdateDlg::slotUpdateAllClicked() | 479 | void KEquityPriceUpdateDlg::slotUpdateAllClicked() | ||
430 | { | 480 | { | ||
481 | Q_D(KEquityPriceUpdateDlg); | ||||
431 | // disable sorting while the update is running to maintain the current order of items on which | 482 | // disable sorting while the update is running to maintain the current order of items on which | ||
432 | // the update process depends and which could be changed with sorting enabled due to the updated values | 483 | // the update process depends and which could be changed with sorting enabled due to the updated values | ||
433 | lvEquityList->setSortingEnabled(false); | 484 | d->ui->lvEquityList->setSortingEnabled(false); | ||
434 | QTreeWidgetItem* item = lvEquityList->invisibleRootItem()->child(0); | 485 | QTreeWidgetItem* item = d->ui->lvEquityList->invisibleRootItem()->child(0); | ||
435 | if (item) { | 486 | if (item) { | ||
436 | prgOnlineProgress->setMaximum(1 + lvEquityList->invisibleRootItem()->childCount()); | 487 | d->ui->prgOnlineProgress->setMaximum(1 + d->ui->lvEquityList->invisibleRootItem()->childCount()); | ||
437 | prgOnlineProgress->setValue(1); | 488 | d->ui->prgOnlineProgress->setValue(1); | ||
438 | m_fUpdateAll = true; | 489 | d->m_fUpdateAll = true; | ||
439 | m_webQuote.launch(item->text(WEBID_COL), item->text(KMMID_COL), item->text(SOURCE_COL)); | 490 | d->m_webQuote.launch(item->text(WEBID_COL), item->text(KMMID_COL), item->text(SOURCE_COL)); | ||
440 | 491 | | |||
441 | } else { | 492 | } else { | ||
442 | logErrorMessage("Security list is empty."); | 493 | logErrorMessage("Security list is empty."); | ||
Context not available. | |||||
445 | 496 | | |||
446 | void KEquityPriceUpdateDlg::slotDateChanged() | 497 | void KEquityPriceUpdateDlg::slotDateChanged() | ||
447 | { | 498 | { | ||
448 | m_fromDate->blockSignals(true); | 499 | Q_D(KEquityPriceUpdateDlg); | ||
449 | m_toDate->blockSignals(true); | 500 | d->ui->m_fromDate->blockSignals(true); | ||
450 | if (m_toDate->date() > QDate::currentDate()) | 501 | d->ui->m_toDate->blockSignals(true); | ||
451 | m_toDate->setDate(QDate::currentDate()); | 502 | if (d->ui->m_toDate->date() > QDate::currentDate()) | ||
452 | if (m_toDate->date() < m_fromDate->date()) | 503 | d->ui->m_toDate->setDate(QDate::currentDate()); | ||
453 | m_fromDate->setDate(m_toDate->date()); | 504 | if (d->ui->m_toDate->date() < d->ui->m_fromDate->date()) | ||
454 | m_fromDate->blockSignals(false); | 505 | d->ui->m_fromDate->setDate(d->ui->m_toDate->date()); | ||
455 | m_toDate->blockSignals(false); | 506 | d->ui->m_fromDate->blockSignals(false); | ||
507 | d->ui->m_toDate->blockSignals(false); | ||||
456 | } | 508 | } | ||
457 | 509 | | |||
458 | void KEquityPriceUpdateDlg::slotQuoteFailed(const QString& _kmmID, const QString& _webID) | 510 | void KEquityPriceUpdateDlg::slotQuoteFailed(const QString& _kmmID, const QString& _webID) | ||
459 | { | 511 | { | ||
460 | QList<QTreeWidgetItem*> foundItems = lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | 512 | Q_D(KEquityPriceUpdateDlg); | ||
461 | QTreeWidgetItem* item = 0; | 513 | auto foundItems = d->ui->lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | ||
514 | QTreeWidgetItem* item = nullptr; | ||||
462 | 515 | | |||
463 | if (! foundItems.empty()) | 516 | if (! foundItems.empty()) | ||
464 | item = foundItems.at(0); | 517 | item = foundItems.at(0); | ||
Context not available. | |||||
493 | 546 | | |||
494 | // As long as the user doesn't want to cancel, move on! | 547 | // As long as the user doesn't want to cancel, move on! | ||
495 | if (result != KMessageBox::Cancel) { | 548 | if (result != KMessageBox::Cancel) { | ||
496 | QTreeWidgetItem* next = 0; | 549 | QTreeWidgetItem* next = nullptr; | ||
497 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 550 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
498 | item->setSelected(false); | 551 | item->setSelected(false); | ||
499 | 552 | | |||
500 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | 553 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | ||
501 | // need to parse the list to find the next selected one | 554 | // need to parse the list to find the next selected one | ||
502 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | 555 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | ||
503 | if (!m_fUpdateAll) { | 556 | if (!d->m_fUpdateAll) { | ||
504 | while (next && !next->isSelected()) { | 557 | while (next && !next->isSelected()) { | ||
505 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 558 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
506 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | 559 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | ||
507 | } | 560 | } | ||
508 | } | 561 | } | ||
509 | if (next) { | 562 | if (next) { | ||
510 | m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | 563 | d->m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | ||
511 | } else { | 564 | } else { | ||
512 | finishUpdate(); | 565 | finishUpdate(); | ||
513 | } | 566 | } | ||
Context not available. | |||||
518 | 571 | | |||
519 | void KEquityPriceUpdateDlg::slotReceivedCSVQuote(const QString& _kmmID, const QString& _webID, MyMoneyStatement& st) | 572 | void KEquityPriceUpdateDlg::slotReceivedCSVQuote(const QString& _kmmID, const QString& _webID, MyMoneyStatement& st) | ||
520 | { | 573 | { | ||
521 | QList<QTreeWidgetItem*> foundItems = lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | 574 | Q_D(KEquityPriceUpdateDlg); | ||
522 | QTreeWidgetItem* item = 0; | 575 | auto foundItems = d->ui->lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | ||
576 | QTreeWidgetItem* item = nullptr; | ||||
523 | 577 | | |||
524 | if (! foundItems.empty()) | 578 | if (! foundItems.empty()) | ||
525 | item = foundItems.at(0); | 579 | item = foundItems.at(0); | ||
526 | 580 | | |||
527 | QTreeWidgetItem* next = 0; | 581 | QTreeWidgetItem* next = nullptr; | ||
528 | 582 | | |||
529 | if (item) { | 583 | if (item) { | ||
530 | MyMoneyFile *file = MyMoneyFile::instance(); | 584 | auto file = MyMoneyFile::instance(); | ||
531 | MyMoneySecurity fromCurrency, toCurrency; | 585 | MyMoneySecurity fromCurrency, toCurrency; | ||
532 | 586 | | |||
533 | if (!_kmmID.contains(QLatin1Char(' '))) { | 587 | if (!_kmmID.contains(QLatin1Char(' '))) { | ||
Context not available. | |||||
550 | } | 604 | } | ||
551 | } | 605 | } | ||
552 | 606 | | |||
553 | if (m_updatingPricePolicy != eUpdateAllPrices) { | 607 | if (d->m_updatingPricePolicy != eDialogs::UpdatePrice::All) { | ||
554 | QStringList qSources = WebPriceQuote::quoteSources(); | 608 | QStringList qSources = WebPriceQuote::quoteSources(); | ||
555 | for (auto it = st.m_listPrices.begin(); it != st.m_listPrices.end();) { | 609 | for (auto it = st.m_listPrices.begin(); it != st.m_listPrices.end();) { | ||
556 | MyMoneyPrice storedPrice = file->price(toCurrency.id(), fromCurrency.id(), (*it).m_date, true); | 610 | MyMoneyPrice storedPrice = file->price(toCurrency.id(), fromCurrency.id(), (*it).m_date, true); | ||
Context not available. | |||||
558 | if (!priceValid) | 612 | if (!priceValid) | ||
559 | ++it; | 613 | ++it; | ||
560 | else { | 614 | else { | ||
561 | switch(m_updatingPricePolicy) { | 615 | switch(d->m_updatingPricePolicy) { | ||
562 | case eUpdateMissingPrices: | 616 | case eDialogs::UpdatePrice::Missing: | ||
563 | it = st.m_listPrices.erase(it); | 617 | it = st.m_listPrices.erase(it); | ||
564 | break; | 618 | break; | ||
565 | case eUpdateDownloadedPrices: | 619 | case eDialogs::UpdatePrice::Downloaded: | ||
566 | if (!qSources.contains(storedPrice.source())) | 620 | if (!qSources.contains(storedPrice.source())) | ||
567 | it = st.m_listPrices.erase(it); | 621 | it = st.m_listPrices.erase(it); | ||
568 | else | 622 | else | ||
569 | ++it; | 623 | ++it; | ||
570 | break; | 624 | break; | ||
571 | case eUpdateSameSourcePrices: | 625 | case eDialogs::UpdatePrice::SameSource: | ||
572 | if (storedPrice.source().compare((*it).m_sourceName) != 0) | 626 | if (storedPrice.source().compare((*it).m_sourceName) != 0) | ||
573 | it = st.m_listPrices.erase(it); | 627 | it = st.m_listPrices.erase(it); | ||
574 | else | 628 | else | ||
575 | ++it; | 629 | ++it; | ||
576 | break; | 630 | break; | ||
577 | case eAsk: | 631 | case eDialogs::UpdatePrice::Ask: | ||
578 | { | 632 | { | ||
579 | int result = KMessageBox::questionYesNoCancel(this, | 633 | int result = KMessageBox::questionYesNoCancel(this, | ||
580 | i18n("For <b>%1</b> on <b>%2</b> price <b>%3</b> already exists.<br>" | 634 | i18n("For <b>%1</b> on <b>%2</b> price <b>%3</b> already exists.<br>" | ||
Context not available. | |||||
624 | logStatusMessage(i18n("Price for %1 updated (id %2)", _webID, _kmmID)); | 678 | logStatusMessage(i18n("Price for %1 updated (id %2)", _webID, _kmmID)); | ||
625 | // make sure to make OK button available | 679 | // make sure to make OK button available | ||
626 | } | 680 | } | ||
627 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | 681 | d->ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | ||
628 | 682 | | |||
629 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 683 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
630 | item->setSelected(false); | 684 | item->setSelected(false); | ||
631 | 685 | | |||
632 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | 686 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | ||
633 | // need to parse the list to find the next selected one | 687 | // need to parse the list to find the next selected one | ||
634 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | 688 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | ||
635 | if (!m_fUpdateAll) { | 689 | if (!d->m_fUpdateAll) { | ||
636 | while (next && !next->isSelected()) { | 690 | while (next && !next->isSelected()) { | ||
637 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 691 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
638 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | 692 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | ||
639 | } | 693 | } | ||
640 | } | 694 | } | ||
641 | } else { | 695 | } else { | ||
Context not available. | |||||
643 | } | 697 | } | ||
644 | 698 | | |||
645 | if (next) { | 699 | if (next) { | ||
646 | m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | 700 | d->m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | ||
647 | } else { | 701 | } else { | ||
648 | finishUpdate(); | 702 | finishUpdate(); | ||
649 | } | 703 | } | ||
Context not available. | |||||
651 | 705 | | |||
652 | void KEquityPriceUpdateDlg::slotReceivedQuote(const QString& _kmmID, const QString& _webID, const QDate& _date, const double& _price) | 706 | void KEquityPriceUpdateDlg::slotReceivedQuote(const QString& _kmmID, const QString& _webID, const QDate& _date, const double& _price) | ||
653 | { | 707 | { | ||
654 | QList<QTreeWidgetItem*> foundItems = lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | 708 | Q_D(KEquityPriceUpdateDlg); | ||
655 | QTreeWidgetItem* item = 0; | 709 | auto foundItems = d->ui->lvEquityList->findItems(_kmmID, Qt::MatchExactly, KMMID_COL); | ||
710 | QTreeWidgetItem* item = nullptr; | ||||
656 | 711 | | |||
657 | if (! foundItems.empty()) | 712 | if (! foundItems.empty()) | ||
658 | item = foundItems.at(0); | 713 | item = foundItems.at(0); | ||
Context not available. | |||||
698 | item->setText(DATE_COL, date.toString(Qt::ISODate)); | 753 | item->setText(DATE_COL, date.toString(Qt::ISODate)); | ||
699 | logStatusMessage(i18n("Price for %1 updated (id %2)", _webID, _kmmID)); | 754 | logStatusMessage(i18n("Price for %1 updated (id %2)", _webID, _kmmID)); | ||
700 | // make sure to make OK button available | 755 | // make sure to make OK button available | ||
701 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | 756 | d->ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | ||
702 | } else { | 757 | } else { | ||
703 | logErrorMessage(i18n("Received an invalid price for %1, unable to update.", _webID)); | 758 | logErrorMessage(i18n("Received an invalid price for %1, unable to update.", _webID)); | ||
704 | } | 759 | } | ||
705 | 760 | | |||
706 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 761 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
707 | item->setSelected(false); | 762 | item->setSelected(false); | ||
708 | 763 | | |||
709 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | 764 | // launch the NEXT one ... in case of m_fUpdateAll == false, we | ||
710 | // need to parse the list to find the next selected one | 765 | // need to parse the list to find the next selected one | ||
711 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | 766 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(item) + 1); | ||
712 | if (!m_fUpdateAll) { | 767 | if (!d->m_fUpdateAll) { | ||
713 | while (next && !next->isSelected()) { | 768 | while (next && !next->isSelected()) { | ||
714 | prgOnlineProgress->setValue(prgOnlineProgress->value() + 1); | 769 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->value() + 1); | ||
715 | next = lvEquityList->invisibleRootItem()->child(lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | 770 | next = d->ui->lvEquityList->invisibleRootItem()->child(d->ui->lvEquityList->invisibleRootItem()->indexOfChild(next) + 1); | ||
716 | } | 771 | } | ||
717 | } | 772 | } | ||
718 | } else { | 773 | } else { | ||
Context not available. | |||||
720 | } | 775 | } | ||
721 | 776 | | |||
722 | if (next) { | 777 | if (next) { | ||
723 | m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | 778 | d->m_webQuote.launch(next->text(WEBID_COL), next->text(KMMID_COL), next->text(SOURCE_COL)); | ||
724 | } else { | 779 | } else { | ||
725 | finishUpdate(); | 780 | finishUpdate(); | ||
726 | } | 781 | } | ||
Context not available. | |||||
728 | 783 | | |||
729 | void KEquityPriceUpdateDlg::finishUpdate() | 784 | void KEquityPriceUpdateDlg::finishUpdate() | ||
730 | { | 785 | { | ||
786 | Q_D(KEquityPriceUpdateDlg); | ||||
731 | // we've run past the end, reset to the default value. | 787 | // we've run past the end, reset to the default value. | ||
732 | m_fUpdateAll = false; | 788 | d->m_fUpdateAll = false; | ||
733 | // force progress bar to show 100% | 789 | // force progress bar to show 100% | ||
734 | prgOnlineProgress->setValue(prgOnlineProgress->maximum()); | 790 | d->ui->prgOnlineProgress->setValue(d->ui->prgOnlineProgress->maximum()); | ||
735 | // re-enable the sorting that was disabled during the update process | 791 | // re-enable the sorting that was disabled during the update process | ||
736 | lvEquityList->setSortingEnabled(true); | 792 | d->ui->lvEquityList->setSortingEnabled(true); | ||
737 | } | 793 | } | ||
738 | 794 | | |||
739 | // Make sure, that these definitions are only used within this file | 795 | // Make sure, that these definitions are only used within this file | ||
Context not available. |