-rw-r--r-- | core/pim/datebook/datebook.cpp | 12 | ||||
-rw-r--r-- | core/pim/datebook/dateentryimpl.cpp | 2 | ||||
-rw-r--r-- | core/pim/datebook/timepicker.cpp | 1 |
3 files changed, 9 insertions, 6 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 2deb96f..97c305c 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,967 +1,967 @@ | |||
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 <qtextcodec.h> | 58 | #include <qtextcodec.h> |
59 | #include <qtextstream.h> | 59 | #include <qtextstream.h> |
60 | #include <qtl.h> | 60 | #include <qtl.h> |
61 | #include <qwidgetstack.h> | 61 | #include <qwidgetstack.h> |
62 | #include <qwindowsystem_qws.h> | 62 | #include <qwindowsystem_qws.h> |
63 | 63 | ||
64 | #include <sys/stat.h> | 64 | #include <sys/stat.h> |
65 | #include <sys/types.h> | 65 | #include <sys/types.h> |
66 | #include <fcntl.h> | 66 | #include <fcntl.h> |
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | 68 | ||
69 | #include <stdlib.h> | 69 | #include <stdlib.h> |
70 | 70 | ||
71 | #define DAY 1 | 71 | #define DAY 1 |
72 | #define WEEK 2 | 72 | #define WEEK 2 |
73 | #define WEEKLST 4 | 73 | #define WEEKLST 4 |
74 | #define MONTH 3 | 74 | #define MONTH 3 |
75 | 75 | ||
76 | 76 | ||
77 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 77 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
78 | : QMainWindow( parent, "datebook", f ), | 78 | : QMainWindow( parent, "datebook", f ), |
79 | aPreset( FALSE ), | 79 | aPreset( FALSE ), |
80 | presetTime( -1 ), | 80 | presetTime( -1 ), |
81 | startTime( 8 ), // an acceptable default | 81 | startTime( 8 ), // an acceptable default |
82 | syncing(FALSE), | 82 | syncing(FALSE), |
83 | inSearch(FALSE) | 83 | inSearch(FALSE) |
84 | { | 84 | { |
85 | QTime t; | 85 | QTime t; |
86 | t.start(); | 86 | t.start(); |
87 | db = new DateBookDB; | 87 | db = new DateBookDB; |
88 | qDebug("loading db t=%d", t.elapsed() ); | 88 | qDebug("loading db t=%d", t.elapsed() ); |
89 | loadSettings(); | 89 | loadSettings(); |
90 | setCaption( tr("Calendar") ); | 90 | setCaption( tr("Calendar") ); |
91 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 91 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
92 | 92 | ||
93 | setToolBarsMovable( FALSE ); | 93 | setToolBarsMovable( FALSE ); |
94 | 94 | ||
95 | views = new QWidgetStack( this ); | 95 | views = new QWidgetStack( this ); |
96 | setCentralWidget( views ); | 96 | setCentralWidget( views ); |
97 | 97 | ||
98 | dayView = 0; | 98 | dayView = 0; |
99 | weekView = 0; | 99 | weekView = 0; |
100 | weekLstView = 0; | 100 | weekLstView = 0; |
101 | monthView = 0; | 101 | monthView = 0; |
102 | 102 | ||
103 | QPEToolBar *bar = new QPEToolBar( this ); | 103 | QPEToolBar *bar = new QPEToolBar( this ); |
104 | bar->setHorizontalStretchable( TRUE ); | 104 | bar->setHorizontalStretchable( TRUE ); |
105 | 105 | ||
106 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 106 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
107 | mb->setMargin( 0 ); | 107 | mb->setMargin( 0 ); |
108 | 108 | ||
109 | QPEToolBar *sub_bar = new QPEToolBar(this); | 109 | QPEToolBar *sub_bar = new QPEToolBar(this); |
110 | 110 | ||
111 | QPopupMenu *view = new QPopupMenu( this ); | 111 | QPopupMenu *view = new QPopupMenu( this ); |
112 | QPopupMenu *settings = new QPopupMenu( this ); | 112 | QPopupMenu *settings = new QPopupMenu( this ); |
113 | 113 | ||
114 | mb->insertItem( tr( "View" ), view ); | 114 | mb->insertItem( tr( "View" ), view ); |
115 | mb->insertItem( tr( "Settings" ), settings ); | 115 | mb->insertItem( tr( "Settings" ), settings ); |
116 | 116 | ||
117 | QActionGroup *g = new QActionGroup( this ); | 117 | QActionGroup *g = new QActionGroup( this ); |
118 | g->setExclusive( TRUE ); | 118 | g->setExclusive( TRUE ); |
119 | 119 | ||
120 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 120 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
121 | QString::null, 0, this, 0 ); | 121 | QString::null, 0, this, 0 ); |
122 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 122 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
123 | a->addTo( sub_bar ); | 123 | a->addTo( sub_bar ); |
124 | 124 | ||
125 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); | 125 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); |
126 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 126 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
127 | a->addTo( sub_bar ); | 127 | a->addTo( sub_bar ); |
128 | a->addTo( view ); | 128 | a->addTo( view ); |
129 | 129 | ||
130 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); | 130 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); |
131 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 131 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
132 | a->addTo( sub_bar ); | 132 | a->addTo( sub_bar ); |
133 | a->addTo( view ); | 133 | a->addTo( view ); |
134 | a->setToggleAction( TRUE ); | 134 | a->setToggleAction( TRUE ); |
135 | a->setOn( TRUE ); | 135 | a->setOn( TRUE ); |
136 | dayAction = a; | 136 | dayAction = a; |
137 | 137 | ||
138 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); | 138 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); |
139 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 139 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
140 | a->addTo( sub_bar ); | 140 | a->addTo( sub_bar ); |
141 | a->addTo( view ); | 141 | a->addTo( view ); |
142 | a->setToggleAction( TRUE ); | 142 | a->setToggleAction( TRUE ); |
143 | weekAction = a; | 143 | weekAction = a; |
144 | 144 | ||
145 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); | 145 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); |
146 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 146 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
147 | a->addTo( sub_bar ); | 147 | a->addTo( sub_bar ); |
148 | a->addTo( view ); | 148 | a->addTo( view ); |
149 | a->setToggleAction( TRUE ); | 149 | a->setToggleAction( TRUE ); |
150 | weekLstAction = a; | 150 | weekLstAction = a; |
151 | 151 | ||
152 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); | 152 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); |
153 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 153 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
154 | a->addTo( sub_bar ); | 154 | a->addTo( sub_bar ); |
155 | a->addTo( view ); | 155 | a->addTo( view ); |
156 | a->setToggleAction( TRUE ); | 156 | a->setToggleAction( TRUE ); |
157 | monthAction = a; | 157 | monthAction = a; |
158 | 158 | ||
159 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); | 159 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); |
160 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 160 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
161 | a->addTo( sub_bar ); | 161 | a->addTo( sub_bar ); |
162 | 162 | ||
163 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); | 163 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); |
164 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 164 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
165 | a->addTo( settings ); | 165 | a->addTo( settings ); |
166 | 166 | ||
167 | QPopupMenu *default_view = new QPopupMenu(this); | 167 | QPopupMenu *default_view = new QPopupMenu(this); |
168 | settings->insertItem( tr( "Default View" ),default_view ); | 168 | settings->insertItem( tr( "Default View" ),default_view ); |
169 | default_view->setCheckable(TRUE); | 169 | default_view->setCheckable(TRUE); |
170 | 170 | ||
171 | Config config("DateBook"); | 171 | Config config("DateBook"); |
172 | config.setGroup("Main"); | 172 | config.setGroup("Main"); |
173 | int current=config.readNumEntry("defaultview", DAY); | 173 | int current=config.readNumEntry("defaultview", DAY); |
174 | 174 | ||
175 | QActionGroup *ag = new QActionGroup(this); | 175 | QActionGroup *ag = new QActionGroup(this); |
176 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); | 176 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); |
177 | if (current==DAY) a->setOn(true), viewDay(); | 177 | if (current==DAY) a->setOn(true), viewDay(); |
178 | ag->insert(a); | 178 | ag->insert(a); |
179 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); | 179 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); |
180 | if (current==WEEK) a->setOn(true), viewWeek(); | 180 | if (current==WEEK) a->setOn(true), viewWeek(); |
181 | ag->insert(a); | 181 | ag->insert(a); |
182 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); | 182 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); |
183 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); | 183 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); |
184 | ag->insert(a); | 184 | ag->insert(a); |
185 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); | 185 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); |
186 | if (current==MONTH) a->setOn(true), viewMonth(); | 186 | if (current==MONTH) a->setOn(true), viewMonth(); |
187 | ag->insert(a); | 187 | ag->insert(a); |
188 | 188 | ||
189 | ag->addTo(default_view); | 189 | ag->addTo(default_view); |
190 | connect(ag, SIGNAL( selected ( QAction * ) ), | 190 | connect(ag, SIGNAL( selected ( QAction * ) ), |
191 | this, SLOT( newDefaultView(QAction *) ) | 191 | this, SLOT( newDefaultView(QAction *) ) |
192 | ); | 192 | ); |
193 | 193 | ||
194 | connect( qApp, SIGNAL(clockChanged(bool)), | 194 | connect( qApp, SIGNAL(clockChanged(bool)), |
195 | this, SLOT(changeClock(bool)) ); | 195 | this, SLOT(changeClock(bool)) ); |
196 | connect( qApp, SIGNAL(weekChanged(bool)), | 196 | connect( qApp, SIGNAL(weekChanged(bool)), |
197 | this, SLOT(changeWeek(bool)) ); | 197 | this, SLOT(changeWeek(bool)) ); |
198 | 198 | ||
199 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 199 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
200 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 200 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
201 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 201 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
202 | #endif | 202 | #endif |
203 | 203 | ||
204 | // listen on QPE/System | 204 | // listen on QPE/System |
205 | #if defined(Q_WS_QWS) | 205 | #if defined(Q_WS_QWS) |
206 | #if !defined(QT_NO_COP) | 206 | #if !defined(QT_NO_COP) |
207 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 207 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
208 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 208 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
209 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 209 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
210 | channel = new QCopChannel( "QPE/Datebook", this ); | 210 | channel = new QCopChannel( "QPE/Datebook", this ); |
211 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 211 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
212 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 212 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
213 | qDebug("olle\n"); | ||
213 | #endif | 214 | #endif |
214 | #endif | 215 | #endif |
215 | 216 | ||
216 | qDebug("done t=%d", t.elapsed() ); | 217 | qDebug("done t=%d", t.elapsed() ); |
217 | 218 | ||
218 | } | 219 | } |
219 | 220 | ||
220 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 221 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
221 | { | 222 | { |
222 | QDataStream stream( data, IO_ReadOnly ); | 223 | QDataStream stream( data, IO_ReadOnly ); |
223 | if ( msg == "timeChange(QString)" ) { | 224 | if ( msg == "timeChange(QString)" ) { |
224 | // update active view! | 225 | // update active view! |
225 | if ( dayAction->isOn() ) | 226 | if ( dayAction->isOn() ) |
226 | viewDay(); | 227 | viewDay(); |
227 | else if ( weekAction->isOn() ) | 228 | else if ( weekAction->isOn() ) |
228 | viewWeek(); | 229 | viewWeek(); |
229 | else if ( monthAction->isOn() ) | 230 | else if ( monthAction->isOn() ) |
230 | viewMonth(); | 231 | viewMonth(); |
231 | } | 232 | } |
232 | else if (msg == "editEvent(int)") { | 233 | else if (msg == "editEvent(int)") { |
233 | /* Not yet working... | 234 | int uid; |
234 | int uid; | 235 | stream >> uid; |
235 | stream >> uid; | 236 | Event e=db->getEvent(uid); |
236 | Event e=db->getEvent(uid); | 237 | editEvent(e); |
237 | editEvent(e); | ||
238 | */ | ||
239 | } | 238 | } |
240 | } | 239 | } |
241 | 240 | ||
242 | DateBook::~DateBook() | 241 | DateBook::~DateBook() |
243 | { | 242 | { |
244 | } | 243 | } |
245 | 244 | ||
246 | void DateBook::slotSettings() | 245 | void DateBook::slotSettings() |
247 | { | 246 | { |
248 | DateBookSettings frmSettings( ampm, this ); | 247 | DateBookSettings frmSettings( ampm, this ); |
249 | frmSettings.setStartTime( startTime ); | 248 | frmSettings.setStartTime( startTime ); |
250 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 249 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
251 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 250 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
252 | frmSettings.showMaximized(); | 251 | frmSettings.showMaximized(); |
253 | #endif | 252 | #endif |
254 | 253 | ||
255 | if ( frmSettings.exec() ) { | 254 | if ( frmSettings.exec() ) { |
256 | aPreset = frmSettings.alarmPreset(); | 255 | aPreset = frmSettings.alarmPreset(); |
257 | presetTime = frmSettings.presetTime(); | 256 | presetTime = frmSettings.presetTime(); |
258 | startTime = frmSettings.startTime(); | 257 | startTime = frmSettings.startTime(); |
259 | if ( dayView ) | 258 | if ( dayView ) |
260 | dayView->setStartViewTime( startTime ); | 259 | dayView->setStartViewTime( startTime ); |
261 | if ( weekView ) | 260 | if ( weekView ) |
262 | weekView->setStartViewTime( startTime ); | 261 | weekView->setStartViewTime( startTime ); |
263 | saveSettings(); | 262 | saveSettings(); |
264 | 263 | ||
265 | // make the change obvious | 264 | // make the change obvious |
266 | if ( views->visibleWidget() ) { | 265 | if ( views->visibleWidget() ) { |
267 | if ( views->visibleWidget() == dayView ) | 266 | if ( views->visibleWidget() == dayView ) |
268 | dayView->redraw(); | 267 | dayView->redraw(); |
269 | else if ( views->visibleWidget() == weekView ) | 268 | else if ( views->visibleWidget() == weekView ) |
270 | weekView->redraw(); | 269 | weekView->redraw(); |
271 | } | 270 | } |
272 | } | 271 | } |
273 | } | 272 | } |
274 | 273 | ||
275 | void DateBook::fileNew() | 274 | void DateBook::fileNew() |
276 | { | 275 | { |
277 | slotNewEventFromKey(""); | 276 | slotNewEventFromKey(""); |
278 | } | 277 | } |
279 | 278 | ||
280 | QString DateBook::checkEvent(const Event &e) | 279 | QString DateBook::checkEvent(const Event &e) |
281 | { | 280 | { |
282 | /* check if overlaps with itself */ | 281 | /* check if overlaps with itself */ |
283 | bool checkFailed = FALSE; | 282 | bool checkFailed = FALSE; |
284 | 283 | ||
285 | /* check the next 12 repeats. should catch most problems */ | 284 | /* check the next 12 repeats. should catch most problems */ |
286 | QDate current_date = e.start().date(); | 285 | QDate current_date = e.start().date(); |
287 | Event previous = e; | 286 | Event previous = e; |
288 | for(int i = 0; i < 12; i++) | 287 | for(int i = 0; i < 12; i++) |
289 | { | 288 | { |
290 | QDateTime next; | 289 | QDateTime next; |
291 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 290 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
292 | break; // no more repeats | 291 | break; // no more repeats |
293 | } | 292 | } |
294 | if(next < previous.end()) { | 293 | if(next < previous.end()) { |
295 | checkFailed = TRUE; | 294 | checkFailed = TRUE; |
296 | break; | 295 | break; |
297 | } | 296 | } |
298 | current_date = next.date(); | 297 | current_date = next.date(); |
299 | } | 298 | } |
300 | 299 | ||
301 | if(checkFailed) | 300 | if(checkFailed) |
302 | return tr("Event duration is potentially longer\n" | 301 | return tr("Event duration is potentially longer\n" |
303 | "than interval between repeats."); | 302 | "than interval between repeats."); |
304 | 303 | ||
305 | return QString::null; | 304 | return QString::null; |
306 | } | 305 | } |
307 | 306 | ||
308 | QDate DateBook::currentDate() | 307 | QDate DateBook::currentDate() |
309 | { | 308 | { |
310 | QDate d = QDate::currentDate(); | 309 | QDate d = QDate::currentDate(); |
311 | 310 | ||
312 | if ( dayView && views->visibleWidget() == dayView ) { | 311 | if ( dayView && views->visibleWidget() == dayView ) { |
313 | d = dayView->date(); | 312 | d = dayView->date(); |
314 | } else if ( weekView && views->visibleWidget() == weekView ) { | 313 | } else if ( weekView && views->visibleWidget() == weekView ) { |
315 | d = weekView->date(); | 314 | d = weekView->date(); |
316 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 315 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
317 | d = weekLstView->date(); | 316 | d = weekLstView->date(); |
318 | } else if ( monthView && views->visibleWidget() == monthView ) { | 317 | } else if ( monthView && views->visibleWidget() == monthView ) { |
319 | d = monthView->selectedDate(); | 318 | d = monthView->selectedDate(); |
320 | } | 319 | } |
321 | 320 | ||
322 | return d; | 321 | return d; |
323 | } | 322 | } |
324 | 323 | ||
325 | void DateBook::view(int v, const QDate &d) { | 324 | void DateBook::view(int v, const QDate &d) { |
326 | if (v==DAY) { | 325 | if (v==DAY) { |
327 | initDay(); | 326 | initDay(); |
328 | dayAction->setOn( TRUE ); | 327 | dayAction->setOn( TRUE ); |
329 | dayView->setDate( d ); | 328 | dayView->setDate( d ); |
330 | views->raiseWidget( dayView ); | 329 | views->raiseWidget( dayView ); |
331 | dayView->redraw(); | 330 | dayView->redraw(); |
332 | } else if (v==WEEK) { | 331 | } else if (v==WEEK) { |
333 | initWeek(); | 332 | initWeek(); |
334 | weekAction->setOn( TRUE ); | 333 | weekAction->setOn( TRUE ); |
335 | weekView->setDate( d ); | 334 | weekView->setDate( d ); |
336 | views->raiseWidget( weekView ); | 335 | views->raiseWidget( weekView ); |
337 | weekView->redraw(); | 336 | weekView->redraw(); |
338 | } else if (v==WEEKLST) { | 337 | } else if (v==WEEKLST) { |
339 | initWeekLst(); | 338 | initWeekLst(); |
340 | weekLstAction->setOn( TRUE ); | 339 | weekLstAction->setOn( TRUE ); |
341 | weekLstView->setDate(d); | 340 | weekLstView->setDate(d); |
342 | views->raiseWidget( weekLstView ); | 341 | views->raiseWidget( weekLstView ); |
343 | weekLstView->redraw(); | 342 | weekLstView->redraw(); |
344 | } else if (v==MONTH) { | 343 | } else if (v==MONTH) { |
345 | initMonth(); | 344 | initMonth(); |
346 | monthAction->setOn( TRUE ); | 345 | monthAction->setOn( TRUE ); |
347 | monthView->setDate( d.year(), d.month(), d.day() ); | 346 | monthView->setDate( d.year(), d.month(), d.day() ); |
348 | views->raiseWidget( monthView ); | 347 | views->raiseWidget( monthView ); |
349 | monthView->redraw(); | 348 | monthView->redraw(); |
350 | } | 349 | } |
351 | } | 350 | } |
352 | 351 | ||
353 | void DateBook::viewDefault(const QDate &d) { | 352 | void DateBook::viewDefault(const QDate &d) { |
354 | Config config("DateBook"); | 353 | Config config("DateBook"); |
355 | config.setGroup("Main"); | 354 | config.setGroup("Main"); |
356 | int current=config.readNumEntry("defaultview", DAY); | 355 | int current=config.readNumEntry("defaultview", DAY); |
357 | 356 | ||
358 | view(current,d); | 357 | view(current,d); |
359 | } | 358 | } |
360 | 359 | ||
361 | void DateBook::viewDay() { | 360 | void DateBook::viewDay() { |
362 | view(DAY,currentDate()); | 361 | view(DAY,currentDate()); |
363 | } | 362 | } |
364 | 363 | ||
365 | void DateBook::viewWeek() { | 364 | void DateBook::viewWeek() { |
366 | view(WEEK,currentDate()); | 365 | view(WEEK,currentDate()); |
367 | } | 366 | } |
368 | 367 | ||
369 | void DateBook::viewWeekLst() { | 368 | void DateBook::viewWeekLst() { |
370 | view(WEEKLST,currentDate()); | 369 | view(WEEKLST,currentDate()); |
371 | } | 370 | } |
372 | 371 | ||
373 | void DateBook::viewMonth() { | 372 | void DateBook::viewMonth() { |
374 | view(MONTH,currentDate()); | 373 | view(MONTH,currentDate()); |
375 | } | 374 | } |
376 | 375 | ||
377 | void DateBook::editEvent( const Event &e ) | 376 | void DateBook::editEvent( const Event &e ) |
378 | { | 377 | { |
379 | if (syncing) { | 378 | if (syncing) { |
380 | QMessageBox::warning( this, tr("Calendar"), | 379 | QMessageBox::warning( this, tr("Calendar"), |
381 | tr( "Can not edit data, currently syncing") ); | 380 | tr( "Can not edit data, currently syncing") ); |
382 | return; | 381 | return; |
383 | } | 382 | } |
384 | 383 | ||
385 | // workaround added for text input. | 384 | // workaround added for text input. |
386 | QDialog editDlg( this, 0, TRUE ); | 385 | QDialog editDlg( this, 0, TRUE ); |
387 | DateEntry *entry; | 386 | DateEntry *entry; |
388 | editDlg.setCaption( tr("Edit Event") ); | 387 | editDlg.setCaption( tr("Edit Event") ); |
389 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 388 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
390 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 389 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
391 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 390 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
392 | // KLUDGE!!! | 391 | // KLUDGE!!! |
393 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 392 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
394 | vb->addWidget( sv ); | 393 | vb->addWidget( sv ); |
395 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 394 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
396 | entry->timezone->setEnabled( FALSE ); | 395 | entry->timezone->setEnabled( FALSE ); |
397 | sv->addChild( entry ); | 396 | sv->addChild( entry ); |
398 | 397 | ||
399 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 398 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
400 | editDlg.showMaximized(); | 399 | editDlg.showMaximized(); |
401 | #endif | 400 | #endif |
402 | while (editDlg.exec() ) { | 401 | while (editDlg.exec() ) { |
403 | Event newEv = entry->event(); | 402 | Event newEv = entry->event(); |
403 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | ||
404 | QString error = checkEvent(newEv); | 404 | QString error = checkEvent(newEv); |
405 | if (!error.isNull()) { | 405 | if (!error.isNull()) { |
406 | if (QMessageBox::warning(this, "error box", | 406 | if (QMessageBox::warning(this, "error box", |
407 | error, "Fix it", "Continue", | 407 | error, "Fix it", "Continue", |
408 | 0, 0, 1) == 0) | 408 | 0, 0, 1) == 0) |
409 | continue; | 409 | continue; |
410 | } | 410 | } |
411 | db->editEvent(e, newEv); | 411 | db->editEvent(e, newEv); |
412 | emit newEvent(); | 412 | emit newEvent(); |
413 | break; | 413 | break; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | void DateBook::removeEvent( const Event &e ) | 417 | void DateBook::removeEvent( const Event &e ) |
418 | { | 418 | { |
419 | if (syncing) { | 419 | if (syncing) { |
420 | QMessageBox::warning( this, tr("Calendar"), | 420 | QMessageBox::warning( this, tr("Calendar"), |
421 | tr( "Can not edit data, currently syncing") ); | 421 | tr( "Can not edit data, currently syncing") ); |
422 | return; | 422 | return; |
423 | } | 423 | } |
424 | 424 | ||
425 | QString strName = e.description(); | 425 | QString strName = e.description(); |
426 | 426 | ||
427 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 427 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
428 | return; | 428 | return; |
429 | 429 | ||
430 | db->removeEvent( e ); | 430 | db->removeEvent( e ); |
431 | if ( views->visibleWidget() == dayView && dayView ) | 431 | if ( views->visibleWidget() == dayView && dayView ) |
432 | dayView->redraw(); | 432 | dayView->redraw(); |
433 | } | 433 | } |
434 | 434 | ||
435 | void DateBook::addEvent( const Event &e ) | 435 | void DateBook::addEvent( const Event &e ) |
436 | { | 436 | { |
437 | QDate d = e.start().date(); | 437 | QDate d = e.start().date(); |
438 | initDay(); | 438 | initDay(); |
439 | dayView->setDate( d ); | 439 | dayView->setDate( d ); |
440 | } | 440 | } |
441 | 441 | ||
442 | void DateBook::showDay( int year, int month, int day ) | 442 | void DateBook::showDay( int year, int month, int day ) |
443 | { | 443 | { |
444 | QDate d(year, month, day); | 444 | QDate d(year, month, day); |
445 | view(DAY,d); | 445 | view(DAY,d); |
446 | } | 446 | } |
447 | 447 | ||
448 | void DateBook::initDay() | 448 | void DateBook::initDay() |
449 | { | 449 | { |
450 | if ( !dayView ) { | 450 | if ( !dayView ) { |
451 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 451 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
452 | views->addWidget( dayView, DAY ); | 452 | views->addWidget( dayView, DAY ); |
453 | dayView->setStartViewTime( startTime ); | 453 | dayView->setStartViewTime( startTime ); |
454 | connect( this, SIGNAL( newEvent() ), | 454 | connect( this, SIGNAL( newEvent() ), |
455 | dayView, SLOT( redraw() ) ); | 455 | dayView, SLOT( redraw() ) ); |
456 | connect( dayView, SIGNAL( newEvent() ), | 456 | connect( dayView, SIGNAL( newEvent() ), |
457 | this, SLOT( fileNew() ) ); | 457 | this, SLOT( fileNew() ) ); |
458 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), | 458 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), |
459 | this, SLOT( removeEvent( const Event & ) ) ); | 459 | this, SLOT( removeEvent( const Event & ) ) ); |
460 | connect( dayView, SIGNAL( editEvent( const Event & ) ), | 460 | connect( dayView, SIGNAL( editEvent( const Event & ) ), |
461 | this, SLOT( editEvent( const Event & ) ) ); | 461 | this, SLOT( editEvent( const Event & ) ) ); |
462 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), | 462 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), |
463 | this, SLOT( beamEvent( const Event & ) ) ); | 463 | this, SLOT( beamEvent( const Event & ) ) ); |
464 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), | 464 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), |
465 | this, SLOT(slotNewEventFromKey(const QString &)) ); | 465 | this, SLOT(slotNewEventFromKey(const QString &)) ); |
466 | } | 466 | } |
467 | } | 467 | } |
468 | 468 | ||
469 | void DateBook::initWeek() | 469 | void DateBook::initWeek() |
470 | { | 470 | { |
471 | if ( !weekView ) { | 471 | if ( !weekView ) { |
472 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 472 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
473 | weekView->setStartViewTime( startTime ); | 473 | weekView->setStartViewTime( startTime ); |
474 | views->addWidget( weekView, WEEK ); | 474 | views->addWidget( weekView, WEEK ); |
475 | connect( weekView, SIGNAL( showDate( int, int, int ) ), | 475 | connect( weekView, SIGNAL( showDate( int, int, int ) ), |
476 | this, SLOT( showDay( int, int, int ) ) ); | 476 | this, SLOT( showDay( int, int, int ) ) ); |
477 | connect( this, SIGNAL( newEvent() ), | 477 | connect( this, SIGNAL( newEvent() ), |
478 | weekView, SLOT( redraw() ) ); | 478 | weekView, SLOT( redraw() ) ); |
479 | } | 479 | } |
480 | //But also get it right: the year that we display can be different | 480 | //But also get it right: the year that we display can be different |
481 | //from the year of the current date. So, first find the year | 481 | //from the year of the current date. So, first find the year |
482 | //number of the current week. | 482 | //number of the current week. |
483 | 483 | ||
484 | int yearNumber, totWeeks; | 484 | int yearNumber, totWeeks; |
485 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | 485 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); |
486 | 486 | ||
487 | QDate d = QDate( yearNumber, 12, 31 ); | 487 | QDate d = QDate( yearNumber, 12, 31 ); |
488 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 488 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
489 | 489 | ||
490 | while ( totWeeks == 1 ) { | 490 | while ( totWeeks == 1 ) { |
491 | d = d.addDays( -1 ); | 491 | d = d.addDays( -1 ); |
492 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 492 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
493 | } | 493 | } |
494 | if ( totWeeks != weekView->totalWeeks() ) | 494 | if ( totWeeks != weekView->totalWeeks() ) |
495 | weekView->setTotalWeeks( totWeeks ); | 495 | weekView->setTotalWeeks( totWeeks ); |
496 | } | 496 | } |
497 | void DateBook::initWeekLst() { | 497 | void DateBook::initWeekLst() { |
498 | if ( !weekLstView ) { | 498 | if ( !weekLstView ) { |
499 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, | 499 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, |
500 | views, "weeklst view" ); | 500 | views, "weeklst view" ); |
501 | views->addWidget( weekLstView, WEEKLST ); | 501 | views->addWidget( weekLstView, WEEKLST ); |
502 | 502 | ||
503 | //weekLstView->setStartViewTime( startTime ); | 503 | //weekLstView->setStartViewTime( startTime ); |
504 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), | 504 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), |
505 | this, SLOT( showDay( int, int, int ) ) ); | 505 | this, SLOT( showDay( int, int, int ) ) ); |
506 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, | 506 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, |
507 | const QDateTime &, | 507 | const QDateTime &, |
508 | const QString & ) ), | 508 | const QString & ) ), |
509 | this, SLOT( slotNewEntry( const QDateTime &, | 509 | this, SLOT( slotNewEntry( const QDateTime &, |
510 | const QDateTime &, | 510 | const QDateTime &, |
511 | const QString & ) ) ); | 511 | const QString & ) ) ); |
512 | connect( this, SIGNAL( newEvent() ), | 512 | connect( this, SIGNAL( newEvent() ), |
513 | weekLstView, SLOT( redraw() ) ); | 513 | weekLstView, SLOT( redraw() ) ); |
514 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), | 514 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), |
515 | this, SLOT( editEvent( const Event & ) ) ); | 515 | this, SLOT( editEvent( const Event & ) ) ); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | 519 | ||
520 | void DateBook::initMonth() | 520 | void DateBook::initMonth() |
521 | { | 521 | { |
522 | if ( !monthView ) { | 522 | if ( !monthView ) { |
523 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 523 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
524 | views->addWidget( monthView, MONTH ); | 524 | views->addWidget( monthView, MONTH ); |
525 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), | 525 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), |
526 | this, SLOT( showDay( int, int, int ) ) ); | 526 | this, SLOT( showDay( int, int, int ) ) ); |
527 | connect( this, SIGNAL( newEvent() ), | 527 | connect( this, SIGNAL( newEvent() ), |
528 | monthView, SLOT( redraw() ) ); | 528 | monthView, SLOT( redraw() ) ); |
529 | qApp->processEvents(); | 529 | qApp->processEvents(); |
530 | } | 530 | } |
531 | } | 531 | } |
532 | 532 | ||
533 | void DateBook::loadSettings() | 533 | void DateBook::loadSettings() |
534 | { | 534 | { |
535 | { | 535 | { |
536 | Config config( "qpe" ); | 536 | Config config( "qpe" ); |
537 | config.setGroup("Time"); | 537 | config.setGroup("Time"); |
538 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 538 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
539 | onMonday = config.readBoolEntry( "MONDAY" ); | 539 | onMonday = config.readBoolEntry( "MONDAY" ); |
540 | } | 540 | } |
541 | 541 | ||
542 | { | 542 | { |
543 | Config config("DateBook"); | 543 | Config config("DateBook"); |
544 | config.setGroup("Main"); | 544 | config.setGroup("Main"); |
545 | startTime = config.readNumEntry("startviewtime", 8); | 545 | startTime = config.readNumEntry("startviewtime", 8); |
546 | aPreset = config.readBoolEntry("alarmpreset"); | 546 | aPreset = config.readBoolEntry("alarmpreset"); |
547 | presetTime = config.readNumEntry("presettime"); | 547 | presetTime = config.readNumEntry("presettime"); |
548 | } | 548 | } |
549 | } | 549 | } |
550 | 550 | ||
551 | void DateBook::saveSettings() | 551 | void DateBook::saveSettings() |
552 | { | 552 | { |
553 | Config config( "qpe" ); | 553 | Config config( "qpe" ); |
554 | Config configDB( "DateBook" ); | 554 | Config configDB( "DateBook" ); |
555 | configDB.setGroup( "Main" ); | 555 | configDB.setGroup( "Main" ); |
556 | configDB.writeEntry("startviewtime",startTime); | 556 | configDB.writeEntry("startviewtime",startTime); |
557 | configDB.writeEntry("alarmpreset",aPreset); | 557 | configDB.writeEntry("alarmpreset",aPreset); |
558 | configDB.writeEntry("presettime",presetTime); | 558 | configDB.writeEntry("presettime",presetTime); |
559 | } | 559 | } |
560 | 560 | ||
561 | void DateBook::newDefaultView(QAction *a) { | 561 | void DateBook::newDefaultView(QAction *a) { |
562 | int val=DAY; | 562 | int val=DAY; |
563 | if (a->text() == "Day") val=DAY; | 563 | if (a->text() == "Day") val=DAY; |
564 | if (a->text() == "Week") val=WEEK; | 564 | if (a->text() == "Week") val=WEEK; |
565 | if (a->text() == "WeekLst") val=WEEKLST; | 565 | if (a->text() == "WeekLst") val=WEEKLST; |
566 | if (a->text() == "Month") val=MONTH; | 566 | if (a->text() == "Month") val=MONTH; |
567 | 567 | ||
568 | Config configDB( "DateBook" ); | 568 | Config configDB( "DateBook" ); |
569 | configDB.setGroup( "Main" ); | 569 | configDB.setGroup( "Main" ); |
570 | configDB.writeEntry("defaultview",val); | 570 | configDB.writeEntry("defaultview",val); |
571 | } | 571 | } |
572 | 572 | ||
573 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 573 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
574 | { | 574 | { |
575 | bool needShow = FALSE; | 575 | bool needShow = FALSE; |
576 | if ( msg == "alarm(QDateTime,int)" ) { | 576 | if ( msg == "alarm(QDateTime,int)" ) { |
577 | QDataStream ds(data,IO_ReadOnly); | 577 | QDataStream ds(data,IO_ReadOnly); |
578 | QDateTime when; int warn; | 578 | QDateTime when; int warn; |
579 | ds >> when >> warn; | 579 | ds >> when >> warn; |
580 | 580 | ||
581 | // check to make it's okay to continue, | 581 | // check to make it's okay to continue, |
582 | // this is the case that the time was set ahead, and | 582 | // this is the case that the time was set ahead, and |
583 | // we are forced given a stale alarm... | 583 | // we are forced given a stale alarm... |
584 | QDateTime current = QDateTime::currentDateTime(); | 584 | QDateTime current = QDateTime::currentDateTime(); |
585 | if ( current.time().hour() != when.time().hour() | 585 | if ( current.time().hour() != when.time().hour() |
586 | && current.time().minute() != when.time().minute() ) | 586 | && current.time().minute() != when.time().minute() ) |
587 | return; | 587 | return; |
588 | 588 | ||
589 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 589 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
590 | if ( list.count() > 0 ) { | 590 | if ( list.count() > 0 ) { |
591 | QString msg; | 591 | QString msg; |
592 | bool bSound = FALSE; | 592 | bool bSound = FALSE; |
593 | int stopTimer = 0; | 593 | int stopTimer = 0; |
594 | bool found = FALSE; | 594 | bool found = FALSE; |
595 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 595 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
596 | it!=list.end(); ++it ) { | 596 | it!=list.end(); ++it ) { |
597 | if ( (*it).event().hasAlarm() ) { | 597 | if ( (*it).event().hasAlarm() ) { |
598 | found = TRUE; | 598 | found = TRUE; |
599 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 599 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
600 | + "<BR>" + (*it).location() + "<BR>" | 600 | + "<BR>" + (*it).location() + "<BR>" |
601 | + TimeString::dateString((*it).event().start(),ampm) | 601 | + TimeString::dateString((*it).event().start(),ampm) |
602 | + (warn | 602 | + (warn |
603 | ? tr(" (in " + QString::number(warn) | 603 | ? tr(" (in " + QString::number(warn) |
604 | + tr(" minutes)")) | 604 | + tr(" minutes)")) |
605 | : QString("")) | 605 | : QString("")) |
606 | + "<BR>" | 606 | + "<BR>" |
607 | + (*it).notes() + "</CENTER>"; | 607 | + (*it).notes() + "</CENTER>"; |
608 | if ( (*it).event().alarmSound() != Event::Silent ) { | 608 | if ( (*it).event().alarmSound() != Event::Silent ) { |
609 | bSound = TRUE; | 609 | bSound = TRUE; |
610 | } | 610 | } |
611 | } | 611 | } |
612 | } | 612 | } |
613 | if ( found ) { | 613 | if ( found ) { |
614 | if ( bSound ) { | 614 | if ( bSound ) { |
615 | Sound::soundAlarm(); | 615 | Sound::soundAlarm(); |
616 | stopTimer = startTimer( 5000 ); | 616 | stopTimer = startTimer( 5000 ); |
617 | } | 617 | } |
618 | 618 | ||
619 | QDialog dlg( this, 0, TRUE ); | 619 | QDialog dlg( this, 0, TRUE ); |
620 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 620 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
621 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 621 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
622 | view->setResizePolicy( QScrollView::AutoOneFit ); | 622 | view->setResizePolicy( QScrollView::AutoOneFit ); |
623 | vb->addWidget( view ); | 623 | vb->addWidget( view ); |
624 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 624 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
625 | view->addChild( lblMsg ); | 625 | view->addChild( lblMsg ); |
626 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 626 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
627 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 627 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
628 | vb->addWidget( cmdOk ); | 628 | vb->addWidget( cmdOk ); |
629 | 629 | ||
630 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 630 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
631 | dlg.showMaximized(); | 631 | dlg.showMaximized(); |
632 | #endif | 632 | #endif |
633 | needShow = dlg.exec(); | 633 | needShow = dlg.exec(); |
634 | 634 | ||
635 | if ( bSound ) | 635 | if ( bSound ) |
636 | killTimer( stopTimer ); | 636 | killTimer( stopTimer ); |
637 | } | 637 | } |
638 | } | 638 | } |
639 | } else if ( msg == "nextView()" ) { | 639 | } else if ( msg == "nextView()" ) { |
640 | QWidget* cur = views->visibleWidget(); | 640 | QWidget* cur = views->visibleWidget(); |
641 | if ( cur ) { | 641 | if ( cur ) { |
642 | if ( cur == dayView ) | 642 | if ( cur == dayView ) |
643 | viewWeek(); | 643 | viewWeek(); |
644 | else if ( cur == weekView ) | 644 | else if ( cur == weekView ) |
645 | viewWeekLst(); | 645 | viewWeekLst(); |
646 | else if ( cur == weekLstView ) | 646 | else if ( cur == weekLstView ) |
647 | viewMonth(); | 647 | viewMonth(); |
648 | else if ( cur == monthView ) | 648 | else if ( cur == monthView ) |
649 | viewDay(); | 649 | viewDay(); |
650 | needShow = TRUE; | 650 | needShow = TRUE; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | if ( needShow ) { | 653 | if ( needShow ) { |
654 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 654 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
655 | showMaximized(); | 655 | showMaximized(); |
656 | #else | 656 | #else |
657 | show(); | 657 | show(); |
658 | #endif | 658 | #endif |
659 | raise(); | 659 | raise(); |
660 | QPEApplication::setKeepRunning(); | 660 | QPEApplication::setKeepRunning(); |
661 | setActiveWindow(); | 661 | setActiveWindow(); |
662 | } | 662 | } |
663 | } | 663 | } |
664 | 664 | ||
665 | void DateBook::reload() | 665 | void DateBook::reload() |
666 | { | 666 | { |
667 | db->reload(); | 667 | db->reload(); |
668 | if ( dayAction->isOn() ) | 668 | if ( dayAction->isOn() ) |
669 | viewDay(); | 669 | viewDay(); |
670 | else if ( weekAction->isOn() ) | 670 | else if ( weekAction->isOn() ) |
671 | viewWeek(); | 671 | viewWeek(); |
672 | else if ( monthAction->isOn() ) | 672 | else if ( monthAction->isOn() ) |
673 | viewMonth(); | 673 | viewMonth(); |
674 | syncing = FALSE; | 674 | syncing = FALSE; |
675 | } | 675 | } |
676 | 676 | ||
677 | void DateBook::flush() | 677 | void DateBook::flush() |
678 | { | 678 | { |
679 | syncing = TRUE; | 679 | syncing = TRUE; |
680 | db->save(); | 680 | db->save(); |
681 | } | 681 | } |
682 | 682 | ||
683 | void DateBook::timerEvent( QTimerEvent *e ) | 683 | void DateBook::timerEvent( QTimerEvent *e ) |
684 | { | 684 | { |
685 | static int stop = 0; | 685 | static int stop = 0; |
686 | if ( stop < 10 ) { | 686 | if ( stop < 10 ) { |
687 | Sound::soundAlarm(); | 687 | Sound::soundAlarm(); |
688 | stop++; | 688 | stop++; |
689 | } else { | 689 | } else { |
690 | stop = 0; | 690 | stop = 0; |
691 | killTimer( e->timerId() ); | 691 | killTimer( e->timerId() ); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | 694 | ||
695 | void DateBook::changeClock( bool newClock ) | 695 | void DateBook::changeClock( bool newClock ) |
696 | { | 696 | { |
697 | ampm = newClock; | 697 | ampm = newClock; |
698 | // repaint the affected objects... | 698 | // repaint the affected objects... |
699 | if (dayView) dayView->redraw(); | 699 | if (dayView) dayView->redraw(); |
700 | if (weekView) weekView->redraw(); | 700 | if (weekView) weekView->redraw(); |
701 | if (weekLstView) weekLstView->redraw(); | 701 | if (weekLstView) weekLstView->redraw(); |
702 | } | 702 | } |
703 | 703 | ||
704 | void DateBook::changeWeek( bool m ) | 704 | void DateBook::changeWeek( bool m ) |
705 | { | 705 | { |
706 | /* no need to redraw, each widget catches. Do need to | 706 | /* no need to redraw, each widget catches. Do need to |
707 | store though for widgets we haven't made yet */ | 707 | store though for widgets we haven't made yet */ |
708 | onMonday = m; | 708 | onMonday = m; |
709 | } | 709 | } |
710 | 710 | ||
711 | void DateBook::slotToday() | 711 | void DateBook::slotToday() |
712 | { | 712 | { |
713 | // we need to view today using default view | 713 | // we need to view today using default view |
714 | viewDefault(QDate::currentDate()); | 714 | viewDefault(QDate::currentDate()); |
715 | } | 715 | } |
716 | 716 | ||
717 | void DateBook::closeEvent( QCloseEvent *e ) | 717 | void DateBook::closeEvent( QCloseEvent *e ) |
718 | { | 718 | { |
719 | if(syncing) { | 719 | if(syncing) { |
720 | /* no need to save, did that at flush */ | 720 | /* no need to save, did that at flush */ |
721 | e->accept(); | 721 | e->accept(); |
722 | return; | 722 | return; |
723 | } | 723 | } |
724 | 724 | ||
725 | // save settings will generate it's own error messages, no | 725 | // save settings will generate it's own error messages, no |
726 | // need to do checking ourselves. | 726 | // need to do checking ourselves. |
727 | saveSettings(); | 727 | saveSettings(); |
728 | if ( db->save() ) | 728 | if ( db->save() ) |
729 | e->accept(); | 729 | e->accept(); |
730 | else { | 730 | else { |
731 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 731 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
732 | tr("Calendar was unable to save\n" | 732 | tr("Calendar was unable to save\n" |
733 | "your changes.\n" | 733 | "your changes.\n" |
734 | "Free up some space and try again.\n" | 734 | "Free up some space and try again.\n" |
735 | "\nQuit anyway?"), | 735 | "\nQuit anyway?"), |
736 | QMessageBox::Yes|QMessageBox::Escape, | 736 | QMessageBox::Yes|QMessageBox::Escape, |
737 | QMessageBox::No|QMessageBox::Default ) | 737 | QMessageBox::No|QMessageBox::Default ) |
738 | != QMessageBox::No ) | 738 | != QMessageBox::No ) |
739 | e->accept(); | 739 | e->accept(); |
740 | else | 740 | else |
741 | e->ignore(); | 741 | e->ignore(); |
742 | } | 742 | } |
743 | } | 743 | } |
744 | 744 | ||
745 | // Entering directly from the "keyboard" | 745 | // Entering directly from the "keyboard" |
746 | void DateBook::slotNewEventFromKey( const QString &str ) | 746 | void DateBook::slotNewEventFromKey( const QString &str ) |
747 | { | 747 | { |
748 | if (syncing) { | 748 | if (syncing) { |
749 | QMessageBox::warning( this, tr("Calendar"), | 749 | QMessageBox::warning( this, tr("Calendar"), |
750 | tr( "Can not edit data, currently syncing") ); | 750 | tr( "Can not edit data, currently syncing") ); |
751 | return; | 751 | return; |
752 | } | 752 | } |
753 | 753 | ||
754 | // We get to here from a key pressed in the Day View | 754 | // We get to here from a key pressed in the Day View |
755 | // So we can assume some things. We want the string | 755 | // So we can assume some things. We want the string |
756 | // passed in to be part of the description. | 756 | // passed in to be part of the description. |
757 | QDateTime start, end; | 757 | QDateTime start, end; |
758 | if ( views->visibleWidget() == dayView ) { | 758 | if ( views->visibleWidget() == dayView ) { |
759 | dayView->selectedDates( start, end ); | 759 | dayView->selectedDates( start, end ); |
760 | } else if ( views->visibleWidget() == monthView ) { | 760 | } else if ( views->visibleWidget() == monthView ) { |
761 | QDate d = monthView->selectedDate(); | 761 | QDate d = monthView->selectedDate(); |
762 | start = end = d; | 762 | start = end = d; |
763 | start.setTime( QTime( 10, 0 ) ); | 763 | start.setTime( QTime( 10, 0 ) ); |
764 | end.setTime( QTime( 12, 0 ) ); | 764 | end.setTime( QTime( 12, 0 ) ); |
765 | } else if ( views->visibleWidget() == weekView ) { | 765 | } else if ( views->visibleWidget() == weekView ) { |
766 | QDate d = weekView->date(); | 766 | QDate d = weekView->date(); |
767 | start = end = d; | 767 | start = end = d; |
768 | start.setTime( QTime( 10, 0 ) ); | 768 | start.setTime( QTime( 10, 0 ) ); |
769 | end.setTime( QTime( 12, 0 ) ); | 769 | end.setTime( QTime( 12, 0 ) ); |
770 | } | 770 | } |
771 | slotNewEntry(start, end, str); | 771 | slotNewEntry(start, end, str); |
772 | } | 772 | } |
773 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { | 773 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { |
774 | // argh! This really needs to be encapsulated in a class | 774 | // argh! This really needs to be encapsulated in a class |
775 | // or function. | 775 | // or function. |
776 | QDialog newDlg( this, 0, TRUE ); | 776 | QDialog newDlg( this, 0, TRUE ); |
777 | newDlg.setCaption( DateEntryBase::tr("New Event") ); | 777 | newDlg.setCaption( DateEntryBase::tr("New Event") ); |
778 | DateEntry *e; | 778 | DateEntry *e; |
779 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); | 779 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); |
780 | QScrollView *sv = new QScrollView( &newDlg ); | 780 | QScrollView *sv = new QScrollView( &newDlg ); |
781 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 781 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
782 | sv->setFrameStyle( QFrame::NoFrame ); | 782 | sv->setFrameStyle( QFrame::NoFrame ); |
783 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 783 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
784 | vb->addWidget( sv ); | 784 | vb->addWidget( sv ); |
785 | 785 | ||
786 | Event ev; | 786 | Event ev; |
787 | ev.setDescription( str ); | 787 | ev.setDescription( str ); |
788 | // When the new gui comes in, change this... | 788 | // When the new gui comes in, change this... |
789 | ev.setLocation( tr("(Unknown)") ); | 789 | ev.setLocation( tr("(Unknown)") ); |
790 | ev.setStart( start ); | 790 | ev.setStart( start ); |
791 | ev.setEnd( end ); | 791 | ev.setEnd( end ); |
792 | 792 | ||
793 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); | 793 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); |
794 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); | 794 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); |
795 | sv->addChild( e ); | 795 | sv->addChild( e ); |
796 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 796 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
797 | newDlg.showMaximized(); | 797 | newDlg.showMaximized(); |
798 | #endif | 798 | #endif |
799 | while (newDlg.exec()) { | 799 | while (newDlg.exec()) { |
800 | ev = e->event(); | 800 | ev = e->event(); |
801 | ev.assignUid(); | 801 | ev.assignUid(); |
802 | QString error = checkEvent( ev ); | 802 | QString error = checkEvent( ev ); |
803 | if ( !error.isNull() ) { | 803 | if ( !error.isNull() ) { |
804 | if ( QMessageBox::warning( this, tr("Error!"), | 804 | if ( QMessageBox::warning( this, tr("Error!"), |
805 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) | 805 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) |
806 | continue; | 806 | continue; |
807 | } | 807 | } |
808 | db->addEvent( ev ); | 808 | db->addEvent( ev ); |
809 | emit newEvent(); | 809 | emit newEvent(); |
810 | break; | 810 | break; |
811 | } | 811 | } |
812 | } | 812 | } |
813 | 813 | ||
814 | void DateBook::setDocument( const QString &filename ) | 814 | void DateBook::setDocument( const QString &filename ) |
815 | { | 815 | { |
816 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 816 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
817 | 817 | ||
818 | QValueList<Event> tl = Event::readVCalendar( filename ); | 818 | QValueList<Event> tl = Event::readVCalendar( filename ); |
819 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 819 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
820 | db->addEvent( *it ); | 820 | db->addEvent( *it ); |
821 | } | 821 | } |
822 | } | 822 | } |
823 | 823 | ||
824 | static const char * beamfile = "/tmp/obex/event.vcs"; | 824 | static const char * beamfile = "/tmp/obex/event.vcs"; |
825 | 825 | ||
826 | void DateBook::beamEvent( const Event &e ) | 826 | void DateBook::beamEvent( const Event &e ) |
827 | { | 827 | { |
828 | qDebug("trying to beamn"); | 828 | qDebug("trying to beamn"); |
829 | unlink( beamfile ); // delete if exists | 829 | unlink( beamfile ); // delete if exists |
830 | mkdir("/tmp/obex/", 0755); | 830 | mkdir("/tmp/obex/", 0755); |
831 | Event::writeVCalendar( beamfile, e ); | 831 | Event::writeVCalendar( beamfile, e ); |
832 | Ir *ir = new Ir( this ); | 832 | Ir *ir = new Ir( this ); |
833 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 833 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
834 | QString description = e.description(); | 834 | QString description = e.description(); |
835 | ir->send( beamfile, description, "text/x-vCalendar" ); | 835 | ir->send( beamfile, description, "text/x-vCalendar" ); |
836 | } | 836 | } |
837 | 837 | ||
838 | void DateBook::beamDone( Ir *ir ) | 838 | void DateBook::beamDone( Ir *ir ) |
839 | { | 839 | { |
840 | delete ir; | 840 | delete ir; |
841 | unlink( beamfile ); | 841 | unlink( beamfile ); |
842 | } | 842 | } |
843 | 843 | ||
844 | void DateBook::slotFind() | 844 | void DateBook::slotFind() |
845 | { | 845 | { |
846 | // move it to the day view... | 846 | // move it to the day view... |
847 | viewDay(); | 847 | viewDay(); |
848 | FindDialog frmFind( "Calendar", this ); | 848 | FindDialog frmFind( "Calendar", this ); |
849 | frmFind.setUseDate( true ); | 849 | frmFind.setUseDate( true ); |
850 | frmFind.setDate( currentDate() ); | 850 | frmFind.setDate( currentDate() ); |
851 | QObject::connect( &frmFind, | 851 | QObject::connect( &frmFind, |
852 | SIGNAL(signalFindClicked(const QString&, const QDate&, | 852 | SIGNAL(signalFindClicked(const QString&, const QDate&, |
853 | bool, bool, int)), | 853 | bool, bool, int)), |
854 | this, | 854 | this, |
855 | SLOT(slotDoFind(const QString&, const QDate&, | 855 | SLOT(slotDoFind(const QString&, const QDate&, |
856 | bool, bool, int)) ); | 856 | bool, bool, int)) ); |
857 | QObject::connect( this, | 857 | QObject::connect( this, |
858 | SIGNAL(signalNotFound()), | 858 | SIGNAL(signalNotFound()), |
859 | &frmFind, | 859 | &frmFind, |
860 | SLOT(slotNotFound()) ); | 860 | SLOT(slotNotFound()) ); |
861 | QObject::connect( this, | 861 | QObject::connect( this, |
862 | SIGNAL(signalWrapAround()), | 862 | SIGNAL(signalWrapAround()), |
863 | &frmFind, | 863 | &frmFind, |
864 | SLOT(slotWrapAround()) ); | 864 | SLOT(slotWrapAround()) ); |
865 | frmFind.exec(); | 865 | frmFind.exec(); |
866 | inSearch = false; | 866 | inSearch = false; |
867 | } | 867 | } |
868 | 868 | ||
869 | bool catComp( QArray<int> cats, int category ) | 869 | bool catComp( QArray<int> cats, int category ) |
870 | { | 870 | { |
871 | bool returnMe; | 871 | bool returnMe; |
872 | int i, | 872 | int i, |
873 | count; | 873 | count; |
874 | 874 | ||
875 | count = int(cats.count()); | 875 | count = int(cats.count()); |
876 | returnMe = false; | 876 | returnMe = false; |
877 | if ( (category == -1 && count == 0) || category == -2 ) | 877 | if ( (category == -1 && count == 0) || category == -2 ) |
878 | returnMe = true; | 878 | returnMe = true; |
879 | else { | 879 | else { |
880 | for ( i = 0; i < count; i++ ) { | 880 | for ( i = 0; i < count; i++ ) { |
881 | if ( category == cats[i] ) { | 881 | if ( category == cats[i] ) { |
882 | returnMe = true; | 882 | returnMe = true; |
883 | break; | 883 | break; |
884 | } | 884 | } |
885 | } | 885 | } |
886 | } | 886 | } |
887 | return returnMe; | 887 | return returnMe; |
888 | } | 888 | } |
889 | 889 | ||
890 | 890 | ||
891 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, | 891 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, |
892 | bool caseSensitive, bool /*backwards*/, | 892 | bool caseSensitive, bool /*backwards*/, |
893 | int category ) | 893 | int category ) |
894 | { | 894 | { |
895 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), | 895 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), |
896 | next; | 896 | next; |
897 | 897 | ||
898 | QRegExp r( txt ); | 898 | QRegExp r( txt ); |
899 | r.setCaseSensitive( caseSensitive ); | 899 | r.setCaseSensitive( caseSensitive ); |
900 | 900 | ||
901 | 901 | ||
902 | static Event rev, | 902 | static Event rev, |
903 | nonrev; | 903 | nonrev; |
904 | if ( !inSearch ) { | 904 | if ( !inSearch ) { |
905 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 905 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
906 | nonrev.setStart( rev.start() ); | 906 | nonrev.setStart( rev.start() ); |
907 | inSearch = true; | 907 | inSearch = true; |
908 | } | 908 | } |
909 | static QDate searchDate = dt; | 909 | static QDate searchDate = dt; |
910 | static bool wrapAround = true; | 910 | static bool wrapAround = true; |
911 | bool candidtate; | 911 | bool candidtate; |
912 | candidtate = false; | 912 | candidtate = false; |
913 | 913 | ||
914 | QValueList<Event> repeats = db->getRawRepeats(); | 914 | QValueList<Event> repeats = db->getRawRepeats(); |
915 | 915 | ||
916 | // find the candidate for the first repeat that matches... | 916 | // find the candidate for the first repeat that matches... |
917 | QValueListConstIterator<Event> it; | 917 | QValueListConstIterator<Event> it; |
918 | QDate start = dt; | 918 | QDate start = dt; |
919 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { | 919 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { |
920 | if ( catComp( (*it).categories(), category ) ) { | 920 | if ( catComp( (*it).categories(), category ) ) { |
921 | while ( nextOccurance( *it, start, next ) ) { | 921 | while ( nextOccurance( *it, start, next ) ) { |
922 | if ( next < dtEnd ) { | 922 | if ( next < dtEnd ) { |
923 | if ( (*it).match( r ) && !(next <= rev.start()) ) { | 923 | if ( (*it).match( r ) && !(next <= rev.start()) ) { |
924 | rev = *it; | 924 | rev = *it; |
925 | dtEnd = next; | 925 | dtEnd = next; |
926 | rev.setStart( next ); | 926 | rev.setStart( next ); |
927 | candidtate = true; | 927 | candidtate = true; |
928 | wrapAround = true; | 928 | wrapAround = true; |
929 | start = dt; | 929 | start = dt; |
930 | break; | 930 | break; |
931 | } else | 931 | } else |
932 | start = next.date().addDays( 1 ); | 932 | start = next.date().addDays( 1 ); |
933 | } | 933 | } |
934 | } | 934 | } |
935 | } | 935 | } |
936 | } | 936 | } |
937 | 937 | ||
938 | // now the for first non repeat... | 938 | // now the for first non repeat... |
939 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); | 939 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); |
940 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); | 940 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); |
941 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { | 941 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { |
942 | if ( catComp( (*it).categories(), category ) ) { | 942 | if ( catComp( (*it).categories(), category ) ) { |
943 | if ( (*it).start() < dtEnd ) { | 943 | if ( (*it).start() < dtEnd ) { |
944 | if ( (*it).match( r ) && !(*it <= nonrev) ) { | 944 | if ( (*it).match( r ) && !(*it <= nonrev) ) { |
945 | nonrev = *it; | 945 | nonrev = *it; |
946 | dtEnd = nonrev.start(); | 946 | dtEnd = nonrev.start(); |
947 | candidtate = true; | 947 | candidtate = true; |
948 | wrapAround = true; | 948 | wrapAround = true; |
949 | break; | 949 | break; |
950 | } | 950 | } |
951 | } | 951 | } |
952 | } | 952 | } |
953 | } | 953 | } |
954 | if ( candidtate ) { | 954 | if ( candidtate ) { |
955 | dayView->setStartViewTime( dtEnd.time().hour() ); | 955 | dayView->setStartViewTime( dtEnd.time().hour() ); |
956 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), | 956 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), |
957 | dtEnd.date().day() ); | 957 | dtEnd.date().day() ); |
958 | } else { | 958 | } else { |
959 | if ( wrapAround ) { | 959 | if ( wrapAround ) { |
960 | emit signalWrapAround(); | 960 | emit signalWrapAround(); |
961 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 961 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
962 | nonrev.setStart( rev.start() ); | 962 | nonrev.setStart( rev.start() ); |
963 | } else | 963 | } else |
964 | emit signalNotFound(); | 964 | emit signalNotFound(); |
965 | wrapAround = !wrapAround; | 965 | wrapAround = !wrapAround; |
966 | } | 966 | } |
967 | } | 967 | } |
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp index 1c43363..e563db0 100644 --- a/core/pim/datebook/dateentryimpl.cpp +++ b/core/pim/datebook/dateentryimpl.cpp | |||
@@ -1,509 +1,511 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "dateentryimpl.h" | 21 | #include "dateentryimpl.h" |
22 | #include "repeatentry.h" | 22 | #include "repeatentry.h" |
23 | 23 | ||
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/categoryselect.h> | 25 | #include <qpe/categoryselect.h> |
26 | #include <qpe/datebookmonth.h> | 26 | #include <qpe/datebookmonth.h> |
27 | #include <qpe/global.h> | 27 | #include <qpe/global.h> |
28 | #include <qpe/timeconversion.h> | 28 | #include <qpe/timeconversion.h> |
29 | #include <qpe/timestring.h> | 29 | #include <qpe/timestring.h> |
30 | #include <qpe/tzselect.h> | 30 | #include <qpe/tzselect.h> |
31 | 31 | ||
32 | #include <qcheckbox.h> | 32 | #include <qcheckbox.h> |
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qmultilineedit.h> | 36 | #include <qmultilineedit.h> |
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | #include <qscrollview.h> | 38 | #include <qscrollview.h> |
39 | #include <qspinbox.h> | 39 | #include <qspinbox.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | 41 | ||
42 | #include "timepicker.h" | 42 | #include "timepicker.h" |
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | 45 | ||
46 | #include <stdiostream.h> | 46 | #include <stdiostream.h> |
47 | 47 | ||
48 | /* | 48 | /* |
49 | * Constructs a DateEntry which is a child of 'parent', with the | 49 | * Constructs a DateEntry which is a child of 'parent', with the |
50 | * name 'name' and widget flags set to 'f' | 50 | * name 'name' and widget flags set to 'f' |
51 | * | 51 | * |
52 | * The dialog will by default be modeless, unless you set 'modal' to | 52 | * The dialog will by default be modeless, unless you set 'modal' to |
53 | * TRUE to construct a modal dialog. | 53 | * TRUE to construct a modal dialog. |
54 | */ | 54 | */ |
55 | 55 | ||
56 | DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, | 56 | DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, |
57 | const QDateTime &end, bool whichClock, QWidget* parent, | 57 | const QDateTime &end, bool whichClock, QWidget* parent, |
58 | const char* name ) | 58 | const char* name ) |
59 | : DateEntryBase( parent, name ), | 59 | : DateEntryBase( parent, name ), |
60 | ampm( whichClock ), | 60 | ampm( whichClock ), |
61 | startWeekOnMonday( startOnMonday ) | 61 | startWeekOnMonday( startOnMonday ) |
62 | { | 62 | { |
63 | init(); | 63 | init(); |
64 | setDates(start,end); | 64 | setDates(start,end); |
65 | setFocusProxy(comboDescription); | 65 | setFocusProxy(comboDescription); |
66 | } | 66 | } |
67 | 67 | ||
68 | static void addOrPick( QComboBox* combo, const QString& t ) | 68 | static void addOrPick( QComboBox* combo, const QString& t ) |
69 | { | 69 | { |
70 | // Pick an item if one excists | 70 | // Pick an item if one excists |
71 | for (int i=0; i<combo->count(); i++) { | 71 | for (int i=0; i<combo->count(); i++) { |
72 | if ( combo->text(i) == t ) { | 72 | if ( combo->text(i) == t ) { |
73 | combo->setCurrentItem(i); | 73 | combo->setCurrentItem(i); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | // Else add one | 78 | // Else add one |
79 | combo->insertItem(t); | 79 | combo->insertItem(t); |
80 | combo->setCurrentItem(combo->count()-1); | 80 | combo->setCurrentItem(combo->count()-1); |
81 | } | 81 | } |
82 | 82 | ||
83 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, | 83 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, |
84 | QWidget* parent, const char* name ) | 84 | QWidget* parent, const char* name ) |
85 | : DateEntryBase( parent, name ), | 85 | : DateEntryBase( parent, name ), |
86 | ampm( whichClock ), | 86 | ampm( whichClock ), |
87 | startWeekOnMonday( startOnMonday ) | 87 | startWeekOnMonday( startOnMonday ) |
88 | { | 88 | { |
89 | init(); | 89 | init(); |
90 | setDates(event.start(),event.end()); | 90 | setDates(event.start(),event.end()); |
91 | comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); | 91 | comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); |
92 | if(!event.description().isEmpty()) | 92 | if(!event.description().isEmpty()) |
93 | addOrPick( comboDescription, event.description() ); | 93 | addOrPick( comboDescription, event.description() ); |
94 | if(!event.location().isEmpty()) | 94 | if(!event.location().isEmpty()) |
95 | addOrPick( comboLocation, event.location() ); | 95 | addOrPick( comboLocation, event.location() ); |
96 | checkAlarm->setChecked( event.hasAlarm() ); | 96 | checkAlarm->setChecked( event.hasAlarm() ); |
97 | checkAllDay->setChecked( event.type() == Event::AllDay ); | 97 | checkAllDay->setChecked( event.type() == Event::AllDay ); |
98 | if(!event.notes().isEmpty()) | 98 | if(!event.notes().isEmpty()) |
99 | editNote->setText(event.notes()); | 99 | editNote->setText(event.notes()); |
100 | spinAlarm->setValue(event.alarmTime()); | 100 | spinAlarm->setValue(event.alarmTime()); |
101 | if ( event.alarmSound() != Event::Silent ) | 101 | if ( event.alarmSound() != Event::Silent ) |
102 | comboSound->setCurrentItem( 1 ); | 102 | comboSound->setCurrentItem( 1 ); |
103 | if ( event.hasRepeat() ) { | 103 | if ( event.hasRepeat() ) { |
104 | rp = event.repeatPattern(); | 104 | rp = event.repeatPattern(); |
105 | cmdRepeat->setText( tr("Repeat...") ); | 105 | cmdRepeat->setText( tr("Repeat...") ); |
106 | } | 106 | } |
107 | setRepeatLabel(); | 107 | setRepeatLabel(); |
108 | } | 108 | } |
109 | 109 | ||
110 | void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) | 110 | void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) |
111 | { | 111 | { |
112 | startDate = s.date(); | 112 | startDate = s.date(); |
113 | endDate = e.date(); | 113 | endDate = e.date(); |
114 | startTime = s.time(); | 114 | startTime = s.time(); |
115 | endTime = e.time(); | 115 | endTime = e.time(); |
116 | |||
116 | startDateChanged( s.date().year(), s.date().month(), s.date().day() ); | 117 | startDateChanged( s.date().year(), s.date().month(), s.date().day() ); |
117 | endDateChanged( e.date().year(), e.date().month(), e.date().day() ); | 118 | endDateChanged( e.date().year(), e.date().month(), e.date().day() ); |
119 | |||
118 | updateTimeEdit(true,true); | 120 | updateTimeEdit(true,true); |
119 | } | 121 | } |
120 | 122 | ||
121 | void DateEntry::updateTimeEdit(bool s, bool e) { | 123 | void DateEntry::updateTimeEdit(bool s, bool e) { |
122 | 124 | ||
123 | // Comboboxes | 125 | // Comboboxes |
124 | QString strStart, strEnd; | 126 | QString strStart, strEnd; |
125 | int shour, ehour; | 127 | int shour, ehour; |
126 | if ( ampm ) { | 128 | if ( ampm ) { |
127 | shour = startTime.hour(); | 129 | shour = startTime.hour(); |
128 | ehour = endTime.hour(); | 130 | ehour = endTime.hour(); |
129 | if ( shour >= 12 ) { | 131 | if ( shour >= 12 ) { |
130 | if ( shour > 12 ) | 132 | if ( shour > 12 ) |
131 | shour -= 12; | 133 | shour -= 12; |
132 | strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); | 134 | strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); |
133 | } else { | 135 | } else { |
134 | if ( shour == 0 ) | 136 | if ( shour == 0 ) |
135 | shour = 12; | 137 | shour = 12; |
136 | strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); | 138 | strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); |
137 | } | 139 | } |
138 | if ( ehour == 24 && endTime.minute() == 0 ) { | 140 | if ( ehour == 24 && endTime.minute() == 0 ) { |
139 | strEnd = "11:59 PM"; // or "midnight" | 141 | strEnd = "11:59 PM"; // or "midnight" |
140 | } else if ( ehour >= 12 ) { | 142 | } else if ( ehour >= 12 ) { |
141 | if ( ehour > 12 ) | 143 | if ( ehour > 12 ) |
142 | ehour -= 12; | 144 | ehour -= 12; |
143 | strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); | 145 | strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); |
144 | } else { | 146 | } else { |
145 | if ( ehour == 0 ) | 147 | if ( ehour == 0 ) |
146 | ehour = 12; | 148 | ehour = 12; |
147 | strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); | 149 | strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); |
148 | } | 150 | } |
149 | } else { | 151 | } else { |
150 | strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); | 152 | strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); |
151 | strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); | 153 | strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); |
152 | } | 154 | } |
153 | 155 | ||
154 | if (s) comboStart->setText(strStart); | 156 | if (s) comboStart->setText(strStart); |
155 | if (e) comboEnd->setText(strEnd); | 157 | if (e) comboEnd->setText(strEnd); |
156 | } | 158 | } |
157 | 159 | ||
158 | void DateEntry::init() | 160 | void DateEntry::init() |
159 | { | 161 | { |
160 | comboDescription->setInsertionPolicy(QComboBox::AtCurrent); | 162 | comboDescription->setInsertionPolicy(QComboBox::AtCurrent); |
161 | comboLocation->setInsertionPolicy(QComboBox::AtCurrent); | 163 | comboLocation->setInsertionPolicy(QComboBox::AtCurrent); |
162 | 164 | ||
163 | initCombos(); | 165 | initCombos(); |
164 | QPopupMenu *m1 = new QPopupMenu( this ); | 166 | QPopupMenu *m1 = new QPopupMenu( this ); |
165 | startPicker = new DateBookMonth( m1, 0, TRUE ); | 167 | startPicker = new DateBookMonth( m1, 0, TRUE ); |
166 | m1->insertItem( startPicker ); | 168 | m1->insertItem( startPicker ); |
167 | buttonStart->setPopup( m1 ); | 169 | buttonStart->setPopup( m1 ); |
168 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), | 170 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), |
169 | this, SLOT( startDateChanged( int, int, int ) ) ); | 171 | this, SLOT( startDateChanged( int, int, int ) ) ); |
170 | 172 | ||
171 | //Let start button change both start and end dates | 173 | //Let start button change both start and end dates |
172 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), | 174 | connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), |
173 | this, SLOT( endDateChanged( int, int, int ) ) ); | 175 | this, SLOT( endDateChanged( int, int, int ) ) ); |
174 | connect( qApp, SIGNAL( clockChanged( bool ) ), | 176 | connect( qApp, SIGNAL( clockChanged( bool ) ), |
175 | this, SLOT( slotChangeClock( bool ) ) ); | 177 | this, SLOT( slotChangeClock( bool ) ) ); |
176 | connect( qApp, SIGNAL(weekChanged(bool)), | 178 | connect( qApp, SIGNAL(weekChanged(bool)), |
177 | this, SLOT(slotChangeStartOfWeek(bool)) ); | 179 | this, SLOT(slotChangeStartOfWeek(bool)) ); |
178 | 180 | ||
179 | QPopupMenu *m2 = new QPopupMenu( this ); | 181 | QPopupMenu *m2 = new QPopupMenu( this ); |
180 | endPicker = new DateBookMonth( m2, 0, TRUE ); | 182 | endPicker = new DateBookMonth( m2, 0, TRUE ); |
181 | m2->insertItem( endPicker ); | 183 | m2->insertItem( endPicker ); |
182 | buttonEnd->setPopup( m2 ); | 184 | buttonEnd->setPopup( m2 ); |
183 | connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), | 185 | connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), |
184 | this, SLOT( endDateChanged( int, int, int ) ) ); | 186 | this, SLOT( endDateChanged( int, int, int ) ) ); |
185 | 187 | ||
186 | connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), | 188 | connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), |
187 | this, SLOT( startTimePicked(const QTime &) )); | 189 | this, SLOT( startTimePicked(const QTime &) )); |
188 | editNote->setFixedVisibleLines(3); | 190 | editNote->setFixedVisibleLines(3); |
189 | } | 191 | } |
190 | 192 | ||
191 | /* | 193 | /* |
192 | * Destroys the object and frees any allocated resources | 194 | * Destroys the object and frees any allocated resources |
193 | */ | 195 | */ |
194 | DateEntry::~DateEntry() | 196 | DateEntry::~DateEntry() |
195 | { | 197 | { |
196 | // no need to delete child widgets, Qt does it all for us | 198 | // no need to delete child widgets, Qt does it all for us |
197 | //cout << "Del: " << comboStart->currentText() << endl; | 199 | //cout << "Del: " << comboStart->currentText() << endl; |
198 | } | 200 | } |
199 | 201 | ||
200 | /* | 202 | /* |
201 | * public slot | 203 | * public slot |
202 | */ | 204 | */ |
203 | void DateEntry::endDateChanged( int y, int m, int d ) | 205 | void DateEntry::endDateChanged( int y, int m, int d ) |
204 | { | 206 | { |
205 | endDate.setYMD( y, m, d ); | 207 | endDate.setYMD( y, m, d ); |
206 | if ( endDate < startDate ) { | 208 | if ( endDate < startDate ) { |
207 | endDate = startDate; | 209 | endDate = startDate; |
208 | } | 210 | } |
209 | 211 | ||
210 | buttonEnd->setText( TimeString::shortDate( endDate ) ); | 212 | buttonEnd->setText( TimeString::shortDate( endDate ) ); |
211 | 213 | ||
212 | endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); | 214 | endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); |
213 | } | 215 | } |
214 | 216 | ||
215 | static QTime parseTime( const QString& s, bool ampm ) | 217 | static QTime parseTime( const QString& s, bool ampm ) |
216 | { | 218 | { |
217 | QTime tmpTime; | 219 | QTime tmpTime; |
218 | QStringList l = QStringList::split( ':', s ); | 220 | QStringList l = QStringList::split( ':', s ); |
219 | int hour = l[0].toInt(); | 221 | int hour = l[0].toInt(); |
220 | if ( ampm ) { | 222 | if ( ampm ) { |
221 | int i=0; | 223 | int i=0; |
222 | while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') | 224 | while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') |
223 | i++; | 225 | i++; |
224 | QString digits = l[1].left(i); | 226 | QString digits = l[1].left(i); |
225 | if ( l[1].contains( "PM", FALSE ) ) { | 227 | if ( l[1].contains( "PM", FALSE ) ) { |
226 | if ( hour != 12 ) | 228 | if ( hour != 12 ) |
227 | hour += 12; | 229 | hour += 12; |
228 | } else { | 230 | } else { |
229 | if ( hour == 12 ) | 231 | if ( hour == 12 ) |
230 | hour = 0; | 232 | hour = 0; |
231 | } | 233 | } |
232 | l[1] = digits; | 234 | l[1] = digits; |
233 | } | 235 | } |
234 | int minute = l[1].toInt(); | 236 | int minute = l[1].toInt(); |
235 | if ( minute > 59 ) | 237 | if ( minute > 59 ) |
236 | minute = 59; | 238 | minute = 59; |
237 | else if ( minute < 0 ) | 239 | else if ( minute < 0 ) |
238 | minute = 0; | 240 | minute = 0; |
239 | if ( hour > 23 ) { | 241 | if ( hour > 23 ) { |
240 | hour = 23; | 242 | hour = 23; |
241 | minute = 59; | 243 | minute = 59; |
242 | } else if ( hour < 0 ) | 244 | } else if ( hour < 0 ) |
243 | hour = 0; | 245 | hour = 0; |
244 | tmpTime.setHMS( hour, minute, 0 ); | 246 | tmpTime.setHMS( hour, minute, 0 ); |
245 | return tmpTime; | 247 | return tmpTime; |
246 | } | 248 | } |
247 | 249 | ||
248 | /* | 250 | /* |
249 | * public slot | 251 | * public slot |
250 | */ | 252 | */ |
251 | void DateEntry::endTimeChanged( const QString &s ) | 253 | void DateEntry::endTimeChanged( const QString &s ) |
252 | { | 254 | { |
253 | QTime tmpTime = parseTime(s,ampm); | 255 | QTime tmpTime = parseTime(s,ampm); |
254 | if ( endDate > startDate || tmpTime >= startTime ) { | 256 | if ( endDate > startDate || tmpTime >= startTime ) { |
255 | endTime = tmpTime; | 257 | endTime = tmpTime; |
256 | } else { | 258 | } else { |
257 | endTime = startTime; | 259 | endTime = startTime; |
258 | //comboEnd->setCurrentItem( comboStart->currentItem() ); | 260 | //comboEnd->setCurrentItem( comboStart->currentItem() ); |
259 | } | 261 | } |
260 | 262 | ||
261 | } | 263 | } |
262 | 264 | ||
263 | void DateEntry::endTimeChanged( const QTime &t ) { | 265 | void DateEntry::endTimeChanged( const QTime &t ) { |
264 | } | 266 | } |
265 | 267 | ||
266 | /* | 268 | /* |
267 | * public slot | 269 | * public slot |
268 | */ | 270 | */ |
269 | void DateEntry::startDateChanged( int y, int m, int d ) | 271 | void DateEntry::startDateChanged( int y, int m, int d ) |
270 | { | 272 | { |
271 | QDate prev = startDate; | 273 | QDate prev = startDate; |
272 | startDate.setYMD( y, m, d ); | 274 | startDate.setYMD( y, m, d ); |
273 | if ( rp.type == Event::Weekly && | 275 | if ( rp.type == Event::Weekly && |
274 | startDate.dayOfWeek() != prev.dayOfWeek() ) { | 276 | startDate.dayOfWeek() != prev.dayOfWeek() ) { |
275 | // if we change the start of a weekly repeating event | 277 | // if we change the start of a weekly repeating event |
276 | // set the repeating day appropriately | 278 | // set the repeating day appropriately |
277 | char mask = 1 << (prev.dayOfWeek()-1); | 279 | char mask = 1 << (prev.dayOfWeek()-1); |
278 | rp.days &= (~mask); | 280 | rp.days &= (~mask); |
279 | rp.days |= 1 << (startDate.dayOfWeek()-1); | 281 | rp.days |= 1 << (startDate.dayOfWeek()-1); |
280 | } | 282 | } |
281 | 283 | ||
282 | buttonStart->setText( TimeString::shortDate( startDate ) ); | 284 | buttonStart->setText( TimeString::shortDate( startDate ) ); |
283 | 285 | ||
284 | // our pickers must be reset... | 286 | // our pickers must be reset... |
285 | startPicker->setDate( y, m, d ); | 287 | startPicker->setDate( y, m, d ); |
286 | endPicker->setDate( y, m, d ); | 288 | endPicker->setDate( y, m, d ); |
287 | } | 289 | } |
288 | 290 | ||
289 | /* | 291 | /* |
290 | * public slot | 292 | * public slot |
291 | */ | 293 | */ |
292 | void DateEntry::startTimeEdited( const QString &s ) | 294 | void DateEntry::startTimeEdited( const QString &s ) |
293 | { | 295 | { |
294 | startTimeChanged(parseTime(s,ampm)); | 296 | startTimeChanged(parseTime(s,ampm)); |
295 | updateTimeEdit(false,true); | 297 | updateTimeEdit(false,true); |
296 | timePickerStart->setHour(startTime.hour()); | 298 | timePickerStart->setHour(startTime.hour()); |
297 | timePickerStart->setMinute(startTime.minute()); | 299 | timePickerStart->setMinute(startTime.minute()); |
298 | } | 300 | } |
299 | 301 | ||
300 | void DateEntry::startTimeChanged( const QTime &t ) | 302 | void DateEntry::startTimeChanged( const QTime &t ) |
301 | { | 303 | { |
302 | int duration=startTime.secsTo(endTime); | 304 | int duration=startTime.secsTo(endTime); |
303 | startTime = t; | 305 | startTime = t; |
304 | endTime=t.addSecs(duration); | 306 | endTime=t.addSecs(duration); |
305 | } | 307 | } |
306 | void DateEntry::startTimePicked( const QTime &t ) { | 308 | void DateEntry::startTimePicked( const QTime &t ) { |
307 | startTimeChanged(t); | 309 | startTimeChanged(t); |
308 | updateTimeEdit(true,true); | 310 | updateTimeEdit(true,true); |
309 | } | 311 | } |
310 | 312 | ||
311 | /* | 313 | /* |
312 | * public slot | 314 | * public slot |
313 | */ | 315 | */ |
314 | void DateEntry::typeChanged( const QString &s ) | 316 | void DateEntry::typeChanged( const QString &s ) |
315 | { | 317 | { |
316 | bool b = s != "All Day"; | 318 | bool b = s != "All Day"; |
317 | buttonStart->setEnabled( b ); | 319 | buttonStart->setEnabled( b ); |
318 | comboStart->setEnabled( b ); | 320 | comboStart->setEnabled( b ); |
319 | comboEnd->setEnabled( b ); | 321 | comboEnd->setEnabled( b ); |
320 | } | 322 | } |
321 | 323 | ||
322 | void DateEntry::slotRepeat() | 324 | void DateEntry::slotRepeat() |
323 | { | 325 | { |
324 | // Work around for compiler Bug.. | 326 | // Work around for compiler Bug.. |
325 | RepeatEntry *e; | 327 | RepeatEntry *e; |
326 | 328 | ||
327 | // it is better in my opinion to just grab this from the mother, | 329 | // it is better in my opinion to just grab this from the mother, |
328 | // since, this dialog doesn't need to keep track of it... | 330 | // since, this dialog doesn't need to keep track of it... |
329 | if ( rp.type != Event::NoRepeat ) | 331 | if ( rp.type != Event::NoRepeat ) |
330 | e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); | 332 | e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); |
331 | else | 333 | else |
332 | e = new RepeatEntry( startWeekOnMonday, startDate, this ); | 334 | e = new RepeatEntry( startWeekOnMonday, startDate, this ); |
333 | 335 | ||
334 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 336 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
335 | e->showMaximized(); | 337 | e->showMaximized(); |
336 | #endif | 338 | #endif |
337 | if ( e->exec() ) { | 339 | if ( e->exec() ) { |
338 | rp = e->repeatPattern(); | 340 | rp = e->repeatPattern(); |
339 | setRepeatLabel(); | 341 | setRepeatLabel(); |
340 | } | 342 | } |
341 | } | 343 | } |
342 | 344 | ||
343 | void DateEntry::slotChangeStartOfWeek( bool onMonday ) | 345 | void DateEntry::slotChangeStartOfWeek( bool onMonday ) |
344 | { | 346 | { |
345 | startWeekOnMonday = onMonday; | 347 | startWeekOnMonday = onMonday; |
346 | } | 348 | } |
347 | 349 | ||
348 | Event DateEntry::event() | 350 | Event DateEntry::event() |
349 | { | 351 | { |
350 | Event ev; | 352 | Event ev; |
351 | Event::SoundTypeChoice st; | 353 | Event::SoundTypeChoice st; |
352 | ev.setDescription( comboDescription->currentText() ); | 354 | ev.setDescription( comboDescription->currentText() ); |
353 | ev.setLocation( comboLocation->currentText() ); | 355 | ev.setLocation( comboLocation->currentText() ); |
354 | ev.setCategories( comboCategory->currentCategories() ); | 356 | ev.setCategories( comboCategory->currentCategories() ); |
355 | ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); | 357 | ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); |
356 | if ( startDate > endDate ) { | 358 | if ( startDate > endDate ) { |
357 | QDate tmp = endDate; | 359 | QDate tmp = endDate; |
358 | endDate = startDate; | 360 | endDate = startDate; |
359 | startDate = tmp; | 361 | startDate = tmp; |
360 | } | 362 | } |
361 | 363 | ||
362 | // This is now done in the changed slots | 364 | // This is now done in the changed slots |
363 | // startTime = parseTime( comboStart->text(), ampm ); | 365 | // startTime = parseTime( comboStart->text(), ampm ); |
364 | //endTime = parseTime( comboEnd->text(), ampm ); | 366 | //endTime = parseTime( comboEnd->text(), ampm ); |
365 | 367 | ||
366 | if ( startTime > endTime && endDate == startDate ) { | 368 | if ( startTime > endTime && endDate == startDate ) { |
367 | QTime tmp = endTime; | 369 | QTime tmp = endTime; |
368 | endTime = startTime; | 370 | endTime = startTime; |
369 | startTime = tmp; | 371 | startTime = tmp; |
370 | } | 372 | } |
371 | // don't set the time if theres no need too | 373 | // don't set the time if theres no need too |
372 | if ( ev.type() == Event::AllDay ) { | 374 | if ( ev.type() == Event::AllDay ) { |
373 | startTime.setHMS( 0, 0, 0 ); | 375 | startTime.setHMS( 0, 0, 0 ); |
374 | endTime.setHMS( 23, 59, 59 ); | 376 | endTime.setHMS( 23, 59, 59 ); |
375 | } | 377 | } |
376 | 378 | ||
377 | // adjust start and end times based on timezone | 379 | // adjust start and end times based on timezone |
378 | QDateTime start( startDate, startTime ); | 380 | QDateTime start( startDate, startTime ); |
379 | QDateTime end( endDate, endTime ); | 381 | QDateTime end( endDate, endTime ); |
380 | time_t start_utc, end_utc; | 382 | time_t start_utc, end_utc; |
381 | 383 | ||
382 | // qDebug( "tz: %s", timezone->currentZone().latin1() ); | 384 | // qDebug( "tz: %s", timezone->currentZone().latin1() ); |
383 | 385 | ||
384 | // get real timezone | 386 | // get real timezone |
385 | QString realTZ; | 387 | QString realTZ; |
386 | realTZ = QString::fromLocal8Bit( getenv("TZ") ); | 388 | realTZ = QString::fromLocal8Bit( getenv("TZ") ); |
387 | 389 | ||
388 | // set timezone | 390 | // set timezone |
389 | if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) | 391 | if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) |
390 | qWarning( "There was a problem setting the timezone." ); | 392 | qWarning( "There was a problem setting the timezone." ); |
391 | 393 | ||
392 | // convert to UTC based on selected TZ (calling tzset internally) | 394 | // convert to UTC based on selected TZ (calling tzset internally) |
393 | start_utc = TimeConversion::toUTC( start ); | 395 | start_utc = TimeConversion::toUTC( start ); |
394 | end_utc = TimeConversion::toUTC( end ); | 396 | end_utc = TimeConversion::toUTC( end ); |
395 | 397 | ||
396 | // done playing around... put it all back | 398 | // done playing around... put it all back |
397 | unsetenv( "TZ" ); | 399 | unsetenv( "TZ" ); |
398 | if ( !realTZ.isNull() ) | 400 | if ( !realTZ.isNull() ) |
399 | if ( setenv( "TZ", realTZ, true ) != 0 ) | 401 | if ( setenv( "TZ", realTZ, true ) != 0 ) |
400 | qWarning( "There was a problem setting the timezone." ); | 402 | qWarning( "There was a problem setting the timezone." ); |
401 | 403 | ||
402 | // convert UTC to local time (calling tzset internally) | 404 | // convert UTC to local time (calling tzset internally) |
403 | ev.setStart( TimeConversion::fromUTC( start_utc ) ); | 405 | ev.setStart( TimeConversion::fromUTC( start_utc ) ); |
404 | ev.setEnd( TimeConversion::fromUTC( end_utc ) ); | 406 | ev.setEnd( TimeConversion::fromUTC( end_utc ) ); |
405 | 407 | ||
406 | // we only have one type of sound at the moment... LOUD!!! | 408 | // we only have one type of sound at the moment... LOUD!!! |
407 | if ( comboSound->currentItem() != 0 ) | 409 | if ( comboSound->currentItem() != 0 ) |
408 | st = Event::Loud; | 410 | st = Event::Loud; |
409 | else | 411 | else |
410 | st = Event::Silent; | 412 | st = Event::Silent; |
411 | ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); | 413 | ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); |
412 | if ( rp.type != Event::NoRepeat ) | 414 | if ( rp.type != Event::NoRepeat ) |
413 | ev.setRepeat( TRUE, rp ); | 415 | ev.setRepeat( TRUE, rp ); |
414 | ev.setNotes( editNote->text() ); | 416 | ev.setNotes( editNote->text() ); |
415 | 417 | ||
416 | //cout << "Start: " << comboStart->currentText() << endl; | 418 | //cout << "Start: " << comboStart->currentText() << endl; |
417 | 419 | ||
418 | return ev; | 420 | return ev; |
419 | } | 421 | } |
420 | 422 | ||
421 | void DateEntry::setRepeatLabel() | 423 | void DateEntry::setRepeatLabel() |
422 | { | 424 | { |
423 | 425 | ||
424 | switch( rp.type ) { | 426 | switch( rp.type ) { |
425 | case Event::Daily: | 427 | case Event::Daily: |
426 | cmdRepeat->setText( tr("Daily...") ); | 428 | cmdRepeat->setText( tr("Daily...") ); |
427 | break; | 429 | break; |
428 | case Event::Weekly: | 430 | case Event::Weekly: |
429 | cmdRepeat->setText( tr("Weekly...") ); | 431 | cmdRepeat->setText( tr("Weekly...") ); |
430 | break; | 432 | break; |
431 | case Event::MonthlyDay: | 433 | case Event::MonthlyDay: |
432 | case Event::MonthlyDate: | 434 | case Event::MonthlyDate: |
433 | cmdRepeat->setText( tr("Monthly...") ); | 435 | cmdRepeat->setText( tr("Monthly...") ); |
434 | break; | 436 | break; |
435 | case Event::Yearly: | 437 | case Event::Yearly: |
436 | cmdRepeat->setText( tr("Yearly...") ); | 438 | cmdRepeat->setText( tr("Yearly...") ); |
437 | break; | 439 | break; |
438 | default: | 440 | default: |
439 | cmdRepeat->setText( tr("No Repeat...") ); | 441 | cmdRepeat->setText( tr("No Repeat...") ); |
440 | } | 442 | } |
441 | } | 443 | } |
442 | 444 | ||
443 | void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) | 445 | void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) |
444 | { | 446 | { |
445 | checkAlarm->setChecked( alarmPreset ); | 447 | checkAlarm->setChecked( alarmPreset ); |
446 | spinAlarm->setValue( presetTime ); | 448 | spinAlarm->setValue( presetTime ); |
447 | if ( sound != Event::Silent ) | 449 | if ( sound != Event::Silent ) |
448 | comboSound->setCurrentItem( 1 ); | 450 | comboSound->setCurrentItem( 1 ); |
449 | else | 451 | else |
450 | comboSound->setCurrentItem( 0 ); | 452 | comboSound->setCurrentItem( 0 ); |
451 | } | 453 | } |
452 | 454 | ||
453 | void DateEntry::initCombos() | 455 | void DateEntry::initCombos() |
454 | { | 456 | { |
455 | /* | 457 | /* |
456 | comboStart->clear(); | 458 | comboStart->clear(); |
457 | comboEnd->clear(); | 459 | comboEnd->clear(); |
458 | if ( ampm ) { | 460 | if ( ampm ) { |
459 | for ( int i = 0; i < 24; i++ ) { | 461 | for ( int i = 0; i < 24; i++ ) { |
460 | if ( i == 0 ) { | 462 | if ( i == 0 ) { |
461 | comboStart->insertItem( "12:00 AM" ); | 463 | comboStart->insertItem( "12:00 AM" ); |
462 | comboStart->insertItem( "12:30 AM" ); | 464 | comboStart->insertItem( "12:30 AM" ); |
463 | comboEnd->insertItem( "12:00 AM" ); | 465 | comboEnd->insertItem( "12:00 AM" ); |
464 | comboEnd->insertItem( "12:30 AM" ); | 466 | comboEnd->insertItem( "12:30 AM" ); |
465 | } else if ( i == 12 ) { | 467 | } else if ( i == 12 ) { |
466 | comboStart->insertItem( "12:00 PM" ); | 468 | comboStart->insertItem( "12:00 PM" ); |
467 | comboStart->insertItem( "12:30 PM" ); | 469 | comboStart->insertItem( "12:30 PM" ); |
468 | comboEnd->insertItem( "12:00 PM" ); | 470 | comboEnd->insertItem( "12:00 PM" ); |
469 | comboEnd->insertItem( "12:30 PM" ); | 471 | comboEnd->insertItem( "12:30 PM" ); |
470 | } else if ( i > 12 ) { | 472 | } else if ( i > 12 ) { |
471 | comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); | 473 | comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); |
472 | comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); | 474 | comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); |
473 | comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); | 475 | comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); |
474 | comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); | 476 | comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); |
475 | } else { | 477 | } else { |
476 | comboStart->insertItem( QString::number( i) + ":00 AM" ); | 478 | comboStart->insertItem( QString::number( i) + ":00 AM" ); |
477 | comboStart->insertItem( QString::number( i ) + ":30 AM" ); | 479 | comboStart->insertItem( QString::number( i ) + ":30 AM" ); |
478 | comboEnd->insertItem( QString::number( i ) + ":00 AM" ); | 480 | comboEnd->insertItem( QString::number( i ) + ":00 AM" ); |
479 | comboEnd->insertItem( QString::number( i ) + ":30 AM" ); | 481 | comboEnd->insertItem( QString::number( i ) + ":30 AM" ); |
480 | } | 482 | } |
481 | } | 483 | } |
482 | } else { | 484 | } else { |
483 | for ( int i = 0; i < 24; i++ ) { | 485 | for ( int i = 0; i < 24; i++ ) { |
484 | if ( i < 10 ) { | 486 | if ( i < 10 ) { |
485 | comboStart->insertItem( QString("0") | 487 | comboStart->insertItem( QString("0") |
486 | + QString::number(i) + ":00" ); | 488 | + QString::number(i) + ":00" ); |
487 | comboStart->insertItem( QString("0") | 489 | comboStart->insertItem( QString("0") |
488 | + QString::number(i) + ":30" ); | 490 | + QString::number(i) + ":30" ); |
489 | comboEnd->insertItem( QString("0") | 491 | comboEnd->insertItem( QString("0") |
490 | + QString::number(i) + ":00" ); | 492 | + QString::number(i) + ":00" ); |
491 | comboEnd->insertItem( QString("0") | 493 | comboEnd->insertItem( QString("0") |
492 | + QString::number(i) + ":30" ); | 494 | + QString::number(i) + ":30" ); |
493 | } else { | 495 | } else { |
494 | comboStart->insertItem( QString::number(i) + ":00" ); | 496 | comboStart->insertItem( QString::number(i) + ":00" ); |
495 | comboStart->insertItem( QString::number(i) + ":30" ); | 497 | comboStart->insertItem( QString::number(i) + ":30" ); |
496 | comboEnd->insertItem( QString::number(i) + ":00" ); | 498 | comboEnd->insertItem( QString::number(i) + ":00" ); |
497 | comboEnd->insertItem( QString::number(i) + ":30" ); | 499 | comboEnd->insertItem( QString::number(i) + ":30" ); |
498 | } | 500 | } |
499 | } | 501 | } |
500 | } | 502 | } |
501 | */ | 503 | */ |
502 | } | 504 | } |
503 | 505 | ||
504 | void DateEntry::slotChangeClock( bool whichClock ) | 506 | void DateEntry::slotChangeClock( bool whichClock ) |
505 | { | 507 | { |
506 | ampm = whichClock; | 508 | ampm = whichClock; |
507 | initCombos(); | 509 | initCombos(); |
508 | setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); | 510 | setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); |
509 | } | 511 | } |
diff --git a/core/pim/datebook/timepicker.cpp b/core/pim/datebook/timepicker.cpp index 5f08a05..9097e1b 100644 --- a/core/pim/datebook/timepicker.cpp +++ b/core/pim/datebook/timepicker.cpp | |||
@@ -1,119 +1,120 @@ | |||
1 | #include "timepicker.h" | 1 | #include "timepicker.h" |
2 | 2 | ||
3 | #include <qbuttongroup.h> | 3 | #include <qbuttongroup.h> |
4 | #include <qtoolbutton.h> | 4 | #include <qtoolbutton.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | #include "clickablelabel.h" | 6 | #include "clickablelabel.h" |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | #include <stdio.h> | ||
8 | 9 | ||
9 | TimePicker::TimePicker(QWidget* parent = 0, const char* name = 0, | 10 | TimePicker::TimePicker(QWidget* parent = 0, const char* name = 0, |
10 | WFlags fl = 0) : | 11 | WFlags fl = 0) : |
11 | QWidget(parent,name,fl) | 12 | QWidget(parent,name,fl) |
12 | { | 13 | { |
13 | QVBoxLayout *vbox=new QVBoxLayout(this); | 14 | QVBoxLayout *vbox=new QVBoxLayout(this); |
14 | 15 | ||
15 | ClickableLabel *r; | 16 | ClickableLabel *r; |
16 | QString s; | 17 | QString s; |
17 | 18 | ||
18 | // Hour Row | 19 | // Hour Row |
19 | QWidget *row=new QWidget(this); | 20 | QWidget *row=new QWidget(this); |
20 | QHBoxLayout *l=new QHBoxLayout(row); | 21 | QHBoxLayout *l=new QHBoxLayout(row); |
21 | vbox->addWidget(row); | 22 | vbox->addWidget(row); |
22 | 23 | ||
23 | 24 | ||
24 | for (int i=0; i<24; i++) { | 25 | for (int i=0; i<24; i++) { |
25 | r=new ClickableLabel(row); | 26 | r=new ClickableLabel(row); |
26 | hourLst.append(r); | 27 | hourLst.append(r); |
27 | s.sprintf("%.2d",i); | 28 | s.sprintf("%.2d",i); |
28 | r->setText(s); | 29 | r->setText(s); |
29 | r->setToggleButton(true); | 30 | r->setToggleButton(true); |
30 | r->setAlignment(AlignHCenter | AlignVCenter); | 31 | r->setAlignment(AlignHCenter | AlignVCenter); |
31 | l->addWidget(r); | 32 | l->addWidget(r); |
32 | connect(r, SIGNAL(toggled(bool)), | 33 | connect(r, SIGNAL(toggled(bool)), |
33 | this, SLOT(slotHour(bool))); | 34 | this, SLOT(slotHour(bool))); |
34 | 35 | ||
35 | if (i==11) { // Second row | 36 | if (i==11) { // Second row |
36 | row=new QWidget(this); | 37 | row=new QWidget(this); |
37 | l=new QHBoxLayout(row); | 38 | l=new QHBoxLayout(row); |
38 | vbox->addWidget(row); | 39 | vbox->addWidget(row); |
39 | } | 40 | } |
40 | } | 41 | } |
41 | 42 | ||
42 | // Minute Row | 43 | // Minute Row |
43 | row=new QWidget(this); | 44 | row=new QWidget(this); |
44 | l=new QHBoxLayout(row); | 45 | l=new QHBoxLayout(row); |
45 | vbox->addWidget(row); | 46 | vbox->addWidget(row); |
46 | 47 | ||
47 | for (int i=0; i<60; i+=5) { | 48 | for (int i=0; i<60; i+=5) { |
48 | r=new ClickableLabel(row); | 49 | r=new ClickableLabel(row); |
49 | minuteLst.append(r); | 50 | minuteLst.append(r); |
50 | s.sprintf("%.2d",i); | 51 | s.sprintf("%.2d",i); |
51 | r->setText(s); | 52 | r->setText(s); |
52 | r->setToggleButton(true); | 53 | r->setToggleButton(true); |
53 | r->setAlignment(AlignHCenter | AlignVCenter); | 54 | r->setAlignment(AlignHCenter | AlignVCenter); |
54 | l->addWidget(r); | 55 | l->addWidget(r); |
55 | connect(r, SIGNAL(toggled(bool)), | 56 | connect(r, SIGNAL(toggled(bool)), |
56 | this, SLOT(slotMinute(bool))); | 57 | this, SLOT(slotMinute(bool))); |
57 | } | 58 | } |
58 | } | 59 | } |
59 | 60 | ||
60 | void TimePicker::slotHour(bool b) { | 61 | void TimePicker::slotHour(bool b) { |
61 | 62 | ||
62 | ClickableLabel *r = (ClickableLabel *) sender(); | 63 | ClickableLabel *r = (ClickableLabel *) sender(); |
63 | 64 | ||
64 | if (b) { | 65 | if (b) { |
65 | QValueListIterator<ClickableLabel *> it; | 66 | QValueListIterator<ClickableLabel *> it; |
66 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { | 67 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { |
67 | if (*it != r) (*it)->setOn(false); | 68 | if (*it != r) (*it)->setOn(false); |
68 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); | 69 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); |
69 | } | 70 | } |
70 | emit timeChanged(tm); | 71 | emit timeChanged(tm); |
71 | } else { | 72 | } else { |
72 | r->setOn(true); | 73 | r->setOn(true); |
73 | } | 74 | } |
74 | 75 | ||
75 | } | 76 | } |
76 | 77 | ||
77 | void TimePicker::slotMinute(bool b) { | 78 | void TimePicker::slotMinute(bool b) { |
78 | 79 | ||
79 | ClickableLabel *r = (ClickableLabel *) sender(); | 80 | ClickableLabel *r = (ClickableLabel *) sender(); |
80 | 81 | ||
81 | if (b) { | 82 | if (b) { |
82 | QValueListIterator<ClickableLabel *> it; | 83 | QValueListIterator<ClickableLabel *> it; |
83 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { | 84 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { |
84 | if (*it != r) (*it)->setOn(false); | 85 | if (*it != r) (*it)->setOn(false); |
85 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); | 86 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); |
86 | } | 87 | } |
87 | emit timeChanged(tm); | 88 | emit timeChanged(tm); |
88 | } else { | 89 | } else { |
89 | r->setOn(true); | 90 | r->setOn(true); |
90 | } | 91 | } |
91 | 92 | ||
92 | } | 93 | } |
93 | 94 | ||
94 | void TimePicker::setMinute(int m) { | 95 | void TimePicker::setMinute(int m) { |
95 | 96 | ||
96 | QString minute; | 97 | QString minute; |
97 | minute.sprintf("%.2d",m); | 98 | minute.sprintf("%.2d",m); |
98 | 99 | ||
99 | QValueListIterator<ClickableLabel *> it; | 100 | QValueListIterator<ClickableLabel *> it; |
100 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { | 101 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { |
101 | if ((*it)->text() == minute) (*it)->setOn(true); | 102 | if ((*it)->text() == minute) (*it)->setOn(true); |
102 | else (*it)->setOn(false); | 103 | else (*it)->setOn(false); |
103 | } | 104 | } |
104 | 105 | ||
105 | tm.setHMS(tm.hour(),m,0); | 106 | tm.setHMS(tm.hour(),m,0); |
106 | } | 107 | } |
107 | 108 | ||
108 | void TimePicker::setHour(int h) { | 109 | void TimePicker::setHour(int h) { |
109 | 110 | ||
110 | QString hour; | 111 | QString hour; |
111 | hour.sprintf("%.2d",h); | 112 | hour.sprintf("%.2d",h); |
112 | 113 | ||
113 | QValueListIterator<ClickableLabel *> it; | 114 | QValueListIterator<ClickableLabel *> it; |
114 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { | 115 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { |
115 | if ((*it)->text() == hour) (*it)->setOn(true); | 116 | if ((*it)->text() == hour) (*it)->setOn(true); |
116 | else (*it)->setOn(false); | 117 | else (*it)->setOn(false); |
117 | } | 118 | } |
118 | tm.setHMS(h,tm.minute(),0); | 119 | tm.setHMS(h,tm.minute(),0); |
119 | } | 120 | } |