From e0ac0208e700cf108f6295f66e2bb003fe53607b Mon Sep 17 00:00:00 2001 From: keshavbhatt Date: Mon, 5 Apr 2021 23:53:46 +0530 Subject: implemented new about dialog, app lock feature --- src/mainwindow.cpp | 220 ++++++++++++++++++++++++++++++------------------- src/mainwindow.h | 10 ++- src/settingswidget.cpp | 25 ++++++ src/settingswidget.h | 6 +- src/settingswidget.ui | 23 ++++-- 5 files changed, 191 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e30f393..69f792e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" +#include extern QString defaultUserAgentStr; @@ -9,17 +10,39 @@ MainWindow::MainWindow(QWidget *parent) trayIconRead(":/icons/app/whatsapp.svg"), trayIconUnread(":/icons/app/whatsapp-message.svg") { + qApp->setQuitOnLastWindowClosed(false); + setWindowTitle(QApplication::applicationName()); setWindowIcon(QIcon(":/icons/app/icon-256.png")); setMinimumWidth(800); setMinimumHeight(600); - readSettings(); + + + restoreGeometry(settings.value("geometry").toByteArray()); + restoreState(settings.value("windowState").toByteArray()); createActions(); createStatusBar(); createTrayIcon(); createWebEngine(); + + if(settings.value("lockscreen",false).toBool()) + { + init_lock(); + } + QTimer *timer = new QTimer(this); + timer->setInterval(1000); + connect(timer,&QTimer::timeout,[=](){ + if(settings.value("asdfg").isValid()){ + if(lockWidget && lockWidget->isLocked==false){ + timer->stop(); + //init_accountWidget(); + } + } + }); + timer->start(); + init_settingWidget(); lightPalette = qApp->palette(); @@ -27,8 +50,6 @@ MainWindow::MainWindow(QWidget *parent) // quit application if the download manager window is the only remaining window m_downloadManagerWidget.setAttribute(Qt::WA_QuitOnClose, false); - - } void MainWindow::updatePageTheme() @@ -48,11 +69,18 @@ void MainWindow::updatePageTheme() } } +void MainWindow::resizeEvent(QResizeEvent *event) +{ + if(lockWidget != nullptr){ + lockWidget->resize(event->size()); + } +} + void MainWindow::updateWindowTheme() { if(settings.value("windowTheme","light").toString() == "dark") { - //TODO make dark palette match whatsapp dark theme + qApp->setStyle(QStyleFactory::create("fusion")); QPalette palette; palette.setColor(QPalette::Window,QColor("#131C21")); //whatsapp dark color @@ -84,6 +112,13 @@ void MainWindow::updateWindowTheme() qApp->setPalette(lightPalette); this->update(); } + + if(lockWidget!=nullptr){ + lockWidget->setStyleSheet("QWidget#login{background-color:palette(window)};" + "QWidget#signup{background-color:palette(window)};" + ); + lockWidget->applyThemeQuirks(); + } } void MainWindow::handleCookieAdded(const QNetworkCookie &cookie) @@ -91,11 +126,6 @@ void MainWindow::handleCookieAdded(const QNetworkCookie &cookie) qDebug() << cookie.toRawForm() << "\n\n\n"; } -void MainWindow::readSettings() -{ - restoreGeometry(settings.value("geometry").toByteArray()); - restoreState(settings.value("windowState").toByteArray()); -} void MainWindow::init_settingWidget() { @@ -106,6 +136,7 @@ void MainWindow::init_settingWidget() settingsWidget->setWindowTitle(QApplication::applicationName()+" | Settings"); settingsWidget->setWindowFlags(Qt::Dialog); + connect(settingsWidget,SIGNAL(init_lock()),this,SLOT(init_lock())); connect(settingsWidget,SIGNAL(updateWindowTheme()),this,SLOT(updateWindowTheme())); connect(settingsWidget,SIGNAL(updatePageTheme()),this,SLOT(updatePageTheme())); connect(settingsWidget,&SettingsWidget::muteToggled,[=](const bool checked) @@ -131,11 +162,49 @@ void MainWindow::init_settingWidget() QWebEngineSettings::PlaybackRequiresUserGesture, checked); }); + + settingsWidget->appLockSetChecked(settings.value("lockscreen",false).toBool()); + settingsWidget->resize(settingsWidget->sizeHint().width(),settingsWidget->minimumSizeHint().height()); + } +} + +void MainWindow::lockApp() +{ + if(settings.value("asdfg").isValid() && settings.value("lockscreen").toBool()==false){ + QMessageBox::critical(this,QApplication::applicationName()+"| Error", + "Unable to lock App, Enable AppLock in settings First."); + this->show(); + return; + } + + if(settings.value("asdfg").isValid()){ + init_lock(); + }else{ + if(settings.value("asdfg").isValid() ==false){ + QMessageBox msgBox; + msgBox.setText("App lock is not configured."); + msgBox.setIconPixmap(QPixmap(":/icons/information-line.png").scaled(42,42,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + msgBox.setInformativeText("Do you want to setup App lock now ?"); + msgBox.setStandardButtons(QMessageBox::Cancel ); + QPushButton *setAppLock = new QPushButton("Yes",nullptr); + msgBox.addButton(setAppLock,QMessageBox::NoRole); + connect(setAppLock,&QPushButton::clicked,[=](){ + init_lock(); + }); + msgBox.exec(); + } } } void MainWindow::showSettings() { + if(lockWidget && lockWidget->isLocked){ + QMessageBox::critical(this,QApplication::applicationName()+"| Error", + "UnLock Application to access Settings."); + this->show(); + return; + } + if(webEngine == nullptr){ QMessageBox::critical(this,QApplication::applicationName()+"| Error", "Unable to initialize settings module.\nIs webengine initialized?"); @@ -166,44 +235,12 @@ void MainWindow::askToReloadPage() void MainWindow::showAbout() { - QDialog *aboutDialog = new QDialog(this,Qt::Dialog); - aboutDialog->setWindowModality(Qt::WindowModal); - QVBoxLayout *layout = new QVBoxLayout; - QLabel *message = new QLabel(aboutDialog); - layout->addWidget(message); - connect(message,&QLabel::linkActivated,[=](const QString linkStr){ - if(linkStr.contains("about_qt")){ - qApp->aboutQt(); - }else{ - QDesktopServices::openUrl(QUrl(linkStr)); - } - }); - aboutDialog->setLayout(layout); - aboutDialog->setAttribute(Qt::WA_DeleteOnClose,true); - aboutDialog->show(); - - QString mes = - "

" - "


" - "

Designed and Developed

" - "

by Keshav Bhatt <keshavnrj@gmail.com>

" - "

Website: https://ktechpit.com

" - "

Runtime: Qt Toolkit

" - "

Version: "+QApplication::applicationVersion()+"

" - "


" - "

More Apps

" - "


"; - - QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this); - message->setGraphicsEffect(eff); - QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity"); - a->setDuration(1000); - a->setStartValue(0); - a->setEndValue(1); - a->setEasingCurve(QEasingCurve::InCurve); - a->start(QPropertyAnimation::DeleteWhenStopped); - message->setText(mes); - message->show(); + About *about = new About(this); + about->setWindowFlag(Qt::Dialog); + about->adjustSize(); + about->setFixedSize(about->sizeHint()); + about->setAttribute(Qt::WA_DeleteOnClose); + about->show(); } void MainWindow::closeEvent(QCloseEvent *event) @@ -255,6 +292,11 @@ void MainWindow::createActions() connect(reloadAction, &QAction::triggered, this, &MainWindow::doReload); addAction(reloadAction); + lockAction = new QAction(tr("Lock"), this); + lockAction->setShortcut(QKeySequence(Qt::Key_Control,Qt::Key_L)); + connect(lockAction, &QAction::triggered, this, &MainWindow::lockApp); + addAction(lockAction); + settingsAction = new QAction(tr("Settings"), this); connect(settingsAction, &QAction::triggered, this, &MainWindow::showSettings); @@ -284,6 +326,7 @@ void MainWindow::createTrayIcon() trayIconMenu->addAction(restoreAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(reloadAction); + trayIconMenu->addAction(lockAction); trayIconMenu->addAction(settingsAction); trayIconMenu->addAction(aboutAction); trayIconMenu->addSeparator(); @@ -304,37 +347,42 @@ void MainWindow::createTrayIcon() void MainWindow::init_lock() { -// if(lockWidget==nullptr){ -// lockWidget = new Lock(this); -// lockWidget->setObjectName("lockWidget"); -// } -// lockWidget->setWindowFlags(Qt::Widget); -// lockWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); -// lockWidget->setGeometry(this->rect()); - -// connect(lockWidget,&Lock::passwordNotSet,[=](){ -// settings.setValue("lockscreen",false); -// ui->applock_checkbox->setChecked(false); -// }); - -// connect(lockWidget,&Lock::unLocked,[=]() -// { -// //unlock event -// }); - -// connect(lockWidget,&Lock::passwordSet,[=](){ -// //enable disable lock screen -// if(settings.value("asdfg").isValid()){ -// ui->current_password->setText("Current Password: "+QByteArray::fromBase64(settings.value("asdfg").toString().toUtf8())+""); -// }else{ -// ui->current_password->setText("Current Password: Require setup"); -// } -// ui->applock_checkbox->setChecked(settings.value("lockscreen",false).toBool()); -// }); -// lockWidget->show(); -// if(settings.value("asdfg").isValid() && settings.value("lockscreen").toBool()==true){ -// lockWidget->lock_app(); -// } + if(lockWidget==nullptr){ + lockWidget = new Lock(this); + lockWidget->setObjectName("lockWidget"); + } + lockWidget->setWindowFlags(Qt::Widget); + lockWidget->setStyleSheet("QWidget#login{background-color:palette(window)};" + "QWidget#signup{background-color:palette(window)}"); + lockWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + lockWidget->setGeometry(this->rect()); + + connect(lockWidget,&Lock::passwordNotSet,[=]() + { + settings.setValue("lockscreen",false); + settingsWidget->appLockSetChecked(false); + }); + + connect(lockWidget,&Lock::unLocked,[=]() + { + //unlock event + }); + + connect(lockWidget,&Lock::passwordSet,[=](){ + //enable disable lock screen + if(settings.value("asdfg").isValid()){ + settingsWidget->setCurrentPasswordText("Current Password: " + +QByteArray::fromBase64(settings.value("asdfg").toString().toUtf8())+""); + }else{ + settingsWidget->setCurrentPasswordText("Current Password: Require setup"); + } + settingsWidget->appLockSetChecked(settings.value("lockscreen",false).toBool()); + }); + lockWidget->applyThemeQuirks(); + lockWidget->show(); + if(settings.value("asdfg").isValid() && settings.value("lockscreen").toBool()==true){ + lockWidget->lock_app(); + } } //check window state and set tray menus @@ -349,6 +397,11 @@ void MainWindow::check_window_state() ((QMenu*)(tray_icon_menu))->actions().at(0)->setDisabled(true); ((QMenu*)(tray_icon_menu))->actions().at(1)->setDisabled(false); } + if(lockWidget && lockWidget->isLocked){ + ((QMenu*)(tray_icon_menu))->actions().at(4)->setDisabled(true); + }else{ + ((QMenu*)(tray_icon_menu))->actions().at(4)->setDisabled(false); + } } } @@ -464,12 +517,13 @@ void MainWindow::createWebPage(bool offTheRecord) QWebEnginePage *page = new WebEnginePage(profile,webEngine); if(settings.value("windowTheme","light").toString() == "dark"){ - page->setBackgroundColor(QColor("#131C21")); //whatsapp bg color + page->setBackgroundColor(QColor("#131C21")); //whatsapp dark bg color } webEngine->setPage(page); //page should be set parent of profile to prevent //Release of profile requested but WebEnginePage still not deleted. Expect troubles ! profile->setParent(page); + profile->setSpellCheckEnabled(true); //RequestInterceptor *interceptor = new RequestInterceptor(profile); //profile->setUrlRequestInterceptor(interceptor); page->setUrl(QUrl("https://web.whatsapp.com/")); @@ -518,6 +572,7 @@ void MainWindow::handleLoadStarted() void MainWindow::handleLoadFinished(bool loaded) { + statusBar->hide(); if(loaded){ updatePageTheme(); } @@ -525,14 +580,11 @@ void MainWindow::handleLoadFinished(bool loaded) void MainWindow::handleLoadProgress(int progress) { - if (progress >= 100) + statusBar->showMessage("Loading "+QString::number(progress)+"%"); + if (progress >= 50) { statusBar->hide(); } - else - { - statusBar->showMessage("Loading "+QString::number(progress)+"%"); - } } //unused direct method to download file without having entry in download manager diff --git a/src/mainwindow.h b/src/mainwindow.h index 67a783b..7614c5f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -29,6 +29,7 @@ #include "lock.h" #include "downloadmanagerwidget.h" +#include "about.h" class MainWindow : public QMainWindow @@ -39,9 +40,11 @@ public: public slots: void updateWindowTheme(); void updatePageTheme(); -protected: - void closeEvent(QCloseEvent *event) override; + +protected slots: + void closeEvent(QCloseEvent *event) override; + void resizeEvent(QResizeEvent *event); private: QPalette lightPalette; void createActions(); @@ -61,6 +64,7 @@ private: QAction *aboutAction; QAction *settingsAction; QAction *quitAction; + QAction *lockAction; QMenu *trayIconMenu; QSystemTrayIcon *trayIcon; @@ -81,7 +85,6 @@ private: private slots: - void readSettings(); void handleWebViewTitleChanged(QString title); void handleLoadStarted(); void handleLoadProgress(int progress); @@ -107,6 +110,7 @@ private slots: void init_globalWebProfile(); void check_window_state(); void init_lock(); + void lockApp(); }; #endif // MAINWINDOW_H diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp index 7f9a257..4a735b8 100644 --- a/src/settingswidget.cpp +++ b/src/settingswidget.cpp @@ -23,6 +23,9 @@ SettingsWidget::SettingsWidget(QWidget *parent, QString engineCachePath, QString ui->themeComboBox->setCurrentText(utils::toCamelCase(settings.value("windowTheme","light").toString())); ui->userAgentLineEdit->setText(settings.value("useragent",defaultUserAgentStr).toString()); + this->setCurrentPasswordText("Current Password: " + +QByteArray::fromBase64(settings.value("asdfg").toString().toUtf8())+""); + applyThemeQuirks(); ui->setUserAgent->setEnabled(false); @@ -187,3 +190,25 @@ void SettingsWidget::on_closeButtonActionComboBox_currentIndexChanged(int index) { settings.setValue("closeButtonActionCombo",index); } + +void SettingsWidget::appLockSetChecked(bool checked) +{ + ui->applock_checkbox->setChecked(checked); +} + +void SettingsWidget::setCurrentPasswordText(QString str) +{ + ui->current_password->setText(str); +} + +void SettingsWidget::on_applock_checkbox_toggled(bool checked) +{ + if(settings.value("asdfg").isValid()){ + settings.setValue("lockscreen",checked); + }else{ + settings.setValue("lockscreen",false); + } + if(checked){ + emit init_lock(); + } +} diff --git a/src/settingswidget.h b/src/settingswidget.h index a21a410..640f294 100644 --- a/src/settingswidget.h +++ b/src/settingswidget.h @@ -21,7 +21,7 @@ signals: void muteToggled(const bool checked); void autoPlayMediaToggled(const bool checked); void userAgentChanged(QString userAgentStr); - + void init_lock(); public: explicit SettingsWidget(QWidget *parent = nullptr,QString engineCachePath = "", QString enginePersistentStoragePath = ""); @@ -30,6 +30,8 @@ public: public slots: void refresh(); void updateDefaultUAButton(const QString engineUA); + void appLockSetChecked(bool checked); + void setCurrentPasswordText(QString str); private slots: QString cachePath(); QString persistentStoragePath(); @@ -57,6 +59,8 @@ private slots: void on_closeButtonActionComboBox_currentIndexChanged(int index); + void on_applock_checkbox_toggled(bool checked); + private: Ui::SettingsWidget *ui; QString engineCachePath,enginePersistentStoragePath; diff --git a/src/settingswidget.ui b/src/settingswidget.ui index 9a1c92c..1e8b647 100644 --- a/src/settingswidget.ui +++ b/src/settingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 553 - 478 + 554 + 565 @@ -83,7 +83,7 @@ background:transparent; - + @@ -98,7 +98,7 @@ background:transparent; 9 - + General settings @@ -249,7 +249,7 @@ background:transparent; - + Application Storage and Other Settings @@ -369,6 +369,19 @@ background:transparent; + + + + Qt::Vertical + + + + 20 + 40 + + + + -- cgit v1.2.3