|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "publishsubscribemainwindow.h" |
|
43 #include "ui_publishsubscribemainwindow.h" |
|
44 |
|
45 #include <qvaluespacesubscriber.h> |
|
46 |
|
47 PublishSubscribeMainWindow::PublishSubscribeMainWindow(QWidget *parent) : |
|
48 QMainWindow(parent), |
|
49 ui(new Ui::PublishSubscribeMainWindow) |
|
50 { |
|
51 ui->setupUi(this); |
|
52 batterySubscriber = new QValueSpaceSubscriber("/resources/battery", this); |
|
53 connect(batterySubscriber, SIGNAL(contentsChanged()), this, SLOT(subscriberChanged())); |
|
54 |
|
55 chargingSubscriber = new QValueSpaceSubscriber("/resources/charging", this); |
|
56 connect(chargingSubscriber, SIGNAL(contentsChanged()), this, SLOT(subscriberChanged())); |
|
57 |
|
58 profileSubscriber = new QValueSpaceSubscriber("/profile", this); |
|
59 connect(profileSubscriber, SIGNAL(contentsChanged()), this, SLOT(subscriberChanged())); |
|
60 |
|
61 subscriberChanged(); |
|
62 } |
|
63 |
|
64 PublishSubscribeMainWindow::~PublishSubscribeMainWindow() |
|
65 { |
|
66 delete ui; |
|
67 } |
|
68 |
|
69 void PublishSubscribeMainWindow::subscriberChanged() |
|
70 { |
|
71 QVariant batteryLevel = batterySubscriber->value("level"); |
|
72 if (!batteryLevel.isNull()) { |
|
73 ui->labelBatteryLevel->setText(batteryLevel.toString()); |
|
74 } else { |
|
75 ui->labelBatteryLevel->setText(tr("value not found")); |
|
76 } |
|
77 |
|
78 QVariant batteryStatus = batterySubscriber->value("status"); |
|
79 if (!batteryStatus.isNull()) { |
|
80 switch (batteryStatus.toInt()) { |
|
81 case 0: ui->labelBatteryStatus->setText(tr("ok")); break; |
|
82 case 1: ui->labelBatteryStatus->setText(tr("low")); break; |
|
83 case 2: ui->labelBatteryStatus->setText(tr("empty")); break; |
|
84 default: |
|
85 ui->labelBatteryStatus->setText(tr("unknown")); |
|
86 break; |
|
87 } |
|
88 } else { |
|
89 ui->labelBatteryStatus->setText(tr("value not found")); |
|
90 } |
|
91 |
|
92 QVariant chargingStatus = chargingSubscriber->value("status"); |
|
93 if (!chargingStatus.isNull()) { |
|
94 switch (chargingSubscriber->value("status").toInt()) { |
|
95 case -1: ui->labelChargingStatus->setText(tr("error")); break; |
|
96 case 0: ui->labelChargingStatus->setText(tr("not connected")); break; |
|
97 case 1: ui->labelChargingStatus->setText(tr("charging")); break; |
|
98 case 2: ui->labelChargingStatus->setText(tr("not charging")); break; |
|
99 case 3: ui->labelChargingStatus->setText(tr("almost complete")); break; |
|
100 case 4: ui->labelChargingStatus->setText(tr("charging complete")); break; |
|
101 case 5: ui->labelChargingStatus->setText(tr("charging continued")); break; |
|
102 default: |
|
103 ui->labelChargingStatus->setText(tr("unknown")); |
|
104 break; |
|
105 } |
|
106 } else { |
|
107 ui->labelChargingStatus->setText(tr("value not found")); |
|
108 } |
|
109 |
|
110 QVariant profileId = profileSubscriber->value("id"); |
|
111 if (!profileId.isNull()) { |
|
112 switch (profileId.toInt()) { |
|
113 case 0: ui->labelCurrentProfile->setText(tr("General profile")); break; |
|
114 case 1: ui->labelCurrentProfile->setText(tr("Silent profile")); break; |
|
115 case 2: ui->labelCurrentProfile->setText(tr("Meeting profile")); break; |
|
116 case 3: ui->labelCurrentProfile->setText(tr("Outdoor profile")); break; |
|
117 case 4: ui->labelCurrentProfile->setText(tr("Pager profile")); break; |
|
118 case 5: ui->labelCurrentProfile->setText(tr("Off-line profile")); break; |
|
119 case 6: ui->labelCurrentProfile->setText(tr("Drive profile")); break; |
|
120 default: |
|
121 if (profileId.toInt() >= 30 && profileId.toInt() <= 49) { |
|
122 ui->labelCurrentProfile->setText(tr("User-created profile")); |
|
123 } else { |
|
124 ui->labelCurrentProfile->setText(tr("unknown")); |
|
125 } |
|
126 break; |
|
127 } |
|
128 } else { |
|
129 ui->labelCurrentProfile->setText(tr("value not found")); |
|
130 } |
|
131 } |