diff options
author | 2023-01-27 10:09:49 +0530 | |
---|---|---|
committer | 2023-01-27 12:22:19 +0530 | |
commit | 085205eb692332ac694ca92c784fa027906aac3b (patch) | |
tree | 1e583e74017f99f48179235ec1e927e8d17bf7a4 /src | |
parent | 011db4495d98932cbffa5fc2268ee1a3e2984aa6 (diff) | |
download | whatsie-085205eb692332ac694ca92c784fa027906aac3b.tar.gz whatsie-085205eb692332ac694ca92c784fa027906aac3b.zip |
chore: code cleanupv4.12.1
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 44 | ||||
-rw-r--r-- | src/mainwindow.h | 8 | ||||
-rw-r--r-- | src/webenginepage.cpp | 12 | ||||
-rw-r--r-- | src/webview.cpp | 41 | ||||
-rw-r--r-- | src/webview.h | 2 |
5 files changed, 55 insertions, 52 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ae8fdbe..c8d688e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -39,7 +39,8 @@ void MainWindow::restoreMainWindow() { if (settings.value("geometry").isValid()) { restoreGeometry(settings.value("geometry").toByteArray()); QPoint pos = QCursor::pos(); - for (QScreen *screen : QGuiApplication::screens()) { + auto localScreens = QGuiApplication::screens(); + for (auto screen : qAsConst(localScreens)) { QRect screenRect = screen->geometry(); if (screenRect.contains(pos)) { this->move(screenRect.center() - this->rect().center()); @@ -356,9 +357,8 @@ void MainWindow::initSettingWidget() { }); connect(settingsWidget, &SettingsWidget::notificationPopupTimeOutChanged, - settingsWidget, [=]() { - setNotificationPresenter(webEngine->page()->profile()); - }); + settingsWidget, + [=]() { setNotificationPresenter(webEngine->page()->profile()); }); connect(settingsWidget, &SettingsWidget::notify, settingsWidget, [=](QString message) { notify("", message); }); @@ -381,7 +381,7 @@ void MainWindow::initSettingWidget() { settings.value("lockscreen", false).toBool()); // spell checker - settingsWidget->loadDictionaries(m_dictionaries); + settingsWidget->loadDictionaries(dictionaries); } } @@ -392,7 +392,8 @@ void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); } -void MainWindow::handleZoomOnWindowStateChange(QWindowStateChangeEvent *ev) { +void MainWindow::handleZoomOnWindowStateChange( + const QWindowStateChangeEvent *ev) { if (settingsWidget != nullptr) { if (ev->oldState().testFlag(Qt::WindowMaximized) && windowState().testFlag(Qt::WindowNoState)) { @@ -743,17 +744,18 @@ void MainWindow::appAutoLockChanged() { void MainWindow::checkWindowState() { QObject *tray_icon_menu = this->findChild<QObject *>("trayIconMenu"); if (tray_icon_menu != nullptr) { + QMenu *menu = qobject_cast<QMenu *>(tray_icon_menu); if (this->isVisible()) { - ((QMenu *)(tray_icon_menu))->actions().at(0)->setDisabled(false); - ((QMenu *)(tray_icon_menu))->actions().at(1)->setDisabled(true); + menu->actions().at(0)->setDisabled(false); + menu->actions().at(1)->setDisabled(true); } else { - ((QMenu *)(tray_icon_menu))->actions().at(0)->setDisabled(true); - ((QMenu *)(tray_icon_menu))->actions().at(1)->setDisabled(false); + menu->actions().at(0)->setDisabled(true); + menu->actions().at(1)->setDisabled(false); } if (lockWidget && lockWidget->getIsLocked()) { - ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(true); + menu->actions().at(4)->setDisabled(true); } else { - ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(false); + menu->actions().at(4)->setDisabled(false); } } } @@ -804,9 +806,9 @@ void MainWindow::createWebEngine() { widgetSize.setHorizontalStretch(1); widgetSize.setVerticalStretch(1); - m_dictionaries = Dictionaries::GetDictionaries(); + dictionaries = Dictionaries::GetDictionaries(); - WebView *webEngineView = new WebView(this, m_dictionaries); + WebView *webEngineView = new WebView(this, dictionaries); setCentralWidget(webEngineView); webEngineView->setSizePolicy(widgetSize); webEngineView->show(); @@ -832,11 +834,11 @@ const QIcon MainWindow::getTrayIcon(const int ¬ificationCount) const { } void MainWindow::createWebPage(bool offTheRecord) { - if (offTheRecord && !m_otrProfile) { - m_otrProfile.reset(new QWebEngineProfile); + if (offTheRecord && !otrProfile) { + otrProfile.reset(new QWebEngineProfile); } auto profile = - offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile(); + offTheRecord ? otrProfile.get() : QWebEngineProfile::defaultProfile(); QStringList dict_names; dict_names.append(settings.value("sc_dict", "en-US").toString()); @@ -864,7 +866,7 @@ void MainWindow::createWebPage(bool offTheRecord) { QUrl("https://web.whatsapp.com?v=" + QString::number(randomValue))); connect(profile, &QWebEngineProfile::downloadRequested, - &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested); + &downloadManagerWidget, &DownloadManagerWidget::downloadRequested); connect(page, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest))); @@ -971,8 +973,6 @@ void MainWindow::handleLoadFinished(bool loaded) { } } - - void MainWindow::checkLoadedCorrectly() { if (webEngine && webEngine->page()) { // test 1 based on the class name of body tag of the page @@ -1108,7 +1108,7 @@ void MainWindow::doReload(bool byPassCache, bool isAskedByCLI, bool byLoadingQuirk) { if (byLoadingQuirk) { webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, - byPassCache); + byPassCache); } else { if (lockWidget && !lockWidget->getIsLocked()) { this->notify(QApplication::applicationName(), @@ -1125,7 +1125,7 @@ void MainWindow::doReload(bool byPassCache, bool isAskedByCLI, return; } webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, - byPassCache); + byPassCache); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index f6346ad..4ca25d5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -91,11 +91,11 @@ private: QSystemTrayIcon *trayIcon; QWebEngineView *webEngine; SettingsWidget *settingsWidget = nullptr; - DownloadManagerWidget m_downloadManagerWidget; - QScopedPointer<QWebEngineProfile> m_otrProfile; + DownloadManagerWidget downloadManagerWidget; + QScopedPointer<QWebEngineProfile> otrProfile; Lock *lockWidget = nullptr; int correctlyLoaderRetries = 4; - QStringList m_dictionaries; + QStringList dictionaries; AutoLockEventFilter *autoLockEventFilter = nullptr; private slots: @@ -121,7 +121,7 @@ private slots: void quitApp(); void initRateWidget(); void initThemes(); - void handleZoomOnWindowStateChange(QWindowStateChangeEvent *ev); + void handleZoomOnWindowStateChange(const QWindowStateChangeEvent *ev); void handleZoom(); void changeLockPassword(); void forceLogOut(); diff --git a/src/webenginepage.cpp b/src/webenginepage.cpp index e27d928..849895e 100644 --- a/src/webenginepage.cpp +++ b/src/webenginepage.cpp @@ -133,12 +133,12 @@ void WebEnginePage::handleLoadFinished(bool ok) { QWebEnginePage::PermissionPolicy::PermissionGrantedByUser); } - if(ok){ - injectMutationObserver(); - injectPreventScrollWheelZoomHelper(); - injectFullWidthJavaScript(); - injectClassChangeObserver(); - injectNewChatJavaScript(); + if (ok) { + injectMutationObserver(); + injectPreventScrollWheelZoomHelper(); + injectFullWidthJavaScript(); + injectClassChangeObserver(); + injectNewChatJavaScript(); } } diff --git a/src/webview.cpp b/src/webview.cpp index cfd9af9..8029ffd 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -8,7 +8,7 @@ WebView::WebView(QWidget *parent, QStringList dictionaries) : QWebEngineView(parent) { - m_dictionaries = dictionaries; + dictionaries = dictionaries; QObject *parentMainWindow = this->parent(); while (!parentMainWindow->objectName().contains("MainWindow")) { @@ -49,18 +49,23 @@ WebView::WebView(QWidget *parent, QStringList dictionaries) } void WebView::wheelEvent(QWheelEvent *event) { - if (event->modifiers().testFlag(Qt::ControlModifier)) { + bool controlKeyIsHeld = + QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); + // this doesn't work, (even after checking the global QApplication keyboard + // modifiers) as expected, the Ctrl+wheel is managed by Chromium + // WebenginePage directly. So, we manage it by injecting js to page using + // WebEnginePage::injectPreventScrollWheelZoomHelper + if ((event->modifiers() & Qt::ControlModifier) != 0 || controlKeyIsHeld) { qDebug() << "skipped ctrl + m_wheel event on webengineview"; - // do nothing + event->ignore(); } else { - qDebug() << "wheel event on webengine view"; QWebEngineView::wheelEvent(event); } } void WebView::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = page()->createStandardContextMenu(); + auto menu = page()->createStandardContextMenu(); menu->setAttribute(Qt::WA_DeleteOnClose, true); // hide reload, back, forward, savepage, copyimagelink menus foreach (auto *action, menu->actions()) { @@ -87,29 +92,27 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) { return; } - QWebEngineProfile *profile = page()->profile(); - const QStringList &languages = profile->spellCheckLanguages(); - + auto pageWebengineProfile = page()->profile(); + const QStringList &languages = pageWebengineProfile->spellCheckLanguages(); menu->addSeparator(); - - QAction *spellcheckAction = new QAction(tr("Check Spelling"), menu); + auto *spellcheckAction = new QAction(tr("Check Spelling"), menu); spellcheckAction->setCheckable(true); - spellcheckAction->setChecked(profile->isSpellCheckEnabled()); + spellcheckAction->setChecked(pageWebengineProfile->isSpellCheckEnabled()); connect(spellcheckAction, &QAction::toggled, this, - [profile, this](bool toogled) { - profile->setSpellCheckEnabled(toogled); + [pageWebengineProfile, this](bool toogled) { + pageWebengineProfile->setSpellCheckEnabled(toogled); settings.setValue("sc_enabled", toogled); }); menu->addAction(spellcheckAction); - if (profile->isSpellCheckEnabled()) { - QMenu *subMenu = menu->addMenu(tr("Select Language")); - for (const QString &dict : qAsConst(m_dictionaries)) { - QAction *action = subMenu->addAction(dict); + if (pageWebengineProfile->isSpellCheckEnabled()) { + auto subMenu = menu->addMenu(tr("Select Language")); + for (const QString &dict : qAsConst(dictionaries)) { + auto action = subMenu->addAction(dict); action->setCheckable(true); action->setChecked(languages.contains(dict)); - connect(action, &QAction::triggered, this, [profile, dict, this]() { - profile->setSpellCheckLanguages(QStringList() << dict); + connect(action, &QAction::triggered, this, [pageWebengineProfile, dict, this]() { + pageWebengineProfile->setSpellCheckLanguages(QStringList() << dict); settings.setValue("sc_dict", dict); }); } diff --git a/src/webview.h b/src/webview.h index 81f5f43..e03fa49 100644 --- a/src/webview.h +++ b/src/webview.h @@ -18,7 +18,7 @@ protected slots: void wheelEvent(QWheelEvent *event); private: - QStringList m_dictionaries; + QStringList dictionaries; QSettings settings; }; |