author | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
commit | 212aef7fd20182fe926644af2ab10a4b49549440 (patch) (unidiff) | |
tree | 9e8fb96b40037b31cb2eed411c7a51f35d819ddc | |
parent | 79fcbf52d267aa3eb839de35f15992bf5e18f8eb (diff) | |
download | opie-212aef7fd20182fe926644af2ab10a4b49549440.zip opie-212aef7fd20182fe926644af2ab10a4b49549440.tar.gz opie-212aef7fd20182fe926644af2ab10a4b49549440.tar.bz2 |
Bugfix: Datebook shouldn't crash if we modify prefences when dayview isn't initialized. :)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 189 |
1 files changed, 97 insertions, 92 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 1bc82a5..829f8f8 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,823 +1,828 @@ | |||
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 | ||
73 | #define DAY 1 | 73 | #define DAY 1 |
74 | #define WEEK 2 | 74 | #define WEEK 2 |
75 | #define WEEKLST 4 | 75 | #define WEEKLST 4 |
76 | #define MONTH 3 | 76 | #define MONTH 3 |
77 | 77 | ||
78 | 78 | ||
79 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 79 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
80 | : QMainWindow( parent, "datebook", f ), | 80 | : QMainWindow( parent, "datebook", f ), |
81 | aPreset( FALSE ), | 81 | aPreset( FALSE ), |
82 | presetTime( -1 ), | 82 | presetTime( -1 ), |
83 | startTime( 8 ), // an acceptable default | 83 | startTime( 8 ), // an acceptable default |
84 | rowStyle( 0 ), | 84 | rowStyle( 0 ), |
85 | bJumpToCurTime(FALSE), | 85 | bJumpToCurTime(FALSE), |
86 | syncing(FALSE), | 86 | syncing(FALSE), |
87 | inSearch(FALSE), | 87 | inSearch(FALSE), |
88 | alarmCounter(0) | 88 | alarmCounter(0) |
89 | { | 89 | { |
90 | bool needEvilHack= false; // if we need an Evil Hack | 90 | bool needEvilHack= false; // if we need an Evil Hack |
91 | QTime t; | 91 | QTime t; |
92 | t.start(); | 92 | t.start(); |
93 | db = new DateBookDBHack; | 93 | db = new DateBookDBHack; |
94 | qDebug("loading db t=%d", t.elapsed() ); | 94 | qDebug("loading db t=%d", t.elapsed() ); |
95 | loadSettings(); | 95 | loadSettings(); |
96 | setCaption( tr("Calendar") ); | 96 | setCaption( tr("Calendar") ); |
97 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 97 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
98 | 98 | ||
99 | setToolBarsMovable( FALSE ); | 99 | setToolBarsMovable( FALSE ); |
100 | 100 | ||
101 | views = new QWidgetStack( this ); | 101 | views = new QWidgetStack( this ); |
102 | setCentralWidget( views ); | 102 | setCentralWidget( views ); |
103 | 103 | ||
104 | dayView = 0; | 104 | dayView = 0; |
105 | weekView = 0; | 105 | weekView = 0; |
106 | weekLstView = 0; | 106 | weekLstView = 0; |
107 | monthView = 0; | 107 | monthView = 0; |
108 | 108 | ||
109 | QPEToolBar *bar = new QPEToolBar( this ); | 109 | QPEToolBar *bar = new QPEToolBar( this ); |
110 | bar->setHorizontalStretchable( TRUE ); | 110 | bar->setHorizontalStretchable( TRUE ); |
111 | 111 | ||
112 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 112 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
113 | mb->setMargin( 0 ); | 113 | mb->setMargin( 0 ); |
114 | 114 | ||
115 | QPEToolBar *sub_bar = new QPEToolBar(this); | 115 | QPEToolBar *sub_bar = new QPEToolBar(this); |
116 | 116 | ||
117 | QPopupMenu *view = new QPopupMenu( this ); | 117 | QPopupMenu *view = new QPopupMenu( this ); |
118 | QPopupMenu *settings = new QPopupMenu( this ); | 118 | QPopupMenu *settings = new QPopupMenu( this ); |
119 | 119 | ||
120 | mb->insertItem( tr( "View" ), view ); | 120 | mb->insertItem( tr( "View" ), view ); |
121 | mb->insertItem( tr( "Settings" ), settings ); | 121 | mb->insertItem( tr( "Settings" ), settings ); |
122 | 122 | ||
123 | QActionGroup *g = new QActionGroup( this ); | 123 | QActionGroup *g = new QActionGroup( this ); |
124 | g->setExclusive( TRUE ); | 124 | g->setExclusive( TRUE ); |
125 | 125 | ||
126 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 126 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
127 | QString::null, 0, this, 0 ); | 127 | QString::null, 0, this, 0 ); |
128 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 128 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
129 | a->addTo( sub_bar ); | 129 | a->addTo( sub_bar ); |
130 | 130 | ||
131 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); | 131 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); |
132 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 132 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
133 | a->addTo( sub_bar ); | 133 | a->addTo( sub_bar ); |
134 | a->addTo( view ); | 134 | a->addTo( view ); |
135 | 135 | ||
136 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); | 136 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); |
137 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 137 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
138 | a->addTo( sub_bar ); | 138 | a->addTo( sub_bar ); |
139 | a->addTo( view ); | 139 | a->addTo( view ); |
140 | a->setToggleAction( TRUE ); | 140 | a->setToggleAction( TRUE ); |
141 | a->setOn( TRUE ); | 141 | a->setOn( TRUE ); |
142 | dayAction = a; | 142 | dayAction = a; |
143 | 143 | ||
144 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); | 144 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); |
145 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 145 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
146 | a->addTo( sub_bar ); | 146 | a->addTo( sub_bar ); |
147 | a->addTo( view ); | 147 | a->addTo( view ); |
148 | a->setToggleAction( TRUE ); | 148 | a->setToggleAction( TRUE ); |
149 | weekAction = a; | 149 | weekAction = a; |
150 | 150 | ||
151 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); | 151 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); |
152 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 152 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
153 | a->addTo( sub_bar ); | 153 | a->addTo( sub_bar ); |
154 | a->addTo( view ); | 154 | a->addTo( view ); |
155 | a->setToggleAction( TRUE ); | 155 | a->setToggleAction( TRUE ); |
156 | weekLstAction = a; | 156 | weekLstAction = a; |
157 | 157 | ||
158 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); | 158 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); |
159 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 159 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
160 | a->addTo( sub_bar ); | 160 | a->addTo( sub_bar ); |
161 | a->addTo( view ); | 161 | a->addTo( view ); |
162 | a->setToggleAction( TRUE ); | 162 | a->setToggleAction( TRUE ); |
163 | monthAction = a; | 163 | monthAction = a; |
164 | 164 | ||
165 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); | 165 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); |
166 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 166 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
167 | a->addTo( sub_bar ); | 167 | a->addTo( sub_bar ); |
168 | 168 | ||
169 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); | 169 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); |
170 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 170 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
171 | a->addTo( settings ); | 171 | a->addTo( settings ); |
172 | 172 | ||
173 | QPopupMenu *default_view = new QPopupMenu(this); | 173 | QPopupMenu *default_view = new QPopupMenu(this); |
174 | settings->insertItem( tr( "Default View" ),default_view ); | 174 | settings->insertItem( tr( "Default View" ),default_view ); |
175 | default_view->setCheckable(TRUE); | 175 | default_view->setCheckable(TRUE); |
176 | 176 | ||
177 | Config config("DateBook"); | 177 | Config config("DateBook"); |
178 | config.setGroup("Main"); | 178 | config.setGroup("Main"); |
179 | int current=config.readNumEntry("defaultview", DAY); | 179 | int current=config.readNumEntry("defaultview", DAY); |
180 | 180 | ||
181 | QActionGroup *ag = new QActionGroup(this); | 181 | QActionGroup *ag = new QActionGroup(this); |
182 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); | 182 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); |
183 | if (current==DAY) a->setOn(true), viewDay(); | 183 | if (current==DAY) a->setOn(true), viewDay(); |
184 | ag->insert(a); | 184 | ag->insert(a); |
185 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); | 185 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); |
186 | if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; | 186 | if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; |
187 | ag->insert(a); | 187 | ag->insert(a); |
188 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); | 188 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); |
189 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); | 189 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); |
190 | ag->insert(a); | 190 | ag->insert(a); |
191 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); | 191 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); |
192 | if (current==MONTH) a->setOn(true), viewMonth(); | 192 | if (current==MONTH) a->setOn(true), viewMonth(); |
193 | ag->insert(a); | 193 | ag->insert(a); |
194 | 194 | ||
195 | ag->addTo(default_view); | 195 | ag->addTo(default_view); |
196 | connect(ag, SIGNAL( selected ( QAction * ) ), | 196 | connect(ag, SIGNAL( selected ( QAction * ) ), |
197 | this, SLOT( newDefaultView(QAction *) ) | 197 | this, SLOT( newDefaultView(QAction *) ) |
198 | ); | 198 | ); |
199 | 199 | ||
200 | connect( qApp, SIGNAL(clockChanged(bool)), | 200 | connect( qApp, SIGNAL(clockChanged(bool)), |
201 | this, SLOT(changeClock(bool)) ); | 201 | this, SLOT(changeClock(bool)) ); |
202 | connect( qApp, SIGNAL(weekChanged(bool)), | 202 | connect( qApp, SIGNAL(weekChanged(bool)), |
203 | this, SLOT(changeWeek(bool)) ); | 203 | this, SLOT(changeWeek(bool)) ); |
204 | 204 | ||
205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
206 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 206 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
207 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 207 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
208 | #endif | 208 | #endif |
209 | 209 | ||
210 | // listen on QPE/System | 210 | // listen on QPE/System |
211 | #if defined(Q_WS_QWS) | 211 | #if defined(Q_WS_QWS) |
212 | #if !defined(QT_NO_COP) | 212 | #if !defined(QT_NO_COP) |
213 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 213 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
214 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 214 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
215 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 215 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
216 | channel = new QCopChannel( "QPE/Datebook", this ); | 216 | channel = new QCopChannel( "QPE/Datebook", this ); |
217 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 217 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
218 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 218 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
219 | qDebug("olle\n"); | 219 | qDebug("olle\n"); |
220 | #endif | 220 | #endif |
221 | #endif | 221 | #endif |
222 | 222 | ||
223 | qDebug("done t=%d", t.elapsed() ); | 223 | qDebug("done t=%d", t.elapsed() ); |
224 | 224 | ||
225 | /* | 225 | /* |
226 | * Here is a problem description: | 226 | * Here is a problem description: |
227 | * When Weekview is the default view | 227 | * When Weekview is the default view |
228 | * a DateBookWeekView get's created | 228 | * a DateBookWeekView get's created |
229 | * redraw() get's called. So what? | 229 | * redraw() get's called. So what? |
230 | * Remember that we're still in the c'tor | 230 | * Remember that we're still in the c'tor |
231 | * and no final layout has happened? Ok | 231 | * and no final layout has happened? Ok |
232 | * now all Events get arranged. Their x | 232 | * now all Events get arranged. Their x |
233 | * position get's determined by a QHeader | 233 | * position get's determined by a QHeader |
234 | * position. But the QHeader isn't layouted or | 234 | * position. But the QHeader isn't layouted or |
235 | * at the right position. redraw() is a slot | 235 | * at the right position. redraw() is a slot |
236 | * so we'll call it then via a singleShot | 236 | * so we'll call it then via a singleShot |
237 | * from view() | 237 | * from view() |
238 | */ | 238 | */ |
239 | if( needEvilHack ){ | 239 | if( needEvilHack ){ |
240 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); | 240 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 244 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
245 | { | 245 | { |
246 | QDataStream stream( data, IO_ReadOnly ); | 246 | QDataStream stream( data, IO_ReadOnly ); |
247 | if ( msg == "timeChange(QString)" ) { | 247 | if ( msg == "timeChange(QString)" ) { |
248 | // update active view! | 248 | // update active view! |
249 | if ( dayAction->isOn() ) | 249 | if ( dayAction->isOn() ) |
250 | viewDay(); | 250 | viewDay(); |
251 | else if ( weekAction->isOn() ) | 251 | else if ( weekAction->isOn() ) |
252 | viewWeek(); | 252 | viewWeek(); |
253 | else if ( monthAction->isOn() ) | 253 | else if ( monthAction->isOn() ) |
254 | viewMonth(); | 254 | viewMonth(); |
255 | } | 255 | } |
256 | else if (msg == "editEvent(int)") { | 256 | else if (msg == "editEvent(int)") { |
257 | int uid; | 257 | int uid; |
258 | stream >> uid; | 258 | stream >> uid; |
259 | Event e=db->eventByUID(uid); | 259 | Event e=db->eventByUID(uid); |
260 | editEvent(e); | 260 | editEvent(e); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | 263 | ||
264 | DateBook::~DateBook() | 264 | DateBook::~DateBook() |
265 | { | 265 | { |
266 | } | 266 | } |
267 | 267 | ||
268 | void DateBook::slotSettings() | 268 | void DateBook::slotSettings() |
269 | { | 269 | { |
270 | DateBookSettings frmSettings( ampm, this ); | 270 | DateBookSettings frmSettings( ampm, this ); |
271 | frmSettings.setStartTime( startTime ); | 271 | frmSettings.setStartTime( startTime ); |
272 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 272 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
273 | frmSettings.setJumpToCurTime( bJumpToCurTime ); | 273 | frmSettings.setJumpToCurTime( bJumpToCurTime ); |
274 | frmSettings.setRowStyle( rowStyle ); | 274 | frmSettings.setRowStyle( rowStyle ); |
275 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 275 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
276 | frmSettings.showMaximized(); | 276 | frmSettings.showMaximized(); |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | if ( frmSettings.exec() ) { | 279 | if ( frmSettings.exec() ) { |
280 | aPreset = frmSettings.alarmPreset(); | 280 | |
281 | presetTime = frmSettings.presetTime(); | 281 | aPreset = frmSettings.alarmPreset(); |
282 | startTime = frmSettings.startTime(); | 282 | presetTime = frmSettings.presetTime(); |
283 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 283 | startTime = frmSettings.startTime(); |
284 | rowStyle = frmSettings.rowStyle(); | 284 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
285 | if ( dayView ) | 285 | rowStyle = frmSettings.rowStyle(); |
286 | dayView->setStartViewTime( startTime ); | 286 | |
287 | dayView->setJumpToCurTime( bJumpToCurTime ); | 287 | if ( dayView ) { |
288 | dayView->setRowStyle( rowStyle ); | 288 | dayView->setStartViewTime( startTime ); |
289 | if ( weekView ) | 289 | dayView->setJumpToCurTime( bJumpToCurTime ); |
290 | weekView->setStartViewTime( startTime ); | 290 | dayView->setRowStyle( rowStyle ); |
291 | saveSettings(); | 291 | } |
292 | 292 | if ( weekView ) { | |
293 | // make the change obvious | 293 | weekView->setStartViewTime( startTime ); |
294 | if ( views->visibleWidget() ) { | 294 | } |
295 | if ( views->visibleWidget() == dayView ) | 295 | saveSettings(); |
296 | dayView->redraw(); | 296 | |
297 | else if ( views->visibleWidget() == weekView ) | 297 | // make the change obvious |
298 | weekView->redraw(); | 298 | if ( views->visibleWidget() ) { |
299 | if ( views->visibleWidget() == dayView ) | ||
300 | dayView->redraw(); | ||
301 | else if ( views->visibleWidget() == weekView ) | ||
302 | weekView->redraw(); | ||
303 | } | ||
299 | } | 304 | } |
300 | } | ||
301 | } | 305 | } |
302 | 306 | ||
303 | void DateBook::fileNew() | 307 | void DateBook::fileNew() |
304 | { | 308 | { |
305 | slotNewEventFromKey(""); | 309 | slotNewEventFromKey(""); |
306 | } | 310 | } |
307 | 311 | ||
308 | QString DateBook::checkEvent(const Event &e) | 312 | QString DateBook::checkEvent(const Event &e) |
309 | { | 313 | { |
310 | /* check if overlaps with itself */ | 314 | /* check if overlaps with itself */ |
311 | bool checkFailed = FALSE; | 315 | bool checkFailed = FALSE; |
312 | 316 | ||
313 | /* check the next 12 repeats. should catch most problems */ | 317 | /* check the next 12 repeats. should catch most problems */ |
314 | QDate current_date = e.start().date(); | 318 | QDate current_date = e.start().date(); |
315 | Event previous = e; | 319 | Event previous = e; |
316 | for(int i = 0; i < 12; i++) | 320 | for(int i = 0; i < 12; i++) |
317 | { | 321 | { |
318 | QDateTime next; | 322 | QDateTime next; |
319 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 323 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
320 | break; // no more repeats | 324 | break; // no more repeats |
321 | } | 325 | } |
322 | if(next < previous.end()) { | 326 | if(next < previous.end()) { |
323 | checkFailed = TRUE; | 327 | checkFailed = TRUE; |
324 | break; | 328 | break; |
325 | } | 329 | } |
326 | current_date = next.date(); | 330 | current_date = next.date(); |
327 | } | 331 | } |
328 | 332 | ||
329 | if(checkFailed) | 333 | if(checkFailed) |
330 | return tr("Event duration is potentially longer\n" | 334 | return tr("Event duration is potentially longer\n" |
331 | "than interval between repeats."); | 335 | "than interval between repeats."); |
332 | 336 | ||
333 | return QString::null; | 337 | return QString::null; |
334 | } | 338 | } |
335 | 339 | ||
336 | QDate DateBook::currentDate() | 340 | QDate DateBook::currentDate() |
337 | { | 341 | { |
338 | QDate d = QDate::currentDate(); | 342 | QDate d = QDate::currentDate(); |
339 | 343 | ||
340 | if ( dayView && views->visibleWidget() == dayView ) { | 344 | if ( dayView && views->visibleWidget() == dayView ) { |
341 | d = dayView->date(); | 345 | d = dayView->date(); |
342 | } else if ( weekView && views->visibleWidget() == weekView ) { | 346 | } else if ( weekView && views->visibleWidget() == weekView ) { |
343 | d = weekView->date(); | 347 | d = weekView->date(); |
344 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 348 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
345 | d = weekLstView->date(); | 349 | d = weekLstView->date(); |
346 | } else if ( monthView && views->visibleWidget() == monthView ) { | 350 | } else if ( monthView && views->visibleWidget() == monthView ) { |
347 | d = monthView->selectedDate(); | 351 | d = monthView->selectedDate(); |
348 | } | 352 | } |
349 | 353 | ||
350 | return d; | 354 | return d; |
351 | } | 355 | } |
352 | 356 | ||
353 | void DateBook::view(int v, const QDate &d) { | 357 | void DateBook::view(int v, const QDate &d) { |
354 | if (v==DAY) { | 358 | if (v==DAY) { |
355 | initDay(); | 359 | initDay(); |
356 | dayAction->setOn( TRUE ); | 360 | dayAction->setOn( TRUE ); |
357 | dayView->setDate( d ); | 361 | dayView->setDate( d ); |
358 | views->raiseWidget( dayView ); | 362 | views->raiseWidget( dayView ); |
359 | dayView->redraw(); | 363 | dayView->redraw(); |
360 | } else if (v==WEEK) { | 364 | } else if (v==WEEK) { |
361 | initWeek(); | 365 | initWeek(); |
362 | weekAction->setOn( TRUE ); | 366 | weekAction->setOn( TRUE ); |
363 | weekView->setDate( d ); | 367 | weekView->setDate( d ); |
364 | views->raiseWidget( weekView ); | 368 | views->raiseWidget( weekView ); |
365 | weekView->redraw(); | 369 | weekView->redraw(); |
366 | } else if (v==WEEKLST) { | 370 | } else if (v==WEEKLST) { |
367 | initWeekLst(); | 371 | initWeekLst(); |
368 | weekLstAction->setOn( TRUE ); | 372 | weekLstAction->setOn( TRUE ); |
369 | weekLstView->setDate(d); | 373 | weekLstView->setDate(d); |
370 | views->raiseWidget( weekLstView ); | 374 | views->raiseWidget( weekLstView ); |
371 | weekLstView->redraw(); | 375 | weekLstView->redraw(); |
372 | } else if (v==MONTH) { | 376 | } else if (v==MONTH) { |
373 | initMonth(); | 377 | initMonth(); |
374 | monthAction->setOn( TRUE ); | 378 | monthAction->setOn( TRUE ); |
375 | monthView->setDate( d.year(), d.month(), d.day() ); | 379 | monthView->setDate( d.year(), d.month(), d.day() ); |
376 | views->raiseWidget( monthView ); | 380 | views->raiseWidget( monthView ); |
377 | monthView->redraw(); | 381 | monthView->redraw(); |
378 | } | 382 | } |
379 | } | 383 | } |
380 | 384 | ||
381 | void DateBook::viewDefault(const QDate &d) { | 385 | void DateBook::viewDefault(const QDate &d) { |
382 | Config config("DateBook"); | 386 | Config config("DateBook"); |
383 | config.setGroup("Main"); | 387 | config.setGroup("Main"); |
384 | int current=config.readNumEntry("defaultview", DAY); | 388 | int current=config.readNumEntry("defaultview", DAY); |
385 | 389 | ||
386 | view(current,d); | 390 | view(current,d); |
387 | } | 391 | } |
388 | 392 | ||
389 | void DateBook::viewDay() { | 393 | void DateBook::viewDay() { |
390 | view(DAY,currentDate()); | 394 | view(DAY,currentDate()); |
391 | } | 395 | } |
392 | 396 | ||
393 | void DateBook::viewWeek() { | 397 | void DateBook::viewWeek() { |
394 | view(WEEK,currentDate()); | 398 | view(WEEK,currentDate()); |
395 | } | 399 | } |
396 | 400 | ||
397 | void DateBook::viewWeekLst() { | 401 | void DateBook::viewWeekLst() { |
398 | view(WEEKLST,currentDate()); | 402 | view(WEEKLST,currentDate()); |
399 | } | 403 | } |
400 | 404 | ||
401 | void DateBook::viewMonth() { | 405 | void DateBook::viewMonth() { |
402 | view(MONTH,currentDate()); | 406 | view(MONTH,currentDate()); |
403 | } | 407 | } |
404 | 408 | ||
405 | void DateBook::duplicateEvent( const Event &e ) | 409 | void DateBook::duplicateEvent( const Event &e ) |
406 | { | 410 | { |
407 | qWarning("Hmmm..."); | 411 | qWarning("Hmmm..."); |
408 | // Alot of code duplication, as this is almost like editEvent(); | 412 | // Alot of code duplication, as this is almost like editEvent(); |
409 | if (syncing) { | 413 | if (syncing) { |
410 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 414 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
411 | return; | 415 | return; |
412 | } | 416 | } |
413 | 417 | ||
414 | Event dupevent(e);// Make a duplicate. | 418 | Event dupevent(e);// Make a duplicate. |
415 | 419 | ||
416 | // workaround added for text input. | 420 | // workaround added for text input. |
417 | QDialog editDlg( this, 0, TRUE ); | 421 | QDialog editDlg( this, 0, TRUE ); |
418 | DateEntry *entry; | 422 | DateEntry *entry; |
419 | editDlg.setCaption( tr("Duplicate Event") ); | 423 | editDlg.setCaption( tr("Duplicate Event") ); |
420 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 424 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
421 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 425 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
422 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 426 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
423 | // KLUDGE!!! | 427 | // KLUDGE!!! |
424 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 428 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
425 | vb->addWidget( sv ); | 429 | vb->addWidget( sv ); |
426 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); | 430 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); |
427 | entry->timezone->setEnabled( FALSE ); | 431 | entry->timezone->setEnabled( FALSE ); |
428 | sv->addChild( entry ); | 432 | sv->addChild( entry ); |
429 | 433 | ||
430 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 434 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
431 | editDlg.showMaximized(); | 435 | editDlg.showMaximized(); |
432 | #endif | 436 | #endif |
433 | while (editDlg.exec() ) { | 437 | while (editDlg.exec() ) { |
434 | Event newEv = entry->event(); | 438 | Event newEv = entry->event(); |
435 | QString error = checkEvent(newEv); | 439 | QString error = checkEvent(newEv); |
436 | if (!error.isNull()) { | 440 | if (!error.isNull()) { |
437 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) | 441 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) |
438 | continue; | 442 | continue; |
439 | } | 443 | } |
440 | db->addEvent(newEv); | 444 | db->addEvent(newEv); |
441 | emit newEvent(); | 445 | emit newEvent(); |
442 | break; | 446 | break; |
443 | } | 447 | } |
444 | } | 448 | } |
445 | 449 | ||
446 | void DateBook::editEvent( const Event &e ) | 450 | void DateBook::editEvent( const Event &e ) |
447 | { | 451 | { |
448 | if (syncing) { | 452 | if (syncing) { |
449 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 453 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
450 | return; | 454 | return; |
451 | } | 455 | } |
452 | 456 | ||
453 | // workaround added for text input. | 457 | // workaround added for text input. |
454 | QDialog editDlg( this, 0, TRUE ); | 458 | QDialog editDlg( this, 0, TRUE ); |
455 | DateEntry *entry; | 459 | DateEntry *entry; |
456 | editDlg.setCaption( tr("Edit Event") ); | 460 | editDlg.setCaption( tr("Edit Event") ); |
457 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 461 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
458 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 462 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
459 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 463 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
460 | // KLUDGE!!! | 464 | // KLUDGE!!! |
461 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 465 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
462 | vb->addWidget( sv ); | 466 | vb->addWidget( sv ); |
463 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 467 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
464 | entry->timezone->setEnabled( FALSE ); | 468 | entry->timezone->setEnabled( FALSE ); |
465 | sv->addChild( entry ); | 469 | sv->addChild( entry ); |
466 | 470 | ||
467 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 471 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
468 | editDlg.showMaximized(); | 472 | editDlg.showMaximized(); |
469 | #endif | 473 | #endif |
470 | while (editDlg.exec() ) { | 474 | while (editDlg.exec() ) { |
471 | Event newEv = entry->event(); | 475 | Event newEv = entry->event(); |
472 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) | 476 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) |
473 | break; | 477 | break; |
474 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 478 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
475 | QString error = checkEvent(newEv); | 479 | QString error = checkEvent(newEv); |
476 | if (!error.isNull()) { | 480 | if (!error.isNull()) { |
477 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; | 481 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; |
478 | } | 482 | } |
479 | db->editEvent(e, newEv); | 483 | db->editEvent(e, newEv); |
480 | emit newEvent(); | 484 | emit newEvent(); |
481 | break; | 485 | break; |
482 | } | 486 | } |
483 | } | 487 | } |
484 | 488 | ||
485 | void DateBook::removeEvent( const Event &e ) | 489 | void DateBook::removeEvent( const Event &e ) |
486 | { | 490 | { |
487 | if (syncing) { | 491 | if (syncing) { |
488 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 492 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
489 | return; | 493 | return; |
490 | } | 494 | } |
491 | 495 | ||
492 | QString strName = e.description(); | 496 | QString strName = e.description(); |
493 | 497 | ||
494 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 498 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
495 | return; | 499 | return; |
496 | 500 | ||
497 | db->removeEvent( e ); | 501 | db->removeEvent( e ); |
498 | if ( views->visibleWidget() == dayView && dayView ) | 502 | if ( views->visibleWidget() == dayView && dayView ) |
499 | dayView->redraw(); | 503 | dayView->redraw(); |
500 | } | 504 | } |
501 | 505 | ||
502 | void DateBook::addEvent( const Event &e ) | 506 | void DateBook::addEvent( const Event &e ) |
503 | { | 507 | { |
504 | QDate d = e.start().date(); | 508 | QDate d = e.start().date(); |
505 | initDay(); | 509 | initDay(); |
506 | dayView->setDate( d ); | 510 | dayView->setDate( d ); |
507 | } | 511 | } |
508 | 512 | ||
509 | void DateBook::showDay( int year, int month, int day ) | 513 | void DateBook::showDay( int year, int month, int day ) |
510 | { | 514 | { |
511 | QDate d(year, month, day); | 515 | QDate d(year, month, day); |
512 | view(DAY,d); | 516 | view(DAY,d); |
513 | } | 517 | } |
514 | 518 | ||
515 | void DateBook::initDay() | 519 | void DateBook::initDay() |
516 | { | 520 | { |
517 | if ( !dayView ) { | 521 | if ( !dayView ) { |
518 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 522 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
519 | views->addWidget( dayView, DAY ); | 523 | views->addWidget( dayView, DAY ); |
520 | dayView->setStartViewTime( startTime ); | 524 | dayView->setStartViewTime( startTime ); |
521 | dayView->setJumpToCurTime( bJumpToCurTime ); | 525 | dayView->setJumpToCurTime( bJumpToCurTime ); |
522 | dayView->setRowStyle( rowStyle ); | 526 | dayView->setRowStyle( rowStyle ); |
523 | connect( this, SIGNAL( newEvent() ), | 527 | connect( this, SIGNAL( newEvent() ), |
524 | dayView, SLOT( redraw() ) ); | 528 | dayView, SLOT( redraw() ) ); |
525 | connect( dayView, SIGNAL( newEvent() ), | 529 | connect( dayView, SIGNAL( newEvent() ), |
526 | this, SLOT( fileNew() ) ); | 530 | this, SLOT( fileNew() ) ); |
527 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), | 531 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), |
528 | this, SLOT( removeEvent( const Event & ) ) ); | 532 | this, SLOT( removeEvent( const Event & ) ) ); |
529 | connect( dayView, SIGNAL( editEvent( const Event & ) ), | 533 | connect( dayView, SIGNAL( editEvent( const Event & ) ), |
530 | this, SLOT( editEvent( const Event & ) ) ); | 534 | this, SLOT( editEvent( const Event & ) ) ); |
531 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), | 535 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), |
532 | this, SLOT( duplicateEvent( const Event & ) ) ); | 536 | this, SLOT( duplicateEvent( const Event & ) ) ); |
533 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), | 537 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), |
534 | this, SLOT( beamEvent( const Event & ) ) ); | 538 | this, SLOT( beamEvent( const Event & ) ) ); |
535 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), | 539 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), |
536 | this, SLOT(slotNewEventFromKey(const QString &)) ); | 540 | this, SLOT(slotNewEventFromKey(const QString &)) ); |
537 | } | 541 | } |
538 | } | 542 | } |
539 | 543 | ||
540 | void DateBook::initWeek() | 544 | void DateBook::initWeek() |
541 | { | 545 | { |
542 | if ( !weekView ) { | 546 | if ( !weekView ) { |
543 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 547 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
544 | weekView->setStartViewTime( startTime ); | 548 | weekView->setStartViewTime( startTime ); |
545 | views->addWidget( weekView, WEEK ); | 549 | views->addWidget( weekView, WEEK ); |
546 | connect( weekView, SIGNAL( showDate( int, int, int ) ), | 550 | connect( weekView, SIGNAL( showDate( int, int, int ) ), |
547 | this, SLOT( showDay( int, int, int ) ) ); | 551 | this, SLOT( showDay( int, int, int ) ) ); |
548 | connect( this, SIGNAL( newEvent() ), | 552 | connect( this, SIGNAL( newEvent() ), |
549 | weekView, SLOT( redraw() ) ); | 553 | weekView, SLOT( redraw() ) ); |
550 | } | 554 | } |
551 | //But also get it right: the year that we display can be different | ||
552 | //from the year of the current date. So, first find the year | ||
553 | //number of the current week. | ||
554 | |||
555 | int yearNumber, totWeeks; | ||
556 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | ||
557 | 555 | ||
558 | QDate d = QDate( yearNumber, 12, 31 ); | 556 | //But also get it right: the year that we display can be different |
559 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 557 | //from the year of the current date. So, first find the year |
558 | //number of the current week. | ||
559 | int yearNumber, totWeeks; | ||
560 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | ||
560 | 561 | ||
561 | while ( totWeeks == 1 ) { | 562 | QDate d = QDate( yearNumber, 12, 31 ); |
562 | d = d.addDays( -1 ); | ||
563 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 563 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
564 | } | 564 | |
565 | if ( totWeeks != weekView->totalWeeks() ) | 565 | while ( totWeeks == 1 ) { |
566 | weekView->setTotalWeeks( totWeeks ); | 566 | d = d.addDays( -1 ); |
567 | calcWeek( d, totWeeks, yearNumber, onMonday ); | ||
568 | } | ||
569 | if ( totWeeks != weekView->totalWeeks() ) | ||
570 | weekView->setTotalWeeks( totWeeks ); | ||
567 | } | 571 | } |
572 | |||
568 | void DateBook::initWeekLst() { | 573 | void DateBook::initWeekLst() { |
569 | if ( !weekLstView ) { | 574 | if ( !weekLstView ) { |
570 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, | 575 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, |
571 | views, "weeklst view" ); | 576 | views, "weeklst view" ); |
572 | views->addWidget( weekLstView, WEEKLST ); | 577 | views->addWidget( weekLstView, WEEKLST ); |
573 | 578 | ||
574 | //weekLstView->setStartViewTime( startTime ); | 579 | //weekLstView->setStartViewTime( startTime ); |
575 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), | 580 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), |
576 | this, SLOT( showDay( int, int, int ) ) ); | 581 | this, SLOT( showDay( int, int, int ) ) ); |
577 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, | 582 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, |
578 | const QDateTime &, | 583 | const QDateTime &, |
579 | const QString & , const QString &) ), | 584 | const QString & , const QString &) ), |
580 | this, SLOT( slotNewEntry( const QDateTime &, | 585 | this, SLOT( slotNewEntry( const QDateTime &, |
581 | const QDateTime &, | 586 | const QDateTime &, |
582 | const QString & , const QString &) ) ); | 587 | const QString & , const QString &) ) ); |
583 | connect( this, SIGNAL( newEvent() ), | 588 | connect( this, SIGNAL( newEvent() ), |
584 | weekLstView, SLOT( redraw() ) ); | 589 | weekLstView, SLOT( redraw() ) ); |
585 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), | 590 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), |
586 | this, SLOT( editEvent( const Event & ) ) ); | 591 | this, SLOT( editEvent( const Event & ) ) ); |
587 | } | 592 | } |
588 | } | 593 | } |
589 | 594 | ||
590 | 595 | ||
591 | void DateBook::initMonth() | 596 | void DateBook::initMonth() |
592 | { | 597 | { |
593 | if ( !monthView ) { | 598 | if ( !monthView ) { |
594 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 599 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
595 | views->addWidget( monthView, MONTH ); | 600 | views->addWidget( monthView, MONTH ); |
596 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), | 601 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), |
597 | this, SLOT( showDay( int, int, int ) ) ); | 602 | this, SLOT( showDay( int, int, int ) ) ); |
598 | connect( this, SIGNAL( newEvent() ), | 603 | connect( this, SIGNAL( newEvent() ), |
599 | monthView, SLOT( redraw() ) ); | 604 | monthView, SLOT( redraw() ) ); |
600 | qApp->processEvents(); | 605 | qApp->processEvents(); |
601 | } | 606 | } |
602 | } | 607 | } |
603 | 608 | ||
604 | void DateBook::loadSettings() | 609 | void DateBook::loadSettings() |
605 | { | 610 | { |
606 | { | 611 | { |
607 | Config config( "qpe" ); | 612 | Config config( "qpe" ); |
608 | config.setGroup("Time"); | 613 | config.setGroup("Time"); |
609 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 614 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
610 | onMonday = config.readBoolEntry( "MONDAY" ); | 615 | onMonday = config.readBoolEntry( "MONDAY" ); |
611 | } | 616 | } |
612 | 617 | ||
613 | { | 618 | { |
614 | Config config("DateBook"); | 619 | Config config("DateBook"); |
615 | config.setGroup("Main"); | 620 | config.setGroup("Main"); |
616 | startTime = config.readNumEntry("startviewtime", 8); | 621 | startTime = config.readNumEntry("startviewtime", 8); |
617 | aPreset = config.readBoolEntry("alarmpreset"); | 622 | aPreset = config.readBoolEntry("alarmpreset"); |
618 | presetTime = config.readNumEntry("presettime"); | 623 | presetTime = config.readNumEntry("presettime"); |
619 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); | 624 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); |
620 | rowStyle = config.readNumEntry("rowstyle"); | 625 | rowStyle = config.readNumEntry("rowstyle"); |
621 | } | 626 | } |
622 | } | 627 | } |
623 | 628 | ||
624 | void DateBook::saveSettings() | 629 | void DateBook::saveSettings() |
625 | { | 630 | { |
626 | Config config( "qpe" ); | 631 | Config config( "qpe" ); |
627 | Config configDB( "DateBook" ); | 632 | Config configDB( "DateBook" ); |
628 | configDB.setGroup( "Main" ); | 633 | configDB.setGroup( "Main" ); |
629 | configDB.writeEntry("startviewtime",startTime); | 634 | configDB.writeEntry("startviewtime",startTime); |
630 | configDB.writeEntry("alarmpreset",aPreset); | 635 | configDB.writeEntry("alarmpreset",aPreset); |
631 | configDB.writeEntry("presettime",presetTime); | 636 | configDB.writeEntry("presettime",presetTime); |
632 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); | 637 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); |
633 | configDB.writeEntry("rowstyle", rowStyle); | 638 | configDB.writeEntry("rowstyle", rowStyle); |
634 | } | 639 | } |
635 | 640 | ||
636 | void DateBook::newDefaultView(QAction *a) { | 641 | void DateBook::newDefaultView(QAction *a) { |
637 | int val=DAY; | 642 | int val=DAY; |
638 | if (a->text() == "Day") val=DAY; | 643 | if (a->text() == "Day") val=DAY; |
639 | if (a->text() == "Week") val=WEEK; | 644 | if (a->text() == "Week") val=WEEK; |
640 | if (a->text() == "WeekLst") val=WEEKLST; | 645 | if (a->text() == "WeekLst") val=WEEKLST; |
641 | if (a->text() == "Month") val=MONTH; | 646 | if (a->text() == "Month") val=MONTH; |
642 | 647 | ||
643 | Config configDB( "DateBook" ); | 648 | Config configDB( "DateBook" ); |
644 | configDB.setGroup( "Main" ); | 649 | configDB.setGroup( "Main" ); |
645 | configDB.writeEntry("defaultview",val); | 650 | configDB.writeEntry("defaultview",val); |
646 | } | 651 | } |
647 | 652 | ||
648 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 653 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
649 | { | 654 | { |
650 | bool needShow = FALSE; | 655 | bool needShow = FALSE; |
651 | if ( msg == "alarm(QDateTime,int)" ) { | 656 | if ( msg == "alarm(QDateTime,int)" ) { |
652 | QDataStream ds(data,IO_ReadOnly); | 657 | QDataStream ds(data,IO_ReadOnly); |
653 | QDateTime when; int warn; | 658 | QDateTime when; int warn; |
654 | ds >> when >> warn; | 659 | ds >> when >> warn; |
655 | 660 | ||
656 | // check to make it's okay to continue, | 661 | // check to make it's okay to continue, |
657 | // this is the case that the time was set ahead, and | 662 | // this is the case that the time was set ahead, and |
658 | // we are forced given a stale alarm... | 663 | // we are forced given a stale alarm... |
659 | QDateTime current = QDateTime::currentDateTime(); | 664 | QDateTime current = QDateTime::currentDateTime(); |
660 | if ( current.time().hour() != when.time().hour() | 665 | if ( current.time().hour() != when.time().hour() |
661 | && current.time().minute() != when.time().minute() ) | 666 | && current.time().minute() != when.time().minute() ) |
662 | return; | 667 | return; |
663 | 668 | ||
664 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 669 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
665 | if ( list.count() > 0 ) { | 670 | if ( list.count() > 0 ) { |
666 | QString msg; | 671 | QString msg; |
667 | bool bSound = FALSE; | 672 | bool bSound = FALSE; |
668 | int stopTimer = 0; | 673 | int stopTimer = 0; |
669 | bool found = FALSE; | 674 | bool found = FALSE; |
670 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 675 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
671 | it!=list.end(); ++it ) { | 676 | it!=list.end(); ++it ) { |
672 | if ( (*it).event().hasAlarm() ) { | 677 | if ( (*it).event().hasAlarm() ) { |
673 | found = TRUE; | 678 | found = TRUE; |
674 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 679 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
675 | + "<BR>" + (*it).location() + "<BR>" | 680 | + "<BR>" + (*it).location() + "<BR>" |
676 | + TimeString::dateString((*it).event().start(),ampm) | 681 | + TimeString::dateString((*it).event().start(),ampm) |
677 | + (warn | 682 | + (warn |
678 | ? tr(" (in " + QString::number(warn) | 683 | ? tr(" (in " + QString::number(warn) |
679 | + tr(" minutes)")) | 684 | + tr(" minutes)")) |
680 | : QString("")) | 685 | : QString("")) |
681 | + "<BR>" | 686 | + "<BR>" |
682 | + (*it).notes() + "</CENTER>"; | 687 | + (*it).notes() + "</CENTER>"; |
683 | if ( (*it).event().alarmSound() != Event::Silent ) { | 688 | if ( (*it).event().alarmSound() != Event::Silent ) { |
684 | bSound = TRUE; | 689 | bSound = TRUE; |
685 | } | 690 | } |
686 | } | 691 | } |
687 | } | 692 | } |
688 | if ( found ) { | 693 | if ( found ) { |
689 | if ( bSound ) { | 694 | if ( bSound ) { |
690 | Sound::soundAlarm(); | 695 | Sound::soundAlarm(); |
691 | alarmCounter = 0; | 696 | alarmCounter = 0; |
692 | stopTimer = startTimer( 5000 ); | 697 | stopTimer = startTimer( 5000 ); |
693 | } | 698 | } |
694 | 699 | ||
695 | QDialog dlg( this, 0, TRUE ); | 700 | QDialog dlg( this, 0, TRUE ); |
696 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 701 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
697 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 702 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
698 | view->setResizePolicy( QScrollView::AutoOneFit ); | 703 | view->setResizePolicy( QScrollView::AutoOneFit ); |
699 | vb->addWidget( view ); | 704 | vb->addWidget( view ); |
700 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 705 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
701 | view->addChild( lblMsg ); | 706 | view->addChild( lblMsg ); |
702 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 707 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
703 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 708 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
704 | vb->addWidget( cmdOk ); | 709 | vb->addWidget( cmdOk ); |
705 | 710 | ||
706 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 711 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
707 | dlg.showMaximized(); | 712 | dlg.showMaximized(); |
708 | #endif | 713 | #endif |
709 | needShow = dlg.exec(); | 714 | needShow = dlg.exec(); |
710 | 715 | ||
711 | if ( bSound ) | 716 | if ( bSound ) |
712 | killTimer( stopTimer ); | 717 | killTimer( stopTimer ); |
713 | } | 718 | } |
714 | } | 719 | } |
715 | } else if ( msg == "nextView()" ) { | 720 | } else if ( msg == "nextView()" ) { |
716 | if ( !qApp-> activeWindow ( )) { | 721 | if ( !qApp-> activeWindow ( )) { |
717 | needShow = TRUE; | 722 | needShow = TRUE; |
718 | } | 723 | } |
719 | else { | 724 | else { |
720 | QWidget* cur = views->visibleWidget(); | 725 | QWidget* cur = views->visibleWidget(); |
721 | if ( cur ) { | 726 | if ( cur ) { |
722 | if ( cur == dayView ) | 727 | if ( cur == dayView ) |
723 | viewWeek(); | 728 | viewWeek(); |
724 | else if ( cur == weekView ) | 729 | else if ( cur == weekView ) |
725 | viewWeekLst(); | 730 | viewWeekLst(); |
726 | else if ( cur == weekLstView ) | 731 | else if ( cur == weekLstView ) |
727 | viewMonth(); | 732 | viewMonth(); |
728 | else if ( cur == monthView ) | 733 | else if ( cur == monthView ) |
729 | viewDay(); | 734 | viewDay(); |
730 | needShow = TRUE; | 735 | needShow = TRUE; |
731 | } | 736 | } |
732 | } | 737 | } |
733 | } | 738 | } |
734 | if ( needShow ) { | 739 | if ( needShow ) { |
735 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 740 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
736 | showMaximized(); | 741 | showMaximized(); |
737 | #else | 742 | #else |
738 | show(); | 743 | show(); |
739 | #endif | 744 | #endif |
740 | raise(); | 745 | raise(); |
741 | QPEApplication::setKeepRunning(); | 746 | QPEApplication::setKeepRunning(); |
742 | setActiveWindow(); | 747 | setActiveWindow(); |
743 | } | 748 | } |
744 | } | 749 | } |
745 | 750 | ||
746 | void DateBook::reload() | 751 | void DateBook::reload() |
747 | { | 752 | { |
748 | db->reload(); | 753 | db->reload(); |
749 | if ( dayAction->isOn() ) | 754 | if ( dayAction->isOn() ) |
750 | viewDay(); | 755 | viewDay(); |
751 | else if ( weekAction->isOn() ) | 756 | else if ( weekAction->isOn() ) |
752 | viewWeek(); | 757 | viewWeek(); |
753 | else if ( monthAction->isOn() ) | 758 | else if ( monthAction->isOn() ) |
754 | viewMonth(); | 759 | viewMonth(); |
755 | syncing = FALSE; | 760 | syncing = FALSE; |
756 | } | 761 | } |
757 | 762 | ||
758 | void DateBook::flush() | 763 | void DateBook::flush() |
759 | { | 764 | { |
760 | syncing = TRUE; | 765 | syncing = TRUE; |
761 | db->save(); | 766 | db->save(); |
762 | } | 767 | } |
763 | 768 | ||
764 | void DateBook::timerEvent( QTimerEvent *e ) | 769 | void DateBook::timerEvent( QTimerEvent *e ) |
765 | { | 770 | { |
766 | if ( alarmCounter < 10 ) { | 771 | if ( alarmCounter < 10 ) { |
767 | alarmCounter++; | 772 | alarmCounter++; |
768 | Sound::soundAlarm(); | 773 | Sound::soundAlarm(); |
769 | } | 774 | } |
770 | else | 775 | else |
771 | killTimer( e->timerId() ); | 776 | killTimer( e->timerId() ); |
772 | } | 777 | } |
773 | 778 | ||
774 | void DateBook::changeClock( bool newClock ) | 779 | void DateBook::changeClock( bool newClock ) |
775 | { | 780 | { |
776 | ampm = newClock; | 781 | ampm = newClock; |
777 | // repaint the affected objects... | 782 | // repaint the affected objects... |
778 | if (dayView) dayView->redraw(); | 783 | if (dayView) dayView->redraw(); |
779 | if (weekView) weekView->redraw(); | 784 | if (weekView) weekView->redraw(); |
780 | if (weekLstView) weekLstView->redraw(); | 785 | if (weekLstView) weekLstView->redraw(); |
781 | } | 786 | } |
782 | 787 | ||
783 | void DateBook::changeWeek( bool m ) | 788 | void DateBook::changeWeek( bool m ) |
784 | { | 789 | { |
785 | /* no need to redraw, each widget catches. Do need to | 790 | /* no need to redraw, each widget catches. Do need to |
786 | store though for widgets we haven't made yet */ | 791 | store though for widgets we haven't made yet */ |
787 | onMonday = m; | 792 | onMonday = m; |
788 | } | 793 | } |
789 | 794 | ||
790 | void DateBook::slotToday() | 795 | void DateBook::slotToday() |
791 | { | 796 | { |
792 | // we need to view today using default view | 797 | // we need to view today using default view |
793 | viewDefault(QDate::currentDate()); | 798 | viewDefault(QDate::currentDate()); |
794 | } | 799 | } |
795 | 800 | ||
796 | void DateBook::closeEvent( QCloseEvent *e ) | 801 | void DateBook::closeEvent( QCloseEvent *e ) |
797 | { | 802 | { |
798 | if(syncing) { | 803 | if(syncing) { |
799 | /* no need to save, did that at flush */ | 804 | /* no need to save, did that at flush */ |
800 | e->accept(); | 805 | e->accept(); |
801 | return; | 806 | return; |
802 | } | 807 | } |
803 | 808 | ||
804 | // save settings will generate it's own error messages, no | 809 | // save settings will generate it's own error messages, no |
805 | // need to do checking ourselves. | 810 | // need to do checking ourselves. |
806 | saveSettings(); | 811 | saveSettings(); |
807 | if ( db->save() ) | 812 | if ( db->save() ) |
808 | e->accept(); | 813 | e->accept(); |
809 | else { | 814 | else { |
810 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 815 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
811 | tr("Calendar was unable to save\n" | 816 | tr("Calendar was unable to save\n" |
812 | "your changes.\n" | 817 | "your changes.\n" |
813 | "Free up some space and try again.\n" | 818 | "Free up some space and try again.\n" |
814 | "\nQuit anyway?"), | 819 | "\nQuit anyway?"), |
815 | QMessageBox::Yes|QMessageBox::Escape, | 820 | QMessageBox::Yes|QMessageBox::Escape, |
816 | QMessageBox::No|QMessageBox::Default ) | 821 | QMessageBox::No|QMessageBox::Default ) |
817 | != QMessageBox::No ) | 822 | != QMessageBox::No ) |
818 | e->accept(); | 823 | e->accept(); |
819 | else | 824 | else |
820 | e->ignore(); | 825 | e->ignore(); |
821 | } | 826 | } |
822 | } | 827 | } |
823 | 828 | ||