Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/views/khomeview.cpp
Show All 32 Lines | |||||
33 | #include <QDomElement> | 33 | #include <QDomElement> | ||
34 | #include <QDomText> | 34 | #include <QDomText> | ||
35 | #include <QFile> | 35 | #include <QFile> | ||
36 | #include <QTimer> | 36 | #include <QTimer> | ||
37 | #include <QBuffer> | 37 | #include <QBuffer> | ||
38 | #include <QStandardPaths> | 38 | #include <QStandardPaths> | ||
39 | #include <QDesktopServices> | 39 | #include <QDesktopServices> | ||
40 | #include <QUrlQuery> | 40 | #include <QUrlQuery> | ||
41 | #include <QPrintDialog> | ||||
41 | 42 | | |||
42 | // ---------------------------------------------------------------------------- | 43 | // ---------------------------------------------------------------------------- | ||
43 | // KDE Includes | 44 | // KDE Includes | ||
44 | 45 | | |||
45 | #include <KLocalizedString> | 46 | #include <KLocalizedString> | ||
46 | #include <khtmlview.h> | | |||
47 | #include <kconfig.h> | 47 | #include <kconfig.h> | ||
48 | #include <kstandardaction.h> | 48 | #include <kstandardaction.h> | ||
49 | #include <kxmlguiwindow.h> | 49 | #include <kxmlguiwindow.h> | ||
50 | #include <kactioncollection.h> | 50 | #include <kactioncollection.h> | ||
51 | #include <kmessagebox.h> | 51 | #include <kmessagebox.h> | ||
52 | #include <kcodecs.h> | 52 | #include <kcodecs.h> | ||
53 | #include <ktoolinvocation.h> | 53 | #include <ktoolinvocation.h> | ||
54 | #include <khtml_part.h> | 54 | #ifdef KF5KHtml_FOUND | ||
55 | #include <KHTMLPart> | ||||
56 | #include <KHTMLView> | ||||
57 | #endif | ||||
55 | 58 | | |||
56 | // ---------------------------------------------------------------------------- | 59 | // ---------------------------------------------------------------------------- | ||
57 | // Project Includes | 60 | // Project Includes | ||
58 | #include "kmymoneyutils.h" | 61 | #include "kmymoneyutils.h" | ||
59 | #include "kwelcomepage.h" | 62 | #include "kwelcomepage.h" | ||
60 | #include "kmymoneyglobalsettings.h" | 63 | #include "kmymoneyglobalsettings.h" | ||
61 | #include "mymoneyfile.h" | 64 | #include "mymoneyfile.h" | ||
62 | #include "mymoneyforecast.h" | 65 | #include "mymoneyforecast.h" | ||
Show All 28 Lines | 91 | Private() : | |||
91 | m_netWorthGraphLastValidSize(400, 300) { | 94 | m_netWorthGraphLastValidSize(400, 300) { | ||
92 | } | 95 | } | ||
93 | 96 | | |||
94 | /** | 97 | /** | ||
95 | * daily balances of an account | 98 | * daily balances of an account | ||
96 | */ | 99 | */ | ||
97 | typedef QMap<QDate, MyMoneyMoney> dailyBalances; | 100 | typedef QMap<QDate, MyMoneyMoney> dailyBalances; | ||
98 | 101 | | |||
99 | KHTMLPart* m_part; | 102 | QWebEngineView *m_view; | ||
100 | QString m_html; | 103 | QString m_html; | ||
101 | bool m_showAllSchedules; | 104 | bool m_showAllSchedules; | ||
102 | bool m_needReload; | 105 | bool m_needReload; | ||
103 | MyMoneyForecast m_forecast; | 106 | MyMoneyForecast m_forecast; | ||
104 | MyMoneyMoney m_total; | 107 | MyMoneyMoney m_total; | ||
105 | /** | 108 | /** | ||
106 | * Hold the last valid size of the net worth graph | 109 | * Hold the last valid size of the net worth graph | ||
107 | * for the times when the needed size can't be computed. | 110 | * for the times when the needed size can't be computed. | ||
108 | */ | 111 | */ | ||
109 | QSize m_netWorthGraphLastValidSize; | 112 | QSize m_netWorthGraphLastValidSize; | ||
110 | 113 | | |||
111 | /** | 114 | /** | ||
112 | * daily forecast balance of accounts | 115 | * daily forecast balance of accounts | ||
Show All 18 Lines | 129 | { | |||
131 | image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer | 134 | image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer | ||
132 | return QLatin1String("data:image/png;base64,") + QString(byteArray.toBase64()); | 135 | return QLatin1String("data:image/png;base64,") + QString(byteArray.toBase64()); | ||
133 | } | 136 | } | ||
134 | 137 | | |||
135 | KHomeView::KHomeView(QWidget *parent, const char *name) : | 138 | KHomeView::KHomeView(QWidget *parent, const char *name) : | ||
136 | KMyMoneyViewBase(parent, name, i18n("Home")), | 139 | KMyMoneyViewBase(parent, name, i18n("Home")), | ||
137 | d(new Private) | 140 | d(new Private) | ||
138 | { | 141 | { | ||
139 | d->m_part = new KHTMLPart(this); | 142 | d->m_view = new QWebEngineView(this); | ||
140 | d->m_part->setOnlyLocalReferences(true); | 143 | d->m_view->setPage(new MyQWebEnginePage(d->m_view)); | ||
141 | addWidget(d->m_part->view()); | 144 | addWidget(d->m_view); | ||
142 | 145 | | |||
143 | d->m_part->begin(); | 146 | d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); | ||
144 | d->m_part->write(KWelcomePage::welcomePage()); | 147 | connect(d->m_view->page(), &QWebEnginePage::urlChanged, | ||
145 | d->m_part->end(); | 148 | this, &KHomeView::slotOpenUrl); | ||
146 | | ||||
147 | // we are going to handle the zoom view signal to change the font scale | | |||
148 | connect(d->m_part->view(), SIGNAL(zoomView(int)), this, SLOT(slotZoomView(int))); | | |||
149 | disconnect(d->m_part->view(), SIGNAL(zoomView(int)), d->m_part, SLOT(slotZoomView(int))); | | |||
150 | | ||||
151 | connect(d->m_part->browserExtension(), SIGNAL(openUrlRequest(const QUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &)), | | |||
152 | this, SLOT(slotOpenUrl(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); | | |||
153 | } | 149 | } | ||
154 | 150 | | |||
155 | KHomeView::~KHomeView() | 151 | KHomeView::~KHomeView() | ||
156 | { | 152 | { | ||
157 | // if user wants to remember the font size, store it here | 153 | // if user wants to remember the font size, store it here | ||
158 | if (KMyMoneyGlobalSettings::rememberFontSize()) { | 154 | if (KMyMoneyGlobalSettings::rememberZoomFactor()) { | ||
159 | KMyMoneyGlobalSettings::setFontSizePercentage(d->m_part->fontScaleFactor()); | 155 | KMyMoneyGlobalSettings::setZoomFactor(d->m_view->zoomFactor()); | ||
160 | KMyMoneyGlobalSettings::self()->save(); | 156 | KMyMoneyGlobalSettings::self()->save(); | ||
161 | } | 157 | } | ||
162 | //This is to prevent a crash on exit with KDE 4.3.2 | | |||
163 | delete d->m_part; | | |||
164 | 158 | | |||
165 | delete d; | 159 | delete d; | ||
166 | } | 160 | } | ||
167 | 161 | | |||
162 | void KHomeView::wheelEvent(QWheelEvent* event) | ||||
163 | { | ||||
164 | // Zoom text on Ctrl + Scroll | ||||
165 | if (event->modifiers() & Qt::CTRL) { | ||||
166 | qreal factor = d->m_view->zoomFactor(); | ||||
167 | if (event->delta() > 0) | ||||
168 | factor += 0.1; | ||||
169 | else if (event->delta() < 0) | ||||
170 | factor -= 0.1; | ||||
171 | d->m_view->setZoomFactor(factor); | ||||
172 | event->accept(); | ||||
173 | return; | ||||
174 | } | ||||
175 | } | ||||
176 | | ||||
168 | void KHomeView::slotLoadView() | 177 | void KHomeView::slotLoadView() | ||
169 | { | 178 | { | ||
170 | d->m_needReload = true; | 179 | d->m_needReload = true; | ||
171 | if (isVisible()) { | 180 | if (isVisible()) { | ||
172 | loadView(); | 181 | loadView(); | ||
173 | d->m_needReload = false; | 182 | d->m_needReload = false; | ||
174 | } | 183 | } | ||
175 | } | 184 | } | ||
176 | 185 | | |||
177 | void KHomeView::showEvent(QShowEvent* event) | 186 | void KHomeView::showEvent(QShowEvent* event) | ||
178 | { | 187 | { | ||
179 | emit aboutToShow(); | 188 | emit aboutToShow(); | ||
180 | 189 | | |||
181 | if (d->m_needReload) { | 190 | if (d->m_needReload) { | ||
182 | loadView(); | 191 | loadView(); | ||
183 | d->m_needReload = false; | 192 | d->m_needReload = false; | ||
184 | } | 193 | } | ||
185 | 194 | | |||
186 | QWidget::showEvent(event); | 195 | QWidget::showEvent(event); | ||
187 | } | 196 | } | ||
188 | 197 | | |||
189 | void KHomeView::slotPrintView() | 198 | void KHomeView::slotPrintView() | ||
190 | { | 199 | { | ||
191 | if (d->m_part && d->m_part->view()) | 200 | if (d->m_view) { | ||
192 | d->m_part->view()->print(); | 201 | #ifdef KF5KHtml_FOUND | ||
202 | KHTMLPart *khtml = new KHTMLPart(this); | ||||
203 | khtml->begin(); | ||||
204 | khtml->write(d->m_html); | ||||
205 | khtml->end(); | ||||
206 | khtml->view()->print(); | ||||
207 | delete khtml; | ||||
208 | #else | ||||
209 | m_currentPrinter = new QPrinter(); | ||||
210 | QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); | ||||
211 | dialog->setWindowTitle(QString()); | ||||
212 | if (dialog->exec() != QDialog::Accepted) { | ||||
213 | delete m_currentPrinter; | ||||
214 | m_currentPrinter = nullptr; | ||||
215 | return; | ||||
216 | } | ||||
217 | d->m_view->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); | ||||
218 | #endif | ||||
193 | } | 219 | } | ||
194 | | ||||
195 | void KHomeView::slotZoomView(int delta) | | |||
196 | { | | |||
197 | const int fontScaleStepping = 10; | | |||
198 | if (delta > 0) | | |||
199 | d->m_part->setFontScaleFactor(d->m_part->fontScaleFactor() + fontScaleStepping); | | |||
200 | else | | |||
201 | d->m_part->setFontScaleFactor(d->m_part->fontScaleFactor() - fontScaleStepping); | | |||
202 | } | 220 | } | ||
203 | 221 | | |||
204 | void KHomeView::loadView() | 222 | void KHomeView::loadView() | ||
205 | { | 223 | { | ||
206 | d->m_part->setFontScaleFactor(KMyMoneyGlobalSettings::fontSizePercentage()); | 224 | d->m_view->setZoomFactor(KMyMoneyGlobalSettings::zoomFactor()); | ||
207 | 225 | | |||
208 | QList<MyMoneyAccount> list; | 226 | QList<MyMoneyAccount> list; | ||
209 | MyMoneyFile::instance()->accountList(list); | 227 | MyMoneyFile::instance()->accountList(list); | ||
210 | if (list.count() == 0) { | 228 | if (list.count() == 0) { | ||
211 | d->m_part->begin(); | 229 | d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); | ||
212 | d->m_part->write(KWelcomePage::welcomePage()); | | |||
213 | d->m_part->end(); | | |||
214 | } else { | 230 | } else { | ||
215 | //clear the forecast flag so it will be reloaded | 231 | //clear the forecast flag so it will be reloaded | ||
216 | d->m_forecast.setForecastDone(false); | 232 | d->m_forecast.setForecastDone(false); | ||
217 | 233 | | |||
218 | const QString filename = QStandardPaths::locate(QStandardPaths::DataLocation, "html/kmymoney.css"); | 234 | const QString filename = QStandardPaths::locate(QStandardPaths::DataLocation, "html/kmymoney.css"); | ||
219 | QString header = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"%1\">\n").arg(QUrl::fromLocalFile(filename).url()); | 235 | QString header = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"%1\">\n").arg(QUrl::fromLocalFile(filename).url()); | ||
220 | 236 | | |||
221 | header += KMyMoneyUtils::variableCSS(); | 237 | header += KMyMoneyUtils::variableCSS(); | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
280 | } | 296 | } | ||
281 | 297 | | |||
282 | d->m_html += "<div id=\"returnlink\">"; | 298 | d->m_html += "<div id=\"returnlink\">"; | ||
283 | d->m_html += link(VIEW_WELCOME, QString()) + i18n("Show KMyMoney welcome page") + linkend(); | 299 | d->m_html += link(VIEW_WELCOME, QString()) + i18n("Show KMyMoney welcome page") + linkend(); | ||
284 | d->m_html += "</div>"; | 300 | d->m_html += "</div>"; | ||
285 | d->m_html += "<div id=\"vieweffect\"></div>"; | 301 | d->m_html += "<div id=\"vieweffect\"></div>"; | ||
286 | d->m_html += footer; | 302 | d->m_html += footer; | ||
287 | 303 | | |||
288 | d->m_part->begin(); | 304 | d->m_view->setHtml(d->m_html, QUrl("file://")); | ||
289 | d->m_part->write(d->m_html); | | |||
290 | d->m_part->end(); | | |||
291 | } | 305 | } | ||
292 | } | 306 | } | ||
293 | 307 | | |||
294 | void KHomeView::showNetWorthGraph() | 308 | void KHomeView::showNetWorthGraph() | ||
295 | { | 309 | { | ||
296 | d->m_html += QString("<div class=\"shadow\"><div class=\"displayblock\"><div class=\"summaryheader\">%1</div>\n<div class=\"gap\"> </div>\n").arg(i18n("Net Worth Forecast")); | 310 | d->m_html += QString("<div class=\"shadow\"><div class=\"displayblock\"><div class=\"summaryheader\">%1</div>\n<div class=\"gap\"> </div>\n").arg(i18n("Net Worth Forecast")); | ||
297 | 311 | | |||
298 | MyMoneyReport reportCfg = MyMoneyReport( | 312 | MyMoneyReport reportCfg = MyMoneyReport( | ||
▲ Show 20 Lines • Show All 849 Lines • ▼ Show 20 Line(s) | 1156 | { | |||
1148 | return QString("<a href=\"/%1%2\"%3>").arg(view, query, titlePart); | 1162 | return QString("<a href=\"/%1%2\"%3>").arg(view, query, titlePart); | ||
1149 | } | 1163 | } | ||
1150 | 1164 | | |||
1151 | QString KHomeView::linkend() const | 1165 | QString KHomeView::linkend() const | ||
1152 | { | 1166 | { | ||
1153 | return QStringLiteral("</a>"); | 1167 | return QStringLiteral("</a>"); | ||
1154 | } | 1168 | } | ||
1155 | 1169 | | |||
1156 | void KHomeView::slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&) | 1170 | void KHomeView::slotOpenUrl(const QUrl &url) | ||
1157 | { | 1171 | { | ||
1158 | QString protocol = url.scheme(); | 1172 | QString protocol = url.scheme(); | ||
1159 | QString view = url.fileName(); | 1173 | QString view = url.fileName(); | ||
1174 | if (view.isEmpty()) | ||||
1175 | return; | ||||
1160 | QUrlQuery query(url); | 1176 | QUrlQuery query(url); | ||
1161 | QString id = query.queryItemValue("id"); | 1177 | QString id = query.queryItemValue("id"); | ||
1162 | QString mode = query.queryItemValue("mode"); | 1178 | QString mode = query.queryItemValue("mode"); | ||
1163 | 1179 | | |||
1164 | if (protocol == "http") { | 1180 | if (protocol == QLatin1String("http")) { | ||
1165 | QDesktopServices::openUrl(url); | 1181 | QDesktopServices::openUrl(url); | ||
1166 | } else if (protocol == "mailto") { | 1182 | } else if (protocol == QLatin1String("mailto")) { | ||
1167 | QDesktopServices::openUrl(url); | 1183 | QDesktopServices::openUrl(url); | ||
1168 | } else { | 1184 | } else { | ||
1169 | KXmlGuiWindow* mw = KMyMoneyUtils::mainWindow(); | 1185 | KXmlGuiWindow* mw = KMyMoneyUtils::mainWindow(); | ||
1170 | Q_CHECK_PTR(mw); | 1186 | Q_CHECK_PTR(mw); | ||
1171 | if (view == VIEW_LEDGER) { | 1187 | if (view == VIEW_LEDGER) { | ||
1172 | emit ledgerSelected(id, QString()); | 1188 | emit ledgerSelected(id, QString()); | ||
1173 | 1189 | | |||
1174 | } else if (view == VIEW_SCHEDULE) { | 1190 | } else if (view == VIEW_SCHEDULE) { | ||
1175 | if (mode == "enter") { | 1191 | if (mode == QLatin1String("enter")) { | ||
1176 | emit scheduleSelected(id); | 1192 | emit scheduleSelected(id); | ||
1177 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleEnter]), SLOT(trigger())); | 1193 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleEnter]), SLOT(trigger())); | ||
1178 | } else if (mode == QLatin1String("edit")) { | 1194 | } else if (mode == QLatin1String("edit")) { | ||
1179 | emit scheduleSelected(id); | 1195 | emit scheduleSelected(id); | ||
1180 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleEdit]), SLOT(trigger())); | 1196 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleEdit]), SLOT(trigger())); | ||
1181 | } else if (mode == QLatin1String("skip")) { | 1197 | } else if (mode == QLatin1String("skip")) { | ||
1182 | emit scheduleSelected(id); | 1198 | emit scheduleSelected(id); | ||
1183 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleSkip]), SLOT(trigger())); | 1199 | QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleSkip]), SLOT(trigger())); | ||
1184 | } else if (mode == QLatin1String("full")) { | 1200 | } else if (mode == QLatin1String("full")) { | ||
1185 | d->m_showAllSchedules = true; | 1201 | d->m_showAllSchedules = true; | ||
1186 | loadView(); | 1202 | loadView(); | ||
1187 | 1203 | | |||
1188 | } else if (mode == "reduced") { | 1204 | } else if (mode == QLatin1String("reduced")) { | ||
1189 | d->m_showAllSchedules = false; | 1205 | d->m_showAllSchedules = false; | ||
1190 | loadView(); | 1206 | loadView(); | ||
1191 | } | 1207 | } | ||
1192 | 1208 | | |||
1193 | } else if (view == VIEW_REPORTS) { | 1209 | } else if (view == VIEW_REPORTS) { | ||
1194 | emit reportSelected(id); | 1210 | emit reportSelected(id); | ||
1195 | 1211 | | |||
1196 | } else if (view == VIEW_WELCOME) { | 1212 | } else if (view == VIEW_WELCOME) { | ||
1197 | if (mode == "whatsnew") { | 1213 | if (mode == QLatin1String("whatsnew")) | ||
1198 | d->m_part->begin(); | 1214 | d->m_view->setHtml(KWelcomePage::whatsNewPage(), QUrl("file://")); | ||
1199 | d->m_part->write(KWelcomePage::whatsNewPage()); | 1215 | else | ||
1200 | d->m_part->end(); | 1216 | d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); | ||
1201 | } else { | | |||
1202 | d->m_part->begin(); | | |||
1203 | d->m_part->write(KWelcomePage::welcomePage()); | | |||
1204 | d->m_part->end(); | | |||
1205 | } | | |||
1206 | 1217 | | |||
1207 | } else if (view == "action") { | 1218 | } else if (view == QLatin1String("action")) { | ||
1208 | QTimer::singleShot(0, mw->actionCollection()->action(id), SLOT(trigger())); | 1219 | QTimer::singleShot(0, mw->actionCollection()->action(id), SLOT(trigger())); | ||
1209 | } else if (view == VIEW_HOME) { | 1220 | } else if (view == VIEW_HOME) { | ||
1210 | QList<MyMoneyAccount> list; | 1221 | QList<MyMoneyAccount> list; | ||
1211 | MyMoneyFile::instance()->accountList(list); | 1222 | MyMoneyFile::instance()->accountList(list); | ||
1212 | if (list.count() == 0) { | 1223 | if (list.count() == 0) { | ||
1213 | KMessageBox::information(this, i18n("Before KMyMoney can give you detailed information about your financial status, you need to create at least one account. Until then, KMyMoney shows the welcome page instead.")); | 1224 | KMessageBox::information(this, i18n("Before KMyMoney can give you detailed information about your financial status, you need to create at least one account. Until then, KMyMoney shows the welcome page instead.")); | ||
1214 | } | 1225 | } | ||
1215 | loadView(); | 1226 | loadView(); | ||
▲ Show 20 Lines • Show All 811 Lines • Show Last 20 Lines |