aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar keshavbhatt <keshavnrj@gmail.com>2021-05-05 02:47:48 +0530
committerLibravatar keshavbhatt <keshavnrj@gmail.com>2021-05-05 02:47:48 +0530
commit45f7260d85197a6d6fc82f9058bdb00941e471ab (patch)
treef4e90a89a3207b7528cf95cd6ac6307174f9c6ce
parenta11a1df736dc275f6df57a2a4ff007090f89ace2 (diff)
downloadwhatsie-45f7260d85197a6d6fc82f9058bdb00941e471ab.tar.gz
whatsie-45f7260d85197a6d6fc82f9058bdb00941e471ab.zip
added rate app dialog
-rw-r--r--src/WhatsApp.pro5
-rw-r--r--src/rateapp.cpp120
-rw-r--r--src/rateapp.h49
-rw-r--r--src/rateapp.ui98
4 files changed, 271 insertions, 1 deletions
diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro
index 552540a..2c9a11b 100644
--- a/src/WhatsApp.pro
+++ b/src/WhatsApp.pro
@@ -1,6 +1,6 @@
#-------------------------------------------------
#
-# Project created by QtCreator 2020-03-26T13:53:21
+# Project created by QtCreator Wed Apr 7 02:25:15 IST 2021
#
#-------------------------------------------------
@@ -58,6 +58,7 @@ SOURCES += \
main.cpp \
mainwindow.cpp \
permissiondialog.cpp \
+ rateapp.cpp \
rungaurd.cpp \
settingswidget.cpp \
utils.cpp \
@@ -81,6 +82,7 @@ HEADERS += \
mainwindow.h \
notificationpopup.h \
permissiondialog.h \
+ rateapp.h \
requestinterceptor.h \
rungaurd.h \
settingswidget.h \
@@ -99,6 +101,7 @@ FORMS += \
lock.ui \
passworddialog.ui \
permissiondialog.ui \
+ rateapp.ui \
settingswidget.ui
DISTFILES += \
diff --git a/src/rateapp.cpp b/src/rateapp.cpp
new file mode 100644
index 0000000..03926e2
--- /dev/null
+++ b/src/rateapp.cpp
@@ -0,0 +1,120 @@
+#include "rateapp.h"
+#include "ui_rateapp.h"
+#include <QDebug>
+#include <QMetaEnum>
+
+RateApp::RateApp(QWidget *parent, QString app_rating_url, int app_launch_count, int app_install_days, int present_delay) :
+ QWidget(parent),
+ ui(new Ui::RateApp)
+{
+ ui->setupUi(this);
+
+ this->app_rating_url= app_rating_url; // Url to open when rating button clicked
+ this->app_launch_count = app_launch_count; // How many time the app must be launched by user to show this dialog
+ this->app_install_days = app_install_days; // How many days the app must be installed by user to show this dialog
+ this->present_delay = present_delay; // Delay after which this dialog should be shown to use if all conditions matched
+
+ showTimer = new QTimer(this);
+ showTimer->setInterval(this->present_delay);
+ connect(showTimer,&QTimer::timeout,[=](){
+ qDebug()<<"Rate timer timeout";
+ emit showRateDialog();
+ if(this->isVisible())
+ showTimer->stop();
+ });
+
+ //increase the app_launched_count by one
+ int app_launched = settings.value("app_launched_count",0).toInt();
+ settings.setValue("app_launched_count",app_launched + 1);
+
+ //check if app install time is set in settings
+ if(settings.value("app_install_time").isNull())
+ {
+ settings.setValue("app_install_time",QDateTime::currentSecsSinceEpoch());
+
+ }else if (settings.value("app_install_time").isValid())
+ {
+ qDebug()<<"RATEAPP should show:"<<shouldShow();
+ if(shouldShow()){
+ showTimer->start();
+ }else {
+ //if shouldshow is false, delete this obj to free resources
+ this->deleteLater();
+ }
+ }
+
+ //if already reated delete this obj to free resources
+ if(settings.value("rated_already",false).toBool())
+ {
+ this->deleteLater();
+ }
+}
+
+void RateApp::delayShowEvent()
+{
+ showTimer->start();
+
+ qDebug()<<"Timer running"<<showTimer->isActive()<<showTimer->interval()<<
+ showTimer->isSingleShot();
+ qDebug()<<"App was minimized and was not visible, "
+ "hence delaying the showevent of RateApp dialog by "
+ <<this->showTimer->interval()/1000<<"seconds";
+}
+
+/**
+ * @brief RateApp::shouldShow
+ * @return true, if the dialog should be shown to user
+ */
+bool RateApp::shouldShow()
+{
+ bool shouldShow = false;
+ int app_launched_count = settings.value("app_launched_count",0).toInt();
+ qint64 currentDateTime = QDateTime::currentSecsSinceEpoch();
+ qint64 installed_date_time = settings.value("app_install_time").toLongLong();
+ bool ratedAlready = settings.value("rated_already",false).toBool();
+
+ shouldShow = (((currentDateTime - installed_date_time > app_install_days * 86400) ||
+ app_launched_count >= this->app_launch_count)
+ && ratedAlready == false);
+
+ return shouldShow;
+}
+
+RateApp::~RateApp()
+{
+ qDebug()<<"RateApp Obj deleted";
+ showTimer->disconnect();
+ showTimer->deleteLater();
+ delete ui;
+}
+
+
+void RateApp::on_rateNowBtn_clicked()
+{
+ QDesktopServices::openUrl(QUrl(app_rating_url));
+ settings.setValue("app_launched_count",0);
+ settings.setValue("app_install_time",QDateTime::currentSecsSinceEpoch());
+ this->close();
+}
+
+void RateApp::on_alreadyDoneBtn_clicked()
+{
+ settings.setValue("rated_already",true);
+ this->close();
+}
+
+void RateApp::on_laterBtn_clicked()
+{
+ settings.setValue("rated_already",false);
+ settings.setValue("app_launched_count",0);
+ settings.setValue("app_install_time",QDateTime::currentSecsSinceEpoch());
+ this->close();
+}
+
+void RateApp::closeEvent(QCloseEvent *event)
+{
+ settings.setValue("rated_already",false);
+ settings.setValue("app_launched_count",0);
+ settings.setValue("app_install_time",QDateTime::currentSecsSinceEpoch());
+ QWidget::closeEvent(event);
+}
diff --git a/src/rateapp.h b/src/rateapp.h
new file mode 100644
index 0000000..7b23214
--- /dev/null
+++ b/src/rateapp.h
@@ -0,0 +1,49 @@
+#ifndef RATEAPP_H
+#define RATEAPP_H
+
+#include <QWidget>
+#include <QSettings>
+#include <QDateTime>
+#include <QUrl>
+#include <QDesktopServices>
+#include <QTimer>
+
+namespace Ui {
+class RateApp;
+}
+
+class RateApp : public QWidget
+{
+ Q_OBJECT
+
+signals:
+ void showRateDialog();
+
+public:
+ explicit RateApp(QWidget *parent = nullptr , QString app_rating_url = "",
+ int app_launch_count = 5, int app_install_days = 5, int present_delay = 5000);
+ ~RateApp();
+
+public slots:
+ void delayShowEvent();
+protected slots:
+ void closeEvent(QCloseEvent *event);
+private slots:
+ void on_rateNowBtn_clicked();
+
+ void on_alreadyDoneBtn_clicked();
+
+ void on_laterBtn_clicked();
+
+ bool shouldShow();
+private:
+ Ui::RateApp *ui;
+ QString app_rating_url;
+ int app_launch_count;
+ int app_install_days;
+ int present_delay;
+ QSettings settings;
+ QTimer *showTimer;
+};
+
+#endif // RATEAPP_H
diff --git a/src/rateapp.ui b/src/rateapp.ui
new file mode 100644
index 0000000..9243daa
--- /dev/null
+++ b/src/rateapp.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>RateApp</class>
+ <widget class="QWidget" name="RateApp">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>424</width>
+ <height>189</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>12</pointsize>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Rate this app</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If you enjoy using this app, would you mind taking a moment to rate it?&lt;/p&gt;&lt;p&gt;It won't take more than a minute. Thanks you for your support!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="laterBtn">
+ <property name="text">
+ <string>Later</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="alreadyDoneBtn">
+ <property name="styleSheet">
+ <string notr="true"/>
+ </property>
+ <property name="text">
+ <string> Already Done </string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="rateNowBtn">
+ <property name="text">
+ <string> Rate Now </string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>