summaryrefslogtreecommitdiff
authoreilers <eilers>2003-08-01 14:19:44 (UTC)
committer eilers <eilers>2003-08-01 14:19:44 (UTC)
commit34991bac7d96b1c17601be6a5607819342571e0c (patch) (unidiff)
tree65d0bc2db22bcc1dc1b5eafdafd53b9cb08a6395
parent5346424fc26bde232a15aa34fbb720f86218b26f (diff)
downloadopie-34991bac7d96b1c17601be6a5607819342571e0c.zip
opie-34991bac7d96b1c17601be6a5607819342571e0c.tar.gz
opie-34991bac7d96b1c17601be6a5607819342571e0c.tar.bz2
Merging changes from BRANCH_1_0 to HEAD..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp50
-rw-r--r--core/pim/datebook/datebook.pro6
-rw-r--r--core/pim/datebook/datebookday.cpp127
-rw-r--r--core/pim/datebook/datebookday.h6
-rw-r--r--core/pim/datebook/datebookdayallday.cpp226
-rw-r--r--core/pim/datebook/datebookdayallday.h80
-rw-r--r--core/pim/datebook/datebooksettings.h5
-rw-r--r--core/pim/datebook/datebookweek.cpp65
-rw-r--r--core/pim/datebook/datebookweekheaderimpl.cpp12
-rw-r--r--core/pim/datebook/datebookweeklst.cpp10
-rw-r--r--core/pim/datebook/dateentryimpl.cpp2
-rw-r--r--core/pim/datebook/opie-datebook.control6
-rw-r--r--core/pim/datebook/repeatentry.cpp50
13 files changed, 564 insertions, 81 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index b7e89b0..10a9b59 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,1063 +1,1093 @@
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** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "datebook.h" 25#include "datebook.h"
26#include "datebookday.h" 26#include "datebookday.h"
27#include "datebooksettings.h" 27#include "datebooksettings.h"
28#include "datebookweek.h" 28#include "datebookweek.h"
29#include "datebookweeklst.h" 29#include "datebookweeklst.h"
30#include "dateentryimpl.h" 30#include "dateentryimpl.h"
31 31
32#include <qpe/datebookmonth.h> 32#include <qpe/datebookmonth.h>
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/qpedebug.h> 35#include <qpe/qpedebug.h>
36#include <qpe/event.h> 36#include <qpe/event.h>
37#include <qpe/finddialog.h> 37#include <qpe/finddialog.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42#include <qpe/sound.h> 42#include <qpe/sound.h>
43#include <qpe/timestring.h> 43#include <qpe/timestring.h>
44#include <qpe/qpetoolbar.h> 44#include <qpe/qpetoolbar.h>
45#include <qpe/tzselect.h> 45#include <qpe/tzselect.h>
46#include <qpe/xmlreader.h> 46#include <qpe/xmlreader.h>
47 47
48#include <qaction.h> 48#include <qaction.h>
49#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qdialog.h> 51#include <qdialog.h>
52#include <qfile.h> 52#include <qfile.h>
53#include <qlabel.h> 53#include <qlabel.h>
54#include <qlayout.h> 54#include <qlayout.h>
55#include <qmessagebox.h> 55#include <qmessagebox.h>
56#include <qpopupmenu.h> 56#include <qpopupmenu.h>
57#include <qpushbutton.h> 57#include <qpushbutton.h>
58#include <qregexp.h> 58#include <qregexp.h>
59#include <qtextcodec.h> 59#include <qtextcodec.h>
60#include <qtextstream.h> 60#include <qtextstream.h>
61#include <qtimer.h> 61#include <qtimer.h>
62#include <qtl.h> 62#include <qtl.h>
63#include <qwidgetstack.h> 63#include <qwidgetstack.h>
64#include <qwindowsystem_qws.h> 64#include <qwindowsystem_qws.h>
65 65
66#include <sys/stat.h> 66#include <sys/stat.h>
67#include <sys/types.h> 67#include <sys/types.h>
68#include <fcntl.h> 68#include <fcntl.h>
69#include <unistd.h> 69#include <unistd.h>
70 70
71#include <stdlib.h> 71#include <stdlib.h>
72 72
73DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 73DateBook::DateBook( QWidget *parent, const char *, WFlags f )
74 : QMainWindow( parent, "datebook", f ), 74 : QMainWindow( parent, "datebook", f ),
75 aPreset( FALSE ), 75 aPreset( FALSE ),
76 presetTime( -1 ), 76 presetTime( -1 ),
77 startTime( 8 ), // an acceptable default 77 startTime( 8 ), // an acceptable default
78 rowStyle( 0 ), 78 rowStyle( 0 ),
79 bJumpToCurTime(FALSE), 79 bJumpToCurTime(FALSE),
80 syncing(FALSE), 80 syncing(FALSE),
81 inSearch(FALSE), 81 inSearch(FALSE),
82 alarmCounter(0) 82 alarmCounter(0)
83{ 83{
84 bool needEvilHack= false; // if we need an Evil Hack 84 bool needEvilHack= false; // if we need an Evil Hack
85 QTime t; 85 QTime t;
86 t.start(); 86 t.start();
87 db = new DateBookDBHack; 87 db = new DateBookDBHack;
88 qDebug("loading db t=%d", t.elapsed() ); 88 qDebug("loading db t=%d", t.elapsed() );
89 loadSettings(); 89 loadSettings();
90 setCaption( tr("Calendar") ); 90 setCaption( tr("Calendar") );
91 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 91 setIcon( Resource::loadPixmap( "datebook_icon" ) );
92 92
93 setToolBarsMovable( FALSE ); 93 setToolBarsMovable( FALSE );
94 94
95 views = new QWidgetStack( this ); 95 views = new QWidgetStack( this );
96 setCentralWidget( views ); 96 setCentralWidget( views );
97 97
98 dayView = 0; 98 dayView = 0;
99 weekView = 0; 99 weekView = 0;
100 weekLstView = 0; 100 weekLstView = 0;
101 monthView = 0; 101 monthView = 0;
102 102
103// QPEToolBar *bar = new QPEToolBar( this ); 103// QPEToolBar *bar = new QPEToolBar( this );
104// bar->setHorizontalStretchable( TRUE ); 104// bar->setHorizontalStretchable( TRUE );
105 105
106// QPEMenuBar *mb = new QPEMenuBar( bar ); 106// QPEMenuBar *mb = new QPEMenuBar( bar );
107// mb->setMargin( 0 ); 107// mb->setMargin( 0 );
108 108
109// QPopupMenu *view = new QPopupMenu( this ); 109// QPopupMenu *view = new QPopupMenu( this );
110// mb->insertItem( tr( "View" ), view ); 110// mb->insertItem( tr( "View" ), view );
111 111
112 QPEToolBar *sub_bar = new QPEToolBar(this); 112 QPEToolBar *sub_bar = new QPEToolBar(this);
113 sub_bar->setHorizontalStretchable(TRUE); 113 sub_bar->setHorizontalStretchable(TRUE);
114 114
115 QActionGroup *g = new QActionGroup( this ); 115 QActionGroup *g = new QActionGroup( this );
116 g->setExclusive( TRUE ); 116 g->setExclusive( TRUE );
117 117
118 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 118 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
119 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 119 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
120 a->addTo( sub_bar ); 120 a->addTo( sub_bar );
121 121
122 sub_bar->addSeparator(); 122 sub_bar->addSeparator();
123 123
124 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); 124 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 );
125 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 125 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
126 a->addTo( sub_bar ); 126 a->addTo( sub_bar );
127 //a->addTo( view ); 127 //a->addTo( view );
128 128
129 sub_bar->addSeparator(); 129 sub_bar->addSeparator();
130 130
131 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 131 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
132 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 132 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
133 a->addTo( sub_bar ); 133 a->addTo( sub_bar );
134// a->addTo( view ); 134// a->addTo( view );
135 a->setToggleAction( TRUE ); 135 a->setToggleAction( TRUE );
136 a->setOn( TRUE ); 136 a->setOn( TRUE );
137 dayAction = a; 137 dayAction = a;
138 138
139 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 139 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
140 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 140 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
141 a->addTo( sub_bar ); 141 a->addTo( sub_bar );
142// a->addTo( view ); 142// a->addTo( view );
143 a->setToggleAction( TRUE ); 143 a->setToggleAction( TRUE );
144 weekAction = a; 144 weekAction = a;
145 145
146 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); 146 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 );
147 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 147 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
148 a->addTo( sub_bar ); 148 a->addTo( sub_bar );
149// a->addTo( view ); 149// a->addTo( view );
150 a->setToggleAction( TRUE ); 150 a->setToggleAction( TRUE );
151 weekLstAction = a; 151 weekLstAction = a;
152 152
153 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 153 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
154 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 154 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
155 a->addTo( sub_bar ); 155 a->addTo( sub_bar );
156// a->addTo( view ); 156// a->addTo( view );
157 a->setToggleAction( TRUE ); 157 a->setToggleAction( TRUE );
158 monthAction = a; 158 monthAction = a;
159 159
160 sub_bar->addSeparator(); 160 sub_bar->addSeparator();
161 161
162 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 162 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
163 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 163 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
164 a->addTo( sub_bar ); 164 a->addTo( sub_bar );
165 165
166 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); 166 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 );
167 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 167 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
168 a->addTo( sub_bar ); 168 a->addTo( sub_bar );
169 169
170 if(defaultView==DAY) viewDay(); 170 if(defaultView==DAY) viewDay();
171 if(defaultView==WEEK) needEvilHack=true;// viewWeek(); 171 if(defaultView==WEEK) needEvilHack=true;// viewWeek();
172 if(defaultView==WEEKLST) viewWeekLst(); 172 if(defaultView==WEEKLST) viewWeekLst();
173 if(defaultView==MONTH) viewMonth(); 173 if(defaultView==MONTH) viewMonth();
174 174
175 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 175 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
176 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); 176 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
177 177
178#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 178#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
179 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 179 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) );
180#endif 180#endif
181 181
182 // listen on QPE/System 182 // listen on QPE/System
183#if defined(Q_WS_QWS) 183#if defined(Q_WS_QWS)
184#if !defined(QT_NO_COP) 184#if !defined(QT_NO_COP)
185 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 185 QCopChannel *channel = new QCopChannel( "QPE/System", this );
186 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); 186 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
187 channel = new QCopChannel( "QPE/Datebook", this ); 187 channel = new QCopChannel( "QPE/Datebook", this );
188 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); 188 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
189 qDebug("olle\n"); 189 qDebug("olle\n");
190#endif 190#endif
191#endif 191#endif
192 192
193 qDebug("done t=%d", t.elapsed() ); 193 qDebug("done t=%d", t.elapsed() );
194 194
195 /* 195 /*
196 * Here is a problem description: 196 * Here is a problem description:
197 * When Weekview is the default view 197 * When Weekview is the default view
198 * a DateBookWeekView get's created 198 * a DateBookWeekView get's created
199 * redraw() get's called. So what? 199 * redraw() get's called. So what?
200 * Remember that we're still in the c'tor 200 * Remember that we're still in the c'tor
201 * and no final layout has happened? Ok 201 * and no final layout has happened? Ok
202 * now all Events get arranged. Their x 202 * now all Events get arranged. Their x
203 * position get's determined by a QHeader 203 * position get's determined by a QHeader
204 * position. But the QHeader isn't layouted or 204 * position. But the QHeader isn't layouted or
205 * at the right position. redraw() is a slot 205 * at the right position. redraw() is a slot
206 * so we'll call it then via a singleShot 206 * so we'll call it then via a singleShot
207 * from view() 207 * from view()
208 */ 208 */
209 if( needEvilHack ){ 209 if( needEvilHack ){
210 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 210 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
211 } 211 }
212} 212}
213 213
214void DateBook::receive( const QCString &msg, const QByteArray &data ) 214void DateBook::receive( const QCString &msg, const QByteArray &data )
215{ 215{
216 QDataStream stream( data, IO_ReadOnly ); 216 QDataStream stream( data, IO_ReadOnly );
217 if ( msg == "timeChange(QString)" ) { 217 if ( msg == "timeChange(QString)" ) {
218 // update active view! 218 // update active view!
219 if ( dayAction->isOn() ) 219 if ( dayAction->isOn() )
220 viewDay(); 220 viewDay();
221 else if ( weekAction->isOn() ) 221 else if ( weekAction->isOn() )
222 viewWeek(); 222 viewWeek();
223 else if ( monthAction->isOn() ) 223 else if ( monthAction->isOn() )
224 viewMonth(); 224 viewMonth();
225 } 225 }
226 else if (msg == "editEvent(int)") { 226 else if (msg == "editEvent(int)") {
227 int uid; 227 int uid;
228 stream >> uid; 228 stream >> uid;
229 Event e=db->eventByUID(uid); 229 Event e=db->eventByUID(uid);
230 editEvent(e); 230 editEvent(e);
231 } 231 }else if (msg == "viewDefault(QDate)"){
232 QDate day;
233 stream >> day;
234 viewDefault(day);
235 }
232} 236}
233 237
234DateBook::~DateBook() 238DateBook::~DateBook()
235{ 239{
236} 240}
237 241
238void DateBook::slotSettings() 242void DateBook::slotSettings()
239{ 243{
240 DateBookSettings frmSettings( ampm, this ); 244 DateBookSettings frmSettings( ampm, this );
241 frmSettings.setStartTime( startTime ); 245 frmSettings.setStartTime( startTime );
242 frmSettings.setAlarmPreset( aPreset, presetTime ); 246 frmSettings.setAlarmPreset( aPreset, presetTime );
243 frmSettings.setJumpToCurTime( bJumpToCurTime ); 247 frmSettings.setJumpToCurTime( bJumpToCurTime );
244 frmSettings.setRowStyle( rowStyle ); 248 frmSettings.setRowStyle( rowStyle );
245 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 249 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
246 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 250 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
247 251
248 bool found=false; 252 bool found=false;
249 for (int i=0; i<(frmSettings.comboLocation->count()); i++) { 253 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
250 if ( frmSettings.comboLocation->text(i) == defaultLocation ) { 254 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
251 frmSettings.comboLocation->setCurrentItem(i); 255 frmSettings.comboLocation->setCurrentItem(i);
252 found=true; 256 found=true;
253 break; 257 break;
254 } 258 }
255 } 259 }
256 if(!found) { 260 if(!found) {
257 frmSettings.comboLocation->insertItem(defaultLocation); 261 frmSettings.comboLocation->insertItem(defaultLocation);
258 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); 262 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1);
259 } 263 }
260 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); 264 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar"));
261 265
262#if defined (Q_WS_QWS) || defined(_WS_QWS_) 266#if defined (Q_WS_QWS) || defined(_WS_QWS_)
263 frmSettings.showMaximized(); 267 frmSettings.showMaximized();
264#endif 268#endif
265 269
266 if ( frmSettings.exec() ) { 270 if ( frmSettings.exec() ) {
267 271
268 aPreset = frmSettings.alarmPreset(); 272 aPreset = frmSettings.alarmPreset();
269 presetTime = frmSettings.presetTime(); 273 presetTime = frmSettings.presetTime();
270 startTime = frmSettings.startTime(); 274 startTime = frmSettings.startTime();
271 bJumpToCurTime = frmSettings.jumpToCurTime(); 275 bJumpToCurTime = frmSettings.jumpToCurTime();
272 rowStyle = frmSettings.rowStyle(); 276 rowStyle = frmSettings.rowStyle();
273 defaultView=frmSettings.comboDefaultView->currentItem()+1; 277 defaultView=frmSettings.comboDefaultView->currentItem()+1;
274 weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); 278 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
275 defaultLocation=frmSettings.comboLocation->currentText(); 279 defaultLocation=frmSettings.comboLocation->currentText();
276 defaultCategories=frmSettings.comboCategory->currentCategories(); 280 defaultCategories=frmSettings.comboCategory->currentCategories();
277 281
278 if ( dayView ) { 282 if ( dayView ) {
279 dayView->setStartViewTime( startTime ); 283 dayView->setStartViewTime( startTime );
280 dayView->setJumpToCurTime( bJumpToCurTime ); 284 dayView->setJumpToCurTime( bJumpToCurTime );
281 dayView->setRowStyle( rowStyle ); 285 dayView->setRowStyle( rowStyle );
282 } 286 }
283 if ( weekView ) { 287 if ( weekView ) {
284 weekView->setStartViewTime( startTime ); 288 weekView->setStartViewTime( startTime );
285 } 289 }
286 saveSettings(); 290 saveSettings();
287 291
288 // make the change obvious 292 // make the change obvious
289 if ( views->visibleWidget() ) { 293 if ( views->visibleWidget() ) {
290 if ( views->visibleWidget() == dayView ) 294 if ( views->visibleWidget() == dayView )
291 dayView->redraw(); 295 dayView->redraw();
292 else if ( views->visibleWidget() == weekView ) 296 else if ( views->visibleWidget() == weekView )
293 weekView->redraw(); 297 weekView->redraw();
294 else if ( views->visibleWidget() == weekLstView ) 298 else if ( views->visibleWidget() == weekLstView )
295 weekLstView->redraw(); 299 weekLstView->redraw();
296 } 300 }
297 } 301 }
298} 302}
299 303
300void DateBook::fileNew() 304void DateBook::fileNew()
301{ 305{
302 slotNewEventFromKey(""); 306 slotNewEventFromKey("");
303} 307}
304 308
305QString DateBook::checkEvent(const Event &e) 309QString DateBook::checkEvent(const Event &e)
306{ 310{
307 /* check if overlaps with itself */ 311 /* check if overlaps with itself */
308 bool checkFailed = FALSE; 312 bool checkFailed = FALSE;
309 313
310 /* check the next 12 repeats. should catch most problems */ 314 /* check the next 12 repeats. should catch most problems */
311 QDate current_date = e.start().date(); 315 QDate current_date = e.start().date();
312 Event previous = e; 316 Event previous = e;
313 for(int i = 0; i < 12; i++) 317 for(int i = 0; i < 12; i++)
314 { 318 {
315 QDateTime next; 319 QDateTime next;
316 if (!nextOccurance(previous, current_date.addDays(1), next)) { 320 if (!nextOccurance(previous, current_date.addDays(1), next)) {
317 break; // no more repeats 321 break; // no more repeats
318 } 322 }
319 if(next < previous.end()) { 323 if(next < previous.end()) {
320 checkFailed = TRUE; 324 checkFailed = TRUE;
321 break; 325 break;
322 } 326 }
323 current_date = next.date(); 327 current_date = next.date();
324 } 328 }
325 329
326 if(checkFailed) 330 if(checkFailed)
327 return tr("Event duration is potentially longer\n" 331 return tr("Event duration is potentially longer\n"
328 "than interval between repeats."); 332 "than interval between repeats.");
329 333
330 return QString::null; 334 return QString::null;
331} 335}
332 336
333QDate DateBook::currentDate() 337QDate DateBook::currentDate()
334{ 338{
335 QDate d = QDate::currentDate(); 339 QDate d = QDate::currentDate();
336 340
337 if ( dayView && views->visibleWidget() == dayView ) { 341 if ( dayView && views->visibleWidget() == dayView ) {
338 d = dayView->date(); 342 d = dayView->date();
339 } else if ( weekView && views->visibleWidget() == weekView ) { 343 } else if ( weekView && views->visibleWidget() == weekView ) {
340 d = weekView->date(); 344 d = weekView->date();
341 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 345 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
342 d = weekLstView->date(); 346 d = weekLstView->date();
343 } else if ( monthView && views->visibleWidget() == monthView ) { 347 } else if ( monthView && views->visibleWidget() == monthView ) {
344 d = monthView->selectedDate(); 348 d = monthView->selectedDate();
345 } 349 }
346 350
347 return d; 351 return d;
348} 352}
349 353
350void DateBook::view(int v, const QDate &d) { 354void DateBook::view(int v, const QDate &d) {
351 if (v==DAY) { 355 if (v==DAY) {
352 initDay(); 356 initDay();
353 dayAction->setOn( TRUE ); 357 dayAction->setOn( TRUE );
354 dayView->setDate( d ); 358 dayView->setDate( d );
355 views->raiseWidget( dayView ); 359 views->raiseWidget( dayView );
356 dayView->redraw(); 360 dayView->redraw();
357 } else if (v==WEEK) { 361 } else if (v==WEEK) {
358 initWeek(); 362 initWeek();
359 weekAction->setOn( TRUE ); 363 weekAction->setOn( TRUE );
360 weekView->setDate( d ); 364 weekView->setDate( d );
361 views->raiseWidget( weekView ); 365 views->raiseWidget( weekView );
362 weekView->redraw(); 366 weekView->redraw();
363 } else if (v==WEEKLST) { 367 } else if (v==WEEKLST) {
364 initWeekLst(); 368 initWeekLst();
365 weekLstAction->setOn( TRUE ); 369 weekLstAction->setOn( TRUE );
366 weekLstView->setDate(d); 370 weekLstView->setDate(d);
367 views->raiseWidget( weekLstView ); 371 views->raiseWidget( weekLstView );
368 weekLstView->redraw(); 372 weekLstView->redraw();
369 } else if (v==MONTH) { 373 } else if (v==MONTH) {
370 initMonth(); 374 initMonth();
371 monthAction->setOn( TRUE ); 375 monthAction->setOn( TRUE );
372 monthView->setDate( d.year(), d.month(), d.day() ); 376 monthView->setDate( d.year(), d.month(), d.day() );
373 views->raiseWidget( monthView ); 377 views->raiseWidget( monthView );
374 monthView->redraw(); 378 monthView->redraw();
375 } 379 }
376} 380}
377 381
378void DateBook::viewDefault(const QDate &d) { 382void DateBook::viewDefault(const QDate &d) {
379 view(defaultView,d); 383 view(defaultView,d);
380} 384}
381 385
382void DateBook::viewDay() { 386void DateBook::viewDay() {
383 view(DAY,currentDate()); 387 view(DAY,currentDate());
384} 388}
385 389
386void DateBook::viewWeek() { 390void DateBook::viewWeek() {
387 view(WEEK,currentDate()); 391 view(WEEK,currentDate());
388} 392}
389 393
390void DateBook::viewWeekLst() { 394void DateBook::viewWeekLst() {
391 view(WEEKLST,currentDate()); 395 view(WEEKLST,currentDate());
392} 396}
393 397
394void DateBook::viewMonth() { 398void DateBook::viewMonth() {
395 view(MONTH,currentDate()); 399 view(MONTH,currentDate());
396} 400}
397 401
398void DateBook::insertEvent( const Event &e ) 402void DateBook::insertEvent( const Event &e )
399{ 403{
400 Event dupEvent=e; 404 Event dupEvent=e;
401 dupEvent.setLocation(defaultLocation); 405 dupEvent.setLocation(defaultLocation);
402 dupEvent.setCategories(defaultCategories); 406 dupEvent.setCategories(defaultCategories);
403 db->addEvent(dupEvent); 407 db->addEvent(dupEvent);
404 emit newEvent(); 408 emit newEvent();
405} 409}
406 410
407void DateBook::duplicateEvent( const Event &e ) 411void DateBook::duplicateEvent( const Event &e )
408{ 412{
409 qWarning("Hmmm..."); 413 qWarning("Hmmm...");
410 // Alot of code duplication, as this is almost like editEvent(); 414 // Alot of code duplication, as this is almost like editEvent();
411 if (syncing) { 415 if (syncing) {
412 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 416 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
413 return; 417 return;
414 } 418 }
415 419
416 Event dupevent(e);// Make a duplicate. 420 Event dupevent(e);// Make a duplicate.
417 421
418 // workaround added for text input. 422 // workaround added for text input.
419 QDialog editDlg( this, 0, TRUE ); 423 QDialog editDlg( this, 0, TRUE );
420 DateEntry *entry; 424 DateEntry *entry;
421 editDlg.setCaption( tr("Duplicate Event") ); 425 editDlg.setCaption( tr("Duplicate Event") );
422 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 426 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
423 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 427 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
424 sv->setResizePolicy( QScrollView::AutoOneFit ); 428 sv->setResizePolicy( QScrollView::AutoOneFit );
425 // KLUDGE!!! 429 // KLUDGE!!!
426 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 430 sv->setHScrollBarMode( QScrollView::AlwaysOff );
427 vb->addWidget( sv ); 431 vb->addWidget( sv );
428 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 432 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
429 entry->timezone->setEnabled( FALSE ); 433 entry->timezone->setEnabled( FALSE );
430 sv->addChild( entry ); 434 sv->addChild( entry );
431 435
432#if defined(Q_WS_QWS) || defined(_WS_QWS_) 436#if defined(Q_WS_QWS) || defined(_WS_QWS_)
433 editDlg.showMaximized(); 437 editDlg.showMaximized();
434#endif 438#endif
435 while (editDlg.exec() ) { 439 while (editDlg.exec() ) {
436 Event newEv = entry->event(); 440 Event newEv = entry->event();
437 QString error = checkEvent(newEv); 441 QString error = checkEvent(newEv);
438 if (!error.isNull()) { 442 if (!error.isNull()) {
439 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) 443 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0)
440 continue; 444 continue;
441 } 445 }
446 /*
447 * The problem:
448 * DateBookDB does remove repeating events not by uid but by the time
449 * the recurrence was created
450 * so we need to update that time as well
451 */
452 Event::RepeatPattern rp = newEv.repeatPattern();
453 rp.createTime = ::time( NULL );
454 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern...
455
442 db->addEvent(newEv); 456 db->addEvent(newEv);
443 emit newEvent(); 457 emit newEvent();
444 break; 458 break;
445 } 459 }
446} 460}
447 461
448void DateBook::editEvent( const Event &e ) 462void DateBook::editEvent( const Event &e )
449{ 463{
450 if (syncing) { 464 if (syncing) {
451 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 465 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
452 return; 466 return;
453 } 467 }
454 468
455 // workaround added for text input. 469 // workaround added for text input.
456 QDialog editDlg( this, 0, TRUE ); 470 QDialog editDlg( this, 0, TRUE );
457 DateEntry *entry; 471 DateEntry *entry;
458 editDlg.setCaption( tr("Edit Event") ); 472 editDlg.setCaption( tr("Edit Event") );
459 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 473 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
460 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 474 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
461 sv->setResizePolicy( QScrollView::AutoOneFit ); 475 sv->setResizePolicy( QScrollView::AutoOneFit );
462 // KLUDGE!!! 476 // KLUDGE!!!
463 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 477 sv->setHScrollBarMode( QScrollView::AlwaysOff );
464 vb->addWidget( sv ); 478 vb->addWidget( sv );
465 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 479 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
466 entry->timezone->setEnabled( FALSE ); 480 entry->timezone->setEnabled( FALSE );
467 sv->addChild( entry ); 481 sv->addChild( entry );
468 482
469#if defined(Q_WS_QWS) || defined(_WS_QWS_) 483#if defined(Q_WS_QWS) || defined(_WS_QWS_)
470 editDlg.showMaximized(); 484 editDlg.showMaximized();
471#endif 485#endif
472 while (editDlg.exec() ) { 486 while (editDlg.exec() ) {
473 Event newEv = entry->event(); 487 Event newEv = entry->event();
474 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 488 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
475 break; 489 break;
476 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 490 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
477 QString error = checkEvent(newEv); 491 QString error = checkEvent(newEv);
478 if (!error.isNull()) { 492 if (!error.isNull()) {
479 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; 493 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
480 } 494 }
481 db->editEvent(e, newEv); 495 db->editEvent(e, newEv);
482 emit newEvent(); 496 emit newEvent();
483 break; 497 break;
484 } 498 }
485} 499}
486 500
487void DateBook::removeEvent( const Event &e ) 501void DateBook::removeEvent( const Event &e )
488{ 502{
489 if (syncing) { 503 if (syncing) {
490 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 504 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
491 return; 505 return;
492 } 506 }
493 507
494 QString strName = e.description(); 508 QString strName = e.description();
495 509
496 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 510 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
497 return; 511 return;
498 512
499 db->removeEvent( e ); 513 db->removeEvent( e );
500 if ( views->visibleWidget() == dayView && dayView ) 514 if ( views->visibleWidget() == dayView && dayView )
501 dayView->redraw(); 515 dayView->redraw();
502} 516}
503 517
504void DateBook::addEvent( const Event &e ) 518void DateBook::addEvent( const Event &e )
505{ 519{
506 QDate d = e.start().date(); 520 QDate d = e.start().date();
507 initDay(); 521 initDay();
508 dayView->setDate( d ); 522 dayView->setDate( d );
509} 523}
510 524
511void DateBook::showDay( int year, int month, int day ) 525void DateBook::showDay( int year, int month, int day )
512{ 526{
513 QDate d(year, month, day); 527 QDate d(year, month, day);
514 view(DAY,d); 528 view(DAY,d);
515} 529}
516 530
517void DateBook::initDay() 531void DateBook::initDay()
518{ 532{
519 if ( !dayView ) { 533 if ( !dayView ) {
520 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 534 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
521 views->addWidget( dayView, DAY ); 535 views->addWidget( dayView, DAY );
536 dayView->setJumpToCurTime( bJumpToCurTime );
522 dayView->setStartViewTime( startTime ); 537 dayView->setStartViewTime( startTime );
523 dayView->setJumpToCurTime( bJumpToCurTime );
524 dayView->setRowStyle( rowStyle ); 538 dayView->setRowStyle( rowStyle );
525 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 539 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
526 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); 540 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) );
527 connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); 541 connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) );
528 connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); 542 connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) );
529 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); 543 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) );
530 connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); 544 connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) );
531 connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); 545 connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) );
532 } 546 }
533} 547}
534 548
535void DateBook::initWeek() 549void DateBook::initWeek()
536{ 550{
537 if ( !weekView ) { 551 if ( !weekView ) {
538 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 552 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
539 weekView->setStartViewTime( startTime ); 553 weekView->setStartViewTime( startTime );
540 views->addWidget( weekView, WEEK ); 554 views->addWidget( weekView, WEEK );
541 connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); 555 connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) );
542 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); 556 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) );
543 } 557 }
544 558
545 //But also get it right: the year that we display can be different 559 //But also get it right: the year that we display can be different
546 //from the year of the current date. So, first find the year 560 //from the year of the current date. So, first find the year
547 //number of the current week. 561 //number of the current week.
548 int yearNumber, totWeeks; 562 int yearNumber, totWeeks;
549 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 563 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
550 564
551 QDate d = QDate( yearNumber, 12, 31 ); 565 QDate d = QDate( yearNumber, 12, 31 );
552 calcWeek( d, totWeeks, yearNumber, onMonday ); 566 calcWeek( d, totWeeks, yearNumber, onMonday );
553 567
554 while ( totWeeks == 1 ) { 568 while ( totWeeks == 1 ) {
555 d = d.addDays( -1 ); 569 d = d.addDays( -1 );
556 calcWeek( d, totWeeks, yearNumber, onMonday ); 570 calcWeek( d, totWeeks, yearNumber, onMonday );
557 } 571 }
558} 572}
559 573
560void DateBook::initWeekLst() { 574void DateBook::initWeekLst() {
561 if ( !weekLstView ) { 575 if ( !weekLstView ) {
562 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); 576 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" );
563 views->addWidget( weekLstView, WEEKLST ); 577 views->addWidget( weekLstView, WEEKLST );
564 578
565 //weekLstView->setStartViewTime( startTime ); 579 //weekLstView->setStartViewTime( startTime );
566 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); 580 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) );
567 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), 581 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ),
568 this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); 582 this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) );
569 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); 583 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) );
570 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); 584 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) );
571 } 585 }
572} 586}
573 587
574 588
575void DateBook::initMonth() 589void DateBook::initMonth()
576{ 590{
577 if ( !monthView ) { 591 if ( !monthView ) {
578 monthView = new DateBookMonth( views, "month view", FALSE, db ); 592 monthView = new DateBookMonth( views, "month view", FALSE, db );
579 views->addWidget( monthView, MONTH ); 593 views->addWidget( monthView, MONTH );
580 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); 594 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) );
581 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); 595 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) );
582 qApp->processEvents(); 596 qApp->processEvents();
583 } 597 }
584} 598}
585 599
586void DateBook::loadSettings() 600void DateBook::loadSettings()
587{ 601{
588 Config qpeconfig( "qpe" ); 602 Config qpeconfig( "qpe" );
589 qpeconfig.setGroup("Time"); 603 qpeconfig.setGroup("Time");
590 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); 604 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
591 onMonday = qpeconfig.readBoolEntry( "MONDAY" ); 605 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
592 606
593 Config config("DateBook"); 607 Config config("DateBook");
594 config.setGroup("Main"); 608 config.setGroup("Main");
595 startTime = config.readNumEntry("startviewtime", 8); 609 startTime = config.readNumEntry("startviewtime", 8);
596 aPreset = config.readBoolEntry("alarmpreset"); 610 aPreset = config.readBoolEntry("alarmpreset");
597 presetTime = config.readNumEntry("presettime"); 611 presetTime = config.readNumEntry("presettime");
598 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 612 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
599 rowStyle = config.readNumEntry("rowstyle"); 613 rowStyle = config.readNumEntry("rowstyle");
600 defaultView = config.readNumEntry("defaultview",DAY); 614 defaultView = config.readNumEntry("defaultview",DAY);
601 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); 615 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
602 616
603 defaultLocation=config.readEntry("defaultLocation"); 617 defaultLocation=config.readEntry("defaultLocation");
604 QString tmpString=config.readEntry("defaultCategories"); 618 QString tmpString=config.readEntry("defaultCategories");
605 QStringList tmpStringList=QStringList::split(",",tmpString); 619 QStringList tmpStringList=QStringList::split(",",tmpString);
606 defaultCategories.truncate(0); 620 defaultCategories.truncate(0);
607 621
608 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { 622 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) {
609 defaultCategories.resize(defaultCategories.count()+1); 623 defaultCategories.resize(defaultCategories.count()+1);
610 defaultCategories[defaultCategories.count()-1]=(*i).toInt(); 624 defaultCategories[defaultCategories.count()-1]=(*i).toInt();
611 } 625 }
612} 626}
613 627
614void DateBook::saveSettings() 628void DateBook::saveSettings()
615{ 629{
616 Config config( "qpe" ); 630 Config config( "qpe" );
617 Config configDB( "DateBook" ); 631 Config configDB( "DateBook" );
618 configDB.setGroup( "Main" ); 632 configDB.setGroup( "Main" );
619 configDB.writeEntry("startviewtime",startTime); 633 configDB.writeEntry("startviewtime",startTime);
620 configDB.writeEntry("alarmpreset",aPreset); 634 configDB.writeEntry("alarmpreset",aPreset);
621 configDB.writeEntry("presettime",presetTime); 635 configDB.writeEntry("presettime",presetTime);
622 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 636 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
623 configDB.writeEntry("rowstyle", rowStyle); 637 configDB.writeEntry("rowstyle", rowStyle);
624 configDB.writeEntry("defaultview",defaultView); 638 configDB.writeEntry("defaultview",defaultView);
625 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); 639 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
626 640
627 configDB.writeEntry("defaultLocation",defaultLocation); 641 configDB.writeEntry("defaultLocation",defaultLocation);
628 QStringList tmpStringList; 642 QStringList tmpStringList;
629 for( uint i=0; i<defaultCategories.count(); i++) { 643 for( uint i=0; i<defaultCategories.count(); i++) {
630 tmpStringList << QString::number(defaultCategories[i]); 644 tmpStringList << QString::number(defaultCategories[i]);
631 } 645 }
632 configDB.writeEntry("defaultCategories",tmpStringList.join(",")); 646 configDB.writeEntry("defaultCategories",tmpStringList.join(","));
633} 647}
634 648
635void DateBook::appMessage(const QCString& msg, const QByteArray& data) 649void DateBook::appMessage(const QCString& msg, const QByteArray& data)
636{ 650{
637 bool needShow = FALSE; 651 bool needShow = FALSE;
638 if ( msg == "alarm(QDateTime,int)" ) { 652 if ( msg == "alarm(QDateTime,int)" ) {
639 QDataStream ds(data,IO_ReadOnly); 653 QDataStream ds(data,IO_ReadOnly);
640 QDateTime when; int warn; 654 QDateTime when; int warn;
641 ds >> when >> warn; 655 ds >> when >> warn;
642 656
643 // check to make it's okay to continue, 657 // check to make it's okay to continue,
644 // this is the case that the time was set ahead, and 658 // this is the case that the time was set ahead, and
645 // we are forced given a stale alarm... 659 // we are forced given a stale alarm...
646 QDateTime current = QDateTime::currentDateTime(); 660 QDateTime current = QDateTime::currentDateTime();
647 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) 661 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
648 return; 662 return;
649 663
650 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 664 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
651 if ( list.count() > 0 ) { 665 if ( list.count() > 0 ) {
652 QString msg; 666 QString msg;
653 bool bSound = FALSE; 667 bool bSound = FALSE;
654 int stopTimer = 0; 668 int stopTimer = 0;
655 bool found = FALSE; 669 bool found = FALSE;
656 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { 670 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
657 if ( (*it).event().hasAlarm() ) { 671 if ( (*it).event().hasAlarm() ) {
658 found = TRUE; 672 found = TRUE;
659 msg += "<CENTER><B>" + (*it).description() + "</B>" 673 msg += "<CENTER><B>" + (*it).description() + "</B>"
660 + "<BR>" + (*it).location() + "<BR>" 674 + "<BR>" + (*it).location() + "<BR>"
661 + TimeString::dateString((*it).event().start(),ampm) 675 + TimeString::dateString((*it).event().start(),ampm)
662 + (warn 676 + (warn
663 ? tr(" (in " + QString::number(warn) 677 ? tr(" (in " + QString::number(warn)
664 + tr(" minutes)")) 678 + tr(" minutes)"))
665 : QString("")) 679 : QString(""))
666 + "<BR>" 680 + "<BR>"
667 + (*it).notes() + "</CENTER>"; 681 + (*it).notes() + "</CENTER>";
668 if ( (*it).event().alarmSound() != Event::Silent ) { 682 if ( (*it).event().alarmSound() != Event::Silent ) {
669 bSound = TRUE; 683 bSound = TRUE;
670 } 684 }
671 } 685 }
672 } 686 }
673 if ( found ) { 687 if ( found ) {
674 if ( bSound ) { 688 if ( bSound ) {
675 Sound::soundAlarm(); 689 Sound::soundAlarm();
676 alarmCounter = 0; 690 alarmCounter = 0;
677 stopTimer = startTimer( 5000 ); 691 stopTimer = startTimer( 5000 );
678 } 692 }
679 QDialog dlg( this, 0, TRUE ); 693 QDialog dlg( this, 0, TRUE );
680 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 694 QVBoxLayout *vb = new QVBoxLayout( &dlg );
681 QScrollView *view = new QScrollView( &dlg, "scrollView"); 695 QScrollView *view = new QScrollView( &dlg, "scrollView");
682 view->setResizePolicy( QScrollView::AutoOneFit ); 696 view->setResizePolicy( QScrollView::AutoOneFit );
683 vb->addWidget( view ); 697 vb->addWidget( view );
684 QLabel *lblMsg = new QLabel( msg, &dlg ); 698 QLabel *lblMsg = new QLabel( msg, &dlg );
685 view->addChild( lblMsg ); 699 view->addChild( lblMsg );
686 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 700 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
687 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 701 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
688 vb->addWidget( cmdOk ); 702 vb->addWidget( cmdOk );
689 703
690#if defined(Q_WS_QWS) || defined(_WS_QWS_) 704#if defined(Q_WS_QWS) || defined(_WS_QWS_)
691 dlg.showMaximized(); 705 dlg.showMaximized();
692#endif 706#endif
693 needShow = dlg.exec(); 707 needShow = dlg.exec();
694 708
695 if ( bSound ) 709 if ( bSound )
696 killTimer( stopTimer ); 710 killTimer( stopTimer );
697 } 711 }
698 } 712 }
699 } else if ( msg == "nextView()" ) { 713 } else if ( msg == "nextView()" ) {
714 needShow = true;
700 if ( !qApp-> activeWindow ( )) { 715 if ( !qApp-> activeWindow ( )) {
701 needShow = TRUE; 716 needShow = TRUE;
702 } else { 717 } else {
703 QWidget* cur = views->visibleWidget(); 718 QWidget* cur = views->visibleWidget();
704 if ( cur ) { 719 if ( cur ) {
705 if ( cur == dayView ) 720 if ( cur == dayView )
706 viewWeek(); 721 viewWeek();
707 else if ( cur == weekView ) 722 else if ( cur == weekView )
708 viewWeekLst(); 723 viewWeekLst();
709 else if ( cur == weekLstView ) 724 else if ( cur == weekLstView )
710 viewMonth(); 725 viewMonth();
711 else if ( cur == monthView ) 726 else if ( cur == monthView )
712 viewDay(); 727 viewDay();
713 needShow = TRUE; 728 needShow = TRUE;
714 } 729 }
715 } 730 }
716 } 731 } else if (msg == "editEvent(int)") {
732 /* simple copy from receive */
733 QDataStream stream(data,IO_ReadOnly);
734 int uid;
735 stream >> uid;
736 Event e=db->eventByUID(uid);
737 editEvent(e);
738 } else if (msg == "viewDefault(QDate)"){
739 /* simple copy from receive */
740 QDataStream stream(data,IO_ReadOnly);
741 QDate day;
742 stream >> day;
743 viewDefault(day);
744 needShow = true;
745 }
746
717 if ( needShow ) { 747 if ( needShow ) {
718#if defined(Q_WS_QWS) || defined(_WS_QWS_) 748#if defined(Q_WS_QWS) || defined(_WS_QWS_)
719 showMaximized(); 749 // showMaximized();
720#else 750#else
721 show(); 751 // show();
722#endif 752#endif
723 raise(); 753 // raise();
724 QPEApplication::setKeepRunning(); 754 QPEApplication::setKeepRunning();
725 setActiveWindow(); 755 // setActiveWindow();
726 } 756 }
727} 757}
728 758
729void DateBook::reload() 759void DateBook::reload()
730{ 760{
731 db->reload(); 761 db->reload();
732 if ( dayAction->isOn() ) viewDay(); 762 if ( dayAction->isOn() ) viewDay();
733 else if ( weekAction->isOn() ) viewWeek(); 763 else if ( weekAction->isOn() ) viewWeek();
734 else if ( monthAction->isOn() ) viewMonth(); 764 else if ( monthAction->isOn() ) viewMonth();
735 syncing = FALSE; 765 syncing = FALSE;
736} 766}
737 767
738void DateBook::flush() 768void DateBook::flush()
739{ 769{
740 syncing = TRUE; 770 syncing = TRUE;
741 db->save(); 771 db->save();
742} 772}
743 773
744void DateBook::timerEvent( QTimerEvent *e ) 774void DateBook::timerEvent( QTimerEvent *e )
745{ 775{
746 if ( alarmCounter < 10 ) { 776 if ( alarmCounter < 10 ) {
747 alarmCounter++; 777 alarmCounter++;
748 Sound::soundAlarm(); 778 Sound::soundAlarm();
749 } else { 779 } else {
750 killTimer( e->timerId() ); 780 killTimer( e->timerId() );
751 } 781 }
752} 782}
753 783
754void DateBook::changeClock( bool newClock ) 784void DateBook::changeClock( bool newClock )
755{ 785{
756 ampm = newClock; 786 ampm = newClock;
757 // repaint the affected objects... 787 // repaint the affected objects...
758 if (dayView) dayView->redraw(); 788 if (dayView) dayView->redraw();
759 if (weekView) weekView->redraw(); 789 if (weekView) weekView->redraw();
760 if (weekLstView) weekLstView->redraw(); 790 if (weekLstView) weekLstView->redraw();
761} 791}
762 792
763void DateBook::changeWeek( bool m ) 793void DateBook::changeWeek( bool m )
764{ 794{
765 /* no need to redraw, each widget catches. Do need to 795 /* no need to redraw, each widget catches. Do need to
766 store though for widgets we haven't made yet */ 796 store though for widgets we haven't made yet */
767 onMonday = m; 797 onMonday = m;
768} 798}
769 799
770void DateBook::slotToday() 800void DateBook::slotToday()
771{ 801{
772 // we need to view today using default view 802 // we need to view today using default view
773 view(defaultView,QDate::currentDate()); 803 view(defaultView,QDate::currentDate());
774} 804}
775 805
776void DateBook::closeEvent( QCloseEvent *e ) 806void DateBook::closeEvent( QCloseEvent *e )
777{ 807{
778 if(syncing) { 808 if(syncing) {
779 /* no need to save, did that at flush */ 809 /* no need to save, did that at flush */
780 e->accept(); 810 e->accept();
781 return; 811 return;
782 } 812 }
783 813
784 // save settings will generate it's own error messages, no 814 // save settings will generate it's own error messages, no
785 // need to do checking ourselves. 815 // need to do checking ourselves.
786 saveSettings(); 816 saveSettings();
787 if ( db->save() ) { 817 if ( db->save() ) {
788 e->accept(); 818 e->accept();
789 } else { 819 } else {
790 if ( QMessageBox::critical( this, tr( "Out of space" ), 820 if ( QMessageBox::critical( this, tr( "Out of space" ),
791 tr("Calendar was unable to save\n" 821 tr("Calendar was unable to save\n"
792 "your changes.\n" 822 "your changes.\n"
793 "Free up some space and try again.\n" 823 "Free up some space and try again.\n"
794 "\nQuit anyway?"), 824 "\nQuit anyway?"),
795 QMessageBox::Yes|QMessageBox::Escape, 825 QMessageBox::Yes|QMessageBox::Escape,
796 QMessageBox::No|QMessageBox::Default ) 826 QMessageBox::No|QMessageBox::Default )
797 != QMessageBox::No ) 827 != QMessageBox::No )
798 e->accept(); 828 e->accept();
799 else 829 else
800 e->ignore(); 830 e->ignore();
801 } 831 }
802} 832}
803 833
804// Entering directly from the "keyboard" 834// Entering directly from the "keyboard"
805void DateBook::slotNewEventFromKey( const QString &str ) 835void DateBook::slotNewEventFromKey( const QString &str )
806{ 836{
807 if (syncing) { 837 if (syncing) {
808 QMessageBox::warning( this, tr("Calendar"), 838 QMessageBox::warning( this, tr("Calendar"),
809 tr( "Can not edit data, currently syncing") ); 839 tr( "Can not edit data, currently syncing") );
810 return; 840 return;
811 } 841 }
812 842
813 // We get to here from a key pressed in the Day View 843 // We get to here from a key pressed in the Day View
814 // So we can assume some things. We want the string 844 // So we can assume some things. We want the string
815 // passed in to be part of the description. 845 // passed in to be part of the description.
816 QDateTime start, end; 846 QDateTime start, end;
817 if ( views->visibleWidget() == dayView ) { 847 if ( views->visibleWidget() == dayView ) {
818 dayView->selectedDates( start, end ); 848 dayView->selectedDates( start, end );
819 } else if ( views->visibleWidget() == monthView ) { 849 } else if ( views->visibleWidget() == monthView ) {
820 QDate d = monthView->selectedDate(); 850 QDate d = monthView->selectedDate();
821 start = end = d; 851 start = end = d;
822 start.setTime( QTime( 10, 0 ) ); 852 start.setTime( QTime( 10, 0 ) );
823 end.setTime( QTime( 12, 0 ) ); 853 end.setTime( QTime( 12, 0 ) );
824 } else if ( views->visibleWidget() == weekView ) { 854 } else if ( views->visibleWidget() == weekView ) {
825 QDate d = weekView->date(); 855 QDate d = weekView->date();
826 start = end = d; 856 start = end = d;
827 start.setTime( QTime( 10, 0 ) ); 857 start.setTime( QTime( 10, 0 ) );
828 end.setTime( QTime( 12, 0 ) ); 858 end.setTime( QTime( 12, 0 ) );
829 } else if ( views->visibleWidget() == weekLstView ) { 859 } else if ( views->visibleWidget() == weekLstView ) {
830 QDate d = weekLstView->date(); 860 QDate d = weekLstView->date();
831 start = end = d; 861 start = end = d;
832 start.setTime( QTime( 10, 0 ) ); 862 start.setTime( QTime( 10, 0 ) );
833 end.setTime( QTime( 12, 0 ) ); 863 end.setTime( QTime( 12, 0 ) );
834 } 864 }
835 slotNewEntry(start, end, str); 865 slotNewEntry(start, end, str);
836} 866}
837void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 867void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
838 // argh! This really needs to be encapsulated in a class 868 // argh! This really needs to be encapsulated in a class
839 // or function. 869 // or function.
840 QDialog newDlg( this, 0, TRUE ); 870 QDialog newDlg( this, 0, TRUE );
841 newDlg.setCaption( DateEntryBase::tr("New Event") ); 871 newDlg.setCaption( DateEntryBase::tr("New Event") );
842 DateEntry *e; 872 DateEntry *e;
843 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 873 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
844 QScrollView *sv = new QScrollView( &newDlg ); 874 QScrollView *sv = new QScrollView( &newDlg );
845 sv->setResizePolicy( QScrollView::AutoOneFit ); 875 sv->setResizePolicy( QScrollView::AutoOneFit );
846 sv->setFrameStyle( QFrame::NoFrame ); 876 sv->setFrameStyle( QFrame::NoFrame );
847 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 877 sv->setHScrollBarMode( QScrollView::AlwaysOff );
848 vb->addWidget( sv ); 878 vb->addWidget( sv );
849 879
850 Event ev; 880 Event ev;
851 ev.setDescription( str ); 881 ev.setDescription( str );
852 // When the new gui comes in, change this... 882 // When the new gui comes in, change this...
853 if(location==0) { 883 if(location==0) {
854 if(defaultLocation.isEmpty()) { 884 if(defaultLocation.isEmpty()) {
855 ev.setLocation(tr("(Unknown)")); 885 ev.setLocation(tr("(Unknown)"));
856 } else { 886 } else {
857 ev.setLocation( defaultLocation ); 887 ev.setLocation( defaultLocation );
858 } 888 }
859 } else { 889 } else {
860 ev.setLocation(location); 890 ev.setLocation(location);
861 } 891 }
862 ev.setCategories(defaultCategories); 892 ev.setCategories(defaultCategories);
863 ev.setStart( start ); 893 ev.setStart( start );
864 ev.setEnd( end ); 894 ev.setEnd( end );
865 895
866 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 896 e = new DateEntry( onMonday, ev, ampm, &newDlg );
867 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 897 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
868 sv->addChild( e ); 898 sv->addChild( e );
869#if defined(Q_WS_QWS) || defined(_WS_QWS_) 899#if defined(Q_WS_QWS) || defined(_WS_QWS_)
870 newDlg.showMaximized(); 900 newDlg.showMaximized();
871#endif 901#endif
872 while (newDlg.exec()) { 902 while (newDlg.exec()) {
873 ev = e->event(); 903 ev = e->event();
874 ev.assignUid(); 904 ev.assignUid();
875 QString error = checkEvent( ev ); 905 QString error = checkEvent( ev );
876 if ( !error.isNull() ) { 906 if ( !error.isNull() ) {
877 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 907 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
878 continue; 908 continue;
879 } 909 }
880 db->addEvent( ev ); 910 db->addEvent( ev );
881 emit newEvent(); 911 emit newEvent();
882 break; 912 break;
883 } 913 }
884} 914}
885 915
886void DateBook::setDocument( const QString &filename ) 916void DateBook::setDocument( const QString &filename )
887{ 917{
888 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 918 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
889 919
890 QValueList<Event> tl = Event::readVCalendar( filename ); 920 QValueList<Event> tl = Event::readVCalendar( filename );
891 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 921 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
892 db->addEvent( *it ); 922 db->addEvent( *it );
893 } 923 }
894} 924}
895 925
896static const char * beamfile = "/tmp/obex/event.vcs"; 926static const char * beamfile = "/tmp/obex/event.vcs";
897 927
898void DateBook::beamEvent( const Event &e ) 928void DateBook::beamEvent( const Event &e )
899{ 929{
900 qDebug("trying to beamn"); 930 qDebug("trying to beamn");
901 unlink( beamfile ); // delete if exists 931 unlink( beamfile ); // delete if exists
902 mkdir("/tmp/obex/", 0755); 932 mkdir("/tmp/obex/", 0755);
903 Event::writeVCalendar( beamfile, e ); 933 Event::writeVCalendar( beamfile, e );
904 Ir *ir = new Ir( this ); 934 Ir *ir = new Ir( this );
905 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 935 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
906 QString description = e.description(); 936 QString description = e.description();
907 ir->send( beamfile, description, "text/x-vCalendar" ); 937 ir->send( beamfile, description, "text/x-vCalendar" );
908} 938}
909 939
910void DateBook::beamDone( Ir *ir ) 940void DateBook::beamDone( Ir *ir )
911{ 941{
912 delete ir; 942 delete ir;
913 unlink( beamfile ); 943 unlink( beamfile );
914} 944}
915 945
916void DateBook::slotFind() 946void DateBook::slotFind()
917{ 947{
918 // move it to the day view... 948 // move it to the day view...
919 viewDay(); 949 viewDay();
920 FindDialog frmFind( "Calendar", this ); 950 FindDialog frmFind( "Calendar", this ); // no tr needed
921 frmFind.setUseDate( true ); 951 frmFind.setUseDate( true );
922 frmFind.setDate( currentDate() ); 952 frmFind.setDate( currentDate() );
923 QObject::connect( &frmFind, 953 QObject::connect( &frmFind,
924 SIGNAL(signalFindClicked(const QString&, const QDate&, 954 SIGNAL(signalFindClicked(const QString&, const QDate&,
925 bool, bool, int)), 955 bool, bool, int)),
926 this, 956 this,
927 SLOT(slotDoFind(const QString&, const QDate&, 957 SLOT(slotDoFind(const QString&, const QDate&,
928 bool, bool, int)) ); 958 bool, bool, int)) );
929 QObject::connect( this, 959 QObject::connect( this,
930 SIGNAL(signalNotFound()), 960 SIGNAL(signalNotFound()),
931 &frmFind, 961 &frmFind,
932 SLOT(slotNotFound()) ); 962 SLOT(slotNotFound()) );
933 QObject::connect( this, 963 QObject::connect( this,
934 SIGNAL(signalWrapAround()), 964 SIGNAL(signalWrapAround()),
935 &frmFind, 965 &frmFind,
936 SLOT(slotWrapAround()) ); 966 SLOT(slotWrapAround()) );
937 frmFind.move(0,0); 967 frmFind.move(0,0);
938 frmFind.exec(); 968 frmFind.exec();
939 inSearch = false; 969 inSearch = false;
940} 970}
941 971
942bool catComp( QArray<int> cats, int category ) 972bool catComp( QArray<int> cats, int category )
943{ 973{
944 bool returnMe; 974 bool returnMe;
945 int i, 975 int i,
946 count; 976 count;
947 977
948 count = int(cats.count()); 978 count = int(cats.count());
949 returnMe = false; 979 returnMe = false;
950 if ( (category == -1 && count == 0) || category == -2 ) 980 if ( (category == -1 && count == 0) || category == -2 )
951 returnMe = true; 981 returnMe = true;
952 else { 982 else {
953 for ( i = 0; i < count; i++ ) { 983 for ( i = 0; i < count; i++ ) {
954 if ( category == cats[i] ) { 984 if ( category == cats[i] ) {
955 returnMe = true; 985 returnMe = true;
956 break; 986 break;
957 } 987 }
958 } 988 }
959 } 989 }
960 return returnMe; 990 return returnMe;
961} 991}
962 992
963 993
964void DateBook::slotDoFind( const QString& txt, const QDate &dt, 994void DateBook::slotDoFind( const QString& txt, const QDate &dt,
965 bool caseSensitive, bool /*backwards*/, 995 bool caseSensitive, bool /*backwards*/,
966 int category ) 996 int category )
967{ 997{
968 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 998 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
969 next; 999 next;
970 1000
971 QRegExp r( txt ); 1001 QRegExp r( txt );
972 r.setCaseSensitive( caseSensitive ); 1002 r.setCaseSensitive( caseSensitive );
973 1003
974 1004
975 static Event rev, 1005 static Event rev,
976 nonrev; 1006 nonrev;
977 if ( !inSearch ) { 1007 if ( !inSearch ) {
978 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1008 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
979 nonrev.setStart( rev.start() ); 1009 nonrev.setStart( rev.start() );
980 inSearch = true; 1010 inSearch = true;
981 } 1011 }
982 static QDate searchDate = dt; 1012 static QDate searchDate = dt;
983 static bool wrapAround = true; 1013 static bool wrapAround = true;
984 bool candidtate; 1014 bool candidtate;
985 candidtate = false; 1015 candidtate = false;
986 1016
987 QValueList<Event> repeats = db->getRawRepeats(); 1017 QValueList<Event> repeats = db->getRawRepeats();
988 1018
989 // find the candidate for the first repeat that matches... 1019 // find the candidate for the first repeat that matches...
990 QValueListConstIterator<Event> it; 1020 QValueListConstIterator<Event> it;
991 QDate start = dt; 1021 QDate start = dt;
992 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1022 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
993 if ( catComp( (*it).categories(), category ) ) { 1023 if ( catComp( (*it).categories(), category ) ) {
994 while ( nextOccurance( *it, start, next ) ) { 1024 while ( nextOccurance( *it, start, next ) ) {
995 if ( next < dtEnd ) { 1025 if ( next < dtEnd ) {
996 if ( (*it).match( r ) && !(next <= rev.start()) ) { 1026 if ( (*it).match( r ) && !(next <= rev.start()) ) {
997 rev = *it; 1027 rev = *it;
998 dtEnd = next; 1028 dtEnd = next;
999 rev.setStart( next ); 1029 rev.setStart( next );
1000 candidtate = true; 1030 candidtate = true;
1001 wrapAround = true; 1031 wrapAround = true;
1002 start = dt; 1032 start = dt;
1003 break; 1033 break;
1004 } else 1034 } else
1005 start = next.date().addDays( 1 ); 1035 start = next.date().addDays( 1 );
1006 } 1036 }
1007 } 1037 }
1008 } 1038 }
1009 } 1039 }
1010 1040
1011 // now the for first non repeat... 1041 // now the for first non repeat...
1012 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 1042 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
1013 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1043 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1014 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1044 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1015 if ( catComp( (*it).categories(), category ) ) { 1045 if ( catComp( (*it).categories(), category ) ) {
1016 if ( (*it).start() < dtEnd ) { 1046 if ( (*it).start() < dtEnd ) {
1017 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1047 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1018 nonrev = *it; 1048 nonrev = *it;
1019 dtEnd = nonrev.start(); 1049 dtEnd = nonrev.start();
1020 candidtate = true; 1050 candidtate = true;
1021 wrapAround = true; 1051 wrapAround = true;
1022 break; 1052 break;
1023 } 1053 }
1024 } 1054 }
1025 } 1055 }
1026 } 1056 }
1027 if ( candidtate ) { 1057 if ( candidtate ) {
1028 dayView->setStartViewTime( dtEnd.time().hour() ); 1058 dayView->setStartViewTime( dtEnd.time().hour() );
1029 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1059 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1030 dtEnd.date().day() ); 1060 dtEnd.date().day() );
1031 } else { 1061 } else {
1032 if ( wrapAround ) { 1062 if ( wrapAround ) {
1033 emit signalWrapAround(); 1063 emit signalWrapAround();
1034 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1064 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1035 nonrev.setStart( rev.start() ); 1065 nonrev.setStart( rev.start() );
1036 } else 1066 } else
1037 emit signalNotFound(); 1067 emit signalNotFound();
1038 wrapAround = !wrapAround; 1068 wrapAround = !wrapAround;
1039 } 1069 }
1040} 1070}
1041 1071
1042Event DateBookDBHack::eventByUID(int uid) { 1072Event DateBookDBHack::eventByUID(int uid) {
1043 1073
1044 // FIXME: Dirty Hacks to get hold of the private event lists 1074 // FIXME: Dirty Hacks to get hold of the private event lists
1045 QDate start; 1075 QDate start;
1046 QDate end=start.addDays(-1); 1076 QDate end=start.addDays(-1);
1047 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1077 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1048 QValueList<Event> myRepeatEvents=getRawRepeats(); 1078 QValueList<Event> myRepeatEvents=getRawRepeats();
1049 1079
1050 QValueList<Event>::ConstIterator it; 1080 QValueList<Event>::ConstIterator it;
1051 1081
1052 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1082 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1053 if ((*it).uid() == uid) return *it; 1083 if ((*it).uid() == uid) return *it;
1054 } 1084 }
1055 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1085 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1056 if ((*it).uid() == uid) return *it; 1086 if ((*it).uid() == uid) return *it;
1057 } 1087 }
1058 1088
1059 qDebug("Event not found: uid=%d\n", uid); 1089 qDebug("Event not found: uid=%d\n", uid);
1060 Event ev; 1090 Event ev;
1061 return ev; // return at least 1091 return ev; // return at least
1062} 1092}
1063 1093
diff --git a/core/pim/datebook/datebook.pro b/core/pim/datebook/datebook.pro
index e8e0a98..ae30c8d 100644
--- a/core/pim/datebook/datebook.pro
+++ b/core/pim/datebook/datebook.pro
@@ -1,61 +1,63 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS= datebookday.h \ 4 HEADERS= datebookday.h \
5 datebook.h \ 5 datebook.h \
6 dateentryimpl.h \ 6 dateentryimpl.h \
7 datebookdayheaderimpl.h \ 7 datebookdayheaderimpl.h \
8 datebooksettings.h \ 8 datebooksettings.h \
9 datebookweek.h \ 9 datebookweek.h \
10 datebookweeklst.h \ 10 datebookweeklst.h \
11 datebookweekheaderimpl.h \ 11 datebookweekheaderimpl.h \
12 repeatentry.h \ 12 repeatentry.h \
13 noteentryimpl.h \ 13 noteentryimpl.h \
14 onoteedit.h 14 onoteedit.h \
15 datebookdayallday.h
15 SOURCES= main.cpp \ 16 SOURCES= main.cpp \
16 datebookday.cpp \ 17 datebookday.cpp \
17 datebook.cpp \ 18 datebook.cpp \
18 dateentryimpl.cpp \ 19 dateentryimpl.cpp \
19 datebookdayheaderimpl.cpp \ 20 datebookdayheaderimpl.cpp \
20 datebooksettings.cpp \ 21 datebooksettings.cpp \
21 datebookweek.cpp \ 22 datebookweek.cpp \
22 datebookweeklst.cpp \ 23 datebookweeklst.cpp \
23 datebookweekheaderimpl.cpp \ 24 datebookweekheaderimpl.cpp \
24 repeatentry.cpp \ 25 repeatentry.cpp \
25 noteentryimpl.cpp \ 26 noteentryimpl.cpp \
26 onoteedit.cpp 27 onoteedit.cpp \
28 datebookdayallday.cpp
27 INTERFACES= dateentry.ui \ 29 INTERFACES= dateentry.ui \
28 datebookdayheader.ui \ 30 datebookdayheader.ui \
29 datebookweekheader.ui \ 31 datebookweekheader.ui \
30 datebookweeklstheader.ui \ 32 datebookweeklstheader.ui \
31 datebookweeklstdayhdr.ui \ 33 datebookweeklstdayhdr.ui \
32 repeatentrybase.ui \ 34 repeatentrybase.ui \
33 datebooksettingsbase.ui \ 35 datebooksettingsbase.ui \
34 noteentry.ui 36 noteentry.ui
35INCLUDEPATH += $(OPIEDIR)/include 37INCLUDEPATH += $(OPIEDIR)/include
36 DEPENDPATH+= $(OPIEDIR)/include 38 DEPENDPATH+= $(OPIEDIR)/include
37LIBS += -lqpe -lopie 39LIBS += -lqpe -lopie
38 TARGET = datebook 40 TARGET = datebook
39 41
40TRANSLATIONS = ../../../i18n/de/datebook.ts \ 42TRANSLATIONS = ../../../i18n/de/datebook.ts \
41 ../../../i18n/nl/datebook.ts \ 43 ../../../i18n/nl/datebook.ts \
42 ../../../i18n/xx/datebook.ts \ 44 ../../../i18n/xx/datebook.ts \
43 ../../../i18n/en/datebook.ts \ 45 ../../../i18n/en/datebook.ts \
44 ../../../i18n/es/datebook.ts \ 46 ../../../i18n/es/datebook.ts \
45 ../../../i18n/fr/datebook.ts \ 47 ../../../i18n/fr/datebook.ts \
46 ../../../i18n/hu/datebook.ts \ 48 ../../../i18n/hu/datebook.ts \
47 ../../../i18n/ja/datebook.ts \ 49 ../../../i18n/ja/datebook.ts \
48 ../../../i18n/ko/datebook.ts \ 50 ../../../i18n/ko/datebook.ts \
49 ../../../i18n/no/datebook.ts \ 51 ../../../i18n/no/datebook.ts \
50 ../../../i18n/pl/datebook.ts \ 52 ../../../i18n/pl/datebook.ts \
51 ../../../i18n/pt/datebook.ts \ 53 ../../../i18n/pt/datebook.ts \
52 ../../../i18n/pt_BR/datebook.ts \ 54 ../../../i18n/pt_BR/datebook.ts \
53 ../../../i18n/sl/datebook.ts \ 55 ../../../i18n/sl/datebook.ts \
54 ../../../i18n/zh_CN/datebook.ts \ 56 ../../../i18n/zh_CN/datebook.ts \
55 ../../../i18n/it/datebook.ts \ 57 ../../../i18n/it/datebook.ts \
56 ../../../i18n/zh_TW/datebook.ts \ 58 ../../../i18n/zh_TW/datebook.ts \
57 ../../../i18n/da/datebook.ts 59 ../../../i18n/da/datebook.ts
58 60
59 61
60 62
61include ( $(OPIEDIR)/include.pro ) 63include ( $(OPIEDIR)/include.pro )
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index 0b213e9..f4008e9 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -1,822 +1,933 @@
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#include <qmessagebox.h> 20#include <qmessagebox.h>
21 21
22#include "datebookday.h" 22#include "datebookday.h"
23#include "datebookdayheaderimpl.h" 23#include "datebookdayheaderimpl.h"
24#include "datebookdayallday.h"
24 25
25#include <qpe/datebookdb.h> 26#include <qpe/datebookdb.h>
26#include <qpe/resource.h> 27#include <qpe/resource.h>
27#include <qpe/event.h> 28#include <qpe/event.h>
28#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
29#include <qpe/timestring.h> 30#include <qpe/timestring.h>
30#include <qpe/qpedebug.h> 31#include <qpe/qpedebug.h>
31#include <qpe/ir.h> 32#include <qpe/ir.h>
32 33
33#include <qheader.h> 34#include <qheader.h>
34#include <qdatetime.h> 35#include <qdatetime.h>
35#include <qpainter.h> 36#include <qpainter.h>
36#include <qsimplerichtext.h> 37#include <qsimplerichtext.h>
37#include <qpopupmenu.h> 38#include <qpopupmenu.h>
38#include <qtextcodec.h> 39#include <qtextcodec.h>
39#include <qpalette.h> 40#include <qpalette.h>
40 41
41#include <qlineedit.h> 42#include <qlineedit.h>
42 43
43#include <qtimer.h> 44#include <qtimer.h>
44 45
45DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) 46DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name )
46 : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) 47 : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() )
47{ 48{
48 enableClipper(TRUE); 49 enableClipper(TRUE);
49 setTopMargin( 0 ); 50 setTopMargin( 0 );
50 horizontalHeader()->hide(); 51 horizontalHeader()->hide();
51 setLeftMargin(38); 52 setLeftMargin(38);
52 setColumnStretchable( 0, TRUE ); 53 setColumnStretchable( 0, TRUE );
53 setHScrollBarMode( QScrollView::AlwaysOff ); 54 setHScrollBarMode( QScrollView::AlwaysOff );
54 verticalHeader()->setPalette(white); 55 verticalHeader()->setPalette(white);
55 verticalHeader()->setResizeEnabled(FALSE); 56 verticalHeader()->setResizeEnabled(FALSE);
56 setSelectionMode( Single ); 57 setSelectionMode( Single );
57 58
58 // get rid of being able to edit things... 59 // get rid of being able to edit things...
59 QTableItem *tmp; 60 QTableItem *tmp;
60 int row; 61 int row;
61 for ( row = 0; row < numRows(); row++ ) { 62 for ( row = 0; row < numRows(); row++ ) {
62 tmp = new QTableItem( this, QTableItem::Never, QString::null); 63 tmp = new QTableItem( this, QTableItem::Never, QString::null);
63 setItem( row, 0, tmp ); 64 setItem( row, 0, tmp );
64 //setRowHeight( row, 40); 65 //setRowHeight( row, 40);
65 } 66 }
66 67
67 initHeader(); 68 initHeader();
68 QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); 69 QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) );
69} 70}
70 71
71void DateBookDayView::initHeader() 72void DateBookDayView::initHeader()
72{ 73{
73 QString strTmp; 74 QString strTmp;
74 for ( int i = 0; i < 24; ++i ) { 75 for ( int i = 0; i < 24; ++i ) {
75 if ( ampm ) { 76 if ( ampm ) {
76 if ( i == 0 ) 77 if ( i == 0 )
77 strTmp = QString::number(12) + ":00"; 78 strTmp = QString::number(12) + ":00";
78 else if ( i == 12 ) 79 else if ( i == 12 )
79 strTmp = QString::number(12) + tr(":00p"); 80 strTmp = QString::number(12) + tr(":00p");
80 else if ( i > 12 ) 81 else if ( i > 12 )
81 strTmp = QString::number( i - 12 ) + tr(":00p"); 82 strTmp = QString::number( i - 12 ) + tr(":00p");
82 else 83 else
83 strTmp = QString::number(i) + ":00"; 84 strTmp = QString::number(i) + ":00";
84 } else { 85 } else {
85 if ( i < 10 ) 86 if ( i < 10 )
86 strTmp = "0" + QString::number(i) + ":00"; 87 strTmp = "0" + QString::number(i) + ":00";
87 else 88 else
88 strTmp = QString::number(i) + ":00"; 89 strTmp = QString::number(i) + ":00";
89 } 90 }
90 strTmp = strTmp.rightJustify( 6, ' ' ); 91 strTmp = strTmp.rightJustify( 6, ' ' );
91 verticalHeader()->setLabel( i, strTmp ); 92 verticalHeader()->setLabel( i, strTmp );
92 setRowStretchable( i, FALSE ); 93 setRowStretchable( i, FALSE );
93 } 94 }
94} 95}
95 96
96void DateBookDayView::slotDateChanged( int y, int m, int d ) 97void DateBookDayView::slotDateChanged( int y, int m, int d )
97{ 98{
98 currDate.setYMD(y,m,d); 99 currDate.setYMD(y,m,d);
99} 100}
100 101
101void DateBookDayView::slotChangeClock( bool newClock ) 102void DateBookDayView::slotChangeClock( bool newClock )
102{ 103{
103 ampm = newClock; 104 ampm = newClock;
104 initHeader(); 105 initHeader();
105} 106}
106 107
107bool DateBookDayView::whichClock() const 108bool DateBookDayView::whichClock() const
108{ 109{
109 return ampm; 110 return ampm;
110} 111}
111 112
112void DateBookDayView::moveUp() 113void DateBookDayView::moveUp()
113{ 114{
114 scrollBy(0, -20); 115 scrollBy(0, -20);
115} 116}
116 117
117void DateBookDayView::moveDown() 118void DateBookDayView::moveDown()
118{ 119{
119 scrollBy(0, 20); 120 scrollBy(0, 20);
120} 121}
121 122
122void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) 123void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
123{ 124{
124 int w = cr.width(); 125 int w = cr.width();
125 int h = cr.height(); 126 int h = cr.height();
126 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 127 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
127 if ( showGrid() ) { 128 if ( showGrid() ) {
128 // Draw our lines 129 // Draw our lines
129 int x2 = w - 1; 130 int x2 = w - 1;
130 int y2 = h - 1; 131 int y2 = h - 1;
131 QPen pen( p->pen() ); 132 QPen pen( p->pen() );
132 p->setPen( colorGroup().dark() ); 133 p->setPen( colorGroup().dark() );
133 p->drawLine( x2, 0, x2, y2 ); 134 p->drawLine( x2, 0, x2, y2 );
134 p->drawLine( 0, y2, x2, y2 ); 135 p->drawLine( 0, y2, x2, y2 );
135 136
136 p->setPen( colorGroup().midlight() ); 137 p->setPen( colorGroup().midlight() );
137 p->drawLine( 0, y2 - h/2, x2, y2 - h/2); 138 p->drawLine( 0, y2 - h/2, x2, y2 - h/2);
138 139
139 p->setPen( pen ); 140 p->setPen( pen );
140 } 141 }
141} 142}
142 143
143void DateBookDayView::paintFocus( QPainter *, const QRect & ) 144void DateBookDayView::paintFocus( QPainter *, const QRect & )
144{ 145{
145} 146}
146 147
147void DateBookDayView::resizeEvent( QResizeEvent *e ) 148void DateBookDayView::resizeEvent( QResizeEvent *e )
148{ 149{
149 QTable::resizeEvent( e ); 150 QTable::resizeEvent( e );
150 columnWidthChanged( 0 ); 151 columnWidthChanged( 0 );
151 emit sigColWidthChanged(); 152 emit sigColWidthChanged();
152} 153}
153 154
154void DateBookDayView::keyPressEvent( QKeyEvent *e ) 155void DateBookDayView::keyPressEvent( QKeyEvent *e )
155{ 156{
156 QString txt = e->text(); 157 QString txt = e->text();
157 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 158 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
158 // we this is some sort of thing we know about... 159 // we this is some sort of thing we know about...
159 e->accept(); 160 e->accept();
160 emit sigCapturedKey( txt ); 161 emit sigCapturedKey( txt );
161 } else { 162 } else {
162 // I don't know what this key is, do you? 163 // I don't know what this key is, do you?
163 e->ignore(); 164 e->ignore();
164 } 165 }
165} 166}
166 167
167void DateBookDayView::setRowStyle( int style ) 168void DateBookDayView::setRowStyle( int style )
168{ 169{
169 if (style<0) style = 0; 170 if (style<0) style = 0;
170 171
171 for (int i=0; i<numRows(); i++) 172 for (int i=0; i<numRows(); i++)
172 setRowHeight(i, style*10+20); 173 setRowHeight(i, style*10+20);
173} 174}
174 175
175void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) 176void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e )
176{ 177{
177 int sh=99,eh=-1; 178 int sh=99,eh=-1;
178 179
179 for(int i=0;i<this->numSelections();i++) { 180 for(int i=0;i<this->numSelections();i++) {
180 QTableSelection sel = this->selection( i ); 181 QTableSelection sel = this->selection( i );
181 sh = QMIN(sh,sel.topRow()); 182 sh = QMIN(sh,sel.topRow());
182 eh = QMAX(sh,sel.bottomRow()+1); 183 eh = QMAX(sh,sel.bottomRow()+1);
183 } 184 }
184 if (sh > 23 || eh < 1) { 185 if (sh > 23 || eh < 1) {
185 sh=8; 186 sh=8;
186 eh=9; 187 eh=9;
187 } 188 }
188 189
189 quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); 190 quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit");
190 quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); 191 quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0));
191 this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); 192 this->moveChild(quickLineEdit,0,sh*this->rowHeight(0));
192 quickLineEdit->setFocus(); 193 quickLineEdit->setFocus();
193 quickLineEdit->show(); 194 quickLineEdit->show();
194} 195}
195 196
196//=========================================================================== 197//===========================================================================
197 198
198DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) 199DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name)
199{ 200{
200 active=1; 201 active=1;
201 quickEvent.setStart(start); 202 quickEvent.setStart(start);
202 quickEvent.setEnd(end); 203 quickEvent.setEnd(end);
203 connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); 204 connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed()));
204} 205}
205 206
206void DateBookDayViewQuickLineEdit::slotReturnPressed() 207void DateBookDayViewQuickLineEdit::slotReturnPressed()
207{ 208{
208 if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. 209 if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times.
209 quickEvent.setDescription(this->text()); 210 quickEvent.setDescription(this->text());
210 connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); 211 connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &)));
211 emit(insertEvent(quickEvent)); 212 emit(insertEvent(quickEvent));
212 active=0; 213 active=0;
213 } 214 }
214 this->close(true);// Close and also delete this widget 215 /* we need to return to this object.. */
216 QTimer::singleShot(500, this, SLOT(finallyCallClose()) );// Close and also delete this widget
217}
218void DateBookDayViewQuickLineEdit::finallyCallClose() {
219 close(true); // also deletes this widget...
215} 220}
216 221
217void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) 222void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e )
218{ 223{
219 slotReturnPressed(); // Reuse code to add event and close this widget. 224 slotReturnPressed(); // Reuse code to add event and close this widget.
220} 225}
221 226
222//=========================================================================== 227//===========================================================================
223 228
224DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) 229DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name )
225 : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) 230 : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 )
226{ 231{
227 widgetList.setAutoDelete( true ); 232 widgetList.setAutoDelete( true );
228 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 233 header = new DateBookDayHeader( startOnMonday, this, "day header" );
229 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 234 header->setDate( currDate.year(), currDate.month(), currDate.day() );
235
236 m_allDays = new DatebookdayAllday(newDb, this, "all day event list" );
237 m_allDays->hide();
238
230 view = new DateBookDayView( ampm, this, "day view" ); 239 view = new DateBookDayView( ampm, this, "day view" );
231 240
232 connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); 241 connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) );
233 connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); 242 connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) );
234 connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); 243 connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) );
235 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 244 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
236 connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); 245 connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) );
237 246
238 QTimer *timer = new QTimer( this ); 247 QTimer *timer = new QTimer( this );
239 248
240 connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors 249 connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
241 timer->start( 1000*60*5, FALSE ); //update every 5min 250 timer->start( 1000*60*5, FALSE ); //update every 5min
242 251
243 selectedWidget = 0; 252 selectedWidget = 0;
244 253
245 timeMarker = new DateBookDayTimeMarker( this ); 254 timeMarker = new DateBookDayTimeMarker( this );
246 timeMarker->setTime( QTime::currentTime() ); 255 timeMarker->setTime( QTime::currentTime() );
247 rowStyle = -1; // initialize with bogus values 256 rowStyle = -1; // initialize with bogus values
257 jumpToCurTime = false;
248} 258}
249 259
250void DateBookDay::setJumpToCurTime( bool bJump ) 260void DateBookDay::setJumpToCurTime( bool bJump )
251{ 261{
252 jumpToCurTime = bJump; 262 jumpToCurTime = bJump;
253} 263}
254 264
255void DateBookDay::setRowStyle( int style ) 265void DateBookDay::setRowStyle( int style )
256{ 266{
257 if (rowStyle != style) view->setRowStyle( style ); 267 if (rowStyle != style) view->setRowStyle( style );
258 rowStyle = style; 268 rowStyle = style;
259} 269}
260 270
261void DateBookDay::updateView( void ) 271void DateBookDay::updateView( void )
262{ 272{
263 timeMarker->setTime( QTime::currentTime() ); 273 timeMarker->setTime( QTime::currentTime() );
264 //need to find a way to update all DateBookDayWidgets 274 //need to find a way to update all DateBookDayWidgets
265} 275}
266 276
267void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) 277void DateBookDay::setSelectedWidget( DateBookDayWidget *w )
268{ 278{
269 selectedWidget = w; 279 selectedWidget = w;
270} 280}
271 281
272DateBookDayWidget * DateBookDay::getSelectedWidget( void ) 282DateBookDayWidget * DateBookDay::getSelectedWidget( void )
273{ 283{
274 return selectedWidget; 284 return selectedWidget;
275} 285}
276 286
277void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) 287void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
278{ 288{
279 start.setDate( currDate ); 289 start.setDate( currDate );
280 end.setDate( currDate ); 290 end.setDate( currDate );
281 291
282 int sh=99,eh=-1; 292 int sh=99,eh=-1;
283 293
284 int n = dayView()->numSelections(); 294 int n = dayView()->numSelections();
285 295
286 for (int i=0; i<n; i++) { 296 for (int i=0; i<n; i++) {
287 QTableSelection sel = dayView()->selection( i ); 297 QTableSelection sel = dayView()->selection( i );
288 sh = QMIN(sh,sel.topRow()); 298 sh = QMIN(sh,sel.topRow());
289 eh = QMAX(sh,sel.bottomRow()+1); 299 eh = QMAX(sh,sel.bottomRow()+1);
290 } 300 }
291 301
292 if (sh > 23 || eh < 1) { 302 if (sh > 23 || eh < 1) {
293 sh=8; 303 sh=8;
294 eh=9; 304 eh=9;
295 } 305 }
296 306
297 start.setTime( QTime( sh, 0, 0 ) ); 307 start.setTime( QTime( sh, 0, 0 ) );
298 end.setTime( QTime( eh, 0, 0 ) ); 308 end.setTime( QTime( eh, 0, 0 ) );
299} 309}
300 310
301void DateBookDay::setDate( int y, int m, int d ) 311void DateBookDay::setDate( int y, int m, int d )
302{ 312{
303 header->setDate( y, m, d ); 313 header->setDate( y, m, d );
304 selectedWidget = 0; 314 selectedWidget = 0;
305} 315}
306 316
307void DateBookDay::setDate( QDate d) 317void DateBookDay::setDate( QDate d)
308{ 318{
309 header->setDate( d.year(), d.month(), d.day() ); 319 header->setDate( d.year(), d.month(), d.day() );
310 selectedWidget = 0; 320 selectedWidget = 0;
311} 321}
312 322
313void DateBookDay::dateChanged( int y, int m, int d ) 323void DateBookDay::dateChanged( int y, int m, int d )
314{ 324{
315 QDate date( y, m, d ); 325 QDate date( y, m, d );
316 if ( currDate == date ) 326 if ( currDate == date )
317 return; 327 return;
318 currDate.setYMD( y, m, d ); 328 currDate.setYMD( y, m, d );
319 relayoutPage(); 329 relayoutPage();
320 dayView()->clearSelection(); 330 dayView()->clearSelection();
321 QTableSelection ts; 331 QTableSelection ts;
322 332
323 if (jumpToCurTime && this->date() == QDate::currentDate()) 333 if (jumpToCurTime && this->date() == QDate::currentDate())
324 { 334 {
325 ts.init( QTime::currentTime().hour(), 0); 335 ts.init( QTime::currentTime().hour(), 0);
326 ts.expandTo( QTime::currentTime().hour(), 0); 336 ts.expandTo( QTime::currentTime().hour(), 0);
327 } else { 337 } else {
328 ts.init( startTime, 0 ); 338 ts.init( startTime, 0 );
329 ts.expandTo( startTime, 0 ); 339 ts.expandTo( startTime, 0 );
330 } 340 }
331 341
332 dayView()->addSelection( ts ); 342 dayView()->addSelection( ts );
333 selectedWidget = 0; 343 selectedWidget = 0;
334} 344}
335 345
336void DateBookDay::redraw() 346void DateBookDay::redraw()
337{ 347{
338 if ( isUpdatesEnabled() ) 348 if ( isUpdatesEnabled() )
339 relayoutPage(); 349 relayoutPage();
340} 350}
341 351
342void DateBookDay::getEvents() 352void DateBookDay::getEvents()
343{ 353{
344 widgetList.clear(); 354 widgetList.clear();
345 355
356 /* clear the AllDay List */
357 m_allDays->hide(); // just in case
358 m_allDays->removeAllEvents();
359
346 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); 360 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate );
347 QValueListIterator<EffectiveEvent> it; 361 QValueListIterator<EffectiveEvent> it;
362 QObject* object = 0;
348 for ( it = eventList.begin(); it != eventList.end(); ++it ) { 363 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
349 EffectiveEvent ev=*it; 364 EffectiveEvent ev=*it;
350 if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. 365 if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day.
366 if (ev.event().type() == Event::AllDay ) {
367 object = m_allDays->addEvent( ev );
368 if (!object)
369 continue;
370 }else {
351 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 371 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
352 connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); 372 widgetList.append( w );
353 connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); 373 object = w;
354 connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); 374 }
355 connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); 375
356 widgetList.append( w ); 376 connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) );
377 connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) );
378 connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) );
379 connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) );
380
357 } 381 }
358 } 382 }
359} 383}
360 384
361static int place( const DateBookDayWidget *item, bool *used, int maxn ) 385static int place( const DateBookDayWidget *item, bool *used, int maxn )
362{ 386{
363 int place = 0; 387 int place = 0;
364 int start = item->event().start().hour(); 388 int start = item->event().start().hour();
365 QTime e = item->event().end(); 389 QTime e = item->event().end();
366 int end = e.hour(); 390 int end = e.hour();
367 if ( e.minute() < 5 ) 391 if ( e.minute() < 5 )
368 end--; 392 end--;
369 if ( end < start ) 393 if ( end < start )
370 end = start; 394 end = start;
371 while ( place < maxn ) { 395 while ( place < maxn ) {
372 bool free = TRUE; 396 bool free = TRUE;
373 int s = start; 397 int s = start;
374 while( s <= end ) { 398 while( s <= end ) {
375 if ( used[10*s+place] ) { 399 if ( used[10*s+place] ) {
376 free = FALSE; 400 free = FALSE;
377 break; 401 break;
378 } 402 }
379 s++; 403 s++;
380 } 404 }
381 if ( free ) 405 if ( free )
382 break; 406 break;
383 place++; 407 place++;
384 } 408 }
385 if ( place == maxn ) { 409 if ( place == maxn ) {
386 return -1; 410 return -1;
387 } 411 }
388 while( start <= end ) { 412 while( start <= end ) {
389 used[10*start+place] = TRUE; 413 used[10*start+place] = TRUE;
390 start++; 414 start++;
391 } 415 }
392 return place; 416 return place;
393} 417}
394 418
395 419
396void DateBookDay::relayoutPage( bool fromResize ) 420void DateBookDay::relayoutPage( bool fromResize )
397{ 421{
398 setUpdatesEnabled( FALSE ); 422 setUpdatesEnabled( FALSE );
399 if ( !fromResize ) 423 if ( !fromResize ) {
400 getEvents(); // no need we already have them! 424 getEvents(); // no need we already have them!
401 425
426 if (m_allDays->items() > 0 )
427 m_allDays->show();
428 /*
429 * else if ( m_allDays->items() == 0 ) already hide in getEvents
430 */
431 }
432
402 widgetList.sort(); 433 widgetList.sort();
403 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning 434 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
404 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view 435 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
405 436
406 int wCount = widgetList.count(); 437 int wCount = widgetList.count();
407 int wid = view->columnWidth(0)-1; 438 int wid = view->columnWidth(0)-1;
408 int wd; 439 int wd;
409 int n = 1; 440 int n = 1;
410 441
411 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget 442 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
412 443
413 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); 444 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
414 445
415 if ( wCount < 20 ) { 446 if ( wCount < 20 ) {
416 447
417 QArray<QRect> geometries(wCount); 448 QArray<QRect> geometries(wCount);
418 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector 449 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector
419 450
420 for ( int i = 0; i < wCount; i++) { 451 for ( int i = 0; i < wCount; i++) {
421 QValueList<int> intersectedWidgets; 452 QValueList<int> intersectedWidgets;
422 453
423 //find all widgets intersecting with widgetList.at(i) 454 //find all widgets intersecting with widgetList.at(i)
424 for ( int j = 0; j < wCount; j++) { 455 for ( int j = 0; j < wCount; j++) {
425 if (i != j) 456 if (i != j)
426 if (geometries[j].intersects(geometries[i])) 457 if (geometries[j].intersects(geometries[i]))
427 intersectedWidgets.append(j); 458 intersectedWidgets.append(j);
428 } 459 }
429 460
430 //for each of these intersecting widgets find out how many widgets are they intersecting with 461 //for each of these intersecting widgets find out how many widgets are they intersecting with
431 for ( uint j = 0; j < intersectedWidgets.count(); j++) 462 for ( uint j = 0; j < intersectedWidgets.count(); j++)
432 { 463 {
433 QArray<int> inter(wCount); 464 QArray<int> inter(wCount);
434 inter[j]=1; 465 inter[j]=1;
435 466
436 if (intersectedWidgets[j] != -1) 467 if (intersectedWidgets[j] != -1)
437 for ( uint k = j; k < intersectedWidgets.count(); k++) { 468 for ( uint k = j; k < intersectedWidgets.count(); k++) {
438 if (j != k && intersectedWidgets[k] != -1) 469 if (j != k && intersectedWidgets[k] != -1)
439 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { 470 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) {
440 inter[j]++; 471 inter[j]++;
441 intersectedWidgets[k] = -1; 472 intersectedWidgets[k] = -1;
442 } 473 }
443 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; 474 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
444 } 475 }
445 } 476 }
446 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; 477 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
447 } 478 }
448 479
449 480
450 for ( int i = 0; i < wCount; i++) { 481 for ( int i = 0; i < wCount; i++) {
451 DateBookDayWidget *w = widgetList.at(i); 482 DateBookDayWidget *w = widgetList.at(i);
452 QRect geom = w->geometry(); 483 QRect geom = w->geometry();
453 geom.setX( 0 ); 484 geom.setX( 0 );
454 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); 485 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
455 geom.setWidth( wd ); 486 geom.setWidth( wd );
456 while ( intersects( w, geom ) ) { 487 while ( intersects( w, geom ) ) {
457 geom.moveBy( wd + 2 + 1, 0 ); 488 geom.moveBy( wd + 2 + 1, 0 );
458 } 489 }
459 w->setGeometry( geom ); 490 w->setGeometry( geom );
460 } 491 }
461 492
462 if (jumpToCurTime && this->date() == QDate::currentDate()) { 493 if (jumpToCurTime && this->date() == QDate::currentDate()) {
463 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 494 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
464 } else { 495 } else {
465 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 496 view->setContentsPos( 0, startTime * view->rowHeight(0) );
466 } 497 }
467 } else { 498 } else {
468 int hours[24]; 499 int hours[24];
469 memset( hours, 0, 24*sizeof( int ) ); 500 memset( hours, 0, 24*sizeof( int ) );
470 bool overFlow = FALSE; 501 bool overFlow = FALSE;
471 for ( int i = 0; i < wCount; i++ ) { 502 for ( int i = 0; i < wCount; i++ ) {
472 DateBookDayWidget *w = widgetList.at(i); 503 DateBookDayWidget *w = widgetList.at(i);
473 int start = w->event().start().hour(); 504 int start = w->event().start().hour();
474 QTime e = w->event().end(); 505 QTime e = w->event().end();
475 int end = e.hour(); 506 int end = e.hour();
476 if ( e.minute() < 5 ) 507 if ( e.minute() < 5 )
477 end--; 508 end--;
478 if ( end < start ) 509 if ( end < start )
479 end = start; 510 end = start;
480 while( start <= end ) { 511 while( start <= end ) {
481 hours[start]++; 512 hours[start]++;
482 if ( hours[start] >= 10 ) 513 if ( hours[start] >= 10 )
483 overFlow = TRUE; 514 overFlow = TRUE;
484 ++start; 515 ++start;
485 } 516 }
486 if ( overFlow ) 517 if ( overFlow )
487 break; 518 break;
488 } 519 }
489 for ( int i = 0; i < 24; i++ ) { 520 for ( int i = 0; i < 24; i++ ) {
490 n = QMAX( n, hours[i] ); 521 n = QMAX( n, hours[i] );
491 } 522 }
492 wid = ( view->columnWidth(0)-1 ) / n; 523 wid = ( view->columnWidth(0)-1 ) / n;
493 524
494 bool used[24*10]; 525 bool used[24*10];
495 memset( used, FALSE, 24*10*sizeof( bool ) ); 526 memset( used, FALSE, 24*10*sizeof( bool ) );
496 527
497 for ( int i = 0; i < wCount; i++ ) { 528 for ( int i = 0; i < wCount; i++ ) {
498 DateBookDayWidget *w = widgetList.at(i); 529 DateBookDayWidget *w = widgetList.at(i);
499 int xp = place( w, used, n ); 530 int xp = place( w, used, n );
500 if ( xp != -1 ) { 531 if ( xp != -1 ) {
501 QRect geom = w->geometry(); 532 QRect geom = w->geometry();
502 geom.setX( xp*(wid+2) ); 533 geom.setX( xp*(wid+2) );
503 geom.setWidth( wid ); 534 geom.setWidth( wid );
504 w->setGeometry( geom ); 535 w->setGeometry( geom );
505 } 536 }
506 } 537 }
507 538
508 if (jumpToCurTime && this->date() == QDate::currentDate()) { 539 if (jumpToCurTime && this->date() == QDate::currentDate()) {
509 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 540 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
510 } else { 541 } else {
511 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 542 view->setContentsPos( 0, startTime * view->rowHeight(0) );
512 } 543 }
513 } 544 }
514 545
515 timeMarker->setTime( QTime::currentTime() );//display timeMarker 546 timeMarker->setTime( QTime::currentTime() );//display timeMarker
516 timeMarker->raise(); //on top of all widgets 547 timeMarker->raise(); //on top of all widgets
517 if (this->date() == QDate::currentDate()) { //only show timeMarker on current day 548 if (this->date() == QDate::currentDate()) { //only show timeMarker on current day
518 timeMarker->show(); 549 timeMarker->show();
519 } else { 550 } else {
520 timeMarker->hide(); 551 timeMarker->hide();
521 } 552 }
522 setUpdatesEnabled( TRUE ); 553 setUpdatesEnabled( TRUE );
523 return; 554 return;
524} 555}
525 556
526DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 557DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
527{ 558{
528 int i = 0; 559 int i = 0;
529 DateBookDayWidget *w = widgetList.at(i); 560 DateBookDayWidget *w = widgetList.at(i);
530 int wCount = widgetList.count(); 561 int wCount = widgetList.count();
531 while ( i < wCount && w != item ) { 562 while ( i < wCount && w != item ) {
532 if ( w->geometry().intersects( geom ) ) { 563 if ( w->geometry().intersects( geom ) ) {
533 return w; 564 return w;
534 } 565 }
535 w = widgetList.at(++i); 566 w = widgetList.at(++i);
536 } 567 }
537 568
538 return 0; 569 return 0;
539} 570}
540 571
541 572
542QDate DateBookDay::date() const 573QDate DateBookDay::date() const
543{ 574{
544 return currDate; 575 return currDate;
545} 576}
546 577
547void DateBookDay::setStartViewTime( int startHere ) 578void DateBookDay::setStartViewTime( int startHere )
548{ 579{
549 startTime = startHere; 580 startTime = startHere;
550 dayView()->clearSelection(); 581 dayView()->clearSelection();
551 QTableSelection ts; 582 QTableSelection ts;
552 583
553 if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called? 584 if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called?
554 ts.init( QTime::currentTime().hour(), 0); 585 ts.init( QTime::currentTime().hour(), 0);
555 ts.expandTo( QTime::currentTime().hour(), 0); 586 ts.expandTo( QTime::currentTime().hour(), 0);
556 } else { 587 } else {
557 ts.init( startTime, 0 ); 588 ts.init( startTime, 0 );
558 ts.expandTo( startTime, 0 ); 589 ts.expandTo( startTime, 0 );
559 } 590 }
560 591
561 dayView()->addSelection( ts ); 592 dayView()->addSelection( ts );
562} 593}
563 594
564int DateBookDay::startViewTime() const 595int DateBookDay::startViewTime() const
565{ 596{
566 return startTime; 597 return startTime;
567} 598}
568 599
569void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 600void DateBookDay::slotWeekChanged( bool bStartOnMonday )
570{ 601{
571 header->setStartOfWeek( bStartOnMonday ); 602 header->setStartOfWeek( bStartOnMonday );
572 //redraw(); 603 //redraw();
573} 604}
574 605
575void DateBookDay::keyPressEvent(QKeyEvent *e) 606void DateBookDay::keyPressEvent(QKeyEvent *e)
576{ 607{
577 switch(e->key()) { 608 switch(e->key()) {
578 case Key_Up: 609 case Key_Up:
579 view->moveUp(); 610 view->moveUp();
580 break; 611 break;
581 case Key_Down: 612 case Key_Down:
582 view->moveDown(); 613 view->moveDown();
583 break; 614 break;
584 case Key_Left: 615 case Key_Left:
585 setDate(QDate(currDate).addDays(-1)); 616 setDate(QDate(currDate).addDays(-1));
586 break; 617 break;
587 case Key_Right: 618 case Key_Right:
588 setDate(QDate(currDate).addDays(1)); 619 setDate(QDate(currDate).addDays(1));
589 break; 620 break;
590 default: 621 default:
591 e->ignore(); 622 e->ignore();
592 } 623 }
593} 624}
594 625
595//=========================================================================== 626//===========================================================================
596 627
597DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ) 628DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db )
598 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) 629 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
599{ 630{
600 // why would someone use "<"? Oh well, fix it up... 631 // why would someone use "<"? Oh well, fix it up...
601 // I wonder what other things may be messed up... 632 // I wonder what other things may be messed up...
602 QString strDesc = ev.description(); 633 QString strDesc = ev.description();
603 int where = strDesc.find( "<" ); 634 int where = strDesc.find( "<" );
604 while ( where != -1 ) { 635 while ( where != -1 ) {
605 strDesc.remove( where, 1 ); 636 strDesc.remove( where, 1 );
606 strDesc.insert( where, "&#60;" ); 637 strDesc.insert( where, "&#60;" );
607 where = strDesc.find( "<", where ); 638 where = strDesc.find( "<", where );
608 } 639 }
609 640
610 QString strCat; 641 QString strCat;
611// ### Fix later... 642// ### Fix later...
612// QString strCat = ev.category(); 643// QString strCat = ev.category();
613// where = strCat.find( "<" ); 644// where = strCat.find( "<" );
614// while ( where != -1 ) { 645// while ( where != -1 ) {
615 // strCat.remove( where, 1 ); 646 // strCat.remove( where, 1 );
616 // strCat.insert( where, "&#60;" ); 647 // strCat.insert( where, "&#60;" );
617 // where = strCat.find( "<", where ); 648 // where = strCat.find( "<", where );
618// } 649// }
619 650
620 QString strNote = ev.notes(); 651 QString strNote = ev.notes();
621 where = strNote.find( "<" ); 652 where = strNote.find( "<" );
622 while ( where != -1 ) { 653 while ( where != -1 ) {
623 strNote.remove( where, 1 ); 654 strNote.remove( where, 1 );
624 strNote.insert( where, "&#60;" ); 655 strNote.insert( where, "&#60;" );
625 where = strNote.find( "<", where ); 656 where = strNote.find( "<", where );
626 } 657 }
627 658
628 text = "<b>" + strDesc + "</b><br>" + "<i>"; 659 text = "<b>" + strDesc + "</b><br>" + "<i>";
629 if ( !strCat.isEmpty() ) { 660 if ( !strCat.isEmpty() ) {
630 text += strCat + "</i><br>"; 661 text += strCat + "</i><br>";
631 } 662 }
632 if (ev.event().type() == Event::Normal ) { 663 if (ev.event().type() == Event::Normal ) {
633 setEventText( text ); 664 setEventText( text );
634 } else { 665 } else {
635 setAllDayText( text ); 666 setAllDayText( text );
636 } 667 }
637 668
638 text += "<br><br>" + strNote; 669 text += "<br><br>" + strNote;
639 670
640 setBackgroundMode( PaletteBase ); 671 setBackgroundMode( PaletteBase );
641 672
642 QTime start = ev.start(); 673 QTime start = ev.start();
643 QTime end = ev.end(); 674 QTime end = ev.end();
644 int y = start.hour()*60+start.minute(); 675 int y = start.hour()*60+start.minute();
645 int h = end.hour()*60+end.minute()-y; 676 int h = end.hour()*60+end.minute()-y;
646 int rh = dateBook->dayView()->rowHeight(0); 677 int rh = dateBook->dayView()->rowHeight(0);
647 y = y*rh/60; 678 y = y*rh/60;
648 h = h*rh/60; 679 h = h*rh/60;
649 680
650 if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line. 681 if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line.
651 if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview. 682 if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview.
652 geom.setY( y ); 683 geom.setY( y );
653 geom.setHeight( h ); 684 geom.setHeight( h );
654 geom.setX( 0 ); 685 geom.setX( 0 );
655 geom.setWidth(dateBook->dayView()->columnWidth(0)-1); 686 geom.setWidth(dateBook->dayView()->columnWidth(0)-1);
656 687
657} 688}
658 689
659void DateBookDayWidget::setAllDayText( QString &text ) { 690void DateBookDayWidget::setAllDayText( QString &text ) {
660 text += "<b>" + tr("This is an all day event.") + "</b>"; 691 text += "<b>" + tr("This is an all day event.") + "</b>";
661} 692}
662 693
663void DateBookDayWidget::setEventText( QString& text ) { 694void DateBookDayWidget::setEventText( QString& text ) {
664 bool whichClock = dateBook->dayView()->whichClock(); 695 bool whichClock = dateBook->dayView()->whichClock();
665 if ( ev.startDate() != ev.endDate() ) { 696 if ( ev.startDate() != ev.endDate() ) {
666 text += "<b>" + tr("Start") + "</b>: "; 697 text += "<b>" + tr("Start") + "</b>: ";
667 text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); 698 text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE );
668 text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; 699 text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>";
669 text += "<b>" + tr("End") + "</b>: "; 700 text += "<b>" + tr("End") + "</b>: ";
670 text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); 701 text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE );
671 text += " - " + TimeString::longDateString( ev.endDate() ); 702 text += " - " + TimeString::longDateString( ev.endDate() );
672 } else { 703 } else {
673 text += "<b>" + tr("Time") + "</b>: "; 704 text += "<b>" + tr("Time") + "</b>: ";
674 text += TimeString::timeString( ev.start(), whichClock, FALSE ); 705 text += TimeString::timeString( ev.start(), whichClock, FALSE );
675 text += "<b>" + tr(" - ") + "</b>"; 706 text += "<b>" + tr(" - ") + "</b>";
676 text += TimeString::timeString( ev.end(), whichClock, FALSE ); 707 text += TimeString::timeString( ev.end(), whichClock, FALSE );
677 } 708 }
678} 709}
679 710
680DateBookDayWidget::~DateBookDayWidget() 711DateBookDayWidget::~DateBookDayWidget()
681{ 712{
682} 713}
683 714
684void DateBookDayWidget::paintEvent( QPaintEvent *e ) 715void DateBookDayWidget::paintEvent( QPaintEvent *e )
685{ 716{
686 QPainter p( this ); 717 QPainter p( this );
687 718
688 if (dateBook->getSelectedWidget() == this) { 719 if (dateBook->getSelectedWidget() == this) {
689 p.setBrush( QColor( 155, 240, 230 ) ); // selected item 720 p.setBrush( QColor( 155, 240, 230 ) ); // selected item
690 } else { 721 } else {
691 if (dateBook->date() == QDate::currentDate()) { 722 if (dateBook->date() == QDate::currentDate()) {
692 QTime curTime = QTime::currentTime(); 723 QTime curTime = QTime::currentTime();
693 if (ev.end() < curTime) { 724 if (ev.end() < curTime) {
694 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive 725 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
695 } else { 726 } else {
696 //change color in dependence of the time till the event starts 727 //change color in dependence of the time till the event starts
697 int duration = curTime.secsTo(ev.start()); 728 int duration = curTime.secsTo(ev.start());
698 if (duration < 0) duration = 0; 729 if (duration < 0) duration = 0;
699 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift 730 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
700 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue 731 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
701 } 732 }
702 } else { 733 } else {
703 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) 734 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
704 //perhaps make a distinction between future/past dates 735 //perhaps make a distinction between future/past dates
705 } 736 }
706 } 737 }
707 738
708 p.setPen( QColor(100, 100, 100) ); 739 p.setPen( QColor(100, 100, 100) );
709 p.drawRect(rect()); 740 p.drawRect(rect());
710 741
711 // p.drawRect(0,0, 5, height()); 742 // p.drawRect(0,0, 5, height());
712 743
713 int y = 0; 744 int y = 0;
714 int d = 0; 745 int d = 0;
715 746
716 if ( ev.event().hasAlarm() ) { 747 if ( ev.event().hasAlarm() ) {
717 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 748 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
718 y = 20; 749 y = 20;
719 d = 20; 750 d = 20;
720 } 751 }
721 752
722 if ( ev.event().hasRepeat() ) { 753 if ( ev.event().hasRepeat() ) {
723 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 754 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
724 d = 20; 755 d = 20;
725 y += 20; 756 y += 20;
726 } 757 }
727 758
728 QSimpleRichText rt( text, font() ); 759 QSimpleRichText rt( text, font() );
729 rt.setWidth( geom.width() - d - 6 ); 760 rt.setWidth( geom.width() - d - 6 );
730 rt.draw( &p, 7, 0, e->region(), colorGroup() ); 761 rt.draw( &p, 7, 0, e->region(), colorGroup() );
731} 762}
732 763
764/*
765 * we need to find the real start date for a uid
766 * we need to check from one day to another...
767 */
768QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) {
769 QDate dt( isIncluded );
770 QDate fnd = dt;
771
772 bool doAgain = true;
773 do{
774 dt = dt.addDays( -1 );
775 QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt );
776 for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) {
777 EffectiveEvent ev = (*it);
778 if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) )
779 return ev.date();
780 }
781 }while (doAgain );
782
783 return fnd;
784}
785
733void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) 786void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
734{ 787{
735 DateBookDayWidget *item; 788 DateBookDayWidget *item;
736 789
737 item = dateBook->getSelectedWidget(); 790 item = dateBook->getSelectedWidget();
738 if (item) 791 if (item)
739 item->update(); 792 item->update();
740 793
741 dateBook->setSelectedWidget(this); 794 dateBook->setSelectedWidget(this);
742 update(); 795 update();
743 dateBook->repaint(); 796 dateBook->repaint();
744 797
745 QPopupMenu m; 798 QPopupMenu m;
746 m.insertItem( tr( "Edit" ), 1 ); 799 m.insertItem( tr( "Edit" ), 1 );
747 m.insertItem( tr( "Duplicate" ), 4 ); 800 m.insertItem( tr( "Duplicate" ), 4 );
748 m.insertItem( tr( "Delete" ), 2 ); 801 m.insertItem( tr( "Delete" ), 2 );
749 if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); 802 if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 );
803 if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 );
750 int r = m.exec( e->globalPos() ); 804 int r = m.exec( e->globalPos() );
751 if ( r == 1 ) { 805 if ( r == 1 ) {
752 emit editMe( ev.event() ); 806 emit editMe( ev.event() );
753 } else if ( r == 2 ) { 807 } else if ( r == 2 ) {
754 emit deleteMe( ev.event() ); 808 emit deleteMe( ev.event() );
755 } else if ( r == 3 ) { 809 } else if ( r == 3 ) {
756 emit beamMe( ev.event() ); 810 emit beamMe( ev.event() );
757 } else if ( r == 4 ) { 811 } else if ( r == 4 ) {
758 emit duplicateMe( ev.event() ); 812 emit duplicateMe( ev.event() );
759 } 813 } else if ( r == 5 ) {
814 // create an Event and beam it...
815 /*
816 * Start with the easy stuff. If start and end date is the same we can just use
817 * the values of effective events
818 * If it is a multi day event we need to find the real start and end date...
819 */
820 if ( ev.event().start().date() == ev.event().end().date() ) {
821 Event event( ev.event() );
822
823 QDateTime dt( ev.date(), ev.start() );
824 event.setStart( dt );
825
826 dt.setTime( ev.end() );
827 event.setEnd( dt );
828 emit beamMe( event );
829 }else {
830 /*
831 * at least the the Times are right now
832 */
833 QDateTime start( ev.event().start() );
834 QDateTime end ( ev.event().end () );
835
836
837 /*
838 * ok we know the start date or we need to find it
839 */
840 if ( ev.start() != QTime( 0, 0, 0 ) ) {
841 start.setDate( ev.date() );
842 }else {
843 QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db );
844 start.setDate( dt );
845 }
846
847
848 /*
849 * ok we know now the end date...
850 * else
851 * get to know the offset btw the real start and real end
852 * and then add it to the new start date...
853 */
854 if ( ev.end() != QTime(23, 59, 59 ) ) {
855 end.setDate( ev.date() );
856 }else{
857 int days = ev.event().start().date().daysTo( ev.event().end().date() );
858 end.setDate( start.date().addDays( days ) );
859 }
860
861
862
863 Event event( ev.event() );
864 event.setStart( start );
865 event.setEnd ( end );
866
867
868 emit beamMe( event );
869 }
870 }
760} 871}
761 872
762void DateBookDayWidget::setGeometry( const QRect &r ) 873void DateBookDayWidget::setGeometry( const QRect &r )
763{ 874{
764 geom = r; 875 geom = r;
765 setFixedSize( r.width()+1, r.height()+1 ); 876 setFixedSize( r.width()+1, r.height()+1 );
766 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 877 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
767 show(); 878 show();
768} 879}
769 880
770 881
771//--------------------------------------------------------------------------------------------- 882//---------------------------------------------------------------------------------------------
772//--------------------------------------------------------------------------------------------- 883//---------------------------------------------------------------------------------------------
773 884
774 885
775DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) 886DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
776 : QWidget( db->dayView()->viewport() ), dateBook( db ) 887 : QWidget( db->dayView()->viewport() ), dateBook( db )
777{ 888{
778 setBackgroundMode( PaletteBase ); 889 setBackgroundMode( PaletteBase );
779} 890}
780 891
781DateBookDayTimeMarker::~DateBookDayTimeMarker() 892DateBookDayTimeMarker::~DateBookDayTimeMarker()
782{ 893{
783} 894}
784 895
785void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) 896void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ )
786{ 897{
787 QPainter p( this ); 898 QPainter p( this );
788 p.setBrush( QColor( 255, 0, 0 ) ); 899 p.setBrush( QColor( 255, 0, 0 ) );
789 900
790 QPen pen; 901 QPen pen;
791 pen.setStyle(NoPen); 902 pen.setStyle(NoPen);
792 903
793 p.setPen( pen ); 904 p.setPen( pen );
794 p.drawRect(rect()); 905 p.drawRect(rect());
795} 906}
796 907
797void DateBookDayTimeMarker::setTime( const QTime &t ) 908void DateBookDayTimeMarker::setTime( const QTime &t )
798{ 909{
799 int y = t.hour()*60+t.minute(); 910 int y = t.hour()*60+t.minute();
800 int rh = dateBook->dayView()->rowHeight(0); 911 int rh = dateBook->dayView()->rowHeight(0);
801 y = y*rh/60; 912 y = y*rh/60;
802 913
803 geom.setX( 0 ); 914 geom.setX( 0 );
804 915
805 int x = dateBook->dayView()->columnWidth(0)-1; 916 int x = dateBook->dayView()->columnWidth(0)-1;
806 geom.setWidth( x ); 917 geom.setWidth( x );
807 918
808 geom.setY( y ); 919 geom.setY( y );
809 geom.setHeight( 1 ); 920 geom.setHeight( 1 );
810 921
811 setGeometry( geom ); 922 setGeometry( geom );
812 923
813 time = t; 924 time = t;
814} 925}
815 926
816void DateBookDayTimeMarker::setGeometry( const QRect &r ) 927void DateBookDayTimeMarker::setGeometry( const QRect &r )
817{ 928{
818 geom = r; 929 geom = r;
819 setFixedSize( r.width()+1, r.height()+1 ); 930 setFixedSize( r.width()+1, r.height()+1 );
820 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 931 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
821 show(); 932 show();
822} 933}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index 961f60f..3898cbc 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -1,230 +1,236 @@
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 DATEBOOKDAY_H 20#ifndef DATEBOOKDAY_H
21#define DATEBOOKDAY_H 21#define DATEBOOKDAY_H
22 22
23#include <qpe/event.h> 23#include <qpe/event.h>
24 24
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qtable.h> 26#include <qtable.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qlist.h> 28#include <qlist.h>
29 29
30#include "datebook.h" 30#include "datebook.h"
31#include <qlineedit.h> 31#include <qlineedit.h>
32 32
33class DateBookDayHeader; 33class DateBookDayHeader;
34class DateBookDB; 34class DateBookDB;
35class DatebookdayAllday;
35class QDateTime; 36class QDateTime;
36class QMouseEvent; 37class QMouseEvent;
37class QPaintEvent; 38class QPaintEvent;
38class QResizeEvent; 39class QResizeEvent;
39 40
40class DateBookDayViewQuickLineEdit : public QLineEdit 41class DateBookDayViewQuickLineEdit : public QLineEdit
41{ 42{
42 Q_OBJECT 43 Q_OBJECT
43public: 44public:
44 DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0); 45 DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0);
45protected: 46protected:
46 Event quickEvent; 47 Event quickEvent;
47 int active; 48 int active;
48 void focusOutEvent( QFocusEvent *e ); 49 void focusOutEvent( QFocusEvent *e );
49protected slots: 50protected slots:
50 void slotReturnPressed(void); 51 void slotReturnPressed(void);
52 void finallyCallClose();
51signals: 53signals:
52 void insertEvent(const Event &e); 54 void insertEvent(const Event &e);
53}; 55};
54 56
55 57
56class DateBookDayView : public QTable 58class DateBookDayView : public QTable
57{ 59{
58 Q_OBJECT 60 Q_OBJECT
59public: 61public:
60 DateBookDayView( bool hourClock, QWidget *parent, const char *name ); 62 DateBookDayView( bool hourClock, QWidget *parent, const char *name );
61 bool whichClock() const; 63 bool whichClock() const;
62 64
63 void setRowStyle( int style ); 65 void setRowStyle( int style );
64 66
65public slots: 67public slots:
66 void moveUp(); 68 void moveUp();
67 void moveDown(); 69 void moveDown();
68 void slotDateChanged( int year, int month, int day ); 70 void slotDateChanged( int year, int month, int day );
69 71
70signals: 72signals:
71 void sigColWidthChanged(); 73 void sigColWidthChanged();
72 void sigCapturedKey( const QString &txt ); 74 void sigCapturedKey( const QString &txt );
73protected slots: 75protected slots:
74 void slotChangeClock( bool ); 76 void slotChangeClock( bool );
75protected: 77protected:
76 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); 78 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected );
77 virtual void paintFocus( QPainter *p, const QRect &cr ); 79 virtual void paintFocus( QPainter *p, const QRect &cr );
78 80
79 virtual void resizeEvent( QResizeEvent *e ); 81 virtual void resizeEvent( QResizeEvent *e );
80 void keyPressEvent( QKeyEvent *e ); 82 void keyPressEvent( QKeyEvent *e );
81 void contentsMouseReleaseEvent( QMouseEvent *e ); 83 void contentsMouseReleaseEvent( QMouseEvent *e );
82 void initHeader(); 84 void initHeader();
83private: 85private:
84 bool ampm; 86 bool ampm;
85 QDate currDate; 87 QDate currDate;
86 DateBookDayViewQuickLineEdit *quickLineEdit; 88 DateBookDayViewQuickLineEdit *quickLineEdit;
87}; 89};
88 90
89class DateBookDay; 91class DateBookDay;
90class DateBookDayWidget : public QWidget 92class DateBookDayWidget : public QWidget
91{ 93{
92 Q_OBJECT 94 Q_OBJECT
93 95
94public: 96public:
95 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); 97 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db );
96 ~DateBookDayWidget(); 98 ~DateBookDayWidget();
97 99
98 const QRect &geometry() { return geom; } 100 const QRect &geometry() { return geom; }
99 void setGeometry( const QRect &r ); 101 void setGeometry( const QRect &r );
100 102
101 const EffectiveEvent &event() const { return ev; } 103 const EffectiveEvent &event() const { return ev; }
102 104
103signals: 105signals:
104 void deleteMe( const Event &e ); 106 void deleteMe( const Event &e );
105 void duplicateMe( const Event &e ); 107 void duplicateMe( const Event &e );
106 void editMe( const Event &e ); 108 void editMe( const Event &e );
107 void beamMe( const Event &e ); 109 void beamMe( const Event &e );
108 110
109protected: 111protected:
110 void paintEvent( QPaintEvent *e ); 112 void paintEvent( QPaintEvent *e );
111 void mousePressEvent( QMouseEvent *e ); 113 void mousePressEvent( QMouseEvent *e );
112 114
113private: 115private:
114 /** 116 /**
115 * Sets the text for an all day Event 117 * Sets the text for an all day Event
116 * All day events have no time associated 118 * All day events have no time associated
117 */ 119 */
118 void setAllDayText( QString& text ); 120 void setAllDayText( QString& text );
119 121
120 /** 122 /**
121 * Sets the EventText 123 * Sets the EventText
122 * it got a start and an end Time 124 * it got a start and an end Time
123 */ 125 */
124 void setEventText( QString& text ); 126 void setEventText( QString& text );
125 const EffectiveEvent ev; 127 const EffectiveEvent ev;
126 DateBookDay *dateBook; 128 DateBookDay *dateBook;
127 QString text; 129 QString text;
128 QRect geom; 130 QRect geom;
129}; 131};
130 132
131//Marker for current time in the dayview 133//Marker for current time in the dayview
132class DateBookDayTimeMarker : public QWidget 134class DateBookDayTimeMarker : public QWidget
133{ 135{
134 Q_OBJECT 136 Q_OBJECT
135 137
136public: 138public:
137 DateBookDayTimeMarker( DateBookDay *db ); 139 DateBookDayTimeMarker( DateBookDay *db );
138 ~DateBookDayTimeMarker(); 140 ~DateBookDayTimeMarker();
139 141
140 const QRect &geometry() { return geom; } 142 const QRect &geometry() { return geom; }
141 void setGeometry( const QRect &r ); 143 void setGeometry( const QRect &r );
142 void setTime( const QTime &t ); 144 void setTime( const QTime &t );
143 145
144signals: 146signals:
145 147
146protected: 148protected:
147 void paintEvent( QPaintEvent *e ); 149 void paintEvent( QPaintEvent *e );
148 150
149private: 151private:
150 QRect geom; 152 QRect geom;
151 QTime time; 153 QTime time;
152 DateBookDay *dateBook; 154 DateBookDay *dateBook;
153}; 155};
154 156
155//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights 157//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights
156class WidgetListClass : public QList<DateBookDayWidget> 158class WidgetListClass : public QList<DateBookDayWidget>
157{ 159{
158 private: 160 private:
159 161
160 int compareItems( QCollection::Item s1, QCollection::Item s2 ) 162 int compareItems( QCollection::Item s1, QCollection::Item s2 )
161 { 163 {
162 //hmm, don't punish me for that ;) 164 //hmm, don't punish me for that ;)
163 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) 165 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height())
164 { 166 {
165 return -1; 167 return -1;
166 } else 168 } else
167 { 169 {
168 return 1; 170 return 1;
169 } 171 }
170 } 172 }
171 173
172 174
173}; 175};
174 176
175class DateBookDay : public QVBox 177class DateBookDay : public QVBox
176{ 178{
177 Q_OBJECT 179 Q_OBJECT
178 180
181 friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB
179public: 182public:
180 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, 183 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,
181 QWidget *parent, const char *name ); 184 QWidget *parent, const char *name );
182 void selectedDates( QDateTime &start, QDateTime &end ); 185 void selectedDates( QDateTime &start, QDateTime &end );
183 QDate date() const; 186 QDate date() const;
184 DateBookDayView *dayView() const { return view; } 187 DateBookDayView *dayView() const { return view; }
185 void setStartViewTime( int startHere ); 188 void setStartViewTime( int startHere );
186 int startViewTime() const; 189 int startViewTime() const;
187 void setSelectedWidget( DateBookDayWidget * ); 190 void setSelectedWidget( DateBookDayWidget * );
188 DateBookDayWidget * getSelectedWidget( void ); 191 DateBookDayWidget * getSelectedWidget( void );
189 void setJumpToCurTime( bool bJump ); 192 void setJumpToCurTime( bool bJump );
190 void setRowStyle( int style ); 193 void setRowStyle( int style );
194 static QDate findRealStart( int uid, const QDate& isIncluded,
195 DateBookDB* );
191 196
192public slots: 197public slots:
193 void setDate( int y, int m, int d ); 198 void setDate( int y, int m, int d );
194 void setDate( QDate ); 199 void setDate( QDate );
195 void redraw(); 200 void redraw();
196 void slotWeekChanged( bool bStartOnMonday ); 201 void slotWeekChanged( bool bStartOnMonday );
197 void updateView();//updates TimeMarker and DayWidget-colors 202 void updateView();//updates TimeMarker and DayWidget-colors
198 203
199signals: 204signals:
200 void removeEvent( const Event& ); 205 void removeEvent( const Event& );
201 void editEvent( const Event& ); 206 void editEvent( const Event& );
202 void duplicateEvent( const Event& ); 207 void duplicateEvent( const Event& );
203 void beamEvent( const Event& ); 208 void beamEvent( const Event& );
204 void newEvent(); 209 void newEvent();
205 void sigNewEvent( const QString & ); 210 void sigNewEvent( const QString & );
206 211
207protected slots: 212protected slots:
208 void keyPressEvent(QKeyEvent *); 213 void keyPressEvent(QKeyEvent *);
209 214
210private slots: 215private slots:
211 void dateChanged( int y, int m, int d ); 216 void dateChanged( int y, int m, int d );
212 void slotColWidthChanged() { relayoutPage(); }; 217 void slotColWidthChanged() { relayoutPage(); };
213 218
214private: 219private:
215 void getEvents(); 220 void getEvents();
216 void relayoutPage( bool fromResize = false ); 221 void relayoutPage( bool fromResize = false );
217 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); 222 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom );
218 QDate currDate; 223 QDate currDate;
219 DateBookDayView *view; 224 DateBookDayView *view;
220 DateBookDayHeader *header; 225 DateBookDayHeader *header;
226 DatebookdayAllday *m_allDays;
221 DateBookDB *db; 227 DateBookDB *db;
222 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height 228 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height
223 int startTime; 229 int startTime;
224 bool jumpToCurTime;//should we jump to current time in dayview? 230 bool jumpToCurTime;//should we jump to current time in dayview?
225 int rowStyle; 231 int rowStyle;
226 DateBookDayWidget *selectedWidget; //actual selected widget (obviously) 232 DateBookDayWidget *selectedWidget; //actual selected widget (obviously)
227 DateBookDayTimeMarker *timeMarker;//marker for current time 233 DateBookDayTimeMarker *timeMarker;//marker for current time
228}; 234};
229 235
230#endif 236#endif
diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp
new file mode 100644
index 0000000..985f31a
--- a/dev/null
+++ b/core/pim/datebook/datebookdayallday.cpp
@@ -0,0 +1,226 @@
1/****************************************************************************
2** GPL by Rajko Albrecht
3**
4**
5**
6**
7**
8****************************************************************************/
9#include "datebookdayallday.h"
10
11#include <qpushbutton.h>
12#include <qlayout.h>
13#include <qvariant.h>
14#include <qtooltip.h>
15#include <qwhatsthis.h>
16#include <qobjectlist.h>
17#include <qpe/event.h>
18#include <qpe/ir.h>
19#include <qpe/datebookdb.h>
20#include <qpe/resource.h>
21#include <qpopupmenu.h>
22#include <qtimer.h>
23#include <qregexp.h>
24#include <qdatetime.h>
25
26#include "datebookday.h"
27
28/*
29 * Constructs a DatebookdayAllday which is a child of 'parent', with the
30 * name 'name' and widget flags set to 'f'
31 */
32DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags fl )
33 : QWidget( parent, name,fl ),item_count(0),dateBook(db)
34{
35 if ( !name )
36 setName( "DatebookdayAllday" );
37 setMinimumSize( QSize( 0, 0 ) );
38
39 datebookdayalldayLayout = new QVBoxLayout( this );
40 datebookdayalldayLayout->setSpacing( 0 );
41 datebookdayalldayLayout->setMargin( 0 );
42
43 lblDesc = new DatebookEventDesc(parent->parentWidget(),"");
44 lblDesc->setBackgroundColor(Qt::yellow);
45 lblDesc->hide();
46 subWidgets.setAutoDelete(true);
47}
48
49/*
50 * Destroys the object and frees any allocated resources
51 */
52DatebookdayAllday::~DatebookdayAllday()
53{
54 // no need to delete child widgets, Qt does it all for us
55}
56
57DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev)
58{
59 DatebookAlldayDisp * lb;
60 lb = new DatebookAlldayDisp(dateBook,ev,this,NULL);
61 datebookdayalldayLayout->addWidget(lb);
62 subWidgets.append(lb);
63
64 connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&)));
65 ++item_count;
66
67 return lb;
68}
69
70void DatebookdayAllday::removeAllEvents()
71{
72 subWidgets.clear();
73 item_count = 0;
74}
75
76DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev,
77 QWidget* parent,const char* name,WFlags f)
78 : QLabel(parent,name,f),m_Ev(ev),dateBook(db)
79{
80 QString strDesc = m_Ev.description();
81 strDesc = strDesc.replace(QRegExp("<"),"&#60;");
82 setBackgroundColor(yellow);
83 setText(strDesc);
84 setFrameStyle(QFrame::Raised|QFrame::Panel);
85 QSize s = sizeHint();
86 setMaximumSize( QSize( 32767, s.height()-4 ) );
87 setMinimumSize( QSize( 0, s.height()-4 ) );
88}
89
90DatebookAlldayDisp::~DatebookAlldayDisp()
91{
92}
93
94void DatebookAlldayDisp::beam_single_event()
95{
96 // create an Event and beam it...
97 /*
98 * Start with the easy stuff. If start and end date is the same we can just use
99 * the values of effective m_Events
100 * If it is a multi day m_Event we need to find the real start and end date...
101 */
102 if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) {
103 Event m_Event( m_Ev.event() );
104
105 QDateTime dt( m_Ev.date(), m_Ev.start() );
106 m_Event.setStart( dt );
107
108 dt.setTime( m_Ev.end() );
109 m_Event.setEnd( dt );
110 emit beamMe( m_Event );
111 }else {
112 /*
113 * at least the the Times are right now
114 */
115 QDateTime start( m_Ev.event().start() );
116 QDateTime end ( m_Ev.event().end () );
117
118 /*
119 * ok we know the start date or we need to find it
120 */
121 if ( m_Ev.start() != QTime( 0, 0, 0 ) ) {
122 start.setDate( m_Ev.date() );
123 }else {
124 QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook );
125 start.setDate( dt );
126 }
127
128 /*
129 * ok we know now the end date...
130 * else
131 * get to know the offset btw the real start and real end
132 * and then add it to the new start date...
133 */
134 if ( m_Ev.end() != QTime(23, 59, 59 ) ) {
135 end.setDate( m_Ev.date() );
136 }else{
137 int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() );
138 end.setDate( start.date().addDays( days ) );
139 }
140 Event m_Event( m_Ev.event() );
141 m_Event.setStart( start );
142 m_Event.setEnd ( end );
143 emit beamMe( m_Event );
144 }
145}
146
147void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e)
148{
149 QColor b = backgroundColor();
150 setBackgroundColor(green);
151 update();
152 QPopupMenu m;
153 m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 );
154 m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 );
155 m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 );
156 if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 );
157 if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 );
158 m.insertItem( tr( "Info"),6);
159 int r = m.exec( e->globalPos() );
160 setBackgroundColor(b);
161 update();
162 switch (r) {
163 case 1:
164 emit editMe( m_Ev.event() );
165 break;
166 case 2:
167 emit deleteMe( m_Ev.event() );
168 break;
169 case 3:
170 emit beamMe( m_Ev.event() );
171 break;
172 case 4:
173 emit duplicateMe( m_Ev.event() );
174 break;
175 case 5:
176 beam_single_event();
177 break;
178 case 6:
179 emit displayMe( m_Ev.event() );
180 break;
181 default:
182 break;
183 }
184}
185
186DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name)
187 :QLabel(parent,name)
188{
189 m_Timer=new QTimer(this);
190 connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide()));
191 setFrameStyle(QFrame::Sunken|QFrame::Panel);
192 setTextFormat(RichText);
193}
194
195DatebookEventDesc::~DatebookEventDesc()
196{
197}
198
199void DatebookEventDesc::mousePressEvent(QMouseEvent*)
200{
201 hide();
202 if (m_Timer->isActive()) m_Timer->stop();
203}
204
205void DatebookEventDesc::disp_event(const Event&e)
206{
207 if (m_Timer->isActive()) m_Timer->stop();
208 QString text;
209 text = "<b><i>"+e.description()+"</i></b><br>";
210 if (e.notes().length()>0) {
211 text+="<b>"+e.notes()+"</b><br>";
212 }
213 if (e.location().length()>0) {
214 text+="<i>"+e.location()+"</i><br>";
215 }
216 text = text.replace(QRegExp("\n"),"<br>");
217 setText(text);
218 QSize s = sizeHint();
219 s+=QSize(10,10);
220 resize(s);
221 move( QMAX(0,(parentWidget()->width()-width()) / 2),
222 (parentWidget()->height()-height())/2 );
223 show();
224 m_Timer->start(2000,true);
225}
226
diff --git a/core/pim/datebook/datebookdayallday.h b/core/pim/datebook/datebookdayallday.h
new file mode 100644
index 0000000..c781785
--- a/dev/null
+++ b/core/pim/datebook/datebookdayallday.h
@@ -0,0 +1,80 @@
1#ifndef DATEBOOKDAYALLDAYBASE_H
2#define DATEBOOKDAYALLDAYBASE_H
3
4#include <qvariant.h>
5#include <qframe.h>
6#include <qlabel.h>
7#include <qlist.h>
8#include <qpe/event.h>
9
10class QVBoxLayout;
11class QHBoxLayout;
12class QGridLayout;
13class DatebookAlldayDisp;
14class DatebookEventDesc;
15class DateBookDB;
16
17class DatebookdayAllday : public QWidget
18{
19 Q_OBJECT
20
21public:
22 DatebookdayAllday(DateBookDB* db,
23 QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
24 ~DatebookdayAllday();
25 DatebookAlldayDisp* addEvent(const EffectiveEvent&e);
26 const unsigned int items()const{return item_count;}
27
28public slots:
29 void removeAllEvents();
30
31protected:
32 QVBoxLayout* datebookdayalldayLayout;
33 DatebookEventDesc * lblDesc;
34 unsigned int item_count;
35 QList<DatebookAlldayDisp> subWidgets;
36 DateBookDB *dateBook;
37};
38
39class DatebookAlldayDisp : public QLabel
40{
41 Q_OBJECT
42
43public:
44 DatebookAlldayDisp(DateBookDB* db,const EffectiveEvent& e,
45 QWidget* parent=0,const char* name = 0, WFlags fl=0);
46 virtual ~DatebookAlldayDisp();
47
48signals:
49 void deleteMe( const Event &e );
50 void duplicateMe( const Event &e );
51 void editMe( const Event &e );
52 void beamMe( const Event &e );
53 void displayMe(const Event &e);
54
55public slots:
56
57protected:
58 EffectiveEvent m_Ev;
59 DateBookDB* dateBook;
60 void mousePressEvent( QMouseEvent *e );
61 void beam_single_event();
62};
63
64class DatebookEventDesc: public QLabel
65{
66 Q_OBJECT
67
68public:
69 DatebookEventDesc(QWidget* Parent=0,const char* name = 0);
70 virtual ~DatebookEventDesc();
71
72public slots:
73 void disp_event(const Event&e);
74
75protected:
76 void mousePressEvent(QMouseEvent*e);
77 QTimer* m_Timer;
78};
79
80#endif // DATEBOOKDAYALLDAYBASE_H
diff --git a/core/pim/datebook/datebooksettings.h b/core/pim/datebook/datebooksettings.h
index c3036e1..cf8a0ff 100644
--- a/core/pim/datebook/datebooksettings.h
+++ b/core/pim/datebook/datebooksettings.h
@@ -1,54 +1,55 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef DATEBOOKSETTINGS_H 21#ifndef DATEBOOKSETTINGS_H
22#define DATEBOOKSETTINGS_H 22#define DATEBOOKSETTINGS_H
23#include "datebooksettingsbase.h" 23#include "datebooksettingsbase.h"
24#include <qpe/categoryselect.h> 24#include <qpe/categoryselect.h>
25 25
26class DateBookSettings : public DateBookSettingsBase 26class DateBookSettings : public DateBookSettingsBase
27{ 27{
28 Q_OBJECT
28public: 29public:
29 DateBookSettings( bool whichClock, QWidget *parent = 0, 30 DateBookSettings( bool whichClock, QWidget *parent = 0,
30 const char *name = 0, bool modal = TRUE, WFlags = 0 ); 31 const char *name = 0, bool modal = TRUE, WFlags = 0 );
31 ~DateBookSettings(); 32 ~DateBookSettings();
32 void setStartTime( int newStartViewTime ); 33 void setStartTime( int newStartViewTime );
33 int startTime() const; 34 int startTime() const;
34 void setAlarmPreset( bool bAlarm, int presetTime ); 35 void setAlarmPreset( bool bAlarm, int presetTime );
35 bool alarmPreset() const; 36 bool alarmPreset() const;
36 int presetTime() const; 37 int presetTime() const;
37 void setAlarmType( int alarmType ); 38 void setAlarmType( int alarmType );
38 int alarmType() const; 39 int alarmType() const;
39 40
40 void setJumpToCurTime( bool bJump ); 41 void setJumpToCurTime( bool bJump );
41 bool jumpToCurTime() const; 42 bool jumpToCurTime() const;
42 void setRowStyle( int style ); 43 void setRowStyle( int style );
43 int rowStyle() const; 44 int rowStyle() const;
44 45
45private slots: 46private slots:
46 void slot12Hour( int ); 47 void slot12Hour( int );
47 void slotChangeClock( bool ); 48 void slotChangeClock( bool );
48 49
49private: 50private:
50 void init(); 51 void init();
51 bool ampm; 52 bool ampm;
52 int oldtime; 53 int oldtime;
53}; 54};
54#endif 55#endif
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 2ad7aa9..ab7e963 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,677 +1,666 @@
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#include "datebookweek.h" 20#include "datebookweek.h"
21#include "datebookweekheaderimpl.h" 21#include "datebookweekheaderimpl.h"
22 22
23#include <qpe/calendar.h>
24#include <qpe/datebookdb.h> 23#include <qpe/datebookdb.h>
25#include <qpe/event.h>
26#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
27#include <qpe/timestring.h> 25#include <qpe/calendar.h>
28 26
29#include <qdatetime.h>
30#include <qheader.h> 27#include <qheader.h>
31#include <qlabel.h> 28#include <qlabel.h>
32#include <qlayout.h> 29#include <qlayout.h>
33#include <qpainter.h>
34#include <qpopupmenu.h>
35#include <qtimer.h> 30#include <qtimer.h>
36#include <qspinbox.h>
37#include <qstyle.h>
38 31
39//----------------------------------------------------------------- 32//-----------------------------------------------------------------
40 33
41 34
42DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) 35DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e )
43 : ev( e ) 36 : ev( e )
44{ 37{
45 // with the current implementation change the color for all day events 38 // with the current implementation change the color for all day events
46 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { 39 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) {
47 c = Qt::green; 40 c = Qt::green;
48 } else { 41 } else {
49 c = ev.event().hasAlarm() ? Qt::red : Qt::blue; 42 c = ev.event().hasAlarm() ? Qt::red : Qt::blue;
50 } 43 }
51} 44}
52 45
53void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) 46void DateBookWeekItem::setGeometry( int x, int y, int w, int h )
54{ 47{
55 r.setRect( x, y, w, h ); 48 r.setRect( x, y, w, h );
56} 49}
57 50
58 51
59//------------------=--------------------------------------------- 52//------------------=---------------------------------------------
60 53
61DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, 54DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
62 QWidget *parent, const char *name ) 55 QWidget *parent, const char *name )
63 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), 56 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ),
64 showingEvent( false ) 57 showingEvent( false )
65{ 58{
66 items.setAutoDelete( true ); 59 items.setAutoDelete( true );
67 60
68 viewport()->setBackgroundMode( PaletteBase ); 61 viewport()->setBackgroundMode( PaletteBase );
69 62
70 header = new QHeader( this ); 63 header = new QHeader( this );
71 header->addLabel( "" ); 64 header->addLabel( "" );
72 65
73 header->setMovingEnabled( false ); 66 header->setMovingEnabled( false );
74 header->setResizeEnabled( false ); 67 header->setResizeEnabled( false );
75 header->setClickEnabled( false, 0 ); 68 header->setClickEnabled( false, 0 );
76 initNames(); 69 initNames();
77 70
78 71
79 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); 72 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) );
80 73
81 QObject::connect(qApp, SIGNAL(clockChanged(bool)), 74 QObject::connect(qApp, SIGNAL(clockChanged(bool)),
82 this, SLOT(slotChangeClock(bool))); 75 this, SLOT(slotChangeClock(bool)));
83 76
84 QFontMetrics fm( font() ); 77 QFontMetrics fm( font() );
85 rowHeight = fm.height()+2; 78 rowHeight = fm.height()+2;
86 79
87 resizeContents( width(), 24*rowHeight ); 80 resizeContents( width(), 24*rowHeight );
88} 81}
89 82
90void DateBookWeekView::initNames() 83void DateBookWeekView::initNames()
91{ 84{
85#warning Please review this ! (eilers)
86
87 // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers)
88
92 static bool bFirst = true; 89 static bool bFirst = true;
93 if ( bFirst ) { 90 if ( bFirst ) {
94 if ( bOnMonday ) { 91 if ( bOnMonday ) {
95 header->addLabel( tr("Mo", "Monday" ) ); 92 for ( int i = 1; i<=7; i++ ) {
96 header->addLabel( tr("Tu", "Tuesday") ); 93 header->addLabel( Calendar::nameOfDay( i ) );
97 header->addLabel( tr("We", "Wednesday" ) ); 94 }
98 header->addLabel( tr("Th", "Thursday" ) ); 95
99 header->addLabel( tr("Fr", "Friday" ) );
100 header->addLabel( tr("Sa", "Saturday" ) );
101 header->addLabel( tr("Su", "Sunday" ) );
102 } else { 96 } else {
103 header->addLabel( tr("Su", "Sunday" ) ); 97 header->addLabel( Calendar::nameOfDay( 7 ) );
104 header->addLabel( tr("Mo", "Monday") ); 98 for ( int i = 1; i<7; i++ ) {
105 header->addLabel( tr("Tu", "Tuesday") ); 99 header->addLabel( Calendar::nameOfDay( i ) );
106 header->addLabel( tr("We", "Wednesday" ) ); 100 }
107 header->addLabel( tr("Th", "Thursday" ) ); 101 }
108 header->addLabel( tr("Fr", "Friday" ) );
109 header->addLabel( tr("Sa", "Saturday" ) );
110 }
111 bFirst = false; 102 bFirst = false;
112 } else { 103 } else {
113 // we are change things... 104 // we are change things...
114 if ( bOnMonday ) { 105 if ( bOnMonday ) {
115 header->setLabel( 1, tr("Mo", "Monday") ); 106 for ( int i = 1; i<=7; i++ ) {
116 header->setLabel( 2, tr("Tu", "Tuesday") ); 107 header->setLabel( i, Calendar::nameOfDay( i ) );
117 header->setLabel( 3, tr("We", "Wednesday" ) ); 108 }
118 header->setLabel( 4, tr("Th", "Thursday" ) ); 109
119 header->setLabel( 5, tr("Fr", "Friday" ) );
120 header->setLabel( 6, tr("Sa", "Saturday" ) );
121 header->setLabel( 7, tr("Su", "Sunday" ) );
122 } else { 110 } else {
123 header->setLabel( 1, tr("Su", "Sunday" ) ); 111 header->setLabel( 1, Calendar::nameOfDay( 7 ) );
124 header->setLabel( 2, tr("Mo", "Monday") ); 112 for ( int i = 1; i<7; i++ ) {
125 header->setLabel( 3, tr("Tu", "Tuesday") ); 113 header->setLabel( i+1, Calendar::nameOfDay( i ) );
126 header->setLabel( 4, tr("We", "Wednesday" ) ); 114 }
127 header->setLabel( 5, tr("Th", "Thursday" ) ); 115
128 header->setLabel( 6, tr("Fr", "Friday" ) );
129 header->setLabel( 7, tr("Sa", "Saturday" ) );
130 } 116 }
131 } 117 }
132} 118}
133 119
134 120
135 121
136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 122void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
137{ 123{
138 items.clear(); 124 items.clear();
139 QValueListIterator<EffectiveEvent> it; 125 QValueListIterator<EffectiveEvent> it;
140 for ( it = ev.begin(); it != ev.end(); ++it ) { 126 for ( it = ev.begin(); it != ev.end(); ++it ) {
141 DateBookWeekItem *i = new DateBookWeekItem( *it ); 127 DateBookWeekItem *i = new DateBookWeekItem( *it );
142 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. 128 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day.
143 positionItem( i ); 129 positionItem( i );
144 items.append( i ); 130 items.append( i );
145 } 131 }
146 } 132 }
147 viewport()->update(); 133 viewport()->update();
148} 134}
149 135
150void DateBookWeekView::moveToHour( int h ) 136void DateBookWeekView::moveToHour( int h )
151{ 137{
152 int offset = h*rowHeight; 138 int offset = h*rowHeight;
153 setContentsPos( 0, offset ); 139 setContentsPos( 0, offset );
154} 140}
155 141
156void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 142void DateBookWeekView::keyPressEvent( QKeyEvent *e )
157{ 143{
158 e->ignore(); 144 e->ignore();
159} 145}
160 146
161void DateBookWeekView::slotChangeClock( bool c ) 147void DateBookWeekView::slotChangeClock( bool c )
162{ 148{
163 ampm = c; 149 ampm = c;
164 viewport()->update(); 150 viewport()->update();
165} 151}
166 152
167static inline int db_round30min( int m ) 153static inline int db_round30min( int m )
168{ 154{
169 if ( m < 15 ) 155 if ( m < 15 )
170 m = 0; 156 m = 0;
171 else if ( m < 45 ) 157 else if ( m < 45 )
172 m = 1; 158 m = 1;
173 else 159 else
174 m = 2; 160 m = 2;
175 161
176 return m; 162 return m;
177} 163}
178 164
179void DateBookWeekView::alterDay( int day ) 165void DateBookWeekView::alterDay( int day )
180{ 166{
181 if ( !bOnMonday ) { 167 if ( !bOnMonday ) {
182 day--; 168 day--;
183 } 169 }
184 emit showDay( day ); 170 emit showDay( day );
185} 171}
186 172
187void DateBookWeekView::positionItem( DateBookWeekItem *i ) 173void DateBookWeekView::positionItem( DateBookWeekItem *i )
188{ 174{
189 const int Width = 8; 175 const int Width = 8;
190 const EffectiveEvent ev = i->event(); 176 const EffectiveEvent ev = i->event();
191 177
192 // 30 minute intervals 178 // 30 minute intervals
193 int y = ev.start().hour() * 2; 179 int y = ev.start().hour() * 2;
194 y += db_round30min( ev.start().minute() ); 180 y += db_round30min( ev.start().minute() );
195 int y2 = ev.end().hour() * 2; 181 int y2 = ev.end().hour() * 2;
196 y2 += db_round30min( ev.end().minute() ); 182 y2 += db_round30min( ev.end().minute() );
197 if ( y > 47 ) y = 47; 183 if ( y > 47 ) y = 47;
198 if ( y2 > 48 ) y2 = 48; 184 if ( y2 > 48 ) y2 = 48;
199 y = (y * rowHeight) / 2; 185 y = (y * rowHeight) / 2;
200 y2 = (y2 * rowHeight) / 2; 186 y2 = (y2 * rowHeight) / 2;
201 187
202 int h; 188 int h;
203 if ( ev.event().type() == Event::AllDay ) { 189 if ( ev.event().type() == Event::AllDay ) {
204 h = (48 * rowHeight) / 2; 190 h = (48 * rowHeight) / 2;
205 y = 0; 191 y = 0;
206 } else { 192 } else {
207 h=y2-y; 193 h=y2-y;
208 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; 194 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
209 } 195 }
210 196
211 int dow = ev.date().dayOfWeek(); 197 int dow = ev.date().dayOfWeek();
212 if ( !bOnMonday ) { 198 if ( !bOnMonday ) {
213 if ( dow == 7 ) 199 if ( dow == 7 )
214 dow = 1; 200 dow = 1;
215 else 201 else
216 dow++; 202 dow++;
217 } 203 }
218 int x = header->sectionPos( dow ) - 1; 204 int x = header->sectionPos( dow ) - 1;
219 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 205 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
220 DateBookWeekItem *isect = 0; 206 DateBookWeekItem *isect = 0;
221 do { 207 do {
222 i->setGeometry( x, y, Width, h ); 208 i->setGeometry( x, y, Width, h );
223 isect = intersects( i ); 209 isect = intersects( i );
224 x += Width - 1; 210 x += Width - 1;
225 } while ( isect && x < xlim ); 211 } while ( isect && x < xlim );
226} 212}
227 213
228DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 214DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
229{ 215{
230 QRect geom = item->geometry(); 216 QRect geom = item->geometry();
231 217
232 // We allow the edges to overlap 218 // We allow the edges to overlap
233 geom.moveBy( 1, 1 ); 219 geom.moveBy( 1, 1 );
234 geom.setSize( geom.size()-QSize(2,2) ); 220 geom.setSize( geom.size()-QSize(2,2) );
235 221
236 QListIterator<DateBookWeekItem> it(items); 222 QListIterator<DateBookWeekItem> it(items);
237 for ( ; it.current(); ++it ) { 223 for ( ; it.current(); ++it ) {
238 DateBookWeekItem *i = it.current(); 224 DateBookWeekItem *i = it.current();
239 if ( i != item ) { 225 if ( i != item ) {
240 if ( i->geometry().intersects( geom ) ) { 226 if ( i->geometry().intersects( geom ) ) {
241 return i; 227 return i;
242 } 228 }
243 } 229 }
244 } 230 }
245 231
246 return 0; 232 return 0;
247} 233}
248 234
249void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 235void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
250{ 236{
251 QListIterator<DateBookWeekItem> it(items); 237 QListIterator<DateBookWeekItem> it(items);
252 for ( ; it.current(); ++it ) { 238 for ( ; it.current(); ++it ) {
253 DateBookWeekItem *i = it.current(); 239 DateBookWeekItem *i = it.current();
254 if ( i->geometry().contains( e->pos() ) ) { 240 if ( i->geometry().contains( e->pos() ) ) {
255 showingEvent = true; 241 showingEvent = true;
256 emit signalShowEvent( i->event() ); 242 emit signalShowEvent( i->event() );
257 break; 243 break;
258 } 244 }
259 } 245 }
260} 246}
261 247
262void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 248void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
263{ 249{
264 if ( showingEvent ) { 250 if ( showingEvent ) {
265 showingEvent = false; 251 showingEvent = false;
266 emit signalHideEvent(); 252 emit signalHideEvent();
267 } else { 253 } else {
268 int d = header->sectionAt( e->pos().x() ); 254 int d = header->sectionAt( e->pos().x() );
269 if ( d > 0 ) { 255 if ( d > 0 ) {
270 // if ( !bOnMonday ) 256 // if ( !bOnMonday )
271 // d--; 257 // d--;
272 emit showDay( d ); 258 emit showDay( d );
273 } 259 }
274 } 260 }
275} 261}
276 262
277void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 263void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
278{ 264{
279 QRect ur( cx, cy, cw, ch ); 265 QRect ur( cx, cy, cw, ch );
280 p->setPen( lightGray ); 266 p->setPen( lightGray );
281 for ( int i = 1; i <= 7; i++ ) 267 for ( int i = 1; i <= 7; i++ )
282 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 268 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
283 269
284 p->setPen( black ); 270 p->setPen( black );
285 for ( int t = 0; t < 24; t++ ) { 271 for ( int t = 0; t < 24; t++ ) {
286 int y = t*rowHeight; 272 int y = t*rowHeight;
287 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 273 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
288 QString s; 274 QString s;
289 if ( ampm ) { 275 if ( ampm ) {
290 if ( t == 0 ) 276 if ( t == 0 )
291 s = QString::number( 12 ); 277 s = QString::number( 12 );
292 else if ( t == 12 ) 278 else if ( t == 12 )
293 s = QString::number(12) + tr( "p" ); 279 s = QString::number(12) + tr( "p" );
294 else if ( t > 12 ) { 280 else if ( t > 12 ) {
295 if ( t - 12 < 10 ) 281 if ( t - 12 < 10 )
296 s = " "; 282 s = " ";
297 else 283 else
298 s = ""; 284 s = "";
299 s += QString::number( t - 12 ) + tr("p"); 285 s += QString::number( t - 12 ) + tr("p");
300 } else { 286 } else {
301 if ( 12 - t < 3 ) 287 if ( 12 - t < 3 )
302 s = ""; 288 s = "";
303 else 289 else
304 s = " "; 290 s = " ";
305 s += QString::number( t ); 291 s += QString::number( t );
306 } 292 }
307 } else { 293 } else {
308 s = QString::number( t ); 294 s = QString::number( t );
309 if ( s.length() == 1 ) 295 if ( s.length() == 1 )
310 s.prepend( "0" ); 296 s.prepend( "0" );
311 } 297 }
312 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 298 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
313 } 299 }
314 } 300 }
315 301
316 QListIterator<DateBookWeekItem> it(items); 302 QListIterator<DateBookWeekItem> it(items);
317 for ( ; it.current(); ++it ) { 303 for ( ; it.current(); ++it ) {
318 DateBookWeekItem *i = it.current(); 304 DateBookWeekItem *i = it.current();
319 if ( i->geometry().intersects( ur ) ) { 305 if ( i->geometry().intersects( ur ) ) {
320 p->setBrush( i->color() ); 306 p->setBrush( i->color() );
321 p->drawRect( i->geometry() ); 307 p->drawRect( i->geometry() );
322 } 308 }
323 } 309 }
324} 310}
325 311
326void DateBookWeekView::resizeEvent( QResizeEvent *e ) 312void DateBookWeekView::resizeEvent( QResizeEvent *e )
327{ 313{
328 const int hourWidth = 20; 314 const int hourWidth = 20;
329 QScrollView::resizeEvent( e ); 315 QScrollView::resizeEvent( e );
330 int avail = width()-qApp->style().scrollBarExtent().width()-1; 316 int avail = width()-qApp->style().scrollBarExtent().width()-1;
331 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 317 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
332 setMargins( 0, header->height(), 0, 0 ); 318 setMargins( 0, header->height(), 0, 0 );
333 header->resizeSection( 0, hourWidth ); 319 header->resizeSection( 0, hourWidth );
334 int sw = (avail - hourWidth) / 7; 320 int sw = (avail - hourWidth) / 7;
335 for ( int i = 1; i < 7; i++ ) 321 for ( int i = 1; i < 7; i++ )
336 header->resizeSection( i, sw ); 322 header->resizeSection( i, sw );
337 header->resizeSection( 7, avail - hourWidth - sw*6 ); 323 header->resizeSection( 7, avail - hourWidth - sw*6 );
338} 324}
339 325
340void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 326void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
341{ 327{
342 bOnMonday = bStartOnMonday; 328 bOnMonday = bStartOnMonday;
343 initNames(); 329 initNames();
344} 330}
345 331
346//------------------------------------------------------------------- 332//-------------------------------------------------------------------
347 333
348DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 334DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
349 QWidget *parent, const char *name ) 335 QWidget *parent, const char *name )
350 : QWidget( parent, name ), 336 : QWidget( parent, name ),
351 db( newDB ), 337 db( newDB ),
352 startTime( 0 ), 338 startTime( 0 ),
353 ampm( ap ), 339 ampm( ap ),
354 bStartOnMonday( startOnMonday ) 340 bStartOnMonday( startOnMonday )
355{ 341{
356 setFocusPolicy(StrongFocus); 342 setFocusPolicy(StrongFocus);
357 QVBoxLayout *vb = new QVBoxLayout( this ); 343 QVBoxLayout *vb = new QVBoxLayout( this );
358 header = new DateBookWeekHeader( bStartOnMonday, this ); 344 header = new DateBookWeekHeader( bStartOnMonday, this );
359 view = new DateBookWeekView( ampm, startOnMonday, this ); 345 view = new DateBookWeekView( ampm, startOnMonday, this );
360 vb->addWidget( header ); 346 vb->addWidget( header );
361 vb->addWidget( view ); 347 vb->addWidget( view );
362 348
363 lblDesc = new QLabel( this, "event label" ); 349 lblDesc = new QLabel( this, "event label" );
364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 350 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
365 lblDesc->setBackgroundColor( yellow ); 351 lblDesc->setBackgroundColor( yellow );
366 lblDesc->hide(); 352 lblDesc->hide();
367 353
368 tHide = new QTimer( this ); 354 tHide = new QTimer( this );
369 355
370 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); 356 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) );
371 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 357 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
372 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); 358 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
373 connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); 359 connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) );
374 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); 360 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
375 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 361 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
376 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); 362 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
377 setDate(QDate::currentDate()); 363 setDate(QDate::currentDate());
378} 364}
379 365
380void DateBookWeek::keyPressEvent(QKeyEvent *e) 366void DateBookWeek::keyPressEvent(QKeyEvent *e)
381{ 367{
382 switch(e->key()) { 368 switch(e->key()) {
383 case Key_Up: 369 case Key_Up:
384 view->scrollBy(0, -20); 370 view->scrollBy(0, -20);
385 break; 371 break;
386 case Key_Down: 372 case Key_Down:
387 view->scrollBy(0, 20); 373 view->scrollBy(0, 20);
388 break; 374 break;
389 case Key_Left: 375 case Key_Left:
390 setDate(date().addDays(-7)); 376 setDate(date().addDays(-7));
391 break; 377 break;
392 case Key_Right: 378 case Key_Right:
393 setDate(date().addDays(7)); 379 setDate(date().addDays(7));
394 break; 380 break;
395 default: 381 default:
396 e->ignore(); 382 e->ignore();
397 } 383 }
398} 384}
399 385
400void DateBookWeek::showDay( int day ) 386void DateBookWeek::showDay( int day )
401{ 387{
402 QDate d=bdate; 388 QDate d=bdate;
403 389
404 // Calculate offset to first day of week. 390 // Calculate offset to first day of week.
405 int dayoffset=d.dayOfWeek(); 391 int dayoffset=d.dayOfWeek() % 7;
392
406 if(bStartOnMonday) dayoffset--; 393 if(bStartOnMonday) dayoffset--;
407 394
408 day--; 395 day--;
409 d=d.addDays(day-dayoffset); 396 d=d.addDays(day-dayoffset);
410 emit showDate( d.year(), d.month(), d.day() ); 397 emit showDate( d.year(), d.month(), d.day() );
411} 398}
412 399
413void DateBookWeek::setDate( int y, int m, int d ) 400void DateBookWeek::setDate( int y, int m, int d )
414{ 401{
415 setDate(QDate(y, m, d)); 402 setDate(QDate(y, m, d));
416} 403}
417 404
418void DateBookWeek::setDate(QDate newdate) 405void DateBookWeek::setDate(QDate newdate)
419{ 406{
420 bdate=newdate; 407 bdate=newdate;
421 dow = newdate.dayOfWeek(); 408 dow = newdate.dayOfWeek();
422 header->setDate( newdate ); 409 header->setDate( newdate );
423} 410}
424 411
425void DateBookWeek::dateChanged( QDate &newdate ) 412void DateBookWeek::dateChanged( QDate &newdate )
426{ 413{
427 bdate=newdate; 414 bdate=newdate;
428 getEvents(); 415 getEvents();
429} 416}
430 417
431QDate DateBookWeek::date() const 418QDate DateBookWeek::date() const
432{ 419{
433 return bdate; 420 return bdate;
434} 421}
435 422
436void DateBookWeek::getEvents() 423void DateBookWeek::getEvents()
437{ 424{
438 QDate startWeek = weekDate(); 425 QDate startWeek = weekDate();
439 426
440 QDate endWeek = startWeek.addDays( 6 ); 427 QDate endWeek = startWeek.addDays( 6 );
441 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 428 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
442 view->showEvents( eventList ); 429 view->showEvents( eventList );
443 view->moveToHour( startTime ); 430 view->moveToHour( startTime );
444} 431}
445 432
446void DateBookWeek::generateAllDayTooltext( QString& text ) { 433void DateBookWeek::generateAllDayTooltext( QString& text ) {
447 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 434 text += "<b>" + tr("This is an all day event.") + "</b><br>";
448} 435}
449 436
450void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 437void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
451 str += "<b>" + QObject::tr("Start") + "</b>: "; 438 str += "<b>" + QObject::tr("Start") + "</b>: ";
452 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 439 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
453 if( ev.startDate()!=ev.endDate() ) { 440 if( ev.startDate()!=ev.endDate() ) {
454 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 441 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
455 } 442 }
456 str += "<br>"; 443 str += "<br>";
457 str += "<b>" + QObject::tr("End") + "</b>: "; 444 str += "<b>" + QObject::tr("End") + "</b>: ";
458 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 445 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
459 if( ev.startDate()!=ev.endDate() ) { 446 if( ev.startDate()!=ev.endDate() ) {
460 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 447 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
461 } 448 }
462} 449}
463 450
464void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 451void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
465{ 452{
466 if ( tHide->isActive() ) 453 if ( tHide->isActive() )
467 tHide->stop(); 454 tHide->stop();
468 455
469 // why would someone use "<"? Oh well, fix it up... 456 // why would someone use "<"? Oh well, fix it up...
470 // I wonder what other things may be messed up... 457 // I wonder what other things may be messed up...
471 QString strDesc = ev.description(); 458 QString strDesc = ev.description();
472 int where = strDesc.find( "<" ); 459 int where = strDesc.find( "<" );
473 while ( where != -1 ) { 460 while ( where != -1 ) {
474 strDesc.remove( where, 1 ); 461 strDesc.remove( where, 1 );
475 strDesc.insert( where, "&#60;" ); 462 strDesc.insert( where, "&#60;" );
476 where = strDesc.find( "<", where ); 463 where = strDesc.find( "<", where );
477 } 464 }
478 465
479 QString strCat; 466 QString strCat;
480 // ### FIX later... 467 // ### FIX later...
481// QString strCat = ev.category(); 468// QString strCat = ev.category();
482// where = strCat.find( "<" ); 469// where = strCat.find( "<" );
483// while ( where != -1 ) { 470// while ( where != -1 ) {
484 // strCat.remove( where, 1 ); 471 // strCat.remove( where, 1 );
485 // strCat.insert( where, "&#60;" ); 472 // strCat.insert( where, "&#60;" );
486 // where = strCat.find( "<", where ); 473 // where = strCat.find( "<", where );
487// } 474// }
488 475
489 QString strLocation = ev.location(); 476 QString strLocation = ev.location();
490 while ( where != -1 ) { 477 while ( where != -1 ) {
491 strLocation.remove( where, 1 ); 478 strLocation.remove( where, 1 );
492 strLocation.insert( where, "&#60;" ); 479 strLocation.insert( where, "&#60;" );
493 where = strLocation.find( "<", where ); 480 where = strLocation.find( "<", where );
494 } 481 }
495 482
496 QString strNote = ev.notes(); 483 QString strNote = ev.notes();
497 where = strNote.find( "<" ); 484 where = strNote.find( "<" );
498 while ( where != -1 ) { 485 while ( where != -1 ) {
499 strNote.remove( where, 1 ); 486 strNote.remove( where, 1 );
500 strNote.insert( where, "&#60;" ); 487 strNote.insert( where, "&#60;" );
501 where = strNote.find( "<", where ); 488 where = strNote.find( "<", where );
502 } 489 }
503 490
504 QString str = "<b>" + strDesc + "</b><br>" 491 QString str = "<b>" + strDesc + "</b><br>"
505 + strLocation + "<br>" 492 + strLocation + "<br>"
506 + "<i>" + strCat + "</i>" 493 + "<i>" + strCat + "</i>"
507 + "<br>" + TimeString::longDateString( ev.date() ) 494 + "<br>" + TimeString::longDateString( ev.date() )
508 + "<br>"; 495 + "<br>";
509 496
510 if (ev.event().type() == Event::Normal ) 497 if (ev.event().type() == Event::Normal )
511 generateNormalTooltext( str, ev ); 498 generateNormalTooltext( str, ev );
512 else 499 else
513 generateAllDayTooltext( str ); 500 generateAllDayTooltext( str );
514 501
515 str += "<br><br>" + strNote; 502 str += "<br><br>" + strNote;
516 503
517 lblDesc->setText( str ); 504 lblDesc->setText( str );
518 lblDesc->resize( lblDesc->sizeHint() ); 505 lblDesc->resize( lblDesc->sizeHint() );
519 // move the label so it is "centerd" horizontally... 506 // move the label so it is "centerd" horizontally...
520 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); 507 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
521 lblDesc->show(); 508 lblDesc->show();
522} 509}
523 510
524void DateBookWeek::slotHideEvent() 511void DateBookWeek::slotHideEvent()
525{ 512{
526 tHide->start( 2000, true ); 513 tHide->start( 2000, true );
527} 514}
528 515
529void DateBookWeek::setStartViewTime( int startHere ) 516void DateBookWeek::setStartViewTime( int startHere )
530{ 517{
531 startTime = startHere; 518 startTime = startHere;
532 view->moveToHour( startTime ); 519 view->moveToHour( startTime );
533} 520}
534 521
535int DateBookWeek::startViewTime() const 522int DateBookWeek::startViewTime() const
536{ 523{
537 return startTime; 524 return startTime;
538} 525}
539 526
540void DateBookWeek::redraw() 527void DateBookWeek::redraw()
541{ 528{
542 getEvents(); 529 getEvents();
543} 530}
544 531
545void DateBookWeek::slotYearChanged( int y ) 532void DateBookWeek::slotYearChanged( int y )
546{ 533{
547 int totWeek; 534 int totWeek;
548 QDate d( y, 12, 31 ); 535 QDate d( y, 12, 31 );
549 int throwAway; 536 int throwAway;
550 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 537 calcWeek( d, totWeek, throwAway, bStartOnMonday );
551 while ( totWeek == 1 ) { 538 while ( totWeek == 1 ) {
552 d = d.addDays( -1 ); 539 d = d.addDays( -1 );
553 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 540 calcWeek( d, totWeek, throwAway, bStartOnMonday );
554 } 541 }
555} 542}
556 543
557void DateBookWeek::slotWeekChanged( bool onMonday ) 544void DateBookWeek::slotWeekChanged( bool onMonday )
558{ 545{
559 bStartOnMonday = onMonday; 546 bStartOnMonday = onMonday;
560 view->setStartOfWeek( bStartOnMonday ); 547 view->setStartOfWeek( bStartOnMonday );
561 header->setStartOfWeek( bStartOnMonday ); 548 header->setStartOfWeek( bStartOnMonday );
562 redraw(); 549 redraw();
563} 550}
564 551
565void DateBookWeek::slotClockChanged( bool ap ) 552void DateBookWeek::slotClockChanged( bool ap )
566{ 553{
567 ampm = ap; 554 ampm = ap;
568} 555}
569 556
570// return the date at the beginning of the week... 557// return the date at the beginning of the week...
571QDate DateBookWeek::weekDate() const 558QDate DateBookWeek::weekDate() const
572{ 559{
573 QDate d=bdate; 560 QDate d=bdate;
574 561
575 // Calculate offset to first day of week. 562 // Calculate offset to first day of week.
576 int dayoffset=d.dayOfWeek(); 563 int dayoffset=d.dayOfWeek();
577 if(bStartOnMonday) dayoffset--; 564 if(bStartOnMonday) dayoffset--;
565 else if( dayoffset == 7 )
566 dayoffset = 0;
578 567
579 return d.addDays(-dayoffset); 568 return d.addDays(-dayoffset);
580} 569}
581 570
582// this used to only be needed by datebook.cpp, but now we need it inside 571// this used to only be needed by datebook.cpp, but now we need it inside
583// week view since 572// week view since
584// we need to be able to figure out our total number of weeks on the fly... 573// we need to be able to figure out our total number of weeks on the fly...
585// this is probably the best place to put it.. 574// this is probably the best place to put it..
586 575
587// For Weeks that start on Monday... (EASY!) 576// For Weeks that start on Monday... (EASY!)
588// At the moment we will use ISO 8601 method for computing 577// At the moment we will use ISO 8601 method for computing
589// the week. Granted, other countries use other methods, 578// the week. Granted, other countries use other methods,
590// bet we aren't doing any Locale stuff at the moment. So, 579// bet we aren't doing any Locale stuff at the moment. So,
591// this should pass. This Algorithim is public domain and 580// this should pass. This Algorithim is public domain and
592// available at: 581// available at:
593// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 582// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
594// the week number is return, and the year number is returned in year 583// the week number is return, and the year number is returned in year
595// for Instance 2001/12/31 is actually the first week in 2002. 584// for Instance 2001/12/31 is actually the first week in 2002.
596// There is a more mathematical definition, but I will implement it when 585// There is a more mathematical definition, but I will implement it when
597// we are pass our deadline. 586// we are pass our deadline.
598 587
599// For Weeks that start on Sunday... (ahh... home rolled) 588// For Weeks that start on Sunday... (ahh... home rolled)
600// okay, if Jan 1 is on Friday or Saturday, 589// okay, if Jan 1 is on Friday or Saturday,
601// it will go to the pervious 590// it will go to the pervious
602// week... 591// week...
603 592
604bool calcWeek( const QDate &d, int &week, int &year, 593bool calcWeek( const QDate &d, int &week, int &year,
605 bool startOnMonday ) 594 bool startOnMonday )
606{ 595{
607 int weekNumber; 596 int weekNumber;
608 int yearNumber; 597 int yearNumber;
609 598
610 // remove a pesky warning, (Optimizations on g++) 599 // remove a pesky warning, (Optimizations on g++)
611 weekNumber = -1; 600 weekNumber = -1;
612 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 601 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
613 int dayOfWeek = d.dayOfWeek(); 602 int dayOfWeek = d.dayOfWeek();
614 603
615 if ( !d.isValid() ) 604 if ( !d.isValid() )
616 return false; 605 return false;
617 606
618 if ( startOnMonday ) { 607 if ( startOnMonday ) {
619 // find the Jan1Weekday; 608 // find the Jan1Weekday;
620 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 609 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
621 yearNumber = d.year() - 1; 610 yearNumber = d.year() - 1;
622 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 611 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
623 weekNumber = 53; 612 weekNumber = 53;
624 else 613 else
625 weekNumber = 52; 614 weekNumber = 52;
626 } else 615 } else
627 yearNumber = d.year(); 616 yearNumber = d.year();
628 if ( yearNumber == d.year() ) { 617 if ( yearNumber == d.year() ) {
629 int totalDays = 365; 618 int totalDays = 365;
630 if ( QDate::leapYear(yearNumber) ) 619 if ( QDate::leapYear(yearNumber) )
631 totalDays++; 620 totalDays++;
632 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 621 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
633 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 622 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
634 yearNumber++; 623 yearNumber++;
635 weekNumber = 1; 624 weekNumber = 1;
636 } 625 }
637 } 626 }
638 if ( yearNumber == d.year() ) { 627 if ( yearNumber == d.year() ) {
639 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 628 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
640 weekNumber = j / 7; 629 weekNumber = j / 7;
641 if ( jan1WeekDay > 4 ) 630 if ( jan1WeekDay > 4 )
642 weekNumber--; 631 weekNumber--;
643 } 632 }
644 } else { 633 } else {
645 // it's better to keep these cases separate... 634 // it's better to keep these cases separate...
646 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 635 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
647 && jan1WeekDay != 7 ) { 636 && jan1WeekDay != 7 ) {
648 yearNumber = d.year() - 1; 637 yearNumber = d.year() - 1;
649 if ( jan1WeekDay == 6 638 if ( jan1WeekDay == 6
650 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 639 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
651 weekNumber = 53; 640 weekNumber = 53;
652 }else 641 }else
653 weekNumber = 52; 642 weekNumber = 52;
654 } else 643 } else
655 yearNumber = d.year(); 644 yearNumber = d.year();
656 if ( yearNumber == d.year() ) { 645 if ( yearNumber == d.year() ) {
657 int totalDays = 365; 646 int totalDays = 365;
658 if ( QDate::leapYear( yearNumber ) ) 647 if ( QDate::leapYear( yearNumber ) )
659 totalDays++; 648 totalDays++;
660 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 649 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
661 yearNumber++; 650 yearNumber++;
662 weekNumber = 1; 651 weekNumber = 1;
663 } 652 }
664 } 653 }
665 if ( yearNumber == d.year() ) { 654 if ( yearNumber == d.year() ) {
666 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 655 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
667 weekNumber = j / 7; 656 weekNumber = j / 7;
668 if ( jan1WeekDay > 4 ) { 657 if ( jan1WeekDay > 4 ) {
669 weekNumber--; 658 weekNumber--;
670 } 659 }
671 } 660 }
672 } 661 }
673 year = yearNumber; 662 year = yearNumber;
674 week = weekNumber; 663 week = weekNumber;
675 return true; 664 return true;
676} 665}
677 666
diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp
index ff7626f..770410e 100644
--- a/core/pim/datebook/datebookweekheaderimpl.cpp
+++ b/core/pim/datebook/datebookweekheaderimpl.cpp
@@ -1,115 +1,123 @@
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#include "datebookweekheaderimpl.h" 20#include "datebookweekheaderimpl.h"
21#include "datebookweekheader.h" 21#include "datebookweekheader.h"
22#include "datebookweek.h" 22#include "datebookweek.h"
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qspinbox.h> 24#include <qspinbox.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/datebookmonth.h> 27#include <qpe/datebookmonth.h>
28 28
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30 30
31/* 31/*
32 * Constructs a DateBookWeekHeader which is a child of 'parent', with the 32 * Constructs a DateBookWeekHeader which is a child of 'parent', with the
33 * name 'name' and widget flags set to 'f' 33 * name 'name' and widget flags set to 'f'
34 */ 34 */
35DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) 35DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl )
36 : DateBookWeekHeaderBase( parent, name, fl ), 36 : DateBookWeekHeaderBase( parent, name, fl ),
37 bStartOnMonday( startOnMonday ) 37 bStartOnMonday( startOnMonday )
38{ 38{
39 setBackgroundMode( PaletteButton ); 39 setBackgroundMode( PaletteButton );
40 labelDate->setBackgroundMode( PaletteButton ); 40 labelDate->setBackgroundMode( PaletteButton );
41 backmonth->setPixmap( Resource::loadPixmap("fastback") ); 41 backmonth->setPixmap( Resource::loadPixmap("fastback") );
42 backweek->setPixmap( Resource::loadPixmap("back") ); 42 backweek->setPixmap( Resource::loadPixmap("back") );
43 forwardweek->setPixmap( Resource::loadPixmap("forward") ); 43 forwardweek->setPixmap( Resource::loadPixmap("forward") );
44 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); 44 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") );
45} 45}
46 46
47/* 47/*
48 * Destroys the object and frees any allocated resources 48 * Destroys the object and frees any allocated resources
49 */ 49 */
50DateBookWeekHeader::~DateBookWeekHeader() 50DateBookWeekHeader::~DateBookWeekHeader()
51{ 51{
52 // no need to delete child widgets, Qt does it all for us 52 // no need to delete child widgets, Qt does it all for us
53} 53}
54 54
55void DateBookWeekHeader::pickDate() 55void DateBookWeekHeader::pickDate()
56{ 56{
57 static QPopupMenu *m1 = 0; 57 static QPopupMenu *m1 = 0;
58 static DateBookMonth *picker = 0; 58 static DateBookMonth *picker = 0;
59 if ( !m1 ) { 59 if ( !m1 ) {
60 m1 = new QPopupMenu( this ); 60 m1 = new QPopupMenu( this );
61 picker = new DateBookMonth( m1, 0, TRUE ); 61 picker = new DateBookMonth( m1, 0, TRUE );
62 m1->insertItem( picker ); 62 m1->insertItem( picker );
63 connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); 63 connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) );
64 // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); 64 // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) );
65 } 65 }
66 picker->setDate( date.year(), date.month(), date.day() ); 66 picker->setDate( date.year(), date.month(), date.day() );
67 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); 67 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
68 picker->setFocus(); 68 picker->setFocus();
69} 69}
70 70
71void DateBookWeekHeader::nextMonth() 71void DateBookWeekHeader::nextMonth()
72{ 72{
73 qWarning("nextMonth() " );
73 setDate(date.addDays(28)); 74 setDate(date.addDays(28));
74} 75}
75void DateBookWeekHeader::prevMonth() 76void DateBookWeekHeader::prevMonth()
76{ 77{
78 qWarning("prevMonth() " );
77 setDate(date.addDays(-28)); 79 setDate(date.addDays(-28));
78} 80}
79void DateBookWeekHeader::nextWeek() 81void DateBookWeekHeader::nextWeek()
80{ 82{
83 qWarning("nextWeek() " );
81 setDate(date.addDays(7)); 84 setDate(date.addDays(7));
82} 85}
83void DateBookWeekHeader::prevWeek() 86void DateBookWeekHeader::prevWeek()
84{ 87{
88 qWarning("prevWeek() ");
85 setDate(date.addDays(-7)); 89 setDate(date.addDays(-7));
86} 90}
87 91
88void DateBookWeekHeader::setDate( int y, int m, int d ) 92void DateBookWeekHeader::setDate( int y, int m, int d )
89{ 93{
90 setDate(QDate(y,m,d)); 94 setDate(QDate(y,m,d));
91} 95}
92 96
93void DateBookWeekHeader::setDate(const QDate &d) { 97void DateBookWeekHeader::setDate(const QDate &d) {
94 int year,week,dayofweek; 98 int year,week,dayofweek;
95 date=d; 99 date=d;
96 dayofweek=d.dayOfWeek(); 100 dayofweek=d.dayOfWeek();
97 if(bStartOnMonday) dayofweek--; 101 if(bStartOnMonday)
102 dayofweek--;
103 else if( dayofweek == 7 )
104 /* we already have the right day -7 would lead to the current week..*/
105 dayofweek = 0;
106
98 date=date.addDays(-dayofweek); 107 date=date.addDays(-dayofweek);
99
100 calcWeek(date,week,year,bStartOnMonday); 108 calcWeek(date,week,year,bStartOnMonday);
101 QDate start=date; 109 QDate start=date;
102 QDate stop=start.addDays(6); 110 QDate stop=start.addDays(6);
103 labelDate->setText( QString::number(start.day()) + "." + 111 labelDate->setText( QString::number(start.day()) + "." +
104 start.monthName(start.month()) + "-" + 112 start.monthName(start.month()) + "-" +
105 QString::number(stop.day()) + "." + 113 QString::number(stop.day()) + "." +
106 start.monthName(stop.month()) +" ("+ 114 start.monthName(stop.month()) +" ("+
107 tr("w")+":"+QString::number( week ) +")"); 115 tr("w")+":"+QString::number( week ) +")");
108 emit dateChanged(date); 116 emit dateChanged(date);
109} 117}
110 118
111void DateBookWeekHeader::setStartOfWeek( bool onMonday ) 119void DateBookWeekHeader::setStartOfWeek( bool onMonday )
112{ 120{
113 bStartOnMonday = onMonday; 121 bStartOnMonday = onMonday;
114 setDate( date ); 122 setDate( date );
115} 123}
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp
index 7817042..aad1f3a 100644
--- a/core/pim/datebook/datebookweeklst.cpp
+++ b/core/pim/datebook/datebookweeklst.cpp
@@ -1,386 +1,392 @@
1#include "datebookweeklst.h" 1#include "datebookweeklst.h"
2 2
3#include "datebookweekheaderimpl.h" 3#include "datebookweekheaderimpl.h"
4 4
5#include "datebook.h" 5#include "datebook.h"
6 6
7#include <qpe/calendar.h> 7#include <qpe/calendar.h>
8#include <qpe/datebookdb.h> 8#include <qpe/datebookdb.h>
9#include <qpe/event.h> 9#include <qpe/event.h>
10#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
11#include <qpe/timestring.h> 11#include <qpe/timestring.h>
12#include <qpe/datebookmonth.h> 12#include <qpe/datebookmonth.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/resource.h> 14#include <qpe/resource.h>
15 15
16#include <qdatetime.h> 16#include <qdatetime.h>
17#include <qheader.h> 17#include <qheader.h>
18#include <qlabel.h> 18#include <qlabel.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qpainter.h> 20#include <qpainter.h>
21#include <qpopupmenu.h> 21#include <qpopupmenu.h>
22#include <qtimer.h> 22#include <qtimer.h>
23#include <qstyle.h> 23#include <qstyle.h>
24#include <qtoolbutton.h> 24#include <qtoolbutton.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qsizepolicy.h> 26#include <qsizepolicy.h>
27#include <qabstractlayout.h> 27#include <qabstractlayout.h>
28#include <qtl.h> 28#include <qtl.h>
29 29
30bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); 30bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false);
31 31
32DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) 32DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl)
33 : DateBookWeekLstHeaderBase(parent, name, fl) 33 : DateBookWeekLstHeaderBase(parent, name, fl)
34{ 34{
35 setBackgroundMode( PaletteButton ); 35 setBackgroundMode( PaletteButton );
36 labelDate->setBackgroundMode( PaletteButton ); 36 labelDate->setBackgroundMode( PaletteButton );
37 forwardweek->setBackgroundMode( PaletteButton ); 37 forwardweek->setBackgroundMode( PaletteButton );
38 forwardweek->setPixmap( Resource::loadPixmap("forward") ); 38 forwardweek->setPixmap( Resource::loadPixmap("forward") );
39 forwardmonth->setBackgroundMode( PaletteButton ); 39 forwardmonth->setBackgroundMode( PaletteButton );
40 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); 40 forwardmonth->setPixmap( Resource::loadPixmap("fastforward") );
41 backweek->setBackgroundMode( PaletteButton ); 41 backweek->setBackgroundMode( PaletteButton );
42 backweek->setPixmap( Resource::loadPixmap("back") ); 42 backweek->setPixmap( Resource::loadPixmap("back") );
43 backmonth->setBackgroundMode( PaletteButton ); 43 backmonth->setBackgroundMode( PaletteButton );
44 backmonth->setPixmap( Resource::loadPixmap("fastback") ); 44 backmonth->setPixmap( Resource::loadPixmap("fastback") );
45 DateBookWeekLstHeaderBaseLayout->setSpacing(0); 45 DateBookWeekLstHeaderBaseLayout->setSpacing(0);
46 DateBookWeekLstHeaderBaseLayout->setMargin(0); 46 DateBookWeekLstHeaderBaseLayout->setMargin(0);
47 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); 47 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
48 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 48 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
49 49
50 connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); 50 connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth()));
51 connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); 51 connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek()));
52 connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); 52 connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek()));
53 connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); 53 connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth()));
54 connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); 54 connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate()));
55 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); 55 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool)));
56 bStartOnMonday=onM; 56 bStartOnMonday=onM;
57} 57}
58DateBookWeekLstHeader::~DateBookWeekLstHeader(){} 58DateBookWeekLstHeader::~DateBookWeekLstHeader(){}
59 59
60void DateBookWeekLstHeader::setDate(const QDate &d) { 60void DateBookWeekLstHeader::setDate(const QDate &d) {
61 int year,week,dayofweek; 61 int year,week,dayofweek;
62 date=d; 62 date=d;
63 dayofweek=d.dayOfWeek(); 63 dayofweek=d.dayOfWeek();
64 if(bStartOnMonday) dayofweek--; 64 if(bStartOnMonday)
65 dayofweek--;
66 else if( dayofweek == 7 )
67 /* we already have the right day -7 would lead to the same week */
68 dayofweek = 0;
69
65 date=date.addDays(-dayofweek); 70 date=date.addDays(-dayofweek);
66 71
67 calcWeek(date,week,year,bStartOnMonday); 72 calcWeek(date,week,year,bStartOnMonday);
68 QDate start=date; 73 QDate start=date;
69 QDate stop=start.addDays(6); 74 QDate stop=start.addDays(6);
70 labelDate->setText( QString::number(start.day()) + "." + 75 labelDate->setText( QString::number(start.day()) + "." +
71 start.monthName(start.month()) + "-" + 76 start.monthName(start.month()) + "-" +
72 QString::number(stop.day()) + "." + 77 QString::number(stop.day()) + "." +
73 start.monthName(stop.month()) +" ("+ 78 start.monthName(stop.month()) +" ("+
74 tr("w")+":"+QString::number( week ) +")"); 79 tr("w")+":"+QString::number( week ) +")");
75 emit dateChanged(date); 80 emit dateChanged(date);
76} 81}
77 82
78void DateBookWeekLstHeader::pickDate() { 83void DateBookWeekLstHeader::pickDate() {
79 static QPopupMenu *m1 = 0; 84 static QPopupMenu *m1 = 0;
80 static DateBookMonth *picker = 0; 85 static DateBookMonth *picker = 0;
81 if ( !m1 ) { 86 if ( !m1 ) {
82 m1 = new QPopupMenu( this ); 87 m1 = new QPopupMenu( this );
83 picker = new DateBookMonth( m1, 0, TRUE ); 88 picker = new DateBookMonth( m1, 0, TRUE );
84 m1->insertItem( picker ); 89 m1->insertItem( picker );
85 connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); 90 connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) );
86 //connect( m1, SIGNAL( aboutToHide() ), 91 //connect( m1, SIGNAL( aboutToHide() ),
87 //this, SLOT( gotHide() ) ); 92 //this, SLOT( gotHide() ) );
88 } 93 }
89 picker->setDate( date.year(), date.month(), date.day() ); 94 picker->setDate( date.year(), date.month(), date.day() );
90 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); 95 m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
91 picker->setFocus(); 96 picker->setFocus();
92} 97}
93void DateBookWeekLstHeader::setDate(int y, int m, int d) { 98void DateBookWeekLstHeader::setDate(int y, int m, int d) {
94 setDate(QDate(y,m,d)); 99 setDate(QDate(y,m,d));
95} 100}
96 101
97void DateBookWeekLstHeader::nextWeek() { 102void DateBookWeekLstHeader::nextWeek() {
98 setDate(date.addDays(7)); 103 setDate(date.addDays(7));
99} 104}
100void DateBookWeekLstHeader::prevWeek() { 105void DateBookWeekLstHeader::prevWeek() {
101 setDate(date.addDays(-7)); 106 setDate(date.addDays(-7));
102} 107}
103void DateBookWeekLstHeader::nextMonth() 108void DateBookWeekLstHeader::nextMonth()
104{ 109{
105 setDate(date.addDays(28)); 110 setDate(date.addDays(28));
106} 111}
107void DateBookWeekLstHeader::prevMonth() 112void DateBookWeekLstHeader::prevMonth()
108{ 113{
109 setDate(date.addDays(-28)); 114 setDate(date.addDays(-28));
110} 115}
111 116
112DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */, 117DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */,
113 QWidget* parent, 118 QWidget* parent,
114 const char* name, 119 const char* name,
115 WFlags fl ) 120 WFlags fl )
116 : DateBookWeekLstDayHdrBase(parent, name, fl) { 121 : DateBookWeekLstDayHdrBase(parent, name, fl) {
117 122
118 date=d; 123 date=d;
119 124
120 static const char *wdays={"MTWTFSSM"}; 125 static const QString wdays=tr("MTWTFSSM", "Week days");
121 char day=wdays[d.dayOfWeek()-1]; 126 char day=wdays[d.dayOfWeek()-1];
122 127
123 label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); 128 label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) );
124 add->setText("+"); 129 add->setText("+");
125 130
126 if (d == QDate::currentDate()) { 131 if (d == QDate::currentDate()) {
127 QPalette pal=label->palette(); 132 QPalette pal=label->palette();
128 pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); 133 pal.setColor(QColorGroup::Foreground, QColor(0,0,255));
129 label->setPalette(pal); 134 label->setPalette(pal);
130 135
131 /* 136 /*
132 QFont f=label->font(); 137 QFont f=label->font();
133 f.setItalic(true); 138 f.setItalic(true);
134 label->setFont(f); 139 label->setFont(f);
135 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); 140 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor()));
136 */ 141 */
137 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday 142 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday
138 QPalette pal=label->palette(); 143 QPalette pal=label->palette();
139 pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); 144 pal.setColor(QColorGroup::Foreground, QColor(255,0,0));
140 label->setPalette(pal); 145 label->setPalette(pal);
141 } 146 }
142 147
143 connect (label, SIGNAL(clicked()), this, SLOT(showDay())); 148 connect (label, SIGNAL(clicked()), this, SLOT(showDay()));
144 connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); 149 connect (add, SIGNAL(clicked()), this, SLOT(newEvent()));
145} 150}
146 151
147void DateBookWeekLstDayHdr::showDay() { 152void DateBookWeekLstDayHdr::showDay() {
148 emit showDate(date.year(), date.month(), date.day()); 153 emit showDate(date.year(), date.month(), date.day());
149} 154}
150 155
151void DateBookWeekLstDayHdr::newEvent() { 156void DateBookWeekLstDayHdr::newEvent() {
152 QDateTime start, stop; 157 QDateTime start, stop;
153 start=stop=date; 158 start=stop=date;
154 start.setTime(QTime(10,0)); 159 start.setTime(QTime(10,0));
155 stop.setTime(QTime(12,0)); 160 stop.setTime(QTime(12,0));
156 161
157 emit addEvent(start,stop,"",0); 162 emit addEvent(start,stop,"",0);
158} 163}
159DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, 164DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev,
160 int weeklistviewconfig, 165 int weeklistviewconfig,
161 QWidget* parent, 166 QWidget* parent,
162 const char* name, 167 const char* name,
163 WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) 168 WFlags fl ) : OClickableLabel(parent,name,fl), event(ev)
164{ 169{
165 // old values... lastday = "__|__", middle=" |---", Firstday="00:00", 170 // old values... lastday = "__|__", middle=" |---", Firstday="00:00",
166 QString s,start,middle,end,day; 171 QString s,start,middle,end,day;
167 172
168 qDebug("weeklistviewconfig=%d",weeklistviewconfig); 173 qDebug("weeklistviewconfig=%d",weeklistviewconfig);
169 if(weeklistviewconfig==NONE) {// No times displayed. 174 if(weeklistviewconfig==NONE) {// No times displayed.
170 // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); 175 // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute());
171 // middle.sprintf("<--->"); 176 // middle.sprintf("<--->");
172 // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); 177 // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute());
173 // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); 178 // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute());
174 } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time. 179 } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time.
175 start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); 180 start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute());
176 middle.sprintf(" |---"); 181 middle.sprintf(" |---");
177 end.sprintf("__|__"); 182 end.sprintf("__|__");
178 day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); 183 day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute());
179 } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. 184 } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times.
180 start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); 185 start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute());
181 middle.sprintf("<--->"); 186 middle.sprintf("<--->");
182 end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); 187 end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute());
183 day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); 188 day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute());
184 } 189 }
185 190
186 if(ev.event().type() == Event::Normal) { 191 if(ev.event().type() == Event::Normal) {
187 if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event. 192 if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event.
188 s=day; 193 s=day;
189 } else if(ev.startDate()==ev.date()) {// start event. 194 } else if(ev.startDate()==ev.date()) {// start event.
190 s=start; 195 s=start;
191 } else if(ev.endDate()==ev.date()) { // end event. 196 } else if(ev.endDate()==ev.date()) { // end event.
192 s=end; 197 s=end;
193 } else {// middle day. 198 } else {// middle day.
194 s=middle; 199 s=middle;
195 } 200 }
196 } else { 201 } else {
197 s=""; 202 s="";
198 } 203 }
199 setText(QString(s) + " " + ev.description()); 204 setText(QString(s) + " " + ev.description());
200 connect(this, SIGNAL(clicked()), this, SLOT(editMe())); 205 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
201 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); 206 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
202} 207}
203void DateBookWeekLstEvent::editMe() { 208void DateBookWeekLstEvent::editMe() {
204 emit editEvent(event.event()); 209 emit editEvent(event.event());
205} 210}
206 211
207 212
208DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, 213DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
209 const QDate &d, bool onM, 214 const QDate &d, bool onM,
210 QWidget* parent, 215 QWidget* parent,
211 const char* name, WFlags fl) 216 const char* name, WFlags fl)
212 : QWidget( parent, name, fl ) 217 : QWidget( parent, name, fl )
213{ 218{
214 Config config("DateBook"); 219 Config config("DateBook");
215 config.setGroup("Main"); 220 config.setGroup("Main");
216 int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); 221 int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL);
217 qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); 222 qDebug("Read weeklistviewconfig: %d",weeklistviewconfig);
218 223
219 bStartOnMonday=onM; 224 bStartOnMonday=onM;
220 setPalette(white); 225 setPalette(white);
221 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); 226 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
222 227
223 QVBoxLayout *layout = new QVBoxLayout( this ); 228 QVBoxLayout *layout = new QVBoxLayout( this );
224 229
225 qBubbleSort(ev); 230 qBubbleSort(ev);
226 QValueListIterator<EffectiveEvent> it; 231 QValueListIterator<EffectiveEvent> it;
227 it=ev.begin(); 232 it=ev.begin();
228 233
229 int dayOrder[7]; 234 int dayOrder[7];
230 if (bStartOnMonday) { 235 if (bStartOnMonday) {
231 for (int d=0; d<7; d++) dayOrder[d]=d+1; 236 for (int d=0; d<7; d++) dayOrder[d]=d+1;
232 } else { 237 } else {
233 for (int d=0; d<7; d++) dayOrder[d]=d; 238 for (int d=0; d<7; d++) dayOrder[d]=d;
234 dayOrder[0]=7; 239 dayOrder[0]=7;
235 } 240 }
236 241
237 // Calculate offset to first day of week. 242 // Calculate offset to first day of week.
238 int dayoffset=d.dayOfWeek(); 243 int dayoffset=d.dayOfWeek();
239 if(bStartOnMonday) dayoffset--; 244 if(bStartOnMonday) dayoffset--;
245 else if( dayoffset == 7 ) dayoffset = 0;
240 246
241 for (int i=0; i<7; i++) { 247 for (int i=0; i<7; i++) {
242 // Header 248 // Header
243 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); 249 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this);
244 connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 250 connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
245 connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), 251 connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)),
246 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 252 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
247 layout->addWidget(hdr); 253 layout->addWidget(hdr);
248 254
249 // Events 255 // Events
250 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { 256 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) {
251 if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. 257 if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day.
252 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); 258 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this);
253 layout->addWidget(l); 259 layout->addWidget(l);
254 connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 260 connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
255 } 261 }
256 it++; 262 it++;
257 } 263 }
258 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); 264 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
259 } 265 }
260} 266}
261DateBookWeekLstView::~DateBookWeekLstView(){} 267DateBookWeekLstView::~DateBookWeekLstView(){}
262void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} 268void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();}
263 269
264DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, 270DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1,
265 QValueList<EffectiveEvent> &ev2, 271 QValueList<EffectiveEvent> &ev2,
266 QDate &d, bool onM, 272 QDate &d, bool onM,
267 QWidget* parent, 273 QWidget* parent,
268 const char* name, WFlags fl) 274 const char* name, WFlags fl)
269 : QWidget( parent, name, fl ) 275 : QWidget( parent, name, fl )
270{ 276{
271 QHBoxLayout *layout = new QHBoxLayout( this ); 277 QHBoxLayout *layout = new QHBoxLayout( this );
272 278
273 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); 279 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this);
274 layout->addWidget(w); 280 layout->addWidget(w);
275 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 281 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
276 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 282 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
277 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), 283 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)),
278 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 284 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
279 285
280 286
281 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); 287 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this);
282 layout->addWidget(w); 288 layout->addWidget(w);
283 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 289 connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
284 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 290 connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
285 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), 291 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)),
286 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 292 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
287} 293}
288 294
289DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, 295DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
290 QWidget *parent, 296 QWidget *parent,
291 const char *name ) 297 const char *name )
292 : QWidget( parent, name ), 298 : QWidget( parent, name ),
293 db( newDB ), 299 db( newDB ),
294 startTime( 0 ), 300 startTime( 0 ),
295 ampm( ap ), 301 ampm( ap ),
296 bStartOnMonday(onM) 302 bStartOnMonday(onM)
297{ 303{
298 setFocusPolicy(StrongFocus); 304 setFocusPolicy(StrongFocus);
299 layout = new QVBoxLayout( this ); 305 layout = new QVBoxLayout( this );
300 layout->setMargin(0); 306 layout->setMargin(0);
301 307
302 header=new DateBookWeekLstHeader(onM, this); 308 header=new DateBookWeekLstHeader(onM, this);
303 layout->addWidget( header ); 309 layout->addWidget( header );
304 connect(header, SIGNAL(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &))); 310 connect(header, SIGNAL(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &)));
305 connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); 311 connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool)));
306 312
307 scroll=new QScrollView(this); 313 scroll=new QScrollView(this);
308 scroll->setResizePolicy(QScrollView::AutoOneFit); 314 scroll->setResizePolicy(QScrollView::AutoOneFit);
309 layout->addWidget(scroll); 315 layout->addWidget(scroll);
310 316
311 view=NULL; 317 view=NULL;
312 Config config("DateBook"); 318 Config config("DateBook");
313 config.setGroup("Main"); 319 config.setGroup("Main");
314 dbl=config.readBoolEntry("weeklst_dbl", false); 320 dbl=config.readBoolEntry("weeklst_dbl", false);
315 header->dbl->setOn(dbl); 321 header->dbl->setOn(dbl);
316} 322}
317DateBookWeekLst::~DateBookWeekLst(){ 323DateBookWeekLst::~DateBookWeekLst(){
318 Config config("DateBook"); 324 Config config("DateBook");
319 config.setGroup("Main"); 325 config.setGroup("Main");
320 config.writeEntry("weeklst_dbl", dbl); 326 config.writeEntry("weeklst_dbl", dbl);
321} 327}
322 328
323void DateBookWeekLst::setDate(const QDate &d) { 329void DateBookWeekLst::setDate(const QDate &d) {
324 bdate=d; 330 bdate=d;
325 header->setDate(d); 331 header->setDate(d);
326} 332}
327 333
328void DateBookWeekLst::setDbl(bool on) { 334void DateBookWeekLst::setDbl(bool on) {
329 dbl=on; 335 dbl=on;
330 redraw(); 336 redraw();
331} 337}
332void DateBookWeekLst::redraw() {getEvents();} 338void DateBookWeekLst::redraw() {getEvents();}
333 339
334QDate DateBookWeekLst::date() { 340QDate DateBookWeekLst::date() {
335 return bdate; 341 return bdate;
336} 342}
337 343
338void DateBookWeekLst::getEvents() { 344void DateBookWeekLst::getEvents() {
339 QDate start = date(); 345 QDate start = date();
340 QDate stop = start.addDays(6); 346 QDate stop = start.addDays(6);
341 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); 347 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop);
342 348
343 if (view) delete view; 349 if (view) delete view;
344 if (dbl) { 350 if (dbl) {
345 QDate start2=start.addDays(7); 351 QDate start2=start.addDays(7);
346 stop=start2.addDays(6); 352 stop=start2.addDays(6);
347 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); 353 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop);
348 view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); 354 view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll);
349 } else { 355 } else {
350 view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); 356 view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll);
351 } 357 }
352 358
353 connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); 359 connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &)));
354 connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); 360 connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
355 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), 361 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)),
356 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); 362 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)));
357 363
358 scroll->addChild(view); 364 scroll->addChild(view);
359 view->show(); 365 view->show();
360 scroll->updateScrollBars(); 366 scroll->updateScrollBars();
361} 367}
362 368
363void DateBookWeekLst::dateChanged(QDate &newdate) { 369void DateBookWeekLst::dateChanged(QDate &newdate) {
364 bdate=newdate; 370 bdate=newdate;
365 getEvents(); 371 getEvents();
366} 372}
367 373
368void DateBookWeekLst::keyPressEvent(QKeyEvent *e) 374void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
369{ 375{
370 switch(e->key()) { 376 switch(e->key()) {
371 case Key_Up: 377 case Key_Up:
372 scroll->scrollBy(0, -20); 378 scroll->scrollBy(0, -20);
373 break; 379 break;
374 case Key_Down: 380 case Key_Down:
375 scroll->scrollBy(0, 20); 381 scroll->scrollBy(0, 20);
376 break; 382 break;
377 case Key_Left: 383 case Key_Left:
378 header->prevWeek(); 384 header->prevWeek();
379 break; 385 break;
380 case Key_Right: 386 case Key_Right:
381 header->nextWeek(); 387 header->nextWeek();
382 break; 388 break;
383 default: 389 default:
384 e->ignore(); 390 e->ignore();
385 } 391 }
386} 392}
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp
index 13d2ce2..d9e5225 100644
--- a/core/pim/datebook/dateentryimpl.cpp
+++ b/core/pim/datebook/dateentryimpl.cpp
@@ -1,574 +1,576 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "dateentryimpl.h" 21#include "dateentryimpl.h"
22#include "repeatentry.h" 22#include "repeatentry.h"
23 23
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/categoryselect.h> 25#include <qpe/categoryselect.h>
26#include <qpe/datebookmonth.h> 26#include <qpe/datebookmonth.h>
27#include <qpe/global.h> 27#include <qpe/global.h>
28#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
29#include <qpe/timestring.h> 29#include <qpe/timestring.h>
30#include <qpe/tzselect.h> 30#include <qpe/tzselect.h>
31 31
32#include <qevent.h> 32#include <qevent.h>
33#include <qcheckbox.h> 33#include <qcheckbox.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qmultilineedit.h> 37#include <qmultilineedit.h>
38#include <qpopupmenu.h> 38#include <qpopupmenu.h>
39#include <qscrollview.h> 39#include <qscrollview.h>
40#include <qspinbox.h> 40#include <qspinbox.h>
41#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42 42
43#include <opie/otimepicker.h> 43#include <opie/otimepicker.h>
44#include "onoteedit.h" 44#include "onoteedit.h"
45 45
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49/* 49/*
50 * Constructs a DateEntry which is a child of 'parent', with the 50 * Constructs a DateEntry which is a child of 'parent', with the
51 * name 'name' and widget flags set to 'f' 51 * name 'name' and widget flags set to 'f'
52 * 52 *
53 * The dialog will by default be modeless, unless you set 'modal' to 53 * The dialog will by default be modeless, unless you set 'modal' to
54 * TRUE to construct a modal dialog. 54 * TRUE to construct a modal dialog.
55 */ 55 */
56 56
57DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, 57DateEntry::DateEntry( bool startOnMonday, const QDateTime &start,
58 const QDateTime &end, bool whichClock, QWidget* parent, 58 const QDateTime &end, bool whichClock, QWidget* parent,
59 const char* name ) 59 const char* name )
60 : DateEntryBase( parent, name ), 60 : DateEntryBase( parent, name ),
61 ampm( whichClock ), 61 ampm( whichClock ),
62 startWeekOnMonday( startOnMonday ), 62 startWeekOnMonday( startOnMonday ),
63 m_showStart(true) 63 m_showStart(true)
64{ 64{
65 init(); 65 init();
66 setDates(start,end); 66 setDates(start,end);
67 setFocusProxy(comboDescription); 67 setFocusProxy(comboDescription);
68} 68}
69 69
70bool DateEntry::eventFilter(QObject *obj, QEvent *ev ) 70bool DateEntry::eventFilter(QObject *obj, QEvent *ev )
71{ 71{
72 if( ev->type() == QEvent::FocusIn ){ 72 if( ev->type() == QEvent::FocusIn ){
73 if( obj == comboStart ){ 73 if( obj == comboStart ){
74 timePickerStart->setHour(startTime.hour()); 74 timePickerStart->setHour(startTime.hour());
75 timePickerStart->setMinute(startTime.minute()); 75 timePickerStart->setMinute(startTime.minute());
76 TimePickerLabel->setText( tr("Start Time" ) ); 76 TimePickerLabel->setText( tr("Start Time" ) );
77 m_showStart= true; 77 m_showStart= true;
78 }else if( obj == comboEnd ){ 78 }else if( obj == comboEnd ){
79 timePickerStart->setHour(endTime.hour()); 79 timePickerStart->setHour(endTime.hour());
80 timePickerStart->setMinute(endTime.minute()); 80 timePickerStart->setMinute(endTime.minute());
81 TimePickerLabel->setText( tr("End Time") ); 81 TimePickerLabel->setText( tr("End Time") );
82 m_showStart = false; 82 m_showStart = false;
83 } 83 }
84 } else if( ev->type() == QEvent::FocusOut ){ 84 } else if( ev->type() == QEvent::FocusOut ){
85// if( obj == comboEnd ){ 85// if( obj == comboEnd ){
86// QString s; 86// QString s;
87// s.sprintf("%.2d:%.2d",endTime.hour(), endTime.minute()); 87// s.sprintf("%.2d:%.2d",endTime.hour(), endTime.minute());
88// comboEnd->setText(s); 88// comboEnd->setText(s);
89// } 89// }
90// else if( obj == comboStart ){ 90// else if( obj == comboStart ){
91// QString s; 91// QString s;
92// s.sprintf("%.2d:%.2d",startTime.hour(), startTime.minute()); 92// s.sprintf("%.2d:%.2d",startTime.hour(), startTime.minute());
93// comboStart->setText(s); 93// comboStart->setText(s);
94// } 94// }
95 } 95 }
96 96
97 return false; 97 return false;
98} 98}
99 99
100static void addOrPick( QComboBox* combo, const QString& t ) 100static void addOrPick( QComboBox* combo, const QString& t )
101{ 101{
102 // Pick an item if one excists 102 // Pick an item if one excists
103 for (int i=0; i<combo->count(); i++) { 103 for (int i=0; i<combo->count(); i++) {
104 if ( combo->text(i) == t ) { 104 if ( combo->text(i) == t ) {
105 combo->setCurrentItem(i); 105 combo->setCurrentItem(i);
106 return; 106 return;
107 } 107 }
108 } 108 }
109 109
110 // Else add one 110 // Else add one
111 combo->insertItem(t); 111 combo->insertItem(t);
112 combo->setCurrentItem(combo->count()-1); 112 combo->setCurrentItem(combo->count()-1);
113} 113}
114 114
115DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, 115DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock,
116 QWidget* parent, const char* name ) 116 QWidget* parent, const char* name )
117 : DateEntryBase( parent, name ), 117 : DateEntryBase( parent, name ),
118 ampm( whichClock ), 118 ampm( whichClock ),
119 startWeekOnMonday( startOnMonday ), 119 startWeekOnMonday( startOnMonday ),
120 m_showStart(true) 120 m_showStart(true)
121 121
122{ 122{
123 init(); 123 init();
124 setDates(event.start(),event.end()); 124 setDates(event.start(),event.end());
125 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); 125 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") );
126 if(!event.description().isEmpty()) 126 if(!event.description().isEmpty())
127 addOrPick( comboDescription, event.description() ); 127 addOrPick( comboDescription, event.description() );
128 if(!event.location().isEmpty()) 128 if(!event.location().isEmpty())
129 addOrPick( comboLocation, event.location() ); 129 addOrPick( comboLocation, event.location() );
130 checkAlarm->setChecked( event.hasAlarm() ); 130 checkAlarm->setChecked( event.hasAlarm() );
131 checkAllDay->setChecked( event.type() == Event::AllDay ); 131 checkAllDay->setChecked( event.type() == Event::AllDay );
132 if(!event.notes().isEmpty()) noteStr=event.notes(); 132 if(!event.notes().isEmpty()) noteStr=event.notes();
133 else noteStr=""; 133 else noteStr="";
134 spinAlarm->setValue(event.alarmTime()); 134 spinAlarm->setValue(event.alarmTime());
135 if ( event.alarmSound() != Event::Silent ) 135 if ( event.alarmSound() != Event::Silent )
136 comboSound->setCurrentItem( 1 ); 136 comboSound->setCurrentItem( 1 );
137 if ( event.hasRepeat() ) { 137 if ( event.hasRepeat() ) {
138 rp = event.repeatPattern(); 138 rp = event.repeatPattern();
139 cmdRepeat->setText( tr("Repeat...") ); 139 cmdRepeat->setText( tr("Repeat...") );
140 } 140 }
141 setRepeatLabel(); 141 setRepeatLabel();
142} 142}
143 143
144void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) 144void DateEntry::setDates( const QDateTime& s, const QDateTime& e )
145{ 145{
146 startDate = s.date(); 146 startDate = s.date();
147 endDate = e.date(); 147 endDate = e.date();
148 startTime = s.time(); 148 startTime = s.time();
149 endTime = e.time(); 149 endTime = e.time();
150 150
151 startDateChanged( s.date().year(), s.date().month(), s.date().day() ); 151 startDateChanged( s.date().year(), s.date().month(), s.date().day() );
152 endDateChanged( e.date().year(), e.date().month(), e.date().day() ); 152 endDateChanged( e.date().year(), e.date().month(), e.date().day() );
153 153
154 updateTimeEdit(true,true); 154 updateTimeEdit(true,true);
155} 155}
156 156
157void DateEntry::updateTimeEdit(bool s, bool e) { 157void DateEntry::updateTimeEdit(bool s, bool e) {
158 158
159 // Comboboxes 159 // Comboboxes
160 QString strStart, strEnd; 160 QString strStart, strEnd;
161 int shour, ehour; 161 int shour, ehour;
162 if ( ampm ) { 162 if ( ampm ) {
163 shour = startTime.hour(); 163 shour = startTime.hour();
164 ehour = endTime.hour(); 164 ehour = endTime.hour();
165 if ( shour >= 12 ) { 165 if ( shour >= 12 ) {
166 if ( shour > 12 ) 166 if ( shour > 12 )
167 shour -= 12; 167 shour -= 12;
168 strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); 168 strStart.sprintf( "%d:%02d PM", shour, startTime.minute() );
169 } else { 169 } else {
170 if ( shour == 0 ) 170 if ( shour == 0 )
171 shour = 12; 171 shour = 12;
172 strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); 172 strStart.sprintf( "%d:%02d AM", shour, startTime.minute() );
173 } 173 }
174 if ( ehour == 24 && endTime.minute() == 0 ) { 174 if ( ehour == 24 && endTime.minute() == 0 ) {
175 strEnd = "11:59 PM"; // or "midnight" 175 strEnd = "11:59 PM"; // or "midnight"
176 } else if ( ehour >= 12 ) { 176 } else if ( ehour >= 12 ) {
177 if ( ehour > 12 ) 177 if ( ehour > 12 )
178 ehour -= 12; 178 ehour -= 12;
179 strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); 179 strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() );
180 } else { 180 } else {
181 if ( ehour == 0 ) 181 if ( ehour == 0 )
182 ehour = 12; 182 ehour = 12;
183 strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); 183 strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() );
184 } 184 }
185 } else { 185 } else {
186 strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); 186 strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() );
187 strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); 187 strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() );
188 } 188 }
189 189
190 if (s) comboStart->setText(strStart); 190 if (s) comboStart->setText(strStart);
191 if (e) comboEnd->setText(strEnd); 191 if (e) comboEnd->setText(strEnd);
192} 192}
193 193
194void DateEntry::init() 194void DateEntry::init()
195{ 195{
196 comboDescription->setInsertionPolicy(QComboBox::AtCurrent); 196 comboDescription->setInsertionPolicy(QComboBox::AtCurrent);
197 comboLocation->setInsertionPolicy(QComboBox::AtCurrent); 197 comboLocation->setInsertionPolicy(QComboBox::AtCurrent);
198 198
199 initCombos(); 199 initCombos();
200 QPopupMenu *m1 = new QPopupMenu( this ); 200 QPopupMenu *m1 = new QPopupMenu( this );
201 startPicker = new DateBookMonth( m1, 0, TRUE ); 201 startPicker = new DateBookMonth( m1, 0, TRUE );
202 m1->insertItem( startPicker ); 202 m1->insertItem( startPicker );
203 buttonStart->setPopup( m1 ); 203 buttonStart->setPopup( m1 );
204 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), 204 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ),
205 this, SLOT( startDateChanged( int, int, int ) ) ); 205 this, SLOT( startDateChanged( int, int, int ) ) );
206 206
207 //Let start button change both start and end dates 207 //Let start button change both start and end dates
208 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), 208 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ),
209 this, SLOT( endDateChanged( int, int, int ) ) ); 209 this, SLOT( endDateChanged( int, int, int ) ) );
210 connect( qApp, SIGNAL( clockChanged( bool ) ), 210 connect( qApp, SIGNAL( clockChanged( bool ) ),
211 this, SLOT( slotChangeClock( bool ) ) ); 211 this, SLOT( slotChangeClock( bool ) ) );
212 connect( qApp, SIGNAL(weekChanged(bool)), 212 connect( qApp, SIGNAL(weekChanged(bool)),
213 this, SLOT(slotChangeStartOfWeek(bool)) ); 213 this, SLOT(slotChangeStartOfWeek(bool)) );
214 214
215 connect( editNote, SIGNAL(clicked()), 215 connect( editNote, SIGNAL(clicked()),
216 this, SLOT(slotEditNote()) ); 216 this, SLOT(slotEditNote()) );
217 217
218 QPopupMenu *m2 = new QPopupMenu( this ); 218 QPopupMenu *m2 = new QPopupMenu( this );
219 endPicker = new DateBookMonth( m2, 0, TRUE ); 219 endPicker = new DateBookMonth( m2, 0, TRUE );
220 m2->insertItem( endPicker ); 220 m2->insertItem( endPicker );
221 buttonEnd->setPopup( m2 ); 221 buttonEnd->setPopup( m2 );
222 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), 222 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ),
223 this, SLOT( endDateChanged( int, int, int ) ) ); 223 this, SLOT( endDateChanged( int, int, int ) ) );
224 224
225 connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), 225 connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ),
226 this, SLOT( startTimePicked(const QTime &) )); 226 this, SLOT( startTimePicked(const QTime &) ));
227 // install eventFilters 227 // install eventFilters
228 comboEnd->installEventFilter( this ); 228 comboEnd->installEventFilter( this );
229 comboStart->installEventFilter( this ); 229 comboStart->installEventFilter( this );
230} 230}
231 231
232/* 232/*
233 * Destroys the object and frees any allocated resources 233 * Destroys the object and frees any allocated resources
234 */ 234 */
235DateEntry::~DateEntry() 235DateEntry::~DateEntry()
236{ 236{
237 // no need to delete child widgets, Qt does it all for us 237 // no need to delete child widgets, Qt does it all for us
238 //cout << "Del: " << comboStart->currentText() << endl; 238 //cout << "Del: " << comboStart->currentText() << endl;
239} 239}
240 240
241/* 241/*
242 * public slot 242 * public slot
243 */ 243 */
244 244
245void DateEntry::slotEditNote() { 245void DateEntry::slotEditNote() {
246 QString s; 246 QString s;
247 s = "<B>"+ TimeString::longDateString( startDate ) + "</B>"; 247 s = "<B>"+ TimeString::longDateString( startDate ) + "</B>";
248// s.sprintf("<B>%d/%d</B> ", startDate.day(), startDate.month()); 248// s.sprintf("<B>%d/%d</B> ", startDate.day(), startDate.month());
249 NoteEntry noteDlg(s+comboDescription->currentText(), noteStr, 249 NoteEntry noteDlg(s+comboDescription->currentText(), noteStr,
250 this,0,TRUE); 250 this,0,TRUE);
251 251
252#if defined(Q_WS_QWS) || defined(_WS_QWS_) 252#if defined(Q_WS_QWS) || defined(_WS_QWS_)
253 noteDlg.showMaximized(); 253 noteDlg.showMaximized();
254#endif 254#endif
255 if (noteDlg.exec() ) { 255 if (noteDlg.exec() ) {
256 noteStr=noteDlg.note->text(); 256 noteStr=noteDlg.note->text();
257 } 257 }
258 258
259} 259}
260 260
261void DateEntry::endDateChanged( int y, int m, int d ) 261void DateEntry::endDateChanged( int y, int m, int d )
262{ 262{
263 endDate.setYMD( y, m, d ); 263 endDate.setYMD( y, m, d );
264 if ( endDate < startDate ) { 264 if ( endDate < startDate ) {
265 endDate = startDate; 265 endDate = startDate;
266 } 266 }
267 267
268 buttonEnd->setText( TimeString::shortDate( endDate ) ); 268 buttonEnd->setText( TimeString::shortDate( endDate ) );
269 269
270 endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); 270 endPicker->setDate( endDate.year(), endDate.month(), endDate.day() );
271} 271}
272 272
273static QTime parseTime( const QString& s, bool ampm ) 273static QTime parseTime( const QString& s, bool ampm )
274{ 274{
275 QTime tmpTime; 275 QTime tmpTime;
276 QStringList l = QStringList::split( ':', s ); 276 QStringList l = QStringList::split( ':', s );
277 int hour = l[0].toInt(); 277 int hour = l[0].toInt();
278 if ( ampm ) { 278 if ( ampm ) {
279 int i=0; 279 int i=0;
280 while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') 280 while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9')
281 i++; 281 i++;
282 QString digits = l[1].left(i); 282 QString digits = l[1].left(i);
283 if ( l[1].contains( "PM", FALSE ) ) { 283 if ( l[1].contains( "PM", FALSE ) ) {
284 if ( hour != 12 ) 284 if ( hour != 12 )
285 hour += 12; 285 hour += 12;
286 } else { 286 } else {
287 if ( hour == 12 ) 287 if ( hour == 12 )
288 hour = 0; 288 hour = 0;
289 } 289 }
290 l[1] = digits; 290 l[1] = digits;
291 } 291 }
292 int minute = l[1].toInt(); 292 int minute = l[1].toInt();
293 if ( minute > 59 ) 293 if ( minute > 59 )
294 minute = 59; 294 minute = 59;
295 else if ( minute < 0 ) 295 else if ( minute < 0 )
296 minute = 0; 296 minute = 0;
297 if ( hour > 23 ) { 297 if ( hour > 23 ) {
298 hour = 23; 298 hour = 23;
299 minute = 59; 299 minute = 59;
300 } else if ( hour < 0 ) 300 } else if ( hour < 0 )
301 hour = 0; 301 hour = 0;
302 tmpTime.setHMS( hour, minute, 0 ); 302 tmpTime.setHMS( hour, minute, 0 );
303 return tmpTime; 303 return tmpTime;
304} 304}
305 305
306/* 306/*
307 * public slot 307 * public slot
308 */ 308 */
309void DateEntry::endTimeChanged( const QString &s ) 309void DateEntry::endTimeChanged( const QString &s )
310{ 310{
311 endTimeChanged( parseTime(s,ampm) ); 311 endTimeChanged( parseTime(s,ampm) );
312} 312}
313 313
314void DateEntry::endTimeChanged( const QTime &t ) { 314void DateEntry::endTimeChanged( const QTime &t ) {
315 if ( endDate > startDate || t >= startTime ) { 315 if ( endDate > startDate || t >= startTime ) {
316 endTime = t; 316 endTime = t;
317 } else { 317 } else {
318 endTime = startTime; 318 endTime = startTime;
319 //comboEnd->setCurrentItem( comboStart->currentItem() ); 319 //comboEnd->setCurrentItem( comboStart->currentItem() );
320 } 320 }
321 timePickerStart->setHour(endTime.hour()); 321 timePickerStart->setHour(endTime.hour());
322 timePickerStart->setMinute(endTime.minute()); 322 timePickerStart->setMinute(endTime.minute());
323} 323}
324 324
325/* 325/*
326 * public slot 326 * public slot
327 */ 327 */
328void DateEntry::startDateChanged( int y, int m, int d ) 328void DateEntry::startDateChanged( int y, int m, int d )
329{ 329{
330 QDate prev = startDate; 330 QDate prev = startDate;
331 startDate.setYMD( y, m, d ); 331 startDate.setYMD( y, m, d );
332 if ( rp.type == Event::Weekly && 332 if ( rp.type == Event::Weekly &&
333 startDate.dayOfWeek() != prev.dayOfWeek() ) { 333 startDate.dayOfWeek() != prev.dayOfWeek() ) {
334 // if we change the start of a weekly repeating event 334 // if we change the start of a weekly repeating event
335 // set the repeating day appropriately 335 // set the repeating day appropriately
336 char mask = 1 << (prev.dayOfWeek()-1); 336 char mask = 1 << (prev.dayOfWeek()-1);
337 rp.days &= (~mask); 337 rp.days &= (~mask);
338 rp.days |= 1 << (startDate.dayOfWeek()-1); 338 rp.days |= 1 << (startDate.dayOfWeek()-1);
339 } 339 }
340 340
341 buttonStart->setText( TimeString::shortDate( startDate ) ); 341 buttonStart->setText( TimeString::shortDate( startDate ) );
342 342
343 // our pickers must be reset... 343 // our pickers must be reset...
344 startPicker->setDate( y, m, d ); 344 startPicker->setDate( y, m, d );
345 endPicker->setDate( y, m, d ); 345 endPicker->setDate( y, m, d );
346} 346}
347 347
348/* 348/*
349 * public slot 349 * public slot
350 */ 350 */
351void DateEntry::startTimeEdited( const QString &s ) 351void DateEntry::startTimeEdited( const QString &s )
352{ 352{
353 startTimeChanged(parseTime(s,ampm)); 353 startTimeChanged(parseTime(s,ampm));
354 updateTimeEdit(false,true); 354 updateTimeEdit(false,true);
355 timePickerStart->setHour(startTime.hour()); 355 timePickerStart->setHour(startTime.hour());
356 timePickerStart->setMinute(startTime.minute()); 356 timePickerStart->setMinute(startTime.minute());
357} 357}
358 358
359void DateEntry::startTimeChanged( const QTime &t ) 359void DateEntry::startTimeChanged( const QTime &t )
360{ 360{
361 int duration=startTime.secsTo(endTime); 361 int duration=startTime.secsTo(endTime);
362 startTime = t; 362 startTime = t;
363 endTime=t.addSecs(duration); 363 endTime=t.addSecs(duration);
364} 364}
365void DateEntry::startTimePicked( const QTime &t ) { 365void DateEntry::startTimePicked( const QTime &t ) {
366 if(m_showStart ){ 366 if(m_showStart ){
367 startTimeChanged(t); 367 startTimeChanged(t);
368 updateTimeEdit(true,true); 368 updateTimeEdit(true,true);
369 }else{ 369 }else{
370 endTimeChanged(t); 370 endTimeChanged(t);
371 updateTimeEdit(false, true ); 371 updateTimeEdit(false, true );
372 } 372 }
373} 373}
374 374
375/* 375/*
376 * public slot 376 * public slot
377 */ 377 */
378void DateEntry::typeChanged( const QString &s ) 378void DateEntry::typeChanged( const QString &s )
379{ 379{
380 bool b = s != "All Day"; 380 bool b = s != "All Day";
381 buttonStart->setEnabled( b ); 381 buttonStart->setEnabled( b );
382 comboStart->setEnabled( b ); 382 comboStart->setEnabled( b );
383 comboEnd->setEnabled( b ); 383 comboEnd->setEnabled( b );
384} 384}
385 385
386void DateEntry::slotRepeat() 386void DateEntry::slotRepeat()
387{ 387{
388 // Work around for compiler Bug.. 388 // Work around for compiler Bug..
389 RepeatEntry *e; 389 RepeatEntry *e;
390 390
391 // it is better in my opinion to just grab this from the mother, 391 // it is better in my opinion to just grab this from the mother,
392 // since, this dialog doesn't need to keep track of it... 392 // since, this dialog doesn't need to keep track of it...
393 if ( rp.type != Event::NoRepeat ) 393 if ( rp.type != Event::NoRepeat )
394 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); 394 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this);
395 else 395 else
396 e = new RepeatEntry( startWeekOnMonday, startDate, this ); 396 e = new RepeatEntry( startWeekOnMonday, startDate, this );
397 397
398#if defined(Q_WS_QWS) || defined(_WS_QWS_) 398#if defined(Q_WS_QWS) || defined(_WS_QWS_)
399 e->showMaximized(); 399 e->showMaximized();
400#endif 400#endif
401 if ( e->exec() ) { 401 if ( e->exec() ) {
402 rp = e->repeatPattern(); 402 rp = e->repeatPattern();
403 setRepeatLabel(); 403 setRepeatLabel();
404 } 404 }
405 // deleting sounds like a nice idea...
406 delete e;
405} 407}
406 408
407void DateEntry::slotChangeStartOfWeek( bool onMonday ) 409void DateEntry::slotChangeStartOfWeek( bool onMonday )
408{ 410{
409 startWeekOnMonday = onMonday; 411 startWeekOnMonday = onMonday;
410} 412}
411 413
412Event DateEntry::event() 414Event DateEntry::event()
413{ 415{
414 Event ev; 416 Event ev;
415 Event::SoundTypeChoice st; 417 Event::SoundTypeChoice st;
416 ev.setDescription( comboDescription->currentText() ); 418 ev.setDescription( comboDescription->currentText() );
417 ev.setLocation( comboLocation->currentText() ); 419 ev.setLocation( comboLocation->currentText() );
418 ev.setCategories( comboCategory->currentCategories() ); 420 ev.setCategories( comboCategory->currentCategories() );
419 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); 421 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal );
420 if ( startDate > endDate ) { 422 if ( startDate > endDate ) {
421 QDate tmp = endDate; 423 QDate tmp = endDate;
422 endDate = startDate; 424 endDate = startDate;
423 startDate = tmp; 425 startDate = tmp;
424 } 426 }
425 427
426 // This is now done in the changed slots 428 // This is now done in the changed slots
427 // startTime = parseTime( comboStart->text(), ampm ); 429 // startTime = parseTime( comboStart->text(), ampm );
428 //endTime = parseTime( comboEnd->text(), ampm ); 430 //endTime = parseTime( comboEnd->text(), ampm );
429 431
430 if ( startTime > endTime && endDate == startDate ) { 432 if ( startTime > endTime && endDate == startDate ) {
431 QTime tmp = endTime; 433 QTime tmp = endTime;
432 endTime = startTime; 434 endTime = startTime;
433 startTime = tmp; 435 startTime = tmp;
434 } 436 }
435 // don't set the time if theres no need too 437 // don't set the time if theres no need too
436 if ( ev.type() == Event::AllDay ) { 438 if ( ev.type() == Event::AllDay ) {
437 startTime.setHMS( 0, 0, 0 ); 439 startTime.setHMS( 0, 0, 0 );
438 endTime.setHMS( 23, 59, 59 ); 440 endTime.setHMS( 23, 59, 59 );
439 } 441 }
440 442
441 // adjust start and end times based on timezone 443 // adjust start and end times based on timezone
442 QDateTime start( startDate, startTime ); 444 QDateTime start( startDate, startTime );
443 QDateTime end( endDate, endTime ); 445 QDateTime end( endDate, endTime );
444 time_t start_utc, end_utc; 446 time_t start_utc, end_utc;
445 447
446// qDebug( "tz: %s", timezone->currentZone().latin1() ); 448// qDebug( "tz: %s", timezone->currentZone().latin1() );
447 449
448 // get real timezone 450 // get real timezone
449 QString realTZ; 451 QString realTZ;
450 realTZ = QString::fromLocal8Bit( getenv("TZ") ); 452 realTZ = QString::fromLocal8Bit( getenv("TZ") );
451 453
452 // set timezone 454 // set timezone
453 if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) 455 if ( setenv( "TZ", timezone->currentZone(), true ) != 0 )
454 qWarning( "There was a problem setting the timezone." ); 456 qWarning( "There was a problem setting the timezone." );
455 457
456 // convert to UTC based on selected TZ (calling tzset internally) 458 // convert to UTC based on selected TZ (calling tzset internally)
457 start_utc = TimeConversion::toUTC( start ); 459 start_utc = TimeConversion::toUTC( start );
458 end_utc = TimeConversion::toUTC( end ); 460 end_utc = TimeConversion::toUTC( end );
459 461
460 // done playing around... put it all back 462 // done playing around... put it all back
461 unsetenv( "TZ" ); 463 unsetenv( "TZ" );
462 if ( !realTZ.isNull() ) 464 if ( !realTZ.isNull() )
463 if ( setenv( "TZ", realTZ, true ) != 0 ) 465 if ( setenv( "TZ", realTZ, true ) != 0 )
464 qWarning( "There was a problem setting the timezone." ); 466 qWarning( "There was a problem setting the timezone." );
465 467
466 // convert UTC to local time (calling tzset internally) 468 // convert UTC to local time (calling tzset internally)
467 ev.setStart( TimeConversion::fromUTC( start_utc ) ); 469 ev.setStart( TimeConversion::fromUTC( start_utc ) );
468 ev.setEnd( TimeConversion::fromUTC( end_utc ) ); 470 ev.setEnd( TimeConversion::fromUTC( end_utc ) );
469 471
470 // we only have one type of sound at the moment... LOUD!!! 472 // we only have one type of sound at the moment... LOUD!!!
471 if ( comboSound->currentItem() != 0 ) 473 if ( comboSound->currentItem() != 0 )
472 st = Event::Loud; 474 st = Event::Loud;
473 else 475 else
474 st = Event::Silent; 476 st = Event::Silent;
475 ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); 477 ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st );
476 if ( rp.type != Event::NoRepeat ) 478 if ( rp.type != Event::NoRepeat )
477 ev.setRepeat( TRUE, rp ); 479 ev.setRepeat( TRUE, rp );
478 ev.setNotes( noteStr ); 480 ev.setNotes( noteStr );
479 481
480 //cout << "Start: " << comboStart->currentText() << endl; 482 //cout << "Start: " << comboStart->currentText() << endl;
481 483
482 return ev; 484 return ev;
483} 485}
484 486
485void DateEntry::setRepeatLabel() 487void DateEntry::setRepeatLabel()
486{ 488{
487 489
488 switch( rp.type ) { 490 switch( rp.type ) {
489 case Event::Daily: 491 case Event::Daily:
490 cmdRepeat->setText( tr("Daily...") ); 492 cmdRepeat->setText( tr("Daily...") );
491 break; 493 break;
492 case Event::Weekly: 494 case Event::Weekly:
493 cmdRepeat->setText( tr("Weekly...") ); 495 cmdRepeat->setText( tr("Weekly...") );
494 break; 496 break;
495 case Event::MonthlyDay: 497 case Event::MonthlyDay:
496 case Event::MonthlyDate: 498 case Event::MonthlyDate:
497 cmdRepeat->setText( tr("Monthly...") ); 499 cmdRepeat->setText( tr("Monthly...") );
498 break; 500 break;
499 case Event::Yearly: 501 case Event::Yearly:
500 cmdRepeat->setText( tr("Yearly...") ); 502 cmdRepeat->setText( tr("Yearly...") );
501 break; 503 break;
502 default: 504 default:
503 cmdRepeat->setText( tr("No Repeat...") ); 505 cmdRepeat->setText( tr("No Repeat...") );
504 } 506 }
505} 507}
506 508
507void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) 509void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound )
508{ 510{
509 checkAlarm->setChecked( alarmPreset ); 511 checkAlarm->setChecked( alarmPreset );
510 spinAlarm->setValue( presetTime ); 512 spinAlarm->setValue( presetTime );
511 if ( sound != Event::Silent ) 513 if ( sound != Event::Silent )
512 comboSound->setCurrentItem( 1 ); 514 comboSound->setCurrentItem( 1 );
513 else 515 else
514 comboSound->setCurrentItem( 0 ); 516 comboSound->setCurrentItem( 0 );
515} 517}
516 518
517void DateEntry::initCombos() 519void DateEntry::initCombos()
518{ 520{
519 /* 521 /*
520 comboStart->clear(); 522 comboStart->clear();
521 comboEnd->clear(); 523 comboEnd->clear();
522 if ( ampm ) { 524 if ( ampm ) {
523 for ( int i = 0; i < 24; i++ ) { 525 for ( int i = 0; i < 24; i++ ) {
524 if ( i == 0 ) { 526 if ( i == 0 ) {
525 comboStart->insertItem( "12:00 AM" ); 527 comboStart->insertItem( "12:00 AM" );
526 comboStart->insertItem( "12:30 AM" ); 528 comboStart->insertItem( "12:30 AM" );
527 comboEnd->insertItem( "12:00 AM" ); 529 comboEnd->insertItem( "12:00 AM" );
528 comboEnd->insertItem( "12:30 AM" ); 530 comboEnd->insertItem( "12:30 AM" );
529 } else if ( i == 12 ) { 531 } else if ( i == 12 ) {
530 comboStart->insertItem( "12:00 PM" ); 532 comboStart->insertItem( "12:00 PM" );
531 comboStart->insertItem( "12:30 PM" ); 533 comboStart->insertItem( "12:30 PM" );
532 comboEnd->insertItem( "12:00 PM" ); 534 comboEnd->insertItem( "12:00 PM" );
533 comboEnd->insertItem( "12:30 PM" ); 535 comboEnd->insertItem( "12:30 PM" );
534 } else if ( i > 12 ) { 536 } else if ( i > 12 ) {
535 comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); 537 comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" );
536 comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); 538 comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" );
537 comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); 539 comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" );
538 comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); 540 comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" );
539 } else { 541 } else {
540 comboStart->insertItem( QString::number( i) + ":00 AM" ); 542 comboStart->insertItem( QString::number( i) + ":00 AM" );
541 comboStart->insertItem( QString::number( i ) + ":30 AM" ); 543 comboStart->insertItem( QString::number( i ) + ":30 AM" );
542 comboEnd->insertItem( QString::number( i ) + ":00 AM" ); 544 comboEnd->insertItem( QString::number( i ) + ":00 AM" );
543 comboEnd->insertItem( QString::number( i ) + ":30 AM" ); 545 comboEnd->insertItem( QString::number( i ) + ":30 AM" );
544 } 546 }
545 } 547 }
546 } else { 548 } else {
547 for ( int i = 0; i < 24; i++ ) { 549 for ( int i = 0; i < 24; i++ ) {
548 if ( i < 10 ) { 550 if ( i < 10 ) {
549 comboStart->insertItem( QString("0") 551 comboStart->insertItem( QString("0")
550 + QString::number(i) + ":00" ); 552 + QString::number(i) + ":00" );
551 comboStart->insertItem( QString("0") 553 comboStart->insertItem( QString("0")
552 + QString::number(i) + ":30" ); 554 + QString::number(i) + ":30" );
553 comboEnd->insertItem( QString("0") 555 comboEnd->insertItem( QString("0")
554 + QString::number(i) + ":00" ); 556 + QString::number(i) + ":00" );
555 comboEnd->insertItem( QString("0") 557 comboEnd->insertItem( QString("0")
556 + QString::number(i) + ":30" ); 558 + QString::number(i) + ":30" );
557 } else { 559 } else {
558 comboStart->insertItem( QString::number(i) + ":00" ); 560 comboStart->insertItem( QString::number(i) + ":00" );
559 comboStart->insertItem( QString::number(i) + ":30" ); 561 comboStart->insertItem( QString::number(i) + ":30" );
560 comboEnd->insertItem( QString::number(i) + ":00" ); 562 comboEnd->insertItem( QString::number(i) + ":00" );
561 comboEnd->insertItem( QString::number(i) + ":30" ); 563 comboEnd->insertItem( QString::number(i) + ":30" );
562 } 564 }
563 } 565 }
564 } 566 }
565 */ 567 */
566} 568}
567 569
568void DateEntry::slotChangeClock( bool whichClock ) 570void DateEntry::slotChangeClock( bool whichClock )
569{ 571{
570 ampm = whichClock; 572 ampm = whichClock;
571 initCombos(); 573 initCombos();
572 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); 574 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) );
573} 575}
574 576
diff --git a/core/pim/datebook/opie-datebook.control b/core/pim/datebook/opie-datebook.control
index 1a28448..fe5a086 100644
--- a/core/pim/datebook/opie-datebook.control
+++ b/core/pim/datebook/opie-datebook.control
@@ -1,11 +1,11 @@
1Package: opie-datebook 1Package: opie-datebook
2Files: bin/datebook apps/1Pim/datebook.desktop pics/datebook 2Files: bin/datebook apps/1Pim/datebook.desktop
3Priority: optional 3Priority: optional
4Section: opie/applications 4Section: opie/applications
5Conflicts: qpe-tkccalendar 5Conflicts: qpe-tkccalendar
6Maintainer: Warwick Allison <warwick@trolltech.com> 6Maintainer: Warwick Allison <warwick@trolltech.com>
7Architecture: arm 7Architecture: arm
8Version: $QPE_VERSION-$SUB_VERSION 8Depends: task-opie-minimal, libopie1, opie-pics
9Depends: task-opie-minimal, libopie1
10Description: A datebook/appointment manager 9Description: A datebook/appointment manager
11 A datebook/appointment manager for the Opie environment. 10 A datebook/appointment manager for the Opie environment.
11Version: $QPE_VERSION$EXTRAVERSION
diff --git a/core/pim/datebook/repeatentry.cpp b/core/pim/datebook/repeatentry.cpp
index 5637c4d..b1a162d 100644
--- a/core/pim/datebook/repeatentry.cpp
+++ b/core/pim/datebook/repeatentry.cpp
@@ -1,595 +1,617 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "repeatentry.h" 21#include "repeatentry.h"
22 22
23#include <qpe/datebookmonth.h> 23#include <qpe/datebookmonth.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/timestring.h> 25#include <qpe/timestring.h>
26 26
27#include <qbuttongroup.h> 27#include <qbuttongroup.h>
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qpopupmenu.h> 29#include <qpopupmenu.h>
30#include <qspinbox.h> 30#include <qspinbox.h>
31#include <qtoolbutton.h> 31#include <qtoolbutton.h>
32 32
33#include <time.h> 33#include <time.h>
34 34
35// Global Templates for use in setting up the repeat label... 35// Global Templates for use in setting up the repeat label...
36const QString strDayTemplate = QObject::tr("Every"); 36// the problem is these strings get initialized before QPEApplication can install the translator -zecke
37const QString strYearTemplate = QObject::tr("%1 %2 every "); 37namespace {
38const QString strMonthDateTemplate = QObject::tr("The %1 every "); 38QString strDayTemplate;
39const QString strMonthDayTemplate = QObject::tr("The %1 %1 of every"); 39QString strYearTemplate;
40const QString strWeekTemplate = QObject::tr("Every "); 40QString strMonthDateTemplate;
41const QString dayLabel[] = { QObject::tr("Monday"), 41QString strMonthDayTemplate;
42 QObject::tr("Tuesday"), 42QString strWeekTemplate;
43 QObject::tr("Wednesday"), 43QString dayLabel[7];
44 QObject::tr("Thursday"), 44}
45 QObject::tr("Friday"),
46 QObject::tr("Saturday"),
47 QObject::tr("Sunday") };
48 45
46/*
47 * static linkage to not polute the symbol table...
48 * The problem is that const and static linkage are resolved prior to installing a translator
49 * leading to that the above strings are translted but to the original we delay the init of these strings...
50 * -zecke
51 */
52static void fillStrings() {
53 strDayTemplate = QObject::tr("Every");
54 strYearTemplate = QObject::tr("%1 %2 every ");
55 strMonthDateTemplate = QObject::tr("The %1 every ");
56 strMonthDayTemplate = QObject::tr("The %1 %1 of every");
57 strWeekTemplate = QObject::tr("Every ");
58 dayLabel[0] = QObject::tr("Monday");
59 dayLabel[1] = QObject::tr("Tuesday");
60 dayLabel[2] = QObject::tr("Wednesday");
61 dayLabel[3] = QObject::tr("Thursday");
62 dayLabel[4] = QObject::tr("Friday");
63 dayLabel[5] = QObject::tr("Saturday");
64 dayLabel[6] = QObject::tr("Sunday");
65}
49 66
50 static QString numberPlacing( int x );// return the proper word format for 67 static QString numberPlacing( int x );// return the proper word format for
51 // x (1st, 2nd, etc) 68 // x (1st, 2nd, etc)
52static int week( const QDate &dt ); // what week in the month is dt? 69static int week( const QDate &dt ); // what week in the month is dt?
53 70
54RepeatEntry::RepeatEntry( bool startOnMonday, 71RepeatEntry::RepeatEntry( bool startOnMonday,
55 const QDate &newStart, QWidget *parent, 72 const QDate &newStart, QWidget *parent,
56 const char *name, bool modal, WFlags fl ) 73 const char *name, bool modal, WFlags fl )
57 : RepeatEntryBase( parent, name, modal, fl ), 74 : RepeatEntryBase( parent, name, modal, fl ),
58 start( newStart ), 75 start( newStart ),
59 currInterval( NONE ), 76 currInterval( NONE ),
60 startWeekOnMonday( startOnMonday ) 77 startWeekOnMonday( startOnMonday )
61{ 78{
79 if (strDayTemplate.isEmpty() )
80 fillStrings();
81
62 init(); 82 init();
63 fraType->setButton( currInterval ); 83 fraType->setButton( currInterval );
64 chkNoEnd->setChecked( TRUE ); 84 chkNoEnd->setChecked( TRUE );
65 setupNone(); 85 setupNone();
66} 86}
67 87
68RepeatEntry::RepeatEntry( bool startOnMonday, const Event::RepeatPattern &rp, 88RepeatEntry::RepeatEntry( bool startOnMonday, const Event::RepeatPattern &rp,
69 const QDate &startDate, 89 const QDate &startDate,
70 QWidget *parent, const char *name, bool modal, 90 QWidget *parent, const char *name, bool modal,
71 WFlags fl ) 91 WFlags fl )
72 : RepeatEntryBase( parent, name, modal, fl ), 92 : RepeatEntryBase( parent, name, modal, fl ),
73 start( startDate ), 93 start( startDate ),
74 end( rp.endDate() ), 94 end( rp.endDate() ),
75 startWeekOnMonday( startOnMonday ) 95 startWeekOnMonday( startOnMonday )
76{ 96{
97 if (strDayTemplate.isEmpty() )
98 fillStrings();
77 // do some stuff with the repeat pattern 99 // do some stuff with the repeat pattern
78 init(); 100 init();
79 switch ( rp.type ) { 101 switch ( rp.type ) {
80 default: 102 default:
81 case Event::NoRepeat: 103 case Event::NoRepeat:
82 currInterval = NONE; 104 currInterval = NONE;
83 setupNone(); 105 setupNone();
84 break; 106 break;
85 case Event::Daily: 107 case Event::Daily:
86 currInterval = DAY; 108 currInterval = DAY;
87 setupDaily(); 109 setupDaily();
88 break; 110 break;
89 case Event::Weekly: 111 case Event::Weekly:
90 currInterval = WEEK; 112 currInterval = WEEK;
91 setupWeekly(); 113 setupWeekly();
92 int day, buttons; 114 int day, buttons;
93 for ( day = 0x01, buttons = 0; buttons < 7; 115 for ( day = 0x01, buttons = 0; buttons < 7;
94 day = day << 1, buttons++ ) { 116 day = day << 1, buttons++ ) {
95 if ( rp.days & day ) { 117 if ( rp.days & day ) {
96 if ( startWeekOnMonday ) 118 if ( startWeekOnMonday )
97 fraExtra->setButton( buttons ); 119 fraExtra->setButton( buttons );
98 else { 120 else {
99 if ( buttons == 7 ) 121 if ( buttons == 7 )
100 fraExtra->setButton( 0 ); 122 fraExtra->setButton( 0 );
101 else 123 else
102 fraExtra->setButton( buttons + 1 ); 124 fraExtra->setButton( buttons + 1 );
103 } 125 }
104 } 126 }
105 } 127 }
106 slotWeekLabel(); 128 slotWeekLabel();
107 break; 129 break;
108 case Event::MonthlyDay: 130 case Event::MonthlyDay:
109 currInterval = MONTH; 131 currInterval = MONTH;
110 setupMonthly(); 132 setupMonthly();
111 fraExtra->setButton( 0 ); 133 fraExtra->setButton( 0 );
112 slotMonthLabel( 0 ); 134 slotMonthLabel( 0 );
113 break; 135 break;
114 case Event::MonthlyDate: 136 case Event::MonthlyDate:
115 currInterval = MONTH; 137 currInterval = MONTH;
116 setupMonthly(); 138 setupMonthly();
117 fraExtra->setButton( 1 ); 139 fraExtra->setButton( 1 );
118 slotMonthLabel( 1 ); 140 slotMonthLabel( 1 );
119 break; 141 break;
120 case Event::Yearly: 142 case Event::Yearly:
121 currInterval = YEAR; 143 currInterval = YEAR;
122 setupYearly(); 144 setupYearly();
123 break; 145 break;
124 } 146 }
125 fraType->setButton( currInterval ); 147 fraType->setButton( currInterval );
126 spinFreq->setValue( rp.frequency ); 148 spinFreq->setValue( rp.frequency );
127 if ( !rp.hasEndDate ) { 149 if ( !rp.hasEndDate ) {
128 cmdEnd->setText( RepeatEntryBase::tr("No End Date") ); 150 cmdEnd->setText( RepeatEntryBase::tr("No End Date") );
129 chkNoEnd->setChecked( TRUE ); 151 chkNoEnd->setChecked( TRUE );
130 } else 152 } else
131 cmdEnd->setText( TimeString::shortDate( end ) ); 153 cmdEnd->setText( TimeString::shortDate( end ) );
132} 154}
133 155
134RepeatEntry::~RepeatEntry() 156RepeatEntry::~RepeatEntry()
135{ 157{
136} 158}
137 159
138Event::RepeatPattern RepeatEntry::repeatPattern() 160Event::RepeatPattern RepeatEntry::repeatPattern()
139{ 161{
140 QListIterator<QToolButton> it( listRTypeButtons ); 162 QListIterator<QToolButton> it( listRTypeButtons );
141 QListIterator<QToolButton> itExtra( listExtra ); 163 QListIterator<QToolButton> itExtra( listExtra );
142 Event::RepeatPattern rpTmp; 164 Event::RepeatPattern rpTmp;
143 int i; 165 int i;
144 for ( i = 0; *it; ++it, i++ ) { 166 for ( i = 0; *it; ++it, i++ ) {
145 if ( (*it)->isOn() ) { 167 if ( (*it)->isOn() ) {
146 switch ( i ) { 168 switch ( i ) {
147 case NONE: 169 case NONE:
148 rpTmp.type = Event::NoRepeat; 170 rpTmp.type = Event::NoRepeat;
149 break; 171 break;
150 case DAY: 172 case DAY:
151 rpTmp.type = Event::Daily; 173 rpTmp.type = Event::Daily;
152 break; 174 break;
153 case WEEK: 175 case WEEK:
154 rpTmp.type = Event::Weekly; 176 rpTmp.type = Event::Weekly;
155 rpTmp.days = 0; 177 rpTmp.days = 0;
156 int day; 178 int day;
157 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 179 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
158 if ( (*itExtra)->isOn() ) { 180 if ( (*itExtra)->isOn() ) {
159 if ( startWeekOnMonday ) 181 if ( startWeekOnMonday )
160 rpTmp.days |= day; 182 rpTmp.days |= day;
161 else { 183 else {
162 if ( day == 1 ) 184 if ( day == 1 )
163 rpTmp.days |= Event::SUN; 185 rpTmp.days |= Event::SUN;
164 else 186 else
165 rpTmp.days |= day >> 1; 187 rpTmp.days |= day >> 1;
166 } 188 }
167 } 189 }
168 } 190 }
169 break; 191 break;
170 case MONTH: 192 case MONTH:
171 if ( cmdExtra1->isOn() ) 193 if ( cmdExtra1->isOn() )
172 rpTmp.type = Event::MonthlyDay; 194 rpTmp.type = Event::MonthlyDay;
173 else if ( cmdExtra2->isOn() ) 195 else if ( cmdExtra2->isOn() )
174 rpTmp.type = Event::MonthlyDate; 196 rpTmp.type = Event::MonthlyDate;
175 // figure out the montly day... 197 // figure out the montly day...
176 rpTmp.position = week( start ); 198 rpTmp.position = week( start );
177 break; 199 break;
178 case YEAR: 200 case YEAR:
179 rpTmp.type = Event::Yearly; 201 rpTmp.type = Event::Yearly;
180 break; 202 break;
181 } 203 }
182 break; // no need to keep looking! 204 break; // no need to keep looking!
183 } 205 }
184 } 206 }
185 rpTmp.frequency = spinFreq->value(); 207 rpTmp.frequency = spinFreq->value();
186 rpTmp.hasEndDate = !chkNoEnd->isChecked(); 208 rpTmp.hasEndDate = !chkNoEnd->isChecked();
187 if ( rpTmp.hasEndDate ) { 209 if ( rpTmp.hasEndDate ) {
188 rpTmp.setEndDate( end ); 210 rpTmp.setEndDate( end );
189 } 211 }
190 // timestamp it... 212 // timestamp it...
191 rpTmp.createTime = time( NULL ); 213 rpTmp.createTime = time( NULL );
192 return rpTmp; 214 return rpTmp;
193} 215}
194 216
195void RepeatEntry::slotSetRType( int rtype ) 217void RepeatEntry::slotSetRType( int rtype )
196{ 218{
197 // now call the right function based on the type... 219 // now call the right function based on the type...
198 currInterval = static_cast<repeatButtons>(rtype); 220 currInterval = static_cast<repeatButtons>(rtype);
199 switch ( currInterval ) { 221 switch ( currInterval ) {
200 case NONE: 222 case NONE:
201 setupNone(); 223 setupNone();
202 break; 224 break;
203 case DAY: 225 case DAY:
204 setupDaily(); 226 setupDaily();
205 break; 227 break;
206 case WEEK: 228 case WEEK:
207 setupWeekly(); 229 setupWeekly();
208 slotWeekLabel(); 230 slotWeekLabel();
209 break; 231 break;
210 case MONTH: 232 case MONTH:
211 setupMonthly(); 233 setupMonthly();
212 cmdExtra2->setOn( TRUE ); 234 cmdExtra2->setOn( TRUE );
213 slotMonthLabel( 1 ); 235 slotMonthLabel( 1 );
214 break; 236 break;
215 case YEAR: 237 case YEAR:
216 setupYearly(); 238 setupYearly();
217 break; 239 break;
218 } 240 }
219} 241}
220 242
221void RepeatEntry::setupNone() 243void RepeatEntry::setupNone()
222{ 244{
223 lblRepeat->setText( tr("No Repeat") ); 245 lblRepeat->setText( tr("No Repeat") );
224 lblVar1->hide(); 246 lblVar1->hide();
225 lblVar2->hide(); 247 lblVar2->hide();
226 hideExtras(); 248 hideExtras();
227 cmdEnd->hide(); 249 cmdEnd->hide();
228 lblFreq->hide(); 250 lblFreq->hide();
229 lblEvery->hide(); 251 lblEvery->hide();
230 lblFreq->hide(); 252 lblFreq->hide();
231 spinFreq->hide(); 253 spinFreq->hide();
232 lblEnd->hide(); 254 lblEnd->hide();
233 lblWeekVar->hide(); 255 lblWeekVar->hide();
234} 256}
235 257
236void RepeatEntry::setupDaily() 258void RepeatEntry::setupDaily()
237{ 259{
238 hideExtras(); 260 hideExtras();
239 lblWeekVar->hide(); 261 lblWeekVar->hide();
240 spinFreq->setValue( 1 ); 262 spinFreq->setValue( 1 );
241 lblFreq->setText( tr("day(s)") ); 263 lblFreq->setText( tr("day(s)") );
242 lblVar2->show(); 264 lblVar2->show();
243 showRepeatStuff(); 265 showRepeatStuff();
244 lblRepeat->setText( strDayTemplate ); 266 lblRepeat->setText( strDayTemplate );
245 setupRepeatLabel( 1 ); 267 setupRepeatLabel( 1 );
246} 268}
247 269
248void RepeatEntry::setupWeekly() 270void RepeatEntry::setupWeekly()
249{ 271{
250 // reshow the buttons... 272 // reshow the buttons...
251 fraExtra->setTitle( RepeatEntryBase::tr("Repeat On") ); 273 fraExtra->setTitle( RepeatEntryBase::tr("Repeat On") );
252 fraExtra->setExclusive( FALSE ); 274 fraExtra->setExclusive( FALSE );
253 fraExtra->show(); 275 fraExtra->show();
254 if ( startWeekOnMonday ) { 276 if ( startWeekOnMonday ) {
255 cmdExtra1->setText( RepeatEntryBase::tr("Mon") ); 277 cmdExtra1->setText( RepeatEntryBase::tr("Mon") );
256 cmdExtra2->setText( RepeatEntryBase::tr("Tue") ); 278 cmdExtra2->setText( RepeatEntryBase::tr("Tue") );
257 cmdExtra3->setText( RepeatEntryBase::tr("Wed") ); 279 cmdExtra3->setText( RepeatEntryBase::tr("Wed") );
258 cmdExtra4->setText( RepeatEntryBase::tr("Thu") ); 280 cmdExtra4->setText( RepeatEntryBase::tr("Thu") );
259 cmdExtra5->setText( RepeatEntryBase::tr("Fri") ); 281 cmdExtra5->setText( RepeatEntryBase::tr("Fri") );
260 cmdExtra6->setText( RepeatEntryBase::tr("Sat") ); 282 cmdExtra6->setText( RepeatEntryBase::tr("Sat") );
261 cmdExtra7->setText( RepeatEntryBase::tr("Sun") ); 283 cmdExtra7->setText( RepeatEntryBase::tr("Sun") );
262 } else { 284 } else {
263 cmdExtra1->setText( RepeatEntryBase::tr("Sun") ); 285 cmdExtra1->setText( RepeatEntryBase::tr("Sun") );
264 cmdExtra2->setText( RepeatEntryBase::tr("Mon") ); 286 cmdExtra2->setText( RepeatEntryBase::tr("Mon") );
265 cmdExtra3->setText( RepeatEntryBase::tr("Tue") ); 287 cmdExtra3->setText( RepeatEntryBase::tr("Tue") );
266 cmdExtra4->setText( RepeatEntryBase::tr("Wed") ); 288 cmdExtra4->setText( RepeatEntryBase::tr("Wed") );
267 cmdExtra5->setText( RepeatEntryBase::tr("Thu") ); 289 cmdExtra5->setText( RepeatEntryBase::tr("Thu") );
268 cmdExtra6->setText( RepeatEntryBase::tr("Fri") ); 290 cmdExtra6->setText( RepeatEntryBase::tr("Fri") );
269 cmdExtra7->setText( RepeatEntryBase::tr("Sat") ); 291 cmdExtra7->setText( RepeatEntryBase::tr("Sat") );
270 } 292 }
271 // I hope clustering these improve performance.... 293 // I hope clustering these improve performance....
272 cmdExtra1->setOn( FALSE ); 294 cmdExtra1->setOn( FALSE );
273 cmdExtra2->setOn( FALSE ); 295 cmdExtra2->setOn( FALSE );
274 cmdExtra3->setOn( FALSE ); 296 cmdExtra3->setOn( FALSE );
275 cmdExtra4->setOn( FALSE ); 297 cmdExtra4->setOn( FALSE );
276 cmdExtra5->setOn( FALSE ); 298 cmdExtra5->setOn( FALSE );
277 cmdExtra6->setOn( FALSE ); 299 cmdExtra6->setOn( FALSE );
278 cmdExtra7->setOn( FALSE ); 300 cmdExtra7->setOn( FALSE );
279 301
280 cmdExtra1->show(); 302 cmdExtra1->show();
281 cmdExtra2->show(); 303 cmdExtra2->show();
282 cmdExtra3->show(); 304 cmdExtra3->show();
283 cmdExtra4->show(); 305 cmdExtra4->show();
284 cmdExtra5->show(); 306 cmdExtra5->show();
285 cmdExtra6->show(); 307 cmdExtra6->show();
286 cmdExtra7->show(); 308 cmdExtra7->show();
287 309
288 lblWeekVar->show(); 310 lblWeekVar->show();
289 spinFreq->setValue( 1 ); 311 spinFreq->setValue( 1 );
290 // might as well set the day too... 312 // might as well set the day too...
291 if ( startWeekOnMonday ) { 313 if ( startWeekOnMonday ) {
292 fraExtra->setButton( start.dayOfWeek() - 1 ); 314 fraExtra->setButton( start.dayOfWeek() - 1 );
293 } else { 315 } else {
294 fraExtra->setButton( start.dayOfWeek() % 7 ); 316 fraExtra->setButton( start.dayOfWeek() % 7 );
295 } 317 }
296 lblFreq->setText( tr("week(s)") ); 318 lblFreq->setText( tr("week(s)") );
297 lblVar2->show(); 319 lblVar2->show();
298 showRepeatStuff(); 320 showRepeatStuff();
299 setupRepeatLabel( 1 ); 321 setupRepeatLabel( 1 );
300} 322}
301 323
302void RepeatEntry::setupMonthly() 324void RepeatEntry::setupMonthly()
303{ 325{
304 hideExtras(); 326 hideExtras();
305 lblWeekVar->hide(); 327 lblWeekVar->hide();
306 fraExtra->setTitle( tr("Repeat By") ); 328 fraExtra->setTitle( tr("Repeat By") );
307 fraExtra->setExclusive( TRUE ); 329 fraExtra->setExclusive( TRUE );
308 fraExtra->show(); 330 fraExtra->show();
309 cmdExtra1->setText( tr("Day") ); 331 cmdExtra1->setText( tr("Day") );
310 cmdExtra1->show(); 332 cmdExtra1->show();
311 cmdExtra2->setText( tr("Date") ); 333 cmdExtra2->setText( tr("Date") );
312 cmdExtra2->show(); 334 cmdExtra2->show();
313 spinFreq->setValue( 1 ); 335 spinFreq->setValue( 1 );
314 lblFreq->setText( tr("month(s)") ); 336 lblFreq->setText( tr("month(s)") );
315 lblVar2->show(); 337 lblVar2->show();
316 showRepeatStuff(); 338 showRepeatStuff();
317 setupRepeatLabel( 1 ); 339 setupRepeatLabel( 1 );
318} 340}
319 341
320void RepeatEntry::setupYearly() 342void RepeatEntry::setupYearly()
321{ 343{
322 hideExtras(); 344 hideExtras();
323 lblWeekVar->hide(); 345 lblWeekVar->hide();
324 spinFreq->setValue( 1 ); 346 spinFreq->setValue( 1 );
325 lblFreq->setText( tr("year(s)") ); 347 lblFreq->setText( tr("year(s)") );
326 lblFreq->show(); 348 lblFreq->show();
327 lblFreq->show(); 349 lblFreq->show();
328 showRepeatStuff(); 350 showRepeatStuff();
329 lblVar2->show(); 351 lblVar2->show();
330 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) ); 352 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) );
331 lblRepeat->setText( strEvery ); 353 lblRepeat->setText( strEvery );
332 setupRepeatLabel( 1 ); 354 setupRepeatLabel( 1 );
333 355
334} 356}
335 357
336void RepeatEntry::init() 358void RepeatEntry::init()
337{ 359{
338 QPopupMenu *m1 = new QPopupMenu( this ); 360 QPopupMenu *m1 = new QPopupMenu( this );
339 repeatPicker = new DateBookMonth( m1, 0, TRUE ); 361 repeatPicker = new DateBookMonth( m1, 0, TRUE );
340 m1->insertItem( repeatPicker ); 362 m1->insertItem( repeatPicker );
341 cmdEnd->setPopup( m1 ); 363 cmdEnd->setPopup( m1 );
342 cmdEnd->setPopupDelay( 0 ); 364 cmdEnd->setPopupDelay( 0 );
343 365
344 QObject::connect( repeatPicker, SIGNAL(dateClicked(int, int, int)), 366 QObject::connect( repeatPicker, SIGNAL(dateClicked(int, int, int)),
345 this, SLOT(endDateChanged(int, int, int)) ); 367 this, SLOT(endDateChanged(int, int, int)) );
346 QObject::connect( qApp, SIGNAL(weekChanged(bool)), 368 QObject::connect( qApp, SIGNAL(weekChanged(bool)),
347 this, SLOT(slotChangeStartOfWeek(bool)) ); 369 this, SLOT(slotChangeStartOfWeek(bool)) );
348 370
349 listRTypeButtons.setAutoDelete( TRUE ); 371 listRTypeButtons.setAutoDelete( TRUE );
350 listRTypeButtons.append( cmdNone ); 372 listRTypeButtons.append( cmdNone );
351 listRTypeButtons.append( cmdDay ); 373 listRTypeButtons.append( cmdDay );
352 listRTypeButtons.append( cmdWeek ); 374 listRTypeButtons.append( cmdWeek );
353 listRTypeButtons.append( cmdMonth ); 375 listRTypeButtons.append( cmdMonth );
354 listRTypeButtons.append( cmdYear ); 376 listRTypeButtons.append( cmdYear );
355 377
356 listExtra.setAutoDelete( TRUE ); 378 listExtra.setAutoDelete( TRUE );
357 listExtra.append( cmdExtra1 ); 379 listExtra.append( cmdExtra1 );
358 listExtra.append( cmdExtra2 ); 380 listExtra.append( cmdExtra2 );
359 listExtra.append( cmdExtra3 ); 381 listExtra.append( cmdExtra3 );
360 listExtra.append( cmdExtra4 ); 382 listExtra.append( cmdExtra4 );
361 listExtra.append( cmdExtra5 ); 383 listExtra.append( cmdExtra5 );
362 listExtra.append( cmdExtra6 ); 384 listExtra.append( cmdExtra6 );
363 listExtra.append( cmdExtra7 ); 385 listExtra.append( cmdExtra7 );
364} 386}
365 387
366void RepeatEntry::slotNoEnd( bool unused ) 388void RepeatEntry::slotNoEnd( bool unused )
367{ 389{
368 // if the item was toggled, then go ahead and set it to the maximum date 390 // if the item was toggled, then go ahead and set it to the maximum date
369 if ( unused ) { 391 if ( unused ) {
370 end.setYMD( 3000, 12, 31 ); 392 end.setYMD( 3000, 12, 31 );
371 cmdEnd->setText( RepeatEntryBase::tr("No End Date") ); 393 cmdEnd->setText( RepeatEntryBase::tr("No End Date") );
372 } else { 394 } else {
373 end = start; 395 end = start;
374 cmdEnd->setText( TimeString::shortDate(end) ); 396 cmdEnd->setText( TimeString::shortDate(end) );
375 } 397 }
376} 398}
377 399
378void RepeatEntry::endDateChanged( int y, int m, int d ) 400void RepeatEntry::endDateChanged( int y, int m, int d )
379{ 401{
380 end.setYMD( y, m, d ); 402 end.setYMD( y, m, d );
381 if ( end < start ) 403 if ( end < start )
382 end = start; 404 end = start;
383 cmdEnd->setText( TimeString::shortDate( end ) ); 405 cmdEnd->setText( TimeString::shortDate( end ) );
384 repeatPicker->setDate( end.year(), end.month(), end.day() ); 406 repeatPicker->setDate( end.year(), end.month(), end.day() );
385} 407}
386 408
387void RepeatEntry::setupRepeatLabel( const QString &s ) 409void RepeatEntry::setupRepeatLabel( const QString &s )
388{ 410{
389 lblVar1->setText( s ); 411 lblVar1->setText( s );
390} 412}
391 413
392void RepeatEntry::setupRepeatLabel( int x ) 414void RepeatEntry::setupRepeatLabel( int x )
393{ 415{
394 // change the spelling based on the value of x 416 // change the spelling based on the value of x
395 QString strVar2; 417 QString strVar2;
396 418
397 if ( x > 1 ) 419 if ( x > 1 )
398 lblVar1->show(); 420 lblVar1->show();
399 else 421 else
400 lblVar1->hide(); 422 lblVar1->hide();
401 423
402 switch ( currInterval ) { 424 switch ( currInterval ) {
403 case NONE: 425 case NONE:
404 break; 426 break;
405 case DAY: 427 case DAY:
406 if ( x > 1 ) 428 if ( x > 1 )
407 strVar2 = tr( "days" ); 429 strVar2 = tr( "days" );
408 else 430 else
409 strVar2 = tr( "day" ); 431 strVar2 = tr( "day" );
410 break; 432 break;
411 case WEEK: 433 case WEEK:
412 if ( x > 1 ) 434 if ( x > 1 )
413 strVar2 = tr( "weeks" ); 435 strVar2 = tr( "weeks" );
414 else 436 else
415 strVar2 = tr( "week" ); 437 strVar2 = tr( "week" );
416 break; 438 break;
417 case MONTH: 439 case MONTH:
418 if ( x > 1 ) 440 if ( x > 1 )
419 strVar2 = RepeatEntryBase::tr( "months" ); 441 strVar2 = RepeatEntryBase::tr( "months" );
420 else 442 else
421 strVar2 = tr( "month" ); 443 strVar2 = tr( "month" );
422 break; 444 break;
423 case YEAR: 445 case YEAR:
424 if ( x > 1 ) 446 if ( x > 1 )
425 strVar2 = RepeatEntryBase::tr( "years" ); 447 strVar2 = RepeatEntryBase::tr( "years" );
426 else 448 else
427 strVar2 = tr( "year" ); 449 strVar2 = tr( "year" );
428 break; 450 break;
429 } 451 }
430 if ( !strVar2.isNull() ) 452 if ( !strVar2.isNull() )
431 lblVar2->setText( strVar2 ); 453 lblVar2->setText( strVar2 );
432} 454}
433 455
434void RepeatEntry::showRepeatStuff() 456void RepeatEntry::showRepeatStuff()
435{ 457{
436 cmdEnd->show(); 458 cmdEnd->show();
437 chkNoEnd->show(); 459 chkNoEnd->show();
438 lblFreq->show(); 460 lblFreq->show();
439 lblEvery->show(); 461 lblEvery->show();
440 lblFreq->show(); 462 lblFreq->show();
441 spinFreq->show(); 463 spinFreq->show();
442 lblEnd->show(); 464 lblEnd->show();
443 lblRepeat->setText( RepeatEntryBase::tr("Every") ); 465 lblRepeat->setText( RepeatEntryBase::tr("Every") );
444} 466}
445 467
446void RepeatEntry::slotWeekLabel() 468void RepeatEntry::slotWeekLabel()
447{ 469{
448 QString str; 470 QString str;
449 QListIterator<QToolButton> it( listExtra ); 471 QListIterator<QToolButton> it( listExtra );
450 unsigned int i; 472 unsigned int i;
451 unsigned int keepMe; 473 unsigned int keepMe;
452 bool bNeedCarriage = FALSE; 474 bool bNeedCarriage = FALSE;
453 // don't do something we'll regret!!! 475 // don't do something we'll regret!!!
454 if ( currInterval != WEEK ) 476 if ( currInterval != WEEK )
455 return; 477 return;
456 478
457 if ( startWeekOnMonday ) 479 if ( startWeekOnMonday )
458 keepMe = start.dayOfWeek() - 1; 480 keepMe = start.dayOfWeek() - 1;
459 else 481 else
460 keepMe = start.dayOfWeek() % 7; 482 keepMe = start.dayOfWeek() % 7;
461 483
462 QStringList list; 484 QStringList list;
463 for ( i = 0; *it; ++it, i++ ) { 485 for ( i = 0; *it; ++it, i++ ) {
464 // a crazy check, if you are repeating weekly, the current day 486 // a crazy check, if you are repeating weekly, the current day
465 // must be selected!!! 487 // must be selected!!!
466 if ( i == keepMe && !( (*it)->isOn() ) ) 488 if ( i == keepMe && !( (*it)->isOn() ) )
467 (*it)->setOn( TRUE ); 489 (*it)->setOn( TRUE );
468 if ( (*it)->isOn() ) { 490 if ( (*it)->isOn() ) {
469 if ( startWeekOnMonday ) 491 if ( startWeekOnMonday )
470 list.append( dayLabel[i] ); 492 list.append( dayLabel[i] );
471 else { 493 else {
472 if ( i == 0 ) 494 if ( i == 0 )
473 list.append( dayLabel[6] ); 495 list.append( dayLabel[6] );
474 else 496 else
475 list.append( dayLabel[i - 1] ); 497 list.append( dayLabel[i - 1] );
476 } 498 }
477 } 499 }
478 } 500 }
479 QStringList::Iterator itStr; 501 QStringList::Iterator itStr;
480 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) { 502 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) {
481 if ( i == 3 ) 503 if ( i == 3 )
482 bNeedCarriage = TRUE; 504 bNeedCarriage = TRUE;
483 else 505 else
484 bNeedCarriage = FALSE; 506 bNeedCarriage = FALSE;
485 if ( str.isNull() ) 507 if ( str.isNull() )
486 str = *itStr; 508 str = *itStr;
487 else if ( i == list.count() - 1 ) { 509 else if ( i == list.count() - 1 ) {
488 if ( i < 2 ) 510 if ( i < 2 )
489 str += tr(" and ") + *itStr; 511 str += tr(" and ") + *itStr;
490 else { 512 else {
491 if ( bNeedCarriage ) 513 if ( bNeedCarriage )
492 str += tr( ",\nand " ) + *itStr; 514 str += tr( ",\nand " ) + *itStr;
493 else 515 else
494 str += tr( ", and " ) + *itStr; 516 str += tr( ", and " ) + *itStr;
495 } 517 }
496 } else { 518 } else {
497 if ( bNeedCarriage ) 519 if ( bNeedCarriage )
498 str += ",\n" + *itStr; 520 str += ",\n" + *itStr;
499 else 521 else
500 str += ", " + *itStr; 522 str += ", " + *itStr;
501 } 523 }
502 } 524 }
503 str = str.prepend( "on " ); 525 str = str.prepend( tr("on ") );
504 lblWeekVar->setText( str ); 526 lblWeekVar->setText( str );
505} 527}
506 528
507void RepeatEntry::slotMonthLabel( int type ) 529void RepeatEntry::slotMonthLabel( int type )
508{ 530{
509 QString str; 531 QString str;
510 if ( currInterval != MONTH || type > 1 ) 532 if ( currInterval != MONTH || type > 1 )
511 return; 533 return;
512 if ( type == 1 ) 534 if ( type == 1 )
513 str = strMonthDateTemplate.arg( numberPlacing(start.day()) ); 535 str = strMonthDateTemplate.arg( numberPlacing(start.day()) );
514 else 536 else
515 str = strMonthDayTemplate.arg( numberPlacing(week(start))) 537 str = strMonthDayTemplate.arg( numberPlacing(week(start)))
516 .arg( dayLabel[start.dayOfWeek() - 1] ); 538 .arg( dayLabel[start.dayOfWeek() - 1] );
517 lblRepeat->setText( str ); 539 lblRepeat->setText( str );
518} 540}
519 541
520void RepeatEntry::slotChangeStartOfWeek( bool onMonday ) 542void RepeatEntry::slotChangeStartOfWeek( bool onMonday )
521{ 543{
522 startWeekOnMonday = onMonday; 544 startWeekOnMonday = onMonday;
523 // we need to make this unintrusive as possible... 545 // we need to make this unintrusive as possible...
524 int saveSpin = spinFreq->value(); 546 int saveSpin = spinFreq->value();
525 char days = 0; 547 char days = 0;
526 int day; 548 int day;
527 QListIterator<QToolButton> itExtra( listExtra ); 549 QListIterator<QToolButton> itExtra( listExtra );
528 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 550 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
529 if ( (*itExtra)->isOn() ) { 551 if ( (*itExtra)->isOn() ) {
530 if ( !startWeekOnMonday ) 552 if ( !startWeekOnMonday )
531 days |= day; 553 days |= day;
532 else { 554 else {
533 if ( day == 1 ) 555 if ( day == 1 )
534 days |= Event::SUN; 556 days |= Event::SUN;
535 else 557 else
536 days |= day >> 1; 558 days |= day >> 1;
537 } 559 }
538 } 560 }
539 } 561 }
540 setupWeekly(); 562 setupWeekly();
541 spinFreq->setValue( saveSpin ); 563 spinFreq->setValue( saveSpin );
542 int buttons; 564 int buttons;
543 for ( day = 0x01, buttons = 0; buttons < 7; 565 for ( day = 0x01, buttons = 0; buttons < 7;
544 day = day << 1, buttons++ ) { 566 day = day << 1, buttons++ ) {
545 if ( days & day ) { 567 if ( days & day ) {
546 if ( startWeekOnMonday ) 568 if ( startWeekOnMonday )
547 fraExtra->setButton( buttons ); 569 fraExtra->setButton( buttons );
548 else { 570 else {
549 if ( buttons == 7 ) 571 if ( buttons == 7 )
550 fraExtra->setButton( 0 ); 572 fraExtra->setButton( 0 );
551 else 573 else
552 fraExtra->setButton( buttons + 1 ); 574 fraExtra->setButton( buttons + 1 );
553 } 575 }
554 } 576 }
555 } 577 }
556 slotWeekLabel(); 578 slotWeekLabel();
557} 579}
558 580
559static int week( const QDate &start ) 581static int week( const QDate &start )
560{ 582{
561 // figure out the week... 583 // figure out the week...
562 int stop = start.day(), 584 int stop = start.day(),
563 sentinel = start.dayOfWeek(), 585 sentinel = start.dayOfWeek(),
564 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(), 586 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(),
565 week = 1, 587 week = 1,
566 i; 588 i;
567 for ( i = 1; i < stop; i++ ) { 589 for ( i = 1; i < stop; i++ ) {
568 if ( dayOfWeek++ == sentinel ) 590 if ( dayOfWeek++ == sentinel )
569 week++; 591 week++;
570 if ( dayOfWeek > 7 ) 592 if ( dayOfWeek > 7 )
571 dayOfWeek = 0; 593 dayOfWeek = 0;
572 } 594 }
573 return week; 595 return week;
574} 596}
575 597
576static QString numberPlacing( int x ) 598static QString numberPlacing( int x )
577{ 599{
578 // I hope this works in other languages besides english... 600 // I hope this works in other languages besides english...
579 QString str = QString::number( x ); 601 QString str = QString::number( x );
580 switch ( x % 10 ) { 602 switch ( x % 10 ) {
581 case 1: 603 case 1:
582 str += QWidget::tr( "st" ); 604 str += QWidget::tr( "st" );
583 break; 605 break;
584 case 2: 606 case 2:
585 str += QWidget::tr( "nd" ); 607 str += QWidget::tr( "nd" );
586 break; 608 break;
587 case 3: 609 case 3:
588 str += QWidget::tr( "rd" ); 610 str += QWidget::tr( "rd" );
589 break; 611 break;
590 default: 612 default:
591 str += QWidget::tr( "th" ); 613 str += QWidget::tr( "th" );
592 break; 614 break;
593 } 615 }
594 return str; 616 return str;
595} 617}