aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar keshavbhatt <keshavnrj@gmail.com>2021-04-11 02:03:36 +0530
committerLibravatar keshavbhatt <keshavnrj@gmail.com>2021-04-11 02:03:36 +0530
commit9f096f17f19dfdae57d51d81343cb4fecb5beb34 (patch)
tree363bb4bbaffde37e59e6bc36b772693d3f6e1692
parentc988b866d56dc7e99097567b9ce400c4a5f94394 (diff)
downloadwhatsie-9f096f17f19dfdae57d51d81343cb4fecb5beb34.tar.gz
whatsie-9f096f17f19dfdae57d51d81343cb4fecb5beb34.zip
code clean up and theme switching issue fix, notification pop-up theme fix.
-rw-r--r--src/mainwindow.cpp98
-rw-r--r--src/mainwindow.h11
2 files changed, 44 insertions, 65 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 678cd2d..41b6429 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -13,14 +13,17 @@ MainWindow::MainWindow(QWidget *parent)
trayIconRead(":/icons/app/whatsapp.svg"),
trayIconUnread(":/icons/app/whatsapp-message.svg")
{
+ this->setObjectName("MainWindow");
+
qApp->setQuitOnLastWindowClosed(false);
+ lightPalette = qApp->palette();
+
setWindowTitle(QApplication::applicationName());
setWindowIcon(QIcon(":/icons/app/icon-256.png"));
setMinimumWidth(800);
setMinimumHeight(600);
-
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
@@ -29,7 +32,6 @@ MainWindow::MainWindow(QWidget *parent)
createTrayIcon();
createWebEngine();
-
if(settings.value("lockscreen",false).toBool())
{
init_lock();
@@ -51,7 +53,6 @@ MainWindow::MainWindow(QWidget *parent)
// quit application if the download manager window is the only remaining window
m_downloadManagerWidget.setAttribute(Qt::WA_QuitOnClose, false);
- lightPalette = qApp->palette();
updateWindowTheme();
}
@@ -83,7 +84,6 @@ void MainWindow::updateWindowTheme()
{
if(settings.value("windowTheme","light").toString() == "dark")
{
-
qApp->setStyle(QStyleFactory::create("fusion"));
QPalette palette;
palette.setColor(QPalette::Window,QColor("#262D31")); //whatsapp dark color
@@ -117,11 +117,12 @@ void MainWindow::updateWindowTheme()
qApp->setPalette(lightPalette);
}
+ setNotificationPresenter(webEngine->page()->profile());
+
if(lockWidget!=nullptr)
{
lockWidget->setStyleSheet("QWidget#login{background-color:palette(window)};"
- "QWidget#signup{background-color:palette(window)};"
- );
+ "QWidget#signup{background-color:palette(window)};");
lockWidget->applyThemeQuirks();
}
this->update();
@@ -301,7 +302,6 @@ void MainWindow::notify(QString title,QString message)
popup->style()->polish(qApp);
popup->setMinimumWidth(300);
popup->adjustSize();
- popup->update();
popup->present(title,message,QPixmap(":/icons/app/icon-64.png"));
}
@@ -503,47 +503,16 @@ void MainWindow::createWebEngine()
webEngine->show();
this->webEngine = webEngine;
- //webEngine->setContextMenuPolicy(Qt::CustomContextMenu);
webEngine->addAction(minimizeAction);
webEngine->addAction(lockAction);
webEngine->addAction(quitAction);
- connect(webEngine, &QWebEngineView::titleChanged,
- this, &MainWindow::handleWebViewTitleChanged);
- connect(webEngine, &QWebEngineView::loadStarted,
- this, &MainWindow::handleLoadStarted);
- connect(webEngine, &QWebEngineView::loadProgress,
- this, &MainWindow::handleLoadProgress);
- connect(webEngine, &QWebEngineView::loadFinished,
- this, &MainWindow::handleLoadFinished);
- connect(webEngine, &QWebEngineView::renderProcessTerminated,
- [this](QWebEnginePage::RenderProcessTerminationStatus termStatus, int statusCode) {
- QString status;
- switch (termStatus) {
- case QWebEnginePage::NormalTerminationStatus:
- status = tr("Render process normal exit");
- break;
- case QWebEnginePage::AbnormalTerminationStatus:
- status = tr("Render process abnormal exit");
- break;
- case QWebEnginePage::CrashedTerminationStatus:
- status = tr("Render process crashed");
- break;
- case QWebEnginePage::KilledTerminationStatus:
- status = tr("Render process killed");
- break;
- }
- QMessageBox::StandardButton btn = QMessageBox::question(window(), status,
- tr("Render process exited with code: %1\n" "Do you want to reload the page ?").arg(statusCode));
- if (btn == QMessageBox::Yes)
- QTimer::singleShot(0, [this] { this->webEngine->reload(); });
- });
+ createWebPage(false);
- QWebEngineCookieStore *browser_cookie_store = webEngine->page()->profile()->cookieStore();
+ QWebEngineCookieStore *browser_cookie_store = this->webEngine->page()->profile()->cookieStore();
connect( browser_cookie_store, &QWebEngineCookieStore::cookieAdded, this, &MainWindow::handleCookieAdded );
- createWebPage(false);
}
void MainWindow::createWebPage(bool offTheRecord)
@@ -552,7 +521,6 @@ void MainWindow::createWebPage(bool offTheRecord)
{
m_otrProfile.reset(new QWebEngineProfile);
}
-
auto profile = offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
QStringList dict_names;
@@ -560,26 +528,9 @@ void MainWindow::createWebPage(bool offTheRecord)
profile->setSpellCheckEnabled(settings.value("sc_enabled",true).toBool());
profile->setSpellCheckLanguages(dict_names);
-
profile->setHttpUserAgent(settings.value("useragent",defaultUserAgentStr).toString());
- auto popup = new NotificationPopup(webEngine);
- connect(popup,&NotificationPopup::notification_clicked,[=](){
- if(windowState()==Qt::WindowMinimized || windowState()!=Qt::WindowActive){
- activateWindow();
- raise();
- showNormal();
- }
- });
- profile->setNotificationPresenter([=] (std::unique_ptr<QWebEngineNotification> notification)
- {
- if(settings.value("disableNotificationPopups",false).toBool() == true){
- return;
- }
- popup->setMinimumWidth(300);
- popup->update();
- popup->present(notification);
- });
+ setNotificationPresenter(profile);
QWebEnginePage *page = new WebEnginePage(profile,webEngine);
if(settings.value("windowTheme","light").toString() == "dark"){
@@ -597,7 +548,6 @@ void MainWindow::createWebPage(bool offTheRecord)
qsrand(time(NULL));
auto randomValue = qrand() % 300;
page->setUrl(QUrl("https://web.whatsapp.com?v="+QString::number(randomValue)));
- //page->setUrl(QUrl("http://ktechpit.com/USS/text.html"));
connect(profile, &QWebEngineProfile::downloadRequested,
&m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
@@ -605,6 +555,34 @@ void MainWindow::createWebPage(bool offTheRecord)
this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest)));
}
+void MainWindow::setNotificationPresenter(QWebEngineProfile* profile)
+{
+ auto *op = webEngine->findChild<NotificationPopup*>("engineNotifier");
+ if( op != nullptr){
+ op->close();
+ op->deleteLater();
+ }
+
+ auto popup = new NotificationPopup(webEngine);
+ popup->setObjectName("engineNotifier");
+ connect(popup,&NotificationPopup::notification_clicked,[=](){
+ if(windowState()==Qt::WindowMinimized || windowState()!=Qt::WindowActive){
+ activateWindow();
+ raise();
+ showNormal();
+ }
+ });
+
+ profile->setNotificationPresenter([=] (std::unique_ptr<QWebEngineNotification> notification)
+ {
+ if(settings.value("disableNotificationPopups",false).toBool() == true){
+ return;
+ }
+ popup->setMinimumWidth(300);
+ popup->present(notification);
+ });
+}
+
void MainWindow::fullScreenRequested(QWebEngineFullScreenRequest request)
{
if (request.toggleOn())
diff --git a/src/mainwindow.h b/src/mainwindow.h
index db8e958..75948e9 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -46,6 +46,11 @@ public slots:
void updateWindowTheme();
void updatePageTheme();
+ void handleWebViewTitleChanged(QString title);
+ void handleLoadStarted();
+ void handleLoadProgress(int progress);
+ void handleLoadFinished(bool loaded);
+ void handleDownloadRequested(QWebEngineDownloadItem *download);
protected slots:
void closeEvent(QCloseEvent *event) override;
@@ -94,10 +99,6 @@ private:
private slots:
- void handleWebViewTitleChanged(QString title);
- void handleLoadStarted();
- void handleLoadProgress(int progress);
- void handleDownloadRequested(QWebEngineDownloadItem *download);
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void messageClicked();
void doReload();
@@ -105,7 +106,6 @@ private slots:
void notify(QString title, QString message);
void showSettings();
void handleCookieAdded(const QNetworkCookie &cookie);
- void handleLoadFinished(bool loaded);
QString getPageTheme();
void toggleMute(const bool checked);
@@ -124,6 +124,7 @@ private slots:
void checkLoadedCorrectly();
void loadingQuirk(QString test);
+ void setNotificationPresenter(QWebEngineProfile *profile);
};
#endif // MAINWINDOW_H