Skip to content

Commit

Permalink
Add ApplicationInfo and first time dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Iktwo committed Sep 27, 2016
1 parent 215a3dd commit 6444eea
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ ApplicationWindow {
}
}

Loader {
id: loaderMainTheme

anchors.fill: parent
source: "themes/tiles/ThemeMain.qml"
}

Loader {
id: loader

Expand All @@ -111,8 +118,7 @@ ApplicationWindow {

anchors.fill: parent

/// TODO: load only if this has never been displayed
// sourceComponent: introView
sourceComponent: !QL.ApplicationInfo.hasShownInitialDialog ? introView : undefined

Component {
id: introView
Expand All @@ -131,7 +137,10 @@ ApplicationWindow {
ListElement { name: "IntroEnd.qml"; backgroundColor: "#2c3e50" }
}

onDone: loader.unload()
onDone: {
QL.ApplicationInfo.hasShownInitialDialog = true
loader.unload()
}
}
}

Expand Down Expand Up @@ -167,13 +176,6 @@ ApplicationWindow {
source: QL.ScreenValues.navBarVisible ? "qrc:/images/shadow_navigationbar" : ""
}

Loader {
id: loaderMainTheme

anchors.fill: parent
source: "themes/classic/ThemeMain.qml"
}

// D.Debug {
// debugData: {
// 'sdkInt': QL.System.sdkInt,
Expand Down
106 changes: 106 additions & 0 deletions src/src/applicationinfo.cpp
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
}

47 changes: 47 additions & 0 deletions src/src/applicationinfo.h
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
14 changes: 12 additions & 2 deletions src/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <QThread>
#include <QDebug>

#include "packagemanager.h"
#include "applicationinfo.h"
#include "iconimageprovider.h"
#include "screenvalues.h"
#include "launcher.h"
#include "packagemanager.h"
#include "screenvalues.h"
#include "system.h"

static QObject *package_manager_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
Expand Down Expand Up @@ -46,6 +47,14 @@ static QObject *system_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
return new System();
}

static QObject *application_info_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)

return new ApplicationInfo();
}

int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(new QApplication(argc, argv));
Expand All @@ -59,6 +68,7 @@ int main(int argc, char *argv[])
QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));

qmlRegisterSingletonType<PackageManager>("com.iktwo.qutelauncher", 1, 0, "PackageManager", package_manager_provider);
qmlRegisterSingletonType<ApplicationInfo>("com.iktwo.qutelauncher", 1, 0, "ApplicationInfo", application_info_provider);
qmlRegisterSingletonType<ScreenValues>("com.iktwo.qutelauncher", 1, 0, "ScreenValues", screen_values_provider);
qmlRegisterSingletonType<System>("com.iktwo.qutelauncher", 1, 0, "System", system_provider);
qmlRegisterSingletonType<Launcher>("com.iktwo.qutelauncher", 1, 0, "Launcher", launcher_provider);
Expand Down

0 comments on commit 6444eea

Please sign in to comment.