-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
169 lines (127 loc) · 4.55 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* This file is part of WhatsQt.
*
* WhatsQt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WhatsQt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WhatsQt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QCloseEvent>
#include "notification/notificationservice.h"
#include "view/webview.h"
namespace Ui {
class MainWindow;
}
class WebViewService : public QObject
{
Q_OBJECT
public:
explicit WebViewService(WebView * view, QWidget* parent = Q_NULLPTR) : QObject(parent), webView(view)
{
connect(webView, &WebView::loadStarted, this, &WebViewService::loadStarted);
connect(webView, &WebView::loadProgress, this, &WebViewService::loadProgress);
connect(webView, &WebView::loadFinished, this, &WebViewService::loadFinished);
connect(webView, &WebView::titleChanged, this, &WebViewService::titleChanged);
connect(webView, &WebView::urlChanged, this, &WebViewService::urlChanged);
}
public slots:
void load(const QUrl& url) { webView->load(url); }
void stop() { webView->stop(); }
void back() { webView->back(); }
void forward() { webView->forward(); }
void reload() { webView->reload(); }
signals:
void loadStarted();
void loadProgress(int progress);
void loadFinished(bool);
void titleChanged(const QString& title);
void urlChanged(const QUrl& url);
private:
WebView * webView;
};
class JSNotifcationWrapper : public QObject {
Q_OBJECT
public:
JSNotifcationWrapper(NotificationService *service, QObject *parent = 0);
void setNotificationService(NotificationService *notificationService);
Q_INVOKABLE void deliverNotification(const QString &title, const QMap<QString, QVariant> &options);
private:
NotificationService *notificationService;
private slots:
void onNotificationClicked(const Notification ¬ification);
void onNotificationReplied(const Notification ¬ification, const QString &reply);
signals:
void notificationClicked(const QString &title, const QMap<QString, QVariant> &options);
void notificationReplied(const QString &title, const QMap<QString, QVariant> &options, const QString &reply);
};
class DownloadManager;
class LocalAppManager;
class AppInfo;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *event);
protected:
bool event(QEvent *event);
virtual void showEvent(QShowEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
private:
Ui::MainWindow *ui;
NotificationService *notificationService;
JSNotifcationWrapper *notificationWrapper;
WebViewService * webViewService;
bool beginDrag;
QPoint dragPosition;
void saveSettings();
void readSettings();
void initActions();
void initMenus();
void initTitleBar();
void initDownloadManager();
void initLocalAppManager();
void initNotificationService();
void initMainWebView();
void initWebService();
void initHttpService();
#ifdef Q_OS_OSX
void nativeSetup();
#else
void nativeSetup() {}
#endif
public slots:
void checkSelfUpdate();
void checkActivitys();
private slots:
void downloadComplete(const QUrl & url);
void downloadProgress(const QUrl & url, int nPercentage);
void webViewLoadStarted();
void webViewLoadProgress(int progress);
void webViewLoadFinished(bool);
void appInstallBegin(const AppInfo & appInfo);
void appInstallProgress(int percentage);
void appInstallComplete(const AppInfo & appInfo);
void linkClicked(const QUrl & url);
void webViewTitleChanged(const QString &title);
void webViewUrlChanged(const QUrl & url);
void notificationClicked(const Notification ¬ification);
void notificationReplied(const Notification ¬ification, const QString &reply);
void updateCheckingFinished(QString);
void updateDownloadFinished(QString, QString);
};
#endif // MAINWINDOW_H