-rw-r--r-- | core/pim/datebook/datebook.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 7dd93a6..e10842a 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -13,258 +13,277 @@ | |||
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 <qtl.h> | 62 | #include <qtl.h> |
62 | #include <qwidgetstack.h> | 63 | #include <qwidgetstack.h> |
63 | #include <qwindowsystem_qws.h> | 64 | #include <qwindowsystem_qws.h> |
64 | 65 | ||
65 | #include <sys/stat.h> | 66 | #include <sys/stat.h> |
66 | #include <sys/types.h> | 67 | #include <sys/types.h> |
67 | #include <fcntl.h> | 68 | #include <fcntl.h> |
68 | #include <unistd.h> | 69 | #include <unistd.h> |
69 | 70 | ||
70 | #include <stdlib.h> | 71 | #include <stdlib.h> |
71 | 72 | ||
72 | #define DAY 1 | 73 | #define DAY 1 |
73 | #define WEEK 2 | 74 | #define WEEK 2 |
74 | #define WEEKLST 4 | 75 | #define WEEKLST 4 |
75 | #define MONTH 3 | 76 | #define MONTH 3 |
76 | 77 | ||
77 | 78 | ||
78 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 79 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
79 | : QMainWindow( parent, "datebook", f ), | 80 | : QMainWindow( parent, "datebook", f ), |
80 | aPreset( FALSE ), | 81 | aPreset( FALSE ), |
81 | presetTime( -1 ), | 82 | presetTime( -1 ), |
82 | startTime( 8 ), // an acceptable default | 83 | startTime( 8 ), // an acceptable default |
83 | rowStyle( 0 ), | 84 | rowStyle( 0 ), |
84 | bJumpToCurTime(FALSE), | 85 | bJumpToCurTime(FALSE), |
85 | syncing(FALSE), | 86 | syncing(FALSE), |
86 | inSearch(FALSE), | 87 | inSearch(FALSE), |
87 | alarmCounter(0) | 88 | alarmCounter(0) |
88 | { | 89 | { |
90 | bool needEvilHack= false; // if we need an Evil Hack | ||
89 | QTime t; | 91 | QTime t; |
90 | t.start(); | 92 | t.start(); |
91 | db = new DateBookDBHack; | 93 | db = new DateBookDBHack; |
92 | qDebug("loading db t=%d", t.elapsed() ); | 94 | qDebug("loading db t=%d", t.elapsed() ); |
93 | loadSettings(); | 95 | loadSettings(); |
94 | setCaption( tr("Calendar") ); | 96 | setCaption( tr("Calendar") ); |
95 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 97 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
96 | 98 | ||
97 | setToolBarsMovable( FALSE ); | 99 | setToolBarsMovable( FALSE ); |
98 | 100 | ||
99 | views = new QWidgetStack( this ); | 101 | views = new QWidgetStack( this ); |
100 | setCentralWidget( views ); | 102 | setCentralWidget( views ); |
101 | 103 | ||
102 | dayView = 0; | 104 | dayView = 0; |
103 | weekView = 0; | 105 | weekView = 0; |
104 | weekLstView = 0; | 106 | weekLstView = 0; |
105 | monthView = 0; | 107 | monthView = 0; |
106 | 108 | ||
107 | QPEToolBar *bar = new QPEToolBar( this ); | 109 | QPEToolBar *bar = new QPEToolBar( this ); |
108 | bar->setHorizontalStretchable( TRUE ); | 110 | bar->setHorizontalStretchable( TRUE ); |
109 | 111 | ||
110 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 112 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
111 | mb->setMargin( 0 ); | 113 | mb->setMargin( 0 ); |
112 | 114 | ||
113 | QPEToolBar *sub_bar = new QPEToolBar(this); | 115 | QPEToolBar *sub_bar = new QPEToolBar(this); |
114 | 116 | ||
115 | QPopupMenu *view = new QPopupMenu( this ); | 117 | QPopupMenu *view = new QPopupMenu( this ); |
116 | QPopupMenu *settings = new QPopupMenu( this ); | 118 | QPopupMenu *settings = new QPopupMenu( this ); |
117 | 119 | ||
118 | mb->insertItem( tr( "View" ), view ); | 120 | mb->insertItem( tr( "View" ), view ); |
119 | mb->insertItem( tr( "Settings" ), settings ); | 121 | mb->insertItem( tr( "Settings" ), settings ); |
120 | 122 | ||
121 | QActionGroup *g = new QActionGroup( this ); | 123 | QActionGroup *g = new QActionGroup( this ); |
122 | g->setExclusive( TRUE ); | 124 | g->setExclusive( TRUE ); |
123 | 125 | ||
124 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 126 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
125 | QString::null, 0, this, 0 ); | 127 | QString::null, 0, this, 0 ); |
126 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 128 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
127 | a->addTo( sub_bar ); | 129 | a->addTo( sub_bar ); |
128 | 130 | ||
129 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); | 131 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); |
130 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 132 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
131 | a->addTo( sub_bar ); | 133 | a->addTo( sub_bar ); |
132 | a->addTo( view ); | 134 | a->addTo( view ); |
133 | 135 | ||
134 | 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 ); |
135 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 137 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
136 | a->addTo( sub_bar ); | 138 | a->addTo( sub_bar ); |
137 | a->addTo( view ); | 139 | a->addTo( view ); |
138 | a->setToggleAction( TRUE ); | 140 | a->setToggleAction( TRUE ); |
139 | a->setOn( TRUE ); | 141 | a->setOn( TRUE ); |
140 | dayAction = a; | 142 | dayAction = a; |
141 | 143 | ||
142 | 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 ); |
143 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 145 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
144 | a->addTo( sub_bar ); | 146 | a->addTo( sub_bar ); |
145 | a->addTo( view ); | 147 | a->addTo( view ); |
146 | a->setToggleAction( TRUE ); | 148 | a->setToggleAction( TRUE ); |
147 | weekAction = a; | 149 | weekAction = a; |
148 | 150 | ||
149 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); | 151 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); |
150 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 152 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
151 | a->addTo( sub_bar ); | 153 | a->addTo( sub_bar ); |
152 | a->addTo( view ); | 154 | a->addTo( view ); |
153 | a->setToggleAction( TRUE ); | 155 | a->setToggleAction( TRUE ); |
154 | weekLstAction = a; | 156 | weekLstAction = a; |
155 | 157 | ||
156 | 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 ); |
157 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 159 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
158 | a->addTo( sub_bar ); | 160 | a->addTo( sub_bar ); |
159 | a->addTo( view ); | 161 | a->addTo( view ); |
160 | a->setToggleAction( TRUE ); | 162 | a->setToggleAction( TRUE ); |
161 | monthAction = a; | 163 | monthAction = a; |
162 | 164 | ||
163 | 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 ); |
164 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 166 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
165 | a->addTo( sub_bar ); | 167 | a->addTo( sub_bar ); |
166 | 168 | ||
167 | 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 ); |
168 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 170 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
169 | a->addTo( settings ); | 171 | a->addTo( settings ); |
170 | 172 | ||
171 | QPopupMenu *default_view = new QPopupMenu(this); | 173 | QPopupMenu *default_view = new QPopupMenu(this); |
172 | settings->insertItem( tr( "Default View" ),default_view ); | 174 | settings->insertItem( tr( "Default View" ),default_view ); |
173 | default_view->setCheckable(TRUE); | 175 | default_view->setCheckable(TRUE); |
174 | 176 | ||
175 | Config config("DateBook"); | 177 | Config config("DateBook"); |
176 | config.setGroup("Main"); | 178 | config.setGroup("Main"); |
177 | int current=config.readNumEntry("defaultview", DAY); | 179 | int current=config.readNumEntry("defaultview", DAY); |
178 | 180 | ||
179 | QActionGroup *ag = new QActionGroup(this); | 181 | QActionGroup *ag = new QActionGroup(this); |
180 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); | 182 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); |
181 | if (current==DAY) a->setOn(true), viewDay(); | 183 | if (current==DAY) a->setOn(true), viewDay(); |
182 | ag->insert(a); | 184 | ag->insert(a); |
183 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); | 185 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); |
184 | if (current==WEEK) a->setOn(true), viewWeek(); | 186 | if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; |
185 | ag->insert(a); | 187 | ag->insert(a); |
186 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); | 188 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); |
187 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); | 189 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); |
188 | ag->insert(a); | 190 | ag->insert(a); |
189 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); | 191 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); |
190 | if (current==MONTH) a->setOn(true), viewMonth(); | 192 | if (current==MONTH) a->setOn(true), viewMonth(); |
191 | ag->insert(a); | 193 | ag->insert(a); |
192 | 194 | ||
193 | ag->addTo(default_view); | 195 | ag->addTo(default_view); |
194 | connect(ag, SIGNAL( selected ( QAction * ) ), | 196 | connect(ag, SIGNAL( selected ( QAction * ) ), |
195 | this, SLOT( newDefaultView(QAction *) ) | 197 | this, SLOT( newDefaultView(QAction *) ) |
196 | ); | 198 | ); |
197 | 199 | ||
198 | connect( qApp, SIGNAL(clockChanged(bool)), | 200 | connect( qApp, SIGNAL(clockChanged(bool)), |
199 | this, SLOT(changeClock(bool)) ); | 201 | this, SLOT(changeClock(bool)) ); |
200 | connect( qApp, SIGNAL(weekChanged(bool)), | 202 | connect( qApp, SIGNAL(weekChanged(bool)), |
201 | this, SLOT(changeWeek(bool)) ); | 203 | this, SLOT(changeWeek(bool)) ); |
202 | 204 | ||
203 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
204 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 206 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
205 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 207 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
206 | #endif | 208 | #endif |
207 | 209 | ||
208 | // listen on QPE/System | 210 | // listen on QPE/System |
209 | #if defined(Q_WS_QWS) | 211 | #if defined(Q_WS_QWS) |
210 | #if !defined(QT_NO_COP) | 212 | #if !defined(QT_NO_COP) |
211 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 213 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
212 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 214 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
213 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 215 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
214 | channel = new QCopChannel( "QPE/Datebook", this ); | 216 | channel = new QCopChannel( "QPE/Datebook", this ); |
215 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 217 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
216 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 218 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
217 | qDebug("olle\n"); | 219 | qDebug("olle\n"); |
218 | #endif | 220 | #endif |
219 | #endif | 221 | #endif |
220 | 222 | ||
221 | qDebug("done t=%d", t.elapsed() ); | 223 | qDebug("done t=%d", t.elapsed() ); |
222 | 224 | ||
225 | /* | ||
226 | * Here is a problem description: | ||
227 | * When Weekview is the default view | ||
228 | * a DateBookWeekView get's created | ||
229 | * redraw() get's called. So what? | ||
230 | * Remember that we're still in the c'tor | ||
231 | * and no final layout has happened? Ok | ||
232 | * now all Events get arranged. Their x | ||
233 | * position get's determined by a QHeader | ||
234 | * position. But the QHeader isn't layouted or | ||
235 | * at the right position. redraw() is a slot | ||
236 | * so we'll call it then via a singleShot | ||
237 | * from view() | ||
238 | */ | ||
239 | if( needEvilHack ){ | ||
240 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); | ||
241 | } | ||
223 | } | 242 | } |
224 | 243 | ||
225 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 244 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
226 | { | 245 | { |
227 | QDataStream stream( data, IO_ReadOnly ); | 246 | QDataStream stream( data, IO_ReadOnly ); |
228 | if ( msg == "timeChange(QString)" ) { | 247 | if ( msg == "timeChange(QString)" ) { |
229 | // update active view! | 248 | // update active view! |
230 | if ( dayAction->isOn() ) | 249 | if ( dayAction->isOn() ) |
231 | viewDay(); | 250 | viewDay(); |
232 | else if ( weekAction->isOn() ) | 251 | else if ( weekAction->isOn() ) |
233 | viewWeek(); | 252 | viewWeek(); |
234 | else if ( monthAction->isOn() ) | 253 | else if ( monthAction->isOn() ) |
235 | viewMonth(); | 254 | viewMonth(); |
236 | } | 255 | } |
237 | else if (msg == "editEvent(int)") { | 256 | else if (msg == "editEvent(int)") { |
238 | int uid; | 257 | int uid; |
239 | stream >> uid; | 258 | stream >> uid; |
240 | Event e=db->eventByUID(uid); | 259 | Event e=db->eventByUID(uid); |
241 | editEvent(e); | 260 | editEvent(e); |
242 | } | 261 | } |
243 | } | 262 | } |
244 | 263 | ||
245 | DateBook::~DateBook() | 264 | DateBook::~DateBook() |
246 | { | 265 | { |
247 | } | 266 | } |
248 | 267 | ||
249 | void DateBook::slotSettings() | 268 | void DateBook::slotSettings() |
250 | { | 269 | { |
251 | DateBookSettings frmSettings( ampm, this ); | 270 | DateBookSettings frmSettings( ampm, this ); |
252 | frmSettings.setStartTime( startTime ); | 271 | frmSettings.setStartTime( startTime ); |
253 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 272 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
254 | frmSettings.setJumpToCurTime( bJumpToCurTime ); | 273 | frmSettings.setJumpToCurTime( bJumpToCurTime ); |
255 | frmSettings.setRowStyle( rowStyle ); | 274 | frmSettings.setRowStyle( rowStyle ); |
256 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 275 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
257 | frmSettings.showMaximized(); | 276 | frmSettings.showMaximized(); |
258 | #endif | 277 | #endif |
259 | 278 | ||
260 | if ( frmSettings.exec() ) { | 279 | if ( frmSettings.exec() ) { |
261 | aPreset = frmSettings.alarmPreset(); | 280 | aPreset = frmSettings.alarmPreset(); |
262 | presetTime = frmSettings.presetTime(); | 281 | presetTime = frmSettings.presetTime(); |
263 | startTime = frmSettings.startTime(); | 282 | startTime = frmSettings.startTime(); |
264 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 283 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
265 | rowStyle = frmSettings.rowStyle(); | 284 | rowStyle = frmSettings.rowStyle(); |
266 | if ( dayView ) | 285 | if ( dayView ) |
267 | dayView->setStartViewTime( startTime ); | 286 | dayView->setStartViewTime( startTime ); |
268 | dayView->setJumpToCurTime( bJumpToCurTime ); | 287 | dayView->setJumpToCurTime( bJumpToCurTime ); |
269 | dayView->setRowStyle( rowStyle ); | 288 | dayView->setRowStyle( rowStyle ); |
270 | if ( weekView ) | 289 | if ( weekView ) |