diff options
-rw-r--r-- | src/main.cpp | 222 | ||||
-rw-r--r-- | src/mainwindow.cpp | 180 | ||||
-rw-r--r-- | src/mainwindow.h | 31 | ||||
-rw-r--r-- | src/settingswidget.cpp | 43 | ||||
-rw-r--r-- | src/settingswidget.h | 9 |
5 files changed, 348 insertions, 137 deletions
diff --git a/src/main.cpp b/src/main.cpp index 88731a6..ffbb1a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,16 +13,6 @@ int main(int argc, char *argv[]) { - QStringList args; - for (int i = 0; i < argc; i++) - args << QString(argv[i]); - - if (args.contains("-v") || args.contains("--version")) { - qInfo() << QString("version: %1, branch: %2, commit: %3, built_at: %4") - .arg(VERSIONSTR, GIT_BRANCH, GIT_HASH, BUILD_TIMESTAMP); - return 0; - } - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) && @@ -38,20 +28,110 @@ int main(int argc, char *argv[]) { qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --single-process"); #endif - SingleApplication app(argc, argv, true); - app.setQuitOnLastWindowClosed(false); - app.setWindowIcon(QIcon(":/icons/app/icon-128.png")); + SingleApplication instance(argc, argv, true); + //instance.setQuitOnLastWindowClosed(false); + instance.setWindowIcon(QIcon(":/icons/app/icon-128.png")); QApplication::setApplicationName("WhatSie"); + QApplication::setOrganizationDomain("com.ktechpit"); QApplication::setOrganizationName("org.keshavnrj.ubuntu"); QApplication::setApplicationVersion(VERSIONSTR); + QCommandLineParser parser; + parser.setApplicationDescription( + QObject::tr("Feature rich WhatsApp web client based on Qt WebEngine")); + + QList<QCommandLineOption> secondaryInstanceCLIOptions; + + QCommandLineOption showCLIHelpOption( + QStringList() << "h" + << "help", + QObject::tr("Displays help on commandline options")); + + QCommandLineOption openSettingsOption( + QStringList() << "s" + << "open-settings", + QObject::tr("Opens Settings dialog in a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption lockAppOption(QStringList() << "l" + << "lock-app", + QObject::tr("Locks a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption openAboutOption( + QStringList() << "i" + << "open-about", + QObject::tr("Opens About dialog in a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption toggleThemeOption( + QStringList() << "t" + << "toggle-theme", + QObject::tr( + "Toggle between dark & light theme in a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption reloadAppOption( + QStringList() << "r" + << "reload-app", + QObject::tr("Reload the app in a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption newChatOption( + QStringList() << "n" + << "new-chat", + QObject::tr("Open new chat prompt in a running instance of ") + + QApplication::applicationName()); + + QCommandLineOption buildInfoOption(QStringList() << "b" + << "build-info", + "Shows detailed current build infomation"); + + QCommandLineOption showAppWindowOption( + QStringList() << "w" + << "show-window", + QObject::tr("Show main window of running instance of ") + + QApplication::applicationName()); + + parser.addOption(showCLIHelpOption); // [x] + parser.addVersionOption(); // [x] + parser.addOption(buildInfoOption); // [x] + parser.addOption(showAppWindowOption); // [x] + parser.addOption(openSettingsOption); // [x] + parser.addOption(lockAppOption); // [x] + parser.addOption(openAboutOption); // [x] + parser.addOption(toggleThemeOption); // [x] + parser.addOption(reloadAppOption); // [x] + parser.addOption(newChatOption); // [x] + + secondaryInstanceCLIOptions << showAppWindowOption << openSettingsOption + << lockAppOption << openAboutOption + << toggleThemeOption << reloadAppOption + << newChatOption; + + parser.process(instance); + + if (parser.isSet(showCLIHelpOption)) { + parser.showHelp(); + } + + if (parser.isSet(buildInfoOption)) { + + qInfo().noquote() + << parser.applicationDescription() << "\n" + << QStringLiteral("version: %1, branch: %2, commit: %3, built_at: %4") + .arg(VERSIONSTR, GIT_BRANCH, GIT_HASH, BUILD_TIMESTAMP); + return 0; + } + // if secondary instance is invoked - if (app.isSecondary()) { - app.sendMessage(app.arguments().join(' ').toUtf8()); - qInfo() << QApplication::applicationName() + - " is already running with PID:" + - QString::number(app.primaryPid()) + "; by USER: " - << app.primaryUser(); + if (instance.isSecondary()) { + instance.sendMessage(instance.arguments().join(' ').toUtf8()); + qInfo().noquote() << QApplication::applicationName() + + " is already running with PID: " + + QString::number(instance.primaryPid()) + + " by USER:" + << instance.primaryUser(); return 0; } @@ -64,41 +144,113 @@ int main(int argc, char *argv[]) { QWebEngineSettings::defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true); - MainWindow window; + MainWindow whatsie; // else QObject::connect( - &app, &SingleApplication::receivedMessage, - [&window](int instanceId, QByteArray message) { - qInfo() << "Another instance with PID: " + QString::number(instanceId) + - ", sent argument: " + message; + &instance, &SingleApplication::receivedMessage, &whatsie, + [&whatsie, &secondaryInstanceCLIOptions](int instanceId, + QByteArray message) { + qInfo().noquote() << "Another instance with PID: " + + QString::number(instanceId) + + ", sent argument: " + message; QString messageStr = QTextCodec::codecForMib(106)->toUnicode(message); - if (messageStr.contains("whatsapp://whatsie", Qt::CaseInsensitive)) { - window.show(); + + QCommandLineParser p; + p.addOptions(secondaryInstanceCLIOptions); + p.parse(QStringList(messageStr.split(" "))); + + if (p.isSet("s")) { + qInfo() << "cmd:" + << "OpenAppSettings"; + whatsie.alreadyRunning(); + whatsie.showSettings(true); + return; + } + + if (p.isSet("l")) { + qInfo() << "cmd:" + << "LockApp"; + whatsie.alreadyRunning(); + QSettings settings; + if (!settings.value("asdfg").isValid()) { + whatsie.notify( + QApplication::applicationName(), + QObject::tr("App lock is not configured, \n" + "Please setup the password in the Settings " + "first.")); + } else { + whatsie.lockApp(); + } + return; + } + + if (p.isSet("i")) { + qInfo() << "cmd:" + << "OpenAppAbout"; + whatsie.alreadyRunning(); + whatsie.showAbout(); + return; + } + + if (p.isSet("t")) { + qInfo() << "cmd:" + << "ToggleAppTheme"; + whatsie.alreadyRunning(); + whatsie.toggleTheme(); return; - } else if (messageStr.contains("whatsapp://", Qt::CaseInsensitive)) { + } + + if (p.isSet("r")) { + qInfo() << "cmd:" + << "ReloadApp"; + whatsie.alreadyRunning(); + whatsie.doReload(false, true); + return; + } + + if (p.isSet("n")) { + qInfo() << "cmd:" + << "OpenNewChatPrompt"; + whatsie.alreadyRunning(); + whatsie.newChat(); //TODO: invetigate the crash + return; + } + + if (p.isSet("w")) { + qInfo() << "cmd:" + << "ShowAppWindow"; + whatsie.alreadyRunning(); + whatsie.show(); + return; + } + + if (messageStr.contains("whatsapp://", Qt::CaseInsensitive)) { QString urlStr = "whatsapp://" + messageStr.split("whatsapp://").last(); - window.loadAppWithArgument(urlStr); + qInfo() << "cmd:" + << "x-schema-handler"; + whatsie.loadSchemaUrl(urlStr); } else { - window.alreadyRunning(true); + whatsie.alreadyRunning(true); } }); - QStringList argsList = app.arguments(); - foreach (QString argStr, argsList) { + foreach (QString argStr, instance.arguments()) { if (argStr.contains("whatsapp://")) { - window.loadAppWithArgument(argStr); + qInfo() << "cmd:" + << "x-schema-handler"; + whatsie.loadSchemaUrl(argStr); } } QSettings settings; if (QSystemTrayIcon::isSystemTrayAvailable() && settings.value("startMinimized", false).toBool()) { - window.runMinimized(); + whatsie.runMinimized(); } else { - window.show(); + whatsie.show(); } - return app.exec(); + return instance.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 553115a..2baaf4b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -28,7 +28,7 @@ MainWindow::MainWindow(QWidget *parent) createActions(); createTrayIcon(); createWebEngine(); - init_settingWidget(); + initSettingWidget(); initRateWidget(); tryLock(); updateWindowTheme(); @@ -151,7 +151,7 @@ void MainWindow::runMinimized() { MainWindow::~MainWindow() { webEngine->deleteLater(); } -void MainWindow::loadAppWithArgument(const QString &arg) { +void MainWindow::loadSchemaUrl(const QString &arg) { // https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app/?lang=en // PASSED SCHEME whatsapp://send?text=Hello%2C%20World!&phone=919568388397" @@ -267,7 +267,7 @@ void MainWindow::tryLogOut() { } } -void MainWindow::init_settingWidget() { +void MainWindow::initSettingWidget() { int screenNumber = qApp->desktop()->screenNumber(this); if (settingsWidget == nullptr) { settingsWidget = new SettingsWidget( @@ -277,9 +277,9 @@ void MainWindow::init_settingWidget() { " | Settings"); settingsWidget->setWindowFlags(Qt::Dialog); - connect(settingsWidget, SIGNAL(init_lock()), this, SLOT(init_lock())); - connect(settingsWidget, SIGNAL(change_lock_password()), this, - SLOT(change_lock_password())); + connect(settingsWidget, SIGNAL(initLock()), this, SLOT(initLock())); + connect(settingsWidget, SIGNAL(changeLockPassword()), this, + SLOT(changeLockPassword())); connect(settingsWidget, SIGNAL(appAutoLockChanged()), this, SLOT(appAutoLockChanged())); @@ -410,34 +410,40 @@ void MainWindow::handleZoom() { } void MainWindow::lockApp() { - if (lockWidget != nullptr && lockWidget->isLocked) + if (lockWidget != nullptr && lockWidget->getIsLocked()) return; if (settings.value("asdfg").isValid()) { - init_lock(); + initLock(); lockWidget->lock_app(); } else { - 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(this->style()->standardIcon(QStyle::SP_DialogYesButton), - "Yes", nullptr); - msgBox.addButton(setAppLock, QMessageBox::NoRole); - connect(setAppLock, &QPushButton::clicked, setAppLock, - [=]() { init_lock(); }); - msgBox.exec(); + int ret = QMessageBox::information( + this, tr(QApplication::applicationName().toUtf8()), + tr("App lock is not configured, \n" + "Please setup the password in the Settings first.\n\nOpen " + "Application Settings now?"), + QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); + if (ret == QMessageBox::Yes) { + this->showSettings(); + } + } +} + +void MainWindow::toggleTheme() { + if (settingsWidget != nullptr) { + settingsWidget->toggleTheme(); } } -void MainWindow::showSettings() { - if (lockWidget && lockWidget->isLocked) { - QMessageBox::critical(this, QApplication::applicationName() + "| Error", - "UnLock Application to access Settings."); +void MainWindow::showSettings(bool isAskedByCLI) { + if (lockWidget && lockWidget->getIsLocked()) { + QString error = tr("UnLock Application to access Settings."); + if (isAskedByCLI) { + this->notify(QApplication::applicationName() + "| Error", error); + } else { + QMessageBox::critical(this, QApplication::applicationName() + "| Error", + error); + } this->show(); return; } @@ -573,7 +579,9 @@ void MainWindow::createActions() { reloadAction = new QAction(tr("Re&load"), this); reloadAction->setShortcut(Qt::Key_F5); - connect(reloadAction, &QAction::triggered, this, &MainWindow::doReload); + connect(reloadAction, &QAction::triggered,this, [=]{ + this->doReload(); + }); addAction(reloadAction); lockAction = new QAction(tr("Loc&k"), this); @@ -582,7 +590,15 @@ void MainWindow::createActions() { addAction(lockAction); settingsAction = new QAction(tr("&Settings"), this); + settingsAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_P)); connect(settingsAction, &QAction::triggered, this, &MainWindow::showSettings); + addAction(settingsAction); + + toggleThemeAction = new QAction(tr("&Toggle theme"), this); + toggleThemeAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_T)); + connect(toggleThemeAction, &QAction::triggered, this, + &MainWindow::toggleTheme); + addAction(toggleThemeAction); aboutAction = new QAction(tr("&About"), this); connect(aboutAction, &QAction::triggered, this, &MainWindow::showAbout); @@ -612,6 +628,7 @@ void MainWindow::createTrayIcon() { trayIconMenu->addAction(lockAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(openUrlAction); + trayIconMenu->addAction(toggleThemeAction); trayIconMenu->addAction(settingsAction); trayIconMenu->addAction(aboutAction); trayIconMenu->addSeparator(); @@ -619,8 +636,7 @@ void MainWindow::createTrayIcon() { trayIcon = new QSystemTrayIcon(trayIconRead, this); trayIcon->setContextMenu(trayIconMenu); - connect(trayIconMenu, SIGNAL(aboutToShow()), this, - SLOT(check_window_state())); + connect(trayIconMenu, SIGNAL(aboutToShow()), this, SLOT(checkWindowState())); trayIcon->show(); @@ -637,54 +653,56 @@ void MainWindow::createTrayIcon() { } } -void MainWindow::init_lock() { +void MainWindow::initLock() { 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()); + lockWidget->setWindowFlags(Qt::Widget); + lockWidget->setStyleSheet( + "QWidget#login{background-color:palette(window)};" + "QWidget#signup{background-color:palette(window)}"); + lockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect(lockWidget, &Lock::passwordNotSet, settingsWidget, [=]() { - settings.setValue("lockscreen", false); - settingsWidget->appLockSetChecked(false); - }); + connect(lockWidget, &Lock::passwordNotSet, settingsWidget, [=]() { + settings.setValue("lockscreen", false); + settingsWidget->appLockSetChecked(false); + }); - connect(lockWidget, &Lock::unLocked, [=]() { - // unlock event - }); + connect(lockWidget, &Lock::unLocked, [=]() { + // unlock event + }); + + connect(lockWidget, &Lock::passwordSet, settingsWidget, [=]() { + if (settings.value("asdfg").isValid()) { + settingsWidget->setCurrentPasswordText(QByteArray::fromBase64( + settings.value("asdfg").toString().toUtf8())); + } else { + settingsWidget->setCurrentPasswordText("Require setup"); + } + settingsWidget->appLockSetChecked( + settings.value("lockscreen", false).toBool()); + }); + lockWidget->applyThemeQuirks(); + } + + lockWidget->setGeometry(this->rect()); - connect(lockWidget, &Lock::passwordSet, settingsWidget, [=]() { + if (settings.value("lockscreen").toBool()) { if (settings.value("asdfg").isValid()) { - settingsWidget->setCurrentPasswordText( - QByteArray::fromBase64(settings.value("asdfg").toString().toUtf8())); + lockWidget->lock_app(); } else { - settingsWidget->setCurrentPasswordText("Require setup"); + lockWidget->signUp(); } - settingsWidget->appLockSetChecked( - settings.value("lockscreen", false).toBool()); - }); - - lockWidget->applyThemeQuirks(); - lockWidget->show(); - if (settings.value("asdfg").isValid() && - settings.value("lockscreen").toBool()) { - lockWidget->lock_app(); - } else if (settings.value("lockscreen").toBool() && - !settings.value("asdfg").isValid()) { - lockWidget->signUp(); + lockWidget->show(); } else { lockWidget->hide(); } updateWindowTheme(); } -void MainWindow::change_lock_password() { +void MainWindow::changeLockPassword() { settings.remove("asdfg"); settingsWidget->appLockSetChecked(false); settingsWidget->autoAppLockSetChecked(false); @@ -696,7 +714,7 @@ void MainWindow::change_lock_password() { doAppReload(); } appAutoLockChanged(); - init_lock(); + initLock(); }); } @@ -715,7 +733,7 @@ void MainWindow::appAutoLockChanged() { } // check window state and set tray menus -void MainWindow::check_window_state() { +void MainWindow::checkWindowState() { QObject *tray_icon_menu = this->findChild<QObject *>("trayIconMenu"); if (tray_icon_menu != nullptr) { if (this->isVisible()) { @@ -725,7 +743,7 @@ 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) { + if (lockWidget && lockWidget->getIsLocked()) { ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(true); } else { ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(false); @@ -733,7 +751,7 @@ void MainWindow::check_window_state() { } } -void MainWindow::init_globalWebProfile() { +void MainWindow::initGlobalWebProfile() { QWebEngineProfile *profile = QWebEngineProfile::defaultProfile(); profile->setHttpUserAgent( @@ -771,7 +789,7 @@ void MainWindow::init_globalWebProfile() { } void MainWindow::createWebEngine() { - init_globalWebProfile(); + initGlobalWebProfile(); QSizePolicy widgetSize; widgetSize.setHorizontalPolicy(QSizePolicy::Expanding); @@ -933,7 +951,9 @@ void MainWindow::handleLoadFinished(bool loaded) { injectFullWidthJavaScript(); injectClassChangeObserver(); injectNewChatJavaScript(); - settingsWidget->refresh(); + if (settingsWidget != nullptr) { + settingsWidget->refresh(); + } } } @@ -1130,7 +1150,7 @@ void MainWindow::newChat() { else QMessageBox::information(this, QApplication::applicationName() + "| Error", - "Invalid Phone Number"); + tr("Invalid Phone Number")); } } @@ -1161,7 +1181,20 @@ bool MainWindow::isPhoneNumber(const QString &phoneNumber) { return reg.match(phoneNumber).hasMatch(); } -void MainWindow::doReload(bool byPassCache) { +void MainWindow::doReload(bool byPassCache, bool isAskedByCLI) { + if (lockWidget && !lockWidget->getIsLocked()) { + this->notify(QApplication::applicationName(), QObject::tr("Reloading...")); + } else { + QString error = tr("UnLock Application to Reload the App."); + if (isAskedByCLI) { + this->notify(QApplication::applicationName() + "| Error", error); + } else { + QMessageBox::critical(this, QApplication::applicationName() + "| Error", + error); + } + this->show(); + return; + } this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, byPassCache); } @@ -1188,19 +1221,24 @@ QString MainWindow::getPageTheme() { void MainWindow::tryLock() { if (settings.value("asdfg").isValid() && settings.value("lockscreen", false).toBool()) { - init_lock(); + initLock(); + return; } if (settings.value("asdfg").isValid() == false) { settings.setValue("lockscreen", false); + settings.setValue("appAutoLocking", false); + settingsWidget->appAutoLockingSetChecked(false); settingsWidget->appLockSetChecked(false); - init_lock(); + initLock(); } } void MainWindow::alreadyRunning(bool notify) { - this->show(); if (notify) { QString appname = QApplication::applicationName(); this->notify(appname, "Restored an already running instance."); } + this->setWindowState((this->windowState() & ~Qt::WindowMinimized) | + Qt::WindowActive); + this->show(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 4c2c1b8..f8a4ff5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -25,6 +25,7 @@ #include <QWebEngineView> #include "about.h" +#include "autolockeventfilter.h" #include "dictionaries.h" #include "downloadmanagerwidget.h" #include "lock.h" @@ -34,7 +35,6 @@ #include "settingswidget.h" #include "webenginepage.h" #include "webview.h" -#include "autolockeventfilter.h" class MainWindow : public QMainWindow { Q_OBJECT @@ -44,13 +44,19 @@ public: public slots: void updateWindowTheme(); void updatePageTheme(); - void handleWebViewTitleChanged(QString title); void handleLoadFinished(bool loaded); void handleDownloadRequested(QWebEngineDownloadItem *download); - void loadAppWithArgument(const QString &arg); + void loadSchemaUrl(const QString &arg); + void showSettings(bool isAskedByCLI = false); + void showAbout(); + void lockApp(); void runMinimized(); void alreadyRunning(bool notify = false); + void notify(QString title, QString message); + void toggleTheme(); + void doReload(bool byPassCache = false, bool isAskedByCLI = false); + void newChat(); protected slots: void closeEvent(QCloseEvent *event) override; void resizeEvent(QResizeEvent *event) override; @@ -72,6 +78,7 @@ private: QAction *restoreAction; QAction *aboutAction; QAction *settingsAction; + QAction *toggleThemeAction; QAction *quitAction; QAction *lockAction; QAction *fullscreenAction; @@ -93,10 +100,6 @@ private slots: QString getPageTheme(); void iconActivated(QSystemTrayIcon::ActivationReason reason); void messageClicked(); - void doReload(bool byPassCache = false); - void showAbout(); - void notify(QString title, QString message); - void showSettings(); void handleCookieAdded(const QNetworkCookie &cookie); void toggleMute(const bool &checked); void doAppReload(); @@ -104,23 +107,21 @@ private slots: void updateSettingsUserAgentWidget(); void fullScreenRequested(QWebEngineFullScreenRequest request); void createWebPage(bool offTheRecord = false); - void init_settingWidget(); - void init_globalWebProfile(); - void check_window_state(); - void init_lock(); - void lockApp(); + void initSettingWidget(); + void initGlobalWebProfile(); + void checkWindowState(); + void initLock(); + void tryLock(); void checkLoadedCorrectly(); void loadingQuirk(QString test); void setNotificationPresenter(QWebEngineProfile *profile); - void newChat(); bool isPhoneNumber(const QString &phoneNumber); void quitApp(); void initRateWidget(); void initThemes(); void handleZoomOnWindowStateChange(QWindowStateChangeEvent *ev); void handleZoom(); - void change_lock_password(); - void tryLock(); + void changeLockPassword(); void forceLogOut(); void tryLogOut(); bool isLoggedIn(); diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp index b272565..80d9047 100644 --- a/src/settingswidget.cpp +++ b/src/settingswidget.cpp @@ -56,8 +56,8 @@ SettingsWidget::SettingsWidget(QWidget *parent, int screenNumber, ui->startMinimized->setChecked( settings.value("startMinimized", false).toBool()); - ui->appAutoLockcheckBox->setChecked( - settings.value("appAutoLocking", defaultAppAutoLock).toBool()); + this->appAutoLockingSetChecked(settings.value("appAutoLocking", defaultAppAutoLock).toBool()); + ui->autoLockDurationSpinbox->setValue( settings.value("autoLockDuration", defaultAppAutoLockDuration).toInt()); ui->minimizeOnTrayIconClick->setChecked( @@ -77,7 +77,8 @@ SettingsWidget::SettingsWidget(QWidget *parent, int screenNumber, settings.value("widgetStyle", "Fusion").toString()); ui->fullWidthViewCheckbox->blockSignals(true); - ui->fullWidthViewCheckbox->setChecked(settings.value("fullWidthView", true).toBool()); + ui->fullWidthViewCheckbox->setChecked( + settings.value("fullWidthView", true).toBool()); ui->fullWidthViewCheckbox->blockSignals(false); ui->automaticThemeCheckBox->blockSignals(true); @@ -125,8 +126,8 @@ SettingsWidget::SettingsWidget(QWidget *parent, int screenNumber, if (settings.value("settingsGeo").isValid()) { this->restoreGeometry(settings.value("settingsGeo").toByteArray()); QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry(); - if(!screenRect.contains(this->pos())){ - this->move(screenRect.center()-this->rect().center()); + if (!screenRect.contains(this->pos())) { + this->move(screenRect.center() - this->rect().center()); } } } @@ -422,6 +423,26 @@ void SettingsWidget::appLockSetChecked(bool checked) { ui->applock_checkbox->blockSignals(false); } +void SettingsWidget::appAutoLockingSetChecked(bool checked) { + ui->appAutoLockcheckBox->blockSignals(true); + ui->appAutoLockcheckBox->setChecked(checked); + ui->appAutoLockcheckBox->blockSignals(false); +} + +void SettingsWidget::toggleTheme() +{ + //disable automatic theme first + if(settings.value("automaticTheme", false).toBool()){ + emit notify(tr("Automatic theme switching was disabled due to manual theme toggle.")); + ui->automaticThemeCheckBox->setChecked(false); + } + if(ui->themeComboBox->currentIndex() == 0){ + ui->themeComboBox->setCurrentIndex(1); + }else{ + ui->themeComboBox->setCurrentIndex(0); + } +} + void SettingsWidget::setCurrentPasswordText(QString str) { ui->current_password->setStyleSheet( "QLineEdit[echoMode=\"2\"]{lineedit-password-character: 9899}"); @@ -458,7 +479,7 @@ void SettingsWidget::showSetApplockPasswordDialog() { int ret = msgBox.exec(); if (ret == QMessageBox::Yes) { this->close(); - emit init_lock(); + emit initLock(); } else { ui->applock_checkbox->blockSignals(true); ui->applock_checkbox->setChecked(false); @@ -725,7 +746,7 @@ void SettingsWidget::on_chnageCurrentPasswordPushButton_clicked() { msgBox.addButton(changePassword, QMessageBox::NoRole); connect(changePassword, &QPushButton::clicked, changePassword, [=]() { this->close(); - emit change_lock_password(); + emit changeLockPassword(); }); msgBox.exec(); @@ -735,9 +756,7 @@ void SettingsWidget::on_chnageCurrentPasswordPushButton_clicked() { } } -void SettingsWidget::on_fullWidthViewCheckbox_toggled(bool checked) -{ - settings.setValue("fullWidthView", checked); - emit updateFullWidthView(checked); +void SettingsWidget::on_fullWidthViewCheckbox_toggled(bool checked) { + settings.setValue("fullWidthView", checked); + emit updateFullWidthView(checked); } - diff --git a/src/settingswidget.h b/src/settingswidget.h index 3e76b20..8e8eab8 100644 --- a/src/settingswidget.h +++ b/src/settingswidget.h @@ -20,8 +20,8 @@ signals: void muteToggled(const bool checked); void autoPlayMediaToggled(const bool checked); void userAgentChanged(QString userAgentStr); - void init_lock(); - void change_lock_password(); + void initLock(); + void changeLockPassword(); void dictChanged(QString dict); void spellCheckChanged(bool checked); void notificationPopupTimeOutChanged(); @@ -43,10 +43,11 @@ public slots: void appLockSetChecked(bool checked); void setCurrentPasswordText(QString str); void loadDictionaries(QStringList dictionaries); - void clearAllData(); void autoAppLockSetChecked(bool checked); void updateAppLockPasswordViewer(); + void appAutoLockingSetChecked(bool checked); + void toggleTheme(); protected slots: bool eventFilter(QObject *obj, QEvent *event); void closeEvent(QCloseEvent *event); @@ -54,6 +55,7 @@ protected slots: private slots: QString cachePath(); QString persistentStoragePath(); + void showSetApplockPasswordDialog(); bool isChildOf(QObject *Of, QObject *self); void applyThemeQuirks(); void on_appAutoLockcheckBox_toggled(bool checked); @@ -92,7 +94,6 @@ private slots: void on_zoomPlus_clicked(); void on_zoomResetMaximized_clicked(); void on_zoomReset_clicked(); - void showSetApplockPasswordDialog(); void themeSwitchTimerTimeout(); void updateAutomaticTheme(); |