aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2021-05-30 20:46:40 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2021-05-30 20:46:40 +0530
commit6045235c1d9a2dfd91d593a9d62b2f5fa09b8c8c (patch)
tree0e85239a43e4b4b81e9748d0ccdeeb5315477e19 /src/mainwindow.cpp
parentdbb6a8311ca0270ddaa2416f6a159ac354ff95f1 (diff)
downloadwhatsie-6045235c1d9a2dfd91d593a9d62b2f5fa09b8c8c.tar.gz
whatsie-6045235c1d9a2dfd91d593a9d62b2f5fa09b8c8c.zip
fixed theme switch issue
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index de208ef..d63b1d4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,5 +1,6 @@
#include "mainwindow.h"
+#include <QInputDialog>
#include <QRegularExpression>
#include <QStyleHints>
#include <QWebEngineNotification>
@@ -314,7 +315,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
{
settings.setValue("geometry", saveGeometry());
settings.setValue("windowState", saveState());
- settings.setValue("windowTheme",getPageTheme());
+
+// getPageTheme();
+// QTimer::singleShot(500,[=](){
+// qWarning()<<"THEME"<<settings.value("windowTheme").toString();
+// });
if(QSystemTrayIcon::isSystemTrayAvailable() && settings.value("closeButtonActionCombo",0).toInt() == 0){
this->hide();
@@ -366,6 +371,12 @@ void MainWindow::notify(QString title,QString message)
void MainWindow::createActions()
{
+
+ openUrlAction = new QAction("New Chat",this);
+ this->addAction(openUrlAction);
+ openUrlAction->setShortcut(QKeySequence(Qt::Modifier::CTRL+Qt::Key_N));
+ connect(openUrlAction,&QAction::triggered,this,&MainWindow::newChat);
+
fullscreenAction = new QAction(tr("Fullscreen"),this);
fullscreenAction->setShortcut(Qt::Key_F11);
connect(fullscreenAction, &QAction::triggered,[=](){
@@ -404,11 +415,20 @@ void MainWindow::createActions()
quitAction = new QAction(tr("&Quit"), this);
quitAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_Q));
- connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
+ connect(quitAction, &QAction::triggered,this,&MainWindow::quitApp);
addAction(quitAction);
this->addAction(quitAction);
}
+void MainWindow::quitApp()
+{
+ getPageTheme();
+ QTimer::singleShot(800,[=](){
+ qWarning()<<"THEME"<<settings.value("windowTheme").toString();
+ qApp->quit();
+ });
+}
+
void MainWindow::createTrayIcon()
{
trayIconMenu = new QMenu(this);
@@ -819,6 +839,28 @@ void MainWindow::doAppReload()
createWebPage(false);
}
+void MainWindow::newChat()
+{
+ bool ok;
+ QString text = QInputDialog::getText(this, tr("New Chat"),
+ tr("Enter a valid WhatsApp number you want to chat with."), QLineEdit::Normal,
+ "",&ok);
+ if (ok && isPhoneNumber(text)){
+ qWarning()<<"Opening new Chat with"<<text;
+ this->webEngine->page()->load(QUrl("https://web.whatsapp.com/send?phone="+text));
+ }else{
+ QMessageBox::information(this,QApplication::applicationName()+"| Error",
+ "Invalid Phone Number");
+ }
+}
+
+bool MainWindow::isPhoneNumber(const QString phoneNumber)
+{
+ const QString phone = "^((\\+?(\\d{2}))\\s?)?((\\d{2})|(\\((\\d{2})\\))\\s?)?(\\d{3,15})(\\-(\\d{3,15}))?$";
+ QRegularExpression reg(phone);
+ return reg.match(phoneNumber).hasMatch();
+}
+
void MainWindow::doReload()
{
this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, false);
@@ -837,8 +879,10 @@ QString MainWindow::getPageTheme()
{
webEngine->page()->runJavaScript(
"document.querySelector('body').className;",
- [](const QVariant &result){
+ [this](const QVariant &result){
theme = result.toString();
+ theme.contains("dark") ? theme = "dark" : theme = "light";
+ settings.setValue("windowTheme",theme);
}
);
}