Changeset View
Changeset View
Standalone View
Standalone View
tools/onlinequoteseditor/mainwindow.cpp
Show All 17 Lines | |||||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "mainwindow.h" | 20 | #include "mainwindow.h" | ||
21 | #include "ui_mainwindow.h" | 21 | #include "ui_mainwindow.h" | ||
22 | 22 | | |||
23 | #include "alkonlinequotesprofile.h" | 23 | #include "alkonlinequotesprofile.h" | ||
24 | #include "alkonlinequotesprofilemanager.h" | 24 | #include "alkonlinequotesprofilemanager.h" | ||
25 | #include "alkonlinequoteswidget.h" | 25 | #include "alkonlinequoteswidget.h" | ||
26 | #include "alkwebpage.h" | ||||
26 | 27 | | |||
27 | #include <QComboBox> | 28 | #include <QComboBox> | ||
28 | #include <QDockWidget> | 29 | #include <QDockWidget> | ||
29 | #include <QLineEdit> | 30 | #include <QLineEdit> | ||
30 | #include <QNetworkRequest> | 31 | #include <QNetworkRequest> | ||
31 | #include <QWebInspector> | 32 | #include <QWebInspector> | ||
32 | 33 | | |||
33 | class MainWindow::Private | 34 | class MainWindow::Private | ||
34 | { | 35 | { | ||
35 | public: | 36 | public: | ||
36 | Private() | 37 | Private() | ||
37 | : view(nullptr) | 38 | : urlLine(nullptr) | ||
38 | , urlLine(nullptr) | | |||
39 | , quotesWidget(nullptr) | 39 | , quotesWidget(nullptr) | ||
40 | { | 40 | { | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | ~Private() | 43 | ~Private() | ||
44 | { | 44 | { | ||
45 | delete view; | | |||
46 | delete quotesWidget; | 45 | delete quotesWidget; | ||
47 | } | 46 | } | ||
48 | QWebView *view; | | |||
49 | QLineEdit *urlLine; | 47 | QLineEdit *urlLine; | ||
50 | AlkOnlineQuotesWidget *quotesWidget; | 48 | AlkOnlineQuotesWidget *quotesWidget; | ||
51 | }; | 49 | }; | ||
52 | 50 | | |||
53 | void MainWindow::slotUrlChanged(const QUrl &url) | 51 | void MainWindow::slotUrlChanged(const QUrl &url) | ||
54 | { | 52 | { | ||
55 | d->urlLine->setText(url.toString()); | 53 | d->urlLine->setText(url.toString()); | ||
56 | } | 54 | } | ||
57 | 55 | | |||
58 | void MainWindow::slotEditingFinished() | 56 | void MainWindow::slotEditingFinished() | ||
59 | { | 57 | { | ||
60 | QUrl url(d->urlLine->text()); | 58 | AlkOnlineQuotesProfileManager::instance().webPage()->load(QUrl(d->urlLine->text()), d->quotesWidget->acceptLanguage()); | ||
61 | QNetworkRequest request; | | |||
62 | request.setUrl(url); | | |||
63 | if (!d->quotesWidget->acceptLanguage().isEmpty()) | | |||
64 | request.setRawHeader("Accept-Language", d->quotesWidget->acceptLanguage().toLocal8Bit()); | | |||
65 | d->view->load(request); | | |||
66 | } | 59 | } | ||
67 | 60 | | |||
68 | void MainWindow::slotLanguageChanged(const QString &text) | 61 | void MainWindow::slotLanguageChanged(const QString &text) | ||
69 | { | 62 | { | ||
70 | d->quotesWidget->setAcceptLanguage(text); | 63 | d->quotesWidget->setAcceptLanguage(text); | ||
71 | if (!d->urlLine->text().isEmpty()) | 64 | if (!d->urlLine->text().isEmpty()) | ||
72 | slotEditingFinished(); | 65 | slotEditingFinished(); | ||
73 | } | 66 | } | ||
74 | 67 | | |||
75 | MainWindow::MainWindow(QWidget *parent) | 68 | MainWindow::MainWindow(QWidget *parent) | ||
76 | : QMainWindow(parent) | 69 | : QMainWindow(parent) | ||
77 | , d(new Private) | 70 | , d(new Private) | ||
78 | , ui(new Ui::MainWindow) | 71 | , ui(new Ui::MainWindow) | ||
79 | { | 72 | { | ||
80 | AlkOnlineQuotesProfileManager &manager = AlkOnlineQuotesProfileManager::instance(); | 73 | AlkOnlineQuotesProfileManager &manager = AlkOnlineQuotesProfileManager::instance(); | ||
74 | manager.setWebPageEnabled(true); | ||||
81 | 75 | | |||
82 | manager.addProfile(new AlkOnlineQuotesProfile("alkimia", AlkOnlineQuotesProfile::Type::KMyMoney, "alkimia-quotes.knsrc")); | 76 | manager.addProfile(new AlkOnlineQuotesProfile("alkimia", AlkOnlineQuotesProfile::Type::KMyMoney, "alkimia-quotes.knsrc")); | ||
83 | //manager.addProfile(new AlkOnlineQuotesProfile("local", AlkOnlineQuotesProfile::Type::GHNS, "alkimia-quotes-local.knsrc")); | 77 | //manager.addProfile(new AlkOnlineQuotesProfile("local", AlkOnlineQuotesProfile::Type::GHNS, "alkimia-quotes-local.knsrc")); | ||
84 | manager.addProfile(new AlkOnlineQuotesProfile("skrooge", AlkOnlineQuotesProfile::Type::GHNS, "skrooge-quotes.knsrc")); | 78 | manager.addProfile(new AlkOnlineQuotesProfile("skrooge", AlkOnlineQuotesProfile::Type::GHNS, "skrooge-quotes.knsrc")); | ||
85 | manager.addProfile(new AlkOnlineQuotesProfile("kmymoney", AlkOnlineQuotesProfile::Type::KMyMoney, "kmymoney-quotes.knsrc")); | 79 | manager.addProfile(new AlkOnlineQuotesProfile("kmymoney", AlkOnlineQuotesProfile::Type::KMyMoney, "kmymoney-quotes.knsrc")); | ||
86 | ui->setupUi(this); | 80 | ui->setupUi(this); | ||
87 | 81 | | |||
88 | QDockWidget *dockWidget = new QDockWidget(tr("Browser"), this); | 82 | QDockWidget *dockWidget = new QDockWidget(tr("Browser"), this); | ||
89 | d->view = new QWebView; | 83 | AlkWebPage *webPage = manager.webPage(); | ||
90 | connect(d->view, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl))); | 84 | connect(webPage, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl))); | ||
91 | 85 | | |||
92 | d->urlLine = new QLineEdit; | 86 | d->urlLine = new QLineEdit; | ||
93 | connect(d->urlLine, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); | 87 | connect(d->urlLine, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); | ||
94 | 88 | | |||
95 | d->quotesWidget = new AlkOnlineQuotesWidget(true, true); | 89 | d->quotesWidget = new AlkOnlineQuotesWidget(true, true); | ||
96 | d->quotesWidget->setView(d->view); | | |||
97 | setCentralWidget(d->quotesWidget); | 90 | setCentralWidget(d->quotesWidget); | ||
98 | 91 | | |||
99 | // setup language box | 92 | // setup language box | ||
100 | QComboBox *box = new QComboBox; | 93 | QComboBox *box = new QComboBox; | ||
101 | QList<QLocale> allLocales = QLocale::matchingLocales( | 94 | QList<QLocale> allLocales = QLocale::matchingLocales( | ||
102 | QLocale::AnyLanguage, | 95 | QLocale::AnyLanguage, | ||
103 | QLocale::AnyScript, | 96 | QLocale::AnyScript, | ||
104 | QLocale::AnyCountry); | 97 | QLocale::AnyCountry); | ||
Show All 9 Lines | |||||
114 | 107 | | |||
115 | // setup layouts | 108 | // setup layouts | ||
116 | QHBoxLayout *hLayout = new QHBoxLayout; | 109 | QHBoxLayout *hLayout = new QHBoxLayout; | ||
117 | hLayout->addWidget(d->urlLine); | 110 | hLayout->addWidget(d->urlLine); | ||
118 | hLayout->addWidget(box); | 111 | hLayout->addWidget(box); | ||
119 | 112 | | |||
120 | QVBoxLayout *layout = new QVBoxLayout; | 113 | QVBoxLayout *layout = new QVBoxLayout; | ||
121 | layout->addLayout(hLayout); | 114 | layout->addLayout(hLayout); | ||
122 | layout->addWidget(d->view); | 115 | layout->addWidget(webPage); | ||
123 | QWidget *group = new QWidget; | 116 | QWidget *group = new QWidget; | ||
124 | group->setLayout(layout); | 117 | group->setLayout(layout); | ||
125 | dockWidget->setWidget(group); | 118 | dockWidget->setWidget(group); | ||
126 | addDockWidget(Qt::RightDockWidgetArea, dockWidget); | 119 | addDockWidget(Qt::RightDockWidgetArea, dockWidget); | ||
127 | 120 | | |||
128 | // setup inspector | 121 | webPage->setWebInspectorEnabled(true); | ||
129 | d->view->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); | | |||
130 | QWebInspector *inspector = new QWebInspector; | | |||
131 | inspector->setPage(d->view->page()); | | |||
132 | } | 122 | } | ||
133 | 123 | | |||
134 | MainWindow::~MainWindow() | 124 | MainWindow::~MainWindow() | ||
135 | { | 125 | { | ||
136 | delete d; | 126 | delete d; | ||
137 | delete ui; | 127 | delete ui; | ||
138 | } | 128 | } |