-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ApplicationInfo and first time dialog
- Loading branch information
Showing
4 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include "applicationinfo.h" | ||
|
||
#include <QSettings> | ||
#include <QDebug> | ||
|
||
#ifdef Q_OS_ANDROID | ||
#include <QAndroidJniEnvironment> | ||
#include <QAndroidJniObject> | ||
#endif | ||
|
||
ApplicationInfo::ApplicationInfo(QObject *parent) : | ||
QObject(parent), | ||
m_timesLaunched(0), | ||
m_hasShownInitialDialog(false) | ||
{ | ||
QSettings settings; | ||
m_timesLaunched = settings.value("timesLaunched", 0).toInt(); | ||
m_hasShownInitialDialog = settings.value("hasShownInitialDialog", false).toBool(); | ||
|
||
m_firstTimeLaunched = settings.value("firstTimeLaunched", QDate::fromString("20000101", "yyyyMMdd")).toDate(); | ||
|
||
if (m_firstTimeLaunched.toString("yyyyMMdd") == "20000101") | ||
setFirstTimeLaunched(QDate::currentDate()); | ||
|
||
m_OSVersion = getOSVersion(); | ||
setTimesLaunched(m_timesLaunched + 1); | ||
} | ||
|
||
int ApplicationInfo::timesLaunched() const | ||
{ | ||
return m_timesLaunched; | ||
} | ||
|
||
void ApplicationInfo::setTimesLaunched(int timesLaunched) | ||
{ | ||
if (m_timesLaunched == timesLaunched) | ||
return; | ||
|
||
m_timesLaunched = timesLaunched; | ||
|
||
QSettings settings; | ||
settings.setValue("timesLaunched", m_timesLaunched); | ||
|
||
emit timesLaunchedChanged(); | ||
} | ||
|
||
QDate ApplicationInfo::firstTimeLaunched() const | ||
{ | ||
return m_firstTimeLaunched; | ||
} | ||
|
||
void ApplicationInfo::setFirstTimeLaunched(const QDate &firstTimeLaunched) | ||
{ | ||
if (m_firstTimeLaunched == firstTimeLaunched) | ||
return; | ||
|
||
m_firstTimeLaunched = firstTimeLaunched; | ||
|
||
QSettings settings; | ||
settings.setValue("firstTimeLaunched", m_firstTimeLaunched); | ||
|
||
emit firstTimeLaunchedChanged(); | ||
} | ||
|
||
bool ApplicationInfo::hasShownInitialDialog() const | ||
{ | ||
return m_hasShownInitialDialog; | ||
} | ||
|
||
void ApplicationInfo::setHasShownInitialDialog(bool hasShownInitialDialog) | ||
{ | ||
if (m_hasShownInitialDialog == hasShownInitialDialog) | ||
return; | ||
|
||
m_hasShownInitialDialog = hasShownInitialDialog; | ||
|
||
QSettings settings; | ||
settings.setValue("hasShownInitialDialog", m_hasShownInitialDialog); | ||
|
||
emit hasShownInitialDialogChanged(); | ||
} | ||
|
||
int ApplicationInfo::OSVersion() const | ||
{ | ||
return m_OSVersion; | ||
} | ||
|
||
void ApplicationInfo::setOSVersion(int version) | ||
{ | ||
if (m_OSVersion == version) | ||
return; | ||
|
||
m_OSVersion = version; | ||
emit OSVersionChanged(); | ||
} | ||
|
||
int ApplicationInfo::getOSVersion() | ||
{ | ||
#ifdef Q_OS_ANDROID | ||
jint version = QAndroidJniObject::getStaticField<jint>("android.os.Build$VERSION", "SDK_INT"); | ||
return version; | ||
#else | ||
return -1; | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef APPLICATIONINFO_H | ||
#define APPLICATIONINFO_H | ||
|
||
#include <QObject> | ||
#include <QDate> | ||
|
||
class ApplicationInfo : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(int timesLaunched READ timesLaunched NOTIFY timesLaunchedChanged) | ||
Q_PROPERTY(QDate firstTimeLaunched READ firstTimeLaunched NOTIFY firstTimeLaunchedChanged) | ||
Q_PROPERTY(bool hasShownInitialDialog READ hasShownInitialDialog WRITE setHasShownInitialDialog NOTIFY hasShownInitialDialogChanged) | ||
Q_PROPERTY(int OSVersion READ OSVersion WRITE setOSVersion NOTIFY OSVersionChanged) | ||
|
||
public: | ||
ApplicationInfo(QObject *parent = 0); | ||
|
||
int timesLaunched() const; | ||
void setTimesLaunched(int timesLaunched); | ||
|
||
QDate firstTimeLaunched() const; | ||
void setFirstTimeLaunched(const QDate &firstTimeLaunched); | ||
|
||
bool hasShownInitialDialog() const; | ||
void setHasShownInitialDialog(bool hasShownInitialDialog); | ||
|
||
int OSVersion() const; | ||
void setOSVersion(int version); | ||
|
||
signals: | ||
void timesLaunchedChanged(); | ||
void firstTimeLaunchedChanged(); | ||
void hasShownInitialDialogChanged(); | ||
void OSVersionChanged(); | ||
|
||
private: | ||
int m_timesLaunched; | ||
QDate m_firstTimeLaunched; | ||
bool m_hasShownInitialDialog; | ||
int m_OSVersion; | ||
|
||
int getOSVersion(); | ||
|
||
}; | ||
|
||
#endif // APPLICATIONINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters