|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "lunchwidget.h" |
|
18 #include <QRect> |
|
19 #include <QPainter> |
|
20 #include <QUrl> |
|
21 #include <hbapplication> |
|
22 #include <tstestpropertydefs.h> |
|
23 #include <HbComboBox> |
|
24 #include <HbCheckBox> |
|
25 #include <qservicemanager.h> |
|
26 |
|
27 |
|
28 QTM_USE_NAMESPACE |
|
29 |
|
30 #define hbApp qobject_cast<HbApplication*>(qApp) |
|
31 |
|
32 lunchwidget::lunchwidget(QGraphicsItem *parent) |
|
33 : HbWidget(parent), mPluginPublisher(TsTestProperty::KTsTestPath) |
|
34 { |
|
35 mLoadLabel = new HbLabel; |
|
36 QServiceManager manager; |
|
37 bool ok = manager.addService(":/tsfakelplugin.xml"); |
|
38 if (!ok) { |
|
39 int err = manager.error(); |
|
40 QString mess; |
|
41 mess = tr("Load service: %1").arg(err); |
|
42 mLoadLabel->setPlainText(mess); |
|
43 } |
|
44 else { |
|
45 mLoadLabel->setPlainText("Load service: Ok"); |
|
46 } |
|
47 |
|
48 mTenLabel= new HbLabel("10x"); |
|
49 mOneLabel= new HbLabel("1x"); |
|
50 |
|
51 |
|
52 mAdd = new HbPushButton("Add"); |
|
53 mRemove = new HbPushButton("Remove all"); |
|
54 |
|
55 |
|
56 mTenCombo = new HbComboBox(); |
|
57 mOneCombo = new HbComboBox(); |
|
58 for (int i=0; i<10; i++) { |
|
59 QString num; |
|
60 num.setNum(i); |
|
61 mTenCombo->addItem(num); |
|
62 mOneCombo->addItem(num); |
|
63 } |
|
64 mRunningCheckBox = new HbCheckBox("Is Running"); |
|
65 mRunningCheckBox->setCheckState(Qt::Checked); |
|
66 mCloseableCheckBox = new HbCheckBox("Is Closeable"); |
|
67 mCloseableCheckBox->setCheckState(Qt::Checked); |
|
68 |
|
69 mGridLayout = new QGraphicsGridLayout(); |
|
70 mGridLayout->addItem(mOneLabel, 0, 0, 1, 3); |
|
71 mGridLayout->addItem(mTenLabel, 0, 3, 1, 3); |
|
72 mGridLayout->addItem(mOneCombo, 1, 0, 1, 3); |
|
73 mGridLayout->addItem(mTenCombo, 1, 3, 1, 3); |
|
74 mGridLayout->addItem(mRunningCheckBox, 2, 0, 1, 6); |
|
75 mGridLayout->addItem(mCloseableCheckBox, 3, 0, 1, 6); |
|
76 mGridLayout->addItem(mAdd, 4, 0, 1, 6); |
|
77 mGridLayout->addItem(mRemove, 5, 0, 1, 6); |
|
78 mGridLayout->addItem(mLoadLabel, 6, 0, 1, 6); |
|
79 setLayout(mGridLayout); |
|
80 |
|
81 |
|
82 connect(mAdd, SIGNAL(released()), this, SLOT(add())); |
|
83 connect(mRemove, SIGNAL(released()), this, SLOT(remove())); |
|
84 |
|
85 |
|
86 mPluginPublisher.setValue(TsTestProperty::KPluginPath, 0); |
|
87 mPluginPublisher.sync(); |
|
88 |
|
89 } |
|
90 |
|
91 lunchwidget::~lunchwidget() |
|
92 { |
|
93 |
|
94 } |
|
95 |
|
96 void lunchwidget::add() |
|
97 { |
|
98 int ten = mTenCombo->currentText().toInt(); |
|
99 int one = mOneCombo->currentText().toInt(); |
|
100 int num = ten*10+one; |
|
101 bool running = false; |
|
102 bool closeable = false; |
|
103 if (mRunningCheckBox->checkState() == Qt::Checked) { |
|
104 running = true; |
|
105 } |
|
106 if (mCloseableCheckBox->checkState() == Qt::Checked) { |
|
107 closeable = true; |
|
108 } |
|
109 |
|
110 int message = 0; |
|
111 setByte(message, 0, num); |
|
112 setByte(message, 1, running); |
|
113 setByte(message, 2, closeable); |
|
114 |
|
115 mPluginPublisher.setValue(TsTestProperty::KPluginPath, message); |
|
116 mPluginPublisher.sync(); |
|
117 } |
|
118 |
|
119 void lunchwidget::remove() |
|
120 { |
|
121 int message = -1; |
|
122 |
|
123 mPluginPublisher.setValue(TsTestProperty::KPluginPath, message); |
|
124 mPluginPublisher.sync(); |
|
125 } |
|
126 |
|
127 |
|
128 void lunchwidget::setByte(int& numtoset, int byte, char value) |
|
129 { |
|
130 if(byte>3 || byte<0) { |
|
131 return; |
|
132 } |
|
133 int multiple = 255;//0b00000000000000000000000011111111; |
|
134 unsigned int temp = 0; |
|
135 temp = temp | value; |
|
136 temp = temp & multiple; |
|
137 temp = temp << byte*8; |
|
138 numtoset = numtoset | temp; |
|
139 } |
|
140 |
|
141 char lunchwidget::byte(int numtoget, int byte) |
|
142 { |
|
143 char ret = 0; |
|
144 if(byte>3 || byte<0) { |
|
145 return ret; |
|
146 } |
|
147 numtoget = numtoget>>8*byte; |
|
148 ret = static_cast<char>(numtoget); |
|
149 |
|
150 return ret; |
|
151 |
|
152 } |