-rw-r--r-- | core/pim/datebook/datebook.cpp | 3 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 43 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.h | 35 |
3 files changed, 72 insertions, 9 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 0a47bb8..a18a5b4 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,1072 +1,1075 @@ | |||
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 <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | 33 | ||
34 | #include <qpe/datebookmonth.h> | 34 | #include <qpe/datebookmonth.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/finddialog.h> | 37 | #include <qpe/finddialog.h> |
38 | #include <qpe/ir.h> | 38 | #include <qpe/ir.h> |
39 | #include <qpe/qpemessagebox.h> | 39 | #include <qpe/qpemessagebox.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/tzselect.h> | 42 | #include <qpe/tzselect.h> |
43 | 43 | ||
44 | #include <qaction.h> | 44 | #include <qaction.h> |
45 | #include <qcopchannel_qws.h> | 45 | #include <qcopchannel_qws.h> |
46 | #include <qlayout.h> | 46 | #include <qlayout.h> |
47 | #include <qmessagebox.h> | 47 | #include <qmessagebox.h> |
48 | #include <qtimer.h> | 48 | #include <qtimer.h> |
49 | #include <qtl.h> | 49 | #include <qtl.h> |
50 | #include <qtoolbar.h> | 50 | #include <qtoolbar.h> |
51 | #include <qwidgetstack.h> | 51 | #include <qwidgetstack.h> |
52 | 52 | ||
53 | #include <sys/stat.h> | 53 | #include <sys/stat.h> |
54 | #include <sys/types.h> | 54 | #include <sys/types.h> |
55 | #include <fcntl.h> | 55 | #include <fcntl.h> |
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | 57 | ||
58 | #include <stdlib.h> | 58 | #include <stdlib.h> |
59 | 59 | ||
60 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 60 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
61 | : QMainWindow( parent, "datebook", f ), | 61 | : QMainWindow( parent, "datebook", f ), |
62 | aPreset( FALSE ), | 62 | aPreset( FALSE ), |
63 | presetTime( -1 ), | 63 | presetTime( -1 ), |
64 | startTime( 8 ), // an acceptable default | 64 | startTime( 8 ), // an acceptable default |
65 | rowStyle( 0 ), | 65 | rowStyle( 0 ), |
66 | bJumpToCurTime(FALSE), | 66 | bJumpToCurTime(FALSE), |
67 | syncing(FALSE), | 67 | syncing(FALSE), |
68 | inSearch(FALSE), | 68 | inSearch(FALSE), |
69 | alarmCounter(0) | 69 | alarmCounter(0) |
70 | { | 70 | { |
71 | bool needEvilHack= false; // if we need an Evil Hack | 71 | bool needEvilHack= false; // if we need an Evil Hack |
72 | QTime t; | 72 | QTime t; |
73 | t.start(); | 73 | t.start(); |
74 | db = new DateBookDBHack; | 74 | db = new DateBookDBHack; |
75 | odebug << "loading db t=" << t.elapsed() << oendl; | 75 | odebug << "loading db t=" << t.elapsed() << oendl; |
76 | loadSettings(); | 76 | loadSettings(); |
77 | setCaption( tr("Calendar") ); | 77 | setCaption( tr("Calendar") ); |
78 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 78 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
79 | 79 | ||
80 | setToolBarsMovable( FALSE ); | 80 | setToolBarsMovable( FALSE ); |
81 | 81 | ||
82 | views = new QWidgetStack( this ); | 82 | views = new QWidgetStack( this ); |
83 | setCentralWidget( views ); | 83 | setCentralWidget( views ); |
84 | 84 | ||
85 | dayView = 0; | 85 | dayView = 0; |
86 | weekView = 0; | 86 | weekView = 0; |
87 | weekLstView = 0; | 87 | weekLstView = 0; |
88 | monthView = 0; | 88 | monthView = 0; |
89 | 89 | ||
90 | // QToolBar *bar = new QToolBar( this ); | 90 | // QToolBar *bar = new QToolBar( this ); |
91 | // bar->setHorizontalStretchable( TRUE ); | 91 | // bar->setHorizontalStretchable( TRUE ); |
92 | 92 | ||
93 | // QMenuBar *mb = new QMenuBar( bar ); | 93 | // QMenuBar *mb = new QMenuBar( bar ); |
94 | // mb->setMargin( 0 ); | 94 | // mb->setMargin( 0 ); |
95 | 95 | ||
96 | // QPopupMenu *view = new QPopupMenu( this ); | 96 | // QPopupMenu *view = new QPopupMenu( this ); |
97 | // mb->insertItem( tr( "View" ), view ); | 97 | // mb->insertItem( tr( "View" ), view ); |
98 | 98 | ||
99 | QToolBar *sub_bar = new QToolBar(this); | 99 | QToolBar *sub_bar = new QToolBar(this); |
100 | sub_bar->setHorizontalStretchable(TRUE); | 100 | sub_bar->setHorizontalStretchable(TRUE); |
101 | 101 | ||
102 | QActionGroup *g = new QActionGroup( this ); | 102 | QActionGroup *g = new QActionGroup( this ); |
103 | g->setExclusive( TRUE ); | 103 | g->setExclusive( TRUE ); |
104 | 104 | ||
105 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 105 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
106 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 106 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
107 | a->addTo( sub_bar ); | 107 | a->addTo( sub_bar ); |
108 | 108 | ||
109 | sub_bar->addSeparator(); | 109 | sub_bar->addSeparator(); |
110 | 110 | ||
111 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); | 111 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); |
112 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 112 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
113 | a->addTo( sub_bar ); | 113 | a->addTo( sub_bar ); |
114 | //a->addTo( view ); | 114 | //a->addTo( view ); |
115 | 115 | ||
116 | sub_bar->addSeparator(); | 116 | sub_bar->addSeparator(); |
117 | 117 | ||
118 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); | 118 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); |
119 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 119 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
120 | a->addTo( sub_bar ); | 120 | a->addTo( sub_bar ); |
121 | // a->addTo( view ); | 121 | // a->addTo( view ); |
122 | a->setToggleAction( TRUE ); | 122 | a->setToggleAction( TRUE ); |
123 | a->setOn( TRUE ); | 123 | a->setOn( TRUE ); |
124 | dayAction = a; | 124 | dayAction = a; |
125 | 125 | ||
126 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); | 126 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); |
127 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 127 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
128 | a->addTo( sub_bar ); | 128 | a->addTo( sub_bar ); |
129 | // a->addTo( view ); | 129 | // a->addTo( view ); |
130 | a->setToggleAction( TRUE ); | 130 | a->setToggleAction( TRUE ); |
131 | weekAction = a; | 131 | weekAction = a; |
132 | 132 | ||
133 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); | 133 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); |
134 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 134 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
135 | a->addTo( sub_bar ); | 135 | a->addTo( sub_bar ); |
136 | // a->addTo( view ); | 136 | // a->addTo( view ); |
137 | a->setToggleAction( TRUE ); | 137 | a->setToggleAction( TRUE ); |
138 | weekLstAction = a; | 138 | weekLstAction = a; |
139 | 139 | ||
140 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); | 140 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); |
141 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 141 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
142 | a->addTo( sub_bar ); | 142 | a->addTo( sub_bar ); |
143 | // a->addTo( view ); | 143 | // a->addTo( view ); |
144 | a->setToggleAction( TRUE ); | 144 | a->setToggleAction( TRUE ); |
145 | monthAction = a; | 145 | monthAction = a; |
146 | 146 | ||
147 | sub_bar->addSeparator(); | 147 | sub_bar->addSeparator(); |
148 | 148 | ||
149 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); | 149 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); |
150 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 150 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
151 | a->addTo( sub_bar ); | 151 | a->addTo( sub_bar ); |
152 | 152 | ||
153 | a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); | 153 | a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); |
154 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 154 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
155 | a->addTo( sub_bar ); | 155 | a->addTo( sub_bar ); |
156 | 156 | ||
157 | if(defaultView==DAY) viewDay(); | 157 | if(defaultView==DAY) viewDay(); |
158 | if(defaultView==WEEK) needEvilHack=true;// viewWeek(); | 158 | if(defaultView==WEEK) needEvilHack=true;// viewWeek(); |
159 | if(defaultView==WEEKLST) viewWeekLst(); | 159 | if(defaultView==WEEKLST) viewWeekLst(); |
160 | if(defaultView==MONTH) viewMonth(); | 160 | if(defaultView==MONTH) viewMonth(); |
161 | 161 | ||
162 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); | 162 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); |
163 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); | 163 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); |
164 | 164 | ||
165 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 165 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
166 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); | 166 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
167 | #endif | 167 | #endif |
168 | 168 | ||
169 | // listen on QPE/System | 169 | // listen on QPE/System |
170 | #if defined(Q_WS_QWS) | 170 | #if defined(Q_WS_QWS) |
171 | #if !defined(QT_NO_COP) | 171 | #if !defined(QT_NO_COP) |
172 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 172 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
173 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); | 173 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); |
174 | channel = new QCopChannel( "QPE/Datebook", this ); | 174 | channel = new QCopChannel( "QPE/Datebook", this ); |
175 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); | 175 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); |
176 | #endif | 176 | #endif |
177 | #endif | 177 | #endif |
178 | 178 | ||
179 | odebug << "done t=" << t.elapsed() << oendl; | 179 | odebug << "done t=" << t.elapsed() << oendl; |
180 | 180 | ||
181 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); | 181 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); |
182 | connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); | 182 | connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); |
183 | /* | 183 | /* |
184 | * Here is a problem description: | 184 | * Here is a problem description: |
185 | * When Weekview is the default view | 185 | * When Weekview is the default view |
186 | * a DateBookWeekView get's created | 186 | * a DateBookWeekView get's created |
187 | * redraw() get's called. So what? | 187 | * redraw() get's called. So what? |
188 | * Remember that we're still in the c'tor | 188 | * Remember that we're still in the c'tor |
189 | * and no final layout has happened? Ok | 189 | * and no final layout has happened? Ok |
190 | * now all Events get arranged. Their x | 190 | * now all Events get arranged. Their x |
191 | * position get's determined by a QHeader | 191 | * position get's determined by a QHeader |
192 | * position. But the QHeader isn't layouted or | 192 | * position. But the QHeader isn't layouted or |
193 | * at the right position. redraw() is a slot | 193 | * at the right position. redraw() is a slot |
194 | * so we'll call it then via a singleShot | 194 | * so we'll call it then via a singleShot |
195 | * from view() | 195 | * from view() |
196 | */ | 196 | */ |
197 | if( needEvilHack ){ | 197 | if( needEvilHack ){ |
198 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); | 198 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 202 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
203 | { | 203 | { |
204 | QDataStream stream( data, IO_ReadOnly ); | 204 | QDataStream stream( data, IO_ReadOnly ); |
205 | if ( msg == "timeChange(QString)" ) { | 205 | if ( msg == "timeChange(QString)" ) { |
206 | // update active view! | 206 | // update active view! |
207 | if ( dayAction->isOn() ) | 207 | if ( dayAction->isOn() ) |
208 | viewDay(); | 208 | viewDay(); |
209 | else if ( weekAction->isOn() ) | 209 | else if ( weekAction->isOn() ) |
210 | viewWeek(); | 210 | viewWeek(); |
211 | else if ( monthAction->isOn() ) | 211 | else if ( monthAction->isOn() ) |
212 | viewMonth(); | 212 | viewMonth(); |
213 | } | 213 | } |
214 | else if (msg == "editEvent(int)") { | 214 | else if (msg == "editEvent(int)") { |
215 | int uid; | 215 | int uid; |
216 | stream >> uid; | 216 | stream >> uid; |
217 | Event e=db->eventByUID(uid); | 217 | Event e=db->eventByUID(uid); |
218 | editEvent(e); | 218 | editEvent(e); |
219 | }else if (msg == "viewDefault(QDate)"){ | 219 | }else if (msg == "viewDefault(QDate)"){ |
220 | QDate day; | 220 | QDate day; |
221 | stream >> day; | 221 | stream >> day; |
222 | viewDefault(day); | 222 | viewDefault(day); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | DateBook::~DateBook() | 226 | DateBook::~DateBook() |
227 | { | 227 | { |
228 | } | 228 | } |
229 | 229 | ||
230 | void DateBook::slotSettings() | 230 | void DateBook::slotSettings() |
231 | { | 231 | { |
232 | DateBookSettings frmSettings( ampm, this ); | 232 | DateBookSettings frmSettings( ampm, this ); |
233 | frmSettings.setStartTime( startTime ); | 233 | frmSettings.setStartTime( startTime ); |
234 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 234 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
235 | frmSettings.setJumpToCurTime( bJumpToCurTime ); | 235 | frmSettings.setJumpToCurTime( bJumpToCurTime ); |
236 | frmSettings.setRowStyle( rowStyle ); | 236 | frmSettings.setRowStyle( rowStyle ); |
237 | frmSettings.comboDefaultView->setCurrentItem(defaultView-1); | 237 | frmSettings.comboDefaultView->setCurrentItem(defaultView-1); |
238 | frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); | 238 | frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); |
239 | 239 | ||
240 | bool found=false; | 240 | bool found=false; |
241 | for (int i=0; i<(frmSettings.comboLocation->count()); i++) { | 241 | for (int i=0; i<(frmSettings.comboLocation->count()); i++) { |
242 | if ( frmSettings.comboLocation->text(i) == defaultLocation ) { | 242 | if ( frmSettings.comboLocation->text(i) == defaultLocation ) { |
243 | frmSettings.comboLocation->setCurrentItem(i); | 243 | frmSettings.comboLocation->setCurrentItem(i); |
244 | found=true; | 244 | found=true; |
245 | break; | 245 | break; |
246 | } | 246 | } |
247 | } | 247 | } |
248 | if(!found) { | 248 | if(!found) { |
249 | frmSettings.comboLocation->insertItem(defaultLocation); | 249 | frmSettings.comboLocation->insertItem(defaultLocation); |
250 | frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); | 250 | frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); |
251 | } | 251 | } |
252 | frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); | 252 | frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); |
253 | 253 | ||
254 | if ( QPEApplication::execDialog( &frmSettings ) ) { | 254 | if ( QPEApplication::execDialog( &frmSettings ) ) { |
255 | aPreset = frmSettings.alarmPreset(); | 255 | aPreset = frmSettings.alarmPreset(); |
256 | presetTime = frmSettings.presetTime(); | 256 | presetTime = frmSettings.presetTime(); |
257 | startTime = frmSettings.startTime(); | 257 | startTime = frmSettings.startTime(); |
258 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 258 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
259 | rowStyle = frmSettings.rowStyle(); | 259 | rowStyle = frmSettings.rowStyle(); |
260 | defaultView=frmSettings.comboDefaultView->currentItem()+1; | 260 | defaultView=frmSettings.comboDefaultView->currentItem()+1; |
261 | weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); | 261 | weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); |
262 | defaultLocation=frmSettings.comboLocation->currentText(); | 262 | defaultLocation=frmSettings.comboLocation->currentText(); |
263 | defaultCategories=frmSettings.comboCategory->currentCategories(); | 263 | defaultCategories=frmSettings.comboCategory->currentCategories(); |
264 | 264 | ||
265 | if ( dayView ) { | 265 | if ( dayView ) { |
266 | dayView->setStartViewTime( startTime ); | 266 | dayView->setStartViewTime( startTime ); |
267 | dayView->setJumpToCurTime( bJumpToCurTime ); | 267 | dayView->setJumpToCurTime( bJumpToCurTime ); |
268 | dayView->setRowStyle( rowStyle ); | 268 | dayView->setRowStyle( rowStyle ); |
269 | } | 269 | } |
270 | if ( weekView ) { | 270 | if ( weekView ) { |
271 | weekView->setStartViewTime( startTime ); | 271 | weekView->setStartViewTime( startTime ); |
272 | } | 272 | } |
273 | saveSettings(); | 273 | saveSettings(); |
274 | 274 | ||
275 | // make the change obvious | 275 | // make the change obvious |
276 | if ( views->visibleWidget() ) { | 276 | if ( views->visibleWidget() ) { |
277 | if ( views->visibleWidget() == dayView ) | 277 | if ( views->visibleWidget() == dayView ) |
278 | dayView->redraw(); | 278 | dayView->redraw(); |
279 | else if ( views->visibleWidget() == weekView ) | 279 | else if ( views->visibleWidget() == weekView ) |
280 | weekView->redraw(); | 280 | weekView->redraw(); |
281 | else if ( views->visibleWidget() == weekLstView ) | 281 | else if ( views->visibleWidget() == weekLstView ) |
282 | weekLstView->redraw(); | 282 | weekLstView->redraw(); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | void DateBook::fileNew() | 287 | void DateBook::fileNew() |
288 | { | 288 | { |
289 | slotNewEventFromKey(""); | 289 | slotNewEventFromKey(""); |
290 | } | 290 | } |
291 | 291 | ||
292 | QString DateBook::checkEvent(const Event &e) | 292 | QString DateBook::checkEvent(const Event &e) |
293 | { | 293 | { |
294 | /* check if overlaps with itself */ | 294 | /* check if overlaps with itself */ |
295 | bool checkFailed = FALSE; | 295 | bool checkFailed = FALSE; |
296 | 296 | ||
297 | /* check the next 12 repeats. should catch most problems */ | 297 | /* check the next 12 repeats. should catch most problems */ |
298 | QDate current_date = e.start().date(); | 298 | QDate current_date = e.start().date(); |
299 | Event previous = e; | 299 | Event previous = e; |
300 | for(int i = 0; i < 12; i++) | 300 | for(int i = 0; i < 12; i++) |
301 | { | 301 | { |
302 | QDateTime next; | 302 | QDateTime next; |
303 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 303 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
304 | break; // no more repeats | 304 | break; // no more repeats |
305 | } | 305 | } |
306 | if(next < previous.end()) { | 306 | if(next < previous.end()) { |
307 | checkFailed = TRUE; | 307 | checkFailed = TRUE; |
308 | break; | 308 | break; |
309 | } | 309 | } |
310 | current_date = next.date(); | 310 | current_date = next.date(); |
311 | } | 311 | } |
312 | 312 | ||
313 | if(checkFailed) | 313 | if(checkFailed) |
314 | return tr("Event duration is potentially longer\n" | 314 | return tr("Event duration is potentially longer\n" |
315 | "than interval between repeats."); | 315 | "than interval between repeats."); |
316 | 316 | ||
317 | return QString::null; | 317 | return QString::null; |
318 | } | 318 | } |
319 | 319 | ||
320 | QDate DateBook::currentDate() | 320 | QDate DateBook::currentDate() |
321 | { | 321 | { |
322 | QDate d = QDate::currentDate(); | 322 | QDate d = QDate::currentDate(); |
323 | 323 | ||
324 | if ( dayView && views->visibleWidget() == dayView ) { | 324 | if ( dayView && views->visibleWidget() == dayView ) { |
325 | d = dayView->date(); | 325 | d = dayView->date(); |
326 | } else if ( weekView && views->visibleWidget() == weekView ) { | 326 | } else if ( weekView && views->visibleWidget() == weekView ) { |
327 | d = weekView->date(); | 327 | d = weekView->date(); |
328 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 328 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
329 | d = weekLstView->date(); | 329 | d = weekLstView->date(); |
330 | } else if ( monthView && views->visibleWidget() == monthView ) { | 330 | } else if ( monthView && views->visibleWidget() == monthView ) { |
331 | d = monthView->selectedDate(); | 331 | d = monthView->selectedDate(); |
332 | } | 332 | } |
333 | 333 | ||
334 | return d; | 334 | return d; |
335 | } | 335 | } |
336 | 336 | ||
337 | void DateBook::view(int v, const QDate &d) { | 337 | void DateBook::view(int v, const QDate &d) { |
338 | if (v==DAY) { | 338 | if (v==DAY) { |
339 | initDay(); | 339 | initDay(); |
340 | dayAction->setOn( TRUE ); | 340 | dayAction->setOn( TRUE ); |
341 | dayView->setDate( d ); | 341 | dayView->setDate( d ); |
342 | views->raiseWidget( dayView ); | 342 | views->raiseWidget( dayView ); |
343 | dayView->redraw(); | 343 | dayView->redraw(); |
344 | } else if (v==WEEK) { | 344 | } else if (v==WEEK) { |
345 | initWeek(); | 345 | initWeek(); |
346 | weekAction->setOn( TRUE ); | 346 | weekAction->setOn( TRUE ); |
347 | weekView->setDate( d ); | 347 | weekView->setDate( d ); |
348 | views->raiseWidget( weekView ); | 348 | views->raiseWidget( weekView ); |
349 | weekView->redraw(); | 349 | weekView->redraw(); |
350 | } else if (v==WEEKLST) { | 350 | } else if (v==WEEKLST) { |
351 | initWeekLst(); | 351 | initWeekLst(); |
352 | weekLstAction->setOn( TRUE ); | 352 | weekLstAction->setOn( TRUE ); |
353 | weekLstView->setDate(d); | 353 | weekLstView->setDate(d); |
354 | views->raiseWidget( weekLstView ); | 354 | views->raiseWidget( weekLstView ); |
355 | weekLstView->redraw(); | 355 | weekLstView->redraw(); |
356 | } else if (v==MONTH) { | 356 | } else if (v==MONTH) { |
357 | initMonth(); | 357 | initMonth(); |
358 | monthAction->setOn( TRUE ); | 358 | monthAction->setOn( TRUE ); |
359 | monthView->setDate( d.year(), d.month(), d.day() ); | 359 | monthView->setDate( d.year(), d.month(), d.day() ); |
360 | views->raiseWidget( monthView ); | 360 | views->raiseWidget( monthView ); |
361 | monthView->redraw(); | 361 | monthView->redraw(); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | 364 | ||
365 | void DateBook::viewDefault(const QDate &d) { | 365 | void DateBook::viewDefault(const QDate &d) { |
366 | view(defaultView,d); | 366 | view(defaultView,d); |
367 | } | 367 | } |
368 | 368 | ||
369 | void DateBook::viewDay() { | 369 | void DateBook::viewDay() { |
370 | view(DAY,currentDate()); | 370 | view(DAY,currentDate()); |
371 | } | 371 | } |
372 | 372 | ||
373 | void DateBook::viewWeek() { | 373 | void DateBook::viewWeek() { |
374 | view(WEEK,currentDate()); | 374 | view(WEEK,currentDate()); |
375 | } | 375 | } |
376 | 376 | ||
377 | void DateBook::viewWeekLst() { | 377 | void DateBook::viewWeekLst() { |
378 | view(WEEKLST,currentDate()); | 378 | view(WEEKLST,currentDate()); |
379 | } | 379 | } |
380 | 380 | ||
381 | void DateBook::viewMonth() { | 381 | void DateBook::viewMonth() { |
382 | view(MONTH,currentDate()); | 382 | view(MONTH,currentDate()); |
383 | } | 383 | } |
384 | 384 | ||
385 | void DateBook::insertEvent( const Event &e ) | 385 | void DateBook::insertEvent( const Event &e ) |
386 | { | 386 | { |
387 | Event dupEvent=e; | 387 | Event dupEvent=e; |
388 | if(!dupEvent.isValidUid() ) // tkcRom seems to be different | 388 | if(!dupEvent.isValidUid() ) // tkcRom seems to be different |
389 | dupEvent.assignUid(); | 389 | dupEvent.assignUid(); |
390 | dupEvent.setLocation(defaultLocation); | 390 | dupEvent.setLocation(defaultLocation); |
391 | dupEvent.setCategories(defaultCategories); | 391 | dupEvent.setCategories(defaultCategories); |
392 | db->addEvent(dupEvent); | 392 | db->addEvent(dupEvent); |
393 | emit newEvent(); | 393 | emit newEvent(); |
394 | } | 394 | } |
395 | 395 | ||
396 | void DateBook::duplicateEvent( const Event &e ) | 396 | void DateBook::duplicateEvent( const Event &e ) |
397 | { | 397 | { |
398 | // Alot of code duplication, as this is almost like editEvent(); | 398 | // Alot of code duplication, as this is almost like editEvent(); |
399 | if (syncing) { | 399 | if (syncing) { |
400 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 400 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
401 | return; | 401 | return; |
402 | } | 402 | } |
403 | 403 | ||
404 | Event dupevent(e);// Make a duplicate. | 404 | Event dupevent(e);// Make a duplicate. |
405 | 405 | ||
406 | // workaround added for text input. | 406 | // workaround added for text input. |
407 | QDialog editDlg( this, 0, TRUE ); | 407 | QDialog editDlg( this, 0, TRUE ); |
408 | DateEntry *entry; | 408 | DateEntry *entry; |
409 | editDlg.setCaption( tr("Duplicate Event") ); | 409 | editDlg.setCaption( tr("Duplicate Event") ); |
410 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 410 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
411 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 411 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
412 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 412 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
413 | // KLUDGE!!! | 413 | // KLUDGE!!! |
414 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 414 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
415 | vb->addWidget( sv ); | 415 | vb->addWidget( sv ); |
416 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); | 416 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); |
417 | entry->timezone->setEnabled( FALSE ); | 417 | entry->timezone->setEnabled( FALSE ); |
418 | sv->addChild( entry ); | 418 | sv->addChild( entry ); |
419 | 419 | ||
420 | while ( QPEApplication::execDialog( &editDlg ) ) { | 420 | while ( QPEApplication::execDialog( &editDlg ) ) { |
421 | Event newEv = entry->event(); | 421 | Event newEv = entry->event(); |
422 | QString error = checkEvent(newEv); | 422 | QString error = checkEvent(newEv); |
423 | if (!error.isNull()) { | 423 | if (!error.isNull()) { |
424 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) | 424 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) |
425 | continue; | 425 | continue; |
426 | } | 426 | } |
427 | /* | 427 | /* |
428 | * The problem: | 428 | * The problem: |
429 | * DateBookDB does remove repeating events not by uid but by the time | 429 | * DateBookDB does remove repeating events not by uid but by the time |
430 | * the recurrence was created | 430 | * the recurrence was created |
431 | * so we need to update that time as well | 431 | * so we need to update that time as well |
432 | */ | 432 | */ |
433 | Event::RepeatPattern rp = newEv.repeatPattern(); | 433 | Event::RepeatPattern rp = newEv.repeatPattern(); |
434 | rp.createTime = ::time( NULL ); | 434 | rp.createTime = ::time( NULL ); |
435 | newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... | 435 | newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... |
436 | if( newEv.uid() == e.uid() || !newEv.isValidUid() ) | 436 | if( newEv.uid() == e.uid() || !newEv.isValidUid() ) |
437 | newEv.assignUid(); | 437 | newEv.assignUid(); |
438 | 438 | ||
439 | db->addEvent(newEv); | 439 | db->addEvent(newEv); |
440 | emit newEvent(); | 440 | emit newEvent(); |
441 | break; | 441 | break; |
442 | } | 442 | } |
443 | } | 443 | } |
444 | 444 | ||
445 | void DateBook::editEvent( const Event &e ) | 445 | void DateBook::editEvent( const Event &e ) |
446 | { | 446 | { |
447 | if (syncing) { | 447 | if (syncing) { |
448 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 448 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
449 | return; | 449 | return; |
450 | } | 450 | } |
451 | 451 | ||
452 | // workaround added for text input. | 452 | // workaround added for text input. |
453 | QDialog editDlg( this, 0, TRUE ); | 453 | QDialog editDlg( this, 0, TRUE ); |
454 | DateEntry *entry; | 454 | DateEntry *entry; |
455 | editDlg.setCaption( tr("Edit Event") ); | 455 | editDlg.setCaption( tr("Edit Event") ); |
456 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 456 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
457 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 457 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
458 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 458 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
459 | // KLUDGE!!! | 459 | // KLUDGE!!! |
460 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 460 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
461 | vb->addWidget( sv ); | 461 | vb->addWidget( sv ); |
462 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 462 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
463 | entry->timezone->setEnabled( FALSE ); | 463 | entry->timezone->setEnabled( FALSE ); |
464 | sv->addChild( entry ); | 464 | sv->addChild( entry ); |
465 | 465 | ||
466 | while ( QPEApplication::execDialog( &editDlg ) ) { | 466 | while ( QPEApplication::execDialog( &editDlg ) ) { |
467 | Event newEv = entry->event(); | 467 | Event newEv = entry->event(); |
468 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) | 468 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) |
469 | break; | 469 | break; |
470 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 470 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
471 | QString error = checkEvent(newEv); | 471 | QString error = checkEvent(newEv); |
472 | if (!error.isNull()) { | 472 | if (!error.isNull()) { |
473 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; | 473 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; |
474 | } | 474 | } |
475 | db->editEvent(e, newEv); | 475 | db->editEvent(e, newEv); |
476 | emit newEvent(); | 476 | emit newEvent(); |
477 | break; | 477 | break; |
478 | } | 478 | } |
479 | } | 479 | } |
480 | 480 | ||
481 | void DateBook::removeEvent( const Event &e ) | 481 | void DateBook::removeEvent( const Event &e ) |
482 | { | 482 | { |
483 | if (syncing) { | 483 | if (syncing) { |
484 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 484 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
485 | return; | 485 | return; |
486 | } | 486 | } |
487 | 487 | ||
488 | QString strName = e.description(); | 488 | QString strName = e.description(); |
489 | 489 | ||
490 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 490 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
491 | return; | 491 | return; |
492 | 492 | ||
493 | db->removeEvent( e ); | 493 | db->removeEvent( e ); |
494 | if ( views->visibleWidget() == dayView && dayView ) | 494 | if ( views->visibleWidget() == dayView && dayView ) |
495 | dayView->redraw(); | 495 | dayView->redraw(); |
496 | 496 | ||
497 | } | 497 | } |
498 | 498 | ||
499 | void DateBook::addEvent( const Event &e ) | 499 | void DateBook::addEvent( const Event &e ) |
500 | { | 500 | { |
501 | QDate d = e.start().date(); | 501 | QDate d = e.start().date(); |
502 | initDay(); | 502 | initDay(); |
503 | dayView->setDate( d ); | 503 | dayView->setDate( d ); |
504 | } | 504 | } |
505 | 505 | ||
506 | void DateBook::showDay( int year, int month, int day ) | 506 | void DateBook::showDay( int year, int month, int day ) |
507 | { | 507 | { |
508 | QDate d(year, month, day); | 508 | QDate d(year, month, day); |
509 | view(DAY,d); | 509 | view(DAY,d); |
510 | } | 510 | } |
511 | 511 | ||
512 | void DateBook::initDay() | 512 | void DateBook::initDay() |
513 | { | 513 | { |
514 | if ( !dayView ) { | 514 | if ( !dayView ) { |
515 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 515 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
516 | views->addWidget( dayView, DAY ); | 516 | views->addWidget( dayView, DAY ); |
517 | dayView->setJumpToCurTime( bJumpToCurTime ); | 517 | dayView->setJumpToCurTime( bJumpToCurTime ); |
518 | dayView->setStartViewTime( startTime ); | 518 | dayView->setStartViewTime( startTime ); |
519 | dayView->setRowStyle( rowStyle ); | 519 | dayView->setRowStyle( rowStyle ); |
520 | connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); | 520 | connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); |
521 | connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); | 521 | connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); |
522 | connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); | 522 | connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); |
523 | connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); | 523 | connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); |
524 | connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); | 524 | connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); |
525 | connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); | 525 | connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); |
526 | connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); | 526 | connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); |
527 | } | 527 | } |
528 | } | 528 | } |
529 | 529 | ||
530 | void DateBook::initWeek() | 530 | void DateBook::initWeek() |
531 | { | 531 | { |
532 | if ( !weekView ) { | 532 | if ( !weekView ) { |
533 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 533 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
534 | weekView->setStartViewTime( startTime ); | 534 | weekView->setStartViewTime( startTime ); |
535 | views->addWidget( weekView, WEEK ); | 535 | views->addWidget( weekView, WEEK ); |
536 | connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); | 536 | connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); |
537 | connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); | 537 | connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); |
538 | } | 538 | } |
539 | 539 | ||
540 | //But also get it right: the year that we display can be different | 540 | //But also get it right: the year that we display can be different |
541 | //from the year of the current date. So, first find the year | 541 | //from the year of the current date. So, first find the year |
542 | //number of the current week. | 542 | //number of the current week. |
543 | int yearNumber, totWeeks; | 543 | int yearNumber, totWeeks; |
544 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | 544 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); |
545 | 545 | ||
546 | QDate d = QDate( yearNumber, 12, 31 ); | 546 | QDate d = QDate( yearNumber, 12, 31 ); |
547 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 547 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
548 | 548 | ||
549 | while ( totWeeks == 1 ) { | 549 | while ( totWeeks == 1 ) { |
550 | d = d.addDays( -1 ); | 550 | d = d.addDays( -1 ); |
551 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 551 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | void DateBook::initWeekLst() { | 555 | void DateBook::initWeekLst() { |
556 | if ( !weekLstView ) { | 556 | if ( !weekLstView ) { |
557 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); | 557 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); |
558 | views->addWidget( weekLstView, WEEKLST ); | 558 | views->addWidget( weekLstView, WEEKLST ); |
559 | 559 | ||
560 | //weekLstView->setStartViewTime( startTime ); | 560 | //weekLstView->setStartViewTime( startTime ); |
561 | connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); | 561 | connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); |
562 | connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ), | 562 | connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ), |
563 | this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); | 563 | this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); |
564 | connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); | 564 | connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); |
565 | connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); | 565 | connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); |
566 | connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); | ||
567 | connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); | ||
568 | connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); | ||
566 | } | 569 | } |
567 | } | 570 | } |
568 | 571 | ||
569 | 572 | ||
570 | void DateBook::initMonth() | 573 | void DateBook::initMonth() |
571 | { | 574 | { |
572 | if ( !monthView ) { | 575 | if ( !monthView ) { |
573 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 576 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
574 | views->addWidget( monthView, MONTH ); | 577 | views->addWidget( monthView, MONTH ); |
575 | connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); | 578 | connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); |
576 | connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); | 579 | connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); |
577 | qApp->processEvents(); | 580 | qApp->processEvents(); |
578 | } | 581 | } |
579 | } | 582 | } |
580 | 583 | ||
581 | void DateBook::loadSettings() | 584 | void DateBook::loadSettings() |
582 | { | 585 | { |
583 | Config qpeconfig( "qpe" ); | 586 | Config qpeconfig( "qpe" ); |
584 | qpeconfig.setGroup("Time"); | 587 | qpeconfig.setGroup("Time"); |
585 | ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); | 588 | ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); |
586 | onMonday = qpeconfig.readBoolEntry( "MONDAY" ); | 589 | onMonday = qpeconfig.readBoolEntry( "MONDAY" ); |
587 | 590 | ||
588 | Config config("DateBook"); | 591 | Config config("DateBook"); |
589 | config.setGroup("Main"); | 592 | config.setGroup("Main"); |
590 | startTime = config.readNumEntry("startviewtime", 8); | 593 | startTime = config.readNumEntry("startviewtime", 8); |
591 | aPreset = config.readBoolEntry("alarmpreset"); | 594 | aPreset = config.readBoolEntry("alarmpreset"); |
592 | presetTime = config.readNumEntry("presettime"); | 595 | presetTime = config.readNumEntry("presettime"); |
593 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); | 596 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); |
594 | rowStyle = config.readNumEntry("rowstyle"); | 597 | rowStyle = config.readNumEntry("rowstyle"); |
595 | defaultView = config.readNumEntry("defaultview",DAY); | 598 | defaultView = config.readNumEntry("defaultview",DAY); |
596 | weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); | 599 | weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); |
597 | 600 | ||
598 | defaultLocation=config.readEntry("defaultLocation"); | 601 | defaultLocation=config.readEntry("defaultLocation"); |
599 | QString tmpString=config.readEntry("defaultCategories"); | 602 | QString tmpString=config.readEntry("defaultCategories"); |
600 | QStringList tmpStringList=QStringList::split(",",tmpString); | 603 | QStringList tmpStringList=QStringList::split(",",tmpString); |
601 | defaultCategories.truncate(0); | 604 | defaultCategories.truncate(0); |
602 | 605 | ||
603 | for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { | 606 | for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { |
604 | defaultCategories.resize(defaultCategories.count()+1); | 607 | defaultCategories.resize(defaultCategories.count()+1); |
605 | defaultCategories[defaultCategories.count()-1]=(*i).toInt(); | 608 | defaultCategories[defaultCategories.count()-1]=(*i).toInt(); |
606 | } | 609 | } |
607 | } | 610 | } |
608 | 611 | ||
609 | void DateBook::saveSettings() | 612 | void DateBook::saveSettings() |
610 | { | 613 | { |
611 | Config config( "qpe" ); | 614 | Config config( "qpe" ); |
612 | Config configDB( "DateBook" ); | 615 | Config configDB( "DateBook" ); |
613 | configDB.setGroup( "Main" ); | 616 | configDB.setGroup( "Main" ); |
614 | configDB.writeEntry("startviewtime",startTime); | 617 | configDB.writeEntry("startviewtime",startTime); |
615 | configDB.writeEntry("alarmpreset",aPreset); | 618 | configDB.writeEntry("alarmpreset",aPreset); |
616 | configDB.writeEntry("presettime",presetTime); | 619 | configDB.writeEntry("presettime",presetTime); |
617 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); | 620 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); |
618 | configDB.writeEntry("rowstyle", rowStyle); | 621 | configDB.writeEntry("rowstyle", rowStyle); |
619 | configDB.writeEntry("defaultview",defaultView); | 622 | configDB.writeEntry("defaultview",defaultView); |
620 | configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); | 623 | configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); |
621 | 624 | ||
622 | configDB.writeEntry("defaultLocation",defaultLocation); | 625 | configDB.writeEntry("defaultLocation",defaultLocation); |
623 | QStringList tmpStringList; | 626 | QStringList tmpStringList; |
624 | for( uint i=0; i<defaultCategories.count(); i++) { | 627 | for( uint i=0; i<defaultCategories.count(); i++) { |
625 | tmpStringList << QString::number(defaultCategories[i]); | 628 | tmpStringList << QString::number(defaultCategories[i]); |
626 | } | 629 | } |
627 | configDB.writeEntry("defaultCategories",tmpStringList.join(",")); | 630 | configDB.writeEntry("defaultCategories",tmpStringList.join(",")); |
628 | } | 631 | } |
629 | 632 | ||
630 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 633 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
631 | { | 634 | { |
632 | bool needShow = FALSE; | 635 | bool needShow = FALSE; |
633 | if ( msg == "alarm(QDateTime,int)" ) { | 636 | if ( msg == "alarm(QDateTime,int)" ) { |
634 | QDataStream ds(data,IO_ReadOnly); | 637 | QDataStream ds(data,IO_ReadOnly); |
635 | QDateTime when; int warn; | 638 | QDateTime when; int warn; |
636 | ds >> when >> warn; | 639 | ds >> when >> warn; |
637 | 640 | ||
638 | // check to make it's okay to continue, | 641 | // check to make it's okay to continue, |
639 | // this is the case that the time was set ahead, and | 642 | // this is the case that the time was set ahead, and |
640 | // we are forced given a stale alarm... | 643 | // we are forced given a stale alarm... |
641 | QDateTime current = QDateTime::currentDateTime(); | 644 | QDateTime current = QDateTime::currentDateTime(); |
642 | if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) | 645 | if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) |
643 | return; | 646 | return; |
644 | 647 | ||
645 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 648 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
646 | if ( list.count() > 0 ) { | 649 | if ( list.count() > 0 ) { |
647 | QString msg; | 650 | QString msg; |
648 | bool bSound = FALSE; | 651 | bool bSound = FALSE; |
649 | int stopTimer = 0; | 652 | int stopTimer = 0; |
650 | bool found = FALSE; | 653 | bool found = FALSE; |
651 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { | 654 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { |
652 | if ( (*it).event().hasAlarm() ) { | 655 | if ( (*it).event().hasAlarm() ) { |
653 | found = TRUE; | 656 | found = TRUE; |
654 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 657 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
655 | + "<BR>" + (*it).location() + "<BR>" | 658 | + "<BR>" + (*it).location() + "<BR>" |
656 | + TimeString::dateString((*it).event().start(),ampm) | 659 | + TimeString::dateString((*it).event().start(),ampm) |
657 | + (warn | 660 | + (warn |
658 | ? tr(" (in " + QString::number(warn) | 661 | ? tr(" (in " + QString::number(warn) |
659 | + tr(" minutes)")) | 662 | + tr(" minutes)")) |
660 | : QString("")) | 663 | : QString("")) |
661 | + "<BR>" | 664 | + "<BR>" |
662 | + (*it).notes() + "</CENTER>"; | 665 | + (*it).notes() + "</CENTER>"; |
663 | if ( (*it).event().alarmSound() != Event::Silent ) { | 666 | if ( (*it).event().alarmSound() != Event::Silent ) { |
664 | bSound = TRUE; | 667 | bSound = TRUE; |
665 | } | 668 | } |
666 | } | 669 | } |
667 | } | 670 | } |
668 | if ( found ) { | 671 | if ( found ) { |
669 | if ( bSound ) { | 672 | if ( bSound ) { |
670 | Sound::soundAlarm(); | 673 | Sound::soundAlarm(); |
671 | alarmCounter = 0; | 674 | alarmCounter = 0; |
672 | stopTimer = startTimer( 5000 ); | 675 | stopTimer = startTimer( 5000 ); |
673 | } | 676 | } |
674 | QDialog dlg( this, 0, TRUE ); | 677 | QDialog dlg( this, 0, TRUE ); |
675 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 678 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
676 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 679 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
677 | view->setResizePolicy( QScrollView::AutoOneFit ); | 680 | view->setResizePolicy( QScrollView::AutoOneFit ); |
678 | vb->addWidget( view ); | 681 | vb->addWidget( view ); |
679 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 682 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
680 | view->addChild( lblMsg ); | 683 | view->addChild( lblMsg ); |
681 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 684 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
682 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 685 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
683 | vb->addWidget( cmdOk ); | 686 | vb->addWidget( cmdOk ); |
684 | 687 | ||
685 | needShow = QPEApplication::execDialog( &dlg ); | 688 | needShow = QPEApplication::execDialog( &dlg ); |
686 | 689 | ||
687 | if ( bSound ) | 690 | if ( bSound ) |
688 | killTimer( stopTimer ); | 691 | killTimer( stopTimer ); |
689 | } | 692 | } |
690 | } | 693 | } |
691 | } else if ( msg == "nextView()" ) { | 694 | } else if ( msg == "nextView()" ) { |
692 | needShow = true; | 695 | needShow = true; |
693 | if ( !qApp-> activeWindow ( )) { | 696 | if ( !qApp-> activeWindow ( )) { |
694 | needShow = TRUE; | 697 | needShow = TRUE; |
695 | } else { | 698 | } else { |
696 | QWidget* cur = views->visibleWidget(); | 699 | QWidget* cur = views->visibleWidget(); |
697 | if ( cur ) { | 700 | if ( cur ) { |
698 | if ( cur == dayView ) | 701 | if ( cur == dayView ) |
699 | viewWeek(); | 702 | viewWeek(); |
700 | else if ( cur == weekView ) | 703 | else if ( cur == weekView ) |
701 | viewWeekLst(); | 704 | viewWeekLst(); |
702 | else if ( cur == weekLstView ) | 705 | else if ( cur == weekLstView ) |
703 | viewMonth(); | 706 | viewMonth(); |
704 | else if ( cur == monthView ) | 707 | else if ( cur == monthView ) |
705 | viewDay(); | 708 | viewDay(); |
706 | needShow = TRUE; | 709 | needShow = TRUE; |
707 | } | 710 | } |
708 | } | 711 | } |
709 | } else if (msg == "editEvent(int)") { | 712 | } else if (msg == "editEvent(int)") { |
710 | /* simple copy from receive */ | 713 | /* simple copy from receive */ |
711 | QDataStream stream(data,IO_ReadOnly); | 714 | QDataStream stream(data,IO_ReadOnly); |
712 | int uid; | 715 | int uid; |
713 | stream >> uid; | 716 | stream >> uid; |
714 | Event e=db->eventByUID(uid); | 717 | Event e=db->eventByUID(uid); |
715 | editEvent(e); | 718 | editEvent(e); |
716 | } else if (msg == "viewDefault(QDate)"){ | 719 | } else if (msg == "viewDefault(QDate)"){ |
717 | /* simple copy from receive */ | 720 | /* simple copy from receive */ |
718 | QDataStream stream(data,IO_ReadOnly); | 721 | QDataStream stream(data,IO_ReadOnly); |
719 | QDate day; | 722 | QDate day; |
720 | stream >> day; | 723 | stream >> day; |
721 | viewDefault(day); | 724 | viewDefault(day); |
722 | needShow = true; | 725 | needShow = true; |
723 | } | 726 | } |
724 | 727 | ||
725 | if ( needShow ) { | 728 | if ( needShow ) { |
726 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 729 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
727 | // showMaximized(); | 730 | // showMaximized(); |
728 | #else | 731 | #else |
729 | // show(); | 732 | // show(); |
730 | #endif | 733 | #endif |
731 | // raise(); | 734 | // raise(); |
732 | QPEApplication::setKeepRunning(); | 735 | QPEApplication::setKeepRunning(); |
733 | // setActiveWindow(); | 736 | // setActiveWindow(); |
734 | } | 737 | } |
735 | } | 738 | } |
736 | 739 | ||
737 | void DateBook::reload() | 740 | void DateBook::reload() |
738 | { | 741 | { |
739 | db->reload(); | 742 | db->reload(); |
740 | if ( dayAction->isOn() ) viewDay(); | 743 | if ( dayAction->isOn() ) viewDay(); |
741 | else if ( weekAction->isOn() ) viewWeek(); | 744 | else if ( weekAction->isOn() ) viewWeek(); |
742 | else if ( monthAction->isOn() ) viewMonth(); | 745 | else if ( monthAction->isOn() ) viewMonth(); |
743 | syncing = FALSE; | 746 | syncing = FALSE; |
744 | } | 747 | } |
745 | 748 | ||
746 | void DateBook::flush() | 749 | void DateBook::flush() |
747 | { | 750 | { |
748 | syncing = TRUE; | 751 | syncing = TRUE; |
749 | db->save(); | 752 | db->save(); |
750 | } | 753 | } |
751 | 754 | ||
752 | void DateBook::timerEvent( QTimerEvent *e ) | 755 | void DateBook::timerEvent( QTimerEvent *e ) |
753 | { | 756 | { |
754 | if ( alarmCounter < 10 ) { | 757 | if ( alarmCounter < 10 ) { |
755 | alarmCounter++; | 758 | alarmCounter++; |
756 | Sound::soundAlarm(); | 759 | Sound::soundAlarm(); |
757 | } else { | 760 | } else { |
758 | killTimer( e->timerId() ); | 761 | killTimer( e->timerId() ); |
759 | } | 762 | } |
760 | } | 763 | } |
761 | 764 | ||
762 | void DateBook::changeClock( bool newClock ) | 765 | void DateBook::changeClock( bool newClock ) |
763 | { | 766 | { |
764 | ampm = newClock; | 767 | ampm = newClock; |
765 | // repaint the affected objects... | 768 | // repaint the affected objects... |
766 | if (dayView) dayView->redraw(); | 769 | if (dayView) dayView->redraw(); |
767 | if (weekView) weekView->redraw(); | 770 | if (weekView) weekView->redraw(); |
768 | if (weekLstView) weekLstView->redraw(); | 771 | if (weekLstView) weekLstView->redraw(); |
769 | } | 772 | } |
770 | 773 | ||
771 | void DateBook::changeWeek( bool m ) | 774 | void DateBook::changeWeek( bool m ) |
772 | { | 775 | { |
773 | /* no need to redraw, each widget catches. Do need to | 776 | /* no need to redraw, each widget catches. Do need to |
774 | store though for widgets we haven't made yet */ | 777 | store though for widgets we haven't made yet */ |
775 | onMonday = m; | 778 | onMonday = m; |
776 | } | 779 | } |
777 | 780 | ||
778 | void DateBook::slotToday() | 781 | void DateBook::slotToday() |
779 | { | 782 | { |
780 | // we need to view today using default view | 783 | // we need to view today using default view |
781 | view(defaultView,QDate::currentDate()); | 784 | view(defaultView,QDate::currentDate()); |
782 | } | 785 | } |
783 | 786 | ||
784 | void DateBook::closeEvent( QCloseEvent *e ) | 787 | void DateBook::closeEvent( QCloseEvent *e ) |
785 | { | 788 | { |
786 | if(syncing) { | 789 | if(syncing) { |
787 | /* no need to save, did that at flush */ | 790 | /* no need to save, did that at flush */ |
788 | e->accept(); | 791 | e->accept(); |
789 | return; | 792 | return; |
790 | } | 793 | } |
791 | 794 | ||
792 | // save settings will generate it's own error messages, no | 795 | // save settings will generate it's own error messages, no |
793 | // need to do checking ourselves. | 796 | // need to do checking ourselves. |
794 | saveSettings(); | 797 | saveSettings(); |
795 | if ( db->save() ) { | 798 | if ( db->save() ) { |
796 | e->accept(); | 799 | e->accept(); |
797 | } else { | 800 | } else { |
798 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 801 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
799 | tr("Calendar was unable to save\n" | 802 | tr("Calendar was unable to save\n" |
800 | "your changes.\n" | 803 | "your changes.\n" |
801 | "Free up some space and try again.\n" | 804 | "Free up some space and try again.\n" |
802 | "\nQuit anyway?"), | 805 | "\nQuit anyway?"), |
803 | QMessageBox::Yes|QMessageBox::Escape, | 806 | QMessageBox::Yes|QMessageBox::Escape, |
804 | QMessageBox::No|QMessageBox::Default ) | 807 | QMessageBox::No|QMessageBox::Default ) |
805 | != QMessageBox::No ) | 808 | != QMessageBox::No ) |
806 | e->accept(); | 809 | e->accept(); |
807 | else | 810 | else |
808 | e->ignore(); | 811 | e->ignore(); |
809 | } | 812 | } |
810 | } | 813 | } |
811 | 814 | ||
812 | // Entering directly from the "keyboard" | 815 | // Entering directly from the "keyboard" |
813 | void DateBook::slotNewEventFromKey( const QString &str ) | 816 | void DateBook::slotNewEventFromKey( const QString &str ) |
814 | { | 817 | { |
815 | if (syncing) { | 818 | if (syncing) { |
816 | QMessageBox::warning( this, tr("Calendar"), | 819 | QMessageBox::warning( this, tr("Calendar"), |
817 | tr( "Can not edit data, currently syncing") ); | 820 | tr( "Can not edit data, currently syncing") ); |
818 | return; | 821 | return; |
819 | } | 822 | } |
820 | 823 | ||
821 | // We get to here from a key pressed in the Day View | 824 | // We get to here from a key pressed in the Day View |
822 | // So we can assume some things. We want the string | 825 | // So we can assume some things. We want the string |
823 | // passed in to be part of the description. | 826 | // passed in to be part of the description. |
824 | QDateTime start, end; | 827 | QDateTime start, end; |
825 | if ( views->visibleWidget() == dayView ) { | 828 | if ( views->visibleWidget() == dayView ) { |
826 | dayView->selectedDates( start, end ); | 829 | dayView->selectedDates( start, end ); |
827 | } else if ( views->visibleWidget() == monthView ) { | 830 | } else if ( views->visibleWidget() == monthView ) { |
828 | QDate d = monthView->selectedDate(); | 831 | QDate d = monthView->selectedDate(); |
829 | start = end = d; | 832 | start = end = d; |
830 | start.setTime( QTime( 10, 0 ) ); | 833 | start.setTime( QTime( 10, 0 ) ); |
831 | end.setTime( QTime( 12, 0 ) ); | 834 | end.setTime( QTime( 12, 0 ) ); |
832 | } else if ( views->visibleWidget() == weekView ) { | 835 | } else if ( views->visibleWidget() == weekView ) { |
833 | QDate d = weekView->date(); | 836 | QDate d = weekView->date(); |
834 | start = end = d; | 837 | start = end = d; |
835 | start.setTime( QTime( 10, 0 ) ); | 838 | start.setTime( QTime( 10, 0 ) ); |
836 | end.setTime( QTime( 12, 0 ) ); | 839 | end.setTime( QTime( 12, 0 ) ); |
837 | } else if ( views->visibleWidget() == weekLstView ) { | 840 | } else if ( views->visibleWidget() == weekLstView ) { |
838 | QDate d = weekLstView->date(); | 841 | QDate d = weekLstView->date(); |
839 | start = end = d; | 842 | start = end = d; |
840 | start.setTime( QTime( 10, 0 ) ); | 843 | start.setTime( QTime( 10, 0 ) ); |
841 | end.setTime( QTime( 12, 0 ) ); | 844 | end.setTime( QTime( 12, 0 ) ); |
842 | } | 845 | } |
843 | slotNewEntry(start, end, str); | 846 | slotNewEntry(start, end, str); |
844 | } | 847 | } |
845 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { | 848 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { |
846 | // argh! This really needs to be encapsulated in a class | 849 | // argh! This really needs to be encapsulated in a class |
847 | // or function. | 850 | // or function. |
848 | QDialog newDlg( this, 0, TRUE ); | 851 | QDialog newDlg( this, 0, TRUE ); |
849 | newDlg.setCaption( DateEntryBase::tr("New Event") ); | 852 | newDlg.setCaption( DateEntryBase::tr("New Event") ); |
850 | DateEntry *e; | 853 | DateEntry *e; |
851 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); | 854 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); |
852 | QScrollView *sv = new QScrollView( &newDlg ); | 855 | QScrollView *sv = new QScrollView( &newDlg ); |
853 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 856 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
854 | sv->setFrameStyle( QFrame::NoFrame ); | 857 | sv->setFrameStyle( QFrame::NoFrame ); |
855 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 858 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
856 | vb->addWidget( sv ); | 859 | vb->addWidget( sv ); |
857 | 860 | ||
858 | Event ev; | 861 | Event ev; |
859 | ev.setDescription( str ); | 862 | ev.setDescription( str ); |
860 | // When the new gui comes in, change this... | 863 | // When the new gui comes in, change this... |
861 | if(location==0) { | 864 | if(location==0) { |
862 | if(defaultLocation.isEmpty()) { | 865 | if(defaultLocation.isEmpty()) { |
863 | ev.setLocation(tr("(Unknown)")); | 866 | ev.setLocation(tr("(Unknown)")); |
864 | } else { | 867 | } else { |
865 | ev.setLocation( defaultLocation ); | 868 | ev.setLocation( defaultLocation ); |
866 | } | 869 | } |
867 | } else { | 870 | } else { |
868 | ev.setLocation(location); | 871 | ev.setLocation(location); |
869 | } | 872 | } |
870 | ev.setCategories(defaultCategories); | 873 | ev.setCategories(defaultCategories); |
871 | ev.setStart( start ); | 874 | ev.setStart( start ); |
872 | ev.setEnd( end ); | 875 | ev.setEnd( end ); |
873 | 876 | ||
874 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); | 877 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); |
875 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); | 878 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); |
876 | sv->addChild( e ); | 879 | sv->addChild( e ); |
877 | while ( QPEApplication::execDialog( &newDlg ) ) { | 880 | while ( QPEApplication::execDialog( &newDlg ) ) { |
878 | ev = e->event(); | 881 | ev = e->event(); |
879 | ev.assignUid(); | 882 | ev.assignUid(); |
880 | QString error = checkEvent( ev ); | 883 | QString error = checkEvent( ev ); |
881 | if ( !error.isNull() ) { | 884 | if ( !error.isNull() ) { |
882 | if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) | 885 | if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) |
883 | continue; | 886 | continue; |
884 | } | 887 | } |
885 | db->addEvent( ev ); | 888 | db->addEvent( ev ); |
886 | emit newEvent(); | 889 | emit newEvent(); |
887 | break; | 890 | break; |
888 | } | 891 | } |
889 | } | 892 | } |
890 | 893 | ||
891 | void DateBook::setDocument( const QString &filename ) | 894 | void DateBook::setDocument( const QString &filename ) |
892 | { | 895 | { |
893 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 896 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
894 | 897 | ||
895 | QValueList<Event> tl = Event::readVCalendar( filename ); | 898 | QValueList<Event> tl = Event::readVCalendar( filename ); |
896 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 899 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
897 | db->addEvent( *it ); | 900 | db->addEvent( *it ); |
898 | } | 901 | } |
899 | } | 902 | } |
900 | 903 | ||
901 | static const char * beamfile = "/tmp/obex/event.vcs"; | 904 | static const char * beamfile = "/tmp/obex/event.vcs"; |
902 | 905 | ||
903 | void DateBook::beamEvent( const Event &e ) | 906 | void DateBook::beamEvent( const Event &e ) |
904 | { | 907 | { |
905 | odebug << "trying to beam" << oendl; | 908 | odebug << "trying to beam" << oendl; |
906 | unlink( beamfile ); // delete if exists | 909 | unlink( beamfile ); // delete if exists |
907 | mkdir("/tmp/obex/", 0755); | 910 | mkdir("/tmp/obex/", 0755); |
908 | Event::writeVCalendar( beamfile, e ); | 911 | Event::writeVCalendar( beamfile, e ); |
909 | Ir *ir = new Ir( this ); | 912 | Ir *ir = new Ir( this ); |
910 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 913 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
911 | QString description = e.description(); | 914 | QString description = e.description(); |
912 | ir->send( beamfile, description, "text/x-vCalendar" ); | 915 | ir->send( beamfile, description, "text/x-vCalendar" ); |
913 | } | 916 | } |
914 | 917 | ||
915 | void DateBook::beamDone( Ir *ir ) | 918 | void DateBook::beamDone( Ir *ir ) |
916 | { | 919 | { |
917 | delete ir; | 920 | delete ir; |
918 | unlink( beamfile ); | 921 | unlink( beamfile ); |
919 | } | 922 | } |
920 | 923 | ||
921 | void DateBook::slotFind() | 924 | void DateBook::slotFind() |
922 | { | 925 | { |
923 | // move it to the day view... | 926 | // move it to the day view... |
924 | viewDay(); | 927 | viewDay(); |
925 | FindDialog frmFind( "Calendar", this ); // no tr needed | 928 | FindDialog frmFind( "Calendar", this ); // no tr needed |
926 | frmFind.setUseDate( true ); | 929 | frmFind.setUseDate( true ); |
927 | frmFind.setDate( currentDate() ); | 930 | frmFind.setDate( currentDate() ); |
928 | QObject::connect( &frmFind, | 931 | QObject::connect( &frmFind, |
929 | SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)), | 932 | SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)), |
930 | this, | 933 | this, |
931 | SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) ); | 934 | SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) ); |
932 | QObject::connect( this, | 935 | QObject::connect( this, |
933 | SIGNAL(signalNotFound()), | 936 | SIGNAL(signalNotFound()), |
934 | &frmFind, | 937 | &frmFind, |
935 | SLOT(slotNotFound()) ); | 938 | SLOT(slotNotFound()) ); |
936 | QObject::connect( this, | 939 | QObject::connect( this, |
937 | SIGNAL(signalWrapAround()), | 940 | SIGNAL(signalWrapAround()), |
938 | &frmFind, | 941 | &frmFind, |
939 | SLOT(slotWrapAround()) ); | 942 | SLOT(slotWrapAround()) ); |
940 | frmFind.move(0,0); | 943 | frmFind.move(0,0); |
941 | frmFind.exec(); | 944 | frmFind.exec(); |
942 | inSearch = false; | 945 | inSearch = false; |
943 | } | 946 | } |
944 | 947 | ||
945 | bool catComp( QArray<int> cats, int category ) | 948 | bool catComp( QArray<int> cats, int category ) |
946 | { | 949 | { |
947 | bool returnMe; | 950 | bool returnMe; |
948 | int i, | 951 | int i, |
949 | count; | 952 | count; |
950 | 953 | ||
951 | count = int(cats.count()); | 954 | count = int(cats.count()); |
952 | returnMe = false; | 955 | returnMe = false; |
953 | if ( (category == -1 && count == 0) || category == -2 ) | 956 | if ( (category == -1 && count == 0) || category == -2 ) |
954 | returnMe = true; | 957 | returnMe = true; |
955 | else { | 958 | else { |
956 | for ( i = 0; i < count; i++ ) { | 959 | for ( i = 0; i < count; i++ ) { |
957 | if ( category == cats[i] ) { | 960 | if ( category == cats[i] ) { |
958 | returnMe = true; | 961 | returnMe = true; |
959 | break; | 962 | break; |
960 | } | 963 | } |
961 | } | 964 | } |
962 | } | 965 | } |
963 | return returnMe; | 966 | return returnMe; |
964 | } | 967 | } |
965 | 968 | ||
966 | 969 | ||
967 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, | 970 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, |
968 | bool caseSensitive, bool /*backwards*/, | 971 | bool caseSensitive, bool /*backwards*/, |
969 | int category ) | 972 | int category ) |
970 | { | 973 | { |
971 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), | 974 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), |
972 | next; | 975 | next; |
973 | 976 | ||
974 | QRegExp r( txt ); | 977 | QRegExp r( txt ); |
975 | r.setCaseSensitive( caseSensitive ); | 978 | r.setCaseSensitive( caseSensitive ); |
976 | 979 | ||
977 | 980 | ||
978 | static Event rev, nonrev; | 981 | static Event rev, nonrev; |
979 | if ( !inSearch ) { | 982 | if ( !inSearch ) { |
980 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 983 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
981 | nonrev.setStart( rev.start() ); | 984 | nonrev.setStart( rev.start() ); |
982 | inSearch = true; | 985 | inSearch = true; |
983 | } | 986 | } |
984 | static QDate searchDate = dt; | 987 | static QDate searchDate = dt; |
985 | // if true at the end we will start at the begin again and afterwards | 988 | // if true at the end we will start at the begin again and afterwards |
986 | // we will emit string not found | 989 | // we will emit string not found |
987 | static bool wrapAround = true; | 990 | static bool wrapAround = true; |
988 | bool candidtate; | 991 | bool candidtate; |
989 | candidtate = false; | 992 | candidtate = false; |
990 | 993 | ||
991 | QValueList<Event> repeats = db->getRawRepeats(); | 994 | QValueList<Event> repeats = db->getRawRepeats(); |
992 | 995 | ||
993 | // find the candidate for the first repeat that matches... | 996 | // find the candidate for the first repeat that matches... |
994 | // first check if there can ever be a match and then compute | 997 | // first check if there can ever be a match and then compute |
995 | // the next occurence from start. See if this event is closer | 998 | // the next occurence from start. See if this event is closer |
996 | // to the beginning (start. next < dtEnd) and not smaller then the last | 999 | // to the beginning (start. next < dtEnd) and not smaller then the last |
997 | // result. If we find a canditate we set the dtEnd to the time | 1000 | // result. If we find a canditate we set the dtEnd to the time |
998 | // of the ocurrence and rev to this occurence. | 1001 | // of the ocurrence and rev to this occurence. |
999 | // set wrap around to true because there might be more events coming | 1002 | // set wrap around to true because there might be more events coming |
1000 | // and we're not at the end. | 1003 | // and we're not at the end. |
1001 | QValueListConstIterator<Event> it; | 1004 | QValueListConstIterator<Event> it; |
1002 | QDate start = dt; | 1005 | QDate start = dt; |
1003 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { | 1006 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { |
1004 | if ( catComp( (*it).categories(), category ) ) { | 1007 | if ( catComp( (*it).categories(), category ) ) { |
1005 | if ( (*it).match( r ) ) { | 1008 | if ( (*it).match( r ) ) { |
1006 | if ( nextOccurance( *it, start, next ) ) { | 1009 | if ( nextOccurance( *it, start, next ) ) { |
1007 | if ( next < dtEnd && !(next <= rev.start() ) ) { | 1010 | if ( next < dtEnd && !(next <= rev.start() ) ) { |
1008 | rev = *it; | 1011 | rev = *it; |
1009 | dtEnd = next; | 1012 | dtEnd = next; |
1010 | rev.setStart( next ); | 1013 | rev.setStart( next ); |
1011 | candidtate = true; | 1014 | candidtate = true; |
1012 | wrapAround = true; | 1015 | wrapAround = true; |
1013 | } | 1016 | } |
1014 | } | 1017 | } |
1015 | } | 1018 | } |
1016 | } | 1019 | } |
1017 | } | 1020 | } |
1018 | 1021 | ||
1019 | // now the for first non repeat... | 1022 | // now the for first non repeat... |
1020 | // dtEnd is set by the previous iteration of repeatingEvents | 1023 | // dtEnd is set by the previous iteration of repeatingEvents |
1021 | // check if we find a closer item. Also set dtEnd to find even | 1024 | // check if we find a closer item. Also set dtEnd to find even |
1022 | // more close occurrence | 1025 | // more close occurrence |
1023 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); | 1026 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); |
1024 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); | 1027 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); |
1025 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { | 1028 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { |
1026 | if ( catComp( (*it).categories(), category ) ) { | 1029 | if ( catComp( (*it).categories(), category ) ) { |
1027 | if ( (*it).start() < dtEnd ) { | 1030 | if ( (*it).start() < dtEnd ) { |
1028 | if ( (*it).match( r ) && !(*it <= nonrev) ) { | 1031 | if ( (*it).match( r ) && !(*it <= nonrev) ) { |
1029 | nonrev = *it; | 1032 | nonrev = *it; |
1030 | dtEnd = nonrev.start(); | 1033 | dtEnd = nonrev.start(); |
1031 | candidtate = true; | 1034 | candidtate = true; |
1032 | wrapAround = true; | 1035 | wrapAround = true; |
1033 | break; | 1036 | break; |
1034 | } | 1037 | } |
1035 | } | 1038 | } |
1036 | } | 1039 | } |
1037 | } | 1040 | } |
1038 | if ( candidtate ) { | 1041 | if ( candidtate ) { |
1039 | dayView->setStartViewTime( dtEnd.time().hour() ); | 1042 | dayView->setStartViewTime( dtEnd.time().hour() ); |
1040 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), | 1043 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), |
1041 | dtEnd.date().day() ); | 1044 | dtEnd.date().day() ); |
1042 | } else { | 1045 | } else { |
1043 | if ( wrapAround ) { | 1046 | if ( wrapAround ) { |
1044 | emit signalWrapAround(); | 1047 | emit signalWrapAround(); |
1045 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 1048 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
1046 | nonrev.setStart( rev.start() ); | 1049 | nonrev.setStart( rev.start() ); |
1047 | } else | 1050 | } else |
1048 | emit signalNotFound(); | 1051 | emit signalNotFound(); |
1049 | wrapAround = !wrapAround; | 1052 | wrapAround = !wrapAround; |
1050 | } | 1053 | } |
1051 | } | 1054 | } |
1052 | 1055 | ||
1053 | Event DateBookDBHack::eventByUID(int uid) { | 1056 | Event DateBookDBHack::eventByUID(int uid) { |
1054 | 1057 | ||
1055 | // FIXME: Dirty Hacks to get hold of the private event lists | 1058 | // FIXME: Dirty Hacks to get hold of the private event lists |
1056 | QDate start; | 1059 | QDate start; |
1057 | QDate end=start.addDays(-1); | 1060 | QDate end=start.addDays(-1); |
1058 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); | 1061 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); |
1059 | QValueList<Event> myRepeatEvents=getRawRepeats(); | 1062 | QValueList<Event> myRepeatEvents=getRawRepeats(); |
1060 | 1063 | ||
1061 | QValueList<Event>::ConstIterator it; | 1064 | QValueList<Event>::ConstIterator it; |
1062 | 1065 | ||
1063 | for (it = myEventList.begin(); it != myEventList.end(); it++) { | 1066 | for (it = myEventList.begin(); it != myEventList.end(); it++) { |
1064 | if ((*it).uid() == uid) return *it; | 1067 | if ((*it).uid() == uid) return *it; |
1065 | } | 1068 | } |
1066 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { | 1069 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { |
1067 | if ((*it).uid() == uid) return *it; | 1070 | if ((*it).uid() == uid) return *it; |
1068 | } | 1071 | } |
1069 | 1072 | ||
1070 | Event ev; | 1073 | Event ev; |
1071 | return ev; // return at least | 1074 | return ev; // return at least |
1072 | } | 1075 | } |
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index fe2ab51..771aa00 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp | |||
@@ -1,397 +1,436 @@ | |||
1 | #include "namespace_hack.h" | 1 | #include "namespace_hack.h" |
2 | #include "datebookweeklst.h" | 2 | #include "datebookweeklst.h" |
3 | 3 | ||
4 | #include "datebook.h" | 4 | #include "datebook.h" |
5 | 5 | ||
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | 7 | ||
8 | #include <qpe/datebookmonth.h> | 8 | #include <qpe/datebookmonth.h> |
9 | #include <qpe/config.h> | 9 | #include <qpe/config.h> |
10 | #include <qpe/ir.h> | ||
10 | #include <qpe/resource.h> | 11 | #include <qpe/resource.h> |
11 | 12 | ||
12 | #include <qlayout.h> | 13 | #include <qlayout.h> |
13 | #include <qtoolbutton.h> | 14 | #include <qtoolbutton.h> |
14 | #include <qtl.h> | 15 | #include <qtl.h> |
15 | 16 | ||
16 | bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); | 17 | bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); |
17 | 18 | ||
18 | using namespace Opie::Ui; | 19 | using namespace Opie::Ui; |
19 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) | 20 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) |
20 | : DateBookWeekLstHeaderBase(parent, name, fl) | 21 | : DateBookWeekLstHeaderBase(parent, name, fl) |
21 | { | 22 | { |
22 | setBackgroundMode( PaletteButton ); | 23 | setBackgroundMode( PaletteButton ); |
23 | labelDate->setBackgroundMode( PaletteButton ); | 24 | labelDate->setBackgroundMode( PaletteButton ); |
24 | forwardweek->setBackgroundMode( PaletteButton ); | 25 | forwardweek->setBackgroundMode( PaletteButton ); |
25 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); | 26 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); |
26 | forwardmonth->setBackgroundMode( PaletteButton ); | 27 | forwardmonth->setBackgroundMode( PaletteButton ); |
27 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); | 28 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); |
28 | backweek->setBackgroundMode( PaletteButton ); | 29 | backweek->setBackgroundMode( PaletteButton ); |
29 | backweek->setPixmap( Resource::loadPixmap("back") ); | 30 | backweek->setPixmap( Resource::loadPixmap("back") ); |
30 | backmonth->setBackgroundMode( PaletteButton ); | 31 | backmonth->setBackgroundMode( PaletteButton ); |
31 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); | 32 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); |
32 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); | 33 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); |
33 | DateBookWeekLstHeaderBaseLayout->setMargin(0); | 34 | DateBookWeekLstHeaderBaseLayout->setMargin(0); |
34 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); | 35 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); |
35 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 36 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
36 | 37 | ||
37 | connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); | 38 | connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); |
38 | connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); | 39 | connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); |
39 | connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); | 40 | connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); |
40 | connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); | 41 | connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); |
41 | connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); | 42 | connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); |
42 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); | 43 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); |
43 | bStartOnMonday=onM; | 44 | bStartOnMonday=onM; |
44 | } | 45 | } |
45 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} | 46 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} |
46 | 47 | ||
47 | void DateBookWeekLstHeader::setDate(const QDate &d) { | 48 | void DateBookWeekLstHeader::setDate(const QDate &d) { |
48 | int year,week,dayofweek; | 49 | int year,week,dayofweek; |
49 | date=d; | 50 | date=d; |
50 | dayofweek=d.dayOfWeek(); | 51 | dayofweek=d.dayOfWeek(); |
51 | if(bStartOnMonday) | 52 | if(bStartOnMonday) |
52 | dayofweek--; | 53 | dayofweek--; |
53 | else if( dayofweek == 7 ) | 54 | else if( dayofweek == 7 ) |
54 | /* we already have the right day -7 would lead to the same week */ | 55 | /* we already have the right day -7 would lead to the same week */ |
55 | dayofweek = 0; | 56 | dayofweek = 0; |
56 | 57 | ||
57 | date=date.addDays(-dayofweek); | 58 | date=date.addDays(-dayofweek); |
58 | 59 | ||
59 | calcWeek(date,week,year,bStartOnMonday); | 60 | calcWeek(date,week,year,bStartOnMonday); |
60 | QDate start=date; | 61 | QDate start=date; |
61 | QDate stop=start.addDays(6); | 62 | QDate stop=start.addDays(6); |
62 | labelDate->setText( QString::number(start.day()) + "." + | 63 | labelDate->setText( QString::number(start.day()) + "." + |
63 | Calendar::nameOfMonth( start.month() ) + "-" + | 64 | Calendar::nameOfMonth( start.month() ) + "-" + |
64 | QString::number(stop.day()) + "." + | 65 | QString::number(stop.day()) + "." + |
65 | Calendar::nameOfMonth( stop.month()) +" ("+ | 66 | Calendar::nameOfMonth( stop.month()) +" ("+ |
66 | tr("w")+":"+QString::number( week ) +")"); | 67 | tr("w")+":"+QString::number( week ) +")"); |
67 | date = d; // bugfix: 0001126 - date has to be the selected date, not monday! | 68 | date = d; // bugfix: 0001126 - date has to be the selected date, not monday! |
68 | emit dateChanged(date); | 69 | emit dateChanged(date); |
69 | } | 70 | } |
70 | 71 | ||
71 | void DateBookWeekLstHeader::pickDate() { | 72 | void DateBookWeekLstHeader::pickDate() { |
72 | static QPopupMenu *m1 = 0; | 73 | static QPopupMenu *m1 = 0; |
73 | static DateBookMonth *picker = 0; | 74 | static DateBookMonth *picker = 0; |
74 | if ( !m1 ) { | 75 | if ( !m1 ) { |
75 | m1 = new QPopupMenu( this ); | 76 | m1 = new QPopupMenu( this ); |
76 | picker = new DateBookMonth( m1, 0, TRUE ); | 77 | picker = new DateBookMonth( m1, 0, TRUE ); |
77 | m1->insertItem( picker ); | 78 | m1->insertItem( picker ); |
78 | connect( picker, SIGNAL( dateClicked(int,int,int) ),this, SLOT( setDate(int,int,int) ) ); | 79 | connect( picker, SIGNAL( dateClicked(int,int,int) ),this, SLOT( setDate(int,int,int) ) ); |
79 | //connect( m1, SIGNAL( aboutToHide() ), | 80 | //connect( m1, SIGNAL( aboutToHide() ), |
80 | //this, SLOT( gotHide() ) ); | 81 | //this, SLOT( gotHide() ) ); |
81 | } | 82 | } |
82 | picker->setDate( date.year(), date.month(), date.day() ); | 83 | picker->setDate( date.year(), date.month(), date.day() ); |
83 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); | 84 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); |
84 | picker->setFocus(); | 85 | picker->setFocus(); |
85 | } | 86 | } |
86 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { | 87 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { |
87 | setDate(QDate(y,m,d)); | 88 | setDate(QDate(y,m,d)); |
88 | } | 89 | } |
89 | 90 | ||
90 | void DateBookWeekLstHeader::nextWeek() { | 91 | void DateBookWeekLstHeader::nextWeek() { |
91 | setDate(date.addDays(7)); | 92 | setDate(date.addDays(7)); |
92 | } | 93 | } |
93 | void DateBookWeekLstHeader::prevWeek() { | 94 | void DateBookWeekLstHeader::prevWeek() { |
94 | setDate(date.addDays(-7)); | 95 | setDate(date.addDays(-7)); |
95 | } | 96 | } |
96 | void DateBookWeekLstHeader::nextMonth() | 97 | void DateBookWeekLstHeader::nextMonth() |
97 | { | 98 | { |
98 | setDate(date.addDays(28)); | 99 | setDate(date.addDays(28)); |
99 | } | 100 | } |
100 | void DateBookWeekLstHeader::prevMonth() | 101 | void DateBookWeekLstHeader::prevMonth() |
101 | { | 102 | { |
102 | setDate(date.addDays(-28)); | 103 | setDate(date.addDays(-28)); |
103 | } | 104 | } |
104 | 105 | ||
105 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */, | 106 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */, |
106 | QWidget* parent, | 107 | QWidget* parent, |
107 | const char* name, | 108 | const char* name, |
108 | WFlags fl ) | 109 | WFlags fl ) |
109 | : DateBookWeekLstDayHdrBase(parent, name, fl) { | 110 | : DateBookWeekLstDayHdrBase(parent, name, fl) { |
110 | 111 | ||
111 | date=d; | 112 | date=d; |
112 | 113 | ||
113 | static const QString wdays=tr("MTWTFSSM", "Week days"); | 114 | static const QString wdays=tr("MTWTFSSM", "Week days"); |
114 | char day=wdays[d.dayOfWeek()-1]; | 115 | char day=wdays[d.dayOfWeek()-1]; |
115 | 116 | ||
116 | //dont use dayOfWeek() to save space ! | 117 | //dont use dayOfWeek() to save space ! |
117 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); | 118 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); |
118 | 119 | ||
119 | add->setText("+"); | 120 | add->setText("+"); |
120 | 121 | ||
121 | if (d == QDate::currentDate()) { | 122 | if (d == QDate::currentDate()) { |
122 | QPalette pal=label->palette(); | 123 | QPalette pal=label->palette(); |
123 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); | 124 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); |
124 | label->setPalette(pal); | 125 | label->setPalette(pal); |
125 | 126 | ||
126 | /* | 127 | /* |
127 | QFont f=label->font(); | 128 | QFont f=label->font(); |
128 | f.setItalic(true); | 129 | f.setItalic(true); |
129 | label->setFont(f); | 130 | label->setFont(f); |
130 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); | 131 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); |
131 | */ | 132 | */ |
132 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday | 133 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday |
133 | QPalette pal=label->palette(); | 134 | QPalette pal=label->palette(); |
134 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); | 135 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); |
135 | label->setPalette(pal); | 136 | label->setPalette(pal); |
136 | } | 137 | } |
137 | 138 | ||
138 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); | 139 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); |
139 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); | 140 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); |
140 | } | 141 | } |
141 | 142 | ||
142 | void DateBookWeekLstDayHdr::showDay() { | 143 | void DateBookWeekLstDayHdr::showDay() { |
143 | emit showDate(date.year(), date.month(), date.day()); | 144 | emit showDate(date.year(), date.month(), date.day()); |
144 | } | 145 | } |
145 | 146 | ||
146 | void DateBookWeekLstDayHdr::newEvent() { | 147 | void DateBookWeekLstDayHdr::newEvent() { |
147 | QDateTime start, stop; | 148 | QDateTime start, stop; |
148 | start=stop=date; | 149 | start=stop=date; |
149 | start.setTime(QTime(10,0)); | 150 | start.setTime(QTime(10,0)); |
150 | stop.setTime(QTime(12,0)); | 151 | stop.setTime(QTime(12,0)); |
151 | 152 | ||
152 | emit addEvent(start,stop,"",0); | 153 | emit addEvent(start,stop,"",0); |
153 | } | 154 | } |
154 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, | 155 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, |
155 | int weeklistviewconfig, | 156 | int weeklistviewconfig, |
156 | QWidget* parent, | 157 | QWidget* parent, |
157 | const char* name, | 158 | const char* name, |
158 | WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) | 159 | WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) |
159 | { | 160 | { |
160 | // old values... lastday = "__|__", middle=" |---", Firstday="00:00", | 161 | // old values... lastday = "__|__", middle=" |---", Firstday="00:00", |
161 | QString s,start,middle,end,day; | 162 | QString s,start,middle,end,day; |
162 | 163 | ||
163 | odebug << "weeklistviewconfig=" << weeklistviewconfig << oendl; | 164 | odebug << "weeklistviewconfig=" << weeklistviewconfig << oendl; |
164 | if(weeklistviewconfig==NONE) {// No times displayed. | 165 | if(weeklistviewconfig==NONE) {// No times displayed. |
165 | // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); | 166 | // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); |
166 | // middle.sprintf("<--->"); | 167 | // middle.sprintf("<--->"); |
167 | // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); | 168 | // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); |
168 | // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); | 169 | // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); |
169 | } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time. | 170 | } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time. |
170 | start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); | 171 | start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); |
171 | middle.sprintf(" |---"); | 172 | middle.sprintf(" |---"); |
172 | end.sprintf("__|__"); | 173 | end.sprintf("__|__"); |
173 | day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); | 174 | day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); |
174 | } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. | 175 | } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. |
175 | start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); | 176 | start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); |
176 | middle.sprintf("<--->"); | 177 | middle.sprintf("<--->"); |
177 | end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); | 178 | end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); |
178 | day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); | 179 | day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); |
179 | } | 180 | } |
180 | 181 | ||
181 | if(ev.event().type() == Event::Normal) { | 182 | if(ev.event().type() == Event::Normal) { |
182 | if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event. | 183 | if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event. |
183 | s=day; | 184 | s=day; |
184 | } else if(ev.startDate()==ev.date()) {// start event. | 185 | } else if(ev.startDate()==ev.date()) {// start event. |
185 | s=start; | 186 | s=start; |
186 | } else if(ev.endDate()==ev.date()) { // end event. | 187 | } else if(ev.endDate()==ev.date()) { // end event. |
187 | s=end; | 188 | s=end; |
188 | } else {// middle day. | 189 | } else {// middle day. |
189 | s=middle; | 190 | s=middle; |
190 | } | 191 | } |
191 | } else { | 192 | } else { |
192 | s=""; | 193 | s=""; |
193 | } | 194 | } |
194 | setText(QString(s) + " " + ev.description()); | 195 | setText(QString(s) + " " + ev.description()); |
195 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); | 196 | //connect(this, SIGNAL(clicked()), this, SLOT(editMe())); |
196 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); | 197 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); |
197 | } | 198 | } |
198 | void DateBookWeekLstEvent::editMe() { | 199 | void DateBookWeekLstEvent::editMe() { |
199 | emit editEvent(event.event()); | 200 | emit editEvent(event.event()); |
200 | } | 201 | } |
201 | 202 | void DateBookWeekLstEvent::duplicateMe() | |
203 | { | ||
204 | emit duplicateEvent(event.event()); | ||
205 | } | ||
206 | void DateBookWeekLstEvent::deleteMe() | ||
207 | { | ||
208 | emit removeEvent(event.event()); | ||
209 | emit redraw(); | ||
210 | } | ||
211 | void DateBookWeekLstEvent::beamMe() | ||
212 | { | ||
213 | emit beamEvent( event.event() ); | ||
214 | } | ||
215 | void DateBookWeekLstEvent::mousePressEvent( QMouseEvent *e ) | ||
216 | { | ||
217 | popmenue = new QPopupMenu; | ||
218 | popmenue->insertItem( tr( "Edit" ), this, SLOT(editMe())); | ||
219 | popmenue->insertItem( tr( "Duplicate" ), this, SLOT(duplicateMe())); | ||
220 | popmenue->insertItem( tr( "Delete" ), this, SLOT(deleteMe())); | ||
221 | if(Ir::supported()) | ||
222 | popmenue->insertItem( tr( "Beam" ), this, SLOT(beamMe())); | ||
223 | popmenue->popup( mapToGlobal( e->pos() )); | ||
224 | } | ||
202 | 225 | ||
203 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | 226 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, |
204 | const QDate &d, bool onM, | 227 | const QDate &d, bool onM, |
205 | QWidget* parent, | 228 | QWidget* parent, |
206 | const char* name, WFlags fl) | 229 | const char* name, WFlags fl) |
207 | : QWidget( parent, name, fl ) | 230 | : QWidget( parent, name, fl ) |
208 | { | 231 | { |
209 | Config config("DateBook"); | 232 | Config config("DateBook"); |
210 | config.setGroup("Main"); | 233 | config.setGroup("Main"); |
211 | int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); | 234 | int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); |
212 | odebug << "weeklistviewconfig: " << weeklistviewconfig << oendl; | 235 | odebug << "weeklistviewconfig: " << weeklistviewconfig << oendl; |
213 | 236 | ||
214 | bStartOnMonday=onM; | 237 | bStartOnMonday=onM; |
215 | setPalette(white); | 238 | setPalette(white); |
216 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); | 239 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); |
217 | 240 | ||
218 | QVBoxLayout *layout = new QVBoxLayout( this ); | 241 | QVBoxLayout *layout = new QVBoxLayout( this ); |
219 | 242 | ||
220 | qBubbleSort(ev); | 243 | qBubbleSort(ev); |
221 | QValueListIterator<EffectiveEvent> it; | 244 | QValueListIterator<EffectiveEvent> it; |
222 | it=ev.begin(); | 245 | it=ev.begin(); |
223 | 246 | ||
224 | int dayOrder[7]; | 247 | int dayOrder[7]; |
225 | if (bStartOnMonday) { | 248 | if (bStartOnMonday) { |
226 | for (int d=0; d<7; d++) dayOrder[d]=d+1; | 249 | for (int d=0; d<7; d++) dayOrder[d]=d+1; |
227 | } else { | 250 | } else { |
228 | for (int d=0; d<7; d++) dayOrder[d]=d; | 251 | for (int d=0; d<7; d++) dayOrder[d]=d; |
229 | dayOrder[0]=7; | 252 | dayOrder[0]=7; |
230 | } | 253 | } |
231 | 254 | ||
232 | // Calculate offset to first day of week. | 255 | // Calculate offset to first day of week. |
233 | int dayoffset=d.dayOfWeek(); | 256 | int dayoffset=d.dayOfWeek(); |
234 | if(bStartOnMonday) dayoffset--; | 257 | if(bStartOnMonday) dayoffset--; |
235 | else if( dayoffset == 7 ) dayoffset = 0; | 258 | else if( dayoffset == 7 ) dayoffset = 0; |
236 | 259 | ||
237 | for (int i=0; i<7; i++) { | 260 | for (int i=0; i<7; i++) { |
238 | // Header | 261 | // Header |
239 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); | 262 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); |
240 | connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 263 | connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
241 | connect(hdr, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), | 264 | connect(hdr, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), |
242 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); | 265 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); |
243 | layout->addWidget(hdr); | 266 | layout->addWidget(hdr); |
244 | 267 | ||
245 | // Events | 268 | // Events |
246 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { | 269 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { |
247 | if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. | 270 | if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. |
248 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); | 271 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); |
249 | layout->addWidget(l); | 272 | layout->addWidget(l); |
250 | connect (l, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); | 273 | connect (l, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); |
274 | connect (l, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); | ||
275 | connect (l, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); | ||
276 | connect (l, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); | ||
277 | connect (l, SIGNAL(redraw()), this, SIGNAL(redraw())); | ||
251 | } | 278 | } |
252 | it++; | 279 | it++; |
253 | } | 280 | } |
254 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); | 281 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
255 | } | 282 | } |
256 | } | 283 | } |
257 | DateBookWeekLstView::~DateBookWeekLstView(){} | 284 | DateBookWeekLstView::~DateBookWeekLstView(){} |
258 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} | 285 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} |
259 | 286 | ||
260 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 287 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
261 | QValueList<EffectiveEvent> &ev2, | 288 | QValueList<EffectiveEvent> &ev2, |
262 | QDate &d, bool onM, | 289 | QDate &d, bool onM, |
263 | QWidget* parent, | 290 | QWidget* parent, |
264 | const char* name, WFlags fl) | 291 | const char* name, WFlags fl) |
265 | : QWidget( parent, name, fl ) | 292 | : QWidget( parent, name, fl ) |
266 | { | 293 | { |
267 | QHBoxLayout *layout = new QHBoxLayout( this ); | 294 | QHBoxLayout *layout = new QHBoxLayout( this ); |
268 | 295 | ||
269 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); | 296 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); |
270 | layout->addWidget(w); | 297 | layout->addWidget(w); |
271 | connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); | 298 | connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); |
299 | connect (w, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); | ||
300 | connect (w, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); | ||
301 | connect (w, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); | ||
302 | connect (w, SIGNAL(redraw()), this, SIGNAL(redraw())); | ||
272 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 303 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
273 | connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), | 304 | connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), |
274 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); | 305 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); |
275 | 306 | ||
276 | 307 | ||
277 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); | 308 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); |
278 | layout->addWidget(w); | 309 | layout->addWidget(w); |
279 | connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); | 310 | connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); |
311 | connect (w, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); | ||
312 | connect (w, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); | ||
313 | connect (w, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); | ||
314 | connect (w, SIGNAL(redraw()), this, SIGNAL(redraw())); | ||
280 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 315 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
281 | connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), | 316 | connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), |
282 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); | 317 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); |
283 | } | 318 | } |
284 | 319 | ||
285 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, | 320 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, |
286 | QWidget *parent, | 321 | QWidget *parent, |
287 | const char *name ) | 322 | const char *name ) |
288 | : QWidget( parent, name ), | 323 | : QWidget( parent, name ), |
289 | db( newDB ), | 324 | db( newDB ), |
290 | startTime( 0 ), | 325 | startTime( 0 ), |
291 | ampm( ap ), | 326 | ampm( ap ), |
292 | bStartOnMonday(onM) | 327 | bStartOnMonday(onM) |
293 | { | 328 | { |
294 | setFocusPolicy(StrongFocus); | 329 | setFocusPolicy(StrongFocus); |
295 | layout = new QVBoxLayout( this ); | 330 | layout = new QVBoxLayout( this ); |
296 | layout->setMargin(0); | 331 | layout->setMargin(0); |
297 | 332 | ||
298 | header=new DateBookWeekLstHeader(onM, this); | 333 | header=new DateBookWeekLstHeader(onM, this); |
299 | layout->addWidget( header ); | 334 | layout->addWidget( header ); |
300 | connect(header, SIGNAL(dateChanged(QDate&)), this, SLOT(dateChanged(QDate&))); | 335 | connect(header, SIGNAL(dateChanged(QDate&)), this, SLOT(dateChanged(QDate&))); |
301 | connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); | 336 | connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); |
302 | 337 | ||
303 | scroll=new QScrollView(this); | 338 | scroll=new QScrollView(this); |
304 | scroll->setResizePolicy(QScrollView::AutoOneFit); | 339 | scroll->setResizePolicy(QScrollView::AutoOneFit); |
305 | layout->addWidget(scroll); | 340 | layout->addWidget(scroll); |
306 | 341 | ||
307 | view=NULL; | 342 | view=NULL; |
308 | Config config("DateBook"); | 343 | Config config("DateBook"); |
309 | config.setGroup("Main"); | 344 | config.setGroup("Main"); |
310 | dbl=config.readBoolEntry("weeklst_dbl", false); | 345 | dbl=config.readBoolEntry("weeklst_dbl", false); |
311 | header->dbl->setOn(dbl); | 346 | header->dbl->setOn(dbl); |
312 | } | 347 | } |
313 | DateBookWeekLst::~DateBookWeekLst(){ | 348 | DateBookWeekLst::~DateBookWeekLst(){ |
314 | Config config("DateBook"); | 349 | Config config("DateBook"); |
315 | config.setGroup("Main"); | 350 | config.setGroup("Main"); |
316 | config.writeEntry("weeklst_dbl", dbl); | 351 | config.writeEntry("weeklst_dbl", dbl); |
317 | } | 352 | } |
318 | 353 | ||
319 | void DateBookWeekLst::setDate(const QDate &d) { | 354 | void DateBookWeekLst::setDate(const QDate &d) { |
320 | bdate=d; | 355 | bdate=d; |
321 | header->setDate(d); | 356 | header->setDate(d); |
322 | } | 357 | } |
323 | 358 | ||
324 | void DateBookWeekLst::setDbl(bool on) { | 359 | void DateBookWeekLst::setDbl(bool on) { |
325 | dbl=on; | 360 | dbl=on; |
326 | redraw(); | 361 | redraw(); |
327 | } | 362 | } |
328 | void DateBookWeekLst::redraw() {getEvents();} | 363 | void DateBookWeekLst::redraw() {getEvents();} |
329 | 364 | ||
330 | QDate DateBookWeekLst::date() { | 365 | QDate DateBookWeekLst::date() { |
331 | return bdate; | 366 | return bdate; |
332 | } | 367 | } |
333 | 368 | ||
334 | // return the date at the beginning of the week... | 369 | // return the date at the beginning of the week... |
335 | // copied from DateBookWeek | 370 | // copied from DateBookWeek |
336 | QDate DateBookWeekLst::weekDate() const | 371 | QDate DateBookWeekLst::weekDate() const |
337 | { | 372 | { |
338 | QDate d=bdate; | 373 | QDate d=bdate; |
339 | 374 | ||
340 | // Calculate offset to first day of week. | 375 | // Calculate offset to first day of week. |
341 | int dayoffset=d.dayOfWeek(); | 376 | int dayoffset=d.dayOfWeek(); |
342 | if(bStartOnMonday) dayoffset--; | 377 | if(bStartOnMonday) dayoffset--; |
343 | else if( dayoffset == 7 ) | 378 | else if( dayoffset == 7 ) |
344 | dayoffset = 0; | 379 | dayoffset = 0; |
345 | 380 | ||
346 | return d.addDays(-dayoffset); | 381 | return d.addDays(-dayoffset); |
347 | } | 382 | } |
348 | 383 | ||
349 | void DateBookWeekLst::getEvents() { | 384 | void DateBookWeekLst::getEvents() { |
350 | QDate start = weekDate(); //date(); | 385 | QDate start = weekDate(); //date(); |
351 | QDate stop = start.addDays(6); | 386 | QDate stop = start.addDays(6); |
352 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); | 387 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); |
353 | 388 | ||
354 | if (view) delete view; | 389 | if (view) delete view; |
355 | if (dbl) { | 390 | if (dbl) { |
356 | QDate start2=start.addDays(7); | 391 | QDate start2=start.addDays(7); |
357 | stop=start2.addDays(6); | 392 | stop=start2.addDays(6); |
358 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); | 393 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); |
359 | view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); | 394 | view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); |
360 | } else { | 395 | } else { |
361 | view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); | 396 | view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); |
362 | } | 397 | } |
363 | 398 | ||
364 | connect (view, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); | 399 | connect (view, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); |
400 | connect (view, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); | ||
401 | connect (view, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); | ||
402 | connect (view, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); | ||
403 | connect (view, SIGNAL(redraw()), this, SLOT(redraw())); | ||
365 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 404 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
366 | connect (view, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), | 405 | connect (view, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), |
367 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); | 406 | this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); |
368 | 407 | ||
369 | scroll->addChild(view); | 408 | scroll->addChild(view); |
370 | view->show(); | 409 | view->show(); |
371 | scroll->updateScrollBars(); | 410 | scroll->updateScrollBars(); |
372 | } | 411 | } |
373 | 412 | ||
374 | void DateBookWeekLst::dateChanged(QDate &newdate) { | 413 | void DateBookWeekLst::dateChanged(QDate &newdate) { |
375 | bdate=newdate; | 414 | bdate=newdate; |
376 | getEvents(); | 415 | getEvents(); |
377 | } | 416 | } |
378 | 417 | ||
379 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) | 418 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) |
380 | { | 419 | { |
381 | switch(e->key()) { | 420 | switch(e->key()) { |
382 | case Key_Up: | 421 | case Key_Up: |
383 | scroll->scrollBy(0, -20); | 422 | scroll->scrollBy(0, -20); |
384 | break; | 423 | break; |
385 | case Key_Down: | 424 | case Key_Down: |
386 | scroll->scrollBy(0, 20); | 425 | scroll->scrollBy(0, 20); |
387 | break; | 426 | break; |
388 | case Key_Left: | 427 | case Key_Left: |
389 | header->prevWeek(); | 428 | header->prevWeek(); |
390 | break; | 429 | break; |
391 | case Key_Right: | 430 | case Key_Right: |
392 | header->nextWeek(); | 431 | header->nextWeek(); |
393 | break; | 432 | break; |
394 | default: | 433 | default: |
395 | e->ignore(); | 434 | e->ignore(); |
396 | } | 435 | } |
397 | } | 436 | } |
diff --git a/core/pim/datebook/datebookweeklst.h b/core/pim/datebook/datebookweeklst.h index 32fa23f..3bc7f2f 100644 --- a/core/pim/datebook/datebookweeklst.h +++ b/core/pim/datebook/datebookweeklst.h | |||
@@ -1,156 +1,177 @@ | |||
1 | #ifndef DATEBOOKWEEKLST | 1 | #ifndef DATEBOOKWEEKLST |
2 | #define DATEBOOKWEEKLST | 2 | #define DATEBOOKWEEKLST |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qdatetime.h> | 5 | #include <qdatetime.h> |
6 | #include <qpe/event.h> | 6 | #include <qpe/event.h> |
7 | #include <qlabel.h> | 7 | #include <qlabel.h> |
8 | #include <qscrollview.h> | 8 | #include <qscrollview.h> |
9 | 9 | ||
10 | #include "datebookweeklstheader.h" | 10 | #include "datebookweeklstheader.h" |
11 | #include "datebookweeklstdayhdr.h" | 11 | #include "datebookweeklstdayhdr.h" |
12 | 12 | ||
13 | #include <opie2/oclickablelabel.h> | 13 | #include <opie2/oclickablelabel.h> |
14 | 14 | ||
15 | class QDateTime; | 15 | class QDateTime; |
16 | class DateBookDB; | 16 | class DateBookDB; |
17 | 17 | ||
18 | class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase | 18 | class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase |
19 | { | 19 | { |
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | public: | 21 | public: |
22 | DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, | 22 | DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, |
23 | WFlags fl = 0 ); | 23 | WFlags fl = 0 ); |
24 | ~DateBookWeekLstHeader(); | 24 | ~DateBookWeekLstHeader(); |
25 | void setDate(const QDate &d); | 25 | void setDate(const QDate &d); |
26 | 26 | ||
27 | public slots: | 27 | public slots: |
28 | void nextWeek(); | 28 | void nextWeek(); |
29 | void prevWeek(); | 29 | void prevWeek(); |
30 | void nextMonth(); | 30 | void nextMonth(); |
31 | void prevMonth(); | 31 | void prevMonth(); |
32 | void pickDate(); | 32 | void pickDate(); |
33 | void setDate(int y, int m, int d); | 33 | void setDate(int y, int m, int d); |
34 | signals: | 34 | signals: |
35 | void dateChanged(QDate &newdate); | 35 | void dateChanged(QDate &newdate); |
36 | void setDbl(bool on); | 36 | void setDbl(bool on); |
37 | private: | 37 | private: |
38 | QDate date; | 38 | QDate date; |
39 | //bool onMonday; | 39 | //bool onMonday; |
40 | bool bStartOnMonday; | 40 | bool bStartOnMonday; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase | 43 | class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | public: | 46 | public: |
47 | DateBookWeekLstDayHdr(const QDate &d, bool onM, | 47 | DateBookWeekLstDayHdr(const QDate &d, bool onM, |
48 | QWidget* parent = 0, const char* name = 0, | 48 | QWidget* parent = 0, const char* name = 0, |
49 | WFlags fl = 0 ); | 49 | WFlags fl = 0 ); |
50 | public slots: | 50 | public slots: |
51 | void showDay(); | 51 | void showDay(); |
52 | void newEvent(); | 52 | void newEvent(); |
53 | signals: | 53 | signals: |
54 | void showDate(int y, int m, int d); | 54 | void showDate(int y, int m, int d); |
55 | void addEvent(const QDateTime &start, const QDateTime &stop, | 55 | void addEvent(const QDateTime &start, const QDateTime &stop, |
56 | const QString &str, const QString &location); | 56 | const QString &str, const QString &location); |
57 | private: | 57 | private: |
58 | QDate date; | 58 | QDate date; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | class DateBookWeekLstEvent: public Opie::Ui::OClickableLabel | 61 | class DateBookWeekLstEvent: public Opie::Ui::OClickableLabel |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, | 65 | DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, |
66 | QWidget* parent = 0, const char* name = 0, | 66 | QWidget* parent = 0, const char* name = 0, |
67 | WFlags fl = 0); | 67 | WFlags fl = 0); |
68 | signals: | 68 | signals: |
69 | void editEvent(const Event &e); | 69 | void editEvent(const Event &e); |
70 | void duplicateEvent(const Event &e); | ||
71 | void removeEvent(const Event &e); | ||
72 | void beamEvent(const Event &e); | ||
73 | void redraw(); | ||
70 | private slots: | 74 | private slots: |
71 | void editMe(); | 75 | void editMe(); |
76 | void duplicateMe(); | ||
77 | void deleteMe(); | ||
78 | void beamMe(); | ||
72 | private: | 79 | private: |
73 | const EffectiveEvent event; | 80 | const EffectiveEvent event; |
81 | QPopupMenu* popmenue; | ||
82 | protected: | ||
83 | void mousePressEvent( QMouseEvent *e ); | ||
74 | }; | 84 | }; |
75 | 85 | ||
76 | class DateBookWeekLstView: public QWidget | 86 | class DateBookWeekLstView: public QWidget |
77 | { | 87 | { |
78 | Q_OBJECT | 88 | Q_OBJECT |
79 | public: | 89 | public: |
80 | DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, | 90 | DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, |
81 | QWidget* parent = 0, const char* name = 0, | 91 | QWidget* parent = 0, const char* name = 0, |
82 | WFlags fl = 0 ); | 92 | WFlags fl = 0 ); |
83 | ~DateBookWeekLstView(); | 93 | ~DateBookWeekLstView(); |
84 | signals: | 94 | signals: |
85 | void editEvent(const Event &e); | 95 | void editEvent(const Event &e); |
96 | void duplicateEvent(const Event &e); | ||
97 | void removeEvent(const Event &e); | ||
98 | void beamEvent(const Event &e); | ||
99 | void redraw(); | ||
86 | void showDate(int y, int m, int d); | 100 | void showDate(int y, int m, int d); |
87 | void addEvent(const QDateTime &start, const QDateTime &stop, | 101 | void addEvent(const QDateTime &start, const QDateTime &stop, |
88 | const QString &str, const QString &location); | 102 | const QString &str, const QString &location); |
89 | private: | 103 | private: |
90 | bool bStartOnMonday; | 104 | bool bStartOnMonday; |
91 | protected slots: | 105 | protected slots: |
92 | void keyPressEvent(QKeyEvent *); | 106 | void keyPressEvent(QKeyEvent *); |
93 | }; | 107 | }; |
94 | 108 | ||
95 | class DateBookWeekLstDblView: public QWidget { | 109 | class DateBookWeekLstDblView: public QWidget { |
96 | Q_OBJECT | 110 | Q_OBJECT |
97 | public: | 111 | public: |
98 | DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 112 | DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
99 | QValueList<EffectiveEvent> &ev2, | 113 | QValueList<EffectiveEvent> &ev2, |
100 | QDate &d, bool onM, | 114 | QDate &d, bool onM, |
101 | QWidget* parent = 0, const char* name = 0, | 115 | QWidget* parent = 0, const char* name = 0, |
102 | WFlags fl = 0 ); | 116 | WFlags fl = 0 ); |
103 | signals: | 117 | signals: |
104 | void editEvent(const Event &e); | 118 | void editEvent(const Event &e); |
119 | void duplicateEvent(const Event &e); | ||
120 | void removeEvent(const Event &e); | ||
121 | void beamEvent(const Event &e); | ||
122 | void redraw(); | ||
105 | void showDate(int y, int m, int d); | 123 | void showDate(int y, int m, int d); |
106 | void addEvent(const QDateTime &start, const QDateTime &stop, | 124 | void addEvent(const QDateTime &start, const QDateTime &stop, |
107 | const QString &str, const QString &location); | 125 | const QString &str, const QString &location); |
108 | }; | 126 | }; |
109 | 127 | ||
110 | class DateBookWeekLst : public QWidget | 128 | class DateBookWeekLst : public QWidget |
111 | { | 129 | { |
112 | Q_OBJECT | 130 | Q_OBJECT |
113 | 131 | ||
114 | public: | 132 | public: |
115 | DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, | 133 | DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, |
116 | QWidget *parent = 0, | 134 | QWidget *parent = 0, |
117 | const char *name = 0 ); | 135 | const char *name = 0 ); |
118 | ~DateBookWeekLst(); | 136 | ~DateBookWeekLst(); |
119 | void setDate( int y, int w ); | 137 | void setDate( int y, int w ); |
120 | void setDate(const QDate &d ); | 138 | void setDate(const QDate &d ); |
121 | int week() const { return _week; }; | 139 | int week() const { return _week; }; |
122 | QDate date(); | 140 | QDate date(); |
123 | QDate weekDate() const; | 141 | QDate weekDate() const; |
124 | 142 | ||
125 | public slots: | 143 | public slots: |
126 | void redraw(); | 144 | void redraw(); |
127 | void dateChanged(QDate &date); | 145 | void dateChanged(QDate &date); |
128 | 146 | ||
129 | protected slots: | 147 | protected slots: |
130 | void keyPressEvent(QKeyEvent *); | 148 | void keyPressEvent(QKeyEvent *); |
131 | void setDbl(bool on); | 149 | void setDbl(bool on); |
132 | 150 | ||
133 | signals: | 151 | signals: |
134 | void showDate(int y, int m, int d); | 152 | void showDate(int y, int m, int d); |
135 | void addEvent(const QDateTime &start, const QDateTime &stop, | 153 | void addEvent(const QDateTime &start, const QDateTime &stop, |
136 | const QString &str, const QString &location); | 154 | const QString &str, const QString &location); |
137 | void editEvent(const Event &e); | 155 | void editEvent(const Event &e); |
156 | void duplicateEvent(const Event &e); | ||
157 | void removeEvent(const Event &e); | ||
158 | void beamEvent(const Event &e); | ||
138 | 159 | ||
139 | private: | 160 | private: |
140 | DateBookDB *db; | 161 | DateBookDB *db; |
141 | int startTime; | 162 | int startTime; |
142 | bool ampm; | 163 | bool ampm; |
143 | bool bStartOnMonday; | 164 | bool bStartOnMonday; |
144 | bool dbl; | 165 | bool dbl; |
145 | QDate bdate; | 166 | QDate bdate; |
146 | int year, _week,dow; | 167 | int year, _week,dow; |
147 | DateBookWeekLstHeader *header; | 168 | DateBookWeekLstHeader *header; |
148 | QWidget *view; | 169 | QWidget *view; |
149 | QVBoxLayout *layout; | 170 | QVBoxLayout *layout; |
150 | QScrollView *scroll; | 171 | QScrollView *scroll; |
151 | 172 | ||
152 | void getEvents(); | 173 | void getEvents(); |
153 | }; | 174 | }; |
154 | 175 | ||
155 | #endif | 176 | #endif |
156 | 177 | ||