aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild/linux/qspacestatusbin77200 -> 78208 bytes
-rw-r--r--img/qspace.blendbin0 -> 94001 bytes
-rw-r--r--img/qspacestatus.pngbin0 -> 162022 bytes
-rw-r--r--main.cpp1
-rw-r--r--mainwindow.cpp114
-rw-r--r--mainwindow.h17
-rw-r--r--mainwindow.ui289
-rw-r--r--qspace.qrc5
-rw-r--r--qspaceapi.pro6
9 files changed, 372 insertions, 60 deletions
diff --git a/build/linux/qspacestatus b/build/linux/qspacestatus
index 6598427..291fbee 100755
--- a/build/linux/qspacestatus
+++ b/build/linux/qspacestatus
Binary files differ
diff --git a/img/qspace.blend b/img/qspace.blend
new file mode 100644
index 0000000..37a979f
--- /dev/null
+++ b/img/qspace.blend
Binary files differ
diff --git a/img/qspacestatus.png b/img/qspacestatus.png
new file mode 100644
index 0000000..cf870aa
--- /dev/null
+++ b/img/qspacestatus.png
Binary files differ
diff --git a/main.cpp b/main.cpp
index 9b39d7c..0e12450 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,6 +9,7 @@ int main(int argc, char *argv[])
9 QApplication a(argc, argv); 9 QApplication a(argc, argv);
10 a.setOrganizationName("CoderOnline"); 10 a.setOrganizationName("CoderOnline");
11 a.setQuitOnLastWindowClosed(false); 11 a.setQuitOnLastWindowClosed(false);
12
12 MainWindow w; 13 MainWindow w;
13 14
14 15
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 55a9769..9385cd6 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -15,9 +15,9 @@ MainWindow::MainWindow(QWidget *parent) :
15 this->qsystemtrayicon->setContextMenu(ui->menuMenu1); 15 this->qsystemtrayicon->setContextMenu(ui->menuMenu1);
16 this->qsystemtrayicon->setToolTip(this->windowTitle()); 16 this->qsystemtrayicon->setToolTip(this->windowTitle());
17 this->connect(this->qsystemtrayicon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotActivated(QSystemTrayIcon::ActivationReason))); 17 this->connect(this->qsystemtrayicon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotActivated(QSystemTrayIcon::ActivationReason)));
18 this->updateStatus();
19 this->updateSpaceList();
20 18
19 this->updateSpaceList();
20 this->updateStatus();
21 21
22 22
23 this->timer = new QTimer(); 23 this->timer = new QTimer();
@@ -25,10 +25,15 @@ MainWindow::MainWindow(QWidget *parent) :
25 // update every five minutes... 25 // update every five minutes...
26 this->timer->start(60000 * 5); 26 this->timer->start(60000 * 5);
27 27
28 //this->pixmap = new QPixmap(120, 120);
29 //this->currentIcon = new QIcon(this->pixmap);
28} 30}
29 31
30MainWindow::~MainWindow() 32MainWindow::~MainWindow()
31{ 33{
34 qDebug() << "unloading application";
35 delete this->qsystemtrayicon;
36 delete this->timer;
32 delete ui; 37 delete ui;
33} 38}
34 39
@@ -40,6 +45,7 @@ void MainWindow::updateSpaceList()
40 QUrl url("http://spaceapi.net/directory.json"); 45 QUrl url("http://spaceapi.net/directory.json");
41 QJsonObject json = QJsonDocument::fromJson(this->download(url)).object(); 46 QJsonObject json = QJsonDocument::fromJson(this->download(url)).object();
42 47
48 ui->comboBox->setDisabled(true);
43 QJsonObject::Iterator it; 49 QJsonObject::Iterator it;
44 for(it=json.begin(); it!=json.end(); it++) 50 for(it=json.begin(); it!=json.end(); it++)
45 { 51 {
@@ -48,7 +54,18 @@ void MainWindow::updateSpaceList()
48 if(it.key() == defaultSpace) 54 if(it.key() == defaultSpace)
49 ui->comboBox->setCurrentIndex(ui->comboBox->count()-1); 55 ui->comboBox->setCurrentIndex(ui->comboBox->count()-1);
50 } 56 }
57 ui->comboBox->setDisabled(false);
58}
51 59
60QJsonObject json_find(QJsonObject json, QStringList list)
61{
62 QJsonObject retval = json;
63 foreach(const QString str, list)
64 if(retval.contains(str))
65 retval = retval[str].toObject();
66 else
67 return QJsonObject();
68 return retval;
52} 69}
53 70
54// lets not talk about memory leaks. yes, they are there. but it works somehow. 71// lets not talk about memory leaks. yes, they are there. but it works somehow.
@@ -59,14 +76,60 @@ void MainWindow::updateStatus()
59 ui->label_url_json->setText(ui->comboBox->currentData().toString()); 76 ui->label_url_json->setText(ui->comboBox->currentData().toString());
60 77
61 QUrl url(ui->comboBox->currentData().toString()); 78 QUrl url(ui->comboBox->currentData().toString());
62 QByteArray rawData = this->download(url); 79 QJsonDocument doc = QJsonDocument::fromJson(this->download(url));
63 //qDebug() << rawData; 80 //ui->plainTextEdit->setPlainText(doc.toJson(QJsonDocument::Indented));
64 QJsonDocument doc = QJsonDocument::fromJson(rawData);
65 ui->plainTextEdit->setPlainText(doc.toJson(QJsonDocument::Indented));
66 81
67 //qDebug() << doc.toJson(QJsonDocument::Indented); 82 //qDebug() << doc.toJson(QJsonDocument::Indented);
68 QJsonObject json = doc.object(); 83 QJsonObject json = doc.object();
84
85 foreach (QLabel *label, this->findChildren<QLabel*>())
86 {
87 if(label->statusTip().isEmpty())
88 continue;
89
90 label->clear();
91 //label->setText("");
92 QStringList list = label->statusTip().split("/");
93 QString name = list.takeLast();
94
95
96 QJsonObject obj = json_find(json, list);
97 if(!obj.isEmpty())
98 {
99 if(obj.value(name).isString())
100 {
101 QString result = obj.value(name).toString();
102 if(name == "logo" || result.endsWith(".png") || result.endsWith(".jpg"))
103 {
104 label->setPixmap(
105 QPixmap::fromImage(
106 QImage::fromData(
107 this->download(
108 QUrl(result)))).scaled(120, 120, Qt::KeepAspectRatio));
109 }
110 else if(result.contains("http"))
111 {
112 label->setText("<b>" + name + ":</b><br/><a href=\"" + result + "\">" + result + "</a> ");
113 label->setOpenExternalLinks(true);
114 }
115 else
116 label->setText("<b>" + name + ":</b><br/>" + result);
117 }
118 else
119 {
120 if(obj.value(name).isBool())
121 label->setText("<b>" + name + "</b>:<br/>" + (obj.value(name).toBool() ? "true" : "false"));
122 else if(name == "lastchange")
123 label->setText("<b>" + name + ":</b><br/>" + QDateTime::fromTime_t(obj.value(name).toInt()).toLocalTime().toString());
124 }
125
126 }
127
128 qDebug() << "NAME: " << name;
129 }
130
69 QString strUrl; 131 QString strUrl;
132
70 strUrl = json["state"].toObject() 133 strUrl = json["state"].toObject()
71 ["icon"].toObject() 134 ["icon"].toObject()
72 [json["state"].toObject()["open"].toBool() ? "open" : "closed"].toString(); 135 [json["state"].toObject()["open"].toBool() ? "open" : "closed"].toString();
@@ -77,18 +140,22 @@ void MainWindow::updateStatus()
77 140
78 141
79 qDebug() << "downloading: " << strUrl; 142 qDebug() << "downloading: " << strUrl;
80 this->imageArray = this->download(QUrl(strUrl)); 143 this->qsystemtrayicon->setIcon(QIcon(
81 //qDebug("test: " + imageArray.size()); 144 QPixmap::fromImage(
82 QImage image = QImage::fromData(imageArray); 145 QImage::fromData(
83 146 this->download(
84 this->currentIcon = new QIcon(QPixmap::fromImage(image)); 147 QUrl(strUrl)))).scaled(120, 120, Qt::KeepAspectRatio)));
85 this->qsystemtrayicon->setIcon(*currentIcon); 148
86 149 if(this->qsystemtrayicon->icon().isNull())
87 //QPixmap* pixmap = new QPixmap("/home/max/folder.png"); 150 {
88 QUrl logoURL(json["logo"].toString()); 151 if(json["state"].toObject().contains("open"))
89 //qDebug() << "logo: " << logoURL.toString(); 152 if(json["state"].toObject()["open"].toBool())
90 QPixmap pixmap = QPixmap::fromImage(QImage::fromData(this->download(logoURL))); 153 this->qsystemtrayicon->setIcon(QIcon::fromTheme("face-smile"));
91 ui->label_icon->setPixmap(pixmap.scaled(120, 120, Qt::KeepAspectRatio)); 154 else
155 this->qsystemtrayicon->setIcon(QIcon::fromTheme("face-sad"));
156 else
157 this->qsystemtrayicon->setIcon(QIcon::fromTheme("face-sick"));
158 }
92} 159}
93 160
94void MainWindow::saveSettings() 161void MainWindow::saveSettings()
@@ -96,8 +163,6 @@ void MainWindow::saveSettings()
96 this->qsettings.setValue("hackerspace", ui->comboBox->currentText()); 163 this->qsettings.setValue("hackerspace", ui->comboBox->currentText());
97} 164}
98 165
99
100
101QByteArray MainWindow::download(QUrl url) 166QByteArray MainWindow::download(QUrl url)
102{ 167{
103 qDebug() << "downloading: " << url.toString(); 168 qDebug() << "downloading: " << url.toString();
@@ -164,14 +229,17 @@ void MainWindow::slotActivated(QSystemTrayIcon::ActivationReason reason)
164void MainWindow::exitApplication() 229void MainWindow::exitApplication()
165{ 230{
166 qDebug() << "exit now!"; 231 qDebug() << "exit now!";
167 exit(0); 232 QApplication::quit();
168} 233}
169 234
170void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1) 235void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
171{ 236{
172 qDebug() << arg1; 237 qDebug() << arg1;
173 this->updateStatus(); 238 if(ui->comboBox->isEnabled())
174 this->saveSettings(); 239 {
240 this->updateStatus();
241 this->saveSettings();
242 }
175} 243}
176 244
177 245
diff --git a/mainwindow.h b/mainwindow.h
index 0ff1884..305b79b 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -9,6 +9,11 @@
9#include <QJsonArray> 9#include <QJsonArray>
10#include <QByteArray> 10#include <QByteArray>
11 11
12#include <QList>
13#include <QAbstractListModel>
14#include <QStringListModel>
15#include <QStandardItemModel>
16
12 17
13#include <QString> 18#include <QString>
14#include <QObject> 19#include <QObject>
@@ -20,6 +25,8 @@
20#include <QSettings> 25#include <QSettings>
21#include <QTimer> 26#include <QTimer>
22 27
28#include <QApplication>
29
23namespace Ui { 30namespace Ui {
24class MainWindow; 31class MainWindow;
25} 32}
@@ -33,14 +40,14 @@ public:
33 ~MainWindow(); 40 ~MainWindow();
34 41
35private: 42private:
36 Ui::MainWindow *ui; 43 Ui::MainWindow* ui;
44 QIcon* currentIcon;
37 QSystemTrayIcon* qsystemtrayicon; 45 QSystemTrayIcon* qsystemtrayicon;
38 QByteArray download(QUrl url);
39 QIcon* currentIcon;
40 QByteArray imageArray;
41 void saveSettings();
42 QSettings qsettings;\ 46 QSettings qsettings;\
43 QTimer* timer; 47 QTimer* timer;
48 void saveSettings();
49 QByteArray download(QUrl url);
50
44 51
45private slots: 52private slots:
46 void slotActivated(QSystemTrayIcon::ActivationReason); 53 void slotActivated(QSystemTrayIcon::ActivationReason);
diff --git a/mainwindow.ui b/mainwindow.ui
index 4bd49e4..be54347 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
6 <rect> 6 <rect>
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>952</width> 9 <width>927</width>
10 <height>497</height> 10 <height>532</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
13 <property name="sizePolicy"> 13 <property name="sizePolicy">
@@ -23,11 +23,11 @@
23 </size> 23 </size>
24 </property> 24 </property>
25 <property name="windowTitle"> 25 <property name="windowTitle">
26 <string>MainWindow</string> 26 <string>qhackerstatus</string>
27 </property> 27 </property>
28 <property name="windowIcon"> 28 <property name="windowIcon">
29 <iconset> 29 <iconset resource="qspace.qrc">
30 <normaloff>folder.png</normaloff>folder.png</iconset> 30 <normaloff>:/icons/img/qspacestatus.png</normaloff>:/icons/img/qspacestatus.png</iconset>
31 </property> 31 </property>
32 <widget class="QWidget" name="centralWidget"> 32 <widget class="QWidget" name="centralWidget">
33 <layout class="QVBoxLayout" name="verticalLayout"> 33 <layout class="QVBoxLayout" name="verticalLayout">
@@ -41,6 +41,9 @@
41 <verstretch>0</verstretch> 41 <verstretch>0</verstretch>
42 </sizepolicy> 42 </sizepolicy>
43 </property> 43 </property>
44 <property name="editable">
45 <bool>true</bool>
46 </property>
44 <property name="insertPolicy"> 47 <property name="insertPolicy">
45 <enum>QComboBox::InsertAlphabetically</enum> 48 <enum>QComboBox::InsertAlphabetically</enum>
46 </property> 49 </property>
@@ -79,7 +82,8 @@
79 <string>refresh</string> 82 <string>refresh</string>
80 </property> 83 </property>
81 <property name="icon"> 84 <property name="icon">
82 <iconset theme="view-refresh"/> 85 <iconset theme="view-refresh">
86 <normaloff>.</normaloff>.</iconset>
83 </property> 87 </property>
84 <property name="flat"> 88 <property name="flat">
85 <bool>false</bool> 89 <bool>false</bool>
@@ -103,9 +107,9 @@
103 </widget> 107 </widget>
104 </item> 108 </item>
105 <item> 109 <item>
106 <layout class="QHBoxLayout" name="horizontalLayout"> 110 <layout class="QVBoxLayout" name="verticalLayout_4">
107 <property name="leftMargin"> 111 <property name="leftMargin">
108 <number>25</number> 112 <number>0</number>
109 </property> 113 </property>
110 <property name="topMargin"> 114 <property name="topMargin">
111 <number>25</number> 115 <number>25</number>
@@ -117,30 +121,248 @@
117 <number>25</number> 121 <number>25</number>
118 </property> 122 </property>
119 <item> 123 <item>
120 <widget class="QLabel" name="label_icon"> 124 <layout class="QHBoxLayout" name="horizontalLayout">
121 <property name="minimumSize"> 125 <property name="leftMargin">
122 <size> 126 <number>0</number>
123 <width>140</width>
124 <height>120</height>
125 </size>
126 </property>
127 <property name="text">
128 <string>TextLabel</string>
129 </property> 127 </property>
130 <property name="alignment"> 128 <property name="topMargin">
131 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> 129 <number>0</number>
132 </property> 130 </property>
133 </widget> 131 <property name="rightMargin">
134 </item> 132 <number>0</number>
135 <item>
136 <widget class="QPlainTextEdit" name="plainTextEdit">
137 <property name="acceptDrops">
138 <bool>false</bool>
139 </property> 133 </property>
140 <property name="readOnly"> 134 <property name="bottomMargin">
141 <bool>true</bool> 135 <number>0</number>
142 </property> 136 </property>
143 </widget> 137 <item>
138 <layout class="QVBoxLayout" name="verticalLayout_2">
139 <property name="sizeConstraint">
140 <enum>QLayout::SetMinAndMaxSize</enum>
141 </property>
142 <property name="rightMargin">
143 <number>0</number>
144 </property>
145 <property name="bottomMargin">
146 <number>0</number>
147 </property>
148 <item>
149 <widget class="QLabel" name="label_logo">
150 <property name="sizePolicy">
151 <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
152 <horstretch>0</horstretch>
153 <verstretch>0</verstretch>
154 </sizepolicy>
155 </property>
156 <property name="minimumSize">
157 <size>
158 <width>120</width>
159 <height>120</height>
160 </size>
161 </property>
162 <property name="statusTip">
163 <string>logo</string>
164 </property>
165 <property name="text">
166 <string>TextLabel</string>
167 </property>
168 <property name="alignment">
169 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
170 </property>
171 </widget>
172 </item>
173 <item>
174 <spacer name="verticalSpacer">
175 <property name="orientation">
176 <enum>Qt::Vertical</enum>
177 </property>
178 <property name="sizeHint" stdset="0">
179 <size>
180 <width>20</width>
181 <height>40</height>
182 </size>
183 </property>
184 </spacer>
185 </item>
186 </layout>
187 </item>
188 <item>
189 <layout class="QVBoxLayout" name="verticalLayout_3">
190 <property name="spacing">
191 <number>10</number>
192 </property>
193 <property name="sizeConstraint">
194 <enum>QLayout::SetMaximumSize</enum>
195 </property>
196 <property name="leftMargin">
197 <number>50</number>
198 </property>
199 <item>
200 <widget class="QLabel" name="label_url">
201 <property name="sizePolicy">
202 <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
203 <horstretch>0</horstretch>
204 <verstretch>0</verstretch>
205 </sizepolicy>
206 </property>
207 <property name="statusTip">
208 <string>url</string>
209 </property>
210 <property name="text">
211 <string>url</string>
212 </property>
213 <property name="textFormat">
214 <enum>Qt::RichText</enum>
215 </property>
216 <property name="alignment">
217 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
218 </property>
219 <property name="openExternalLinks">
220 <bool>true</bool>
221 </property>
222 </widget>
223 </item>
224 <item>
225 <widget class="QLabel" name="label_location_address">
226 <property name="statusTip">
227 <string>location/address</string>
228 </property>
229 <property name="text">
230 <string>location/address</string>
231 </property>
232 </widget>
233 </item>
234 <item>
235 <widget class="QLabel" name="label_contact_email">
236 <property name="statusTip">
237 <string>contact/email</string>
238 </property>
239 <property name="text">
240 <string>contact/email</string>
241 </property>
242 </widget>
243 </item>
244 <item>
245 <widget class="QLabel" name="label_contact_phone">
246 <property name="statusTip">
247 <string>contact/phone</string>
248 </property>
249 <property name="text">
250 <string>contact/phone</string>
251 </property>
252 </widget>
253 </item>
254 <item>
255 <widget class="QLabel" name="label_contact_facebook">
256 <property name="statusTip">
257 <string>contact/facebook</string>
258 </property>
259 <property name="text">
260 <string>contact/facebook</string>
261 </property>
262 </widget>
263 </item>
264 <item>
265 <widget class="QLabel" name="label_contact_jabber">
266 <property name="statusTip">
267 <string>contact/jabber</string>
268 </property>
269 <property name="text">
270 <string>contact/jabber</string>
271 </property>
272 </widget>
273 </item>
274 <item>
275 <widget class="QLabel" name="label_contact_twitter">
276 <property name="statusTip">
277 <string>contact/twitter</string>
278 </property>
279 <property name="text">
280 <string>contact/twitter</string>
281 </property>
282 </widget>
283 </item>
284 <item>
285 <spacer name="verticalSpacer_2">
286 <property name="orientation">
287 <enum>Qt::Vertical</enum>
288 </property>
289 <property name="sizeHint" stdset="0">
290 <size>
291 <width>20</width>
292 <height>40</height>
293 </size>
294 </property>
295 </spacer>
296 </item>
297 </layout>
298 </item>
299 <item>
300 <layout class="QVBoxLayout" name="verticalLayout_5">
301 <property name="leftMargin">
302 <number>50</number>
303 </property>
304 <property name="rightMargin">
305 <number>0</number>
306 </property>
307 <item>
308 <widget class="QLabel" name="state_open">
309 <property name="statusTip">
310 <string>state/open</string>
311 </property>
312 <property name="text">
313 <string>state/open</string>
314 </property>
315 </widget>
316 </item>
317 <item>
318 <widget class="QLabel" name="label_state_lastchange">
319 <property name="statusTip">
320 <string>state/lastchange</string>
321 </property>
322 <property name="text">
323 <string>state/lastchange</string>
324 </property>
325 </widget>
326 </item>
327 <item>
328 <widget class="QLabel" name="label_state_trigger_person">
329 <property name="statusTip">
330 <string>state/trigger_person</string>
331 </property>
332 <property name="text">
333 <string extracomment="test">state/trigger_person</string>
334 </property>
335 </widget>
336 </item>
337 <item>
338 <spacer name="horizontalSpacer_2">
339 <property name="orientation">
340 <enum>Qt::Horizontal</enum>
341 </property>
342 <property name="sizeHint" stdset="0">
343 <size>
344 <width>40</width>
345 <height>20</height>
346 </size>
347 </property>
348 </spacer>
349 </item>
350 <item>
351 <spacer name="verticalSpacer_3">
352 <property name="orientation">
353 <enum>Qt::Vertical</enum>
354 </property>
355 <property name="sizeHint" stdset="0">
356 <size>
357 <width>20</width>
358 <height>40</height>
359 </size>
360 </property>
361 </spacer>
362 </item>
363 </layout>
364 </item>
365 </layout>
144 </item> 366 </item>
145 </layout> 367 </layout>
146 </item> 368 </item>
@@ -154,7 +376,7 @@
154 <rect> 376 <rect>
155 <x>0</x> 377 <x>0</x>
156 <y>0</y> 378 <y>0</y>
157 <width>952</width> 379 <width>927</width>
158 <height>29</height> 380 <height>29</height>
159 </rect> 381 </rect>
160 </property> 382 </property>
@@ -190,9 +412,16 @@
190 <string>Update Status</string> 412 <string>Update Status</string>
191 </property> 413 </property>
192 </action> 414 </action>
415 <action name="actionHackerspace">
416 <property name="text">
417 <string>Hackerspace</string>
418 </property>
419 </action>
193 </widget> 420 </widget>
194 <layoutdefault spacing="6" margin="11"/> 421 <layoutdefault spacing="6" margin="11"/>
195 <resources/> 422 <resources>
423 <include location="qspace.qrc"/>
424 </resources>
196 <connections> 425 <connections>
197 <connection> 426 <connection>
198 <sender>actionExit</sender> 427 <sender>actionExit</sender>
diff --git a/qspace.qrc b/qspace.qrc
new file mode 100644
index 0000000..ebd432b
--- /dev/null
+++ b/qspace.qrc
@@ -0,0 +1,5 @@
1<RCC>
2 <qresource prefix="/icons">
3 <file>img/qspacestatus.png</file>
4 </qresource>
5</RCC>
diff --git a/qspaceapi.pro b/qspaceapi.pro
index 2cc1ade..67e018a 100644
--- a/qspaceapi.pro
+++ b/qspaceapi.pro
@@ -26,6 +26,8 @@ DISTFILES += \
26 folder.png \ 26 folder.png \
27 packages/arch/PKGBUILD \ 27 packages/arch/PKGBUILD \
28 packages/arch/Makefile \ 28 packages/arch/Makefile \
29 share/xdg/qspacestatus.desktop 29 share/xdg/qspacestatus.desktop \
30 img/qspace.blend
30 31
31RESOURCES += 32RESOURCES += \
33 qspace.qrc
..