-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·696 lines (575 loc) · 21.8 KB
/
Copy pathmainwindow.cpp
File metadata and controls
executable file
·696 lines (575 loc) · 21.8 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/****************************************************************************
**
** mysms - Send & receive all your SMS on your Notebook, PC or tablet – like on your smartphone
** Copyright (C) 2013 Up To Eleven
** All rights reserved.
**
**
** This library is free software. either version 2.1 of the License, or (at your option) any later version.
** you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation;
** either version 2.1 of the License, or (at your option) any later version.
**
**
** This library 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 Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License along with this library;
** if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
**
****************************************************************************/
#include "mainwindow.h"
#include "qtsingleapplication.h"
#include "qnetworkaccessmanagercustom.h"
#include "notificationpopupmanager.h"
#include "updatedialog.h"
#include "globalsettings.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QFontDatabase>
#include <QMessageBox>
#include <QWebFrame>
#include <QWindowStateChangeEvent>
#include <QShortcut>
#include <QKeySequence>
#include <QNetworkDiskCache>
#include <QNetworkProxyQuery>
#include <QDesktopServices>
#include <QDesktopWidget>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#include <QtWidgets>
#endif
static const QString SettingGeometry = "geometry";
static const QString SettingWindowState = "state";
static const QString SettingCloseInfo = "closeinfo";
static const QString SettingLocale = "locale";
static const QString SettingNotificationDisabledUntil = "notificationDisabled";
static const QString SettingVersion = "version";
static const int versionStringLength = 5;
MainWindow *MainWindow::m_instance = 0;
MainWindow *MainWindow::instance()
{
if (m_instance == 0)
{
m_instance = new MainWindow();
}
return m_instance;
}
void MainWindow::drop()
{
if (m_instance != 0)
{
delete m_instance;
m_instance = 0;
}
}
MainWindow::~MainWindow()
{
delete m_notificationPopupManager;
m_notificationPopupManager = NULL;
delete m_trayIconMenu;
m_trayIconMenu = NULL;
delete m_trayIcon;
m_trayIcon = NULL;
delete m_quitAction;
m_quitAction = NULL;
delete m_refreshAction;
m_refreshAction = NULL;
delete m_settingsAction;
m_settingsAction = NULL;
delete m_jsInterface;
m_jsInterface = NULL;
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
if (m_taskBarButton != NULL) {
delete m_taskBarButton;
m_taskBarButton = NULL;
}
#endif
#ifdef WEBINSPECTOR
delete m_inspector;
m_inspector = NULL;
#endif
}
void MainWindow::updateBadgeCounter(const int badgeCounter)
{
QIcon icon;
if (badgeCounter > 9)
icon = QIcon(":/resource/icon-9.png");
else if (badgeCounter == 0)
icon = m_icon;
else
icon = QIcon(QString(":/resource/icon-%1.png").arg(badgeCounter));
QWidget::setWindowIcon(icon);
m_trayIcon->setIcon(icon);
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
if (m_taskBarButton != NULL) {
if (badgeCounter == 0) {
m_taskBarButton->clearOverlayIcon();
} else {
m_taskBarButton->setOverlayIcon(icon);
}
}
#endif
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
m_userSettingsDialog = NULL;
m_notificationPopupManager = new NotificationPopupManager();
m_lastClickTime = 0;
UserSettings *userSettings = UserSettings::getInstance();
if (userSettings->areSettingsAvailable())
userSettings->loadSettings();
else
userSettings->setDefaultData();
m_userSettingsDialog = new UserSettingsDialog();
m_icon = QIcon(":/resource/icon.png");
QFontDatabase::addApplicationFont(":/resource/opensans.ttf");
QFontDatabase::addApplicationFont(":/resource/opensans-bold.ttf");
QApplication::font().setFamily("Open Sans");
QWidget::setWindowIcon(m_icon);
setWindowTitle(tr("mysms"));
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
m_taskBarButton = new QWinTaskbarButton(this);
m_taskBarButton->setWindow(this->windowHandle());
} else {
m_taskBarButton = NULL;
}
QApplication::instance()->installNativeEventFilter(new CustomNativeEventFilter());
#endif
createActions();
createTrayIcon();
bool skipResize = false;
if (m_settings.contains(SettingWindowState))
{
if (m_settings.value(SettingWindowState).toBool()) // maximized
{
setGeometry(m_settings.value(SettingGeometry).toRect());
showMaximized();
skipResize = true;
}
}
if (!(skipResize))
{
if (m_settings.contains(SettingGeometry))
{
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect clientRect = desktopWidget->availableGeometry(this);
QRect storedRect = m_settings.value(SettingGeometry).toRect();
if (storedRect.right() > clientRect.right())
showMaximized();
else
setGeometry(m_settings.value(SettingGeometry).toRect());
}
else
resize(qMin(QApplication::desktop()->width(), 960), qMin(QApplication::desktop()->height(), 800));
}
if (!m_settings.contains(SettingVersion)
|| m_settings.value(SettingVersion).toString().compare(QtSingleApplication::applicationVersion()) != 0) {
// we need delete the cache dir on upgrades (at least from qt4)
#if QT_VERSION >= 0x050000
QDir *cacheDir = new QDir(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).at(0));
if (cacheDir->exists()) {
cacheDir->removeRecursively();
}
#endif
m_settings.setValue(SettingVersion, QtSingleApplication::applicationVersion());
m_settings.sync();
}
m_webview = new WebView(this);
#ifdef CACHE_CLEAR
QWebSettings::clearMemoryCaches();
m_webview.settings()->clearMemoryCaches();
#endif
QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
#if defined(Q_OS_WIN) && QT_VERSION < 0x050000
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
#else
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, false);
#endif
QWebSettings::enablePersistentStorage();
m_webview->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
m_webview->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
m_webview->settings()->setAttribute(QWebSettings::SiteSpecificQuirksEnabled, false);
m_webview->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, true);
m_webview->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
m_webview->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
m_webview->settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
QNetworkAccessManagerCustom *networkAccessManager = new QNetworkAccessManagerCustom(this);
m_webview->page()->setNetworkAccessManager(networkAccessManager);
m_webview->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
#if QT_VERSION >= 0x050000
diskCache->setCacheDirectory(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).at(0));
#else
diskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
#endif
networkAccessManager->setCache(diskCache);
qDebug() << "default cache size :" << diskCache->cacheSize() << ", max cache size: " << diskCache->maximumCacheSize();
m_networkCookieJar = new NetworkCookieJar();
networkAccessManager->setCookieJar(m_networkCookieJar);
QNetworkProxyQuery npq(QUrl("http://www.google.com"));
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
if ((listOfProxies.size() > 0) && (listOfProxies[0].type() != QNetworkProxy::NoProxy))
{
QNetworkProxy::setApplicationProxy(listOfProxies[0]);
}
setCentralWidget(m_webview);
connect(m_webview, SIGNAL(linkClicked(QUrl)), SLOT(openExternalUrl(QUrl)));
connect(m_webview->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJsObjects()));
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
connect(&m_clickDelayTimer, SIGNAL(timeout()), this, SLOT(singleClick()));
#ifdef WEBINSPECTOR
m_webview.page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
m_inspector = new QWebInspector();
m_inspector->setPage(m_webview.page());
m_inspector->setVisible(true);
m_inspector->show();
#endif
loadPage();
}
void MainWindow::checkVersion()
{
#ifdef UPDATE_SUPPORTED
QNetworkReply *networkReply = networkAccessManager()->get(QNetworkRequest(QUrl(UPDATE_VERSION_FILE_URL)));
connect(networkReply, SIGNAL(finished()), this, SLOT(downloadVersionFileFinished()));
#endif
}
void MainWindow::downloadVersionFileFinished()
{
QNetworkReply *networkReply = (QNetworkReply *)sender();
bool updateAvailable = false;
if (networkReply->error() != QNetworkReply::NoError) {
qDebug() << "error occured on downloading version file" << networkReply->url() << ":" << networkReply->errorString();
} else {
QString version;
QString data = (QString)networkReply->readAll();
QXmlStreamReader xml(data);
while(!xml.atEnd())
{
xml.readNextStartElement();
if(xml.name() == "Program_Version" && !xml.isEndElement())
{
version = xml.readElementText();
break;
}
}
if (!version.isEmpty() && (version.length() == versionStringLength) && (version[1] == '.') && (version[3] == '.'))
{
int majorServerVersion = version[0].digitValue();
int middleServerVersion = version[2].digitValue();
int minorServerVersion = version[4].digitValue();
if (VERSION_MAJOR < majorServerVersion)
updateAvailable = true;
else if (VERSION_MAJOR == majorServerVersion)
{
if (VERSION_MIDDLE < middleServerVersion)
updateAvailable = true;
else if (VERSION_MIDDLE == middleServerVersion)
{
if (VERSION_MINOR < minorServerVersion)
updateAvailable = true;
}
}
}
}
disconnect(networkReply, SIGNAL(finished()));
networkReply->deleteLater();
if (updateAvailable)
{
networkReply = networkAccessManager()->get(QNetworkRequest(QUrl(UPDATE_INSTALLER_URL)));
connect(networkReply, SIGNAL(finished()), this, SLOT(downloadInstallerFinished()));
}
}
void MainWindow::downloadInstallerFinished()
{
QNetworkReply *networkReply = (QNetworkReply *)sender();
if (networkReply->error() != QNetworkReply::NoError) {
qDebug() << "error occured on downloading version file" << networkReply->url() << ":" << networkReply->errorString();
} else {
QString installerFileName = QDir::tempPath() + "/" + UPDATE_INSTALLER_FILE_NAME;
QFile localFile(installerFileName);
if (localFile.open(QIODevice::WriteOnly))
{
localFile.write(networkReply->readAll());
localFile.close();
UpdateDialog *updateDialog = new UpdateDialog(installerFileName);
updateDialog->show();
}
}
disconnect(networkReply, SIGNAL(finished()));
networkReply->deleteLater();
}
void MainWindow::loadPage(QString address)
{
QUrl url;
if (m_settings.contains(SettingLocale))
url = QUrl::fromUserInput(QString(SERVER_URL) + "/?locale=" + m_settings.value(SettingLocale).toString() + address);
else
url = QUrl::fromUserInput(QString(SERVER_URL) + address);
if (m_webview->url() != url)
m_webview->load(url);
}
QNetworkAccessManager *MainWindow::networkAccessManager()
{
return m_webview->page()->networkAccessManager();
}
QSystemTrayIcon *MainWindow::systemTrayIcon()
{
return m_trayIcon;
}
void MainWindow::changeEvent(QEvent *event)
{
if (event->type() == QEvent::WindowStateChange)
{
QWindowStateChangeEvent *qwsc_event = dynamic_cast<QWindowStateChangeEvent*>(event);
m_savedWindowState = qwsc_event->oldState();
if(!(this->isWindowClosed()))
{
m_notificationPopupManager->clearAllMessages();
m_notificationPopupManager->setNotificationModeOverview(false);
}
}
QMainWindow::changeEvent(event);
}
void MainWindow::closeWindow(QCloseEvent *event)
{
UserSettingsData data = UserSettings::getInstance()->getUserSettingsData();
if (data.commonTabData.showInTaskbarAfterExitSelector)
showMinimized();
else
hide();
if (event != NULL)
{
event->ignore();
}
}
void MainWindow::openWindow()
{
m_notificationPopupManager->clearAllMessages();
m_notificationPopupManager->setNotificationModeOverview(false);
if (isHidden() || isMinimized())
{
raise();
show();
setWindowState(m_savedWindowState);
}
#ifdef Q_OS_WIN
m_trayIcon->hide(); // workaround -> after activation of the main window, the next Trigger event of the system tray doesn´t occur
m_trayIcon->show();
#endif
activateWindow();
}
bool MainWindow::isWindowClosed()
{
return ((isHidden()) || (isMinimized()) || (!isActiveWindow()));
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (!isHidden() && !isMinimized())
{
if (!m_settings.contains(SettingCloseInfo))
{
m_settings.setValue(SettingCloseInfo, true);
QMessageBox::information(this, tr("Systray"),
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
}
m_savedWindowState = windowState();
closeWindow(event);
}
}
void MainWindow::singleClick()
{
m_clickDelayTimer.stop();
if (!(isWindowClosed()))
{
m_savedWindowState = windowState();
closeWindow(NULL);
}
else
m_notificationPopupManager->setNotificationModeOverview(true);
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
qint64 time;
switch (reason)
{
case QSystemTrayIcon::DoubleClick:
m_clickDelayTimer.stop();
if (isWindowClosed())
openWindow();
#ifdef Q_OS_LINUX
else
closeWindow(NULL);
#endif
break;
case QSystemTrayIcon::Trigger:
if (isWindowClosed()) {
time = QDateTime::currentMSecsSinceEpoch();
if (time - m_lastClickTime > POPUP_HOVER_FADEOUT_TIME) {
m_lastClickTime = time;
m_notificationPopupManager->setNotificationModeOverview(false);
m_clickDelayTimer.start(POPUP_DELAY_TIME);
} else {
openWindow();
}
} else {
m_notificationPopupManager->setNotificationModeOverview(false);
m_clickDelayTimer.start(POPUP_DELAY_TIME);
}
break;
case QSystemTrayIcon::Context:
updateTrayIconMenu();
break;
default:
break;
}
}
void MainWindow::openExternalUrl(QUrl url)
{
if (url.toString().startsWith(QString(SERVER_URL)))
{
QRegExp rx("locale\\=(\\w\\w)");
if (rx.indexIn(url.toString(), 0) > 0)
{
QString locale = rx.capturedTexts().value(1);
m_settings.setValue(SettingLocale, locale);
}
m_webview->load(url);
}
else
QDesktopServices::openUrl(url);
}
void MainWindow::addJsObjects()
{
m_jsInterface = new JsInterface(m_notificationPopupManager, m_networkCookieJar);
m_webview->page()->mainFrame()->addToJavaScriptWindowObject(QString(APPLICATION_NAME), m_jsInterface );
}
void MainWindow::saveSettings()
{
m_settings.setValue(SettingGeometry, geometry());
m_settings.setValue(SettingWindowState, isMaximized());
m_settings.sync();
}
void MainWindow::createActions()
{
m_quitAction = new QAction(tr("&Quit"), this);
connect(m_quitAction, SIGNAL(triggered()), this, SLOT(quit()));
m_refreshAction = new QAction(tr("&Refresh"), this);
connect(m_refreshAction, SIGNAL(triggered()), this, SLOT(refresh()));
m_settingsAction = new QAction(tr("&Settings"), this);
connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(settings()));
m_notificationDisable30m = new QAction(tr("Mute for 30 minutes"), this);
connect(m_notificationDisable30m, SIGNAL(triggered()), this, SLOT(disableNotifications()));
m_notificationDisable1h = new QAction(tr("Mute for 1 hour"), this);
connect(m_notificationDisable1h, SIGNAL(triggered()), this, SLOT(disableNotifications()));
m_notificationDisable3h = new QAction(tr("Mute for 3 hour"), this);
connect(m_notificationDisable3h, SIGNAL(triggered()), this, SLOT(disableNotifications()));
m_notificationDisable8h = new QAction(tr("Mute for 8 hour"), this);
connect(m_notificationDisable8h, SIGNAL(triggered()), this, SLOT(disableNotifications()));
m_notificationDisabled = new QAction(tr("Notifications disabled"), this);
m_notificationDisabled->setIcon(QIcon(QPixmap(":/resource/notification-disabled.png")));
connect(m_notificationDisabled, SIGNAL(triggered()), this, SLOT(enableNotifications()));
/* rfu
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+Shift+o"), this);
connect(shortcut, SIGNAL(activated()), this, SLOT(shortcut_Ctrl_O()));
*/
}
void MainWindow::createTrayIcon()
{
m_trayIconMenu = new QMenu(this);
m_notificationMenu = new QMenu(tr("Notifications"), this);
m_notificationMenu->addAction(m_notificationDisable30m);
m_notificationMenu->addAction(m_notificationDisable1h);
m_notificationMenu->addAction(m_notificationDisable3h);
m_notificationMenu->addAction(m_notificationDisable8h);
m_trayIconMenu->addMenu(m_notificationMenu);
m_trayIconMenu->addAction(m_notificationDisabled);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_settingsAction);
m_trayIconMenu->addAction(m_refreshAction);
m_trayIconMenu->addAction(m_quitAction);
m_trayIcon = new QSystemTrayIcon(this);
m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->setIcon(m_icon);
m_trayIcon->show();
}
void MainWindow::updateTrayIconMenu()
{
if (isNotificationDisabled())
{
m_notificationMenu->menuAction()->setVisible(false);
m_notificationDisabled->setVisible(true);
} else {
m_notificationMenu->menuAction()->setVisible(true);
m_notificationDisabled->setVisible(false);
}
}
void MainWindow::settings()
{
m_userSettingsDialog->show();
m_userSettingsDialog->activateWindow();
}
void MainWindow::refresh()
{
// workaround for webkit crash if offline application cache is enabled and reload (m_webview.reload()) is done
QUrl url = m_webview->url();
m_webview->load(QUrl::fromUserInput("about:blank"));
m_webview->load(url);
}
void MainWindow::quit()
{
saveSettings();
QWebSettings::clearMemoryCaches();
qApp->quit();
}
bool MainWindow::isNotificationDisabled()
{
return m_settings.contains(SettingNotificationDisabledUntil)
&& m_settings.value(SettingNotificationDisabledUntil).toLongLong() > QDateTime::currentMSecsSinceEpoch();
}
void MainWindow::disableNotifications()
{
qint64 timespan = 30 * 60 * 1000;
if (sender() == m_notificationDisable1h) {
timespan = 60 * 60 * 1000;
} else if (sender() == m_notificationDisable3h) {
timespan = 3 * 60 * 60 * 1000;
} else if (sender() == m_notificationDisable8h) {
timespan = 8 * 60 * 60 * 1000;
}
qDebug() << "disable notifications for " << timespan << " millis";
m_settings.setValue(SettingNotificationDisabledUntil, QDateTime::currentMSecsSinceEpoch() + timespan);
m_settings.sync();
}
void MainWindow::enableNotifications()
{
m_settings.remove(SettingNotificationDisabledUntil);
m_settings.sync();
}
QString WebPage::userAgentForUrl(const QUrl &url ) const
{
QString ua = QWebPage::userAgentForUrl(url);
if (url.toString().indexOf("analytics") >= 0)
return ua.replace(QRegExp("^\\S*\\s(\\([^\\)]*\\)).*$"), "mysms/" + QtSingleApplication::applicationVersion() + " \\1" );
return ua;
}
#if QT_VERSION >= 0x050000 && defined(Q_OS_WIN)
bool CustomNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
MSG* msg = (MSG*)(message);
if (msg->message == WM_QUERYENDSESSION) {
MainWindow::instance()->quit();
return true;
} else if (msg->message == WM_CLOSE && result == 0) {
qDebug() << "win event filter - event type: " << eventType << ", message: " << msg->message << ", result: " << result;
MainWindow::instance()->quit();
return true;
}
return false;
}
#endif