summaryrefslogtreecommitdiff
path: root/noncore/applets
Unidiff
Diffstat (limited to 'noncore/applets') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/memoryapplet/swapfile.cpp4
-rw-r--r--noncore/applets/notesapplet/notes.cpp8
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp8
-rw-r--r--noncore/applets/zkbapplet/zkbwidget.cpp4
4 files changed, 12 insertions, 12 deletions
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp
index 04da8bb..9416db3 100644
--- a/noncore/applets/memoryapplet/swapfile.cpp
+++ b/noncore/applets/memoryapplet/swapfile.cpp
@@ -1,307 +1,307 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "swapfile.h" 21#include "swapfile.h"
22 22
23#include <qfile.h> 23#include <qfile.h>
24#include <qtextstream.h> 24#include <qtextstream.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qtimer.h> 26#include <qtimer.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qhbuttongroup.h> 29#include <qhbuttongroup.h>
30#include <qradiobutton.h> 30#include <qradiobutton.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qprogressbar.h> 32#include <qprogressbar.h>
33#include <qcombobox.h> 33#include <qcombobox.h>
34#include <qvgroupbox.h> 34#include <qvgroupbox.h>
35#include <qhbox.h> 35#include <qhbox.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40 40
41#include <qcopchannel_qws.h> 41#include <qcopchannel_qws.h>
42#include <qpe/resource.h> 42#include <qpe/resource.h>
43 43
44#include <unistd.h> 44#include <unistd.h>
45#include <fcntl.h> 45#include <fcntl.h>
46#include <sys/vfs.h> 46#include <sys/vfs.h>
47#include <mntent.h> 47#include <mntent.h>
48#include <unistd.h> 48#include <unistd.h>
49#include <sys/types.h> 49#include <sys/types.h>
50 50
51Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) 51Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f )
52 : QWidget( parent, name, f ) 52 : QWidget( parent, name, f )
53{ 53{
54 // are we running as root? 54 // are we running as root?
55 isRoot = geteuid() == 0; 55 isRoot = geteuid() == 0;
56 56
57 QVBoxLayout* vb = new QVBoxLayout(this, 5); 57 QVBoxLayout* vb = new QVBoxLayout(this, 5);
58 58
59 QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); 59 QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this);
60 cfsdRBG->setRadioButtonExclusive(true); 60 cfsdRBG->setRadioButtonExclusive(true);
61 vb->addWidget(cfsdRBG); 61 vb->addWidget(cfsdRBG);
62 62
63 ramRB = new QRadioButton(tr("RAM"), cfsdRBG); 63 ramRB = new QRadioButton(tr("RAM"), cfsdRBG);
64 cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); 64 cfRB = new QRadioButton(tr("CF Card"), cfsdRBG);
65 sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); 65 sdRB = new QRadioButton(tr("SD Card"), cfsdRBG);
66 66
67 QHBox *hb1 = new QHBox(this); 67 QHBox *hb1 = new QHBox(this);
68 hb1->setSpacing(5); 68 hb1->setSpacing(5);
69 69
70 swapPath1 = new QLineEdit(hb1); 70 swapPath1 = new QLineEdit(hb1);
71 swapPath1->setEnabled(false); 71 swapPath1->setEnabled(false);
72 72
73 QPushButton* swapOn = new QPushButton(tr(" On "), hb1); 73 QPushButton* swapOn = new QPushButton(tr(" On "), hb1);
74 QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); 74 QPushButton* swapOff = new QPushButton(tr(" Off "), hb1);
75 vb->addWidget(hb1); 75 vb->addWidget(hb1);
76 76
77 QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); 77 QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this);
78 vb->addWidget(box1); 78 vb->addWidget(box1);
79 79
80 QHBox *hb2 = new QHBox(box1); 80 QHBox *hb2 = new QHBox(box1);
81 hb2->setSpacing(5); 81 hb2->setSpacing(5);
82 QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); 82 QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2);
83 QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); 83 QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2);
84 84
85 QHBox *hb3 = new QHBox(box1); 85 QHBox *hb3 = new QHBox(box1);
86 hb3->setSpacing(5); 86 hb3->setSpacing(5);
87 swapSize = new QComboBox(hb3); 87 swapSize = new QComboBox(hb3);
88 swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); 88 swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb")));
89 89
90 mkswapProgress = new QProgressBar(3, hb3); 90 mkswapProgress = new QProgressBar(3, hb3);
91 mkswapProgress->setCenterIndicator(true); 91 mkswapProgress->setCenterIndicator(true);
92 92
93 QHBox *hb4 = new QHBox(this); 93 QHBox *hb4 = new QHBox(this);
94 hb4->setSpacing(5); 94 hb4->setSpacing(5);
95 95
96 swapStatusIcon = new QLabel(hb4); 96 swapStatusIcon = new QLabel(hb4);
97 swapStatus = new QLabel(tr(""), hb4); 97 swapStatus = new QLabel(tr(""), hb4);
98 hb4->setStretchFactor(swapStatus, 99); 98 hb4->setStretchFactor(swapStatus, 99);
99 vb->addWidget(hb4); 99 vb->addWidget(hb4);
100 100
101 connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); 101 connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon()));
102 connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); 102 connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff()));
103 connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 103 connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
104 connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 104 connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
105 connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 105 connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
106 connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); 106 connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile()));
107 connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); 107 connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile()));
108 108
109 cfRB->setEnabled(FALSE); 109 cfRB->setEnabled(FALSE);
110 sdRB->setEnabled(FALSE); 110 sdRB->setEnabled(FALSE);
111 111
112 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); 112 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this);
113 connect(pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &))); 113 connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&)));
114 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); 114 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this);
115 connect(sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &))); 115 connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&)));
116 116
117 cardInPcmcia0 = FALSE; 117 cardInPcmcia0 = FALSE;
118 cardInPcmcia1 = FALSE; 118 cardInPcmcia1 = FALSE;
119 cardInSd = FALSE; 119 cardInSd = FALSE;
120 120
121 Swapfile::status(); 121 Swapfile::status();
122 Swapfile::getStatusPcmcia(); 122 Swapfile::getStatusPcmcia();
123 Swapfile::getStatusSd(); 123 Swapfile::getStatusSd();
124} 124}
125 125
126int Swapfile::exec(const QString& arg) 126int Swapfile::exec(const QString& arg)
127{ 127{
128 return system((!isRoot ? "sudo " : "") + arg); 128 return system((!isRoot ? "sudo " : "") + arg);
129} 129}
130 130
131 131
132Swapfile::~Swapfile() 132Swapfile::~Swapfile()
133{ 133{
134} 134}
135 135
136void Swapfile::cardnotify(const QCString & msg, const QByteArray &) 136void Swapfile::cardnotify(const QCString & msg, const QByteArray &)
137{ 137{
138 if (msg == "stabChanged()") 138 if (msg == "stabChanged()")
139 { 139 {
140 getStatusPcmcia(); 140 getStatusPcmcia();
141 } 141 }
142 else if (msg == "mtabChanged()") 142 else if (msg == "mtabChanged()")
143 { 143 {
144 getStatusSd(); 144 getStatusSd();
145 } 145 }
146} 146}
147 147
148void Swapfile::getStatusPcmcia() 148void Swapfile::getStatusPcmcia()
149{ 149{
150 150
151 bool cardWas0 = cardInPcmcia0;// remember last state 151 bool cardWas0 = cardInPcmcia0;// remember last state
152 bool cardWas1 = cardInPcmcia1; 152 bool cardWas1 = cardInPcmcia1;
153 153
154 QString fileName; 154 QString fileName;
155 155
156 // one of these 3 files should exist 156 // one of these 3 files should exist
157 if (QFile::exists("/var/run/stab")) { 157 if (QFile::exists("/var/run/stab")) {
158 fileName = "/var/run/stab"; 158 fileName = "/var/run/stab";
159 } else if (QFile::exists("/var/state/pcmcia/stab")) { 159 } else if (QFile::exists("/var/state/pcmcia/stab")) {
160 fileName = "/var/state/pcmcia/stab"; 160 fileName = "/var/state/pcmcia/stab";
161 } else { 161 } else {
162 fileName = "/var/lib/pcmcia/stab"; 162 fileName = "/var/lib/pcmcia/stab";
163 } 163 }
164 164
165 QFile f(fileName); 165 QFile f(fileName);
166 166
167 if (f.open(IO_ReadOnly)) { 167 if (f.open(IO_ReadOnly)) {
168 QStringList list; 168 QStringList list;
169 QTextStream stream(&f); 169 QTextStream stream(&f);
170 QString streamIn; 170 QString streamIn;
171 streamIn = stream.read(); 171 streamIn = stream.read();
172 list = QStringList::split("\n", streamIn); 172 list = QStringList::split("\n", streamIn);
173 for (QStringList::Iterator line = list.begin(); line != list.end(); 173 for (QStringList::Iterator line = list.begin(); line != list.end();
174 line++) { 174 line++) {
175 if ((*line).startsWith("Socket 0:")) { 175 if ((*line).startsWith("Socket 0:")) {
176 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { 176 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) {
177 cardInPcmcia0 = FALSE; 177 cardInPcmcia0 = FALSE;
178 } else if (!(*line).startsWith("Socket 0: empty") 178 } else if (!(*line).startsWith("Socket 0: empty")
179 && !cardInPcmcia0) { 179 && !cardInPcmcia0) {
180 cardInPcmcia0 = TRUE; 180 cardInPcmcia0 = TRUE;
181 } 181 }
182 } else if ((*line).startsWith("Socket 1:")) { 182 } else if ((*line).startsWith("Socket 1:")) {
183 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { 183 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) {
184 cardInPcmcia1 = FALSE; 184 cardInPcmcia1 = FALSE;
185 } else if (!(*line).startsWith("Socket 1: empty") 185 } else if (!(*line).startsWith("Socket 1: empty")
186 && !cardInPcmcia1) { 186 && !cardInPcmcia1) {
187 cardInPcmcia1 = TRUE; 187 cardInPcmcia1 = TRUE;
188 } 188 }
189 } 189 }
190 } 190 }
191 f.close(); 191 f.close();
192 192
193 if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { 193 if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) {
194 QString text = QString::null; 194 QString text = QString::null;
195 QString what = QString::null; 195 QString what = QString::null;
196 if (cardWas0 != cardInPcmcia0) { 196 if (cardWas0 != cardInPcmcia0) {
197 if (cardInPcmcia0) { 197 if (cardInPcmcia0) {
198 cfRB->setEnabled(TRUE); 198 cfRB->setEnabled(TRUE);
199 } else { 199 } else {
200 cfRB->setChecked(FALSE); 200 cfRB->setChecked(FALSE);
201 cfRB->setEnabled(FALSE); 201 cfRB->setEnabled(FALSE);
202 } 202 }
203 } 203 }
204 204
205 if (cardWas1 != cardInPcmcia1) { 205 if (cardWas1 != cardInPcmcia1) {
206 if (cardInPcmcia1) { 206 if (cardInPcmcia1) {
207 cfRB->setEnabled(TRUE); 207 cfRB->setEnabled(TRUE);
208 } else { 208 } else {
209 cfRB->setChecked(FALSE); 209 cfRB->setChecked(FALSE);
210 cfRB->setEnabled(FALSE); 210 cfRB->setEnabled(FALSE);
211 } 211 }
212 } 212 }
213 } 213 }
214 } else { 214 } else {
215 // no file found 215 // no file found
216 qDebug("no file found"); 216 qDebug("no file found");
217 cardInPcmcia0 = FALSE; 217 cardInPcmcia0 = FALSE;
218 cardInPcmcia1 = FALSE; 218 cardInPcmcia1 = FALSE;
219 } 219 }
220 Swapfile::cfsdchecked(); 220 Swapfile::cfsdchecked();
221} 221}
222 222
223 223
224void Swapfile::getStatusSd() 224void Swapfile::getStatusSd()
225{ 225{
226 226
227 bool cardWas = cardInSd;// remember last state 227 bool cardWas = cardInSd;// remember last state
228 cardInSd = FALSE; 228 cardInSd = FALSE;
229 229
230#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 230#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
231 struct mntent *me; 231 struct mntent *me;
232 FILE *mntfp = setmntent("/etc/mtab", "r"); 232 FILE *mntfp = setmntent("/etc/mtab", "r");
233 233
234 if (mntfp) { 234 if (mntfp) {
235 while ((me = getmntent(mntfp)) != 0) { 235 while ((me = getmntent(mntfp)) != 0) {
236 QString fs = me->mnt_fsname; 236 QString fs = me->mnt_fsname;
237 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" 237 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd"
238 || fs.left(9) == "/dev/mmcd") { 238 || fs.left(9) == "/dev/mmcd") {
239 cardInSd = TRUE; 239 cardInSd = TRUE;
240 show(); 240 show();
241 } 241 }
242 } 242 }
243 endmntent(mntfp); 243 endmntent(mntfp);
244 } 244 }
245 245
246 if (cardWas != cardInSd) { 246 if (cardWas != cardInSd) {
247 QString text = QString::null; 247 QString text = QString::null;
248 QString what = QString::null; 248 QString what = QString::null;
249 if (cardInSd) { 249 if (cardInSd) {
250 sdRB->setEnabled(TRUE); 250 sdRB->setEnabled(TRUE);
251 } else { 251 } else {
252 sdRB->setChecked(FALSE); 252 sdRB->setChecked(FALSE);
253 sdRB->setEnabled(FALSE); 253 sdRB->setEnabled(FALSE);
254 } 254 }
255 } 255 }
256#else 256#else
257#error "Not on Linux" 257#error "Not on Linux"
258#endif 258#endif
259 Swapfile::cfsdchecked(); 259 Swapfile::cfsdchecked();
260} 260}
261 261
262int rc=0; 262int rc=0;
263 263
264void Swapfile::swapon() 264void Swapfile::swapon()
265{ 265{
266 char swapcmd[128] ="swapon "; 266 char swapcmd[128] ="swapon ";
267 Swapfile::cfsdchecked(); 267 Swapfile::cfsdchecked();
268 strcat(swapcmd,swapPath1->text()); 268 strcat(swapcmd,swapPath1->text());
269 char *runcmd = swapcmd; 269 char *runcmd = swapcmd;
270 rc = exec(QString("%1").arg(runcmd)); 270 rc = exec(QString("%1").arg(runcmd));
271 if (rc != 0) { 271 if (rc != 0) {
272 setStatusMessage("Failed to attach swapfile.", true); 272 setStatusMessage("Failed to attach swapfile.", true);
273 } 273 }
274 else { 274 else {
275 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 275 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
276 setStatusMessage("Swapfile activated."); 276 setStatusMessage("Swapfile activated.");
277 } 277 }
278 Swapfile::status(); 278 Swapfile::status();
279} 279}
280 280
281 281
282void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) 282void Swapfile::setStatusMessage(const QString& text, bool error /* = false */)
283{ 283{
284 swapStatus->setText("<b>" + text + "</b>"); 284 swapStatus->setText("<b>" + text + "</b>");
285 swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done")); 285 swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done"));
286} 286}
287 287
288 288
289void Swapfile::swapoff() 289void Swapfile::swapoff()
290{ 290{
291 char swapcmd[128] ="swapoff "; 291 char swapcmd[128] ="swapoff ";
292 if (Swapfile::cfRB->isChecked() == TRUE) 292 if (Swapfile::cfRB->isChecked() == TRUE)
293 Swapfile::cfsdchecked(); 293 Swapfile::cfsdchecked();
294 strcat(swapcmd,swapPath1->text()); 294 strcat(swapcmd,swapPath1->text());
295 char *runcmd = swapcmd; 295 char *runcmd = swapcmd;
296 rc = exec(QString("%1").arg(runcmd)); 296 rc = exec(QString("%1").arg(runcmd));
297 if (rc != 0) { 297 if (rc != 0) {
298 setStatusMessage(tr("Failed to detach swapfile."), true); 298 setStatusMessage(tr("Failed to detach swapfile."), true);
299 } 299 }
300 else { 300 else {
301 /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ 301 /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */
302 setStatusMessage(tr("Swapfile deactivated.")); 302 setStatusMessage(tr("Swapfile deactivated."));
303 /* Swapfile::swapPath->clear();*/ 303 /* Swapfile::swapPath->clear();*/
304 } 304 }
305 Swapfile::status(); 305 Swapfile::status();
306} 306}
307 307
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 1142028..9b5e475 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -1,417 +1,417 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> 2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3 3
4** All rights reserved. 4** All rights reserved.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "notes.h" 16#include "notes.h"
17 17
18#include <qapplication.h> 18#include <qapplication.h>
19#include <stdlib.h> 19#include <stdlib.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21 21
22#include <opie2/otaskbarapplet.h> 22#include <opie2/otaskbarapplet.h>
23#include <qpe/filemanager.h> 23#include <qpe/filemanager.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/timestring.h> 25#include <qpe/timestring.h>
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/ir.h> 27#include <qpe/ir.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30// #include <qsocket.h> 30// #include <qsocket.h>
31// #include <qclipboard.h> 31// #include <qclipboard.h>
32#include <qmultilineedit.h> 32#include <qmultilineedit.h>
33#include <qlistbox.h> 33#include <qlistbox.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qpoint.h> 39#include <qpoint.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qpixmap.h> 44#include <qpixmap.h>
45#include <qstring.h> 45#include <qstring.h>
46#include <qtimer.h> 46#include <qtimer.h>
47 47
48/* XPM */ 48/* XPM */
49static char * notes_xpm[] = { 49static char * notes_xpm[] = {
50"16 16 11 1", 50"16 16 11 1",
51" c None", 51" c None",
52". c #000000", 52". c #000000",
53"+ c #7F7F7F", 53"+ c #7F7F7F",
54"@ c #BFBFBF", 54"@ c #BFBFBF",
55"# c #BFC1FF", 55"# c #BFC1FF",
56"$ c #FF0000", 56"$ c #FF0000",
57"% c #FFFFFF", 57"% c #FFFFFF",
58"& c #00037F", 58"& c #00037F",
59"* c #0006FF", 59"* c #0006FF",
60"= c #0005BF", 60"= c #0005BF",
61"- c #7F0000", 61"- c #7F0000",
62" .. ", 62" .. ",
63" .. ", 63" .. ",
64" ... ", 64" ... ",
65" .+ ", 65" .+ ",
66" .@. ", 66" .@. ",
67" . .+ ", 67" . .+ ",
68" ..#.@. ", 68" ..#.@. ",
69" ..###.+.. ", 69" ..###.+.. ",
70" ..###$...##.. ", 70" ..###$...##.. ",
71"..###$$$%+$$##&.", 71"..###$$$%+$$##&.",
72".*=####$-###&=&.", 72".*=####$-###&=&.",
73".=**=###==&=&=..", 73".=**=###==&=&=..",
74" ..=**=#&=&=.. ", 74" ..=**=#&=&=.. ",
75" ..=*=&=.. ", 75" ..=*=&=.. ",
76" ..=.. ", 76" ..=.. ",
77" . "}; 77" . "};
78 78
79 79
80NotesControl::NotesControl( QWidget *, const char * ) 80NotesControl::NotesControl( QWidget *, const char * )
81 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) 81 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop )
82// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 82// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
83{ 83{
84 QDir d( QDir::homeDirPath()+"/notes"); 84 QDir d( QDir::homeDirPath()+"/notes");
85 if( !d.exists()) { 85 if( !d.exists()) {
86 qDebug("make dir"); 86 qDebug("make dir");
87 if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) 87 if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
88 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed"); 88 qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed");
89 } 89 }
90 Config cfg("Notes"); 90 Config cfg("Notes");
91 cfg.setGroup("Options"); 91 cfg.setGroup("Options");
92 showMax = cfg.readBoolEntry("ShowMax", false); 92 showMax = cfg.readBoolEntry("ShowMax", false);
93 93
94 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 94 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
95 loaded=false; 95 loaded=false;
96 edited=false; 96 edited=false;
97 doPopulate=true; 97 doPopulate=true;
98 isNew=false; 98 isNew=false;
99 QVBox *vbox = new QVBox( this, "Vlayout" ); 99 QVBox *vbox = new QVBox( this, "Vlayout" );
100 QHBox *hbox = new QHBox( this, "HLayout" ); 100 QHBox *hbox = new QHBox( this, "HLayout" );
101 101
102 view = new QMultiLineEdit(vbox, "OpieNotesView"); 102 view = new QMultiLineEdit(vbox, "OpieNotesView");
103 103
104 box = new QListBox(vbox, "OpieNotesBox"); 104 box = new QListBox(vbox, "OpieNotesBox");
105 105
106 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); 106 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
107 107
108 box->setFixedHeight(50); 108 box->setFixedHeight(50);
109 109
110 vbox->setMargin( 6 ); 110 vbox->setMargin( 6 );
111 vbox->setSpacing( 3 ); 111 vbox->setSpacing( 3 );
112 112
113 113
114 114
115 setFocusPolicy(QWidget::StrongFocus); 115 setFocusPolicy(QWidget::StrongFocus);
116 116
117 newButton= new QPushButton( hbox, "newButton" ); 117 newButton= new QPushButton( hbox, "newButton" );
118 newButton->setText(tr("New")); 118 newButton->setText(tr("New"));
119 119
120 120
121 saveButton= new QPushButton( hbox, "saveButton" ); 121 saveButton= new QPushButton( hbox, "saveButton" );
122 saveButton->setText(tr("Save")); 122 saveButton->setText(tr("Save"));
123 123
124 124
125 deleteButton= new QPushButton( hbox, "deleteButton" ); 125 deleteButton= new QPushButton( hbox, "deleteButton" );
126 deleteButton->setText(tr("Delete")); 126 deleteButton->setText(tr("Delete"));
127 127
128 128
129 129
130 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), 130 connect( box, SIGNAL( mouseButtonPressed(int,QListBoxItem*,const QPoint&)),
131 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); 131 this,SLOT( boxPressed(int,QListBoxItem*,const QPoint&)) );
132 132
133 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); 133 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString&)));
134 134
135 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); 135 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
136 136
137 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); 137 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
138 138
139 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); 139 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
140 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); 140 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton()));
141 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); 141 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked()));
142 142
143 populateBox(); 143 populateBox();
144 load(); 144 load();
145 setCaption("Notes"); 145 setCaption("Notes");
146 // parent->setFocus(); 146 // parent->setFocus();
147} 147}
148 148
149void NotesControl::slotSaveButton() { 149void NotesControl::slotSaveButton() {
150 slotNewButton(); 150 slotNewButton();
151 populateBox(); 151 populateBox();
152} 152}
153 153
154void NotesControl::slotDeleteButtonClicked() { 154void NotesControl::slotDeleteButtonClicked() {
155 switch ( QMessageBox::warning(this,tr("Delete?") 155 switch ( QMessageBox::warning(this,tr("Delete?")
156 ,tr("Do you really want to<BR><B> delete</B> this note ?") 156 ,tr("Do you really want to<BR><B> delete</B> this note ?")
157 ,tr("Yes"),tr("No"),0,1,1) ) { 157 ,tr("Yes"),tr("No"),0,1,1) ) {
158 case 0: 158 case 0:
159 slotDeleteButton(); 159 slotDeleteButton();
160 break; 160 break;
161 }; 161 };
162} 162}
163 163
164void NotesControl::slotDeleteButton() { 164void NotesControl::slotDeleteButton() {
165 165
166 QString selectedText = box->currentText(); 166 QString selectedText = box->currentText();
167 qDebug("deleting "+selectedText); 167 qDebug("deleting "+selectedText);
168 168
169 if( !selectedText.isEmpty()) { 169 if( !selectedText.isEmpty()) {
170 170
171 Config cfg("Notes"); 171 Config cfg("Notes");
172 cfg.setGroup("Docs"); 172 cfg.setGroup("Docs");
173 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 173 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
174 QString entryName, entryName2;; 174 QString entryName, entryName2;;
175 for ( int i = 0; i < noOfFiles; i++ ) { 175 for ( int i = 0; i < noOfFiles; i++ ) {
176 entryName.sprintf( "File%i", i + 1 ); 176 entryName.sprintf( "File%i", i + 1 );
177 if(selectedText == cfg.readEntry( entryName )) { 177 if(selectedText == cfg.readEntry( entryName )) {
178 qDebug("removing %s, %d", selectedText.latin1(), i); 178 qDebug("removing %s, %d", selectedText.latin1(), i);
179 for ( int j = i; j < noOfFiles; j++ ) { 179 for ( int j = i; j < noOfFiles; j++ ) {
180 entryName.sprintf( "File%i", i + 1 ); 180 entryName.sprintf( "File%i", i + 1 );
181 entryName2.sprintf( "File%i", i + 2 ); 181 entryName2.sprintf( "File%i", i + 2 );
182 QString temp = cfg.readEntry(entryName2); 182 QString temp = cfg.readEntry(entryName2);
183 qDebug("move "+temp); 183 qDebug("move "+temp);
184 cfg.writeEntry(entryName, temp); 184 cfg.writeEntry(entryName, temp);
185 i++; 185 i++;
186 } 186 }
187 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 187 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
188 entryName.sprintf( "File%i", noOfFiles ); 188 entryName.sprintf( "File%i", noOfFiles );
189 cfg.removeEntry(entryName); 189 cfg.removeEntry(entryName);
190 cfg.write(); 190 cfg.write();
191 DocLnk nf(selectedText); 191 DocLnk nf(selectedText);
192 nf.removeFiles(); 192 nf.removeFiles();
193 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; 193 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
194 qDebug(fi); 194 qDebug(fi);
195 195
196 QFile f( fi); 196 QFile f( fi);
197 if( !f.remove()) qDebug(".desktop file not removed"); 197 if( !f.remove()) qDebug(".desktop file not removed");
198 198
199 } 199 }
200 } 200 }
201 view->clear(); 201 view->clear();
202 202
203 populateBox(); 203 populateBox();
204 } 204 }
205} 205}
206 206
207void NotesControl::slotNewButton() { 207void NotesControl::slotNewButton() {
208 if(edited) save(); 208 if(edited) save();
209 view->clear(); 209 view->clear();
210 view->setFocus(); 210 view->setFocus();
211 edited=false; 211 edited=false;
212 isNew=false; 212 isNew=false;
213} 213}
214 214
215void NotesControl::slotBeamButton() { 215void NotesControl::slotBeamButton() {
216 Ir ir; 216 Ir ir;
217 if(!ir.supported()){ 217 if(!ir.supported()){
218 } else { 218 } else {
219 this->hide(); 219 this->hide();
220 QString selectedText = box->currentText(); 220 QString selectedText = box->currentText();
221 if( !selectedText.isEmpty()) { 221 if( !selectedText.isEmpty()) {
222 QString file = QDir::homeDirPath()+"/"+selectedText; 222 QString file = QDir::homeDirPath()+"/"+selectedText;
223 QFile f(file); 223 QFile f(file);
224 Ir *irFile = new Ir(this, "IR"); 224 Ir *irFile = new Ir(this, "IR");
225 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * ))); 225 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*)));
226 irFile->send( file, "Note", "text/plain" ); 226 irFile->send( file, "Note", "text/plain" );
227 } 227 }
228 } 228 }
229} 229}
230 230
231void NotesControl::slotBeamFinished(Ir *) { 231void NotesControl::slotBeamFinished(Ir *) {
232 this->show(); 232 this->show();
233} 233}
234 234
235void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { 235void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
236 switch (mouse) { 236 switch (mouse) {
237 case 1:{ 237 case 1:{
238 } 238 }
239 break; 239 break;
240 case 2: 240 case 2:
241 menuTimer.start( 500, TRUE ); 241 menuTimer.start( 500, TRUE );
242 break; 242 break;
243 }; 243 };
244} 244}
245 245
246void NotesControl::slotBoxSelected(const QString &itemString) { 246void NotesControl::slotBoxSelected(const QString &itemString) {
247 if(edited) { 247 if(edited) {
248 save(); 248 save();
249 } 249 }
250 loaded=false; 250 loaded=false;
251 edited=false; 251 edited=false;
252 load(itemString); 252 load(itemString);
253} 253}
254 254
255 255
256void NotesControl::showMenu() { 256void NotesControl::showMenu() {
257 QPopupMenu *m = new QPopupMenu(0); 257 QPopupMenu *m = new QPopupMenu(0);
258 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); 258 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
259 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); 259 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
260 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); 260 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
261 m->insertSeparator(); 261 m->insertSeparator();
262 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 262 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
263 m->setFocus(); 263 m->setFocus();
264 m->exec( QCursor::pos() ); 264 m->exec( QCursor::pos() );
265 265
266 if(m) delete m; 266 if(m) delete m;
267} 267}
268 268
269void NotesControl::focusOutEvent ( QFocusEvent * e) { 269void NotesControl::focusOutEvent ( QFocusEvent * e) {
270 if( e->reason() == QFocusEvent::Popup) 270 if( e->reason() == QFocusEvent::Popup)
271 save(); 271 save();
272 else { 272 else {
273 if(!loaded) { 273 if(!loaded) {
274 populateBox(); 274 populateBox();
275 load(); 275 load();
276 } 276 }
277 } 277 }
278 QWidget::focusOutEvent(e); 278 QWidget::focusOutEvent(e);
279} 279}
280 280
281void NotesControl::save() { 281void NotesControl::save() {
282 Config cfg("Notes"); 282 Config cfg("Notes");
283 cfg.setGroup("Docs"); 283 cfg.setGroup("Docs");
284 if( edited) { 284 if( edited) {
285// qDebug("is edited"); 285// qDebug("is edited");
286 QString rt = view->text(); 286 QString rt = view->text();
287 if( rt.length()>1) { 287 if( rt.length()>1) {
288 QString pt = rt.simplifyWhiteSpace(); 288 QString pt = rt.simplifyWhiteSpace();
289 int i = pt.find( ' ', pt.find( ' ' )+2 ); 289 int i = pt.find( ' ', pt.find( ' ' )+2 );
290 QString docname = pt; 290 QString docname = pt;
291 if ( i > 0 ) 291 if ( i > 0 )
292 docname = pt.left(i); 292 docname = pt.left(i);
293 // remove "." at the beginning 293 // remove "." at the beginning
294 while( docname.startsWith( "." ) ) 294 while( docname.startsWith( "." ) )
295 docname = docname.mid( 1 ); 295 docname = docname.mid( 1 );
296 docname.replace( QRegExp("/"), "_" ); 296 docname.replace( QRegExp("/"), "_" );
297 // cut the length. filenames longer than that don't make sense 297 // cut the length. filenames longer than that don't make sense
298 // and something goes wrong when they get too long. 298 // and something goes wrong when they get too long.
299 if ( docname.length() > 40 ) 299 if ( docname.length() > 40 )
300 docname = docname.left(40); 300 docname = docname.left(40);
301 if ( docname.isEmpty() ) 301 if ( docname.isEmpty() )
302 docname = "Empty Text"; 302 docname = "Empty Text";
303// qDebug(docname); 303// qDebug(docname);
304 304
305 if( oldDocName != docname) { 305 if( oldDocName != docname) {
306 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 306 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
307 QString entryName; 307 QString entryName;
308 entryName.sprintf( "File%i", noOfFiles + 1 ); 308 entryName.sprintf( "File%i", noOfFiles + 1 );
309 cfg.writeEntry( entryName,docname ); 309 cfg.writeEntry( entryName,docname );
310 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 310 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
311 cfg.write(); 311 cfg.write();
312 } 312 }
313// else 313// else
314// qDebug("oldname equals docname"); 314// qDebug("oldname equals docname");
315 315
316 doc = new DocLnk(docname); 316 doc = new DocLnk(docname);
317 if(QFile(doc->linkFile()).exists()) 317 if(QFile(doc->linkFile()).exists())
318 qDebug("puppie"); 318 qDebug("puppie");
319 doc->setType("text/plain"); 319 doc->setType("text/plain");
320 doc->setName(docname); 320 doc->setName(docname);
321 QString temp = docname.replace( QRegExp(" "), "_" ); 321 QString temp = docname.replace( QRegExp(" "), "_" );
322 doc->setFile( QDir::homeDirPath()+"/notes/"+temp); 322 doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
323 FileManager fm; 323 FileManager fm;
324 if ( !fm.saveFile( *doc, rt ) ) { 324 if ( !fm.saveFile( *doc, rt ) ) {
325 } 325 }
326 326
327 oldDocName=docname; 327 oldDocName=docname;
328 edited=false; 328 edited=false;
329// qDebug("save"); 329// qDebug("save");
330 if (doPopulate) 330 if (doPopulate)
331 populateBox(); 331 populateBox();
332 } 332 }
333 cfg.writeEntry( "LastDoc",oldDocName ); 333 cfg.writeEntry( "LastDoc",oldDocName );
334 cfg.write(); 334 cfg.write();
335 335
336 } 336 }
337} 337}
338 338
339void NotesControl::populateBox() { 339void NotesControl::populateBox() {
340 box->clear(); 340 box->clear();
341// qDebug("populate"); 341// qDebug("populate");
342 Config cfg("Notes"); 342 Config cfg("Notes");
343 cfg.setGroup("Docs"); 343 cfg.setGroup("Docs");
344 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 344 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
345 QStringList list; 345 QStringList list;
346 QString entryName; 346 QString entryName;
347 for ( int i = 0; i < noOfFiles; i++ ) { 347 for ( int i = 0; i < noOfFiles; i++ ) {
348 entryName.sprintf( "File%i", i + 1 ); 348 entryName.sprintf( "File%i", i + 1 );
349 list.append(cfg.readEntry( entryName )); 349 list.append(cfg.readEntry( entryName ));
350 } 350 }
351 list.sort(); 351 list.sort();
352 box->insertStringList(list,-1); 352 box->insertStringList(list,-1);
353 doPopulate=false; 353 doPopulate=false;
354 update(); 354 update();
355} 355}
356 356
357void NotesControl::load() { 357void NotesControl::load() {
358 358
359 if(!loaded) { 359 if(!loaded) {
360 Config cfg("Notes"); 360 Config cfg("Notes");
361 cfg.setGroup("Docs"); 361 cfg.setGroup("Docs");
362 QString lastDoc=cfg.readEntry( "LastDoc","notes"); 362 QString lastDoc=cfg.readEntry( "LastDoc","notes");
363 DocLnk nf; 363 DocLnk nf;
364 nf.setType("text/plain"); 364 nf.setType("text/plain");
365 nf.setFile(lastDoc); 365 nf.setFile(lastDoc);
366 366
367 loadDoc(nf); 367 loadDoc(nf);
368 loaded=true; 368 loaded=true;
369 oldDocName=lastDoc; 369 oldDocName=lastDoc;
370 cfg.writeEntry( "LastDoc",oldDocName ); 370 cfg.writeEntry( "LastDoc",oldDocName );
371 cfg.write(); 371 cfg.write();
372 } 372 }
373} 373}
374 374
375void NotesControl::load(const QString & file) { 375void NotesControl::load(const QString & file) {
376 qDebug("loading "+file); 376 qDebug("loading "+file);
377 QString name = file; 377 QString name = file;
378 QString temp; 378 QString temp;
379 if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) 379 if( !QFile( QDir::homeDirPath()+"/"+file).exists() )
380 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); 380 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" );
381 else 381 else
382 temp = name; 382 temp = name;
383 if(!loaded) { 383 if(!loaded) {
384 DocLnk nf; 384 DocLnk nf;
385 nf.setType("text/plain"); 385 nf.setType("text/plain");
386 nf.setFile( temp); 386 nf.setFile( temp);
387 if(!temp.isEmpty()) 387 if(!temp.isEmpty())
388 loadDoc(nf); 388 loadDoc(nf);
389 loaded=true; 389 loaded=true;
390 } 390 }
391// view->setFocus(); 391// view->setFocus();
392 oldDocName=file; 392 oldDocName=file;
393 Config cfg("Notes"); 393 Config cfg("Notes");
394 cfg.setGroup("Docs"); 394 cfg.setGroup("Docs");
395 cfg.writeEntry( "LastDoc",oldDocName ); 395 cfg.writeEntry( "LastDoc",oldDocName );
396 cfg.write(); 396 cfg.write();
397} 397}
398 398
399void NotesControl::loadDoc( const DocLnk &f) { 399void NotesControl::loadDoc( const DocLnk &f) {
400 FileManager fm; 400 FileManager fm;
401 QString txt; 401 QString txt;
402 if ( !fm.loadFile( f, txt ) ) { 402 if ( !fm.loadFile( f, txt ) ) {
403 qDebug("could not load file "+f.file()); 403 qDebug("could not load file "+f.file());
404 return; 404 return;
405 } 405 }
406 view->setText(txt); 406 view->setText(txt);
407} 407}
408 408
409void NotesControl::slotViewEdited() { 409void NotesControl::slotViewEdited() {
410 if(loaded) { 410 if(loaded) {
411 edited=true; 411 edited=true;
412 } 412 }
413} 413}
414 414
415 415
416void NotesControl::slotShowMax() { 416void NotesControl::slotShowMax() {
417 Config cfg("Notes"); 417 Config cfg("Notes");
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index 9ce6618..6ef2e44 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -1,326 +1,326 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de> 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de>
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU General Public License version 2 as published by the Free Software 5** GNU General Public License version 2 as published by the Free Software
6** Foundation and appearing in the file LICENSE.GPL included in the 6** Foundation and appearing in the file LICENSE.GPL included in the
7** packaging of this file. 7** packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13 13
14#include "wireless.h" 14#include "wireless.h"
15#include "mgraph.h" 15#include "mgraph.h"
16#include "advancedconfig.h" 16#include "advancedconfig.h"
17#include "connect0.xpm" 17#include "connect0.xpm"
18#include "connect1.xpm" 18#include "connect1.xpm"
19#include "connect2.xpm" 19#include "connect2.xpm"
20#include "connect3.xpm" 20#include "connect3.xpm"
21#include "connect4.xpm" 21#include "connect4.xpm"
22#include "connect5.xpm" 22#include "connect5.xpm"
23#include "nowireless.xpm" 23#include "nowireless.xpm"
24 24
25/* OPIE */ 25/* OPIE */
26#include <opie2/onetwork.h> 26#include <opie2/onetwork.h>
27#include <opie2/otaskbarapplet.h> 27#include <opie2/otaskbarapplet.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30/* QT */ 30/* QT */
31#include <qradiobutton.h> 31#include <qradiobutton.h>
32#include <qpushbutton.h> 32#include <qpushbutton.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qslider.h> 35#include <qslider.h>
36#include <qbuttongroup.h> 36#include <qbuttongroup.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40 40
41/* STD */ 41/* STD */
42#include <sys/types.h> 42#include <sys/types.h>
43#include <signal.h> 43#include <signal.h>
44 44
45#define STYLE_BARS 0 45#define STYLE_BARS 0
46#define STYLE_ANTENNA 1 46#define STYLE_ANTENNA 1
47 47
48//#define MDEBUG 48//#define MDEBUG
49#undef MDEBUG 49#undef MDEBUG
50 50
51WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 51WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
52 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 52 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
53{ 53{
54 54
55 readConfig(); 55 readConfig();
56 writeConfigEntry( "UpdateFrequency", updateFrequency ); 56 writeConfigEntry( "UpdateFrequency", updateFrequency );
57 writeConfigEntry( "DisplayStyle", displayStyle ); 57 writeConfigEntry( "DisplayStyle", displayStyle );
58 58
59 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 59 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
60 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); 60 QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
61 61
62 /* status label */ 62 /* status label */
63 63
64 statusLabel = new QLabel( this, "statuslabel" ); 64 statusLabel = new QLabel( this, "statuslabel" );
65 QString text( "Wireless Status:<br>" 65 QString text( "Wireless Status:<br>"
66 "*** Unknown ***<br>" 66 "*** Unknown ***<br>"
67 "Card not inserted ?<br>" 67 "Card not inserted ?<br>"
68 "Or Sharp ROM ?<br>" 68 "Or Sharp ROM ?<br>"
69 "CELL: 00:00:00:00:00:00" ); 69 "CELL: 00:00:00:00:00:00" );
70 /* QString text( "Station: Unknown<br>" 70 /* QString text( "Station: Unknown<br>"
71 "ESSID: Unknown<br>" 71 "ESSID: Unknown<br>"
72 "MODE: Unknown<br>" 72 "MODE: Unknown<br>"
73 "FREQ: Unknown<br>" 73 "FREQ: Unknown<br>"
74 "CELL: AA:BB:CC:DD:EE:FF" ); */ 74 "CELL: AA:BB:CC:DD:EE:FF" ); */
75 statusLabel->setText( text ); 75 statusLabel->setText( text );
76 statusLabel->setFixedSize( statusLabel->sizeHint() ); 76 statusLabel->setFixedSize( statusLabel->sizeHint() );
77 grid->addWidget( statusLabel, 0, 0 ); 77 grid->addWidget( statusLabel, 0, 0 );
78 78
79 /* visualization group box */ 79 /* visualization group box */
80 80
81 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); 81 QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this );
82 QRadioButton* r1 = new QRadioButton( "Color Bars", group ); 82 QRadioButton* r1 = new QRadioButton( "Color Bars", group );
83 QRadioButton* r2 = new QRadioButton( "Antenna", group ); 83 QRadioButton* r2 = new QRadioButton( "Antenna", group );
84 r1->setFocusPolicy( QWidget::NoFocus ); 84 r1->setFocusPolicy( QWidget::NoFocus );
85 r2->setFocusPolicy( QWidget::NoFocus ); 85 r2->setFocusPolicy( QWidget::NoFocus );
86 group->setFocusPolicy( QWidget::NoFocus ); 86 group->setFocusPolicy( QWidget::NoFocus );
87 group->setButton( displayStyle ); 87 group->setButton( displayStyle );
88 grid->addWidget( group, 0, 1 ); 88 grid->addWidget( group, 0, 1 );
89 89
90 /* quality graph */ 90 /* quality graph */
91 91
92 mgraph = new MGraph( this ); 92 mgraph = new MGraph( this );
93 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 93 mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
94 mgraph->setMin( 0 ); 94 mgraph->setMin( 0 );
95 mgraph->setMax( 92 ); 95 mgraph->setMax( 92 );
96 grid->addWidget( mgraph, 1, 0 ); 96 grid->addWidget( mgraph, 1, 0 );
97 mgraph->setFocusPolicy( QWidget::NoFocus ); 97 mgraph->setFocusPolicy( QWidget::NoFocus );
98 98
99 /* advanced configuration Button */ 99 /* advanced configuration Button */
100 100
101 QPushButton* advanced = new QPushButton( "Advanced...", this ); 101 QPushButton* advanced = new QPushButton( "Advanced...", this );
102 advanced->setFocusPolicy( QWidget::NoFocus ); 102 advanced->setFocusPolicy( QWidget::NoFocus );
103 grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); 103 grid->addWidget( advanced, 2, 0, Qt::AlignCenter );
104 connect( advanced, SIGNAL( clicked() ), 104 connect( advanced, SIGNAL( clicked() ),
105 this, SLOT( advancedConfigClicked() ) ); 105 this, SLOT( advancedConfigClicked() ) );
106 106
107 /* update Frequency Label */ 107 /* update Frequency Label */
108 108
109 updateLabel = new QLabel( this ); 109 updateLabel = new QLabel( this );
110 text.sprintf( "Update every %d s", updateFrequency ); 110 text.sprintf( "Update every %d s", updateFrequency );
111 updateLabel->setText( text ); 111 updateLabel->setText( text );
112 grid->addWidget( updateLabel, 2, 1 ); 112 grid->addWidget( updateLabel, 2, 1 );
113 113
114 /* update Frequency Slider */ 114 /* update Frequency Slider */
115 115
116 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); 116 QSlider* updateSlider = new QSlider( QSlider::Horizontal, this );
117 updateSlider->setRange( 0, 9 ); 117 updateSlider->setRange( 0, 9 );
118 updateSlider->setValue( updateFrequency ); 118 updateSlider->setValue( updateFrequency );
119 updateSlider->setTickmarks( QSlider::Both ); 119 updateSlider->setTickmarks( QSlider::Both );
120 updateSlider->setTickInterval( 1 ); 120 updateSlider->setTickInterval( 1 );
121 updateSlider->setSteps( 1, 1 ); 121 updateSlider->setSteps( 1, 1 );
122 updateSlider->setFocusPolicy( QWidget::NoFocus ); 122 updateSlider->setFocusPolicy( QWidget::NoFocus );
123 grid->addWidget( updateSlider, 1, 1 ); 123 grid->addWidget( updateSlider, 1, 1 );
124 connect( updateSlider, SIGNAL( valueChanged( int ) ), 124 connect( updateSlider, SIGNAL( valueChanged(int) ),
125 this, SLOT( updateDelayChange( int ) ) ); 125 this, SLOT( updateDelayChange(int) ) );
126 126
127 setFixedSize( sizeHint() ); 127 setFixedSize( sizeHint() );
128 setFocusPolicy( QWidget::NoFocus ); 128 setFocusPolicy( QWidget::NoFocus );
129 129
130 applet->displayStyleChange( displayStyle ); 130 applet->displayStyleChange( displayStyle );
131 applet->updateDelayChange( updateFrequency ); 131 applet->updateDelayChange( updateFrequency );
132 132
133 connect( group, SIGNAL( clicked( int ) ), 133 connect( group, SIGNAL( clicked(int) ),
134 this, SLOT( displayStyleChange( int ) ) ); 134 this, SLOT( displayStyleChange(int) ) );
135 135
136 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 136 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
137} 137}
138 138
139void WirelessControl::advancedConfigClicked() 139void WirelessControl::advancedConfigClicked()
140{ 140{
141 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE ); 141 AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE );
142 int result = a->exec(); 142 int result = a->exec();
143 a->hide(); 143 a->hide();
144 delete a; 144 delete a;
145 if ( result == QDialog::Accepted ) 145 if ( result == QDialog::Accepted )
146 { 146 {
147 readConfig(); 147 readConfig();
148 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); 148 applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE );
149 } 149 }
150} 150}
151 151
152void WirelessControl::updateDelayChange( int delay ) 152void WirelessControl::updateDelayChange( int delay )
153{ 153{
154 QString text; 154 QString text;
155 text.sprintf( "Update every %d s", delay ); 155 text.sprintf( "Update every %d s", delay );
156 updateLabel->setText( text ); 156 updateLabel->setText( text );
157 applet->updateDelayChange( delay ); 157 applet->updateDelayChange( delay );
158 writeConfigEntry( "UpdateFrequency", delay ); 158 writeConfigEntry( "UpdateFrequency", delay );
159} 159}
160 160
161void WirelessControl::displayStyleChange( int style ) 161void WirelessControl::displayStyleChange( int style )
162{ 162{
163 applet->displayStyleChange( style ); 163 applet->displayStyleChange( style );
164 writeConfigEntry( "DisplayStyle", style ); 164 writeConfigEntry( "DisplayStyle", style );
165} 165}
166 166
167void WirelessControl::show ( bool ) 167void WirelessControl::show ( bool )
168{ 168{
169 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); 169 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
170 170
171 int w = sizeHint().width(); 171 int w = sizeHint().width();
172 int x = curPos.x() - ( w / 2 ); 172 int x = curPos.x() - ( w / 2 );
173 173
174 if ( ( x + w ) > QPEApplication::desktop() ->width() ) 174 if ( ( x + w ) > QPEApplication::desktop() ->width() )
175 x = QPEApplication::desktop ( ) -> width ( ) - w; 175 x = QPEApplication::desktop ( ) -> width ( ) - w;
176 176
177 move( x, curPos.y () - sizeHint().height () ); 177 move( x, curPos.y () - sizeHint().height () );
178 QFrame::show(); 178 QFrame::show();
179} 179}
180 180
181void WirelessControl::readConfig() 181void WirelessControl::readConfig()
182{ 182{
183 Config cfg( "qpe" ); 183 Config cfg( "qpe" );
184 cfg.setGroup( "Wireless" ); 184 cfg.setGroup( "Wireless" );
185 185
186 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); 186 updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 );
187 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); 187 displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA );
188 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); 188 rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false );
189 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); 189 rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false );
190 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); 190 rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false );
191 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); 191 rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false );
192} 192}
193 193
194void WirelessControl::writeConfigEntry( const char *entry, int val ) 194void WirelessControl::writeConfigEntry( const char *entry, int val )
195{ 195{
196 Config cfg( "qpe" ); 196 Config cfg( "qpe" );
197 cfg.setGroup( "Wireless" ); 197 cfg.setGroup( "Wireless" );
198 cfg.writeEntry( entry, val ); 198 cfg.writeEntry( entry, val );
199} 199}
200 200
201//=========================================================================== 201//===========================================================================
202 202
203WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) 203WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
204 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), 204 : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ),
205 timer( 0 ), interface( 0 ), oldiface( 0 ), 205 timer( 0 ), interface( 0 ), oldiface( 0 ),
206 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) 206 rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false )
207{ 207{
208 setFixedHeight( 18 ); 208 setFixedHeight( 18 );
209 setFixedWidth( 14 ); 209 setFixedWidth( 14 );
210 status = new WirelessControl( this, this, "wireless status" ); 210 status = new WirelessControl( this, this, "wireless status" );
211} 211}
212 212
213void WirelessApplet::checkInterface() 213void WirelessApplet::checkInterface()
214{ 214{
215 interface = 0L; 215 interface = 0L;
216 ONetwork* net = ONetwork::instance(); 216 ONetwork* net = ONetwork::instance();
217 net->synchronize(); 217 net->synchronize();
218 ONetwork::InterfaceIterator it = net->iterator(); 218 ONetwork::InterfaceIterator it = net->iterator();
219 219
220 while ( it.current() && !it.current()->isWireless() ) ++it; 220 while ( it.current() && !it.current()->isWireless() ) ++it;
221 221
222 if ( it.current() && it.current()->isWireless() ) 222 if ( it.current() && it.current()->isWireless() )
223 interface = static_cast<OWirelessNetworkInterface*>( it.current() ); 223 interface = static_cast<OWirelessNetworkInterface*>( it.current() );
224 224
225 if ( interface ) 225 if ( interface )
226 { 226 {
227#ifdef MDEBUG 227#ifdef MDEBUG
228 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() ); 228 qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() );
229#endif 229#endif
230 230
231 } 231 }
232 else 232 else
233 { 233 {
234#ifdef MDEBUG 234#ifdef MDEBUG
235 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); 235 qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" );
236#endif 236#endif
237 hide(); 237 hide();
238 } 238 }
239} 239}
240 240
241void WirelessApplet::renewDHCP() 241void WirelessApplet::renewDHCP()
242{ 242{
243#ifdef MDEBUG 243#ifdef MDEBUG
244 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); 244 qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." );
245#endif 245#endif
246 246
247 QString pidfile; 247 QString pidfile;
248 if ( !interface ) 248 if ( !interface )
249 return ; 249 return ;
250 QString ifacename( interface->name() ); 250 QString ifacename( interface->name() );
251 251
252 // At first we are trying dhcpcd 252 // At first we are trying dhcpcd
253 253
254 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename ); 254 pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename );
255#ifdef MDEBUG 255#ifdef MDEBUG
256 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile ); 256 qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile );
257#endif 257#endif
258 int pid; 258 int pid;
259 QFile pfile( pidfile ); 259 QFile pfile( pidfile );
260 bool hasFile = pfile.open( IO_ReadOnly ); 260 bool hasFile = pfile.open( IO_ReadOnly );
261 QTextStream s( &pfile ); 261 QTextStream s( &pfile );
262 if ( hasFile ) 262 if ( hasFile )
263 { 263 {
264 s >> pid; 264 s >> pid;
265#ifdef MDEBUG 265#ifdef MDEBUG
266 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); 266 qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid );
267#endif 267#endif
268 kill( pid, SIGALRM ); 268 kill( pid, SIGALRM );
269 return ; 269 return ;
270 } 270 }
271 271
272 // No dhcpcd, so we are trying udhcpc 272 // No dhcpcd, so we are trying udhcpc
273#ifdef MDEBUG 273#ifdef MDEBUG
274 qDebug( "WIFIAPPLET: dhcpcd not available." ); 274 qDebug( "WIFIAPPLET: dhcpcd not available." );
275#endif 275#endif
276 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); 276 pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename );
277#ifdef MDEBUG 277#ifdef MDEBUG
278 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); 278 qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile );
279#endif 279#endif
280 QFile pfile2( pidfile ); 280 QFile pfile2( pidfile );
281 hasFile = pfile2.open( IO_ReadOnly ); 281 hasFile = pfile2.open( IO_ReadOnly );
282 QTextStream s2( &pfile2 ); 282 QTextStream s2( &pfile2 );
283 if ( hasFile ) 283 if ( hasFile )
284 { 284 {
285 s2 >> pid; 285 s2 >> pid;
286#ifdef MDEBUG 286#ifdef MDEBUG
287 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); 287 qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid );
288#endif 288#endif
289 kill( pid, SIGUSR1 ); 289 kill( pid, SIGUSR1 );
290 return ; 290 return ;
291 } 291 }
292} 292}
293 293
294void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) 294void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
295{ 295{
296 rocESSID = ESSID; 296 rocESSID = ESSID;
297 rocFREQ = FREQ; 297 rocFREQ = FREQ;
298 rocAP = AP; 298 rocAP = AP;
299 rocMODE = MODE; 299 rocMODE = MODE;
300} 300}
301 301
302void WirelessApplet::updateDelayChange( int delay ) 302void WirelessApplet::updateDelayChange( int delay )
303{ 303{
304 if ( timer ) 304 if ( timer )
305 killTimer( timer ); 305 killTimer( timer );
306 delay *= 1000; 306 delay *= 1000;
307 if ( delay == 0 ) 307 if ( delay == 0 )
308 delay = 50; 308 delay = 50;
309 timer = startTimer( delay ); 309 timer = startTimer( delay );
310} 310}
311 311
312void WirelessApplet::displayStyleChange( int style ) 312void WirelessApplet::displayStyleChange( int style )
313{ 313{
314 visualStyle = style; 314 visualStyle = style;
315 repaint(); 315 repaint();
316} 316}
317 317
318WirelessApplet::~WirelessApplet() 318WirelessApplet::~WirelessApplet()
319{} 319{}
320 320
321void WirelessApplet::timerEvent( QTimerEvent* ) 321void WirelessApplet::timerEvent( QTimerEvent* )
322{ 322{
323#ifdef MDEBUG 323#ifdef MDEBUG
324 qDebug( "WirelessApplet::timerEvent" ); 324 qDebug( "WirelessApplet::timerEvent" );
325#endif 325#endif
326 if ( interface ) 326 if ( interface )
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp
index 0b5ab78..0083e9b 100644
--- a/noncore/applets/zkbapplet/zkbwidget.cpp
+++ b/noncore/applets/zkbapplet/zkbwidget.cpp
@@ -1,162 +1,162 @@
1#include <opie2/otaskbarapplet.h> 1#include <opie2/otaskbarapplet.h>
2#include <qpe/qcopenvelope_qws.h> 2#include <qpe/qcopenvelope_qws.h>
3#include <qpe/applnk.h> 3#include <qpe/applnk.h>
4#include <qpe/qpeapplication.h> 4#include <qpe/qpeapplication.h>
5#include <qpe/resource.h> 5#include <qpe/resource.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <unistd.h> 7#include <unistd.h>
8#include "zkbwidget.h" 8#include "zkbwidget.h"
9#include "zkbcfg.h" 9#include "zkbcfg.h"
10 10
11ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), 11ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0),
12 disabled(Resource::loadPixmap("zkb-disabled")) { 12 disabled(Resource::loadPixmap("zkb-disabled")) {
13 13
14 labels = new QPopupMenu(); 14 labels = new QPopupMenu();
15 connect(labels, SIGNAL(activated(int)), this, 15 connect(labels, SIGNAL(activated(int)), this,
16 SLOT(labelChanged(int))); 16 SLOT(labelChanged(int)));
17 17
18 loadKeymap(); 18 loadKeymap();
19 19
20 channel = new QCopChannel("QPE/zkb", this); 20 channel = new QCopChannel("QPE/zkb", this);
21 connect(channel, SIGNAL(received(const QCString&, const QByteArray&)), 21 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
22 this, SLOT(signalReceived(const QCString&, const QByteArray&))); 22 this, SLOT(signalReceived(const QCString&,const QByteArray&)));
23 setFixedWidth ( AppLnk::smallIconSize() ); 23 setFixedWidth ( AppLnk::smallIconSize() );
24 setFixedHeight ( AppLnk::smallIconSize() ); 24 setFixedHeight ( AppLnk::smallIconSize() );
25} 25}
26 26
27ZkbWidget::~ZkbWidget() { 27ZkbWidget::~ZkbWidget() {
28} 28}
29 29
30int ZkbWidget::position() 30int ZkbWidget::position()
31{ 31{
32 return 8; 32 return 8;
33} 33}
34 34
35bool ZkbWidget::loadKeymap() { 35bool ZkbWidget::loadKeymap() {
36 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); 36 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb");
37 QFontMetrics fm(font()); 37 QFontMetrics fm(font());
38 38
39 if (keymap != 0) { 39 if (keymap != 0) {
40 delete keymap; 40 delete keymap;
41 keymap = 0; 41 keymap = 0;
42 } 42 }
43 43
44 Keymap* km = new Keymap(); 44 Keymap* km = new Keymap();
45 45
46 if (!c.load("zkb.xml", *km, "")) { 46 if (!c.load("zkb.xml", *km, "")) {
47 delete km; 47 delete km;
48 setPixmap(disabled); 48 setPixmap(disabled);
49 return false; 49 return false;
50 } 50 }
51 51
52 connect(km, SIGNAL(stateChanged(const QString&)), 52 connect(km, SIGNAL(stateChanged(const QString&)),
53 this, SLOT(stateChanged(const QString&))); 53 this, SLOT(stateChanged(const QString&)));
54 54
55 qwsServer->setKeyboardFilter(km); 55 qwsServer->setKeyboardFilter(km);
56 56
57 Keymap* oldkm = keymap; 57 Keymap* oldkm = keymap;
58 keymap = km; 58 keymap = km;
59 59
60 if (oldkm != 0) { 60 if (oldkm != 0) {
61 delete oldkm; 61 delete oldkm;
62 } 62 }
63 63
64 setText(keymap->getCurrentLabel()); 64 setText(keymap->getCurrentLabel());
65 65
66 labels->clear(); 66 labels->clear();
67 QStringList l = keymap->listLabels(); 67 QStringList l = keymap->listLabels();
68 labels->insertItem(disabled, 0, 0); 68 labels->insertItem(disabled, 0, 0);
69 int n = 1; 69 int n = 1;
70 w = 0; 70 w = 0;
71 for(QStringList::Iterator it = l.begin(); it != l.end(); 71 for(QStringList::Iterator it = l.begin(); it != l.end();
72 ++it, n++) { 72 ++it, n++) {
73 73
74 // printf("label: %s\n", (const char*) (*it).utf8()); 74 // printf("label: %s\n", (const char*) (*it).utf8());
75 75
76 labels->insertItem(*it, n, n); 76 labels->insertItem(*it, n, n);
77 int lw = fm.width(*it); 77 int lw = fm.width(*it);
78 if (lw > w) { 78 if (lw > w) {
79 w = lw; 79 w = lw;
80 } 80 }
81 } 81 }
82 82
83 if (w == 0) { 83 if (w == 0) {
84 hide(); 84 hide();
85 } else { 85 } else {
86 show(); 86 show();
87 } 87 }
88 return true; 88 return true;
89} 89}
90 90
91QSize ZkbWidget::sizeHint() const { 91QSize ZkbWidget::sizeHint() const {
92 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); 92 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize());
93} 93}
94 94
95void ZkbWidget::stateChanged(const QString& s) { 95void ZkbWidget::stateChanged(const QString& s) {
96 //qDebug("stateChanged: %s\n", (const char*) s.utf8()); 96 //qDebug("stateChanged: %s\n", (const char*) s.utf8());
97 setText(s); 97 setText(s);
98} 98}
99 99
100void ZkbWidget::labelChanged(int id) { 100void ZkbWidget::labelChanged(int id) {
101 if (id == 0) { 101 if (id == 0) {
102 keymap->disable(); 102 keymap->disable();
103 setPixmap(disabled); 103 setPixmap(disabled);
104 return; 104 return;
105 } 105 }
106 106
107 keymap->enable(); 107 keymap->enable();
108 108
109 QStringList l = keymap->listLabels(); 109 QStringList l = keymap->listLabels();
110 QString lbl = l[id-1]; 110 QString lbl = l[id-1];
111 111
112 //printf("labelChanged: %s\n", (const char*) lbl.utf8()); 112 //printf("labelChanged: %s\n", (const char*) lbl.utf8());
113 State* state = keymap->getStateByLabel(lbl); 113 State* state = keymap->getStateByLabel(lbl);
114 if (state != 0) { 114 if (state != 0) {
115 keymap->setCurrentState(state); 115 keymap->setCurrentState(state);
116 setText(lbl); 116 setText(lbl);
117 } 117 }
118} 118}
119 119
120void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { 120void ZkbWidget::mouseReleaseEvent(QMouseEvent*) {
121 QSize sh = labels->sizeHint(); 121 QSize sh = labels->sizeHint();
122 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); 122 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height()));
123 labels->exec(p); 123 labels->exec(p);
124} 124}
125 125
126void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { 126void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) {
127 QDataStream stream(data, IO_ReadOnly); 127 QDataStream stream(data, IO_ReadOnly);
128 128
129 if (msg == "enable()") { 129 if (msg == "enable()") {
130 keymap->enable(); 130 keymap->enable();
131 } else if (msg == "disable()") { 131 } else if (msg == "disable()") {
132 keymap->disable(); 132 keymap->disable();
133 } else if (msg == "reload()") { 133 } else if (msg == "reload()") {
134 QCopEnvelope("QPE/System", "busy()"); 134 QCopEnvelope("QPE/System", "busy()");
135 QTimer::singleShot(0, this, SLOT(reload())); 135 QTimer::singleShot(0, this, SLOT(reload()));
136 } else if (msg == "switch(QString)") { 136 } else if (msg == "switch(QString)") {
137 QString lbl; 137 QString lbl;
138 stream >> lbl; 138 stream >> lbl;
139 139
140 if (keymap != 0) { 140 if (keymap != 0) {
141 State* state = keymap->getStateByLabel(lbl); 141 State* state = keymap->getStateByLabel(lbl);
142 if (state != 0) { 142 if (state != 0) {
143 keymap->setCurrentState(state); 143 keymap->setCurrentState(state);
144 setText(lbl); 144 setText(lbl);
145 } 145 }
146 } 146 }
147 } else if (msg == "debug(QString)") { 147 } else if (msg == "debug(QString)") {
148 QString flag; 148 QString flag;
149 stream >> flag; 149 stream >> flag;
150 } 150 }
151} 151}
152 152
153void ZkbWidget::reload() { 153void ZkbWidget::reload() {
154 loadKeymap(); 154 loadKeymap();
155 QCopEnvelope("QPE/System", "notBusy()"); 155 QCopEnvelope("QPE/System", "notBusy()");
156} 156}
157 157
158Q_EXPORT_INTERFACE() 158Q_EXPORT_INTERFACE()
159{ 159{
160 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<ZkbWidget> ); 160 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<ZkbWidget> );
161} 161}
162 162