author | sandman <sandman> | 2002-12-22 19:02:29 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-22 19:02:29 (UTC) |
commit | c5de1fcc13b32e7c1f893dc3f8a1385b8698ebaf (patch) (unidiff) | |
tree | 3d9373bb500716cb8739e885fe5aa908e14283dc | |
parent | 3ae485ccb47ca618bc00d96a0e81c978a1cfbdaf (diff) | |
download | opie-c5de1fcc13b32e7c1f893dc3f8a1385b8698ebaf.zip opie-c5de1fcc13b32e7c1f893dc3f8a1385b8698ebaf.tar.gz opie-c5de1fcc13b32e7c1f893dc3f8a1385b8698ebaf.tar.bz2 |
correct implementation for QCop "nextView()":
- if we are not active, raise the window
- if we are active, switch to the next view
(this is needed for the new appskey framework)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index c0a744a..7dcf156 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,1026 +1,1031 @@ | |||
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 | aPreset = frmSettings.alarmPreset(); |
281 | presetTime = frmSettings.presetTime(); | 281 | presetTime = frmSettings.presetTime(); |
282 | startTime = frmSettings.startTime(); | 282 | startTime = frmSettings.startTime(); |
283 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 283 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
284 | rowStyle = frmSettings.rowStyle(); | 284 | rowStyle = frmSettings.rowStyle(); |
285 | if ( dayView ) | 285 | if ( dayView ) |
286 | dayView->setStartViewTime( startTime ); | 286 | dayView->setStartViewTime( startTime ); |
287 | dayView->setJumpToCurTime( bJumpToCurTime ); | 287 | dayView->setJumpToCurTime( bJumpToCurTime ); |
288 | dayView->setRowStyle( rowStyle ); | 288 | dayView->setRowStyle( rowStyle ); |
289 | if ( weekView ) | 289 | if ( weekView ) |
290 | weekView->setStartViewTime( startTime ); | 290 | weekView->setStartViewTime( startTime ); |
291 | saveSettings(); | 291 | saveSettings(); |
292 | 292 | ||
293 | // make the change obvious | 293 | // make the change obvious |
294 | if ( views->visibleWidget() ) { | 294 | if ( views->visibleWidget() ) { |
295 | if ( views->visibleWidget() == dayView ) | 295 | if ( views->visibleWidget() == dayView ) |
296 | dayView->redraw(); | 296 | dayView->redraw(); |
297 | else if ( views->visibleWidget() == weekView ) | 297 | else if ( views->visibleWidget() == weekView ) |
298 | weekView->redraw(); | 298 | weekView->redraw(); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | void DateBook::fileNew() | 303 | void DateBook::fileNew() |
304 | { | 304 | { |
305 | slotNewEventFromKey(""); | 305 | slotNewEventFromKey(""); |
306 | } | 306 | } |
307 | 307 | ||
308 | QString DateBook::checkEvent(const Event &e) | 308 | QString DateBook::checkEvent(const Event &e) |
309 | { | 309 | { |
310 | /* check if overlaps with itself */ | 310 | /* check if overlaps with itself */ |
311 | bool checkFailed = FALSE; | 311 | bool checkFailed = FALSE; |
312 | 312 | ||
313 | /* check the next 12 repeats. should catch most problems */ | 313 | /* check the next 12 repeats. should catch most problems */ |
314 | QDate current_date = e.start().date(); | 314 | QDate current_date = e.start().date(); |
315 | Event previous = e; | 315 | Event previous = e; |
316 | for(int i = 0; i < 12; i++) | 316 | for(int i = 0; i < 12; i++) |
317 | { | 317 | { |
318 | QDateTime next; | 318 | QDateTime next; |
319 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 319 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
320 | break; // no more repeats | 320 | break; // no more repeats |
321 | } | 321 | } |
322 | if(next < previous.end()) { | 322 | if(next < previous.end()) { |
323 | checkFailed = TRUE; | 323 | checkFailed = TRUE; |
324 | break; | 324 | break; |
325 | } | 325 | } |
326 | current_date = next.date(); | 326 | current_date = next.date(); |
327 | } | 327 | } |
328 | 328 | ||
329 | if(checkFailed) | 329 | if(checkFailed) |
330 | return tr("Event duration is potentially longer\n" | 330 | return tr("Event duration is potentially longer\n" |
331 | "than interval between repeats."); | 331 | "than interval between repeats."); |
332 | 332 | ||
333 | return QString::null; | 333 | return QString::null; |
334 | } | 334 | } |
335 | 335 | ||
336 | QDate DateBook::currentDate() | 336 | QDate DateBook::currentDate() |
337 | { | 337 | { |
338 | QDate d = QDate::currentDate(); | 338 | QDate d = QDate::currentDate(); |
339 | 339 | ||
340 | if ( dayView && views->visibleWidget() == dayView ) { | 340 | if ( dayView && views->visibleWidget() == dayView ) { |
341 | d = dayView->date(); | 341 | d = dayView->date(); |
342 | } else if ( weekView && views->visibleWidget() == weekView ) { | 342 | } else if ( weekView && views->visibleWidget() == weekView ) { |
343 | d = weekView->date(); | 343 | d = weekView->date(); |
344 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 344 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
345 | d = weekLstView->date(); | 345 | d = weekLstView->date(); |
346 | } else if ( monthView && views->visibleWidget() == monthView ) { | 346 | } else if ( monthView && views->visibleWidget() == monthView ) { |
347 | d = monthView->selectedDate(); | 347 | d = monthView->selectedDate(); |
348 | } | 348 | } |
349 | 349 | ||
350 | return d; | 350 | return d; |
351 | } | 351 | } |
352 | 352 | ||
353 | void DateBook::view(int v, const QDate &d) { | 353 | void DateBook::view(int v, const QDate &d) { |
354 | if (v==DAY) { | 354 | if (v==DAY) { |
355 | initDay(); | 355 | initDay(); |
356 | dayAction->setOn( TRUE ); | 356 | dayAction->setOn( TRUE ); |
357 | dayView->setDate( d ); | 357 | dayView->setDate( d ); |
358 | views->raiseWidget( dayView ); | 358 | views->raiseWidget( dayView ); |
359 | dayView->redraw(); | 359 | dayView->redraw(); |
360 | } else if (v==WEEK) { | 360 | } else if (v==WEEK) { |
361 | initWeek(); | 361 | initWeek(); |
362 | weekAction->setOn( TRUE ); | 362 | weekAction->setOn( TRUE ); |
363 | weekView->setDate( d ); | 363 | weekView->setDate( d ); |
364 | views->raiseWidget( weekView ); | 364 | views->raiseWidget( weekView ); |
365 | weekView->redraw(); | 365 | weekView->redraw(); |
366 | } else if (v==WEEKLST) { | 366 | } else if (v==WEEKLST) { |
367 | initWeekLst(); | 367 | initWeekLst(); |
368 | weekLstAction->setOn( TRUE ); | 368 | weekLstAction->setOn( TRUE ); |
369 | weekLstView->setDate(d); | 369 | weekLstView->setDate(d); |
370 | views->raiseWidget( weekLstView ); | 370 | views->raiseWidget( weekLstView ); |
371 | weekLstView->redraw(); | 371 | weekLstView->redraw(); |
372 | } else if (v==MONTH) { | 372 | } else if (v==MONTH) { |
373 | initMonth(); | 373 | initMonth(); |
374 | monthAction->setOn( TRUE ); | 374 | monthAction->setOn( TRUE ); |
375 | monthView->setDate( d.year(), d.month(), d.day() ); | 375 | monthView->setDate( d.year(), d.month(), d.day() ); |
376 | views->raiseWidget( monthView ); | 376 | views->raiseWidget( monthView ); |
377 | monthView->redraw(); | 377 | monthView->redraw(); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | void DateBook::viewDefault(const QDate &d) { | 381 | void DateBook::viewDefault(const QDate &d) { |
382 | Config config("DateBook"); | 382 | Config config("DateBook"); |
383 | config.setGroup("Main"); | 383 | config.setGroup("Main"); |
384 | int current=config.readNumEntry("defaultview", DAY); | 384 | int current=config.readNumEntry("defaultview", DAY); |
385 | 385 | ||
386 | view(current,d); | 386 | view(current,d); |
387 | } | 387 | } |
388 | 388 | ||
389 | void DateBook::viewDay() { | 389 | void DateBook::viewDay() { |
390 | view(DAY,currentDate()); | 390 | view(DAY,currentDate()); |
391 | } | 391 | } |
392 | 392 | ||
393 | void DateBook::viewWeek() { | 393 | void DateBook::viewWeek() { |
394 | view(WEEK,currentDate()); | 394 | view(WEEK,currentDate()); |
395 | } | 395 | } |
396 | 396 | ||
397 | void DateBook::viewWeekLst() { | 397 | void DateBook::viewWeekLst() { |
398 | view(WEEKLST,currentDate()); | 398 | view(WEEKLST,currentDate()); |
399 | } | 399 | } |
400 | 400 | ||
401 | void DateBook::viewMonth() { | 401 | void DateBook::viewMonth() { |
402 | view(MONTH,currentDate()); | 402 | view(MONTH,currentDate()); |
403 | } | 403 | } |
404 | 404 | ||
405 | void DateBook::editEvent( const Event &e ) | 405 | void DateBook::editEvent( const Event &e ) |
406 | { | 406 | { |
407 | if (syncing) { | 407 | if (syncing) { |
408 | QMessageBox::warning( this, tr("Calendar"), | 408 | QMessageBox::warning( this, tr("Calendar"), |
409 | tr( "Can not edit data, currently syncing") ); | 409 | tr( "Can not edit data, currently syncing") ); |
410 | return; | 410 | return; |
411 | } | 411 | } |
412 | 412 | ||
413 | // workaround added for text input. | 413 | // workaround added for text input. |
414 | QDialog editDlg( this, 0, TRUE ); | 414 | QDialog editDlg( this, 0, TRUE ); |
415 | DateEntry *entry; | 415 | DateEntry *entry; |
416 | editDlg.setCaption( tr("Edit Event") ); | 416 | editDlg.setCaption( tr("Edit Event") ); |
417 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 417 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
418 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 418 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
419 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 419 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
420 | // KLUDGE!!! | 420 | // KLUDGE!!! |
421 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 421 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
422 | vb->addWidget( sv ); | 422 | vb->addWidget( sv ); |
423 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 423 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
424 | entry->timezone->setEnabled( FALSE ); | 424 | entry->timezone->setEnabled( FALSE ); |
425 | sv->addChild( entry ); | 425 | sv->addChild( entry ); |
426 | 426 | ||
427 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 427 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
428 | editDlg.showMaximized(); | 428 | editDlg.showMaximized(); |
429 | #endif | 429 | #endif |
430 | while (editDlg.exec() ) { | 430 | while (editDlg.exec() ) { |
431 | Event newEv = entry->event(); | 431 | Event newEv = entry->event(); |
432 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) | 432 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) |
433 | break; | 433 | break; |
434 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 434 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
435 | QString error = checkEvent(newEv); | 435 | QString error = checkEvent(newEv); |
436 | if (!error.isNull()) { | 436 | if (!error.isNull()) { |
437 | if (QMessageBox::warning(this, "error box", | 437 | if (QMessageBox::warning(this, "error box", |
438 | error, "Fix it", "Continue", | 438 | error, "Fix it", "Continue", |
439 | 0, 0, 1) == 0) | 439 | 0, 0, 1) == 0) |
440 | continue; | 440 | continue; |
441 | } | 441 | } |
442 | db->editEvent(e, newEv); | 442 | db->editEvent(e, newEv); |
443 | emit newEvent(); | 443 | emit newEvent(); |
444 | break; | 444 | break; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | void DateBook::removeEvent( const Event &e ) | 448 | void DateBook::removeEvent( const Event &e ) |
449 | { | 449 | { |
450 | if (syncing) { | 450 | if (syncing) { |
451 | QMessageBox::warning( this, tr("Calendar"), | 451 | QMessageBox::warning( this, tr("Calendar"), |
452 | tr( "Can not edit data, currently syncing") ); | 452 | tr( "Can not edit data, currently syncing") ); |
453 | return; | 453 | return; |
454 | } | 454 | } |
455 | 455 | ||
456 | QString strName = e.description(); | 456 | QString strName = e.description(); |
457 | 457 | ||
458 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 458 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
459 | return; | 459 | return; |
460 | 460 | ||
461 | db->removeEvent( e ); | 461 | db->removeEvent( e ); |
462 | if ( views->visibleWidget() == dayView && dayView ) | 462 | if ( views->visibleWidget() == dayView && dayView ) |
463 | dayView->redraw(); | 463 | dayView->redraw(); |
464 | } | 464 | } |
465 | 465 | ||
466 | void DateBook::addEvent( const Event &e ) | 466 | void DateBook::addEvent( const Event &e ) |
467 | { | 467 | { |
468 | QDate d = e.start().date(); | 468 | QDate d = e.start().date(); |
469 | initDay(); | 469 | initDay(); |
470 | dayView->setDate( d ); | 470 | dayView->setDate( d ); |
471 | } | 471 | } |
472 | 472 | ||
473 | void DateBook::showDay( int year, int month, int day ) | 473 | void DateBook::showDay( int year, int month, int day ) |
474 | { | 474 | { |
475 | QDate d(year, month, day); | 475 | QDate d(year, month, day); |
476 | view(DAY,d); | 476 | view(DAY,d); |
477 | } | 477 | } |
478 | 478 | ||
479 | void DateBook::initDay() | 479 | void DateBook::initDay() |
480 | { | 480 | { |
481 | if ( !dayView ) { | 481 | if ( !dayView ) { |
482 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 482 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
483 | views->addWidget( dayView, DAY ); | 483 | views->addWidget( dayView, DAY ); |
484 | dayView->setStartViewTime( startTime ); | 484 | dayView->setStartViewTime( startTime ); |
485 | dayView->setJumpToCurTime( bJumpToCurTime ); | 485 | dayView->setJumpToCurTime( bJumpToCurTime ); |
486 | dayView->setRowStyle( rowStyle ); | 486 | dayView->setRowStyle( rowStyle ); |
487 | connect( this, SIGNAL( newEvent() ), | 487 | connect( this, SIGNAL( newEvent() ), |
488 | dayView, SLOT( redraw() ) ); | 488 | dayView, SLOT( redraw() ) ); |
489 | connect( dayView, SIGNAL( newEvent() ), | 489 | connect( dayView, SIGNAL( newEvent() ), |
490 | this, SLOT( fileNew() ) ); | 490 | this, SLOT( fileNew() ) ); |
491 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), | 491 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), |
492 | this, SLOT( removeEvent( const Event & ) ) ); | 492 | this, SLOT( removeEvent( const Event & ) ) ); |
493 | connect( dayView, SIGNAL( editEvent( const Event & ) ), | 493 | connect( dayView, SIGNAL( editEvent( const Event & ) ), |
494 | this, SLOT( editEvent( const Event & ) ) ); | 494 | this, SLOT( editEvent( const Event & ) ) ); |
495 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), | 495 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), |
496 | this, SLOT( beamEvent( const Event & ) ) ); | 496 | this, SLOT( beamEvent( const Event & ) ) ); |
497 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), | 497 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), |
498 | this, SLOT(slotNewEventFromKey(const QString &)) ); | 498 | this, SLOT(slotNewEventFromKey(const QString &)) ); |
499 | } | 499 | } |
500 | } | 500 | } |
501 | 501 | ||
502 | void DateBook::initWeek() | 502 | void DateBook::initWeek() |
503 | { | 503 | { |
504 | if ( !weekView ) { | 504 | if ( !weekView ) { |
505 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 505 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
506 | weekView->setStartViewTime( startTime ); | 506 | weekView->setStartViewTime( startTime ); |
507 | views->addWidget( weekView, WEEK ); | 507 | views->addWidget( weekView, WEEK ); |
508 | connect( weekView, SIGNAL( showDate( int, int, int ) ), | 508 | connect( weekView, SIGNAL( showDate( int, int, int ) ), |
509 | this, SLOT( showDay( int, int, int ) ) ); | 509 | this, SLOT( showDay( int, int, int ) ) ); |
510 | connect( this, SIGNAL( newEvent() ), | 510 | connect( this, SIGNAL( newEvent() ), |
511 | weekView, SLOT( redraw() ) ); | 511 | weekView, SLOT( redraw() ) ); |
512 | } | 512 | } |
513 | //But also get it right: the year that we display can be different | 513 | //But also get it right: the year that we display can be different |
514 | //from the year of the current date. So, first find the year | 514 | //from the year of the current date. So, first find the year |
515 | //number of the current week. | 515 | //number of the current week. |
516 | 516 | ||
517 | int yearNumber, totWeeks; | 517 | int yearNumber, totWeeks; |
518 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | 518 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); |
519 | 519 | ||
520 | QDate d = QDate( yearNumber, 12, 31 ); | 520 | QDate d = QDate( yearNumber, 12, 31 ); |
521 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 521 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
522 | 522 | ||
523 | while ( totWeeks == 1 ) { | 523 | while ( totWeeks == 1 ) { |
524 | d = d.addDays( -1 ); | 524 | d = d.addDays( -1 ); |
525 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 525 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
526 | } | 526 | } |
527 | if ( totWeeks != weekView->totalWeeks() ) | 527 | if ( totWeeks != weekView->totalWeeks() ) |
528 | weekView->setTotalWeeks( totWeeks ); | 528 | weekView->setTotalWeeks( totWeeks ); |
529 | } | 529 | } |
530 | void DateBook::initWeekLst() { | 530 | void DateBook::initWeekLst() { |
531 | if ( !weekLstView ) { | 531 | if ( !weekLstView ) { |
532 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, | 532 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, |
533 | views, "weeklst view" ); | 533 | views, "weeklst view" ); |
534 | views->addWidget( weekLstView, WEEKLST ); | 534 | views->addWidget( weekLstView, WEEKLST ); |
535 | 535 | ||
536 | //weekLstView->setStartViewTime( startTime ); | 536 | //weekLstView->setStartViewTime( startTime ); |
537 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), | 537 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), |
538 | this, SLOT( showDay( int, int, int ) ) ); | 538 | this, SLOT( showDay( int, int, int ) ) ); |
539 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, | 539 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, |
540 | const QDateTime &, | 540 | const QDateTime &, |
541 | const QString & ) ), | 541 | const QString & ) ), |
542 | this, SLOT( slotNewEntry( const QDateTime &, | 542 | this, SLOT( slotNewEntry( const QDateTime &, |
543 | const QDateTime &, | 543 | const QDateTime &, |
544 | const QString & ) ) ); | 544 | const QString & ) ) ); |
545 | connect( this, SIGNAL( newEvent() ), | 545 | connect( this, SIGNAL( newEvent() ), |
546 | weekLstView, SLOT( redraw() ) ); | 546 | weekLstView, SLOT( redraw() ) ); |
547 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), | 547 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), |
548 | this, SLOT( editEvent( const Event & ) ) ); | 548 | this, SLOT( editEvent( const Event & ) ) ); |
549 | } | 549 | } |
550 | } | 550 | } |
551 | 551 | ||
552 | 552 | ||
553 | void DateBook::initMonth() | 553 | void DateBook::initMonth() |
554 | { | 554 | { |
555 | if ( !monthView ) { | 555 | if ( !monthView ) { |
556 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 556 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
557 | views->addWidget( monthView, MONTH ); | 557 | views->addWidget( monthView, MONTH ); |
558 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), | 558 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), |
559 | this, SLOT( showDay( int, int, int ) ) ); | 559 | this, SLOT( showDay( int, int, int ) ) ); |
560 | connect( this, SIGNAL( newEvent() ), | 560 | connect( this, SIGNAL( newEvent() ), |
561 | monthView, SLOT( redraw() ) ); | 561 | monthView, SLOT( redraw() ) ); |
562 | qApp->processEvents(); | 562 | qApp->processEvents(); |
563 | } | 563 | } |
564 | } | 564 | } |
565 | 565 | ||
566 | void DateBook::loadSettings() | 566 | void DateBook::loadSettings() |
567 | { | 567 | { |
568 | { | 568 | { |
569 | Config config( "qpe" ); | 569 | Config config( "qpe" ); |
570 | config.setGroup("Time"); | 570 | config.setGroup("Time"); |
571 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 571 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
572 | onMonday = config.readBoolEntry( "MONDAY" ); | 572 | onMonday = config.readBoolEntry( "MONDAY" ); |
573 | } | 573 | } |
574 | 574 | ||
575 | { | 575 | { |
576 | Config config("DateBook"); | 576 | Config config("DateBook"); |
577 | config.setGroup("Main"); | 577 | config.setGroup("Main"); |
578 | startTime = config.readNumEntry("startviewtime", 8); | 578 | startTime = config.readNumEntry("startviewtime", 8); |
579 | aPreset = config.readBoolEntry("alarmpreset"); | 579 | aPreset = config.readBoolEntry("alarmpreset"); |
580 | presetTime = config.readNumEntry("presettime"); | 580 | presetTime = config.readNumEntry("presettime"); |
581 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); | 581 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); |
582 | rowStyle = config.readNumEntry("rowstyle"); | 582 | rowStyle = config.readNumEntry("rowstyle"); |
583 | } | 583 | } |
584 | } | 584 | } |
585 | 585 | ||
586 | void DateBook::saveSettings() | 586 | void DateBook::saveSettings() |
587 | { | 587 | { |
588 | Config config( "qpe" ); | 588 | Config config( "qpe" ); |
589 | Config configDB( "DateBook" ); | 589 | Config configDB( "DateBook" ); |
590 | configDB.setGroup( "Main" ); | 590 | configDB.setGroup( "Main" ); |
591 | configDB.writeEntry("startviewtime",startTime); | 591 | configDB.writeEntry("startviewtime",startTime); |
592 | configDB.writeEntry("alarmpreset",aPreset); | 592 | configDB.writeEntry("alarmpreset",aPreset); |
593 | configDB.writeEntry("presettime",presetTime); | 593 | configDB.writeEntry("presettime",presetTime); |
594 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); | 594 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); |
595 | configDB.writeEntry("rowstyle", rowStyle); | 595 | configDB.writeEntry("rowstyle", rowStyle); |
596 | } | 596 | } |
597 | 597 | ||
598 | void DateBook::newDefaultView(QAction *a) { | 598 | void DateBook::newDefaultView(QAction *a) { |
599 | int val=DAY; | 599 | int val=DAY; |
600 | if (a->text() == "Day") val=DAY; | 600 | if (a->text() == "Day") val=DAY; |
601 | if (a->text() == "Week") val=WEEK; | 601 | if (a->text() == "Week") val=WEEK; |
602 | if (a->text() == "WeekLst") val=WEEKLST; | 602 | if (a->text() == "WeekLst") val=WEEKLST; |
603 | if (a->text() == "Month") val=MONTH; | 603 | if (a->text() == "Month") val=MONTH; |
604 | 604 | ||
605 | Config configDB( "DateBook" ); | 605 | Config configDB( "DateBook" ); |
606 | configDB.setGroup( "Main" ); | 606 | configDB.setGroup( "Main" ); |
607 | configDB.writeEntry("defaultview",val); | 607 | configDB.writeEntry("defaultview",val); |
608 | } | 608 | } |
609 | 609 | ||
610 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 610 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
611 | { | 611 | { |
612 | bool needShow = FALSE; | 612 | bool needShow = FALSE; |
613 | if ( msg == "alarm(QDateTime,int)" ) { | 613 | if ( msg == "alarm(QDateTime,int)" ) { |
614 | QDataStream ds(data,IO_ReadOnly); | 614 | QDataStream ds(data,IO_ReadOnly); |
615 | QDateTime when; int warn; | 615 | QDateTime when; int warn; |
616 | ds >> when >> warn; | 616 | ds >> when >> warn; |
617 | 617 | ||
618 | // check to make it's okay to continue, | 618 | // check to make it's okay to continue, |
619 | // this is the case that the time was set ahead, and | 619 | // this is the case that the time was set ahead, and |
620 | // we are forced given a stale alarm... | 620 | // we are forced given a stale alarm... |
621 | QDateTime current = QDateTime::currentDateTime(); | 621 | QDateTime current = QDateTime::currentDateTime(); |
622 | if ( current.time().hour() != when.time().hour() | 622 | if ( current.time().hour() != when.time().hour() |
623 | && current.time().minute() != when.time().minute() ) | 623 | && current.time().minute() != when.time().minute() ) |
624 | return; | 624 | return; |
625 | 625 | ||
626 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 626 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
627 | if ( list.count() > 0 ) { | 627 | if ( list.count() > 0 ) { |
628 | QString msg; | 628 | QString msg; |
629 | bool bSound = FALSE; | 629 | bool bSound = FALSE; |
630 | int stopTimer = 0; | 630 | int stopTimer = 0; |
631 | bool found = FALSE; | 631 | bool found = FALSE; |
632 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 632 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
633 | it!=list.end(); ++it ) { | 633 | it!=list.end(); ++it ) { |
634 | if ( (*it).event().hasAlarm() ) { | 634 | if ( (*it).event().hasAlarm() ) { |
635 | found = TRUE; | 635 | found = TRUE; |
636 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 636 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
637 | + "<BR>" + (*it).location() + "<BR>" | 637 | + "<BR>" + (*it).location() + "<BR>" |
638 | + TimeString::dateString((*it).event().start(),ampm) | 638 | + TimeString::dateString((*it).event().start(),ampm) |
639 | + (warn | 639 | + (warn |
640 | ? tr(" (in " + QString::number(warn) | 640 | ? tr(" (in " + QString::number(warn) |
641 | + tr(" minutes)")) | 641 | + tr(" minutes)")) |
642 | : QString("")) | 642 | : QString("")) |
643 | + "<BR>" | 643 | + "<BR>" |
644 | + (*it).notes() + "</CENTER>"; | 644 | + (*it).notes() + "</CENTER>"; |
645 | if ( (*it).event().alarmSound() != Event::Silent ) { | 645 | if ( (*it).event().alarmSound() != Event::Silent ) { |
646 | bSound = TRUE; | 646 | bSound = TRUE; |
647 | } | 647 | } |
648 | } | 648 | } |
649 | } | 649 | } |
650 | if ( found ) { | 650 | if ( found ) { |
651 | if ( bSound ) { | 651 | if ( bSound ) { |
652 | Sound::soundAlarm(); | 652 | Sound::soundAlarm(); |
653 | alarmCounter = 0; | 653 | alarmCounter = 0; |
654 | stopTimer = startTimer( 5000 ); | 654 | stopTimer = startTimer( 5000 ); |
655 | } | 655 | } |
656 | 656 | ||
657 | QDialog dlg( this, 0, TRUE ); | 657 | QDialog dlg( this, 0, TRUE ); |
658 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 658 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
659 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 659 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
660 | view->setResizePolicy( QScrollView::AutoOneFit ); | 660 | view->setResizePolicy( QScrollView::AutoOneFit ); |
661 | vb->addWidget( view ); | 661 | vb->addWidget( view ); |
662 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 662 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
663 | view->addChild( lblMsg ); | 663 | view->addChild( lblMsg ); |
664 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 664 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
665 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 665 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
666 | vb->addWidget( cmdOk ); | 666 | vb->addWidget( cmdOk ); |
667 | 667 | ||
668 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 668 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
669 | dlg.showMaximized(); | 669 | dlg.showMaximized(); |
670 | #endif | 670 | #endif |
671 | needShow = dlg.exec(); | 671 | needShow = dlg.exec(); |
672 | 672 | ||
673 | if ( bSound ) | 673 | if ( bSound ) |
674 | killTimer( stopTimer ); | 674 | killTimer( stopTimer ); |
675 | } | 675 | } |
676 | } | 676 | } |
677 | } else if ( msg == "nextView()" ) { | 677 | } else if ( msg == "nextView()" ) { |
678 | QWidget* cur = views->visibleWidget(); | 678 | if ( !qApp-> activeWindow ( )) { |
679 | if ( cur ) { | ||
680 | if ( cur == dayView ) | ||
681 | viewWeek(); | ||
682 | else if ( cur == weekView ) | ||
683 | viewWeekLst(); | ||
684 | else if ( cur == weekLstView ) | ||
685 | viewMonth(); | ||
686 | else if ( cur == monthView ) | ||
687 | viewDay(); | ||
688 | needShow = TRUE; | 679 | needShow = TRUE; |
689 | } | 680 | } |
681 | else { | ||
682 | QWidget* cur = views->visibleWidget(); | ||
683 | if ( cur ) { | ||
684 | if ( cur == dayView ) | ||
685 | viewWeek(); | ||
686 | else if ( cur == weekView ) | ||
687 | viewWeekLst(); | ||
688 | else if ( cur == weekLstView ) | ||
689 | viewMonth(); | ||
690 | else if ( cur == monthView ) | ||
691 | viewDay(); | ||
692 | needShow = TRUE; | ||
693 | } | ||
694 | } | ||
690 | } | 695 | } |
691 | if ( needShow ) { | 696 | if ( needShow ) { |
692 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 697 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
693 | showMaximized(); | 698 | showMaximized(); |
694 | #else | 699 | #else |
695 | show(); | 700 | show(); |
696 | #endif | 701 | #endif |
697 | raise(); | 702 | raise(); |
698 | QPEApplication::setKeepRunning(); | 703 | QPEApplication::setKeepRunning(); |
699 | setActiveWindow(); | 704 | setActiveWindow(); |
700 | } | 705 | } |
701 | } | 706 | } |
702 | 707 | ||
703 | void DateBook::reload() | 708 | void DateBook::reload() |
704 | { | 709 | { |
705 | db->reload(); | 710 | db->reload(); |
706 | if ( dayAction->isOn() ) | 711 | if ( dayAction->isOn() ) |
707 | viewDay(); | 712 | viewDay(); |
708 | else if ( weekAction->isOn() ) | 713 | else if ( weekAction->isOn() ) |
709 | viewWeek(); | 714 | viewWeek(); |
710 | else if ( monthAction->isOn() ) | 715 | else if ( monthAction->isOn() ) |
711 | viewMonth(); | 716 | viewMonth(); |
712 | syncing = FALSE; | 717 | syncing = FALSE; |
713 | } | 718 | } |
714 | 719 | ||
715 | void DateBook::flush() | 720 | void DateBook::flush() |
716 | { | 721 | { |
717 | syncing = TRUE; | 722 | syncing = TRUE; |
718 | db->save(); | 723 | db->save(); |
719 | } | 724 | } |
720 | 725 | ||
721 | void DateBook::timerEvent( QTimerEvent *e ) | 726 | void DateBook::timerEvent( QTimerEvent *e ) |
722 | { | 727 | { |
723 | if ( alarmCounter < 10 ) { | 728 | if ( alarmCounter < 10 ) { |
724 | alarmCounter++; | 729 | alarmCounter++; |
725 | Sound::soundAlarm(); | 730 | Sound::soundAlarm(); |
726 | } | 731 | } |
727 | else | 732 | else |
728 | killTimer( e->timerId() ); | 733 | killTimer( e->timerId() ); |
729 | } | 734 | } |
730 | 735 | ||
731 | void DateBook::changeClock( bool newClock ) | 736 | void DateBook::changeClock( bool newClock ) |
732 | { | 737 | { |
733 | ampm = newClock; | 738 | ampm = newClock; |
734 | // repaint the affected objects... | 739 | // repaint the affected objects... |
735 | if (dayView) dayView->redraw(); | 740 | if (dayView) dayView->redraw(); |
736 | if (weekView) weekView->redraw(); | 741 | if (weekView) weekView->redraw(); |
737 | if (weekLstView) weekLstView->redraw(); | 742 | if (weekLstView) weekLstView->redraw(); |
738 | } | 743 | } |
739 | 744 | ||
740 | void DateBook::changeWeek( bool m ) | 745 | void DateBook::changeWeek( bool m ) |
741 | { | 746 | { |
742 | /* no need to redraw, each widget catches. Do need to | 747 | /* no need to redraw, each widget catches. Do need to |
743 | store though for widgets we haven't made yet */ | 748 | store though for widgets we haven't made yet */ |
744 | onMonday = m; | 749 | onMonday = m; |
745 | } | 750 | } |
746 | 751 | ||
747 | void DateBook::slotToday() | 752 | void DateBook::slotToday() |
748 | { | 753 | { |
749 | // we need to view today using default view | 754 | // we need to view today using default view |
750 | viewDefault(QDate::currentDate()); | 755 | viewDefault(QDate::currentDate()); |
751 | } | 756 | } |
752 | 757 | ||
753 | void DateBook::closeEvent( QCloseEvent *e ) | 758 | void DateBook::closeEvent( QCloseEvent *e ) |
754 | { | 759 | { |
755 | if(syncing) { | 760 | if(syncing) { |
756 | /* no need to save, did that at flush */ | 761 | /* no need to save, did that at flush */ |
757 | e->accept(); | 762 | e->accept(); |
758 | return; | 763 | return; |
759 | } | 764 | } |
760 | 765 | ||
761 | // save settings will generate it's own error messages, no | 766 | // save settings will generate it's own error messages, no |
762 | // need to do checking ourselves. | 767 | // need to do checking ourselves. |
763 | saveSettings(); | 768 | saveSettings(); |
764 | if ( db->save() ) | 769 | if ( db->save() ) |
765 | e->accept(); | 770 | e->accept(); |
766 | else { | 771 | else { |
767 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 772 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
768 | tr("Calendar was unable to save\n" | 773 | tr("Calendar was unable to save\n" |
769 | "your changes.\n" | 774 | "your changes.\n" |
770 | "Free up some space and try again.\n" | 775 | "Free up some space and try again.\n" |
771 | "\nQuit anyway?"), | 776 | "\nQuit anyway?"), |
772 | QMessageBox::Yes|QMessageBox::Escape, | 777 | QMessageBox::Yes|QMessageBox::Escape, |
773 | QMessageBox::No|QMessageBox::Default ) | 778 | QMessageBox::No|QMessageBox::Default ) |
774 | != QMessageBox::No ) | 779 | != QMessageBox::No ) |
775 | e->accept(); | 780 | e->accept(); |
776 | else | 781 | else |
777 | e->ignore(); | 782 | e->ignore(); |
778 | } | 783 | } |
779 | } | 784 | } |
780 | 785 | ||
781 | // Entering directly from the "keyboard" | 786 | // Entering directly from the "keyboard" |
782 | void DateBook::slotNewEventFromKey( const QString &str ) | 787 | void DateBook::slotNewEventFromKey( const QString &str ) |
783 | { | 788 | { |
784 | if (syncing) { | 789 | if (syncing) { |
785 | QMessageBox::warning( this, tr("Calendar"), | 790 | QMessageBox::warning( this, tr("Calendar"), |
786 | tr( "Can not edit data, currently syncing") ); | 791 | tr( "Can not edit data, currently syncing") ); |
787 | return; | 792 | return; |
788 | } | 793 | } |
789 | 794 | ||
790 | // We get to here from a key pressed in the Day View | 795 | // We get to here from a key pressed in the Day View |
791 | // So we can assume some things. We want the string | 796 | // So we can assume some things. We want the string |
792 | // passed in to be part of the description. | 797 | // passed in to be part of the description. |
793 | QDateTime start, end; | 798 | QDateTime start, end; |
794 | if ( views->visibleWidget() == dayView ) { | 799 | if ( views->visibleWidget() == dayView ) { |
795 | dayView->selectedDates( start, end ); | 800 | dayView->selectedDates( start, end ); |
796 | } else if ( views->visibleWidget() == monthView ) { | 801 | } else if ( views->visibleWidget() == monthView ) { |
797 | QDate d = monthView->selectedDate(); | 802 | QDate d = monthView->selectedDate(); |
798 | start = end = d; | 803 | start = end = d; |
799 | start.setTime( QTime( 10, 0 ) ); | 804 | start.setTime( QTime( 10, 0 ) ); |
800 | end.setTime( QTime( 12, 0 ) ); | 805 | end.setTime( QTime( 12, 0 ) ); |
801 | } else if ( views->visibleWidget() == weekView ) { | 806 | } else if ( views->visibleWidget() == weekView ) { |
802 | QDate d = weekView->date(); | 807 | QDate d = weekView->date(); |
803 | start = end = d; | 808 | start = end = d; |
804 | start.setTime( QTime( 10, 0 ) ); | 809 | start.setTime( QTime( 10, 0 ) ); |
805 | end.setTime( QTime( 12, 0 ) ); | 810 | end.setTime( QTime( 12, 0 ) ); |
806 | } | 811 | } |
807 | slotNewEntry(start, end, str); | 812 | slotNewEntry(start, end, str); |
808 | } | 813 | } |
809 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { | 814 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { |
810 | // argh! This really needs to be encapsulated in a class | 815 | // argh! This really needs to be encapsulated in a class |
811 | // or function. | 816 | // or function. |
812 | QDialog newDlg( this, 0, TRUE ); | 817 | QDialog newDlg( this, 0, TRUE ); |
813 | newDlg.setCaption( DateEntryBase::tr("New Event") ); | 818 | newDlg.setCaption( DateEntryBase::tr("New Event") ); |
814 | DateEntry *e; | 819 | DateEntry *e; |
815 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); | 820 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); |
816 | QScrollView *sv = new QScrollView( &newDlg ); | 821 | QScrollView *sv = new QScrollView( &newDlg ); |
817 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 822 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
818 | sv->setFrameStyle( QFrame::NoFrame ); | 823 | sv->setFrameStyle( QFrame::NoFrame ); |
819 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 824 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
820 | vb->addWidget( sv ); | 825 | vb->addWidget( sv ); |
821 | 826 | ||
822 | Event ev; | 827 | Event ev; |
823 | ev.setDescription( str ); | 828 | ev.setDescription( str ); |
824 | // When the new gui comes in, change this... | 829 | // When the new gui comes in, change this... |
825 | ev.setLocation( tr("(Unknown)") ); | 830 | ev.setLocation( tr("(Unknown)") ); |
826 | ev.setStart( start ); | 831 | ev.setStart( start ); |
827 | ev.setEnd( end ); | 832 | ev.setEnd( end ); |
828 | 833 | ||
829 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); | 834 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); |
830 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); | 835 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); |
831 | sv->addChild( e ); | 836 | sv->addChild( e ); |
832 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 837 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
833 | newDlg.showMaximized(); | 838 | newDlg.showMaximized(); |
834 | #endif | 839 | #endif |
835 | while (newDlg.exec()) { | 840 | while (newDlg.exec()) { |
836 | ev = e->event(); | 841 | ev = e->event(); |
837 | ev.assignUid(); | 842 | ev.assignUid(); |
838 | QString error = checkEvent( ev ); | 843 | QString error = checkEvent( ev ); |
839 | if ( !error.isNull() ) { | 844 | if ( !error.isNull() ) { |
840 | if ( QMessageBox::warning( this, tr("Error!"), | 845 | if ( QMessageBox::warning( this, tr("Error!"), |
841 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) | 846 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) |
842 | continue; | 847 | continue; |
843 | } | 848 | } |
844 | db->addEvent( ev ); | 849 | db->addEvent( ev ); |
845 | emit newEvent(); | 850 | emit newEvent(); |
846 | break; | 851 | break; |
847 | } | 852 | } |
848 | } | 853 | } |
849 | 854 | ||
850 | void DateBook::setDocument( const QString &filename ) | 855 | void DateBook::setDocument( const QString &filename ) |
851 | { | 856 | { |
852 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 857 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
853 | 858 | ||
854 | QValueList<Event> tl = Event::readVCalendar( filename ); | 859 | QValueList<Event> tl = Event::readVCalendar( filename ); |
855 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 860 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
856 | db->addEvent( *it ); | 861 | db->addEvent( *it ); |
857 | } | 862 | } |
858 | } | 863 | } |
859 | 864 | ||
860 | static const char * beamfile = "/tmp/obex/event.vcs"; | 865 | static const char * beamfile = "/tmp/obex/event.vcs"; |
861 | 866 | ||
862 | void DateBook::beamEvent( const Event &e ) | 867 | void DateBook::beamEvent( const Event &e ) |
863 | { | 868 | { |
864 | qDebug("trying to beamn"); | 869 | qDebug("trying to beamn"); |
865 | unlink( beamfile ); // delete if exists | 870 | unlink( beamfile ); // delete if exists |
866 | mkdir("/tmp/obex/", 0755); | 871 | mkdir("/tmp/obex/", 0755); |
867 | Event::writeVCalendar( beamfile, e ); | 872 | Event::writeVCalendar( beamfile, e ); |
868 | Ir *ir = new Ir( this ); | 873 | Ir *ir = new Ir( this ); |
869 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 874 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
870 | QString description = e.description(); | 875 | QString description = e.description(); |
871 | ir->send( beamfile, description, "text/x-vCalendar" ); | 876 | ir->send( beamfile, description, "text/x-vCalendar" ); |
872 | } | 877 | } |
873 | 878 | ||
874 | void DateBook::beamDone( Ir *ir ) | 879 | void DateBook::beamDone( Ir *ir ) |
875 | { | 880 | { |
876 | delete ir; | 881 | delete ir; |
877 | unlink( beamfile ); | 882 | unlink( beamfile ); |
878 | } | 883 | } |
879 | 884 | ||
880 | void DateBook::slotFind() | 885 | void DateBook::slotFind() |
881 | { | 886 | { |
882 | // move it to the day view... | 887 | // move it to the day view... |
883 | viewDay(); | 888 | viewDay(); |
884 | FindDialog frmFind( "Calendar", this ); | 889 | FindDialog frmFind( "Calendar", this ); |
885 | frmFind.setUseDate( true ); | 890 | frmFind.setUseDate( true ); |
886 | frmFind.setDate( currentDate() ); | 891 | frmFind.setDate( currentDate() ); |
887 | QObject::connect( &frmFind, | 892 | QObject::connect( &frmFind, |
888 | SIGNAL(signalFindClicked(const QString&, const QDate&, | 893 | SIGNAL(signalFindClicked(const QString&, const QDate&, |
889 | bool, bool, int)), | 894 | bool, bool, int)), |
890 | this, | 895 | this, |
891 | SLOT(slotDoFind(const QString&, const QDate&, | 896 | SLOT(slotDoFind(const QString&, const QDate&, |
892 | bool, bool, int)) ); | 897 | bool, bool, int)) ); |
893 | QObject::connect( this, | 898 | QObject::connect( this, |
894 | SIGNAL(signalNotFound()), | 899 | SIGNAL(signalNotFound()), |
895 | &frmFind, | 900 | &frmFind, |
896 | SLOT(slotNotFound()) ); | 901 | SLOT(slotNotFound()) ); |
897 | QObject::connect( this, | 902 | QObject::connect( this, |
898 | SIGNAL(signalWrapAround()), | 903 | SIGNAL(signalWrapAround()), |
899 | &frmFind, | 904 | &frmFind, |
900 | SLOT(slotWrapAround()) ); | 905 | SLOT(slotWrapAround()) ); |
901 | frmFind.exec(); | 906 | frmFind.exec(); |
902 | inSearch = false; | 907 | inSearch = false; |
903 | } | 908 | } |
904 | 909 | ||
905 | bool catComp( QArray<int> cats, int category ) | 910 | bool catComp( QArray<int> cats, int category ) |
906 | { | 911 | { |
907 | bool returnMe; | 912 | bool returnMe; |
908 | int i, | 913 | int i, |
909 | count; | 914 | count; |
910 | 915 | ||
911 | count = int(cats.count()); | 916 | count = int(cats.count()); |
912 | returnMe = false; | 917 | returnMe = false; |
913 | if ( (category == -1 && count == 0) || category == -2 ) | 918 | if ( (category == -1 && count == 0) || category == -2 ) |
914 | returnMe = true; | 919 | returnMe = true; |
915 | else { | 920 | else { |
916 | for ( i = 0; i < count; i++ ) { | 921 | for ( i = 0; i < count; i++ ) { |
917 | if ( category == cats[i] ) { | 922 | if ( category == cats[i] ) { |
918 | returnMe = true; | 923 | returnMe = true; |
919 | break; | 924 | break; |
920 | } | 925 | } |
921 | } | 926 | } |
922 | } | 927 | } |
923 | return returnMe; | 928 | return returnMe; |
924 | } | 929 | } |
925 | 930 | ||
926 | 931 | ||
927 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, | 932 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, |
928 | bool caseSensitive, bool /*backwards*/, | 933 | bool caseSensitive, bool /*backwards*/, |
929 | int category ) | 934 | int category ) |
930 | { | 935 | { |
931 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), | 936 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), |
932 | next; | 937 | next; |
933 | 938 | ||
934 | QRegExp r( txt ); | 939 | QRegExp r( txt ); |
935 | r.setCaseSensitive( caseSensitive ); | 940 | r.setCaseSensitive( caseSensitive ); |
936 | 941 | ||
937 | 942 | ||
938 | static Event rev, | 943 | static Event rev, |
939 | nonrev; | 944 | nonrev; |
940 | if ( !inSearch ) { | 945 | if ( !inSearch ) { |
941 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 946 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
942 | nonrev.setStart( rev.start() ); | 947 | nonrev.setStart( rev.start() ); |
943 | inSearch = true; | 948 | inSearch = true; |
944 | } | 949 | } |
945 | static QDate searchDate = dt; | 950 | static QDate searchDate = dt; |
946 | static bool wrapAround = true; | 951 | static bool wrapAround = true; |
947 | bool candidtate; | 952 | bool candidtate; |
948 | candidtate = false; | 953 | candidtate = false; |
949 | 954 | ||
950 | QValueList<Event> repeats = db->getRawRepeats(); | 955 | QValueList<Event> repeats = db->getRawRepeats(); |
951 | 956 | ||
952 | // find the candidate for the first repeat that matches... | 957 | // find the candidate for the first repeat that matches... |
953 | QValueListConstIterator<Event> it; | 958 | QValueListConstIterator<Event> it; |
954 | QDate start = dt; | 959 | QDate start = dt; |
955 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { | 960 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { |
956 | if ( catComp( (*it).categories(), category ) ) { | 961 | if ( catComp( (*it).categories(), category ) ) { |
957 | while ( nextOccurance( *it, start, next ) ) { | 962 | while ( nextOccurance( *it, start, next ) ) { |
958 | if ( next < dtEnd ) { | 963 | if ( next < dtEnd ) { |
959 | if ( (*it).match( r ) && !(next <= rev.start()) ) { | 964 | if ( (*it).match( r ) && !(next <= rev.start()) ) { |
960 | rev = *it; | 965 | rev = *it; |
961 | dtEnd = next; | 966 | dtEnd = next; |
962 | rev.setStart( next ); | 967 | rev.setStart( next ); |
963 | candidtate = true; | 968 | candidtate = true; |
964 | wrapAround = true; | 969 | wrapAround = true; |
965 | start = dt; | 970 | start = dt; |
966 | break; | 971 | break; |
967 | } else | 972 | } else |
968 | start = next.date().addDays( 1 ); | 973 | start = next.date().addDays( 1 ); |
969 | } | 974 | } |
970 | } | 975 | } |
971 | } | 976 | } |
972 | } | 977 | } |
973 | 978 | ||
974 | // now the for first non repeat... | 979 | // now the for first non repeat... |
975 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); | 980 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); |
976 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); | 981 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); |
977 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { | 982 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { |
978 | if ( catComp( (*it).categories(), category ) ) { | 983 | if ( catComp( (*it).categories(), category ) ) { |
979 | if ( (*it).start() < dtEnd ) { | 984 | if ( (*it).start() < dtEnd ) { |
980 | if ( (*it).match( r ) && !(*it <= nonrev) ) { | 985 | if ( (*it).match( r ) && !(*it <= nonrev) ) { |
981 | nonrev = *it; | 986 | nonrev = *it; |
982 | dtEnd = nonrev.start(); | 987 | dtEnd = nonrev.start(); |
983 | candidtate = true; | 988 | candidtate = true; |
984 | wrapAround = true; | 989 | wrapAround = true; |
985 | break; | 990 | break; |
986 | } | 991 | } |
987 | } | 992 | } |
988 | } | 993 | } |
989 | } | 994 | } |
990 | if ( candidtate ) { | 995 | if ( candidtate ) { |
991 | dayView->setStartViewTime( dtEnd.time().hour() ); | 996 | dayView->setStartViewTime( dtEnd.time().hour() ); |
992 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), | 997 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), |
993 | dtEnd.date().day() ); | 998 | dtEnd.date().day() ); |
994 | } else { | 999 | } else { |
995 | if ( wrapAround ) { | 1000 | if ( wrapAround ) { |
996 | emit signalWrapAround(); | 1001 | emit signalWrapAround(); |
997 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 1002 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
998 | nonrev.setStart( rev.start() ); | 1003 | nonrev.setStart( rev.start() ); |
999 | } else | 1004 | } else |
1000 | emit signalNotFound(); | 1005 | emit signalNotFound(); |
1001 | wrapAround = !wrapAround; | 1006 | wrapAround = !wrapAround; |
1002 | } | 1007 | } |
1003 | } | 1008 | } |
1004 | 1009 | ||
1005 | Event DateBookDBHack::eventByUID(int uid) { | 1010 | Event DateBookDBHack::eventByUID(int uid) { |
1006 | 1011 | ||
1007 | // FIXME: Dirty Hacks to get hold of the private event lists | 1012 | // FIXME: Dirty Hacks to get hold of the private event lists |
1008 | QDate start; | 1013 | QDate start; |
1009 | QDate end=start.addDays(-1); | 1014 | QDate end=start.addDays(-1); |
1010 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); | 1015 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); |
1011 | QValueList<Event> myRepeatEvents=getRawRepeats(); | 1016 | QValueList<Event> myRepeatEvents=getRawRepeats(); |
1012 | 1017 | ||
1013 | QValueList<Event>::ConstIterator it; | 1018 | QValueList<Event>::ConstIterator it; |
1014 | 1019 | ||
1015 | for (it = myEventList.begin(); it != myEventList.end(); it++) { | 1020 | for (it = myEventList.begin(); it != myEventList.end(); it++) { |
1016 | if ((*it).uid() == uid) return *it; | 1021 | if ((*it).uid() == uid) return *it; |
1017 | } | 1022 | } |
1018 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { | 1023 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { |
1019 | if ((*it).uid() == uid) return *it; | 1024 | if ((*it).uid() == uid) return *it; |
1020 | } | 1025 | } |
1021 | 1026 | ||
1022 | qDebug("Event not found: uid=%d\n", uid); | 1027 | qDebug("Event not found: uid=%d\n", uid); |
1023 | Event ev; | 1028 | Event ev; |
1024 | return ev; // return at least | 1029 | return ev; // return at least |
1025 | } | 1030 | } |
1026 | 1031 | ||