summaryrefslogtreecommitdiff
authorzecke <zecke>2004-10-17 18:38:39 (UTC)
committer zecke <zecke>2004-10-17 18:38:39 (UTC)
commite95fcb09fc069a83b3c10c19c081873daba49831 (patch) (unidiff)
tree13d13bac82d5bcf2489075e4f2962685ff3c897d
parent7e28835e246e06e157d760a40754b6257f2ad6b3 (diff)
downloadopie-e95fcb09fc069a83b3c10c19c081873daba49831.zip
opie-e95fcb09fc069a83b3c10c19c081873daba49831.tar.gz
opie-e95fcb09fc069a83b3c10c19c081873daba49831.tar.bz2
G++ 4.0 compiler fixes
-Remove anonymous structures and name them -Include 'card.h' to cardpile to make 'Card' known to QList so deleteItem will work -cast 'enum' to char in event.cpp and opimevent.cpp
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/firstuse.cpp9
-rw-r--r--libopie2/opiepim/core/opimevent.cpp2
-rw-r--r--library/backend/event.cpp2
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp26
-rw-r--r--noncore/games/qasteroids/view.cpp7
-rw-r--r--noncore/games/solitaire/cardpile.h2
6 files changed, 29 insertions, 19 deletions
diff --git a/core/launcher/firstuse.cpp b/core/launcher/firstuse.cpp
index acddeea..8344787 100644
--- a/core/launcher/firstuse.cpp
+++ b/core/launcher/firstuse.cpp
@@ -1,513 +1,514 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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// I need access to some things you don't normally get access to. 21// I need access to some things you don't normally get access to.
22 22
23#ifndef _MSC_VER 23#ifndef _MSC_VER
24 //### revise to allow removal of translators under MSVC 24 //### revise to allow removal of translators under MSVC
25#define private public 25#define private public
26#define protected public 26#define protected public
27#endif 27#endif
28#include "firstuse.h" 28#include "firstuse.h"
29#include "inputmethods.h" 29#include "inputmethods.h"
30#include "applauncher.h" 30#include "applauncher.h"
31#include "serverapp.h" 31#include "serverapp.h"
32#include "calibrate.h" 32#include "calibrate.h"
33#include "documentlist.h" 33#include "documentlist.h"
34 34
35/* OPIE */ 35/* OPIE */
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37#include <qtopia/resource.h> 37#include <qtopia/resource.h>
38#include <qtopia/qcopenvelope_qws.h> 38#include <qtopia/qcopenvelope_qws.h>
39#include <qtopia/config.h> 39#include <qtopia/config.h>
40#include <qtopia/fontmanager.h> 40#include <qtopia/fontmanager.h>
41using namespace Opie::Core; 41using namespace Opie::Core;
42 42
43/* QT */ 43/* QT */
44#include <qfile.h> 44#include <qfile.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#include <qsimplerichtext.h> 46#include <qsimplerichtext.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qlabel.h> 48#include <qlabel.h>
49#include <qtimer.h> 49#include <qtimer.h>
50 50
51#if defined( Q_WS_QWS ) 51#if defined( Q_WS_QWS )
52#include <qwsdisplay_qws.h> 52#include <qwsdisplay_qws.h>
53#include <qgfx_qws.h> 53#include <qgfx_qws.h>
54#endif 54#endif
55 55
56/* STD */ 56/* STD */
57#include <stdlib.h> 57#include <stdlib.h>
58#include <sys/types.h> 58#include <sys/types.h>
59#if defined(Q_OS_LINUX) || defined(_OS_LINUX_) 59#if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
60#include <unistd.h> 60#include <unistd.h>
61#endif 61#endif
62 62
63 63
64struct { 64struct settingsTable_t {
65 bool enabled; 65 bool enabled : 1;
66 const char *app; 66 const char *app;
67 const char *start; 67 const char *start;
68 const char *stop; 68 const char *stop;
69 const char *desc; 69 const char *desc;
70} 70};
71settingsTable [] = 71
72static settingsTable_t settingsTable [] =
72{ 73{
73 { FALSE, "language", "raise()", "accept()", // No tr 74 { FALSE, "language", "raise()", "accept()", // No tr
74 QT_TR_NOOP("Language") }, 75 QT_TR_NOOP("Language") },
75 { FALSE, "doctab", "raise()", "accept()", // No tr 76 { FALSE, "doctab", "raise()", "accept()", // No tr
76 QT_TR_NOOP("DocTab") }, 77 QT_TR_NOOP("DocTab") },
77#ifndef Q_OS_WIN32 78#ifndef Q_OS_WIN32
78 { FALSE, "systemtime", "raise()", "accept()", // No tr 79 { FALSE, "systemtime", "raise()", "accept()", // No tr
79 QT_TR_NOOP("Time and Date") }, 80 QT_TR_NOOP("Time and Date") },
80#endif 81#endif
81 { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr 82 { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr
82 QT_TR_NOOP("Personal Information") }, 83 QT_TR_NOOP("Personal Information") },
83 { FALSE, 0, 0, 0, 0 } 84 { FALSE, 0, 0, 0, 0 }
84}; 85};
85 86
86 87
87FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) : 88FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) :
88 QDialog( parent, name, TRUE, wf), 89 QDialog( parent, name, TRUE, wf),
89 transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1), 90 transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1),
90 waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE) 91 waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE)
91{ 92{
92 ServerApplication::allowRestart = FALSE; 93 ServerApplication::allowRestart = FALSE;
93 // we force our height beyound the maximum (which we set anyway) 94 // we force our height beyound the maximum (which we set anyway)
94 QRect desk = qApp->desktop()->geometry(); 95 QRect desk = qApp->desktop()->geometry();
95 setGeometry( 0, 0, desk.width(), desk.height() ); 96 setGeometry( 0, 0, desk.width(), desk.height() );
96 97
97 connect(qwsServer, SIGNAL(newChannel(const QString&)), 98 connect(qwsServer, SIGNAL(newChannel(const QString&)),
98 this, SLOT(newQcopChannel(const QString&))); 99 this, SLOT(newQcopChannel(const QString&)));
99 100
100 // Create a DocumentList so appLauncher has appLnkSet to search 101 // Create a DocumentList so appLauncher has appLnkSet to search
101 docList = new DocumentList( 0, FALSE ); 102 docList = new DocumentList( 0, FALSE );
102 appLauncher = new AppLauncher( this ); 103 appLauncher = new AppLauncher( this );
103 connect( appLauncher, SIGNAL(terminated(int,const QString&)), 104 connect( appLauncher, SIGNAL(terminated(int,const QString&)),
104 this, SLOT(terminated(int,const QString&)) ); 105 this, SLOT(terminated(int,const QString&)) );
105 106
106 // more hackery 107 // more hackery
107 // I will be run as either the main server or as part of the main server 108 // I will be run as either the main server or as part of the main server
108 QWSServer::setScreenSaverIntervals(0); 109 QWSServer::setScreenSaverIntervals(0);
109 loadPixmaps(); 110 loadPixmaps();
110 111
111 //check if there is a language program 112 //check if there is a language program
112#ifndef Q_OS_WIN32 113#ifndef Q_OS_WIN32
113 QString exeSuffix; 114 QString exeSuffix;
114#else 115#else
115 QString exeSuffix(".exe"); 116 QString exeSuffix(".exe");
116#endif 117#endif
117 118
118 for ( int i = 0; settingsTable[i].app; i++ ) { 119 for ( int i = 0; settingsTable[i].app; i++ ) {
119 QString file = QPEApplication::qpeDir() + "bin/"; 120 QString file = QPEApplication::qpeDir() + "bin/";
120 file += settingsTable[i].app; 121 file += settingsTable[i].app;
121 file += exeSuffix; 122 file += exeSuffix;
122 if ( QFile::exists(file) ) 123 if ( QFile::exists(file) )
123 settingsTable[i].enabled = TRUE; 124 settingsTable[i].enabled = TRUE;
124 } 125 }
125 126
126 setFocusPolicy(NoFocus); 127 setFocusPolicy(NoFocus);
127 128
128 taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader); 129 taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader);
129 130
130 inputMethods = new InputMethods(taskBar); 131 inputMethods = new InputMethods(taskBar);
131 connect(inputMethods, SIGNAL(inputToggled(bool)), 132 connect(inputMethods, SIGNAL(inputToggled(bool)),
132 this, SLOT(calcMaxWindowRect())); 133 this, SLOT(calcMaxWindowRect()));
133 134
134 back = new QPushButton(tr("<< Back"), taskBar); 135 back = new QPushButton(tr("<< Back"), taskBar);
135 back->setFocusPolicy(NoFocus); 136 back->setFocusPolicy(NoFocus);
136 connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) ); 137 connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) );
137 138
138 next = new QPushButton(tr("Next >>"), taskBar); 139 next = new QPushButton(tr("Next >>"), taskBar);
139 next->setFocusPolicy(NoFocus); 140 next->setFocusPolicy(NoFocus);
140 connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) ); 141 connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) );
141 142
142 // need to set the geom to lower corner 143 // need to set the geom to lower corner
143 QSize sz = inputMethods->sizeHint(); 144 QSize sz = inputMethods->sizeHint();
144 int buttonWidth = (width() - sz.width()) / 2; 145 int buttonWidth = (width() - sz.width()) / 2;
145 int x = 0; 146 int x = 0;
146 147
147 controlHeight = back->sizeHint().height(); 148 controlHeight = back->sizeHint().height();
148 149
149 inputMethods->setGeometry(0,0, sz.width(), controlHeight ); 150 inputMethods->setGeometry(0,0, sz.width(), controlHeight );
150 x += sz.width(); 151 x += sz.width();
151 152
152 back->setGeometry(x, 0, buttonWidth, controlHeight); 153 back->setGeometry(x, 0, buttonWidth, controlHeight);
153 x += buttonWidth; 154 x += buttonWidth;
154 next->setGeometry(x, 0, buttonWidth, controlHeight); 155 next->setGeometry(x, 0, buttonWidth, controlHeight);
155 156
156 taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight); 157 taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight);
157 taskBar->hide(); 158 taskBar->hide();
158 159
159#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 160#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
160 odebug << "Setting up QCop to QPE/System" << oendl; 161 odebug << "Setting up QCop to QPE/System" << oendl;
161 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 162 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
162 connect(sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), 163 connect(sysChannel, SIGNAL(received(const QCString&,const QByteArray&)),
163 this, SLOT(message(const QCString&,const QByteArray&)) ); 164 this, SLOT(message(const QCString&,const QByteArray&)) );
164#endif 165#endif
165 calcMaxWindowRect(); 166 calcMaxWindowRect();
166 167
167 m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false; 168 m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false;
168 169
169 if ( m_calHandler) { 170 if ( m_calHandler) {
170 if ( !QFile::exists("/etc/pointercal") ) { 171 if ( !QFile::exists("/etc/pointercal") ) {
171 needCalibrate = TRUE; 172 needCalibrate = TRUE;
172 grabMouse(); 173 grabMouse();
173 } 174 }
174 } 175 }
175 176
176 Config config("locale"); 177 Config config("locale");
177 config.setGroup( "Language"); 178 config.setGroup( "Language");
178 lang = config.readEntry( "Language", "en"); 179 lang = config.readEntry( "Language", "en");
179 180
180 defaultFont = font(); 181 defaultFont = font();
181 182
182 //###language/font hack; should look it up somewhere 183 //###language/font hack; should look it up somewhere
183#ifdef Q_WS_QWS 184#ifdef Q_WS_QWS
184 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 185 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
185 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 186 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
186 qApp->setFont( fn, TRUE ); 187 qApp->setFont( fn, TRUE );
187 } 188 }
188#endif 189#endif
189} 190}
190 191
191FirstUse::~FirstUse() 192FirstUse::~FirstUse()
192{ 193{
193 delete appLauncher; 194 delete appLauncher;
194 delete docList; 195 delete docList;
195 delete taskBar; 196 delete taskBar;
196 ServerApplication::allowRestart = TRUE; 197 ServerApplication::allowRestart = TRUE;
197} 198}
198 199
199void FirstUse::calcMaxWindowRect() 200void FirstUse::calcMaxWindowRect()
200{ 201{
201#ifdef Q_WS_QWS 202#ifdef Q_WS_QWS
202 QRect wr; 203 QRect wr;
203 int displayWidth = qApp->desktop()->width(); 204 int displayWidth = qApp->desktop()->width();
204 QRect ir = inputMethods->inputRect(); 205 QRect ir = inputMethods->inputRect();
205 if ( ir.isValid() ) { 206 if ( ir.isValid() ) {
206 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); 207 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
207 } else { 208 } else {
208 wr.setCoords( 0, 0, displayWidth-1, 209 wr.setCoords( 0, 0, displayWidth-1,
209 qApp->desktop()->height() - controlHeight-1); 210 qApp->desktop()->height() - controlHeight-1);
210 } 211 }
211 212
212#if QT_VERSION < 0x030000 213#if QT_VERSION < 0x030000
213 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, 214 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,
214 QSize(qt_screen->width(),qt_screen->height())) 215 QSize(qt_screen->width(),qt_screen->height()))
215 ); 216 );
216#else 217#else
217 QWSServer::setMaxWindowRect( wr ); 218 QWSServer::setMaxWindowRect( wr );
218#endif 219#endif
219#endif 220#endif
220} 221}
221 222
222/* cancel current dialog, and bring up next */ 223/* cancel current dialog, and bring up next */
223void FirstUse::nextDialog() 224void FirstUse::nextDialog()
224{ 225{
225 int prevApp = currApp; 226 int prevApp = currApp;
226 do { 227 do {
227 currApp++; 228 currApp++;
228 odebug << "currApp = " << currApp << "" << oendl; 229 odebug << "currApp = " << currApp << "" << oendl;
229 if ( settingsTable[currApp].app == 0 ) { 230 if ( settingsTable[currApp].app == 0 ) {
230 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { 231 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
231 // The last application is still running. 232 // The last application is still running.
232 // Tell it to stop, and when its done we'll come back 233 // Tell it to stop, and when its done we'll come back
233 // to nextDialog and exit. 234 // to nextDialog and exit.
234 odebug << "Waiting for " << settingsTable[prevApp].app << " to exit" << oendl; 235 odebug << "Waiting for " << settingsTable[prevApp].app << " to exit" << oendl;
235 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 236 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
236 settingsTable[prevApp].stop ); 237 settingsTable[prevApp].stop );
237 currApp = prevApp; 238 currApp = prevApp;
238 } else { 239 } else {
239 odebug << "Done!" << oendl; 240 odebug << "Done!" << oendl;
240 Config config( "qpe" ); 241 Config config( "qpe" );
241 config.setGroup( "Startup" ); 242 config.setGroup( "Startup" );
242 config.writeEntry( "FirstUse", FALSE ); 243 config.writeEntry( "FirstUse", FALSE );
243 QPixmap pix = Resource::loadPixmap("bigwait"); 244 QPixmap pix = Resource::loadPixmap("bigwait");
244 QLabel *lblWait = new QLabel(0, "wait hack!", // No tr 245 QLabel *lblWait = new QLabel(0, "wait hack!", // No tr
245 QWidget::WStyle_Customize | QWidget::WDestructiveClose | 246 QWidget::WStyle_Customize | QWidget::WDestructiveClose |
246 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | 247 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool |
247 QWidget::WStyle_StaysOnTop); 248 QWidget::WStyle_StaysOnTop);
248 lblWait->setPixmap( pix ); 249 lblWait->setPixmap( pix );
249 lblWait->setAlignment( QWidget::AlignCenter ); 250 lblWait->setAlignment( QWidget::AlignCenter );
250 lblWait->setGeometry( qApp->desktop()->geometry() ); 251 lblWait->setGeometry( qApp->desktop()->geometry() );
251 lblWait->show(); 252 lblWait->show();
252 qApp->processEvents(); 253 qApp->processEvents();
253 QTimer::singleShot( 1000, lblWait, SLOT(close()) ); 254 QTimer::singleShot( 1000, lblWait, SLOT(close()) );
254 repaint(); 255 repaint();
255 close(); 256 close();
256 ServerApplication::allowRestart = TRUE; 257 ServerApplication::allowRestart = TRUE;
257 } 258 }
258 return; 259 return;
259 } 260 }
260 } while ( !settingsTable[currApp].enabled ); 261 } while ( !settingsTable[currApp].enabled );
261 262
262 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { 263 if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
263 odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl; 264 odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl;
264 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 265 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
265 settingsTable[prevApp].stop ); 266 settingsTable[prevApp].stop );
266 waitForExit = prevApp; 267 waitForExit = prevApp;
267 } else { 268 } else {
268 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; 269 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
269 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 270 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
270 settingsTable[currApp].start ); 271 settingsTable[currApp].start );
271 waitingForLaunch = TRUE; 272 waitingForLaunch = TRUE;
272 } 273 }
273 274
274 updateButtons(); 275 updateButtons();
275} 276}
276 277
277/* accept current dialog and bring up previous */ 278/* accept current dialog and bring up previous */
278void FirstUse::previousDialog() 279void FirstUse::previousDialog()
279{ 280{
280 int prevApp = currApp; 281 int prevApp = currApp;
281 do { 282 do {
282 currApp--; 283 currApp--;
283 if ( currApp < 0 ) { 284 if ( currApp < 0 ) {
284 currApp = prevApp; 285 currApp = prevApp;
285 return; 286 return;
286 } 287 }
287 } while ( !settingsTable[currApp].enabled ); 288 } while ( !settingsTable[currApp].enabled );
288 289
289 if ( prevApp >= 0 ) { 290 if ( prevApp >= 0 ) {
290 odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl; 291 odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl;
291 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, 292 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
292 settingsTable[prevApp].stop ); 293 settingsTable[prevApp].stop );
293/* 294/*
294 if (settingsTable[prevApp].app == QString("systemtime")) 295 if (settingsTable[prevApp].app == QString("systemtime"))
295 QCopEnvelope e("QPE/Application/citytime", "close()"); 296 QCopEnvelope e("QPE/Application/citytime", "close()");
296*/ 297*/
297 waitForExit = prevApp; 298 waitForExit = prevApp;
298 } else { 299 } else {
299 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; 300 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
300 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 301 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
301 settingsTable[currApp].start ); 302 settingsTable[currApp].start );
302 waitingForLaunch = TRUE; 303 waitingForLaunch = TRUE;
303 } 304 }
304 305
305 updateButtons(); 306 updateButtons();
306} 307}
307 308
308void FirstUse::message(const QCString &msg, const QByteArray &data) 309void FirstUse::message(const QCString &msg, const QByteArray &data)
309{ 310{
310 QDataStream stream( data, IO_ReadOnly ); 311 QDataStream stream( data, IO_ReadOnly );
311 if ( msg == "timeChange(QString)" ) { 312 if ( msg == "timeChange(QString)" ) {
312 QString t; 313 QString t;
313 stream >> t; 314 stream >> t;
314 if ( t.isNull() ) 315 if ( t.isNull() )
315 unsetenv("TZ"); 316 unsetenv("TZ");
316 else 317 else
317 setenv( "TZ", t.latin1(), 1 ); 318 setenv( "TZ", t.latin1(), 1 );
318 } 319 }
319} 320}
320 321
321void FirstUse::terminated( int, const QString &app ) 322void FirstUse::terminated( int, const QString &app )
322{ 323{
323 odebug << "--- terminated: " << app << "" << oendl; 324 odebug << "--- terminated: " << app << "" << oendl;
324 if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) { 325 if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) {
325 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; 326 odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
326 if ( settingsTable[waitForExit].app == "language" ) { // No tr 327 if ( settingsTable[waitForExit].app == "language" ) { // No tr
327 Config config("locale"); 328 Config config("locale");
328 config.setGroup( "Language"); 329 config.setGroup( "Language");
329 QString l = config.readEntry( "Language", "en"); 330 QString l = config.readEntry( "Language", "en");
330 if ( l != lang ) { 331 if ( l != lang ) {
331 reloadLanguages(); 332 reloadLanguages();
332 needRestart = TRUE; 333 needRestart = TRUE;
333 lang = l; 334 lang = l;
334 } 335 }
335 } 336 }
336 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, 337 QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
337 settingsTable[currApp].start ); 338 settingsTable[currApp].start );
338 waitingForLaunch = TRUE; 339 waitingForLaunch = TRUE;
339 updateButtons(); 340 updateButtons();
340 repaint(); 341 repaint();
341 waitForExit = -1; 342 waitForExit = -1;
342 } else if ( settingsTable[currApp].app == app ) { 343 } else if ( settingsTable[currApp].app == app ) {
343 nextDialog(); 344 nextDialog();
344 } else { 345 } else {
345 back->setEnabled(TRUE); 346 back->setEnabled(TRUE);
346 next->setEnabled(TRUE); 347 next->setEnabled(TRUE);
347 } 348 }
348} 349}
349 350
350void FirstUse::newQcopChannel(const QString& channelName) 351void FirstUse::newQcopChannel(const QString& channelName)
351{ 352{
352 odebug << "channel " << channelName.data() << " added" << oendl; 353 odebug << "channel " << channelName.data() << " added" << oendl;
353 QString prefix("QPE/Application/"); 354 QString prefix("QPE/Application/");
354 if (channelName.startsWith(prefix)) { 355 if (channelName.startsWith(prefix)) {
355 QString appName = channelName.mid(prefix.length()); 356 QString appName = channelName.mid(prefix.length());
356 if ( currApp >= 0 && appName == settingsTable[currApp].app ) { 357 if ( currApp >= 0 && appName == settingsTable[currApp].app ) {
357 odebug << "Application: " << settingsTable[currApp].app << " started" << oendl; 358 odebug << "Application: " << settingsTable[currApp].app << " started" << oendl;
358 waitingForLaunch = FALSE; 359 waitingForLaunch = FALSE;
359 updateButtons(); 360 updateButtons();
360 repaint(); 361 repaint();
361 } else if (appName != "quicklauncher") { 362 } else if (appName != "quicklauncher") {
362 back->setEnabled(FALSE); 363 back->setEnabled(FALSE);
363 next->setEnabled(FALSE); 364 next->setEnabled(FALSE);
364 } 365 }
365 } 366 }
366} 367}
367 368
368void FirstUse::reloadLanguages() 369void FirstUse::reloadLanguages()
369{ 370{
370 // read language from config file. Waiting on QCop takes too long. 371 // read language from config file. Waiting on QCop takes too long.
371 Config config("locale"); 372 Config config("locale");
372 config.setGroup( "Language"); 373 config.setGroup( "Language");
373 QString l = config.readEntry( "Language", "en"); 374 QString l = config.readEntry( "Language", "en");
374 QString cl = getenv("LANG"); 375 QString cl = getenv("LANG");
375 owarn << "language message - " + l << oendl; 376 owarn << "language message - " + l << oendl;
376 // setting anyway... 377 // setting anyway...
377 if (l.isNull() ) 378 if (l.isNull() )
378 unsetenv( "LANG" ); 379 unsetenv( "LANG" );
379 else { 380 else {
380 owarn << "and its not null" << oendl; 381 owarn << "and its not null" << oendl;
381 setenv( "LANG", l.latin1(), 1 ); 382 setenv( "LANG", l.latin1(), 1 );
382 } 383 }
383#ifndef QT_NO_TRANSLATION 384#ifndef QT_NO_TRANSLATION
384 // clear old translators 385 // clear old translators
385#ifndef _MSC_VER 386#ifndef _MSC_VER
386 //### revise to allow removal of translators under MSVC 387 //### revise to allow removal of translators under MSVC
387 if(qApp->translators) { 388 if(qApp->translators) {
388 qApp->translators->setAutoDelete(TRUE); 389 qApp->translators->setAutoDelete(TRUE);
389 delete (qApp->translators); 390 delete (qApp->translators);
390 qApp->translators = 0; 391 qApp->translators = 0;
391 } 392 }
392#endif 393#endif
393 394
394 // load translation tables 395 // load translation tables
395 transApp = new QTranslator(qApp); 396 transApp = new QTranslator(qApp);
396 QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm"; 397 QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm";
397 owarn << "loading " + tfn << oendl; 398 owarn << "loading " + tfn << oendl;
398 if ( transApp->load(tfn) ) { 399 if ( transApp->load(tfn) ) {
399 owarn << "installing translator" << oendl; 400 owarn << "installing translator" << oendl;
400 qApp->installTranslator( transApp ); 401 qApp->installTranslator( transApp );
401 } else { 402 } else {
402 delete transApp; 403 delete transApp;
403 transApp = 0; 404 transApp = 0;
404 } 405 }
405 406
406 transLib = new QTranslator(qApp); 407 transLib = new QTranslator(qApp);
407 tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm"; 408 tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm";
408 owarn << "loading " + tfn << oendl; 409 owarn << "loading " + tfn << oendl;
409 if ( transLib->load(tfn) ) { 410 if ( transLib->load(tfn) ) {
410 owarn << "installing translator library" << oendl; 411 owarn << "installing translator library" << oendl;
411 qApp->installTranslator( transLib ); 412 qApp->installTranslator( transLib );
412 } else { 413 } else {
413 delete transLib; 414 delete transLib;
414 transLib = 0; 415 transLib = 0;
415 } 416 }
416 loadPixmaps(); 417 loadPixmaps();
417 //###language/font hack; should look it up somewhere 418 //###language/font hack; should look it up somewhere
418#ifdef Q_WS_QWS 419#ifdef Q_WS_QWS
419 if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) { 420 if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) {
420 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 421 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
421 qApp->setFont( fn, TRUE ); 422 qApp->setFont( fn, TRUE );
422 } else { 423 } else {
423 qApp->setFont( defaultFont, TRUE ); 424 qApp->setFont( defaultFont, TRUE );
424 } 425 }
425#endif 426#endif
426#endif 427#endif
427} 428}
428 429
429void FirstUse::paintEvent( QPaintEvent * ) 430void FirstUse::paintEvent( QPaintEvent * )
430{ 431{
431 QPainter p( this ); 432 QPainter p( this );
432 433
433 p.drawPixmap(0,0, splash); 434 p.drawPixmap(0,0, splash);
434 435
435 QFont f = p.font(); 436 QFont f = p.font();
436 f.setPointSize(15); 437 f.setPointSize(15);
437 f.setItalic(FALSE); 438 f.setItalic(FALSE);
438 f.setBold(FALSE); 439 f.setBold(FALSE);
439 p.setFont(f); 440 p.setFont(f);
440 441
441 if ( currApp < 0 ) { 442 if ( currApp < 0 ) {
442 drawText(p, tr( "Tap anywhere on the screen to continue." )); 443 drawText(p, tr( "Tap anywhere on the screen to continue." ));
443 } else if ( settingsTable[currApp].app ) { 444 } else if ( settingsTable[currApp].app ) {
444 if ( waitingForLaunch ) 445 if ( waitingForLaunch )
445 drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) ); 446 drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) );
446 } else { 447 } else {
447 drawText(p, tr("Please wait...")); 448 drawText(p, tr("Please wait..."));
448 } 449 }
449} 450}
450 451
451void FirstUse::loadPixmaps() 452void FirstUse::loadPixmaps()
452{ 453{
453 splash.convertFromImage( Resource::loadImage("launcher/firstuse") 454 splash.convertFromImage( Resource::loadImage("launcher/firstuse")
454 .smoothScale( width(), height() ) ); 455 .smoothScale( width(), height() ) );
455 456
456 setBackgroundPixmap(splash); 457 setBackgroundPixmap(splash);
457} 458}
458 459
459void FirstUse::drawText(QPainter &p, const QString &text) 460void FirstUse::drawText(QPainter &p, const QString &text)
460{ 461{
461 QString altered = "<CENTER>" + text + "</CENTER>"; 462 QString altered = "<CENTER>" + text + "</CENTER>";
462 463
463 QSimpleRichText rt(altered, p.font()); 464 QSimpleRichText rt(altered, p.font());
464 rt.setWidth(width() - 20); 465 rt.setWidth(width() - 20);
465 466
466 int h = (height() * 3) / 10; // start at 30% 467 int h = (height() * 3) / 10; // start at 30%
467 if (rt.height() < height() / 2) 468 if (rt.height() < height() / 2)
468 h += ((height() / 2) - rt.height()) / 2; 469 h += ((height() / 2) - rt.height()) / 2;
469 rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette()); 470 rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette());
470} 471}
471 472
472void FirstUse::updateButtons() 473void FirstUse::updateButtons()
473{ 474{
474 if ( currApp >= 0 ) { 475 if ( currApp >= 0 ) {
475 taskBar->show(); 476 taskBar->show();
476 } 477 }
477 478
478 int i = currApp-1; 479 int i = currApp-1;
479 while ( i >= 0 && !settingsTable[i].enabled ) 480 while ( i >= 0 && !settingsTable[i].enabled )
480 i--; 481 i--;
481 back->setText(tr("<< Back")); 482 back->setText(tr("<< Back"));
482 back->setEnabled( i >= 0 && !waitingForLaunch ); 483 back->setEnabled( i >= 0 && !waitingForLaunch );
483 484
484 i = currApp+1; 485 i = currApp+1;
485 while ( settingsTable[i].app && !settingsTable[i].enabled ) 486 while ( settingsTable[i].app && !settingsTable[i].enabled )
486 i++; 487 i++;
487 if ( !settingsTable[i].app ) 488 if ( !settingsTable[i].app )
488 next->setText(tr("Finish")); 489 next->setText(tr("Finish"));
489 else 490 else
490 next->setText(tr("Next >>")); 491 next->setText(tr("Next >>"));
491 492
492 next->setEnabled( !waitingForLaunch ); 493 next->setEnabled( !waitingForLaunch );
493} 494}
494 495
495void FirstUse::keyPressEvent( QKeyEvent *e ) 496void FirstUse::keyPressEvent( QKeyEvent *e )
496{ 497{
497 // Allow cancelling at first dialog, in case display is broken. 498 // Allow cancelling at first dialog, in case display is broken.
498 if ( e->key() == Key_Escape && currApp < 0 ) 499 if ( e->key() == Key_Escape && currApp < 0 )
499 QDialog::keyPressEvent(e); 500 QDialog::keyPressEvent(e);
500} 501}
501 502
502void FirstUse::mouseReleaseEvent( QMouseEvent * ) 503void FirstUse::mouseReleaseEvent( QMouseEvent * )
503{ 504{
504 if ( currApp < 0 ) { 505 if ( currApp < 0 ) {
505 if ( m_calHandler && needCalibrate ) { 506 if ( m_calHandler && needCalibrate ) {
506 releaseMouse(); 507 releaseMouse();
507 Calibrate *cal = new Calibrate; 508 Calibrate *cal = new Calibrate;
508 cal->exec(); 509 cal->exec();
509 delete cal; 510 delete cal;
510 } 511 }
511 nextDialog(); 512 nextDialog();
512 } 513 }
513} 514}
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index c656c3d..7bc6c32 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -1,1028 +1,1028 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> 3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimevent.h" 30#include "opimevent.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecurrence.h> 33#include <opie2/opimrecurrence.h>
34#include <opie2/opimresolver.h> 34#include <opie2/opimresolver.h>
35#include <opie2/opimnotifymanager.h> 35#include <opie2/opimnotifymanager.h>
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37 37
38#include <qpe/categories.h> 38#include <qpe/categories.h>
39#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
40 40
41/* QT */ 41/* QT */
42 42
43namespace Opie 43namespace Opie
44{ 44{
45 45
46int OCalendarHelper::week( const QDate& date ) 46int OCalendarHelper::week( const QDate& date )
47{ 47{
48 // Calculates the week this date is in within that 48 // Calculates the week this date is in within that
49 // month. Equals the "row" is is in in the month view 49 // month. Equals the "row" is is in in the month view
50 int week = 1; 50 int week = 1;
51 QDate tmp( date.year(), date.month(), 1 ); 51 QDate tmp( date.year(), date.month(), 1 );
52 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 52 if ( date.dayOfWeek() < tmp.dayOfWeek() )
53 ++week; 53 ++week;
54 54
55 week += ( date.day() - 1 ) / 7; 55 week += ( date.day() - 1 ) / 7;
56 56
57 return week; 57 return week;
58} 58}
59 59
60 60
61int OCalendarHelper::ocurrence( const QDate& date ) 61int OCalendarHelper::ocurrence( const QDate& date )
62{ 62{
63 // calculates the number of occurrances of this day of the 63 // calculates the number of occurrances of this day of the
64 // week till the given date (e.g 3rd Wednesday of the month) 64 // week till the given date (e.g 3rd Wednesday of the month)
65 return ( date.day() - 1 ) / 7 + 1; 65 return ( date.day() - 1 ) / 7 + 1;
66} 66}
67 67
68 68
69int OCalendarHelper::dayOfWeek( char day ) 69int OCalendarHelper::dayOfWeek( char day )
70{ 70{
71 int dayOfWeek = 1; 71 int dayOfWeek = 1;
72 char i = OPimRecurrence::MON; 72 char i = OPimRecurrence::MON;
73 while ( !( i & day ) && i <= OPimRecurrence::SUN ) 73 while ( !( i & day ) && i <= static_cast<char>(OPimRecurrence::SUN) )
74 { 74 {
75 i <<= 1; 75 i <<= 1;
76 ++dayOfWeek; 76 ++dayOfWeek;
77 } 77 }
78 return dayOfWeek; 78 return dayOfWeek;
79} 79}
80 80
81 81
82int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) 82int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
83{ 83{
84 return ( second.year() - first.year() ) * 12 + 84 return ( second.year() - first.year() ) * 12 +
85 second.month() - first.month(); 85 second.month() - first.month();
86} 86}
87 87
88 88
89struct OPimEvent::Data : public QShared 89struct OPimEvent::Data : public QShared
90{ 90{
91 Data() : QShared() 91 Data() : QShared()
92 { 92 {
93 child = 0; 93 child = 0;
94 recur = 0; 94 recur = 0;
95 manager = 0; 95 manager = 0;
96 isAllDay = false; 96 isAllDay = false;
97 parent = 0; 97 parent = 0;
98 } 98 }
99 ~Data() 99 ~Data()
100 { 100 {
101 delete manager; 101 delete manager;
102 delete recur; 102 delete recur;
103 } 103 }
104 QString description; 104 QString description;
105 QString location; 105 QString location;
106 OPimNotifyManager* manager; 106 OPimNotifyManager* manager;
107 OPimRecurrence* recur; 107 OPimRecurrence* recur;
108 QString note; 108 QString note;
109 QDateTime created; 109 QDateTime created;
110 QDateTime start; 110 QDateTime start;
111 QDateTime end; 111 QDateTime end;
112bool isAllDay : 1; 112bool isAllDay : 1;
113 QString timezone; 113 QString timezone;
114 QArray<int>* child; 114 QArray<int>* child;
115 int parent; 115 int parent;
116}; 116};
117 117
118 118
119OPimEvent::OPimEvent( int uid ) 119OPimEvent::OPimEvent( int uid )
120 : OPimRecord( uid ) 120 : OPimRecord( uid )
121{ 121{
122 data = new Data; 122 data = new Data;
123} 123}
124 124
125 125
126OPimEvent::OPimEvent( const OPimEvent& ev ) 126OPimEvent::OPimEvent( const OPimEvent& ev )
127 : OPimRecord( ev ), data( ev.data ) 127 : OPimRecord( ev ), data( ev.data )
128{ 128{
129 data->ref(); 129 data->ref();
130} 130}
131 131
132 132
133OPimEvent::OPimEvent( const QMap<int, QString> map ) 133OPimEvent::OPimEvent( const QMap<int, QString> map )
134 : OPimRecord( 0 ) 134 : OPimRecord( 0 )
135{ 135{
136 data = new Data; 136 data = new Data;
137 137
138 fromMap( map ); 138 fromMap( map );
139} 139}
140 140
141 141
142OPimEvent::~OPimEvent() 142OPimEvent::~OPimEvent()
143{ 143{
144 if ( data->deref() ) 144 if ( data->deref() )
145 { 145 {
146 delete data; 146 delete data;
147 data = 0; 147 data = 0;
148 } 148 }
149} 149}
150 150
151 151
152OPimEvent& OPimEvent::operator=( const OPimEvent& ev ) 152OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
153{ 153{
154 if ( this == &ev ) return * this; 154 if ( this == &ev ) return * this;
155 155
156 OPimRecord::operator=( ev ); 156 OPimRecord::operator=( ev );
157 ev.data->ref(); 157 ev.data->ref();
158 deref(); 158 deref();
159 data = ev.data; 159 data = ev.data;
160 160
161 161
162 return *this; 162 return *this;
163} 163}
164 164
165 165
166QString OPimEvent::description() const 166QString OPimEvent::description() const
167{ 167{
168 return data->description; 168 return data->description;
169} 169}
170 170
171 171
172void OPimEvent::setDescription( const QString& description ) 172void OPimEvent::setDescription( const QString& description )
173{ 173{
174 changeOrModify(); 174 changeOrModify();
175 data->description = description; 175 data->description = description;
176} 176}
177 177
178 178
179void OPimEvent::setLocation( const QString& loc ) 179void OPimEvent::setLocation( const QString& loc )
180{ 180{
181 changeOrModify(); 181 changeOrModify();
182 data->location = loc; 182 data->location = loc;
183} 183}
184 184
185 185
186QString OPimEvent::location() const 186QString OPimEvent::location() const
187{ 187{
188 return data->location; 188 return data->location;
189} 189}
190 190
191 191
192OPimNotifyManager &OPimEvent::notifiers() const 192OPimNotifyManager &OPimEvent::notifiers() const
193{ 193{
194 // I hope we can skip the changeOrModify here 194 // I hope we can skip the changeOrModify here
195 // the notifier should take care of it 195 // the notifier should take care of it
196 // and OPimNotify is shared too 196 // and OPimNotify is shared too
197 if ( !data->manager ) 197 if ( !data->manager )
198 data->manager = new OPimNotifyManager; 198 data->manager = new OPimNotifyManager;
199 199
200 return *data->manager; 200 return *data->manager;
201} 201}
202 202
203 203
204bool OPimEvent::hasNotifiers() const 204bool OPimEvent::hasNotifiers() const
205{ 205{
206 if ( !data->manager ) 206 if ( !data->manager )
207 return false; 207 return false;
208 if ( data->manager->reminders().isEmpty() && 208 if ( data->manager->reminders().isEmpty() &&
209 data->manager->alarms().isEmpty() ) 209 data->manager->alarms().isEmpty() )
210 return false; 210 return false;
211 211
212 return true; 212 return true;
213} 213}
214 214
215 215
216OPimRecurrence OPimEvent::recurrence() const 216OPimRecurrence OPimEvent::recurrence() const
217{ 217{
218 if ( !data->recur ) 218 if ( !data->recur )
219 data->recur = new OPimRecurrence; 219 data->recur = new OPimRecurrence;
220 220
221 return *data->recur; 221 return *data->recur;
222} 222}
223 223
224 224
225void OPimEvent::setRecurrence( const OPimRecurrence& rec ) 225void OPimEvent::setRecurrence( const OPimRecurrence& rec )
226{ 226{
227 changeOrModify(); 227 changeOrModify();
228 if ( data->recur ) 228 if ( data->recur )
229 ( *data->recur ) = rec; 229 ( *data->recur ) = rec;
230 else 230 else
231 data->recur = new OPimRecurrence( rec ); 231 data->recur = new OPimRecurrence( rec );
232} 232}
233 233
234 234
235bool OPimEvent::hasRecurrence() const 235bool OPimEvent::hasRecurrence() const
236{ 236{
237 if ( !data->recur ) return false; 237 if ( !data->recur ) return false;
238 return data->recur->doesRecur(); 238 return data->recur->doesRecur();
239} 239}
240 240
241 241
242QString OPimEvent::note() const 242QString OPimEvent::note() const
243{ 243{
244 return data->note; 244 return data->note;
245} 245}
246 246
247 247
248void OPimEvent::setNote( const QString& note ) 248void OPimEvent::setNote( const QString& note )
249{ 249{
250 changeOrModify(); 250 changeOrModify();
251 data->note = note; 251 data->note = note;
252} 252}
253 253
254 254
255QDateTime OPimEvent::createdDateTime() const 255QDateTime OPimEvent::createdDateTime() const
256{ 256{
257 return data->created; 257 return data->created;
258} 258}
259 259
260 260
261void OPimEvent::setCreatedDateTime( const QDateTime& time ) 261void OPimEvent::setCreatedDateTime( const QDateTime& time )
262{ 262{
263 changeOrModify(); 263 changeOrModify();
264 data->created = time; 264 data->created = time;
265} 265}
266 266
267 267
268QDateTime OPimEvent::startDateTime() const 268QDateTime OPimEvent::startDateTime() const
269{ 269{
270 if ( data->isAllDay ) 270 if ( data->isAllDay )
271 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) ); 271 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
272 return data->start; 272 return data->start;
273} 273}
274 274
275 275
276QDateTime OPimEvent::startDateTimeInZone() const 276QDateTime OPimEvent::startDateTimeInZone() const
277{ 277{
278 /* if no timezone, or all day event or if the current and this timeZone match... */ 278 /* if no timezone, or all day event or if the current and this timeZone match... */
279 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime(); 279 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
280 280
281 OPimTimeZone zone( data->timezone ); 281 OPimTimeZone zone( data->timezone );
282 return zone.toDateTime( data->start, OPimTimeZone::current() ); 282 return zone.toDateTime( data->start, OPimTimeZone::current() );
283} 283}
284 284
285 285
286void OPimEvent::setStartDateTime( const QDateTime& dt ) 286void OPimEvent::setStartDateTime( const QDateTime& dt )
287{ 287{
288 changeOrModify(); 288 changeOrModify();
289 data->start = dt; 289 data->start = dt;
290} 290}
291 291
292 292
293QDateTime OPimEvent::endDateTime() const 293QDateTime OPimEvent::endDateTime() const
294{ 294{
295 /* 295 /*
296 * if all Day event the end time needs 296 * if all Day event the end time needs
297 * to be on the same day as the start 297 * to be on the same day as the start
298 */ 298 */
299 if ( data->isAllDay ) { 299 if ( data->isAllDay ) {
300 QDate end = data->end.isValid() ? data->end.date() : data->start.date() ; 300 QDate end = data->end.isValid() ? data->end.date() : data->start.date() ;
301 return QDateTime( end, QTime( 23, 59, 59 ) ); 301 return QDateTime( end, QTime( 23, 59, 59 ) );
302 } 302 }
303 return data->end; 303 return data->end;
304} 304}
305 305
306 306
307QDateTime OPimEvent::endDateTimeInZone() const 307QDateTime OPimEvent::endDateTimeInZone() const
308{ 308{
309 /* if no timezone, or all day event or if the current and this timeZone match... */ 309 /* if no timezone, or all day event or if the current and this timeZone match... */
310 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime(); 310 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
311 311
312 OPimTimeZone zone( data->timezone ); 312 OPimTimeZone zone( data->timezone );
313 return zone.toDateTime( data->end, OPimTimeZone::current() ); 313 return zone.toDateTime( data->end, OPimTimeZone::current() );
314} 314}
315 315
316 316
317void OPimEvent::setEndDateTime( const QDateTime& dt ) 317void OPimEvent::setEndDateTime( const QDateTime& dt )
318{ 318{
319 changeOrModify(); 319 changeOrModify();
320 data->end = dt; 320 data->end = dt;
321} 321}
322 322
323 323
324bool OPimEvent::isMultipleDay() const 324bool OPimEvent::isMultipleDay() const
325{ 325{
326 return data->end.date().day() - data->start.date().day(); 326 return data->end.date().day() - data->start.date().day();
327} 327}
328 328
329 329
330bool OPimEvent::isAllDay() const 330bool OPimEvent::isAllDay() const
331{ 331{
332 return data->isAllDay; 332 return data->isAllDay;
333} 333}
334 334
335 335
336void OPimEvent::setAllDay( bool allDay ) 336void OPimEvent::setAllDay( bool allDay )
337{ 337{
338 changeOrModify(); 338 changeOrModify();
339 data->isAllDay = allDay; 339 data->isAllDay = allDay;
340} 340}
341 341
342 342
343void OPimEvent::setTimeZone( const QString& tz ) 343void OPimEvent::setTimeZone( const QString& tz )
344{ 344{
345 changeOrModify(); 345 changeOrModify();
346 data->timezone = tz; 346 data->timezone = tz;
347} 347}
348 348
349 349
350QString OPimEvent::timeZone() const 350QString OPimEvent::timeZone() const
351{ 351{
352 if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" ); 352 if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" );
353 return data->timezone; 353 return data->timezone;
354} 354}
355 355
356 356
357bool OPimEvent::match( const QRegExp& re ) const 357bool OPimEvent::match( const QRegExp& re ) const
358{ 358{
359 if ( re.match( data->description ) != -1 ) 359 if ( re.match( data->description ) != -1 )
360 { 360 {
361 setLastHitField( Qtopia::DatebookDescription ); 361 setLastHitField( Qtopia::DatebookDescription );
362 return true; 362 return true;
363 } 363 }
364 if ( re.match( data->note ) != -1 ) 364 if ( re.match( data->note ) != -1 )
365 { 365 {
366 setLastHitField( Qtopia::Note ); 366 setLastHitField( Qtopia::Note );
367 return true; 367 return true;
368 } 368 }
369 if ( re.match( data->location ) != -1 ) 369 if ( re.match( data->location ) != -1 )
370 { 370 {
371 setLastHitField( Qtopia::Location ); 371 setLastHitField( Qtopia::Location );
372 return true; 372 return true;
373 } 373 }
374 if ( re.match( data->start.toString() ) != -1 ) 374 if ( re.match( data->start.toString() ) != -1 )
375 { 375 {
376 setLastHitField( Qtopia::StartDateTime ); 376 setLastHitField( Qtopia::StartDateTime );
377 return true; 377 return true;
378 } 378 }
379 if ( re.match( data->end.toString() ) != -1 ) 379 if ( re.match( data->end.toString() ) != -1 )
380 { 380 {
381 setLastHitField( Qtopia::EndDateTime ); 381 setLastHitField( Qtopia::EndDateTime );
382 return true; 382 return true;
383 } 383 }
384 return false; 384 return false;
385} 385}
386 386
387 387
388QString OPimEvent::toRichText() const 388QString OPimEvent::toRichText() const
389{ 389{
390 QString text, value; 390 QString text, value;
391 391
392 // description 392 // description
393 text += "<b><h3><img src=\"datebook/DateBook\">"; 393 text += "<b><h3><img src=\"datebook/DateBook\">";
394 if ( !description().isEmpty() ) 394 if ( !description().isEmpty() )
395 { 395 {
396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); 396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
397 } 397 }
398 text += "</h3></b><br><hr><br>"; 398 text += "</h3></b><br><hr><br>";
399 399
400 // location 400 // location
401 if ( !( value = location() ).isEmpty() ) 401 if ( !( value = location() ).isEmpty() )
402 { 402 {
403 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 403 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
404 text += Qtopia::escapeString( value ) + "<br>"; 404 text += Qtopia::escapeString( value ) + "<br>";
405 } 405 }
406 406
407 // all day event 407 // all day event
408 if ( isAllDay() ) 408 if ( isAllDay() )
409 { 409 {
410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
411 } 411 }
412 // multiple day event 412 // multiple day event
413 else if ( isMultipleDay () ) 413 else if ( isMultipleDay () )
414 { 414 {
415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
416 } 416 }
417 // start & end times 417 // start & end times
418 else 418 else
419 { 419 {
420 // start time 420 // start time
421 if ( startDateTime().isValid() ) 421 if ( startDateTime().isValid() )
422 { 422 {
423 text += "<b>" + QObject::tr( "Start:" ) + "</b> "; 423 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
424 text += Qtopia::escapeString( startDateTime().toString() ). 424 text += Qtopia::escapeString( startDateTime().toString() ).
425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
426 } 426 }
427 427
428 // end time 428 // end time
429 if ( endDateTime().isValid() ) 429 if ( endDateTime().isValid() )
430 { 430 {
431 text += "<b>" + QObject::tr( "End:" ) + "</b> "; 431 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
432 text += Qtopia::escapeString( endDateTime().toString() ). 432 text += Qtopia::escapeString( endDateTime().toString() ).
433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
434 } 434 }
435 } 435 }
436 436
437 // categories 437 // categories
438 if ( categoryNames( "Calendar" ).count() ) 438 if ( categoryNames( "Calendar" ).count() )
439 { 439 {
440 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 440 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
441 text += categoryNames( "Calendar" ).join( ", " ); 441 text += categoryNames( "Calendar" ).join( ", " );
442 text += "<br>"; 442 text += "<br>";
443 } 443 }
444 444
445 //notes 445 //notes
446 if ( !note().isEmpty() ) 446 if ( !note().isEmpty() )
447 { 447 {
448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>"; 448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
449 text += note(); 449 text += note();
450 // text += Qtopia::escapeString(note() ). 450 // text += Qtopia::escapeString(note() ).
451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
452 } 452 }
453 return text; 453 return text;
454} 454}
455 455
456 456
457QString OPimEvent::toShortText() const 457QString OPimEvent::toShortText() const
458{ 458{
459 QString text; 459 QString text;
460 text += QString::number( startDateTime().date().day() ); 460 text += QString::number( startDateTime().date().day() );
461 text += "."; 461 text += ".";
462 text += QString::number( startDateTime().date().month() ); 462 text += QString::number( startDateTime().date().month() );
463 text += "."; 463 text += ".";
464 text += QString::number( startDateTime().date().year() ); 464 text += QString::number( startDateTime().date().year() );
465 text += " "; 465 text += " ";
466 text += QString::number( startDateTime().time().hour() ); 466 text += QString::number( startDateTime().time().hour() );
467 text += ":"; 467 text += ":";
468 text += QString::number( startDateTime().time().minute() ); 468 text += QString::number( startDateTime().time().minute() );
469 text += " - "; 469 text += " - ";
470 text += description(); 470 text += description();
471 return text; 471 return text;
472} 472}
473 473
474 474
475QString OPimEvent::type() const 475QString OPimEvent::type() const
476{ 476{
477 return QString::fromLatin1( "OPimEvent" ); 477 return QString::fromLatin1( "OPimEvent" );
478} 478}
479 479
480 480
481QString OPimEvent::recordField( int /*id */ ) const 481QString OPimEvent::recordField( int /*id */ ) const
482{ 482{
483 return QString::null; 483 return QString::null;
484} 484}
485 485
486 486
487int OPimEvent::rtti() const 487int OPimEvent::rtti() const
488{ 488{
489 return OPimResolver::DateBook; 489 return OPimResolver::DateBook;
490} 490}
491 491
492 492
493bool OPimEvent::loadFromStream( QDataStream& ) 493bool OPimEvent::loadFromStream( QDataStream& )
494{ 494{
495 return true; 495 return true;
496} 496}
497 497
498 498
499bool OPimEvent::saveToStream( QDataStream& ) const 499bool OPimEvent::saveToStream( QDataStream& ) const
500{ 500{
501 return true; 501 return true;
502} 502}
503 503
504 504
505void OPimEvent::changeOrModify() 505void OPimEvent::changeOrModify()
506{ 506{
507 if ( data->count != 1 ) 507 if ( data->count != 1 )
508 { 508 {
509 data->deref(); 509 data->deref();
510 Data* d2 = new Data; 510 Data* d2 = new Data;
511 d2->description = data->description; 511 d2->description = data->description;
512 d2->location = data->location; 512 d2->location = data->location;
513 513
514 if ( data->manager ) 514 if ( data->manager )
515 d2->manager = new OPimNotifyManager( *data->manager ); 515 d2->manager = new OPimNotifyManager( *data->manager );
516 516
517 if ( data->recur ) 517 if ( data->recur )
518 d2->recur = new OPimRecurrence( *data->recur ); 518 d2->recur = new OPimRecurrence( *data->recur );
519 519
520 d2->note = data->note; 520 d2->note = data->note;
521 d2->created = data->created; 521 d2->created = data->created;
522 d2->start = data->start; 522 d2->start = data->start;
523 d2->end = data->end; 523 d2->end = data->end;
524 d2->isAllDay = data->isAllDay; 524 d2->isAllDay = data->isAllDay;
525 d2->timezone = data->timezone; 525 d2->timezone = data->timezone;
526 d2->parent = data->parent; 526 d2->parent = data->parent;
527 527
528 if ( data->child ) 528 if ( data->child )
529 { 529 {
530 d2->child = new QArray<int>( *data->child ); 530 d2->child = new QArray<int>( *data->child );
531 d2->child->detach(); 531 d2->child->detach();
532 } 532 }
533 533
534 data = d2; 534 data = d2;
535 } 535 }
536} 536}
537 537
538 538
539void OPimEvent::deref() 539void OPimEvent::deref()
540{ 540{
541 if ( data->deref() ) 541 if ( data->deref() )
542 { 542 {
543 delete data; 543 delete data;
544 data = 0; 544 data = 0;
545 } 545 }
546} 546}
547// Exporting Event data to map. Using the same 547// Exporting Event data to map. Using the same
548// encoding as ODateBookAccessBackend_xml does.. 548// encoding as ODateBookAccessBackend_xml does..
549// Thus, we could remove the stuff there and use this 549// Thus, we could remove the stuff there and use this
550// for it and for all other places.. 550// for it and for all other places..
551// Encoding should happen at one place, only ! (eilers) 551// Encoding should happen at one place, only ! (eilers)
552QMap<int, QString> OPimEvent::toMap() const 552QMap<int, QString> OPimEvent::toMap() const
553{ 553{
554 QMap<int, QString> retMap; 554 QMap<int, QString> retMap;
555 555
556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
561 if ( notifiers().alarms().count() ){ 561 if ( notifiers().alarms().count() ){
562 // Currently we just support one alarm.. (eilers) 562 // Currently we just support one alarm.. (eilers)
563 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 563 OPimAlarm alarm = notifiers().alarms() [ 0 ];
564 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 564 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
565 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 565 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
566 } 566 }
567 567
568 /* either use UTC timeZone or current() if there is was a timezone set */ 568 /* either use UTC timeZone or current() if there is was a timezone set */
569 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); 569 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
570 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime()))); 570 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
571 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() ))); 571 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
572 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 572 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
573 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 573 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
574 if ( parent() ) 574 if ( parent() )
575 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 575 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
576 if ( children().count() ) 576 if ( children().count() )
577 { 577 {
578 QArray<int> childr = children(); 578 QArray<int> childr = children();
579 QString buf; 579 QString buf;
580 for ( uint i = 0; i < childr.count(); i++ ) 580 for ( uint i = 0; i < childr.count(); i++ )
581 { 581 {
582 if ( i != 0 ) buf += " "; 582 if ( i != 0 ) buf += " ";
583 buf += QString::number( childr[ i ] ); 583 buf += QString::number( childr[ i ] );
584 } 584 }
585 retMap.insert( OPimEvent::FRecChildren, buf ); 585 retMap.insert( OPimEvent::FRecChildren, buf );
586 } 586 }
587 587
588 // Add recurrence stuff 588 // Add recurrence stuff
589 if ( hasRecurrence() ) 589 if ( hasRecurrence() )
590 { 590 {
591 OPimRecurrence recur = recurrence(); 591 OPimRecurrence recur = recurrence();
592 QMap<int, QString> recFields = recur.toMap(); 592 QMap<int, QString> recFields = recur.toMap();
593 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 593 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
594 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); 594 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
595 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); 595 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
596 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); 596 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
597 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); 597 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
598 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); 598 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
599 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); 599 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
600 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); 600 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
601 } 601 }
602 else 602 else
603 { 603 {
604 OPimRecurrence recur = recurrence(); 604 OPimRecurrence recur = recurrence();
605 QMap<int, QString> recFields = recur.toMap(); 605 QMap<int, QString> recFields = recur.toMap();
606 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 606 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
607 } 607 }
608 608
609 return retMap; 609 return retMap;
610} 610}
611 611
612 612
613void OPimEvent::fromMap( const QMap<int, QString>& map ) 613void OPimEvent::fromMap( const QMap<int, QString>& map )
614{ 614{
615 615
616 // We just want to set the UID if it is really stored. 616 // We just want to set the UID if it is really stored.
617 if ( !map[ OPimEvent::FUid ].isEmpty() ) 617 if ( !map[ OPimEvent::FUid ].isEmpty() )
618 setUid( map[ OPimEvent::FUid ].toInt() ); 618 setUid( map[ OPimEvent::FUid ].toInt() );
619 619
620 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 620 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
621 setDescription( map[ OPimEvent::FDescription ] ); 621 setDescription( map[ OPimEvent::FDescription ] );
622 setLocation( map[ OPimEvent::FLocation ] ); 622 setLocation( map[ OPimEvent::FLocation ] );
623 623
624 if ( map[ OPimEvent::FType ] == "AllDay" ) 624 if ( map[ OPimEvent::FType ] == "AllDay" )
625 setAllDay( true ); 625 setAllDay( true );
626 else 626 else
627 setAllDay( false ); 627 setAllDay( false );
628 628
629 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 629 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
630 { 630 {
631 setTimeZone( map[ OPimEvent::FTimeZone ] ); 631 setTimeZone( map[ OPimEvent::FTimeZone ] );
632 } 632 }
633 633
634 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 634 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
635 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 635 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
636 636
637 /* AllDay is always in UTC */ 637 /* AllDay is always in UTC */
638 if ( isAllDay() ) 638 if ( isAllDay() )
639 { 639 {
640 OPimTimeZone utc = OPimTimeZone::utc(); 640 OPimTimeZone utc = OPimTimeZone::utc();
641 setStartDateTime(utc.toDateTime( start ) ); 641 setStartDateTime(utc.toDateTime( start ) );
642 setEndDateTime ( utc.toDateTime( end ) ); 642 setEndDateTime ( utc.toDateTime( end ) );
643 } 643 }
644 else { 644 else {
645 /* to current date time */ 645 /* to current date time */
646 OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); 646 OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
647 647
648 setStartDateTime(to_zone.toDateTime( start)); 648 setStartDateTime(to_zone.toDateTime( start));
649 setEndDateTime (to_zone.toDateTime( end)); 649 setEndDateTime (to_zone.toDateTime( end));
650 } 650 }
651 651
652 int alarmTime = -1; 652 int alarmTime = -1;
653 if ( !map[ OPimEvent::FAlarm ].isEmpty() ) 653 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
654 alarmTime = map[ OPimEvent::FAlarm ].toInt(); 654 alarmTime = map[ OPimEvent::FAlarm ].toInt();
655 655
656 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 656 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
657 if ( ( alarmTime != -1 ) ) 657 if ( ( alarmTime != -1 ) )
658 { 658 {
659 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); 659 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
660 OPimAlarm al( sound , dt ); 660 OPimAlarm al( sound , dt );
661 notifiers().add( al ); 661 notifiers().add( al );
662 } 662 }
663 663
664 664
665 if ( !map[ OPimEvent::FNote ].isEmpty() ) 665 if ( !map[ OPimEvent::FNote ].isEmpty() )
666 setNote( map[ OPimEvent::FNote ] ); 666 setNote( map[ OPimEvent::FNote ] );
667 667
668 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 668 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
669 setParent( map[ OPimEvent::FRecParent ].toInt() ); 669 setParent( map[ OPimEvent::FRecParent ].toInt() );
670 670
671 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 671 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
672 { 672 {
673 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 673 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
674 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 674 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
675 { 675 {
676 addChild( ( *it ).toInt() ); 676 addChild( ( *it ).toInt() );
677 } 677 }
678 } 678 }
679 679
680 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. 680 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
681 if ( !map[ OPimEvent::FRType ].isEmpty() ) 681 if ( !map[ OPimEvent::FRType ].isEmpty() )
682 { 682 {
683 QMap<int, QString> recFields; 683 QMap<int, QString> recFields;
684 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); 684 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
685 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); 685 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
686 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); 686 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
687 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); 687 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
688 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); 688 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
689 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); 689 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
690 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); 690 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
691 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); 691 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
692 OPimRecurrence recur( recFields ); 692 OPimRecurrence recur( recFields );
693 setRecurrence( recur ); 693 setRecurrence( recur );
694 } 694 }
695 695
696} 696}
697 697
698 698
699int OPimEvent::parent() const 699int OPimEvent::parent() const
700{ 700{
701 return data->parent; 701 return data->parent;
702} 702}
703 703
704 704
705void OPimEvent::setParent( int uid ) 705void OPimEvent::setParent( int uid )
706{ 706{
707 changeOrModify(); 707 changeOrModify();
708 data->parent = uid; 708 data->parent = uid;
709} 709}
710 710
711 711
712QArray<int> OPimEvent::children() const 712QArray<int> OPimEvent::children() const
713{ 713{
714 if ( !data->child ) return QArray<int>(); 714 if ( !data->child ) return QArray<int>();
715 else 715 else
716 return data->child->copy(); 716 return data->child->copy();
717} 717}
718 718
719 719
720void OPimEvent::setChildren( const QArray<int>& arr ) 720void OPimEvent::setChildren( const QArray<int>& arr )
721{ 721{
722 changeOrModify(); 722 changeOrModify();
723 if ( data->child ) delete data->child; 723 if ( data->child ) delete data->child;
724 724
725 data->child = new QArray<int>( arr ); 725 data->child = new QArray<int>( arr );
726 data->child->detach(); 726 data->child->detach();
727} 727}
728 728
729 729
730void OPimEvent::addChild( int uid ) 730void OPimEvent::addChild( int uid )
731{ 731{
732 changeOrModify(); 732 changeOrModify();
733 if ( !data->child ) 733 if ( !data->child )
734 { 734 {
735 data->child = new QArray<int>( 1 ); 735 data->child = new QArray<int>( 1 );
736 ( *data->child ) [ 0 ] = uid; 736 ( *data->child ) [ 0 ] = uid;
737 } 737 }
738 else 738 else
739 { 739 {
740 int count = data->child->count(); 740 int count = data->child->count();
741 data->child->resize( count + 1 ); 741 data->child->resize( count + 1 );
742 ( *data->child ) [ count ] = uid; 742 ( *data->child ) [ count ] = uid;
743 } 743 }
744} 744}
745 745
746 746
747void OPimEvent::removeChild( int uid ) 747void OPimEvent::removeChild( int uid )
748{ 748{
749 if ( !data->child || !data->child->contains( uid ) ) return ; 749 if ( !data->child || !data->child->contains( uid ) ) return ;
750 changeOrModify(); 750 changeOrModify();
751 QArray<int> newAr( data->child->count() - 1 ); 751 QArray<int> newAr( data->child->count() - 1 );
752 int j = 0; 752 int j = 0;
753 uint count = data->child->count(); 753 uint count = data->child->count();
754 for ( uint i = 0; i < count; i++ ) 754 for ( uint i = 0; i < count; i++ )
755 { 755 {
756 if ( ( *data->child ) [ i ] != uid ) 756 if ( ( *data->child ) [ i ] != uid )
757 { 757 {
758 newAr[ j ] = ( *data->child ) [ i ]; 758 newAr[ j ] = ( *data->child ) [ i ];
759 j++; 759 j++;
760 } 760 }
761 } 761 }
762 ( *data->child ) = newAr; 762 ( *data->child ) = newAr;
763} 763}
764 764
765 765
766struct OEffectiveEvent::Data : public QShared 766struct OEffectiveEvent::Data : public QShared
767{ 767{
768 Data() : QShared() 768 Data() : QShared()
769 {} 769 {}
770 OPimEvent event; 770 OPimEvent event;
771 QDate date; 771 QDate date;
772 QTime start, end; 772 QTime start, end;
773 QDate startDate, endDate; 773 QDate startDate, endDate;
774bool dates : 1; 774bool dates : 1;
775}; 775};
776 776
777 777
778OEffectiveEvent::OEffectiveEvent() 778OEffectiveEvent::OEffectiveEvent()
779{ 779{
780 data = new Data; 780 data = new Data;
781 data->date = QDate::currentDate(); 781 data->date = QDate::currentDate();
782 data->start = data->end = QTime::currentTime(); 782 data->start = data->end = QTime::currentTime();
783 data->dates = false; 783 data->dates = false;
784} 784}
785 785
786 786
787OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate, 787OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
788 Position pos ) 788 Position pos )
789{ 789{
790 data = new Data; 790 data = new Data;
791 data->event = ev; 791 data->event = ev;
792 data->date = startDate; 792 data->date = startDate;
793 if ( pos & Start ) 793 if ( pos & Start )
794 data->start = ev.startDateTime().time(); 794 data->start = ev.startDateTime().time();
795 else 795 else
796 data->start = QTime( 0, 0, 0 ); 796 data->start = QTime( 0, 0, 0 );
797 797
798 if ( pos & End ) 798 if ( pos & End )
799 data->end = ev.endDateTime().time(); 799 data->end = ev.endDateTime().time();
800 else 800 else
801 data->end = QTime( 23, 59, 59 ); 801 data->end = QTime( 23, 59, 59 );
802 802
803 data->dates = false; 803 data->dates = false;
804} 804}
805 805
806 806
807OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) 807OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
808{ 808{
809 data = ev.data; 809 data = ev.data;
810 data->ref(); 810 data->ref();
811} 811}
812 812
813 813
814OEffectiveEvent::~OEffectiveEvent() 814OEffectiveEvent::~OEffectiveEvent()
815{ 815{
816 if ( data->deref() ) 816 if ( data->deref() )
817 { 817 {
818 delete data; 818 delete data;
819 data = 0; 819 data = 0;
820 } 820 }
821} 821}
822 822
823 823
824OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) 824OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
825{ 825{
826 if ( *this == ev ) return * this; 826 if ( *this == ev ) return * this;
827 827
828 ev.data->ref(); 828 ev.data->ref();
829 deref(); 829 deref();
830 data = ev.data; 830 data = ev.data;
831 831
832 return *this; 832 return *this;
833} 833}
834 834
835 835
836void OEffectiveEvent::setStartTime( const QTime& ti ) 836void OEffectiveEvent::setStartTime( const QTime& ti )
837{ 837{
838 changeOrModify(); 838 changeOrModify();
839 data->start = ti; 839 data->start = ti;
840} 840}
841 841
842 842
843void OEffectiveEvent::setEndTime( const QTime& en ) 843void OEffectiveEvent::setEndTime( const QTime& en )
844{ 844{
845 changeOrModify(); 845 changeOrModify();
846 data->end = en; 846 data->end = en;
847} 847}
848 848
849 849
850void OEffectiveEvent::setEvent( const OPimEvent& ev ) 850void OEffectiveEvent::setEvent( const OPimEvent& ev )
851{ 851{
852 changeOrModify(); 852 changeOrModify();
853 data->event = ev; 853 data->event = ev;
854} 854}
855 855
856 856
857void OEffectiveEvent::setDate( const QDate& da ) 857void OEffectiveEvent::setDate( const QDate& da )
858{ 858{
859 changeOrModify(); 859 changeOrModify();
860 data->date = da; 860 data->date = da;
861} 861}
862 862
863 863
864void OEffectiveEvent::setEffectiveDates( const QDate& from, 864void OEffectiveEvent::setEffectiveDates( const QDate& from,
865 const QDate& to ) 865 const QDate& to )
866{ 866{
867 if ( !from.isValid() ) 867 if ( !from.isValid() )
868 { 868 {
869 data->dates = false; 869 data->dates = false;
870 return ; 870 return ;
871 } 871 }
872 872
873 data->startDate = from; 873 data->startDate = from;
874 data->endDate = to; 874 data->endDate = to;
875} 875}
876 876
877 877
878QString OEffectiveEvent::description() const 878QString OEffectiveEvent::description() const
879{ 879{
880 return data->event.description(); 880 return data->event.description();
881} 881}
882 882
883 883
884QString OEffectiveEvent::location() const 884QString OEffectiveEvent::location() const
885{ 885{
886 return data->event.location(); 886 return data->event.location();
887} 887}
888 888
889 889
890QString OEffectiveEvent::note() const 890QString OEffectiveEvent::note() const
891{ 891{
892 return data->event.note(); 892 return data->event.note();
893} 893}
894 894
895 895
896OPimEvent OEffectiveEvent::event() const 896OPimEvent OEffectiveEvent::event() const
897{ 897{
898 return data->event; 898 return data->event;
899} 899}
900 900
901 901
902QTime OEffectiveEvent::startTime() const 902QTime OEffectiveEvent::startTime() const
903{ 903{
904 return data->start; 904 return data->start;
905} 905}
906 906
907 907
908QTime OEffectiveEvent::endTime() const 908QTime OEffectiveEvent::endTime() const
909{ 909{
910 return data->end; 910 return data->end;
911} 911}
912 912
913 913
914QDate OEffectiveEvent::date() const 914QDate OEffectiveEvent::date() const
915{ 915{
916 return data->date; 916 return data->date;
917} 917}
918 918
919 919
920int OEffectiveEvent::length() const 920int OEffectiveEvent::length() const
921{ 921{
922 return ( data->end.hour() * 60 - data->start.hour() * 60 ) 922 return ( data->end.hour() * 60 - data->start.hour() * 60 )
923 + QABS( data->start.minute() - data->end.minute() ); 923 + QABS( data->start.minute() - data->end.minute() );
924} 924}
925 925
926 926
927int OEffectiveEvent::size() const 927int OEffectiveEvent::size() const
928{ 928{
929 return ( data->end.hour() - data->start.hour() ) * 3600 929 return ( data->end.hour() - data->start.hour() ) * 3600
930 + ( data->end.minute() - data->start.minute() * 60 930 + ( data->end.minute() - data->start.minute() * 60
931 + data->end.second() - data->start.second() ); 931 + data->end.second() - data->start.second() );
932} 932}
933 933
934 934
935QDate OEffectiveEvent::startDate() const 935QDate OEffectiveEvent::startDate() const
936{ 936{
937 if ( data->dates ) 937 if ( data->dates )
938 return data->startDate; 938 return data->startDate;
939 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 939 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
940 return data->date; 940 return data->date;
941 else 941 else
942 return data->event.startDateTime().date(); 942 return data->event.startDateTime().date();
943} 943}
944 944
945 945
946QDate OEffectiveEvent::endDate() const 946QDate OEffectiveEvent::endDate() const
947{ 947{
948 if ( data->dates ) 948 if ( data->dates )
949 return data->endDate; 949 return data->endDate;
950 else if ( data->event.hasRecurrence() ) 950 else if ( data->event.hasRecurrence() )
951 return data->date; 951 return data->date;
952 else 952 else
953 return data->event.endDateTime().date(); 953 return data->event.endDateTime().date();
954} 954}
955 955
956 956
957void OEffectiveEvent::deref() 957void OEffectiveEvent::deref()
958{ 958{
959 if ( data->deref() ) 959 if ( data->deref() )
960 { 960 {
961 delete data; 961 delete data;
962 data = 0; 962 data = 0;
963 } 963 }
964} 964}
965 965
966 966
967void OEffectiveEvent::changeOrModify() 967void OEffectiveEvent::changeOrModify()
968{ 968{
969 if ( data->count != 1 ) 969 if ( data->count != 1 )
970 { 970 {
971 data->deref(); 971 data->deref();
972 Data* d2 = new Data; 972 Data* d2 = new Data;
973 d2->event = data->event; 973 d2->event = data->event;
974 d2->date = data->date; 974 d2->date = data->date;
975 d2->start = data->start; 975 d2->start = data->start;
976 d2->end = data->end; 976 d2->end = data->end;
977 d2->startDate = data->startDate; 977 d2->startDate = data->startDate;
978 d2->endDate = data->endDate; 978 d2->endDate = data->endDate;
979 d2->dates = data->dates; 979 d2->dates = data->dates;
980 data = d2; 980 data = d2;
981 } 981 }
982} 982}
983 983
984 984
985bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const 985bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const
986{ 986{
987 if ( data->date < e.date() ) 987 if ( data->date < e.date() )
988 return TRUE; 988 return TRUE;
989 if ( data->date == e.date() ) 989 if ( data->date == e.date() )
990 return ( startTime() < e.startTime() ); 990 return ( startTime() < e.startTime() );
991 else 991 else
992 return FALSE; 992 return FALSE;
993} 993}
994 994
995 995
996bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const 996bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const
997{ 997{
998 return ( data->date <= e.date() ); 998 return ( data->date <= e.date() );
999} 999}
1000 1000
1001 1001
1002bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const 1002bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const
1003{ 1003{
1004 return ( date() == e.date() 1004 return ( date() == e.date()
1005 && startTime() == e.startTime() 1005 && startTime() == e.startTime()
1006 && endTime() == e.endTime() 1006 && endTime() == e.endTime()
1007 && event() == e.event() ); 1007 && event() == e.event() );
1008} 1008}
1009 1009
1010 1010
1011bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const 1011bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const
1012{ 1012{
1013 return !( *this == e ); 1013 return !( *this == e );
1014} 1014}
1015 1015
1016 1016
1017bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const 1017bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const
1018{ 1018{
1019 return !( *this <= e ); 1019 return !( *this <= e );
1020} 1020}
1021 1021
1022 1022
1023bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const 1023bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const
1024{ 1024{
1025 return !( *this < e ); 1025 return !( *this < e );
1026} 1026}
1027 1027
1028} 1028}
diff --git a/library/backend/event.cpp b/library/backend/event.cpp
index 90860e8..abc420b 100644
--- a/library/backend/event.cpp
+++ b/library/backend/event.cpp
@@ -1,1354 +1,1354 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 "event.h" 21#include "event.h"
22#include "qfiledirect_p.h" 22#include "qfiledirect_p.h"
23#include <qtopia/timeconversion.h> 23#include <qtopia/timeconversion.h>
24#include <qtopia/stringutil.h> 24#include <qtopia/stringutil.h>
25#include <qtopia/private/recordfields.h> 25#include <qtopia/private/recordfields.h>
26#include <qbuffer.h> 26#include <qbuffer.h>
27#include <time.h> 27#include <time.h>
28#include "vobject_p.h" 28#include "vobject_p.h"
29 29
30#include <stdio.h> 30#include <stdio.h>
31 31
32using namespace Qtopia; 32using namespace Qtopia;
33 33
34static void write( QString& buf, const Event::RepeatPattern &r ) 34static void write( QString& buf, const Event::RepeatPattern &r )
35{ 35{
36 buf += " rtype=\""; 36 buf += " rtype=\"";
37 switch ( r.type ) { 37 switch ( r.type ) {
38 case Event::Daily: 38 case Event::Daily:
39 buf += "Daily"; 39 buf += "Daily";
40 break; 40 break;
41 case Event::Weekly: 41 case Event::Weekly:
42 buf += "Weekly"; 42 buf += "Weekly";
43 break; 43 break;
44 case Event::MonthlyDay: 44 case Event::MonthlyDay:
45 buf += "MonthlyDay"; 45 buf += "MonthlyDay";
46 break; 46 break;
47 case Event::MonthlyDate: 47 case Event::MonthlyDate:
48 buf += "MonthlyDate"; 48 buf += "MonthlyDate";
49 break; 49 break;
50 case Event::Yearly: 50 case Event::Yearly:
51 buf += "Yearly"; 51 buf += "Yearly";
52 break; 52 break;
53 default: 53 default:
54 buf += "NoRepeat"; 54 buf += "NoRepeat";
55 break; 55 break;
56 } 56 }
57 buf += "\""; 57 buf += "\"";
58 if ( r.days > 0 ) 58 if ( r.days > 0 )
59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\""; 59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\"";
60 if ( r.position != 0 ) 60 if ( r.position != 0 )
61 buf += " rposition=\"" + QString::number( r.position ) + "\""; 61 buf += " rposition=\"" + QString::number( r.position ) + "\"";
62 62
63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\""; 63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\"";
64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\""; 64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\"";
65 if ( r.hasEndDate ) 65 if ( r.hasEndDate )
66 buf += " enddt=\"" 66 buf += " enddt=\""
67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) ) 67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) )
68 + "\""; 68 + "\"";
69 buf += " created=\"" + QString::number( r.createTime ) + "\""; 69 buf += " created=\"" + QString::number( r.createTime ) + "\"";
70} 70}
71 71
72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia ); 72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia );
73 73
74/*! 74/*!
75 \class Event event.h 75 \class Event event.h
76 \brief The Event class holds the data of a calendar event. 76 \brief The Event class holds the data of a calendar event.
77 77
78 This data includes descriptive data of the event and schedualing information. 78 This data includes descriptive data of the event and schedualing information.
79 79
80 \ingroup qtopiaemb 80 \ingroup qtopiaemb
81 \ingroup qtopiadesktop 81 \ingroup qtopiadesktop
82*/ 82*/
83 83
84/*! 84/*!
85 \class Event::RepeatPattern 85 \class Event::RepeatPattern
86 \class The Event::RepeatPattern class is internal. 86 \class The Event::RepeatPattern class is internal.
87 \internal 87 \internal
88*/ 88*/
89 89
90/*! 90/*!
91 \enum Event::Days 91 \enum Event::Days
92 \internal 92 \internal
93*/ 93*/
94 94
95/*! 95/*!
96 \enum Event::Type 96 \enum Event::Type
97 \internal 97 \internal
98*/ 98*/
99 99
100/*! 100/*!
101 \enum Event::SoundTypeChoice 101 \enum Event::SoundTypeChoice
102 102
103 This enum type defines what kind of sound is made when an alarm occurs 103 This enum type defines what kind of sound is made when an alarm occurs
104 for an event. The currently defined types are: 104 for an event. The currently defined types are:
105 105
106 <ul> 106 <ul>
107 <li>\c Silent - No sound is produced. 107 <li>\c Silent - No sound is produced.
108 <li>\c Loud - A loud sound is produced. 108 <li>\c Loud - A loud sound is produced.
109 </ul> 109 </ul>
110*/ 110*/
111 111
112/*! 112/*!
113 \fn bool Event::operator<( const Event & ) const 113 \fn bool Event::operator<( const Event & ) const
114 \internal 114 \internal
115*/ 115*/
116 116
117/*! 117/*!
118 \fn bool Event::operator<=( const Event & ) const 118 \fn bool Event::operator<=( const Event & ) const
119 \internal 119 \internal
120*/ 120*/
121 121
122/*! 122/*!
123 \fn bool Event::operator!=( const Event & ) const 123 \fn bool Event::operator!=( const Event & ) const
124 \internal 124 \internal
125*/ 125*/
126 126
127/*! 127/*!
128 \fn bool Event::operator>( const Event & ) const 128 \fn bool Event::operator>( const Event & ) const
129 \internal 129 \internal
130*/ 130*/
131 131
132/*! 132/*!
133 \fn bool Event::operator>=( const Event & ) const 133 \fn bool Event::operator>=( const Event & ) const
134 \internal 134 \internal
135*/ 135*/
136 136
137/*! 137/*!
138 \enum Event::RepeatType 138 \enum Event::RepeatType
139 139
140 This enum defines how a event will repeat, if at all. 140 This enum defines how a event will repeat, if at all.
141 141
142 <ul> 142 <ul>
143 <li>\c NoRepeat - Event does not repeat. 143 <li>\c NoRepeat - Event does not repeat.
144 <li>\c Daily - Event occurs every n days. 144 <li>\c Daily - Event occurs every n days.
145 <li>\c Weekly - Event occurs every n weeks. 145 <li>\c Weekly - Event occurs every n weeks.
146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in 146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in
147 the same week and same day of week as the first event. 147 the same week and same day of week as the first event.
148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur 148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur
149 on the same day of the month as the first event. 149 on the same day of the month as the first event.
150 <li>\c Yearly - Event occurs every n years. 150 <li>\c Yearly - Event occurs every n years.
151 </ul> 151 </ul>
152*/ 152*/
153 153
154/*! 154/*!
155 \fn bool Event::isAllDay() const 155 \fn bool Event::isAllDay() const
156 156
157 Returns TRUE if the event is an all day event. Otherwise returns FALSE. 157 Returns TRUE if the event is an all day event. Otherwise returns FALSE.
158*/ 158*/
159 159
160/*! 160/*!
161 \fn void Event::setAllDay(bool allday) 161 \fn void Event::setAllDay(bool allday)
162 162
163 If \a allday is TRUE, will set the event to be an all day event. 163 If \a allday is TRUE, will set the event to be an all day event.
164 Otherwise sets the event to not be an all day event. 164 Otherwise sets the event to not be an all day event.
165 165
166 \warning This function may affect the start and end times of the event. 166 \warning This function may affect the start and end times of the event.
167*/ 167*/
168 168
169/*! 169/*!
170 \fn QDateTime Event::start(bool) const 170 \fn QDateTime Event::start(bool) const
171 171
172 Returns the start date and time of the first occurance of the event. 172 Returns the start date and time of the first occurance of the event.
173*/ 173*/
174 174
175/*! 175/*!
176 \fn QDateTime Event::end(bool) const 176 \fn QDateTime Event::end(bool) const
177 177
178 Returns the end date and time of the first occurance of the event. 178 Returns the end date and time of the first occurance of the event.
179*/ 179*/
180 180
181/*! 181/*!
182 \fn time_t Event::startTime() const 182 \fn time_t Event::startTime() const
183 \internal 183 \internal
184*/ 184*/
185 185
186/*! 186/*!
187 \fn time_t Event::endTime() const 187 \fn time_t Event::endTime() const
188 \internal 188 \internal
189*/ 189*/
190 190
191/*! 191/*!
192 \fn void Event::setAlarm(int delay, SoundTypeChoice s) 192 \fn void Event::setAlarm(int delay, SoundTypeChoice s)
193 193
194 Sets the alarm delay of the event to \a delay and the sound type of the 194 Sets the alarm delay of the event to \a delay and the sound type of the
195 alarm to \a s. 195 alarm to \a s.
196*/ 196*/
197 197
198/*! 198/*!
199 \fn void Event::clearAlarm() 199 \fn void Event::clearAlarm()
200 200
201 Clears the alarm for the event. 201 Clears the alarm for the event.
202*/ 202*/
203 203
204/*! 204/*!
205 \fn int Event::alarmDelay() const 205 \fn int Event::alarmDelay() const
206 206
207 Returns the delay in minutes between the alarm for an event and the 207 Returns the delay in minutes between the alarm for an event and the
208 start of the event. 208 start of the event.
209*/ 209*/
210 210
211/*! 211/*!
212 \fn Event::RepeatType Event::repeatType() const 212 \fn Event::RepeatType Event::repeatType() const
213 213
214 Returns the repeat pattern type for the event. 214 Returns the repeat pattern type for the event.
215 215
216 \sa frequency() 216 \sa frequency()
217*/ 217*/
218 218
219/*! 219/*!
220 \fn int Event::weekOffset() const 220 \fn int Event::weekOffset() const
221 221
222 Returns the number of weeks from the start of the month that this event 222 Returns the number of weeks from the start of the month that this event
223 occurs. 223 occurs.
224*/ 224*/
225 225
226/*! 226/*!
227 \fn QDate Event::repeatTill() const 227 \fn QDate Event::repeatTill() const
228 228
229 Returns the date that the event will continue to repeat until. If the event 229 Returns the date that the event will continue to repeat until. If the event
230 repeats forever the value returned is undefined. 230 repeats forever the value returned is undefined.
231 231
232 \sa repeatForever() 232 \sa repeatForever()
233*/ 233*/
234 234
235/*! 235/*!
236 \fn bool Event::repeatForever() const 236 \fn bool Event::repeatForever() const
237 237
238 Returns FALSE if there is a date set for the event to continue until. 238 Returns FALSE if there is a date set for the event to continue until.
239 Otherwise returns TRUE. 239 Otherwise returns TRUE.
240*/ 240*/
241 241
242/*! 242/*!
243 \fn bool Event::doRepeat() const 243 \fn bool Event::doRepeat() const
244 \internal 244 \internal
245*/ 245*/
246 246
247/*! 247/*!
248 \fn bool Event::repeatOnWeekDay(int day) const 248 \fn bool Event::repeatOnWeekDay(int day) const
249 249
250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on 250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on
251 \a day each week. Otherwise returns FALSE. 251 \a day each week. Otherwise returns FALSE.
252 252
253 \sa QDate::dayName() 253 \sa QDate::dayName()
254*/ 254*/
255 255
256/*! 256/*!
257 \fn void Event::setRepeatOnWeekDay(int day, bool enable) 257 \fn void Event::setRepeatOnWeekDay(int day, bool enable)
258 258
259 If \a enable is TRUE then sets the event to occur on \a day each week. 259 If \a enable is TRUE then sets the event to occur on \a day each week.
260 Otherwise sets the event not to occur on \a day. 260 Otherwise sets the event not to occur on \a day.
261 261
262 \warning this function is only relavent for a event with RepeatType of 262 \warning this function is only relavent for a event with RepeatType of
263 Weekly. 263 Weekly.
264 264
265 \sa QDate::dayName() 265 \sa QDate::dayName()
266*/ 266*/
267 267
268/*! 268/*!
269 \fn int Event::frequency() const 269 \fn int Event::frequency() const
270 270
271 Returns how often the event repeats. 271 Returns how often the event repeats.
272 272
273 \sa repeatType() 273 \sa repeatType()
274*/ 274*/
275 275
276/*! 276/*!
277 \fn void Event::setRepeatType(RepeatType t) 277 \fn void Event::setRepeatType(RepeatType t)
278 278
279 Sets the repeat pattern type of the event to \a t. 279 Sets the repeat pattern type of the event to \a t.
280 280
281 \sa setFrequency() 281 \sa setFrequency()
282*/ 282*/
283 283
284/*! 284/*!
285 \fn void Event::setFrequency(int n) 285 \fn void Event::setFrequency(int n)
286 286
287 Sets how often the event occurs with in its repeat pattern. 287 Sets how often the event occurs with in its repeat pattern.
288 288
289 \sa setRepeatType() 289 \sa setRepeatType()
290*/ 290*/
291 291
292/*! 292/*!
293 \fn void Event::setRepeatTill(const QDate &d) 293 \fn void Event::setRepeatTill(const QDate &d)
294 294
295 Sets the event to repeat until \a d. 295 Sets the event to repeat until \a d.
296*/ 296*/
297 297
298/*! 298/*!
299 \fn void Event::setRepeatForever(bool enable) 299 \fn void Event::setRepeatForever(bool enable)
300 300
301 If \a enable is TRUE, sets the event to repeat forever. Otherwise 301 If \a enable is TRUE, sets the event to repeat forever. Otherwise
302 sets the event to stop repeating at some date. 302 sets the event to stop repeating at some date.
303 303
304 \warning This function may affect the specific date the event will repeat 304 \warning This function may affect the specific date the event will repeat
305 till. 305 till.
306*/ 306*/
307 307
308/*! 308/*!
309 \fn bool Event::match(const QRegExp &r) const 309 \fn bool Event::match(const QRegExp &r) const
310 310
311 Returns TRUE if the event matches the regular expression \a r. 311 Returns TRUE if the event matches the regular expression \a r.
312 Otherwise returns FALSE. 312 Otherwise returns FALSE.
313*/ 313*/
314 314
315/*! 315/*!
316 \fn char Event::day(int) 316 \fn char Event::day(int)
317 \internal 317 \internal
318*/ 318*/
319 319
320/*! 320/*!
321 Creates a new, empty event. 321 Creates a new, empty event.
322*/ 322*/
323Event::Event() : Record() 323Event::Event() : Record()
324{ 324{
325 startUTC = endUTC = time( 0 ); 325 startUTC = endUTC = time( 0 );
326 typ = Normal; 326 typ = Normal;
327 hAlarm = FALSE; 327 hAlarm = FALSE;
328 hRepeat = FALSE; 328 hRepeat = FALSE;
329 aMinutes = 0; 329 aMinutes = 0;
330 aSound = Silent; 330 aSound = Silent;
331 pattern.type = NoRepeat; 331 pattern.type = NoRepeat;
332 pattern.frequency = -1; 332 pattern.frequency = -1;
333} 333}
334 334
335/*! 335/*!
336 \internal 336 \internal
337*/ 337*/
338Event::Event( const QMap<int, QString> &map ) 338Event::Event( const QMap<int, QString> &map )
339{ 339{
340 setDescription( map[DatebookDescription] ); 340 setDescription( map[DatebookDescription] );
341 setLocation( map[Location] ); 341 setLocation( map[Location] );
342 setCategories( idsFromString( map[DatebookCategory] ) ); 342 setCategories( idsFromString( map[DatebookCategory] ) );
343 setTimeZone( map[TimeZone] ); 343 setTimeZone( map[TimeZone] );
344 setNotes( map[Note] ); 344 setNotes( map[Note] );
345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) ); 345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) );
346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) ); 346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) );
347 setType( (Event::Type) map[DatebookType].toInt() ); 347 setType( (Event::Type) map[DatebookType].toInt() );
348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() ); 348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() );
349 Event::RepeatPattern p; 349 Event::RepeatPattern p;
350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt(); 350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt();
351 p.frequency = map[ RepeatPatternFrequency ].toInt(); 351 p.frequency = map[ RepeatPatternFrequency ].toInt();
352 p.position = map[ RepeatPatternPosition ].toInt(); 352 p.position = map[ RepeatPatternPosition ].toInt();
353 p.days = map[ RepeatPatternDays ].toInt(); 353 p.days = map[ RepeatPatternDays ].toInt();
354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt(); 354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt();
355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt(); 355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt();
356 setRepeat( p ); 356 setRepeat( p );
357 357
358 setUid( map[ DatebookUid ].toInt() ); 358 setUid( map[ DatebookUid ].toInt() );
359} 359}
360 360
361/*! 361/*!
362 Destroys an event. 362 Destroys an event.
363*/ 363*/
364Event::~Event() 364Event::~Event()
365{ 365{
366} 366}
367 367
368/*! 368/*!
369 \internal 369 \internal
370*/ 370*/
371int Event::week( const QDate& date ) 371int Event::week( const QDate& date )
372{ 372{
373 // Calculates the week this date is in within that 373 // Calculates the week this date is in within that
374 // month. Equals the "row" is is in in the month view 374 // month. Equals the "row" is is in in the month view
375 int week = 1; 375 int week = 1;
376 QDate tmp( date.year(), date.month(), 1 ); 376 QDate tmp( date.year(), date.month(), 1 );
377 377
378 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 378 if ( date.dayOfWeek() < tmp.dayOfWeek() )
379 ++week; 379 ++week;
380 380
381 week += ( date.day() - 1 ) / 7; 381 week += ( date.day() - 1 ) / 7;
382 return week; 382 return week;
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Event::occurrence( const QDate& date ) 388int Event::occurrence( const QDate& date )
389{ 389{
390 // calculates the number of occurrances of this day of the 390 // calculates the number of occurrances of this day of the
391 // week till the given date (e.g 3rd Wednesday of the month) 391 // week till the given date (e.g 3rd Wednesday of the month)
392 return ( date.day() - 1 ) / 7 + 1; 392 return ( date.day() - 1 ) / 7 + 1;
393} 393}
394 394
395/*! 395/*!
396 \internal 396 \internal
397*/ 397*/
398int Event::dayOfWeek( char day ) 398int Event::dayOfWeek( char day )
399{ 399{
400 int dayOfWeek = 1; 400 int dayOfWeek = 1;
401 char i = Event::MON; 401 char i = Event::MON;
402 while ( !( i & day ) && i <= Event::SUN ) { 402 while ( !( i & day ) && i <= static_cast<char>(Event::SUN) ) {
403 i <<= 1; 403 i <<= 1;
404 ++dayOfWeek; 404 ++dayOfWeek;
405 } 405 }
406 return dayOfWeek; 406 return dayOfWeek;
407} 407}
408 408
409/*! 409/*!
410 \internal 410 \internal
411*/ 411*/
412int Event::monthDiff( const QDate& first, const QDate& second ) 412int Event::monthDiff( const QDate& first, const QDate& second )
413{ 413{
414 return ( second.year() - first.year() ) * 12 + 414 return ( second.year() - first.year() ) * 12 +
415 second.month() - first.month(); 415 second.month() - first.month();
416} 416}
417 417
418/*! 418/*!
419 \internal 419 \internal
420*/ 420*/
421QMap<int, QString> Event::toMap() const 421QMap<int, QString> Event::toMap() const
422{ 422{
423 QMap<int, QString> m; 423 QMap<int, QString> m;
424 424
425 if ( !description().isEmpty() ) 425 if ( !description().isEmpty() )
426 m.insert( DatebookDescription, description() ); 426 m.insert( DatebookDescription, description() );
427 if ( !location().isEmpty() ) 427 if ( !location().isEmpty() )
428 m.insert ( Location, location() ); 428 m.insert ( Location, location() );
429 if ( categories().count() ) 429 if ( categories().count() )
430 m.insert ( DatebookCategory, idsToString( categories() ) ); 430 m.insert ( DatebookCategory, idsToString( categories() ) );
431 if ( !timeZone().isEmpty() ) 431 if ( !timeZone().isEmpty() )
432 m.insert ( TimeZone, timeZone() ); 432 m.insert ( TimeZone, timeZone() );
433 if ( !notes().isEmpty() ) 433 if ( !notes().isEmpty() )
434 m.insert ( Note, notes() ); 434 m.insert ( Note, notes() );
435 435
436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) ); 436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) );
437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) ); 437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) );
438 m.insert ( DatebookType, QString::number( (int)type() ) ); 438 m.insert ( DatebookType, QString::number( (int)type() ) );
439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) ); 439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) );
440 m.insert ( SoundType, QString::number( (int)alarmSound() ) ); 440 m.insert ( SoundType, QString::number( (int)alarmSound() ) );
441 m.insert ( AlarmTime, QString::number( alarmTime() ) ); 441 m.insert ( AlarmTime, QString::number( alarmTime() ) );
442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) ); 442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) );
443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) ); 443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) );
444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) ); 444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) );
445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) ); 445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) );
446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) ); 446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) );
447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) ); 447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) );
448 448
449 m.insert( DatebookUid, QString::number( uid()) ); 449 m.insert( DatebookUid, QString::number( uid()) );
450 450
451 return m; 451 return m;
452} 452}
453 453
454/*! 454/*!
455 \internal 455 \internal
456*/ 456*/
457void Event::setRepeat( const RepeatPattern &p ) 457void Event::setRepeat( const RepeatPattern &p )
458{ 458{
459 setRepeat( p.type != NoRepeat, p ); 459 setRepeat( p.type != NoRepeat, p );
460} 460}
461 461
462/*! 462/*!
463 Sets the description of the event to \a s. 463 Sets the description of the event to \a s.
464*/ 464*/
465void Event::setDescription( const QString &s ) 465void Event::setDescription( const QString &s )
466{ 466{
467 descript = s; 467 descript = s;
468} 468}
469 469
470/*! 470/*!
471 Sets the location of the event to \a s. 471 Sets the location of the event to \a s.
472*/ 472*/
473void Event::setLocation( const QString &s ) 473void Event::setLocation( const QString &s )
474{ 474{
475 locat = s; 475 locat = s;
476} 476}
477 477
478// void Event::setCategory( const QString &s ) 478// void Event::setCategory( const QString &s )
479// { 479// {
480// categ = s; 480// categ = s;
481// } 481// }
482 482
483/*! 483/*!
484 \internal 484 \internal
485*/ 485*/
486void Event::setType( Type t ) 486void Event::setType( Type t )
487{ 487{
488 typ = t; 488 typ = t;
489} 489}
490 490
491/*! 491/*!
492 Sets the start date and time of the first or only occurance of this event 492 Sets the start date and time of the first or only occurance of this event
493 to the date and time \a d. \a d should be in local time. 493 to the date and time \a d. \a d should be in local time.
494*/ 494*/
495void Event::setStart( const QDateTime &d ) 495void Event::setStart( const QDateTime &d )
496{ 496{
497 startUTC = TimeConversion::toUTC( d ); 497 startUTC = TimeConversion::toUTC( d );
498} 498}
499 499
500/*! 500/*!
501 \internal 501 \internal
502*/ 502*/
503void Event::setStart( time_t time ) 503void Event::setStart( time_t time )
504{ 504{
505 startUTC = time; 505 startUTC = time;
506} 506}
507 507
508/*! 508/*!
509 Sets the end date and time of the first or only occurance of this event 509 Sets the end date and time of the first or only occurance of this event
510 to the date and time \a d. \a d should be in local time. 510 to the date and time \a d. \a d should be in local time.
511*/ 511*/
512void Event::setEnd( const QDateTime &d ) 512void Event::setEnd( const QDateTime &d )
513{ 513{
514 endUTC = TimeConversion::toUTC( d ); 514 endUTC = TimeConversion::toUTC( d );
515} 515}
516 516
517/*! 517/*!
518 \internal 518 \internal
519*/ 519*/
520void Event::setEnd( time_t time ) 520void Event::setEnd( time_t time )
521{ 521{
522 endUTC = time; 522 endUTC = time;
523} 523}
524 524
525/*! 525/*!
526 \internal 526 \internal
527*/ 527*/
528void Event::setTimeZone( const QString &z ) 528void Event::setTimeZone( const QString &z )
529{ 529{
530 tz = z; 530 tz = z;
531} 531}
532 532
533/*! 533/*!
534 \internal 534 \internal
535*/ 535*/
536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s ) 536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s )
537{ 537{
538 hAlarm = b; 538 hAlarm = b;
539 aMinutes = minutes; 539 aMinutes = minutes;
540 aSound = s; 540 aSound = s;
541} 541}
542 542
543/*! 543/*!
544 \internal 544 \internal
545*/ 545*/
546void Event::setRepeat( bool b, const RepeatPattern &p ) 546void Event::setRepeat( bool b, const RepeatPattern &p )
547{ 547{
548 hRepeat = b; 548 hRepeat = b;
549 pattern = p; 549 pattern = p;
550} 550}
551 551
552/*! 552/*!
553 Sets the notes for the event to \a n. 553 Sets the notes for the event to \a n.
554*/ 554*/
555void Event::setNotes( const QString &n ) 555void Event::setNotes( const QString &n )
556{ 556{
557 note = n; 557 note = n;
558} 558}
559 559
560/*! 560/*!
561 Returns the description of the event. 561 Returns the description of the event.
562*/ 562*/
563const QString &Event::description() const 563const QString &Event::description() const
564{ 564{
565 return descript; 565 return descript;
566} 566}
567 567
568/*! 568/*!
569 Returns the location of the event. 569 Returns the location of the event.
570*/ 570*/
571const QString &Event::location() const 571const QString &Event::location() const
572{ 572{
573 return locat; 573 return locat;
574} 574}
575 575
576// QString Event::category() const 576// QString Event::category() const
577// { 577// {
578// return categ; 578// return categ;
579// } 579// }
580 580
581/*! 581/*!
582 \internal 582 \internal
583*/ 583*/
584Event::Type Event::type() const 584Event::Type Event::type() const
585{ 585{
586 return typ; 586 return typ;
587} 587}
588/* 588/*
589QDateTime Event::start() const { 589QDateTime Event::start() const {
590 return start( TRUE ); 590 return start( TRUE );
591} 591}
592*/ 592*/
593/*! 593/*!
594 \internal 594 \internal
595*/ 595*/
596QDateTime Event::start( bool actual ) const 596QDateTime Event::start( bool actual ) const
597{ 597{
598 QDateTime dt = TimeConversion::fromUTC( startUTC ); 598 QDateTime dt = TimeConversion::fromUTC( startUTC );
599 599
600 if ( actual && typ == AllDay ) { 600 if ( actual && typ == AllDay ) {
601 QTime t = dt.time(); 601 QTime t = dt.time();
602 t.setHMS( 0, 0, 0 ); 602 t.setHMS( 0, 0, 0 );
603 dt.setTime( t ); 603 dt.setTime( t );
604 } 604 }
605 return dt; 605 return dt;
606} 606}
607/* 607/*
608QDateTime Event::end() const { 608QDateTime Event::end() const {
609 return end( TRUE ); 609 return end( TRUE );
610} 610}
611*/ 611*/
612/*! 612/*!
613 \internal 613 \internal
614*/ 614*/
615QDateTime Event::end( bool actual ) const 615QDateTime Event::end( bool actual ) const
616{ 616{
617 QDateTime dt = TimeConversion::fromUTC( endUTC ); 617 QDateTime dt = TimeConversion::fromUTC( endUTC );
618 if ( actual && typ == AllDay ) { 618 if ( actual && typ == AllDay ) {
619 dt.setTime( QTime(23,59,59) ); 619 dt.setTime( QTime(23,59,59) );
620 } 620 }
621 return dt; 621 return dt;
622} 622}
623 623
624/*! 624/*!
625 \internal 625 \internal
626*/ 626*/
627const QString &Event::timeZone() const 627const QString &Event::timeZone() const
628{ 628{
629 return tz; 629 return tz;
630} 630}
631 631
632/*! 632/*!
633 \internal 633 \internal
634*/ 634*/
635bool Event::hasAlarm() const 635bool Event::hasAlarm() const
636{ 636{
637 return hAlarm; 637 return hAlarm;
638} 638}
639 639
640/*! 640/*!
641 \internal 641 \internal
642*/ 642*/
643int Event::alarmTime() const 643int Event::alarmTime() const
644{ 644{
645 return aMinutes; 645 return aMinutes;
646} 646}
647 647
648/*! 648/*!
649 Returns the sound type for the alarm of this event. 649 Returns the sound type for the alarm of this event.
650*/ 650*/
651Event::SoundTypeChoice Event::alarmSound() const 651Event::SoundTypeChoice Event::alarmSound() const
652{ 652{
653 return aSound; 653 return aSound;
654} 654}
655 655
656/*! 656/*!
657 \internal 657 \internal
658*/ 658*/
659bool Event::hasRepeat() const 659bool Event::hasRepeat() const
660{ 660{
661 return doRepeat(); 661 return doRepeat();
662} 662}
663 663
664/*! 664/*!
665 \internal 665 \internal
666*/ 666*/
667const Event::RepeatPattern &Event::repeatPattern() const 667const Event::RepeatPattern &Event::repeatPattern() const
668{ 668{
669 return pattern; 669 return pattern;
670} 670}
671 671
672/*! 672/*!
673 \internal 673 \internal
674*/ 674*/
675Event::RepeatPattern &Event::repeatPattern() 675Event::RepeatPattern &Event::repeatPattern()
676{ 676{
677 return pattern; 677 return pattern;
678} 678}
679 679
680/*! 680/*!
681 Returns the notes for the event. 681 Returns the notes for the event.
682*/ 682*/
683const QString &Event::notes() const 683const QString &Event::notes() const
684{ 684{
685 return note; 685 return note;
686} 686}
687 687
688/*! 688/*!
689 \internal 689 \internal
690*/ 690*/
691bool Event::operator==( const Event &e ) const 691bool Event::operator==( const Event &e ) const
692{ 692{
693 if ( uid() && e.uid() == uid() ) 693 if ( uid() && e.uid() == uid() )
694 return TRUE; 694 return TRUE;
695 return ( e.descript == descript && 695 return ( e.descript == descript &&
696 e.locat == locat && 696 e.locat == locat &&
697 e.categ == categ && 697 e.categ == categ &&
698 e.typ == typ && 698 e.typ == typ &&
699 e.startUTC == startUTC && 699 e.startUTC == startUTC &&
700 e.endUTC == endUTC && 700 e.endUTC == endUTC &&
701 e.tz == tz && 701 e.tz == tz &&
702 e.hAlarm == hAlarm && 702 e.hAlarm == hAlarm &&
703 e.aMinutes == aMinutes && 703 e.aMinutes == aMinutes &&
704 e.aSound == aSound && 704 e.aSound == aSound &&
705 e.hRepeat == hRepeat && 705 e.hRepeat == hRepeat &&
706 e.pattern == pattern && 706 e.pattern == pattern &&
707 e.note == note ); 707 e.note == note );
708} 708}
709 709
710/*! 710/*!
711 \internal 711 \internal
712 Appends the contact information to \a buf. 712 Appends the contact information to \a buf.
713*/ 713*/
714void Event::save( QString& buf ) 714void Event::save( QString& buf )
715{ 715{
716 buf += " description=\"" + Qtopia::escapeString(descript) + "\""; 716 buf += " description=\"" + Qtopia::escapeString(descript) + "\"";
717 if ( !locat.isEmpty() ) 717 if ( !locat.isEmpty() )
718 buf += " location=\"" + Qtopia::escapeString(locat) + "\""; 718 buf += " location=\"" + Qtopia::escapeString(locat) + "\"";
719 // save the categoies differently.... 719 // save the categoies differently....
720 QString strCats = idsToString( categories() ); 720 QString strCats = idsToString( categories() );
721 buf += " categories=\"" + Qtopia::escapeString(strCats) + "\""; 721 buf += " categories=\"" + Qtopia::escapeString(strCats) + "\"";
722 buf += " uid=\"" + QString::number( uid() ) + "\""; 722 buf += " uid=\"" + QString::number( uid() ) + "\"";
723 if ( (Type)typ != Normal ) 723 if ( (Type)typ != Normal )
724 buf += " type=\"AllDay\""; 724 buf += " type=\"AllDay\"";
725 if ( hAlarm ) { 725 if ( hAlarm ) {
726 buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\""; 726 buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\"";
727 if ( aSound == Event::Loud ) 727 if ( aSound == Event::Loud )
728 buf += "loud"; 728 buf += "loud";
729 else 729 else
730 buf += "silent"; 730 buf += "silent";
731 buf += "\""; 731 buf += "\"";
732 } 732 }
733 if ( hRepeat ) 733 if ( hRepeat )
734 write( buf, pattern ); 734 write( buf, pattern );
735 735
736 buf += " start=\"" 736 buf += " start=\""
737 + QString::number( startUTC ) 737 + QString::number( startUTC )
738 + "\""; 738 + "\"";
739 739
740 buf += " end=\"" 740 buf += " end=\""
741 + QString::number( endUTC ) 741 + QString::number( endUTC )
742 + "\""; 742 + "\"";
743 743
744 if ( !note.isEmpty() ) 744 if ( !note.isEmpty() )
745 buf += " note=\"" + Qtopia::escapeString( note ) + "\""; 745 buf += " note=\"" + Qtopia::escapeString( note ) + "\"";
746 buf += customToXml(); 746 buf += customToXml();
747} 747}
748 748
749/*! 749/*!
750 \internal 750 \internal
751*/ 751*/
752bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const 752bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const
753{ 753{
754 // *sigh* 754 // *sigh*
755 return ( type == right.type 755 return ( type == right.type
756 && frequency == right.frequency 756 && frequency == right.frequency
757 && position == right.position 757 && position == right.position
758 && days == right.days 758 && days == right.days
759 && hasEndDate == right.hasEndDate 759 && hasEndDate == right.hasEndDate
760 && endDateUTC == right.endDateUTC 760 && endDateUTC == right.endDateUTC
761 && createTime == right.createTime ); 761 && createTime == right.createTime );
762} 762}
763 763
764/*! 764/*!
765 \class EffectiveEvent 765 \class EffectiveEvent
766 \brief The EffectiveEvent class the data for a single occurance of an event. 766 \brief The EffectiveEvent class the data for a single occurance of an event.
767 767
768 This class describes the event for a single occurance of it. For example if 768 This class describes the event for a single occurance of it. For example if
769 an Event occurs every week, the effective event might represent the third 769 an Event occurs every week, the effective event might represent the third
770 occurance of this Event. 770 occurance of this Event.
771 771
772 \ingroup qtopiaemb 772 \ingroup qtopiaemb
773 \ingroup qtopiadesktop 773 \ingroup qtopiadesktop
774 \warning This class will be phased out in Qtopia 3.x 774 \warning This class will be phased out in Qtopia 3.x
775*/ 775*/
776 776
777/*! 777/*!
778 \enum EffectiveEvent::Position 778 \enum EffectiveEvent::Position
779 \internal 779 \internal
780*/ 780*/
781 781
782/*! 782/*!
783 \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &) 783 \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &)
784 \internal 784 \internal
785*/ 785*/
786 786
787class EffectiveEventPrivate 787class EffectiveEventPrivate
788{ 788{
789public: 789public:
790 //currently the existence of the d pointer means multi-day repeating, 790 //currently the existence of the d pointer means multi-day repeating,
791 //msut be changed if we use the d pointer for anything else. 791 //msut be changed if we use the d pointer for anything else.
792 QDate startDate; 792 QDate startDate;
793 QDate endDate; 793 QDate endDate;
794}; 794};
795 795
796/*! 796/*!
797 \internal 797 \internal
798*/ 798*/
799EffectiveEvent::EffectiveEvent() 799EffectiveEvent::EffectiveEvent()
800{ 800{
801 mDate = QDate::currentDate(); 801 mDate = QDate::currentDate();
802 mStart = mEnd = QTime::currentTime(); 802 mStart = mEnd = QTime::currentTime();
803 d = 0; 803 d = 0;
804} 804}
805 805
806/*! 806/*!
807 \internal 807 \internal
808*/ 808*/
809EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos ) 809EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos )
810{ 810{
811 mEvent = e; 811 mEvent = e;
812 mDate = date; 812 mDate = date;
813 if ( pos & Start ) 813 if ( pos & Start )
814 mStart = e.start( TRUE ).time(); 814 mStart = e.start( TRUE ).time();
815 else 815 else
816 mStart = QTime( 0, 0, 0 ); 816 mStart = QTime( 0, 0, 0 );
817 817
818 if ( pos & End ) 818 if ( pos & End )
819 mEnd = e.end( TRUE ).time(); 819 mEnd = e.end( TRUE ).time();
820 else 820 else
821 mEnd = QTime( 23, 59, 59 ); 821 mEnd = QTime( 23, 59, 59 );
822 d = 0; 822 d = 0;
823} 823}
824 824
825/*! 825/*!
826 \internal 826 \internal
827*/ 827*/
828EffectiveEvent::~EffectiveEvent() 828EffectiveEvent::~EffectiveEvent()
829{ 829{
830 delete d; 830 delete d;
831} 831}
832 832
833/*! 833/*!
834 \internal 834 \internal
835*/ 835*/
836EffectiveEvent::EffectiveEvent( const EffectiveEvent &e ) 836EffectiveEvent::EffectiveEvent( const EffectiveEvent &e )
837{ 837{
838 d = 0; 838 d = 0;
839 *this = e; 839 *this = e;
840} 840}
841 841
842EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e ) 842EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e )
843{ 843{
844 if ( &e == this ) 844 if ( &e == this )
845 return *this; 845 return *this;
846 delete d; 846 delete d;
847 if ( e.d ) { 847 if ( e.d ) {
848 d = new EffectiveEventPrivate; 848 d = new EffectiveEventPrivate;
849 d->startDate = e.d->startDate; 849 d->startDate = e.d->startDate;
850 d->endDate = e.d->endDate; 850 d->endDate = e.d->endDate;
851 } else { 851 } else {
852 d = 0; 852 d = 0;
853 } 853 }
854 mEvent = e.mEvent; 854 mEvent = e.mEvent;
855 mDate = e.mDate; 855 mDate = e.mDate;
856 mStart = e.mStart; 856 mStart = e.mStart;
857 mEnd = e.mEnd; 857 mEnd = e.mEnd;
858 858
859 return *this; 859 return *this;
860 860
861} 861}
862 862
863// QString EffectiveEvent::category() const 863// QString EffectiveEvent::category() const
864// { 864// {
865// return mEvent.category(); 865// return mEvent.category();
866// } 866// }
867 867
868/*! 868/*!
869 Returns the description of the event for this effective event. 869 Returns the description of the event for this effective event.
870*/ 870*/
871const QString &EffectiveEvent::description( ) const 871const QString &EffectiveEvent::description( ) const
872{ 872{
873 return mEvent.description(); 873 return mEvent.description();
874} 874}
875 875
876/*! 876/*!
877\internal 877\internal
878*/ 878*/
879const QString &EffectiveEvent::location( ) const 879const QString &EffectiveEvent::location( ) const
880{ 880{
881 return mEvent.location(); 881 return mEvent.location();
882} 882}
883 883
884/*! 884/*!
885\internal 885\internal
886*/ 886*/
887const QString &EffectiveEvent::notes() const 887const QString &EffectiveEvent::notes() const
888{ 888{
889 return mEvent.notes(); 889 return mEvent.notes();
890} 890}
891 891
892/*! 892/*!
893 Returns the event associated with this effective event. 893 Returns the event associated with this effective event.
894*/ 894*/
895const Event &EffectiveEvent::event() const 895const Event &EffectiveEvent::event() const
896{ 896{
897 return mEvent; 897 return mEvent;
898} 898}
899 899
900/*! 900/*!
901 \internal 901 \internal
902*/ 902*/
903const QTime &EffectiveEvent::end() const 903const QTime &EffectiveEvent::end() const
904{ 904{
905 return mEnd; 905 return mEnd;
906} 906}
907 907
908/*! 908/*!
909 \internal 909 \internal
910*/ 910*/
911const QTime &EffectiveEvent::start() const 911const QTime &EffectiveEvent::start() const
912{ 912{
913 return mStart; 913 return mStart;
914} 914}
915 915
916/*! 916/*!
917 Returns the date the effective event occurs on. 917 Returns the date the effective event occurs on.
918*/ 918*/
919const QDate &EffectiveEvent::date() const 919const QDate &EffectiveEvent::date() const
920{ 920{
921 return mDate; 921 return mDate;
922} 922}
923 923
924/*! 924/*!
925 \internal 925 \internal
926*/ 926*/
927int EffectiveEvent::length() const 927int EffectiveEvent::length() const
928{ 928{
929 return (mEnd.hour() * 60 - mStart.hour() * 60) 929 return (mEnd.hour() * 60 - mStart.hour() * 60)
930 + QABS(mStart.minute() - mEnd.minute() ); 930 + QABS(mStart.minute() - mEnd.minute() );
931} 931}
932 932
933/*! 933/*!
934 \internal 934 \internal
935*/ 935*/
936void EffectiveEvent::setDate( const QDate &dt ) 936void EffectiveEvent::setDate( const QDate &dt )
937{ 937{
938 mDate = dt; 938 mDate = dt;
939} 939}
940 940
941/*! 941/*!
942 \internal 942 \internal
943*/ 943*/
944void EffectiveEvent::setStart( const QTime &start ) 944void EffectiveEvent::setStart( const QTime &start )
945{ 945{
946 mStart = start; 946 mStart = start;
947} 947}
948 948
949/*! 949/*!
950 \internal 950 \internal
951*/ 951*/
952void EffectiveEvent::setEnd( const QTime &end ) 952void EffectiveEvent::setEnd( const QTime &end )
953{ 953{
954 mEnd = end; 954 mEnd = end;
955} 955}
956 956
957/*! 957/*!
958 \internal 958 \internal
959*/ 959*/
960void EffectiveEvent::setEvent( Event e ) 960void EffectiveEvent::setEvent( Event e )
961{ 961{
962 mEvent = e; 962 mEvent = e;
963} 963}
964 964
965/*! 965/*!
966 \internal 966 \internal
967*/ 967*/
968bool EffectiveEvent::operator<( const EffectiveEvent &e ) const 968bool EffectiveEvent::operator<( const EffectiveEvent &e ) const
969{ 969{
970 if ( mDate < e.date() ) 970 if ( mDate < e.date() )
971 return TRUE; 971 return TRUE;
972 if ( mDate == e.date() ) 972 if ( mDate == e.date() )
973 return ( mStart < e.start() ); 973 return ( mStart < e.start() );
974 else 974 else
975 return FALSE; 975 return FALSE;
976} 976}
977 977
978/*! 978/*!
979 \internal 979 \internal
980*/ 980*/
981bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const 981bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const
982{ 982{
983 return (mDate <= e.date() ); 983 return (mDate <= e.date() );
984} 984}
985 985
986/*! 986/*!
987 \internal 987 \internal
988*/ 988*/
989bool EffectiveEvent::operator==( const EffectiveEvent &e ) const 989bool EffectiveEvent::operator==( const EffectiveEvent &e ) const
990{ 990{
991 return ( mDate == e.date() 991 return ( mDate == e.date()
992 && mStart == e.start() 992 && mStart == e.start()
993 && mEnd == e.end() 993 && mEnd == e.end()
994 && mEvent == e.event() ); 994 && mEvent == e.event() );
995} 995}
996 996
997/*! 997/*!
998 \internal 998 \internal
999*/ 999*/
1000bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const 1000bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const
1001{ 1001{
1002 return !(*this == e); 1002 return !(*this == e);
1003} 1003}
1004 1004
1005/*! 1005/*!
1006 \internal 1006 \internal
1007*/ 1007*/
1008bool EffectiveEvent::operator>( const EffectiveEvent &e ) const 1008bool EffectiveEvent::operator>( const EffectiveEvent &e ) const
1009{ 1009{
1010 return !(*this <= e ); 1010 return !(*this <= e );
1011} 1011}
1012 1012
1013/*! 1013/*!
1014 \internal 1014 \internal
1015*/ 1015*/
1016bool EffectiveEvent::operator>=(const EffectiveEvent &e) const 1016bool EffectiveEvent::operator>=(const EffectiveEvent &e) const
1017{ 1017{
1018 return !(*this < e); 1018 return !(*this < e);
1019} 1019}
1020 1020
1021/*! 1021/*!
1022 \internal 1022 \internal
1023*/ 1023*/
1024void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to ) 1024void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to )
1025{ 1025{
1026 if ( !from.isValid() ) { 1026 if ( !from.isValid() ) {
1027 delete d; 1027 delete d;
1028 d = 0; 1028 d = 0;
1029 return; 1029 return;
1030 } 1030 }
1031 if ( !d ) 1031 if ( !d )
1032 d = new EffectiveEventPrivate; 1032 d = new EffectiveEventPrivate;
1033 d->startDate = from; 1033 d->startDate = from;
1034 d->endDate = to; 1034 d->endDate = to;
1035} 1035}
1036 1036
1037/*! 1037/*!
1038 \internal 1038 \internal
1039*/ 1039*/
1040QDate EffectiveEvent::startDate() const 1040QDate EffectiveEvent::startDate() const
1041{ 1041{
1042 if ( d ) 1042 if ( d )
1043 return d->startDate; 1043 return d->startDate;
1044 else if ( mEvent.hasRepeat() ) 1044 else if ( mEvent.hasRepeat() )
1045 return mDate; // single day, since multi-day should have a d pointer 1045 return mDate; // single day, since multi-day should have a d pointer
1046 else 1046 else
1047 return mEvent.start().date(); 1047 return mEvent.start().date();
1048} 1048}
1049 1049
1050/*! 1050/*!
1051 \internal 1051 \internal
1052*/ 1052*/
1053QDate EffectiveEvent::endDate() const 1053QDate EffectiveEvent::endDate() const
1054{ 1054{
1055 if ( d ) 1055 if ( d )
1056 return d->endDate; 1056 return d->endDate;
1057 else if ( mEvent.hasRepeat() ) 1057 else if ( mEvent.hasRepeat() )
1058 return mDate; // single day, since multi-day should have a d pointer 1058 return mDate; // single day, since multi-day should have a d pointer
1059 else 1059 else
1060 return mEvent.end().date(); 1060 return mEvent.end().date();
1061} 1061}
1062 1062
1063/*! 1063/*!
1064 \internal 1064 \internal
1065*/ 1065*/
1066int EffectiveEvent::size() const 1066int EffectiveEvent::size() const
1067{ 1067{
1068 return ( mEnd.hour() - mStart.hour() ) * 3600 1068 return ( mEnd.hour() - mStart.hour() ) * 3600
1069 + (mEnd.minute() - mStart.minute() * 60 1069 + (mEnd.minute() - mStart.minute() * 60
1070 + mEnd.second() - mStart.second() ); 1070 + mEnd.second() - mStart.second() );
1071} 1071}
1072 1072
1073 1073
1074// vcal conversion code 1074// vcal conversion code
1075static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1075static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1076{ 1076{
1077 VObject *ret = 0; 1077 VObject *ret = 0;
1078 if ( o && !value.isEmpty() ) 1078 if ( o && !value.isEmpty() )
1079 ret = addPropValue( o, prop, value.latin1() ); 1079 ret = addPropValue( o, prop, value.latin1() );
1080 return ret; 1080 return ret;
1081} 1081}
1082 1082
1083static inline VObject *safeAddProp( VObject *o, const char *prop) 1083static inline VObject *safeAddProp( VObject *o, const char *prop)
1084{ 1084{
1085 VObject *ret = 0; 1085 VObject *ret = 0;
1086 if ( o ) 1086 if ( o )
1087 ret = addProp( o, prop ); 1087 ret = addProp( o, prop );
1088 return ret; 1088 return ret;
1089} 1089}
1090 1090
1091/* 1091/*
1092 * Until we support vCal/iCal right 1092 * Until we support vCal/iCal right
1093 * we will make DTSTART and other things 1093 * we will make DTSTART and other things
1094 * be floating in the sense of 1094 * be floating in the sense of
1095 * RFC 2445 1095 * RFC 2445
1096 */ 1096 */
1097namespace { 1097namespace {
1098/* 1098/*
1099 * Convert QDateTime to iso8601 but take 1099 * Convert QDateTime to iso8601 but take
1100 * local time and do not use the Z at the end 1100 * local time and do not use the Z at the end
1101 * 1101 *
1102 */ 1102 */
1103 QCString toISOLocal( const QDateTime& dt ) { 1103 QCString toISOLocal( const QDateTime& dt ) {
1104 QCString str; 1104 QCString str;
1105 /* 1105 /*
1106 * year month day T Hour Minute Second 1106 * year month day T Hour Minute Second
1107 * 4 2 2 2 2 2 digits 1107 * 4 2 2 2 2 2 digits
1108 */ 1108 */
1109 str.sprintf("%04d%02d%02dT%02d%02d%02d", 1109 str.sprintf("%04d%02d%02dT%02d%02d%02d",
1110 dt.date().year(), 1110 dt.date().year(),
1111 dt.date().month(), 1111 dt.date().month(),
1112 dt.date().day(), 1112 dt.date().day(),
1113 dt.time().hour(), 1113 dt.time().hour(),
1114 dt.time().minute(), 1114 dt.time().minute(),
1115 dt.time().second() ); 1115 dt.time().second() );
1116 1116
1117 qWarning("Str ist %s", str.data() ); 1117 qWarning("Str ist %s", str.data() );
1118 1118
1119 return str; 1119 return str;
1120 } 1120 }
1121 1121
1122 1122
1123}; 1123};
1124 1124
1125static VObject *createVObject( const Event &e ) 1125static VObject *createVObject( const Event &e )
1126{ 1126{
1127 VObject *vcal = newVObject( VCCalProp ); 1127 VObject *vcal = newVObject( VCCalProp );
1128 safeAddPropValue( vcal, VCVersionProp, "1.0" ); 1128 safeAddPropValue( vcal, VCVersionProp, "1.0" );
1129 VObject *event = safeAddProp( vcal, VCEventProp ); 1129 VObject *event = safeAddProp( vcal, VCEventProp );
1130 1130
1131 safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) ); 1131 safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) );
1132 safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) ); 1132 safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) );
1133 safeAddPropValue( event, "X-Qtopia-NOTES", e.description() ); 1133 safeAddPropValue( event, "X-Qtopia-NOTES", e.description() );
1134 safeAddPropValue( event, VCDescriptionProp, e.description() ); 1134 safeAddPropValue( event, VCDescriptionProp, e.description() );
1135 safeAddPropValue( event, VCLocationProp, e.location() ); 1135 safeAddPropValue( event, VCLocationProp, e.location() );
1136 1136
1137 if ( e.hasAlarm() ) { 1137 if ( e.hasAlarm() ) {
1138 VObject *alarm = safeAddProp( event, VCAAlarmProp ); 1138 VObject *alarm = safeAddProp( event, VCAAlarmProp );
1139 QDateTime dt = e.start(); 1139 QDateTime dt = e.start();
1140 dt = dt.addSecs( -e.alarmTime()*60 ); 1140 dt = dt.addSecs( -e.alarmTime()*60 );
1141 safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) ); 1141 safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) );
1142 safeAddPropValue( alarm, VCAudioContentProp, 1142 safeAddPropValue( alarm, VCAudioContentProp,
1143 (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) ); 1143 (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) );
1144 } 1144 }
1145 1145
1146 safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() ); 1146 safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() );
1147 1147
1148 if ( e.type() == Event::AllDay ) 1148 if ( e.type() == Event::AllDay )
1149 safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() ); 1149 safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() );
1150 1150
1151 // ### repeat missing 1151 // ### repeat missing
1152 1152
1153 // ### categories missing 1153 // ### categories missing
1154 1154
1155 return vcal; 1155 return vcal;
1156} 1156}
1157 1157
1158 1158
1159static Event parseVObject( VObject *obj ) 1159static Event parseVObject( VObject *obj )
1160{ 1160{
1161 Event e; 1161 Event e;
1162 1162
1163 bool haveAlarm = FALSE; 1163 bool haveAlarm = FALSE;
1164 bool haveStart = FALSE; 1164 bool haveStart = FALSE;
1165 bool haveEnd = FALSE; 1165 bool haveEnd = FALSE;
1166 QDateTime alarmTime; 1166 QDateTime alarmTime;
1167 Event::SoundTypeChoice soundType = Event::Silent; 1167 Event::SoundTypeChoice soundType = Event::Silent;
1168 1168
1169 VObjectIterator it; 1169 VObjectIterator it;
1170 initPropIterator( &it, obj ); 1170 initPropIterator( &it, obj );
1171 while( moreIteration( &it ) ) { 1171 while( moreIteration( &it ) ) {
1172 VObject *o = nextVObject( &it ); 1172 VObject *o = nextVObject( &it );
1173 QCString name = vObjectName( o ); 1173 QCString name = vObjectName( o );
1174 QCString value = vObjectStringZValue( o ); 1174 QCString value = vObjectStringZValue( o );
1175 if ( name == VCDTstartProp ) { 1175 if ( name == VCDTstartProp ) {
1176 e.setStart( TimeConversion::fromISO8601( value ) ); 1176 e.setStart( TimeConversion::fromISO8601( value ) );
1177 haveStart = TRUE; 1177 haveStart = TRUE;
1178 } 1178 }
1179 else if ( name == VCDTendProp ) { 1179 else if ( name == VCDTendProp ) {
1180 e.setEnd( TimeConversion::fromISO8601( value ) ); 1180 e.setEnd( TimeConversion::fromISO8601( value ) );
1181 haveEnd = TRUE; 1181 haveEnd = TRUE;
1182 } 1182 }
1183 else if ( name == "X-Qtopia-NOTES" ) { 1183 else if ( name == "X-Qtopia-NOTES" ) {
1184 e.setNotes( value ); 1184 e.setNotes( value );
1185 } 1185 }
1186 else if ( name == VCDescriptionProp ) { 1186 else if ( name == VCDescriptionProp ) {
1187 e.setDescription( value ); 1187 e.setDescription( value );
1188 } 1188 }
1189 else if ( name == VCLocationProp ) { 1189 else if ( name == VCLocationProp ) {
1190 e.setLocation( value ); 1190 e.setLocation( value );
1191 } 1191 }
1192 else if ( name == VCAudioContentProp ) { 1192 else if ( name == VCAudioContentProp ) {
1193 haveAlarm = TRUE; 1193 haveAlarm = TRUE;
1194 VObjectIterator nit; 1194 VObjectIterator nit;
1195 initPropIterator( &nit, o ); 1195 initPropIterator( &nit, o );
1196 while( moreIteration( &nit ) ) { 1196 while( moreIteration( &nit ) ) {
1197 VObject *o = nextVObject( &nit ); 1197 VObject *o = nextVObject( &nit );
1198 QCString name = vObjectName( o ); 1198 QCString name = vObjectName( o );
1199 QCString value = vObjectStringZValue( o ); 1199 QCString value = vObjectStringZValue( o );
1200 if ( name == VCRunTimeProp ) 1200 if ( name == VCRunTimeProp )
1201 alarmTime = TimeConversion::fromISO8601( value ); 1201 alarmTime = TimeConversion::fromISO8601( value );
1202 else if ( name == VCAudioContentProp ) { 1202 else if ( name == VCAudioContentProp ) {
1203 if ( value == "silent" ) 1203 if ( value == "silent" )
1204 soundType = Event::Silent; 1204 soundType = Event::Silent;
1205 else 1205 else
1206 soundType = Event::Loud; 1206 soundType = Event::Loud;
1207 } 1207 }
1208 } 1208 }
1209 } 1209 }
1210 else if ( name == "X-Qtopia-TIMEZONE") { 1210 else if ( name == "X-Qtopia-TIMEZONE") {
1211 e.setTimeZone( value ); 1211 e.setTimeZone( value );
1212 } 1212 }
1213 else if ( name == "X-Qtopia-AllDay" ) { 1213 else if ( name == "X-Qtopia-AllDay" ) {
1214 e.setType( Event::AllDay ); 1214 e.setType( Event::AllDay );
1215 } 1215 }
1216#if 0 1216#if 0
1217 else { 1217 else {
1218 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1218 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1219 VObjectIterator nit; 1219 VObjectIterator nit;
1220 initPropIterator( &nit, o ); 1220 initPropIterator( &nit, o );
1221 while( moreIteration( &nit ) ) { 1221 while( moreIteration( &nit ) ) {
1222 VObject *o = nextVObject( &nit ); 1222 VObject *o = nextVObject( &nit );
1223 QCString name = vObjectName( o ); 1223 QCString name = vObjectName( o );
1224 QString value = vObjectStringZValue( o ); 1224 QString value = vObjectStringZValue( o );
1225 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1225 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1226 } 1226 }
1227 } 1227 }
1228#endif 1228#endif
1229 } 1229 }
1230 1230
1231 if ( !haveStart && !haveEnd ) 1231 if ( !haveStart && !haveEnd )
1232 e.setStart( QDateTime::currentDateTime() ); 1232 e.setStart( QDateTime::currentDateTime() );
1233 1233
1234 if ( !haveEnd ) { 1234 if ( !haveEnd ) {
1235 e.setType( Event::AllDay ); 1235 e.setType( Event::AllDay );
1236 e.setEnd( e.start() ); 1236 e.setEnd( e.start() );
1237 } 1237 }
1238 1238
1239 if ( haveAlarm ) { 1239 if ( haveAlarm ) {
1240 int minutes = alarmTime.secsTo( e.start() ) / 60; 1240 int minutes = alarmTime.secsTo( e.start() ) / 60;
1241 e.setAlarm( TRUE, minutes, soundType ); 1241 e.setAlarm( TRUE, minutes, soundType );
1242 } 1242 }
1243 return e; 1243 return e;
1244} 1244}
1245 1245
1246 1246
1247/*! 1247/*!
1248 Writes the list of \a events as a set of VCards to the file \a filename. 1248 Writes the list of \a events as a set of VCards to the file \a filename.
1249*/ 1249*/
1250void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events) 1250void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events)
1251{ 1251{
1252 1252
1253 QFileDirect f( filename.utf8().data() ); 1253 QFileDirect f( filename.utf8().data() );
1254 1254
1255 if ( !f.open( IO_WriteOnly ) ) { 1255 if ( !f.open( IO_WriteOnly ) ) {
1256 1256
1257 qWarning("Unable to open vcard write"); 1257 qWarning("Unable to open vcard write");
1258 1258
1259 return; 1259 return;
1260 1260
1261 } 1261 }
1262 1262
1263 1263
1264 QValueList<Event>::ConstIterator it; 1264 QValueList<Event>::ConstIterator it;
1265 for( it = events.begin(); it != events.end(); ++it ) { 1265 for( it = events.begin(); it != events.end(); ++it ) {
1266 VObject *obj = createVObject( *it ); 1266 VObject *obj = createVObject( *it );
1267 writeVObject( f.directHandle() , obj ); 1267 writeVObject( f.directHandle() , obj );
1268 cleanVObject( obj ); 1268 cleanVObject( obj );
1269 } 1269 }
1270 1270
1271 1271
1272 cleanStrTbl(); 1272 cleanStrTbl();
1273} 1273}
1274 1274
1275/*! 1275/*!
1276 Writes \a event as a VCard to the file \a filename. 1276 Writes \a event as a VCard to the file \a filename.
1277*/ 1277*/
1278void Event::writeVCalendar( const QString &filename, const Event &event) 1278void Event::writeVCalendar( const QString &filename, const Event &event)
1279{ 1279{
1280 1280
1281 QFileDirect f( filename.utf8().data() ); 1281 QFileDirect f( filename.utf8().data() );
1282 1282
1283 if ( !f.open( IO_WriteOnly ) ) { 1283 if ( !f.open( IO_WriteOnly ) ) {
1284 1284
1285 qWarning("Unable to open vcard write"); 1285 qWarning("Unable to open vcard write");
1286 1286
1287 return; 1287 return;
1288 1288
1289 } 1289 }
1290 1290
1291 1291
1292 VObject *obj = createVObject( event ); 1292 VObject *obj = createVObject( event );
1293 writeVObject( f.directHandle() , obj ); 1293 writeVObject( f.directHandle() , obj );
1294 cleanVObject( obj ); 1294 cleanVObject( obj );
1295 1295
1296 cleanStrTbl(); 1296 cleanStrTbl();
1297} 1297}
1298 1298
1299/*! 1299/*!
1300 Returns the set of events read as VCards from the file \a filename. 1300 Returns the set of events read as VCards from the file \a filename.
1301*/ 1301*/
1302QValueList<Event> Event::readVCalendar( const QString &filename ) 1302QValueList<Event> Event::readVCalendar( const QString &filename )
1303{ 1303{
1304 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1304 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1305 1305
1306 QValueList<Event> events; 1306 QValueList<Event> events;
1307 1307
1308 while ( obj ) { 1308 while ( obj ) {
1309 QCString name = vObjectName( obj ); 1309 QCString name = vObjectName( obj );
1310 if ( name == VCCalProp ) { 1310 if ( name == VCCalProp ) {
1311 VObjectIterator nit; 1311 VObjectIterator nit;
1312 initPropIterator( &nit, obj ); 1312 initPropIterator( &nit, obj );
1313 while( moreIteration( &nit ) ) { 1313 while( moreIteration( &nit ) ) {
1314 VObject *o = nextVObject( &nit ); 1314 VObject *o = nextVObject( &nit );
1315 QCString name = vObjectName( o ); 1315 QCString name = vObjectName( o );
1316 if ( name == VCEventProp ) 1316 if ( name == VCEventProp )
1317 events.append( parseVObject( o ) ); 1317 events.append( parseVObject( o ) );
1318 } 1318 }
1319 } else if ( name == VCEventProp ) { 1319 } else if ( name == VCEventProp ) {
1320 // shouldn't happen, but just to be sure 1320 // shouldn't happen, but just to be sure
1321 events.append( parseVObject( obj ) ); 1321 events.append( parseVObject( obj ) );
1322 } 1322 }
1323 VObject *t = obj; 1323 VObject *t = obj;
1324 obj = nextVObjectInList(obj); 1324 obj = nextVObjectInList(obj);
1325 cleanVObject( t ); 1325 cleanVObject( t );
1326 } 1326 }
1327 1327
1328 return events; 1328 return events;
1329} 1329}
1330 1330
1331bool Event::match( const QRegExp &r ) const 1331bool Event::match( const QRegExp &r ) const
1332{ 1332{
1333 bool returnMe; 1333 bool returnMe;
1334 returnMe = false; 1334 returnMe = false;
1335 1335
1336 if ( descript.find( r ) > -1 ) 1336 if ( descript.find( r ) > -1 )
1337 returnMe = true; 1337 returnMe = true;
1338 else if ( locat.find( r ) > -1 ) 1338 else if ( locat.find( r ) > -1 )
1339 returnMe = true; 1339 returnMe = true;
1340 else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 ) 1340 else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 )
1341 returnMe = true; 1341 returnMe = true;
1342 else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 ) 1342 else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 )
1343 returnMe = true; 1343 returnMe = true;
1344 else if ( tz.find( r ) > -1 ) 1344 else if ( tz.find( r ) > -1 )
1345 returnMe = true; 1345 returnMe = true;
1346 else if ( note.find( r ) > -1 ) 1346 else if ( note.find( r ) > -1 )
1347 returnMe = true; 1347 returnMe = true;
1348 else if ( doRepeat() ) { 1348 else if ( doRepeat() ) {
1349 if ( pattern.hasEndDate ) 1349 if ( pattern.hasEndDate )
1350 if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 ) 1350 if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 )
1351 returnMe = true; 1351 returnMe = true;
1352 } 1352 }
1353 return returnMe; 1353 return returnMe;
1354} 1354}
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
index b2180ba..a47bf6c 100644
--- a/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
@@ -1,446 +1,452 @@
1#include <qmap.h> 1#include <qmap.h>
2 2
3#include "zkbnames.h" 3#include "zkbnames.h"
4 4
5QString Null_String((const char*) 0); 5QString Null_String((const char*) 0);
6 6
7// Implementation of KeyNames 7// Implementation of KeyNames
8static struct { 8struct Key_Names_t {
9 int key; 9 int key;
10 char *name; 10 char *name;
11} Key_Names[] = { 11};
12
13static const Key_Names_t Key_Names[] = {
12 { 32, "Space" }, 14 { 32, "Space" },
13 { 39, "Apostrophe" }, 15 { 39, "Apostrophe" },
14 { 44, "Comma" }, 16 { 44, "Comma" },
15 { 46, "Period" }, 17 { 46, "Period" },
16 { 47, "Slash" }, 18 { 47, "Slash" },
17 { 65, "A" }, 19 { 65, "A" },
18 { 66, "B" }, 20 { 66, "B" },
19 { 67, "C" }, 21 { 67, "C" },
20 { 68, "D" }, 22 { 68, "D" },
21 { 69, "E" }, 23 { 69, "E" },
22 { 70, "F" }, 24 { 70, "F" },
23 { 71, "G" }, 25 { 71, "G" },
24 { 72, "H" }, 26 { 72, "H" },
25 { 73, "I" }, 27 { 73, "I" },
26 { 74, "J" }, 28 { 74, "J" },
27 { 75, "K" }, 29 { 75, "K" },
28 { 76, "L" }, 30 { 76, "L" },
29 { 77, "M" }, 31 { 77, "M" },
30 { 78, "N" }, 32 { 78, "N" },
31 { 79, "O" }, 33 { 79, "O" },
32 { 80, "P" }, 34 { 80, "P" },
33 { 81, "Q" }, 35 { 81, "Q" },
34 { 82, "R" }, 36 { 82, "R" },
35 { 83, "S" }, 37 { 83, "S" },
36 { 84, "T" }, 38 { 84, "T" },
37 { 85, "U" }, 39 { 85, "U" },
38 { 86, "V" }, 40 { 86, "V" },
39 { 87, "W" }, 41 { 87, "W" },
40 { 88, "X" }, 42 { 88, "X" },
41 { 89, "Y" }, 43 { 89, "Y" },
42 { 90, "Z" }, 44 { 90, "Z" },
43 { 4096, "Cancel" }, 45 { 4096, "Cancel" },
44 { 4097, "Tab" }, 46 { 4097, "Tab" },
45 { 4099, "Backspace" }, 47 { 4099, "Backspace" },
46 { 4100, "Enter" }, 48 { 4100, "Enter" },
47 { 4114, "Left" }, 49 { 4114, "Left" },
48 { 4115, "Up" }, 50 { 4115, "Up" },
49 { 4116, "Right" }, 51 { 4116, "Right" },
50 { 4117, "Down" }, 52 { 4117, "Down" },
51 { 4128, "Left Shift" }, 53 { 4128, "Left Shift" },
52 { 4130, "Right Shift" }, 54 { 4130, "Right Shift" },
53 { 4152, "Calendar" }, 55 { 4152, "Calendar" },
54 { 4153, "Addressbook" }, 56 { 4153, "Addressbook" },
55 { 4154, "Menu" }, 57 { 4154, "Menu" },
56 { 4155, "Home" }, 58 { 4155, "Home" },
57 { 4156, "Mail" }, 59 { 4156, "Mail" },
58 { 4165, "Fn" }, 60 { 4165, "Fn" },
59 { 4173, "Middle" }, 61 { 4173, "Middle" },
60 { 4176, "OK" }, 62 { 4176, "OK" },
61 { 4177, "Off" }, 63 { 4177, "Off" },
62 { 4178, "Light" }, 64 { 4178, "Light" },
63 { 0, 0 } 65 { 0, 0 }
64}; 66};
65 67
66static QMap<QString, int> kn_map; 68static QMap<QString, int> kn_map;
67static QMap<int, QString> kn_rmap; 69static QMap<int, QString> kn_rmap;
68 70
69void init_kn_maps() { 71void init_kn_maps() {
70 int i = 0; 72 int i = 0;
71 while (Key_Names[i].name != 0) { 73 while (Key_Names[i].name != 0) {
72 int key = Key_Names[i].key; 74 int key = Key_Names[i].key;
73 QString name(Key_Names[i].name); 75 QString name(Key_Names[i].name);
74 76
75 kn_map.insert(name, key); 77 kn_map.insert(name, key);
76 kn_rmap.insert(key, name); 78 kn_rmap.insert(key, name);
77 i++; 79 i++;
78 } 80 }
79} 81}
80 82
81int KeyNames::find(const QString& key) { 83int KeyNames::find(const QString& key) {
82 if (kn_map.isEmpty()) { 84 if (kn_map.isEmpty()) {
83 init_kn_maps(); 85 init_kn_maps();
84 } 86 }
85 87
86 QMap<QString, int>::Iterator it = kn_map.find(key); 88 QMap<QString, int>::Iterator it = kn_map.find(key);
87 if (it == kn_map.end()) { 89 if (it == kn_map.end()) {
88 return -1; 90 return -1;
89 } else { 91 } else {
90 return it.data(); 92 return it.data();
91 } 93 }
92} 94}
93 95
94const QString& KeyNames::find(int k) { 96const QString& KeyNames::find(int k) {
95 if (kn_map.isEmpty()) { 97 if (kn_map.isEmpty()) {
96 init_kn_maps(); 98 init_kn_maps();
97 } 99 }
98 100
99 QMap<int, QString>::Iterator it = kn_rmap.find(k); 101 QMap<int, QString>::Iterator it = kn_rmap.find(k);
100 if (it == kn_rmap.end()) { 102 if (it == kn_rmap.end()) {
101 return Null_String; 103 return Null_String;
102 } else { 104 } else {
103 return it.data(); 105 return it.data();
104 } 106 }
105} 107}
106 108
107// Implementation of ModifierNames 109// Implementation of ModifierNames
108struct { 110struct Modifier_Names_t {
109 int value; 111 int value;
110 char* name; 112 char* name;
111} Modifier_Names[] = { 113};
114
115static const Modifier_Names_t Modifier_Names[] = {
112 { 8, "Shift" }, 116 { 8, "Shift" },
113 { 16, "Control" }, 117 { 16, "Control" },
114 { 32, "Alt" }, 118 { 32, "Alt" },
115 { 0x4000, "Keypad" }, 119 { 0x4000, "Keypad" },
116 { 0, 0 } 120 { 0, 0 }
117}; 121};
118 122
119static QMap<QString, int> mn_map; 123static QMap<QString, int> mn_map;
120static QMap<int, QString> mn_rmap; 124static QMap<int, QString> mn_rmap;
121 125
122void init_mn_maps() { 126void init_mn_maps() {
123 int i = 0; 127 int i = 0;
124 while (Modifier_Names[i].name != 0) { 128 while (Modifier_Names[i].name != 0) {
125 int value = Modifier_Names[i].value; 129 int value = Modifier_Names[i].value;
126 QString name(Modifier_Names[i].name); 130 QString name(Modifier_Names[i].name);
127 131
128 mn_map.insert(name, value); 132 mn_map.insert(name, value);
129 mn_rmap.insert(value, name); 133 mn_rmap.insert(value, name);
130 i++; 134 i++;
131 } 135 }
132} 136}
133 137
134int ModifierNames::find(const QString& key) { 138int ModifierNames::find(const QString& key) {
135 if (mn_map.isEmpty()) { 139 if (mn_map.isEmpty()) {
136 init_mn_maps(); 140 init_mn_maps();
137 } 141 }
138 142
139 QMap<QString, int>::Iterator it = mn_map.find(key); 143 QMap<QString, int>::Iterator it = mn_map.find(key);
140 if (it == mn_map.end()) { 144 if (it == mn_map.end()) {
141 return -1; 145 return -1;
142 } else { 146 } else {
143 return it.data(); 147 return it.data();
144 } 148 }
145} 149}
146 150
147const QString& ModifierNames::find(int k) { 151const QString& ModifierNames::find(int k) {
148 if (mn_map.isEmpty()) { 152 if (mn_map.isEmpty()) {
149 init_mn_maps(); 153 init_mn_maps();
150 } 154 }
151 155
152 QMap<int, QString>::Iterator it = mn_rmap.find(k); 156 QMap<int, QString>::Iterator it = mn_rmap.find(k);
153 if (it == mn_rmap.end()) { 157 if (it == mn_rmap.end()) {
154 return Null_String; 158 return Null_String;
155 } else { 159 } else {
156 return it.data(); 160 return it.data();
157 } 161 }
158} 162}
159 163
160// Implementation of KeycodeNames 164// Implementation of KeycodeNames
161 165
162struct { 166struct Keycode_Names_t {
163 char* name; 167 char* name;
164 int keycode; 168 int keycode;
165} Keycode_Names[] = { 169};
170
171static const Keycode_Names_t Keycode_Names[] = {
166 { "Escape", 0x1000 }, 172 { "Escape", 0x1000 },
167 { "Tab", 0x1001 }, 173 { "Tab", 0x1001 },
168 { "Backtab", 0x1002 }, 174 { "Backtab", 0x1002 },
169 { "Backspace", 0x1003 }, 175 { "Backspace", 0x1003 },
170 { "BackSpace", 0x1003 }, 176 { "BackSpace", 0x1003 },
171 { "Return", 0x1004 }, 177 { "Return", 0x1004 },
172 { "Enter", 0x1005 }, 178 { "Enter", 0x1005 },
173 { "Insert", 0x1006 }, 179 { "Insert", 0x1006 },
174 { "Delete", 0x1007 }, 180 { "Delete", 0x1007 },
175 { "Pause", 0x1008 }, 181 { "Pause", 0x1008 },
176 { "Print", 0x1009 }, 182 { "Print", 0x1009 },
177 { "SysReq", 0x100a }, 183 { "SysReq", 0x100a },
178 { "Home", 0x1010 }, 184 { "Home", 0x1010 },
179 { "End", 0x1011 }, 185 { "End", 0x1011 },
180 { "Left", 0x1012 }, 186 { "Left", 0x1012 },
181 { "Up", 0x1013 }, 187 { "Up", 0x1013 },
182 { "Right", 0x1014 }, 188 { "Right", 0x1014 },
183 { "Down", 0x1015 }, 189 { "Down", 0x1015 },
184 { "Prior", 0x1016 }, 190 { "Prior", 0x1016 },
185 { "PageUp", 0x1016 }, 191 { "PageUp", 0x1016 },
186 { "Next", 0x1017 }, 192 { "Next", 0x1017 },
187 { "PageDown", 0x1017 }, 193 { "PageDown", 0x1017 },
188 { "Shift", 0x1020 }, 194 { "Shift", 0x1020 },
189 { "Control", 0x1021 }, 195 { "Control", 0x1021 },
190 { "Meta", 0x1022 }, 196 { "Meta", 0x1022 },
191 { "Alt", 0x1023 }, 197 { "Alt", 0x1023 },
192 { "CapsLock", 0x1024 }, 198 { "CapsLock", 0x1024 },
193 { "NumLock", 0x1025 }, 199 { "NumLock", 0x1025 },
194 { "ScrollLock", 0x1026 }, 200 { "ScrollLock", 0x1026 },
195 { "F1", 0x1030 }, 201 { "F1", 0x1030 },
196 { "F2", 0x1031 }, 202 { "F2", 0x1031 },
197 { "F3", 0x1032 }, 203 { "F3", 0x1032 },
198 { "F4", 0x1033 }, 204 { "F4", 0x1033 },
199 { "F5", 0x1034 }, 205 { "F5", 0x1034 },
200 { "F6", 0x1035 }, 206 { "F6", 0x1035 },
201 { "F7", 0x1036 }, 207 { "F7", 0x1036 },
202 { "F8", 0x1037 }, 208 { "F8", 0x1037 },
203 { "F9", 0x1038 }, 209 { "F9", 0x1038 },
204 { "F10", 0x1039 }, 210 { "F10", 0x1039 },
205 { "F11", 0x103a }, 211 { "F11", 0x103a },
206 { "F12", 0x103b }, 212 { "F12", 0x103b },
207 { "F13", 0x103c }, 213 { "F13", 0x103c },
208 { "F14", 0x103d }, 214 { "F14", 0x103d },
209 { "F15", 0x103e }, 215 { "F15", 0x103e },
210 { "F16", 0x103f }, 216 { "F16", 0x103f },
211 { "F17", 0x1040 }, 217 { "F17", 0x1040 },
212 { "F18", 0x1041 }, 218 { "F18", 0x1041 },
213 { "F19", 0x1042 }, 219 { "F19", 0x1042 },
214 { "F20", 0x1043 }, 220 { "F20", 0x1043 },
215 { "F21", 0x1044 }, 221 { "F21", 0x1044 },
216 { "F22", 0x1045 }, 222 { "F22", 0x1045 },
217 { "F23", 0x1046 }, 223 { "F23", 0x1046 },
218 { "F24", 0x1047 }, 224 { "F24", 0x1047 },
219 { "F25", 0x1048 }, 225 { "F25", 0x1048 },
220 { "F26", 0x1049 }, 226 { "F26", 0x1049 },
221 { "F27", 0x104a }, 227 { "F27", 0x104a },
222 { "F28", 0x104b }, 228 { "F28", 0x104b },
223 { "F29", 0x104c }, 229 { "F29", 0x104c },
224 { "F30", 0x104d }, 230 { "F30", 0x104d },
225 { "F31", 0x104e }, 231 { "F31", 0x104e },
226 { "F32", 0x104f }, 232 { "F32", 0x104f },
227 { "F33", 0x1050 }, 233 { "F33", 0x1050 },
228 { "F34", 0x1051 }, 234 { "F34", 0x1051 },
229 { "F35", 0x1052 }, 235 { "F35", 0x1052 },
230 { "Super_L", 0x1053 }, 236 { "Super_L", 0x1053 },
231 { "Super_R", 0x1054 }, 237 { "Super_R", 0x1054 },
232 { "Menu", 0x1055 }, 238 { "Menu", 0x1055 },
233 { "Hyper_L", 0x1056 }, 239 { "Hyper_L", 0x1056 },
234 { "Hyper_R", 0x1057 }, 240 { "Hyper_R", 0x1057 },
235 { "Help", 0x1058 }, 241 { "Help", 0x1058 },
236 { "Space", 0x20 }, 242 { "Space", 0x20 },
237 { "Any", 0x20 }, 243 { "Any", 0x20 },
238 { "Exclam", 0x21 }, 244 { "Exclam", 0x21 },
239 { "QuoteDbl", 0x22 }, 245 { "QuoteDbl", 0x22 },
240 { "NumberSign", 0x23 }, 246 { "NumberSign", 0x23 },
241 { "Dollar", 0x24 }, 247 { "Dollar", 0x24 },
242 { "Percent", 0x25 }, 248 { "Percent", 0x25 },
243 { "Ampersand", 0x26 }, 249 { "Ampersand", 0x26 },
244 { "Apostrophe", 0x27 }, 250 { "Apostrophe", 0x27 },
245 { "ParenLeft", 0x28 }, 251 { "ParenLeft", 0x28 },
246 { "ParenRight", 0x29 }, 252 { "ParenRight", 0x29 },
247 { "Asterisk", 0x2a }, 253 { "Asterisk", 0x2a },
248 { "Plus", 0x2b }, 254 { "Plus", 0x2b },
249 { "Comma", 0x2c }, 255 { "Comma", 0x2c },
250 { "Minus", 0x2d }, 256 { "Minus", 0x2d },
251 { "Period", 0x2e }, 257 { "Period", 0x2e },
252 { "Slash", 0x2f }, 258 { "Slash", 0x2f },
253 { "0", 0x30 }, 259 { "0", 0x30 },
254 { "1", 0x31 }, 260 { "1", 0x31 },
255 { "2", 0x32 }, 261 { "2", 0x32 },
256 { "3", 0x33 }, 262 { "3", 0x33 },
257 { "4", 0x34 }, 263 { "4", 0x34 },
258 { "5", 0x35 }, 264 { "5", 0x35 },
259 { "6", 0x36 }, 265 { "6", 0x36 },
260 { "7", 0x37 }, 266 { "7", 0x37 },
261 { "8", 0x38 }, 267 { "8", 0x38 },
262 { "9", 0x39 }, 268 { "9", 0x39 },
263 { "Colon", 0x3a }, 269 { "Colon", 0x3a },
264 { "Semicolon", 0x3b }, 270 { "Semicolon", 0x3b },
265 { "Less", 0x3c }, 271 { "Less", 0x3c },
266 { "Equal", 0x3d }, 272 { "Equal", 0x3d },
267 { "Greater", 0x3e }, 273 { "Greater", 0x3e },
268 { "Question", 0x3f }, 274 { "Question", 0x3f },
269 { "At", 0x40 }, 275 { "At", 0x40 },
270 { "A", 0x41 }, 276 { "A", 0x41 },
271 { "B", 0x42 }, 277 { "B", 0x42 },
272 { "C", 0x43 }, 278 { "C", 0x43 },
273 { "D", 0x44 }, 279 { "D", 0x44 },
274 { "E", 0x45 }, 280 { "E", 0x45 },
275 { "F", 0x46 }, 281 { "F", 0x46 },
276 { "G", 0x47 }, 282 { "G", 0x47 },
277 { "H", 0x48 }, 283 { "H", 0x48 },
278 { "I", 0x49 }, 284 { "I", 0x49 },
279 { "J", 0x4a }, 285 { "J", 0x4a },
280 { "K", 0x4b }, 286 { "K", 0x4b },
281 { "L", 0x4c }, 287 { "L", 0x4c },
282 { "M", 0x4d }, 288 { "M", 0x4d },
283 { "N", 0x4e }, 289 { "N", 0x4e },
284 { "O", 0x4f }, 290 { "O", 0x4f },
285 { "P", 0x50 }, 291 { "P", 0x50 },
286 { "Q", 0x51 }, 292 { "Q", 0x51 },
287 { "R", 0x52 }, 293 { "R", 0x52 },
288 { "S", 0x53 }, 294 { "S", 0x53 },
289 { "T", 0x54 }, 295 { "T", 0x54 },
290 { "U", 0x55 }, 296 { "U", 0x55 },
291 { "V", 0x56 }, 297 { "V", 0x56 },
292 { "W", 0x57 }, 298 { "W", 0x57 },
293 { "X", 0x58 }, 299 { "X", 0x58 },
294 { "Y", 0x59 }, 300 { "Y", 0x59 },
295 { "Z", 0x5a }, 301 { "Z", 0x5a },
296 { "BracketLeft", 0x5b }, 302 { "BracketLeft", 0x5b },
297 { "Backslash", 0x5c }, 303 { "Backslash", 0x5c },
298 { "BracketRight", 0x5d }, 304 { "BracketRight", 0x5d },
299 { "AsciiCircum", 0x5e }, 305 { "AsciiCircum", 0x5e },
300 { "Underscore", 0x5f }, 306 { "Underscore", 0x5f },
301 { "QuoteLeft", 0x60 }, 307 { "QuoteLeft", 0x60 },
302 { "BraceLeft", 0x7b }, 308 { "BraceLeft", 0x7b },
303 { "Bar", 0x7c }, 309 { "Bar", 0x7c },
304 { "BraceRight", 0x7d }, 310 { "BraceRight", 0x7d },
305 { "AsciiTilde", 0x7e }, 311 { "AsciiTilde", 0x7e },
306 { "nobreakspace", 0x0a0 }, 312 { "nobreakspace", 0x0a0 },
307 { "exclamdown", 0x0a1 }, 313 { "exclamdown", 0x0a1 },
308 { "cent", 0x0a2 }, 314 { "cent", 0x0a2 },
309 { "sterling", 0x0a3 }, 315 { "sterling", 0x0a3 },
310 { "currency", 0x0a4 }, 316 { "currency", 0x0a4 },
311 { "yen", 0x0a5 }, 317 { "yen", 0x0a5 },
312 { "brokenbar", 0x0a6 }, 318 { "brokenbar", 0x0a6 },
313 { "section", 0x0a7 }, 319 { "section", 0x0a7 },
314 { "diaeresis", 0x0a8 }, 320 { "diaeresis", 0x0a8 },
315 { "copyright", 0x0a9 }, 321 { "copyright", 0x0a9 },
316 { "ordfeminine", 0x0aa }, 322 { "ordfeminine", 0x0aa },
317 { "guillemotleft", 0x0ab }, 323 { "guillemotleft", 0x0ab },
318 { "notsign", 0x0ac }, 324 { "notsign", 0x0ac },
319 { "hyphen", 0x0ad }, 325 { "hyphen", 0x0ad },
320 { "registered", 0x0ae }, 326 { "registered", 0x0ae },
321 { "macron", 0x0af }, 327 { "macron", 0x0af },
322 { "degree", 0x0b0 }, 328 { "degree", 0x0b0 },
323 { "plusminus", 0x0b1 }, 329 { "plusminus", 0x0b1 },
324 { "twosuperior", 0x0b2 }, 330 { "twosuperior", 0x0b2 },
325 { "threesuperior", 0x0b3 }, 331 { "threesuperior", 0x0b3 },
326 { "acute", 0x0b4 }, 332 { "acute", 0x0b4 },
327 { "mu", 0x0b5 }, 333 { "mu", 0x0b5 },
328 { "paragraph", 0x0b6 }, 334 { "paragraph", 0x0b6 },
329 { "periodcentered", 0x0b7 }, 335 { "periodcentered", 0x0b7 },
330 { "cedilla", 0x0b8 }, 336 { "cedilla", 0x0b8 },
331 { "onesuperior", 0x0b9 }, 337 { "onesuperior", 0x0b9 },
332 { "masculine", 0x0ba }, 338 { "masculine", 0x0ba },
333 { "guillemotright", 0x0bb }, 339 { "guillemotright", 0x0bb },
334 { "onequarter", 0x0bc }, 340 { "onequarter", 0x0bc },
335 { "onehalf", 0x0bd }, 341 { "onehalf", 0x0bd },
336 { "threequarters", 0x0be }, 342 { "threequarters", 0x0be },
337 { "questiondown", 0x0bf }, 343 { "questiondown", 0x0bf },
338 { "Agrave", 0x0c0 }, 344 { "Agrave", 0x0c0 },
339 { "Aacute", 0x0c1 }, 345 { "Aacute", 0x0c1 },
340 { "Acircumflex", 0x0c2 }, 346 { "Acircumflex", 0x0c2 },
341 { "Atilde", 0x0c3 }, 347 { "Atilde", 0x0c3 },
342 { "Adiaeresis", 0x0c4 }, 348 { "Adiaeresis", 0x0c4 },
343 { "Aring", 0x0c5 }, 349 { "Aring", 0x0c5 },
344 { "AE", 0x0c6 }, 350 { "AE", 0x0c6 },
345 { "Ccedilla", 0x0c7 }, 351 { "Ccedilla", 0x0c7 },
346 { "Egrave", 0x0c8 }, 352 { "Egrave", 0x0c8 },
347 { "Eacute", 0x0c9 }, 353 { "Eacute", 0x0c9 },
348 { "Ecircumflex", 0x0ca }, 354 { "Ecircumflex", 0x0ca },
349 { "Ediaeresis", 0x0cb }, 355 { "Ediaeresis", 0x0cb },
350 { "Igrave", 0x0cc }, 356 { "Igrave", 0x0cc },
351 { "Iacute", 0x0cd }, 357 { "Iacute", 0x0cd },
352 { "Icircumflex", 0x0ce }, 358 { "Icircumflex", 0x0ce },
353 { "Idiaeresis", 0x0cf }, 359 { "Idiaeresis", 0x0cf },
354 { "ETH", 0x0d0 }, 360 { "ETH", 0x0d0 },
355 { "Ntilde", 0x0d1 }, 361 { "Ntilde", 0x0d1 },
356 { "Ograve", 0x0d2 }, 362 { "Ograve", 0x0d2 },
357 { "Oacute", 0x0d3 }, 363 { "Oacute", 0x0d3 },
358 { "Ocircumflex", 0x0d4 }, 364 { "Ocircumflex", 0x0d4 },
359 { "Otilde", 0x0d5 }, 365 { "Otilde", 0x0d5 },
360 { "Odiaeresis", 0x0d6 }, 366 { "Odiaeresis", 0x0d6 },
361 { "multiply", 0x0d7 }, 367 { "multiply", 0x0d7 },
362 { "Ooblique", 0x0d8 }, 368 { "Ooblique", 0x0d8 },
363 { "Ugrave", 0x0d9 }, 369 { "Ugrave", 0x0d9 },
364 { "Uacute", 0x0da }, 370 { "Uacute", 0x0da },
365 { "Ucircumflex", 0x0db }, 371 { "Ucircumflex", 0x0db },
366 { "Udiaeresis", 0x0dc }, 372 { "Udiaeresis", 0x0dc },
367 { "Yacute", 0x0dd }, 373 { "Yacute", 0x0dd },
368 { "THORN", 0x0de }, 374 { "THORN", 0x0de },
369 { "ssharp", 0x0df }, 375 { "ssharp", 0x0df },
370 { "agrave", 0x0e0 }, 376 { "agrave", 0x0e0 },
371 { "aacute", 0x0e1 }, 377 { "aacute", 0x0e1 },
372 { "acircumflex", 0x0e2 }, 378 { "acircumflex", 0x0e2 },
373 { "atilde", 0x0e3 }, 379 { "atilde", 0x0e3 },
374 { "adiaeresis", 0x0e4 }, 380 { "adiaeresis", 0x0e4 },
375 { "aring", 0x0e5 }, 381 { "aring", 0x0e5 },
376 { "ae", 0x0e6 }, 382 { "ae", 0x0e6 },
377 { "ccedilla", 0x0e7 }, 383 { "ccedilla", 0x0e7 },
378 { "egrave", 0x0e8 }, 384 { "egrave", 0x0e8 },
379 { "eacute", 0x0e9 }, 385 { "eacute", 0x0e9 },
380 { "ecircumflex", 0x0ea }, 386 { "ecircumflex", 0x0ea },
381 { "ediaeresis", 0x0eb }, 387 { "ediaeresis", 0x0eb },
382 { "igrave", 0x0ec }, 388 { "igrave", 0x0ec },
383 { "iacute", 0x0ed }, 389 { "iacute", 0x0ed },
384 { "icircumflex", 0x0ee }, 390 { "icircumflex", 0x0ee },
385 { "idiaeresis", 0x0ef }, 391 { "idiaeresis", 0x0ef },
386 { "eth", 0x0f0 }, 392 { "eth", 0x0f0 },
387 { "ntilde", 0x0f1 }, 393 { "ntilde", 0x0f1 },
388 { "ograve", 0x0f2 }, 394 { "ograve", 0x0f2 },
389 { "oacute", 0x0f3 }, 395 { "oacute", 0x0f3 },
390 { "ocircumflex", 0x0f4 }, 396 { "ocircumflex", 0x0f4 },
391 { "otilde", 0x0f5 }, 397 { "otilde", 0x0f5 },
392 { "odiaeresis", 0x0f6 }, 398 { "odiaeresis", 0x0f6 },
393 { "division", 0x0f7 }, 399 { "division", 0x0f7 },
394 { "oslash", 0x0f8 }, 400 { "oslash", 0x0f8 },
395 { "ugrave", 0x0f9 }, 401 { "ugrave", 0x0f9 },
396 { "uacute", 0x0fa }, 402 { "uacute", 0x0fa },
397 { "ucircumflex", 0x0fb }, 403 { "ucircumflex", 0x0fb },
398 { "udiaeresis", 0x0fc }, 404 { "udiaeresis", 0x0fc },
399 { "yacute", 0x0fd }, 405 { "yacute", 0x0fd },
400 { "thorn", 0x0fe }, 406 { "thorn", 0x0fe },
401 { "ydiaeresis", 0x0ff }, 407 { "ydiaeresis", 0x0ff },
402 { "unknown", 0xffff }, 408 { "unknown", 0xffff },
403 { 0, 0} 409 { 0, 0}
404}; 410};
405 411
406static QMap<QString, int> kcn_map; 412static QMap<QString, int> kcn_map;
407static QMap<int, QString> kcn_rmap; 413static QMap<int, QString> kcn_rmap;
408 414
409void init_kcn_maps() { 415void init_kcn_maps() {
410 int i = 0; 416 int i = 0;
411 while (Keycode_Names[i].name != 0) { 417 while (Keycode_Names[i].name != 0) {
412 int keycode = Keycode_Names[i].keycode; 418 int keycode = Keycode_Names[i].keycode;
413 QString name(Keycode_Names[i].name); 419 QString name(Keycode_Names[i].name);
414 420
415 kcn_map.insert(name, keycode); 421 kcn_map.insert(name, keycode);
416 kcn_rmap.insert(keycode, name); 422 kcn_rmap.insert(keycode, name);
417 i++; 423 i++;
418 } 424 }
419} 425}
420 426
421int KeycodeNames::find(const QString& key) { 427int KeycodeNames::find(const QString& key) {
422 if (kcn_map.isEmpty()) { 428 if (kcn_map.isEmpty()) {
423 init_kcn_maps(); 429 init_kcn_maps();
424 } 430 }
425 431
426 QMap<QString, int>::Iterator it = kcn_map.find(key); 432 QMap<QString, int>::Iterator it = kcn_map.find(key);
427 if (it == kcn_map.end()) { 433 if (it == kcn_map.end()) {
428 return -1; 434 return -1;
429 } else { 435 } else {
430 return it.data(); 436 return it.data();
431 } 437 }
432} 438}
433 439
434const QString& KeycodeNames::find(int k) { 440const QString& KeycodeNames::find(int k) {
435 if (kcn_map.isEmpty()) { 441 if (kcn_map.isEmpty()) {
436 init_kcn_maps(); 442 init_kcn_maps();
437 } 443 }
438 444
439 QMap<int, QString>::Iterator it = kcn_rmap.find(k); 445 QMap<int, QString>::Iterator it = kcn_rmap.find(k);
440 if (it == kcn_rmap.end()) { 446 if (it == kcn_rmap.end()) {
441 return Null_String; 447 return Null_String;
442 } else { 448 } else {
443 return it.data(); 449 return it.data();
444 } 450 }
445} 451}
446 452
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp
index 352c63b..3a4d410 100644
--- a/noncore/games/qasteroids/view.cpp
+++ b/noncore/games/qasteroids/view.cpp
@@ -1,881 +1,882 @@
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 * KAsteroids - Copyright (c) Martin R. Jones 1997 20 * KAsteroids - Copyright (c) Martin R. Jones 1997
21 * 21 *
22 * Part of the KDE project 22 * Part of the KDE project
23 */ 23 */
24 24
25#include "view.h" 25#include "view.h"
26 26
27#include <qpe/resource.h> 27#include <qpe/resource.h>
28 28
29 29
30#include <stdlib.h> 30#include <stdlib.h>
31#include <math.h> 31#include <math.h>
32 32
33#define IMG_BACKGROUND "qasteroids/bg.png" 33#define IMG_BACKGROUND "qasteroids/bg.png"
34 34
35#define REFRESH_DELAY 33 35#define REFRESH_DELAY 33
36#define SHIP_SPEED 0.3 36#define SHIP_SPEED 0.3
37#define MISSILE_SPEED 10.0 37#define MISSILE_SPEED 10.0
38#define SHIP_STEPS 64 38#define SHIP_STEPS 64
39#define ROTATE_RATE 2 39#define ROTATE_RATE 2
40#define SHIELD_ON_COST 1 40#define SHIELD_ON_COST 1
41#define SHIELD_HIT_COST 30 41#define SHIELD_HIT_COST 30
42#define BRAKE_ON_COST 4 42#define BRAKE_ON_COST 4
43 43
44#define MAX_ROCK_SPEED 2.5 44#define MAX_ROCK_SPEED 2.5
45#define MAX_POWERUP_SPEED 1.5 45#define MAX_POWERUP_SPEED 1.5
46 #define MAX_SHIP_SPEED 8 46 #define MAX_SHIP_SPEED 8
47#define MAX_BRAKES 5 47#define MAX_BRAKES 5
48#define MAX_SHIELDS 5 48#define MAX_SHIELDS 5
49 #define MAX_FIREPOWER 5 49 #define MAX_FIREPOWER 5
50 50
51#define TEXT_SPEED 4 51#define TEXT_SPEED 4
52 52
53#define PI_X_2 6.283185307 53#define PI_X_2 6.283185307
54#ifndef M_PI 54#ifndef M_PI
55#define M_PI 3.141592654 55#define M_PI 3.141592654
56#endif 56#endif
57 57
58struct 58struct kas_animations_t
59{ 59{
60 int id; 60 int id;
61 const char *path; 61 const char *path;
62 int frames; 62 int frames;
63} 63};
64kas_animations [] = 64
65static const kas_animations_t kas_animations [] =
65{ 66{
66// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 }, 67// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 },
67 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 }, 68 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 },
68 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 }, 69 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 },
69 { ID_SHIP, "ship/ship\%1.png", 32 }, 70 { ID_SHIP, "ship/ship\%1.png", 32 },
70 { ID_MISSILE, "missile/missile.png", 0 }, 71 { ID_MISSILE, "missile/missile.png", 0 },
71 { ID_BIT, "bits/bits\%1.png", 16 }, 72 { ID_BIT, "bits/bits\%1.png", 16 },
72 { ID_EXHAUST, "exhaust/exhaust.png", 0 }, 73 { ID_EXHAUST, "exhaust/exhaust.png", 0 },
73 { ID_ENERGY_POWERUP, "powerups/energy.png", 0 }, 74 { ID_ENERGY_POWERUP, "powerups/energy.png", 0 },
74// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, 75// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
75 { ID_BRAKE_POWERUP, "powerups/brake.png", 0 }, 76 { ID_BRAKE_POWERUP, "powerups/brake.png", 0 },
76 { ID_SHIELD_POWERUP, "powerups/shield.png", 0 }, 77 { ID_SHIELD_POWERUP, "powerups/shield.png", 0 },
77 { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 }, 78 { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 },
78 { ID_SHIELD, "shield/shield\%1.png", 6 }, 79 { ID_SHIELD, "shield/shield\%1.png", 6 },
79 { 0, 0, 0 } 80 { 0, 0, 0 }
80}; 81};
81 82
82 83
83 84
84KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) 85KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
85 : QWidget( parent, name ), 86 : QWidget( parent, name ),
86 field(200, 200), 87 field(200, 200),
87 view(&field,this) 88 view(&field,this)
88{ 89{
89 view.setVScrollBarMode( QScrollView::AlwaysOff ); 90 view.setVScrollBarMode( QScrollView::AlwaysOff );
90 view.setHScrollBarMode( QScrollView::AlwaysOff ); 91 view.setHScrollBarMode( QScrollView::AlwaysOff );
91 rocks.setAutoDelete( TRUE ); 92 rocks.setAutoDelete( TRUE );
92 missiles.setAutoDelete( TRUE ); 93 missiles.setAutoDelete( TRUE );
93 bits.setAutoDelete( TRUE ); 94 bits.setAutoDelete( TRUE );
94 powerups.setAutoDelete( TRUE ); 95 powerups.setAutoDelete( TRUE );
95 exhaust.setAutoDelete( TRUE ); 96 exhaust.setAutoDelete( TRUE );
96 97
97 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) ); 98 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) );
98 field.setBackgroundPixmap( pm ); 99 field.setBackgroundPixmap( pm );
99 100
100 textSprite = new QCanvasText( &field ); 101 textSprite = new QCanvasText( &field );
101 QFont font( "helvetica", 14 ); 102 QFont font( "helvetica", 14 );
102 textSprite->setFont( font ); 103 textSprite->setFont( font );
103 104
104 shield = 0; 105 shield = 0;
105 shieldOn = FALSE; 106 shieldOn = FALSE;
106 refreshRate = REFRESH_DELAY; 107 refreshRate = REFRESH_DELAY;
107 108
108 readSprites(); 109 readSprites();
109 110
110 shieldTimer = new QTimer( this ); 111 shieldTimer = new QTimer( this );
111 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); 112 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
112 mTimerId = -1; 113 mTimerId = -1;
113 114
114 shipPower = MAX_POWER_LEVEL; 115 shipPower = MAX_POWER_LEVEL;
115 vitalsChanged = TRUE; 116 vitalsChanged = TRUE;
116 can_destroy_powerups = FALSE; 117 can_destroy_powerups = FALSE;
117 118
118 mPaused = TRUE; 119 mPaused = TRUE;
119} 120}
120 121
121// - - - 122// - - -
122 123
123KAsteroidsView::~KAsteroidsView() 124KAsteroidsView::~KAsteroidsView()
124{ 125{
125} 126}
126 127
127// - - - 128// - - -
128 129
129void KAsteroidsView::reset() 130void KAsteroidsView::reset()
130{ 131{
131 rocks.clear(); 132 rocks.clear();
132 missiles.clear(); 133 missiles.clear();
133 bits.clear(); 134 bits.clear();
134 powerups.clear(); 135 powerups.clear();
135 exhaust.clear(); 136 exhaust.clear();
136 137
137 shotsFired = 0; 138 shotsFired = 0;
138 shotsHit = 0; 139 shotsHit = 0;
139 140
140 rockSpeed = 1.0; 141 rockSpeed = 1.0;
141 powerupSpeed = 1.0; 142 powerupSpeed = 1.0;
142 mFrameNum = 0; 143 mFrameNum = 0;
143 mPaused = FALSE; 144 mPaused = FALSE;
144 145
145 ship->hide(); 146 ship->hide();
146 shield->hide(); 147 shield->hide();
147/* 148/*
148 if ( mTimerId >= 0 ) { 149 if ( mTimerId >= 0 ) {
149 killTimer( mTimerId ); 150 killTimer( mTimerId );
150 mTimerId = -1; 151 mTimerId = -1;
151 } 152 }
152*/ 153*/
153} 154}
154 155
155// - -- 156// - --
156 157
157void KAsteroidsView::newGame() 158void KAsteroidsView::newGame()
158{ 159{
159 if ( shieldOn ) 160 if ( shieldOn )
160 { 161 {
161 shield->hide(); 162 shield->hide();
162 shieldOn = FALSE; 163 shieldOn = FALSE;
163 } 164 }
164 reset(); 165 reset();
165 if ( mTimerId < 0 ) 166 if ( mTimerId < 0 )
166 mTimerId = startTimer( REFRESH_DELAY ); 167 mTimerId = startTimer( REFRESH_DELAY );
167 emit updateVitals(); 168 emit updateVitals();
168} 169}
169 170
170// - - - 171// - - -
171 172
172void KAsteroidsView::endGame() 173void KAsteroidsView::endGame()
173{ 174{
174} 175}
175 176
176void KAsteroidsView::pause( bool p ) 177void KAsteroidsView::pause( bool p )
177{ 178{
178 if ( !mPaused && p ) { 179 if ( !mPaused && p ) {
179 if ( mTimerId >= 0 ) { 180 if ( mTimerId >= 0 ) {
180 killTimer( mTimerId ); 181 killTimer( mTimerId );
181 mTimerId = -1; 182 mTimerId = -1;
182 } 183 }
183 } else if ( mPaused && !p ) 184 } else if ( mPaused && !p )
184 mTimerId = startTimer( REFRESH_DELAY ); 185 mTimerId = startTimer( REFRESH_DELAY );
185 mPaused = p; 186 mPaused = p;
186} 187}
187 188
188// - - - 189// - - -
189 190
190void KAsteroidsView::newShip() 191void KAsteroidsView::newShip()
191{ 192{
192 ship->move( field.width()/2, field.height()/2, 0 ); 193 ship->move( field.width()/2, field.height()/2, 0 );
193 shield->move( field.width()/2, field.height()/2, 0 ); 194 shield->move( field.width()/2, field.height()/2, 0 );
194 ship->setVelocity( 0.0, 0.0 ); 195 ship->setVelocity( 0.0, 0.0 );
195 shipDx = 0; 196 shipDx = 0;
196 shipDy = 0; 197 shipDy = 0;
197 shipAngle = 0; 198 shipAngle = 0;
198 rotateL = FALSE; 199 rotateL = FALSE;
199 rotateR = FALSE; 200 rotateR = FALSE;
200 thrustShip = FALSE; 201 thrustShip = FALSE;
201 shootShip = FALSE; 202 shootShip = FALSE;
202 brakeShip = FALSE; 203 brakeShip = FALSE;
203 teleportShip = FALSE; 204 teleportShip = FALSE;
204 shieldOn = TRUE; 205 shieldOn = TRUE;
205 shootDelay = 0; 206 shootDelay = 0;
206 shipPower = MAX_POWER_LEVEL; 207 shipPower = MAX_POWER_LEVEL;
207 rotateRate = ROTATE_RATE; 208 rotateRate = ROTATE_RATE;
208 rotateSlow = 0; 209 rotateSlow = 0;
209 210
210 mBrakeCount = 0; 211 mBrakeCount = 0;
211 mTeleportCount = 0; 212 mTeleportCount = 0;
212 mShootCount = 0; 213 mShootCount = 0;
213 214
214 ship->show(); 215 ship->show();
215 shield->show(); 216 shield->show();
216 mShieldCount = 1; // just in case the ship appears on a rock. 217 mShieldCount = 1; // just in case the ship appears on a rock.
217 shieldTimer->start( 1000, TRUE ); 218 shieldTimer->start( 1000, TRUE );
218} 219}
219 220
220void KAsteroidsView::setShield( bool s ) 221void KAsteroidsView::setShield( bool s )
221{ 222{
222 if ( shieldTimer->isActive() && !s ) { 223 if ( shieldTimer->isActive() && !s ) {
223 shieldTimer->stop(); 224 shieldTimer->stop();
224 hideShield(); 225 hideShield();
225 } else { 226 } else {
226 shieldOn = s && mShieldCount; 227 shieldOn = s && mShieldCount;
227 } 228 }
228} 229}
229 230
230void KAsteroidsView::brake( bool b ) 231void KAsteroidsView::brake( bool b )
231{ 232{
232 if ( mBrakeCount ) 233 if ( mBrakeCount )
233 { 234 {
234 if ( brakeShip && !b ) 235 if ( brakeShip && !b )
235 { 236 {
236 rotateL = FALSE; 237 rotateL = FALSE;
237 rotateR = FALSE; 238 rotateR = FALSE;
238 thrustShip = FALSE; 239 thrustShip = FALSE;
239 rotateRate = ROTATE_RATE; 240 rotateRate = ROTATE_RATE;
240 } 241 }
241 242
242 brakeShip = b; 243 brakeShip = b;
243 } 244 }
244} 245}
245 246
246// - - - 247// - - -
247 248
248void KAsteroidsView::readSprites() 249void KAsteroidsView::readSprites()
249{ 250{
250 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND ); 251 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND );
251 int sep = sprites_prefix.findRev( "/" ); 252 int sep = sprites_prefix.findRev( "/" );
252 253
253 sprites_prefix.truncate( sep ); 254 sprites_prefix.truncate( sep );
254 255
255 int i = 0; 256 int i = 0;
256 while ( kas_animations[i].id ) 257 while ( kas_animations[i].id )
257 { 258 {
258 animation.insert( kas_animations[i].id, 259 animation.insert( kas_animations[i].id,
259 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path, 260 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path,
260 kas_animations[i].frames ) ); 261 kas_animations[i].frames ) );
261 i++; 262 i++;
262 } 263 }
263 264
264 ship = new QCanvasSprite( animation[ID_SHIP], &field ); 265 ship = new QCanvasSprite( animation[ID_SHIP], &field );
265 ship->hide(); 266 ship->hide();
266 267
267 shield = new KShield( animation[ID_SHIELD], &field ); 268 shield = new KShield( animation[ID_SHIELD], &field );
268 shield->hide(); 269 shield->hide();
269} 270}
270 271
271// - - - 272// - - -
272 273
273void KAsteroidsView::addRocks( int num ) 274void KAsteroidsView::addRocks( int num )
274{ 275{
275 for ( int i = 0; i < num; i++ ) 276 for ( int i = 0; i < num; i++ )
276 { 277 {
277 KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field, 278 KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field,
278 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); 279 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
279 double dx = (2.0 - randDouble()*4.0) * rockSpeed; 280 double dx = (2.0 - randDouble()*4.0) * rockSpeed;
280 double dy = (2.0 - randDouble()*4.0) * rockSpeed; 281 double dy = (2.0 - randDouble()*4.0) * rockSpeed;
281 rock->setVelocity( dx, dy ); 282 rock->setVelocity( dx, dy );
282 rock->setFrame( randInt( rock->frameCount() ) ); 283 rock->setFrame( randInt( rock->frameCount() ) );
283 if ( dx > 0 ) 284 if ( dx > 0 )
284 { 285 {
285 if ( dy > 0 ) 286 if ( dy > 0 )
286 rock->move( 5, 5, 0 ); 287 rock->move( 5, 5, 0 );
287 else 288 else
288 rock->move( 5, field.height() - 25, 0 ); 289 rock->move( 5, field.height() - 25, 0 );
289 } 290 }
290 else 291 else
291 { 292 {
292 if ( dy > 0 ) 293 if ( dy > 0 )
293 rock->move( field.width() - 25, 5, 0 ); 294 rock->move( field.width() - 25, 5, 0 );
294 else 295 else
295 rock->move( field.width() - 25, field.height() - 25, 0 ); 296 rock->move( field.width() - 25, field.height() - 25, 0 );
296 } 297 }
297 rock->show( ); 298 rock->show( );
298 rocks.append( rock ); 299 rocks.append( rock );
299 } 300 }
300} 301}
301 302
302// - - - 303// - - -
303 304
304void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) 305void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll )
305{ 306{
306 textSprite->setTextFlags( AlignLeft | AlignVCenter ); 307 textSprite->setTextFlags( AlignLeft | AlignVCenter );
307 textSprite->setText( text ); 308 textSprite->setText( text );
308 textSprite->setColor( color ); 309 textSprite->setColor( color );
309 310
310 if ( scroll ) { 311 if ( scroll ) {
311 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, 312 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
312 -textSprite->boundingRect().height() ); 313 -textSprite->boundingRect().height() );
313 textDy = TEXT_SPEED; 314 textDy = TEXT_SPEED;
314 } else { 315 } else {
315 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, 316 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
316 (field.height()-textSprite->boundingRect().height()) / 2 ); 317 (field.height()-textSprite->boundingRect().height()) / 2 );
317 textDy = 0; 318 textDy = 0;
318 } 319 }
319 textSprite->show(); 320 textSprite->show();
320} 321}
321 322
322// - - - 323// - - -
323 324
324void KAsteroidsView::hideText() 325void KAsteroidsView::hideText()
325{ 326{
326 textDy = -TEXT_SPEED; 327 textDy = -TEXT_SPEED;
327} 328}
328 329
329// - - - 330// - - -
330 331
331void KAsteroidsView::resizeEvent(QResizeEvent* event) 332void KAsteroidsView::resizeEvent(QResizeEvent* event)
332{ 333{
333 QWidget::resizeEvent(event); 334 QWidget::resizeEvent(event);
334 field.resize(width()-4, height()-4); 335 field.resize(width()-4, height()-4);
335 view.resize(width(),height()); 336 view.resize(width(),height());
336} 337}
337 338
338// - - - 339// - - -
339 340
340void KAsteroidsView::timerEvent( QTimerEvent * ) 341void KAsteroidsView::timerEvent( QTimerEvent * )
341{ 342{
342 field.advance(); 343 field.advance();
343 344
344 QCanvasSprite *rock; 345 QCanvasSprite *rock;
345 346
346 // move rocks forward 347 // move rocks forward
347 for ( rock = rocks.first(); rock; rock = rocks.next() ) { 348 for ( rock = rocks.first(); rock; rock = rocks.next() ) {
348 ((KRock *)rock)->nextFrame(); 349 ((KRock *)rock)->nextFrame();
349 wrapSprite( rock ); 350 wrapSprite( rock );
350 } 351 }
351 352
352 wrapSprite( ship ); 353 wrapSprite( ship );
353 354
354 // check for missile collision with rocks. 355 // check for missile collision with rocks.
355 processMissiles(); 356 processMissiles();
356 357
357 // these are generated when a ship explodes 358 // these are generated when a ship explodes
358 for ( KBit *bit = bits.first(); bit; bit = bits.next() ) 359 for ( KBit *bit = bits.first(); bit; bit = bits.next() )
359 { 360 {
360 if ( bit->expired() ) 361 if ( bit->expired() )
361 { 362 {
362 bits.removeRef( bit ); 363 bits.removeRef( bit );
363 } 364 }
364 else 365 else
365 { 366 {
366 bit->growOlder(); 367 bit->growOlder();
367 bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); 368 bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() );
368 } 369 }
369 } 370 }
370 371
371 for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) 372 for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() )
372 exhaust.removeRef( e ); 373 exhaust.removeRef( e );
373 374
374 // move / rotate ship. 375 // move / rotate ship.
375 // check for collision with a rock. 376 // check for collision with a rock.
376 processShip(); 377 processShip();
377 378
378 // move powerups and check for collision with player and missiles 379 // move powerups and check for collision with player and missiles
379 processPowerups(); 380 processPowerups();
380 381
381 if ( textSprite->visible() ) 382 if ( textSprite->visible() )
382 { 383 {
383 if ( textDy < 0 && 384 if ( textDy < 0 &&
384 textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { 385 textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) {
385 textSprite->hide(); 386 textSprite->hide();
386 } else { 387 } else {
387 textSprite->moveBy( 0, textDy ); 388 textSprite->moveBy( 0, textDy );
388 } 389 }
389 if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) 390 if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 )
390 textDy = 0; 391 textDy = 0;
391 } 392 }
392 393
393 if ( vitalsChanged && !(mFrameNum % 10) ) { 394 if ( vitalsChanged && !(mFrameNum % 10) ) {
394 emit updateVitals(); 395 emit updateVitals();
395 vitalsChanged = FALSE; 396 vitalsChanged = FALSE;
396 } 397 }
397 398
398 mFrameNum++; 399 mFrameNum++;
399} 400}
400 401
401void KAsteroidsView::wrapSprite( QCanvasItem *s ) 402void KAsteroidsView::wrapSprite( QCanvasItem *s )
402{ 403{
403 int x = int(s->x() + s->boundingRect().width() / 2); 404 int x = int(s->x() + s->boundingRect().width() / 2);
404 int y = int(s->y() + s->boundingRect().height() / 2); 405 int y = int(s->y() + s->boundingRect().height() / 2);
405 406
406 if ( x > field.width() ) 407 if ( x > field.width() )
407 s->move( s->x() - field.width(), s->y() ); 408 s->move( s->x() - field.width(), s->y() );
408 else if ( x < 0 ) 409 else if ( x < 0 )
409 s->move( field.width() + s->x(), s->y() ); 410 s->move( field.width() + s->x(), s->y() );
410 411
411 if ( y > field.height() ) 412 if ( y > field.height() )
412 s->move( s->x(), s->y() - field.height() ); 413 s->move( s->x(), s->y() - field.height() );
413 else if ( y < 0 ) 414 else if ( y < 0 )
414 s->move( s->x(), field.height() + s->y() ); 415 s->move( s->x(), field.height() + s->y() );
415} 416}
416 417
417// - - - 418// - - -
418 419
419void KAsteroidsView::rockHit( QCanvasItem *hit ) 420void KAsteroidsView::rockHit( QCanvasItem *hit )
420{ 421{
421 KPowerup *nPup = 0; 422 KPowerup *nPup = 0;
422 int rnd = static_cast<int>(randDouble()*30.0) % 30; 423 int rnd = static_cast<int>(randDouble()*30.0) % 30;
423 switch( rnd ) 424 switch( rnd )
424 { 425 {
425 case 4: 426 case 4:
426 case 5: 427 case 5:
427 nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, 428 nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field,
428 ID_ENERGY_POWERUP ); 429 ID_ENERGY_POWERUP );
429 break; 430 break;
430 case 10: 431 case 10:
431// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, 432// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field,
432// ID_TELEPORT_POWERUP ); 433// ID_TELEPORT_POWERUP );
433 break; 434 break;
434 case 15: 435 case 15:
435 nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, 436 nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field,
436 ID_BRAKE_POWERUP ); 437 ID_BRAKE_POWERUP );
437 break; 438 break;
438 case 20: 439 case 20:
439 nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, 440 nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field,
440 ID_SHIELD_POWERUP ); 441 ID_SHIELD_POWERUP );
441 break; 442 break;
442 case 24: 443 case 24:
443 case 25: 444 case 25:
444 nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, 445 nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field,
445 ID_SHOOT_POWERUP ); 446 ID_SHOOT_POWERUP );
446 break; 447 break;
447 } 448 }
448 if ( nPup ) 449 if ( nPup )
449 { 450 {
450 double r = 0.5 - randDouble(); 451 double r = 0.5 - randDouble();
451 nPup->move( hit->x(), hit->y(), 0 ); 452 nPup->move( hit->x(), hit->y(), 0 );
452 nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); 453 nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r );
453 nPup->show( ); 454 nPup->show( );
454 powerups.append( nPup ); 455 powerups.append( nPup );
455 } 456 }
456 457
457 if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) 458 if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM )
458 { 459 {
459 // break into smaller rocks 460 // break into smaller rocks
460 double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; 461 double addx[4] = { 1.0, 1.0, -1.0, -1.0 };
461 double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; 462 double addy[4] = { -1.0, 1.0, -1.0, 1.0 };
462 463
463 double dx = hit->xVelocity(); 464 double dx = hit->xVelocity();
464 double dy = hit->yVelocity(); 465 double dy = hit->yVelocity();
465 466
466 double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; 467 double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed;
467 if ( dx > maxRockSpeed ) 468 if ( dx > maxRockSpeed )
468 dx = maxRockSpeed; 469 dx = maxRockSpeed;
469 else if ( dx < -maxRockSpeed ) 470 else if ( dx < -maxRockSpeed )
470 dx = -maxRockSpeed; 471 dx = -maxRockSpeed;
471 if ( dy > maxRockSpeed ) 472 if ( dy > maxRockSpeed )
472 dy = maxRockSpeed; 473 dy = maxRockSpeed;
473 else if ( dy < -maxRockSpeed ) 474 else if ( dy < -maxRockSpeed )
474 dy = -maxRockSpeed; 475 dy = -maxRockSpeed;
475 476
476 QCanvasSprite *nrock; 477 QCanvasSprite *nrock;
477 478
478 for ( int i = 0; i < 4; i++ ) 479 for ( int i = 0; i < 4; i++ )
479 { 480 {
480 double r = rockSpeed/2 - randDouble()*rockSpeed; 481 double r = rockSpeed/2 - randDouble()*rockSpeed;
481 if ( hit->rtti() == ID_ROCK_LARGE ) 482 if ( hit->rtti() == ID_ROCK_LARGE )
482 { 483 {
483 nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, 484 nrock = new KRock( animation[ID_ROCK_MEDIUM], &field,
484 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); 485 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
485 emit rockHit( 0 ); 486 emit rockHit( 0 );
486 } 487 }
487 else 488 else
488 { 489 {
489 nrock = new KRock( animation[ID_ROCK_SMALL], &field, 490 nrock = new KRock( animation[ID_ROCK_SMALL], &field,
490 ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); 491 ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 );
491 emit rockHit( 1 ); 492 emit rockHit( 1 );
492 } 493 }
493 494
494 nrock->move( hit->x(), hit->y(), 0 ); 495 nrock->move( hit->x(), hit->y(), 0 );
495 nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); 496 nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r );
496 nrock->setFrame( randInt( nrock->frameCount() ) ); 497 nrock->setFrame( randInt( nrock->frameCount() ) );
497 nrock->show( ); 498 nrock->show( );
498 rocks.append( nrock ); 499 rocks.append( nrock );
499 } 500 }
500 } 501 }
501 else if ( hit->rtti() == ID_ROCK_SMALL ) 502 else if ( hit->rtti() == ID_ROCK_SMALL )
502 emit rockHit( 2 ); 503 emit rockHit( 2 );
503 rocks.removeRef( (QCanvasSprite *)hit ); 504 rocks.removeRef( (QCanvasSprite *)hit );
504 if ( rocks.count() == 0 ) 505 if ( rocks.count() == 0 )
505 emit rocksRemoved(); 506 emit rocksRemoved();
506} 507}
507 508
508void KAsteroidsView::reducePower( int val ) 509void KAsteroidsView::reducePower( int val )
509{ 510{
510 shipPower -= val; 511 shipPower -= val;
511 if ( shipPower <= 0 ) 512 if ( shipPower <= 0 )
512 { 513 {
513 shipPower = 0; 514 shipPower = 0;
514 thrustShip = FALSE; 515 thrustShip = FALSE;
515 if ( shieldOn ) 516 if ( shieldOn )
516 { 517 {
517 shieldOn = FALSE; 518 shieldOn = FALSE;
518 shield->hide(); 519 shield->hide();
519 } 520 }
520 } 521 }
521 vitalsChanged = TRUE; 522 vitalsChanged = TRUE;
522} 523}
523 524
524void KAsteroidsView::addExhaust( double x, double y, double dx, 525void KAsteroidsView::addExhaust( double x, double y, double dx,
525 double dy, int count ) 526 double dy, int count )
526{ 527{
527 for ( int i = 0; i < count; i++ ) 528 for ( int i = 0; i < count; i++ )
528 { 529 {
529 KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); 530 KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field );
530 e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); 531 e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 );
531 e->setVelocity( dx, dy ); 532 e->setVelocity( dx, dy );
532 e->show( ); 533 e->show( );
533 exhaust.append( e ); 534 exhaust.append( e );
534 } 535 }
535} 536}
536 537
537void KAsteroidsView::processMissiles() 538void KAsteroidsView::processMissiles()
538{ 539{
539 KMissile *missile; 540 KMissile *missile;
540 541
541 // if a missile has hit a rock, remove missile and break rock into smaller 542 // if a missile has hit a rock, remove missile and break rock into smaller
542 // rocks or remove completely. 543 // rocks or remove completely.
543 QPtrListIterator<KMissile> it(missiles); 544 QPtrListIterator<KMissile> it(missiles);
544 545
545 for ( ; it.current(); ++it ) 546 for ( ; it.current(); ++it )
546 { 547 {
547 missile = it.current(); 548 missile = it.current();
548 missile->growOlder(); 549 missile->growOlder();
549 550
550 if ( missile->expired() ) 551 if ( missile->expired() )
551 { 552 {
552 missiles.removeRef( missile ); 553 missiles.removeRef( missile );
553 continue; 554 continue;
554 } 555 }
555 556
556 wrapSprite( missile ); 557 wrapSprite( missile );
557 558
558 QCanvasItemList hits = missile->collisions( TRUE ); 559 QCanvasItemList hits = missile->collisions( TRUE );
559 QCanvasItemList::Iterator hit; 560 QCanvasItemList::Iterator hit;
560 for ( hit = hits.begin(); hit != hits.end(); ++hit ) 561 for ( hit = hits.begin(); hit != hits.end(); ++hit )
561 { 562 {
562 if ( (*hit)->rtti() >= ID_ROCK_LARGE && 563 if ( (*hit)->rtti() >= ID_ROCK_LARGE &&
563 (*hit)->rtti() <= ID_ROCK_SMALL ) 564 (*hit)->rtti() <= ID_ROCK_SMALL )
564 { 565 {
565 shotsHit++; 566 shotsHit++;
566 rockHit( *hit ); 567 rockHit( *hit );
567 missiles.removeRef( missile ); 568 missiles.removeRef( missile );
568 break; 569 break;
569 } 570 }
570 } 571 }
571 } 572 }
572} 573}
573 574
574// - - - 575// - - -
575 576
576void KAsteroidsView::processShip() 577void KAsteroidsView::processShip()
577{ 578{
578 if ( ship->visible() ) 579 if ( ship->visible() )
579 { 580 {
580 if ( shieldOn ) 581 if ( shieldOn )
581 { 582 {
582 shield->show(); 583 shield->show();
583 reducePower( SHIELD_ON_COST ); 584 reducePower( SHIELD_ON_COST );
584 static int sf = 0; 585 static int sf = 0;
585 sf++; 586 sf++;
586 587
587 if ( sf % 2 ) 588 if ( sf % 2 )
588 shield->setFrame( (shield->frame()+1) % shield->frameCount() ); 589 shield->setFrame( (shield->frame()+1) % shield->frameCount() );
589 shield->move( ship->x() - 5, ship->y() - 5 ); 590 shield->move( ship->x() - 5, ship->y() - 5 );
590 591
591 QCanvasItemList hits = shield->collisions( TRUE ); 592 QCanvasItemList hits = shield->collisions( TRUE );
592 QCanvasItemList::Iterator it; 593 QCanvasItemList::Iterator it;
593 for ( it = hits.begin(); it != hits.end(); ++it ) 594 for ( it = hits.begin(); it != hits.end(); ++it )
594 { 595 {
595 if ( (*it)->rtti() >= ID_ROCK_LARGE && 596 if ( (*it)->rtti() >= ID_ROCK_LARGE &&
596 (*it)->rtti() <= ID_ROCK_SMALL ) 597 (*it)->rtti() <= ID_ROCK_SMALL )
597 { 598 {
598 int factor; 599 int factor;
599 switch ( (*it)->rtti() ) 600 switch ( (*it)->rtti() )
600 { 601 {
601 case ID_ROCK_LARGE: 602 case ID_ROCK_LARGE:
602 factor = 3; 603 factor = 3;
603 break; 604 break;
604 605
605 case ID_ROCK_MEDIUM: 606 case ID_ROCK_MEDIUM:
606 factor = 2; 607 factor = 2;
607 break; 608 break;
608 609
609 default: 610 default:
610 factor = 1; 611 factor = 1;
611 } 612 }
612 613
613 if ( factor > mShieldCount ) 614 if ( factor > mShieldCount )
614 { 615 {
615 // shield not strong enough 616 // shield not strong enough
616 shieldOn = FALSE; 617 shieldOn = FALSE;
617 break; 618 break;
618 } 619 }
619 rockHit( *it ); 620 rockHit( *it );
620 // the more shields we have the less costly 621 // the more shields we have the less costly
621 reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) ); 622 reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) );
622 } 623 }
623 } 624 }
624 } 625 }
625 626
626 if ( !shieldOn ) 627 if ( !shieldOn )
627 { 628 {
628 shield->hide(); 629 shield->hide();
629 QCanvasItemList hits = ship->collisions( TRUE ); 630 QCanvasItemList hits = ship->collisions( TRUE );
630 QCanvasItemList::Iterator it; 631 QCanvasItemList::Iterator it;
631 for ( it = hits.begin(); it != hits.end(); ++it ) 632 for ( it = hits.begin(); it != hits.end(); ++it )
632 { 633 {
633 if ( (*it)->rtti() >= ID_ROCK_LARGE && 634 if ( (*it)->rtti() >= ID_ROCK_LARGE &&
634 (*it)->rtti() <= ID_ROCK_SMALL ) 635 (*it)->rtti() <= ID_ROCK_SMALL )
635 { 636 {
636 KBit *bit; 637 KBit *bit;
637 for ( int i = 0; i < 8; i++ ) 638 for ( int i = 0; i < 8; i++ )
638 { 639 {
639 bit = new KBit( animation[ID_BIT], &field ); 640 bit = new KBit( animation[ID_BIT], &field );
640 bit->move( ship->x() + 5 - randDouble() * 10, 641 bit->move( ship->x() + 5 - randDouble() * 10,
641 ship->y() + 5 - randDouble() * 10, 642 ship->y() + 5 - randDouble() * 10,
642 randInt(bit->frameCount()) ); 643 randInt(bit->frameCount()) );
643 bit->setVelocity( 1-randDouble()*2, 644 bit->setVelocity( 1-randDouble()*2,
644 1-randDouble()*2 ); 645 1-randDouble()*2 );
645 bit->setDeath( 60 + randInt(60) ); 646 bit->setDeath( 60 + randInt(60) );
646 bit->show( ); 647 bit->show( );
647 bits.append( bit ); 648 bits.append( bit );
648 } 649 }
649 ship->hide(); 650 ship->hide();
650 shield->hide(); 651 shield->hide();
651 emit shipKilled(); 652 emit shipKilled();
652 break; 653 break;
653 } 654 }
654 } 655 }
655 } 656 }
656 657
657 658
658 if ( rotateSlow ) 659 if ( rotateSlow )
659 rotateSlow--; 660 rotateSlow--;
660 661
661 if ( rotateL ) 662 if ( rotateL )
662 { 663 {
663 shipAngle -= rotateSlow ? 1 : rotateRate; 664 shipAngle -= rotateSlow ? 1 : rotateRate;
664 if ( shipAngle < 0 ) 665 if ( shipAngle < 0 )
665 shipAngle += SHIP_STEPS; 666 shipAngle += SHIP_STEPS;
666 } 667 }
667 668
668 if ( rotateR ) 669 if ( rotateR )
669 { 670 {
670 shipAngle += rotateSlow ? 1 : rotateRate; 671 shipAngle += rotateSlow ? 1 : rotateRate;
671 if ( shipAngle >= SHIP_STEPS ) 672 if ( shipAngle >= SHIP_STEPS )
672 shipAngle -= SHIP_STEPS; 673 shipAngle -= SHIP_STEPS;
673 } 674 }
674 675
675 double angle = shipAngle * PI_X_2 / SHIP_STEPS; 676 double angle = shipAngle * PI_X_2 / SHIP_STEPS;
676 double cosangle = cos( angle ); 677 double cosangle = cos( angle );
677 double sinangle = sin( angle ); 678 double sinangle = sin( angle );
678 679
679 if ( brakeShip ) 680 if ( brakeShip )
680 { 681 {
681 thrustShip = FALSE; 682 thrustShip = FALSE;
682 rotateL = FALSE; 683 rotateL = FALSE;
683 rotateR = FALSE; 684 rotateR = FALSE;
684 rotateRate = ROTATE_RATE; 685 rotateRate = ROTATE_RATE;
685 if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 ) 686 if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 )
686 { 687 {
687 shipDx = 0.0; 688 shipDx = 0.0;
688 shipDy = 0.0; 689 shipDy = 0.0;
689 ship->setVelocity( shipDx, shipDy ); 690 ship->setVelocity( shipDx, shipDy );
690 brakeShip = FALSE; 691 brakeShip = FALSE;
691 } 692 }
692 else 693 else
693 { 694 {
694 double motionAngle = atan2( -shipDy, -shipDx ); 695 double motionAngle = atan2( -shipDy, -shipDx );
695 if ( angle > M_PI ) 696 if ( angle > M_PI )
696 angle -= PI_X_2; 697 angle -= PI_X_2;
697 double angleDiff = angle - motionAngle; 698 double angleDiff = angle - motionAngle;
698 if ( angleDiff > M_PI ) 699 if ( angleDiff > M_PI )
699 angleDiff = PI_X_2 - angleDiff; 700 angleDiff = PI_X_2 - angleDiff;
700 else if ( angleDiff < -M_PI ) 701 else if ( angleDiff < -M_PI )
701 angleDiff = PI_X_2 + angleDiff; 702 angleDiff = PI_X_2 + angleDiff;
702 double fdiff = fabs( angleDiff ); 703 double fdiff = fabs( angleDiff );
703 if ( fdiff > 0.08 ) 704 if ( fdiff > 0.08 )
704 { 705 {
705 if ( angleDiff > 0 ) 706 if ( angleDiff > 0 )
706 rotateL = TRUE; 707 rotateL = TRUE;
707 else if ( angleDiff < 0 ) 708 else if ( angleDiff < 0 )
708 rotateR = TRUE; 709 rotateR = TRUE;
709 if ( fdiff > 0.6 ) 710 if ( fdiff > 0.6 )
710 rotateRate = mBrakeCount + 1; 711 rotateRate = mBrakeCount + 1;
711 else if ( fdiff > 0.4 ) 712 else if ( fdiff > 0.4 )
712 rotateRate = 2; 713 rotateRate = 2;
713 else 714 else
714 rotateRate = 1; 715 rotateRate = 1;
715 716
716 if ( rotateRate > 5 ) 717 if ( rotateRate > 5 )
717 rotateRate = 5; 718 rotateRate = 5;
718 } 719 }
719 else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 ) 720 else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 )
720 { 721 {
721 thrustShip = TRUE; 722 thrustShip = TRUE;
722 // we'll make braking a bit faster 723 // we'll make braking a bit faster
723 shipDx += cosangle/6 * (mBrakeCount - 1); 724 shipDx += cosangle/6 * (mBrakeCount - 1);
724 shipDy += sinangle/6 * (mBrakeCount - 1); 725 shipDy += sinangle/6 * (mBrakeCount - 1);
725 reducePower( BRAKE_ON_COST ); 726 reducePower( BRAKE_ON_COST );
726 addExhaust( ship->x() + 10 - cosangle*11, 727 addExhaust( ship->x() + 10 - cosangle*11,
727 ship->y() + 10 - sinangle*11, 728 ship->y() + 10 - sinangle*11,
728 shipDx-cosangle, shipDy-sinangle, 729 shipDx-cosangle, shipDy-sinangle,
729 mBrakeCount+1 ); 730 mBrakeCount+1 );
730 } 731 }
731 } 732 }
732 } 733 }
733 734
734 if ( thrustShip ) 735 if ( thrustShip )
735 { 736 {
736 // The ship has a terminal velocity, but trying to go faster 737 // The ship has a terminal velocity, but trying to go faster
737 // still uses fuel (can go faster diagonally - don't care). 738 // still uses fuel (can go faster diagonally - don't care).
738 double thrustx = cosangle/8; 739 double thrustx = cosangle/8;
739 double thrusty = sinangle/8; 740 double thrusty = sinangle/8;
740 if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED ) 741 if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED )
741 shipDx += thrustx; 742 shipDx += thrustx;
742 if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED ) 743 if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED )
743 shipDy += thrusty; 744 shipDy += thrusty;
744 ship->setVelocity( shipDx, shipDy ); 745 ship->setVelocity( shipDx, shipDy );
745 reducePower( 1 ); 746 reducePower( 1 );
746 addExhaust( ship->x() + 10 - cosangle*10, 747 addExhaust( ship->x() + 10 - cosangle*10,
747 ship->y() + 10 - sinangle*10, 748 ship->y() + 10 - sinangle*10,
748 shipDx-cosangle, shipDy-sinangle, 3 ); 749 shipDx-cosangle, shipDy-sinangle, 3 );
749 } 750 }
750 751
751 ship->setFrame( shipAngle >> 1 ); 752 ship->setFrame( shipAngle >> 1 );
752 753
753 if ( shootShip ) 754 if ( shootShip )
754 { 755 {
755 if ( !shootDelay && (int)missiles.count() < mShootCount + 2 ) 756 if ( !shootDelay && (int)missiles.count() < mShootCount + 2 )
756 { 757 {
757 KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); 758 KMissile *missile = new KMissile( animation[ID_MISSILE], &field );
758 missile->move( 11+ship->x()+cosangle*11, 759 missile->move( 11+ship->x()+cosangle*11,
759 11+ship->y()+sinangle*11, 0 ); 760 11+ship->y()+sinangle*11, 0 );
760 missile->setVelocity( shipDx + cosangle*MISSILE_SPEED, 761 missile->setVelocity( shipDx + cosangle*MISSILE_SPEED,
761 shipDy + sinangle*MISSILE_SPEED ); 762 shipDy + sinangle*MISSILE_SPEED );
762 missile->show( ); 763 missile->show( );
763 missiles.append( missile ); 764 missiles.append( missile );
764 shotsFired++; 765 shotsFired++;
765 reducePower( 1 ); 766 reducePower( 1 );
766 767
767 shootDelay = 5; 768 shootDelay = 5;
768 } 769 }
769 770
770 if ( shootDelay ) 771 if ( shootDelay )
771 shootDelay--; 772 shootDelay--;
772 } 773 }
773 774
774 if ( teleportShip ) 775 if ( teleportShip )
775 { 776 {
776 int ra = rand() % 10; 777 int ra = rand() % 10;
777 if( ra == 0 ) 778 if( ra == 0 )
778 ra += rand() % 20; 779 ra += rand() % 20;
779 int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) ); 780 int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) );
780 int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) ); 781 int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) );
781 ship->move( xra, yra ); 782 ship->move( xra, yra );
782 } 783 }
783 784
784 vitalsChanged = TRUE; 785 vitalsChanged = TRUE;
785 } 786 }
786} 787}
787 788
788// - - - 789// - - -
789 790
790void KAsteroidsView::processPowerups() 791void KAsteroidsView::processPowerups()
791{ 792{
792 if ( !powerups.isEmpty() ) 793 if ( !powerups.isEmpty() )
793 { 794 {
794 // if player gets the powerup remove it from the screen, if option 795 // if player gets the powerup remove it from the screen, if option
795 // "Can destroy powerups" is enabled and a missile hits the powerup 796 // "Can destroy powerups" is enabled and a missile hits the powerup
796 // destroy it 797 // destroy it
797 798
798 KPowerup *pup; 799 KPowerup *pup;
799 QPtrListIterator<KPowerup> it( powerups ); 800 QPtrListIterator<KPowerup> it( powerups );
800 801
801 for( ; it.current(); ++it ) 802 for( ; it.current(); ++it )
802 { 803 {
803 pup = it.current(); 804 pup = it.current();
804 pup->growOlder(); 805 pup->growOlder();
805 806
806 if( pup->expired() ) 807 if( pup->expired() )
807 { 808 {
808 powerups.removeRef( pup ); 809 powerups.removeRef( pup );
809 continue; 810 continue;
810 } 811 }
811 812
812 wrapSprite( pup ); 813 wrapSprite( pup );
813 814
814 QCanvasItemList hits = pup->collisions( TRUE ); 815 QCanvasItemList hits = pup->collisions( TRUE );
815 QCanvasItemList::Iterator it; 816 QCanvasItemList::Iterator it;
816 for ( it = hits.begin(); it != hits.end(); ++it ) 817 for ( it = hits.begin(); it != hits.end(); ++it )
817 { 818 {
818 if ( (*it) == ship ) 819 if ( (*it) == ship )
819 { 820 {
820 switch( pup->rtti() ) 821 switch( pup->rtti() )
821 { 822 {
822 case ID_ENERGY_POWERUP: 823 case ID_ENERGY_POWERUP:
823 shipPower += 150; 824 shipPower += 150;
824 if ( shipPower > MAX_POWER_LEVEL ) 825 if ( shipPower > MAX_POWER_LEVEL )
825 shipPower = MAX_POWER_LEVEL; 826 shipPower = MAX_POWER_LEVEL;
826 break; 827 break;
827 case ID_TELEPORT_POWERUP: 828 case ID_TELEPORT_POWERUP:
828 mTeleportCount++; 829 mTeleportCount++;
829 break; 830 break;
830 case ID_BRAKE_POWERUP: 831 case ID_BRAKE_POWERUP:
831 if ( mBrakeCount < MAX_BRAKES ) 832 if ( mBrakeCount < MAX_BRAKES )
832 mBrakeCount++; 833 mBrakeCount++;
833 break; 834 break;
834 case ID_SHIELD_POWERUP: 835 case ID_SHIELD_POWERUP:
835 if ( mShieldCount < MAX_SHIELDS ) 836 if ( mShieldCount < MAX_SHIELDS )
836 mShieldCount++; 837 mShieldCount++;
837 break; 838 break;
838 case ID_SHOOT_POWERUP: 839 case ID_SHOOT_POWERUP:
839 if ( mShootCount < MAX_FIREPOWER ) 840 if ( mShootCount < MAX_FIREPOWER )
840 mShootCount++; 841 mShootCount++;
841 break; 842 break;
842 } 843 }
843 844
844 powerups.removeRef( pup ); 845 powerups.removeRef( pup );
845 vitalsChanged = TRUE; 846 vitalsChanged = TRUE;
846 } 847 }
847 else if ( (*it) == shield ) 848 else if ( (*it) == shield )
848 { 849 {
849 powerups.removeRef( pup ); 850 powerups.removeRef( pup );
850 } 851 }
851 else if ( (*it)->rtti() == ID_MISSILE ) 852 else if ( (*it)->rtti() == ID_MISSILE )
852 { 853 {
853 if ( can_destroy_powerups ) 854 if ( can_destroy_powerups )
854 { 855 {
855 powerups.removeRef( pup ); 856 powerups.removeRef( pup );
856 } 857 }
857 } 858 }
858 } 859 }
859 } 860 }
860 } // -- if( powerups.isEmpty() ) 861 } // -- if( powerups.isEmpty() )
861} 862}
862 863
863// - - - 864// - - -
864 865
865void KAsteroidsView::hideShield() 866void KAsteroidsView::hideShield()
866{ 867{
867 shield->hide(); 868 shield->hide();
868 mShieldCount = 0; 869 mShieldCount = 0;
869 shieldOn = FALSE; 870 shieldOn = FALSE;
870} 871}
871 872
872double KAsteroidsView::randDouble() 873double KAsteroidsView::randDouble()
873{ 874{
874 int v = rand(); 875 int v = rand();
875 return (double)v / (double)RAND_MAX; 876 return (double)v / (double)RAND_MAX;
876} 877}
877 878
878int KAsteroidsView::randInt( int range ) 879int KAsteroidsView::randInt( int range )
879{ 880{
880 return rand() % range; 881 return rand() % range;
881} 882}
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h
index 1eb2499..757e6b3 100644
--- a/noncore/games/solitaire/cardpile.h
+++ b/noncore/games/solitaire/cardpile.h
@@ -1,115 +1,117 @@
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#ifndef CARD_PILE_H 20#ifndef CARD_PILE_H
21#define CARD_PILE_H 21#define CARD_PILE_H
22 22
23#include "card.h"
24
23 25
24#include <qpoint.h> 26#include <qpoint.h>
25#include <qlist.h> 27#include <qlist.h>
26 28
27 29
28enum ePileStackingType { 30enum ePileStackingType {
29 pileCascades = 0, pileStacks, pileCascadesOrStacks 31 pileCascades = 0, pileStacks, pileCascadesOrStacks
30}; 32};
31 33
32 34
33enum ePileFaceingType { 35enum ePileFaceingType {
34 pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown 36 pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown
35}; 37};
36 38
37 39
38class Card; 40class Card;
39class Config; 41class Config;
40 42
41 43
42class CardPile : public QList<Card> 44class CardPile : public QList<Card>
43{ 45{
44public: 46public:
45 CardPile(int x, int y); 47 CardPile(int x, int y);
46 virtual ~CardPile() { } 48 virtual ~CardPile() { }
47 49
48 int getX() { return pileX; } 50 int getX() { return pileX; }
49 int getY() { return pileY; } 51 int getY() { return pileY; }
50 int getNextX() { return pileNextX; } 52 int getNextX() { return pileNextX; }
51 int getNextY() { return pileNextY; } 53 int getNextY() { return pileNextY; }
52 int getWidth() { return pileWidth; } 54 int getWidth() { return pileWidth; }
53 int getHeight() { return pileHeight; } 55 int getHeight() { return pileHeight; }
54 int getOffsetDown() { return pileOffsetDown; } 56 int getOffsetDown() { return pileOffsetDown; }
55 int getAnzCardsInPile() { 57 int getAnzCardsInPile() {
56 int anz=0; 58 int anz=0;
57 Card *card = cardOnBottom(); 59 Card *card = cardOnBottom();
58 while (card != NULL) { anz++; card = cardInfront(card); } 60 while (card != NULL) { anz++; card = cardInfront(card); }
59 return anz; 61 return anz;
60 } 62 }
61 63
62 void setX(int x) { pileX = x; } 64 void setX(int x) { pileX = x; }
63 void setY(int y) { pileY = y; } 65 void setY(int y) { pileY = y; }
64 void setNextX(int x) { pileNextX = x; } 66 void setNextX(int x) { pileNextX = x; }
65 void setNextY(int y) { pileNextY = y; } 67 void setNextY(int y) { pileNextY = y; }
66 void setWidth(int width) { pileWidth = width; } 68 void setWidth(int width) { pileWidth = width; }
67 void setHeight(int height) { pileHeight = height; } 69 void setHeight(int height) { pileHeight = height; }
68 void setOffsetDown(int down) { pileOffsetDown = down; } 70 void setOffsetDown(int down) { pileOffsetDown = down; }
69 71
70 void beginDealing() { dealing = TRUE; } 72 void beginDealing() { dealing = TRUE; }
71 void endDealing() { dealing = FALSE; } 73 void endDealing() { dealing = FALSE; }
72 bool isDealing() { return dealing; } 74 bool isDealing() { return dealing; }
73 75
74 void beginPileResize() { PileResize = TRUE; } 76 void beginPileResize() { PileResize = TRUE; }
75 void endPileResize() { PileResize = FALSE; } 77 void endPileResize() { PileResize = FALSE; }
76 bool isPileResize() { return PileResize; } 78 bool isPileResize() { return PileResize; }
77 79
78 int distanceFromPile(int x, int y); 80 int distanceFromPile(int x, int y);
79 int distanceFromNextPos(int x, int y); 81 int distanceFromNextPos(int x, int y);
80 82
81 Card *cardOnTop() { return getLast(); } 83 Card *cardOnTop() { return getLast(); }
82 Card *cardOnBottom() { return getFirst(); } 84 Card *cardOnBottom() { return getFirst(); }
83 Card *cardInfront(Card *c); 85 Card *cardInfront(Card *c);
84 bool kingOnTop(); 86 bool kingOnTop();
85 87
86 bool addCardToTop(Card *c); 88 bool addCardToTop(Card *c);
87 bool addCardToBottom(Card *c); 89 bool addCardToBottom(Card *c);
88 bool removeCard(Card *c); 90 bool removeCard(Card *c);
89 91
90 virtual void cardAddedToTop(Card *) { } 92 virtual void cardAddedToTop(Card *) { }
91 virtual void cardAddedToBottom(Card *) { } 93 virtual void cardAddedToBottom(Card *) { }
92 virtual void cardRemoved(Card *) { } 94 virtual void cardRemoved(Card *) { }
93 virtual bool isAllowedOnTop(Card *) { return FALSE; } 95 virtual bool isAllowedOnTop(Card *) { return FALSE; }
94 virtual bool isAllowedOnBottom(Card *) { return FALSE; } 96 virtual bool isAllowedOnBottom(Card *) { return FALSE; }
95 virtual bool isAllowedToBeMoved(Card *) { return FALSE; } 97 virtual bool isAllowedToBeMoved(Card *) { return FALSE; }
96 virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); } 98 virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); }
97 virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); } 99 virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); }
98 100
99 void writeConfig( Config& cfg, QString name ); 101 void writeConfig( Config& cfg, QString name );
100 102
101protected: 103protected:
102 int pileX, pileY; 104 int pileX, pileY;
103 int pileNextX, pileNextY; 105 int pileNextX, pileNextY;
104 int pileWidth, pileHeight; 106 int pileWidth, pileHeight;
105 int pileCenterX, pileCenterY; 107 int pileCenterX, pileCenterY;
106 int pileRadius; 108 int pileRadius;
107 int pileOffsetDown; 109 int pileOffsetDown;
108private: 110private:
109 bool dealing; 111 bool dealing;
110 bool PileResize; 112 bool PileResize;
111}; 113};
112 114
113 115
114#endif 116#endif
115 117