-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatformintegration.cpp
More file actions
executable file
·162 lines (134 loc) · 4.54 KB
/
platformintegration.cpp
File metadata and controls
executable file
·162 lines (134 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "platformintegration.h"
#include <QDebug>
//Q_DECLARE_METATYPE(QList<QObject*>*);
PlatformIntegration::PlatformIntegration(QDeclarativeContext *ctx, QObject *parent) :
QObject(parent),
m_ctx(ctx),
m_updatingGalleryModel(false),
m_sparqlConnection(0),
m_sparqlQuery(0),
m_sparqlResult(0),
m_operatorlogo(0),
m_qsettings(0)
{
m_qsettings = new QSettings;
//m_galleryModel = new GalleryModel(new GalleryItem(""), this);
m_list = new QList<QObject*>();
m_sparqlConnection = new QSparqlConnection("QTRACKER");
m_sparqlQuery = new QSparqlQuery("select nie:url(?photo) nfo:width(?photo) nfo:height(?photo) where { ?photo a nmm:Photo . } ");
m_operatorlogo = new GConfItem("/desktop/meego/screen_lock/low_power_mode/operator_logo");
connect(m_operatorlogo, SIGNAL(valueChanged()), this, SLOT(operatorLogoChangedSlot()));
qDebug() << __PRETTY_FUNCTION__ << "Status:" << m_qsettings->fileName();
}
PlatformIntegration::~PlatformIntegration()
{
qDebug() << __PRETTY_FUNCTION__;
if(m_sparqlConnection) delete m_sparqlConnection;
if(m_operatorlogo) delete m_operatorlogo;
if(m_qsettings) delete m_qsettings;
}
QList<QObject*>* PlatformIntegration::galleryModel() const
{
qDebug() << __PRETTY_FUNCTION__ << m_list;
return m_list;
}
bool PlatformIntegration::firstLaunchDone() const
{
QVariant ret = m_qsettings->value("firstlaunchDone");
return ret.toBool();
}
void PlatformIntegration::setFirstLaunchDone()
{
qDebug() << __PRETTY_FUNCTION__;
m_qsettings->setValue("firstlaunchDone", true);
m_qsettings->sync();
qDebug() << __PRETTY_FUNCTION__ << "Status:" << m_qsettings->status();
}
bool PlatformIntegration::updating() const
{
return m_updatingGalleryModel;
}
void PlatformIntegration::updateGallery()
{
qDebug() << __PRETTY_FUNCTION__;
if(m_updatingGalleryModel) return;
m_updatingGalleryModel = true;
emit updatingChanged();
m_sparqlResult = m_sparqlConnection->exec(*m_sparqlQuery);
bool ok = connect(m_sparqlResult, SIGNAL(finished()), this, SLOT(sparqlFinished()), Qt::UniqueConnection);
Q_ASSERT(ok); Q_UNUSED(ok);
emit galleryModelChanged();
}
void PlatformIntegration::sparqlFinished()
{
qDebug() << __PRETTY_FUNCTION__;
if(m_sparqlResult) {
m_list->clear();
while(m_sparqlResult->next()) {
QString path = m_sparqlResult->binding(0).value().toString();
if(path.startsWith("file:")) {
path = QUrl::fromPercentEncoding(path.toUtf8());
path = path.right(path.length() - 7);
}
if(m_list) {
m_list->insert(0, new GalleryItem(path));
}
}
}
addNoLogo();
m_updatingGalleryModel = false;
m_ctx->setContextProperty("platformGalleryModel", QVariant::fromValue(*m_list));
emit updatingChanged();
}
int PlatformIntegration::indexOf(const QString& path)
{
qDebug() << __PRETTY_FUNCTION__ << path;
int index = -1;
if(!m_list) return index;
if(path == "") return 0;
QString p = path;
p = p.remove("file://");
qDebug() << p;
for(int i = 0; i < m_list->size(); i++) {
GalleryItem* item = qobject_cast<GalleryItem*>(m_list->at(i));
if(item) {
if(item->filepath() == p) {
index = i;
break;
}
}
}
return index;
}
void PlatformIntegration::addNoLogo()
{
qDebug() << __PRETTY_FUNCTION__;
if(m_list /*&& operatorLogo() != ""*/) {
//if(m_list->at(0)->filepath() != "/opt/lpmcustomizer/no-logo.png") {
m_list->insert(0, new GalleryItem("/opt/lpmcustomizer/no-logo.png"));
m_list->insert(1, new GalleryItem("/home/user/lpmlogo.png"));
//emit galleryModelChanged();
//}
}
}
void PlatformIntegration::operatorLogoChangedSlot()
{
qDebug() << __PRETTY_FUNCTION__ << m_operatorlogo->value();
emit operatorLogoChanged();
}
void PlatformIntegration::setOperatorLogo(const QString &path)
{
qDebug() << __PRETTY_FUNCTION__ << path;
m_operatorlogo->set(path);
}
QString PlatformIntegration::operatorLogo() const
{
return m_operatorlogo->value().toString();
}
void PlatformIntegration::onImageSaved(const QString &path)
{
setOperatorLogo("");
setOperatorLogo(path);
m_ctx->setContextProperty("platformGalleryModel", QVariant::fromValue(*m_list));
emit galleryModelChanged();
}