summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Unidiff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp8
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp8
-rw-r--r--libopie2/opiepim/ui/opimrecurrencewidget.cpp4
3 files changed, 10 insertions, 10 deletions
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index c12e138..4f9b504 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,152 +1,152 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: XML-Backend: Automatic reload if something was changed... 31 * ToDo: XML-Backend: Automatic reload if something was changed...
32 * 32 *
33 * 33 *
34 */ 34 */
35 35
36#include "ocontactaccess.h" 36#include "ocontactaccess.h"
37#include "obackendfactory.h" 37#include "obackendfactory.h"
38 38
39#include <qasciidict.h> 39#include <qasciidict.h>
40#include <qdatetime.h> 40#include <qdatetime.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qregexp.h> 42#include <qregexp.h>
43#include <qlist.h> 43#include <qlist.h>
44#include <qcopchannel_qws.h> 44#include <qcopchannel_qws.h>
45 45
46//#include <qpe/qcopenvelope_qws.h> 46//#include <qpe/qcopenvelope_qws.h>
47#include <qpe/global.h> 47#include <qpe/global.h>
48 48
49#include <errno.h> 49#include <errno.h>
50#include <fcntl.h> 50#include <fcntl.h>
51#include <unistd.h> 51#include <unistd.h>
52#include <stdlib.h> 52#include <stdlib.h>
53 53
54#include <opie2/ocontactaccessbackend_xml.h> 54#include <opie2/ocontactaccessbackend_xml.h>
55 55
56namespace Opie { 56namespace Opie {
57 57
58OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 58OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
59 OPimContactAccessBackend* end, bool autosync ): 59 OPimContactAccessBackend* end, bool autosync ):
60 OPimAccessTemplate<OPimContact>( end ) 60 OPimAccessTemplate<OPimContact>( end )
61{ 61{
62 /* take care of the backend. If there is no one defined, we 62 /* take care of the backend. If there is no one defined, we
63 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 63 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
64 */ 64 */
65 if( end == 0 ) { 65 if( end == 0 ) {
66 qWarning ("Using BackendFactory !"); 66 qWarning ("Using BackendFactory !");
67 end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname ); 67 end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname );
68 } 68 }
69 // Set backend locally and in template 69 // Set backend locally and in template
70 m_backEnd = end; 70 m_backEnd = end;
71 OPimAccessTemplate<OPimContact>::setBackEnd (end); 71 OPimAccessTemplate<OPimContact>::setBackEnd (end);
72 72
73 73
74 /* Connect signal of external db change to function */ 74 /* Connect signal of external db change to function */
75 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 75 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
76 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), 76 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
77 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 77 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
78 if ( autosync ){ 78 if ( autosync ){
79 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 79 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
80 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), 80 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
81 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 81 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
82 } 82 }
83 83
84 84
85} 85}
86OPimContactAccess::~OPimContactAccess () 86OPimContactAccess::~OPimContactAccess ()
87{ 87{
88 /* The user may forget to save the changed database, therefore try to 88 /* The user may forget to save the changed database, therefore try to
89 * do it for him.. 89 * do it for him..
90 */ 90 */
91 save(); 91 save();
92 // delete m_backEnd; is done by template.. 92 // delete m_backEnd; is done by template..
93} 93}
94 94
95 95
96bool OPimContactAccess::save () 96bool OPimContactAccess::save ()
97{ 97{
98 /* If the database was changed externally, we could not save the 98 /* If the database was changed externally, we could not save the
99 * Data. This will remove added items which is unacceptable ! 99 * Data. This will remove added items which is unacceptable !
100 * Therefore: Reload database and merge the data... 100 * Therefore: Reload database and merge the data...
101 */ 101 */
102 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) 102 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
103 reload(); 103 reload();
104 104
105 bool status = OPimAccessTemplate<OPimContact>::save(); 105 bool status = OPimAccessTemplate<OPimContact>::save();
106 if ( !status ) return false; 106 if ( !status ) return false;
107 107
108 /* Now tell everyone that new data is available. 108 /* Now tell everyone that new data is available.
109 */ 109 */
110 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 110 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
111 111
112 return true; 112 return true;
113} 113}
114 114
115const uint OPimContactAccess::querySettings() 115const uint OPimContactAccess::querySettings()
116{ 116{
117 return ( m_backEnd->querySettings() ); 117 return ( m_backEnd->querySettings() );
118} 118}
119 119
120bool OPimContactAccess::hasQuerySettings ( int querySettings ) const 120bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
121{ 121{
122 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 122 return ( m_backEnd->hasQuerySettings ( querySettings ) );
123} 123}
124OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 124OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
125{ 125{
126 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 126 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
127 return ( OPimRecordList<OPimContact>(matchingContacts, this) ); 127 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
128} 128}
129 129
130 130
131bool OPimContactAccess::wasChangedExternally()const 131bool OPimContactAccess::wasChangedExternally()const
132{ 132{
133 return ( m_backEnd->wasChangedExternally() ); 133 return ( m_backEnd->wasChangedExternally() );
134} 134}
135 135
136 136
137void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 137void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
138{ 138{
139 if ( msg == "addressbookUpdated()" ){ 139 if ( msg == "addressbookUpdated()" ){
140 qWarning ("OPimContactAccess: Received addressbokUpdated()"); 140 qWarning ("OPimContactAccess: Received addressbokUpdated()");
141 emit signalChanged ( this ); 141 emit signalChanged ( this );
142 } else if ( msg == "flush()" ) { 142 } else if ( msg == "flush()" ) {
143 qWarning ("OPimContactAccess: Received flush()"); 143 qWarning ("OPimContactAccess: Received flush()");
144 save (); 144 save ();
145 } else if ( msg == "reload()" ) { 145 } else if ( msg == "reload()" ) {
146 qWarning ("OPimContactAccess: Received reload()"); 146 qWarning ("OPimContactAccess: Received reload()");
147 reload (); 147 reload ();
148 emit signalChanged ( this ); 148 emit signalChanged ( this );
149 } 149 }
150} 150}
151 151
152} 152}
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp
index 10ed743..40dc297 100644
--- a/libopie2/opiepim/ui/opimmainwindow.cpp
+++ b/libopie2/opiepim/ui/opimmainwindow.cpp
@@ -1,181 +1,181 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#include <qapplication.h> 29#include <qapplication.h>
30#include <qdatetime.h> 30#include <qdatetime.h>
31#include <qcopchannel_qws.h> 31#include <qcopchannel_qws.h>
32 32
33#include <qpe/sound.h> 33#include <qpe/sound.h>
34#include <qpe/qcopenvelope_qws.h> 34#include <qpe/qcopenvelope_qws.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36 36
37#include <opie2/opimresolver.h> 37#include <opie2/opimresolver.h>
38#include "opimmainwindow.h" 38#include "opimmainwindow.h"
39 39
40namespace Opie { 40namespace Opie {
41OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 41OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
42 const char* name, WFlags flag ) 42 const char* name, WFlags flag )
43 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { 43 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) {
44 44
45 /* 45 /*
46 * let's generate our QCopChannel 46 * let's generate our QCopChannel
47 */ 47 */
48 m_str = QString("QPE/"+m_service).local8Bit(); 48 m_str = QString("QPE/"+m_service).local8Bit();
49 m_channel= new QCopChannel(m_str, this ); 49 m_channel= new QCopChannel(m_str, this );
50 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), 50 connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&) ),
51 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 51 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
52 connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), 52 connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&) ),
53 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 53 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
54 54
55 /* connect flush and reload */ 55 /* connect flush and reload */
56 connect(qApp, SIGNAL(flush() ), 56 connect(qApp, SIGNAL(flush() ),
57 this, SLOT(flush() ) ); 57 this, SLOT(flush() ) );
58 connect(qApp, SIGNAL(reload() ), 58 connect(qApp, SIGNAL(reload() ),
59 this, SLOT(reload() ) ); 59 this, SLOT(reload() ) );
60} 60}
61OPimMainWindow::~OPimMainWindow() { 61OPimMainWindow::~OPimMainWindow() {
62 delete m_channel; 62 delete m_channel;
63} 63}
64QCopChannel* OPimMainWindow::channel() { 64QCopChannel* OPimMainWindow::channel() {
65 return m_channel; 65 return m_channel;
66} 66}
67void OPimMainWindow::doSetDocument( const QString& ) { 67void OPimMainWindow::doSetDocument( const QString& ) {
68 68
69} 69}
70void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 70void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
71 bool needShow = false; 71 bool needShow = false;
72 /* 72 /*
73 * create demands to create 73 * create demands to create
74 * a new record... 74 * a new record...
75 */ 75 */
76 QDataStream stream(array, IO_ReadOnly); 76 QDataStream stream(array, IO_ReadOnly);
77 if ( cmd == "create()" ) { 77 if ( cmd == "create()" ) {
78 raise(); 78 raise();
79 int uid = create(); 79 int uid = create();
80 QCopEnvelope e(m_str, "created(int)" ); 80 QCopEnvelope e(m_str, "created(int)" );
81 e << uid; 81 e << uid;
82 needShow = true; 82 needShow = true;
83 }else if ( cmd == "remove(int)" ) { 83 }else if ( cmd == "remove(int)" ) {
84 int uid; 84 int uid;
85 stream >> uid; 85 stream >> uid;
86 bool rem = remove( uid ); 86 bool rem = remove( uid );
87 QCopEnvelope e(m_str, "removed(bool)" ); 87 QCopEnvelope e(m_str, "removed(bool)" );
88 e << rem; 88 e << rem;
89 needShow = true; 89 needShow = true;
90 }else if ( cmd == "beam(int)" ) { 90 }else if ( cmd == "beam(int)" ) {
91 int uid; 91 int uid;
92 stream >> uid; 92 stream >> uid;
93 beam( uid); 93 beam( uid);
94 }else if ( cmd == "show(int)" ) { 94 }else if ( cmd == "show(int)" ) {
95 raise(); 95 raise();
96 int uid; 96 int uid;
97 stream >> uid; 97 stream >> uid;
98 show( uid ); 98 show( uid );
99 needShow = true; 99 needShow = true;
100 }else if ( cmd == "edit(int)" ) { 100 }else if ( cmd == "edit(int)" ) {
101 raise(); 101 raise();
102 int uid; 102 int uid;
103 stream >> uid; 103 stream >> uid;
104 edit( uid ); 104 edit( uid );
105 }else if ( cmd == "add(int,QByteArray)" ) { 105 }else if ( cmd == "add(int,QByteArray)" ) {
106 int rtti; 106 int rtti;
107 QByteArray array; 107 QByteArray array;
108 stream >> rtti; 108 stream >> rtti;
109 stream >> array; 109 stream >> array;
110 m_fallBack = record(rtti, array ); 110 m_fallBack = record(rtti, array );
111 if (!m_fallBack) return; 111 if (!m_fallBack) return;
112 add( *m_fallBack ); 112 add( *m_fallBack );
113 delete m_fallBack; 113 delete m_fallBack;
114 }else if ( cmd == "alarm(QDateTime,int)" ) { 114 }else if ( cmd == "alarm(QDateTime,int)" ) {
115 raise(); 115 raise();
116 QDateTime dt; int uid; 116 QDateTime dt; int uid;
117 stream >> dt; 117 stream >> dt;
118 stream >> uid; 118 stream >> uid;
119 qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); 119 qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid );
120 QDateTime current = QDateTime::currentDateTime(); 120 QDateTime current = QDateTime::currentDateTime();
121 if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) 121 if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() )
122 return; 122 return;
123 doAlarm( dt, uid ); 123 doAlarm( dt, uid );
124 needShow = true; 124 needShow = true;
125 } 125 }
126 126
127 if (needShow ) 127 if (needShow )
128 QPEApplication::setKeepRunning(); 128 QPEApplication::setKeepRunning();
129} 129}
130/* implement the url scripting here */ 130/* implement the url scripting here */
131void OPimMainWindow::setDocument( const QString& str) { 131void OPimMainWindow::setDocument( const QString& str) {
132 doSetDocument( str ); 132 doSetDocument( str );
133} 133}
134/* 134/*
135 * we now try to get the array demarshalled 135 * we now try to get the array demarshalled
136 * check if the rtti matches this one 136 * check if the rtti matches this one
137 */ 137 */
138OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { 138OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
139 if ( service() != rtti ) 139 if ( service() != rtti )
140 return 0l; 140 return 0l;
141 141
142 OPimRecord* record = OPimResolver::self()->record( rtti ); 142 OPimRecord* record = OPimResolver::self()->record( rtti );
143 QDataStream str(array, IO_ReadOnly ); 143 QDataStream str(array, IO_ReadOnly );
144 if ( !record || !record->loadFromStream(str) ) { 144 if ( !record || !record->loadFromStream(str) ) {
145 delete record; 145 delete record;
146 record = 0l; 146 record = 0l;
147 } 147 }
148 148
149 return record; 149 return record;
150} 150}
151/* 151/*
152 * get the rtti for the service 152 * get the rtti for the service
153 */ 153 */
154int OPimMainWindow::service() { 154int OPimMainWindow::service() {
155 if ( m_rtti == -1 ) 155 if ( m_rtti == -1 )
156 m_rtti = OPimResolver::self()->serviceId( m_service ); 156 m_rtti = OPimResolver::self()->serviceId( m_service );
157 157
158 return m_rtti; 158 return m_rtti;
159} 159}
160void OPimMainWindow::doAlarm( const QDateTime&, int ) { 160void OPimMainWindow::doAlarm( const QDateTime&, int ) {
161 161
162} 162}
163void OPimMainWindow::startAlarm(int count ) { 163void OPimMainWindow::startAlarm(int count ) {
164 m_alarmCount = count; 164 m_alarmCount = count;
165 m_playedCount = 0; 165 m_playedCount = 0;
166 Sound::soundAlarm(); 166 Sound::soundAlarm();
167 m_timerId = startTimer( 5000 ); 167 m_timerId = startTimer( 5000 );
168} 168}
169void OPimMainWindow::killAlarm() { 169void OPimMainWindow::killAlarm() {
170 killTimer( m_timerId ); 170 killTimer( m_timerId );
171} 171}
172void OPimMainWindow::timerEvent( QTimerEvent* e) { 172void OPimMainWindow::timerEvent( QTimerEvent* e) {
173 if ( m_playedCount <m_alarmCount ) { 173 if ( m_playedCount <m_alarmCount ) {
174 m_playedCount++; 174 m_playedCount++;
175 Sound::soundAlarm(); 175 Sound::soundAlarm();
176 }else { 176 }else {
177 killTimer( e->timerId() ); 177 killTimer( e->timerId() );
178 } 178 }
179} 179}
180 180
181} 181}
diff --git a/libopie2/opiepim/ui/opimrecurrencewidget.cpp b/libopie2/opiepim/ui/opimrecurrencewidget.cpp
index 569bdd5..90c1a5f 100644
--- a/libopie2/opiepim/ui/opimrecurrencewidget.cpp
+++ b/libopie2/opiepim/ui/opimrecurrencewidget.cpp
@@ -1,634 +1,634 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qlabel.h> 2#include <qlabel.h>
3#include <qpopupmenu.h> 3#include <qpopupmenu.h>
4#include <qspinbox.h> 4#include <qspinbox.h>
5 5
6#include <qpe/timestring.h> 6#include <qpe/timestring.h>
7 7
8#include "opimrecurrencewidget.h" 8#include "opimrecurrencewidget.h"
9 9
10// Global Templates for use in setting up the repeat label... 10// Global Templates for use in setting up the repeat label...
11// the problem is these strings get initialized before QPEApplication can install the translator -zecke 11// the problem is these strings get initialized before QPEApplication can install the translator -zecke
12namespace { 12namespace {
13QString strDayTemplate; 13QString strDayTemplate;
14QString strYearTemplate; 14QString strYearTemplate;
15QString strMonthDateTemplate; 15QString strMonthDateTemplate;
16QString strMonthDayTemplate; 16QString strMonthDayTemplate;
17QString strWeekTemplate; 17QString strWeekTemplate;
18QString dayLabel[7]; 18QString dayLabel[7];
19} 19}
20 20
21/* 21/*
22 * static linkage to not polute the symbol table... 22 * static linkage to not polute the symbol table...
23 * The problem is that const and static linkage are resolved prior to installing a translator 23 * The problem is that const and static linkage are resolved prior to installing a translator
24 * leading to that the above strings are translted but to the original we delay the init of these strings... 24 * leading to that the above strings are translted but to the original we delay the init of these strings...
25 * -zecke 25 * -zecke
26 */ 26 */
27static void fillStrings() { 27static void fillStrings() {
28 strDayTemplate = QObject::tr("Every"); 28 strDayTemplate = QObject::tr("Every");
29 strYearTemplate = QObject::tr("%1 %2 every "); 29 strYearTemplate = QObject::tr("%1 %2 every ");
30 strMonthDateTemplate = QObject::tr("The %1 every "); 30 strMonthDateTemplate = QObject::tr("The %1 every ");
31 strMonthDayTemplate = QObject::tr("The %1 %2 of every"); 31 strMonthDayTemplate = QObject::tr("The %1 %2 of every");
32 strWeekTemplate = QObject::tr("Every "); 32 strWeekTemplate = QObject::tr("Every ");
33 dayLabel[0] = QObject::tr("Monday"); 33 dayLabel[0] = QObject::tr("Monday");
34 dayLabel[1] = QObject::tr("Tuesday"); 34 dayLabel[1] = QObject::tr("Tuesday");
35 dayLabel[2] = QObject::tr("Wednesday"); 35 dayLabel[2] = QObject::tr("Wednesday");
36 dayLabel[3] = QObject::tr("Thursday"); 36 dayLabel[3] = QObject::tr("Thursday");
37 dayLabel[4] = QObject::tr("Friday"); 37 dayLabel[4] = QObject::tr("Friday");
38 dayLabel[5] = QObject::tr("Saturday"); 38 dayLabel[5] = QObject::tr("Saturday");
39 dayLabel[6] = QObject::tr("Sunday"); 39 dayLabel[6] = QObject::tr("Sunday");
40} 40}
41 41
42 static QString numberPlacing( int x );// return the proper word format for 42 static QString numberPlacing( int x );// return the proper word format for
43 // x (1st, 2nd, etc) 43 // x (1st, 2nd, etc)
44static int week( const QDate &dt ); // what week in the month is dt? 44static int week( const QDate &dt ); // what week in the month is dt?
45 45
46/** 46/**
47 * Constructs the Widget 47 * Constructs the Widget
48 * @param startOnMonday Does the week start on monday 48 * @param startOnMonday Does the week start on monday
49 * @param newStart The start date of the recurrence 49 * @param newStart The start date of the recurrence
50 * @param parent The parent widget 50 * @param parent The parent widget
51 * @param name the name of object 51 * @param name the name of object
52 * @param modal if the dialog should be modal 52 * @param modal if the dialog should be modal
53 * @param fl Additional window flags 53 * @param fl Additional window flags
54 */ 54 */
55OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday, 55OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday,
56 const QDate& newStart, 56 const QDate& newStart,
57 QWidget* parent, 57 QWidget* parent,
58 const char* name, 58 const char* name,
59 bool modal, 59 bool modal,
60 WFlags fl ) 60 WFlags fl )
61 : OPimRecurrenceBase( parent, name, modal, fl ), 61 : OPimRecurrenceBase( parent, name, modal, fl ),
62 start( newStart ), 62 start( newStart ),
63 currInterval( None ), 63 currInterval( None ),
64 startWeekOnMonday( startOnMonday ) 64 startWeekOnMonday( startOnMonday )
65{ 65{
66 if (strDayTemplate.isEmpty() ) 66 if (strDayTemplate.isEmpty() )
67 fillStrings(); 67 fillStrings();
68 68
69 init(); 69 init();
70 fraType->setButton( currInterval ); 70 fraType->setButton( currInterval );
71 chkNoEnd->setChecked( TRUE ); 71 chkNoEnd->setChecked( TRUE );
72 setupNone(); 72 setupNone();
73} 73}
74 74
75/** 75/**
76 * Different constructor 76 * Different constructor
77 * @param startOnMonday Does the week start on monday? 77 * @param startOnMonday Does the week start on monday?
78 * @param rp Already set OPimRecurrence object 78 * @param rp Already set OPimRecurrence object
79 * @param startDate The start date 79 * @param startDate The start date
80 * @param parent The parent widget 80 * @param parent The parent widget
81 * @param name The name of the object 81 * @param name The name of the object
82 * @param modal 82 * @param modal
83 * @param fl The flags for window 83 * @param fl The flags for window
84 */ 84 */
85OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday, 85OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday,
86 const OPimRecurrence& rp, const QDate& startDate, 86 const OPimRecurrence& rp, const QDate& startDate,
87 QWidget* parent, const char* name, 87 QWidget* parent, const char* name,
88 bool modal, WFlags fl) 88 bool modal, WFlags fl)
89 : OPimRecurrenceBase( parent, name, modal, fl ), 89 : OPimRecurrenceBase( parent, name, modal, fl ),
90 start( startDate ), 90 start( startDate ),
91 end( rp.endDate() ), 91 end( rp.endDate() ),
92 startWeekOnMonday( startOnMonday ) 92 startWeekOnMonday( startOnMonday )
93{ 93{
94 if (strDayTemplate.isEmpty() ) 94 if (strDayTemplate.isEmpty() )
95 fillStrings(); 95 fillStrings();
96 // do some stuff with the repeat pattern 96 // do some stuff with the repeat pattern
97 init(); 97 init();
98 setRecurrence( rp ); 98 setRecurrence( rp );
99} 99}
100 100
101OPimRecurrenceWidget::~OPimRecurrenceWidget() { 101OPimRecurrenceWidget::~OPimRecurrenceWidget() {
102} 102}
103 103
104/** 104/**
105 * set the start date 105 * set the start date
106 * @param date the new start date 106 * @param date the new start date
107 */ 107 */
108void OPimRecurrenceWidget::setStartDate( const QDate& date ) { 108void OPimRecurrenceWidget::setStartDate( const QDate& date ) {
109 setRecurrence( recurrence(), date ); 109 setRecurrence( recurrence(), date );
110} 110}
111/** 111/**
112 * set the recurrence 112 * set the recurrence
113 * @param rp The OPimRecurrence object with the new recurrence rules 113 * @param rp The OPimRecurrence object with the new recurrence rules
114 */ 114 */
115void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp ) { 115void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp ) {
116 setRecurrence( rp, start ); 116 setRecurrence( rp, start );
117} 117}
118 118
119/** 119/**
120 * overloaded method taking OPimRecurrence and a new start date 120 * overloaded method taking OPimRecurrence and a new start date
121 * @param rp Recurrence rule 121 * @param rp Recurrence rule
122 * @param date The new start date 122 * @param date The new start date
123 */ 123 */
124void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp, const QDate& date ) { 124void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp, const QDate& date ) {
125 start = date; 125 start = date;
126 end = rp.endDate(); 126 end = rp.endDate();
127 switch ( rp.type() ) { 127 switch ( rp.type() ) {
128 default: 128 default:
129 case OPimRecurrence::NoRepeat: 129 case OPimRecurrence::NoRepeat:
130 currInterval = None; 130 currInterval = None;
131 setupNone(); 131 setupNone();
132 break; 132 break;
133 case OPimRecurrence::Daily: 133 case OPimRecurrence::Daily:
134 currInterval = Day; 134 currInterval = Day;
135 setupDaily(); 135 setupDaily();
136 break; 136 break;
137 case OPimRecurrence::Weekly: 137 case OPimRecurrence::Weekly:
138 currInterval = Week; 138 currInterval = Week;
139 setupWeekly(); 139 setupWeekly();
140 int day, buttons; 140 int day, buttons;
141 for ( day = 0x01, buttons = 0; buttons < 7; 141 for ( day = 0x01, buttons = 0; buttons < 7;
142 day = day << 1, buttons++ ) { 142 day = day << 1, buttons++ ) {
143 if ( rp.days() & day ) { 143 if ( rp.days() & day ) {
144 if ( startWeekOnMonday ) 144 if ( startWeekOnMonday )
145 fraExtra->setButton( buttons ); 145 fraExtra->setButton( buttons );
146 else { 146 else {
147 if ( buttons == 7 ) 147 if ( buttons == 7 )
148 fraExtra->setButton( 0 ); 148 fraExtra->setButton( 0 );
149 else 149 else
150 fraExtra->setButton( buttons + 1 ); 150 fraExtra->setButton( buttons + 1 );
151 } 151 }
152 } 152 }
153 } 153 }
154 slotWeekLabel(); 154 slotWeekLabel();
155 break; 155 break;
156 case OPimRecurrence::MonthlyDay: 156 case OPimRecurrence::MonthlyDay:
157 currInterval = Month; 157 currInterval = Month;
158 setupMonthly(); 158 setupMonthly();
159 fraExtra->setButton( 0 ); 159 fraExtra->setButton( 0 );
160 slotMonthLabel( 0 ); 160 slotMonthLabel( 0 );
161 break; 161 break;
162 case OPimRecurrence::MonthlyDate: 162 case OPimRecurrence::MonthlyDate:
163 currInterval = Month; 163 currInterval = Month;
164 setupMonthly(); 164 setupMonthly();
165 fraExtra->setButton( 1 ); 165 fraExtra->setButton( 1 );
166 slotMonthLabel( 1 ); 166 slotMonthLabel( 1 );
167 break; 167 break;
168 case OPimRecurrence::Yearly: 168 case OPimRecurrence::Yearly:
169 currInterval = Year; 169 currInterval = Year;
170 setupYearly(); 170 setupYearly();
171 break; 171 break;
172 } 172 }
173 fraType->setButton( currInterval ); 173 fraType->setButton( currInterval );
174 spinFreq->setValue( rp.frequency() ); 174 spinFreq->setValue( rp.frequency() );
175 if ( !rp.hasEndDate() ) { 175 if ( !rp.hasEndDate() ) {
176 cmdEnd->setText( tr("No End Date") ); 176 cmdEnd->setText( tr("No End Date") );
177 chkNoEnd->setChecked( TRUE ); 177 chkNoEnd->setChecked( TRUE );
178 } else 178 } else
179 cmdEnd->setText( TimeString::shortDate( end ) ); 179 cmdEnd->setText( TimeString::shortDate( end ) );
180} 180}
181 181
182/** 182/**
183 * the user selected recurrence rule. 183 * the user selected recurrence rule.
184 * @return The recurrence rule. 184 * @return The recurrence rule.
185 */ 185 */
186OPimRecurrence OPimRecurrenceWidget::recurrence()const { 186OPimRecurrence OPimRecurrenceWidget::recurrence()const {
187 QListIterator<QToolButton> it( listRTypeButtons ); 187 QListIterator<QToolButton> it( listRTypeButtons );
188 QListIterator<QToolButton> itExtra( listExtra ); 188 QListIterator<QToolButton> itExtra( listExtra );
189 OPimRecurrence rpTmp; 189 OPimRecurrence rpTmp;
190 int i; 190 int i;
191 for ( i = 0; *it; ++it, i++ ) { 191 for ( i = 0; *it; ++it, i++ ) {
192 if ( (*it)->isOn() ) { 192 if ( (*it)->isOn() ) {
193 switch ( i ) { 193 switch ( i ) {
194 case None: 194 case None:
195 rpTmp.setType( OPimRecurrence::NoRepeat ); 195 rpTmp.setType( OPimRecurrence::NoRepeat );
196 break; 196 break;
197 case Day: 197 case Day:
198 rpTmp.setType( OPimRecurrence::Daily ); 198 rpTmp.setType( OPimRecurrence::Daily );
199 break; 199 break;
200 case Week:{ 200 case Week:{
201 rpTmp.setType( OPimRecurrence::Weekly ); 201 rpTmp.setType( OPimRecurrence::Weekly );
202 int day; 202 int day;
203 int day2 = 0; 203 int day2 = 0;
204 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 204 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
205 if ( (*itExtra)->isOn() ) { 205 if ( (*itExtra)->isOn() ) {
206 if ( startWeekOnMonday ) 206 if ( startWeekOnMonday )
207 day2 |= day; 207 day2 |= day;
208 else { 208 else {
209 if ( day == 1 ) 209 if ( day == 1 )
210 day2 |= Event::SUN; 210 day2 |= Event::SUN;
211 else 211 else
212 day2 |= day >> 1; 212 day2 |= day >> 1;
213 } 213 }
214 } 214 }
215 } 215 }
216 rpTmp.setDays( day2 ); 216 rpTmp.setDays( day2 );
217 } 217 }
218 break; 218 break;
219 case Month: 219 case Month:
220 if ( cmdExtra1->isOn() ) 220 if ( cmdExtra1->isOn() )
221 rpTmp.setType( OPimRecurrence::MonthlyDay ); 221 rpTmp.setType( OPimRecurrence::MonthlyDay );
222 else if ( cmdExtra2->isOn() ) 222 else if ( cmdExtra2->isOn() )
223 rpTmp.setType( OPimRecurrence::MonthlyDate ); 223 rpTmp.setType( OPimRecurrence::MonthlyDate );
224 // figure out the montly day... 224 // figure out the montly day...
225 rpTmp.setPosition( week( start ) ); 225 rpTmp.setPosition( week( start ) );
226 break; 226 break;
227 case Year: 227 case Year:
228 rpTmp.setType( OPimRecurrence::Yearly ); 228 rpTmp.setType( OPimRecurrence::Yearly );
229 break; 229 break;
230 } 230 }
231 break; // no need to keep looking! 231 break; // no need to keep looking!
232 } 232 }
233 } 233 }
234 rpTmp.setFrequency(spinFreq->value() ); 234 rpTmp.setFrequency(spinFreq->value() );
235 rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); 235 rpTmp.setHasEndDate( !chkNoEnd->isChecked() );
236 if ( rpTmp.hasEndDate() ) { 236 if ( rpTmp.hasEndDate() ) {
237 rpTmp.setEndDate( end ); 237 rpTmp.setEndDate( end );
238 } 238 }
239 // timestamp it... 239 // timestamp it...
240// rpTmp.setCreateTime( ); current DateTime is already set -zecke 240// rpTmp.setCreateTime( ); current DateTime is already set -zecke
241 return rpTmp; 241 return rpTmp;
242} 242}
243 243
244/** 244/**
245 * Return the end date of the recurrence. This is only 245 * Return the end date of the recurrence. This is only
246 * valid if the recurrence rule does contain an enddate 246 * valid if the recurrence rule does contain an enddate
247 */ 247 */
248QDate OPimRecurrenceWidget::endDate()const { 248QDate OPimRecurrenceWidget::endDate()const {
249 return end; 249 return end;
250} 250}
251void OPimRecurrenceWidget::slotSetRType(int rtype) { 251void OPimRecurrenceWidget::slotSetRType(int rtype) {
252 // now call the right function based on the type... 252 // now call the right function based on the type...
253 currInterval = static_cast<repeatButtons>(rtype); 253 currInterval = static_cast<repeatButtons>(rtype);
254 switch ( currInterval ) { 254 switch ( currInterval ) {
255 case None: 255 case None:
256 setupNone(); 256 setupNone();
257 break; 257 break;
258 case Day: 258 case Day:
259 setupDaily(); 259 setupDaily();
260 break; 260 break;
261 case Week: 261 case Week:
262 setupWeekly(); 262 setupWeekly();
263 slotWeekLabel(); 263 slotWeekLabel();
264 break; 264 break;
265 case Month: 265 case Month:
266 setupMonthly(); 266 setupMonthly();
267 cmdExtra2->setOn( TRUE ); 267 cmdExtra2->setOn( TRUE );
268 slotMonthLabel( 1 ); 268 slotMonthLabel( 1 );
269 break; 269 break;
270 case Year: 270 case Year:
271 setupYearly(); 271 setupYearly();
272 break; 272 break;
273 } 273 }
274} 274}
275void OPimRecurrenceWidget::endDateChanged(int y, int m, int d) { 275void OPimRecurrenceWidget::endDateChanged(int y, int m, int d) {
276 end.setYMD( y, m, d ); 276 end.setYMD( y, m, d );
277 if ( end < start ) 277 if ( end < start )
278 end = start; 278 end = start;
279 cmdEnd->setText( TimeString::shortDate( end ) ); 279 cmdEnd->setText( TimeString::shortDate( end ) );
280 repeatPicker->setDate( end.year(), end.month(), end.day() ); 280 repeatPicker->setDate( end.year(), end.month(), end.day() );
281} 281}
282void OPimRecurrenceWidget::slotNoEnd( bool unused) { 282void OPimRecurrenceWidget::slotNoEnd( bool unused) {
283 // if the item was toggled, then go ahead and set it to the maximum date 283 // if the item was toggled, then go ahead and set it to the maximum date
284 if ( unused ) { 284 if ( unused ) {
285 end.setYMD( 3000, 12, 31 ); 285 end.setYMD( 3000, 12, 31 );
286 cmdEnd->setText( tr("No End Date") ); 286 cmdEnd->setText( tr("No End Date") );
287 } else { 287 } else {
288 end = start; 288 end = start;
289 cmdEnd->setText( TimeString::shortDate(end) ); 289 cmdEnd->setText( TimeString::shortDate(end) );
290 } 290 }
291} 291}
292void OPimRecurrenceWidget::setupRepeatLabel( const QString& s) { 292void OPimRecurrenceWidget::setupRepeatLabel( const QString& s) {
293 lblVar1->setText( s ); 293 lblVar1->setText( s );
294} 294}
295void OPimRecurrenceWidget::setupRepeatLabel( int x) { 295void OPimRecurrenceWidget::setupRepeatLabel( int x) {
296 // change the spelling based on the value of x 296 // change the spelling based on the value of x
297 QString strVar2; 297 QString strVar2;
298 298
299 if ( x > 1 ) 299 if ( x > 1 )
300 lblVar1->show(); 300 lblVar1->show();
301 else 301 else
302 lblVar1->hide(); 302 lblVar1->hide();
303 303
304 switch ( currInterval ) { 304 switch ( currInterval ) {
305 case None: 305 case None:
306 break; 306 break;
307 case Day: 307 case Day:
308 if ( x > 1 ) 308 if ( x > 1 )
309 strVar2 = tr( "days" ); 309 strVar2 = tr( "days" );
310 else 310 else
311 strVar2 = tr( "day" ); 311 strVar2 = tr( "day" );
312 break; 312 break;
313 case Week: 313 case Week:
314 if ( x > 1 ) 314 if ( x > 1 )
315 strVar2 = tr( "weeks" ); 315 strVar2 = tr( "weeks" );
316 else 316 else
317 strVar2 = tr( "week" ); 317 strVar2 = tr( "week" );
318 break; 318 break;
319 case Month: 319 case Month:
320 if ( x > 1 ) 320 if ( x > 1 )
321 strVar2 = tr( "months" ); 321 strVar2 = tr( "months" );
322 else 322 else
323 strVar2 = tr( "month" ); 323 strVar2 = tr( "month" );
324 break; 324 break;
325 case Year: 325 case Year:
326 if ( x > 1 ) 326 if ( x > 1 )
327 strVar2 = tr( "years" ); 327 strVar2 = tr( "years" );
328 else 328 else
329 strVar2 = tr( "year" ); 329 strVar2 = tr( "year" );
330 break; 330 break;
331 } 331 }
332 if ( !strVar2.isNull() ) 332 if ( !strVar2.isNull() )
333 lblVar2->setText( strVar2 ); 333 lblVar2->setText( strVar2 );
334} 334}
335void OPimRecurrenceWidget::slotWeekLabel() { 335void OPimRecurrenceWidget::slotWeekLabel() {
336 QString str; 336 QString str;
337 QListIterator<QToolButton> it( listExtra ); 337 QListIterator<QToolButton> it( listExtra );
338 unsigned int i; 338 unsigned int i;
339 unsigned int keepMe; 339 unsigned int keepMe;
340 bool bNeedCarriage = FALSE; 340 bool bNeedCarriage = FALSE;
341 // don't do something we'll regret!!! 341 // don't do something we'll regret!!!
342 if ( currInterval != Week ) 342 if ( currInterval != Week )
343 return; 343 return;
344 344
345 if ( startWeekOnMonday ) 345 if ( startWeekOnMonday )
346 keepMe = start.dayOfWeek() - 1; 346 keepMe = start.dayOfWeek() - 1;
347 else 347 else
348 keepMe = start.dayOfWeek() % 7; 348 keepMe = start.dayOfWeek() % 7;
349 349
350 QStringList list; 350 QStringList list;
351 for ( i = 0; *it; ++it, i++ ) { 351 for ( i = 0; *it; ++it, i++ ) {
352 // a crazy check, if you are repeating weekly, the current day 352 // a crazy check, if you are repeating weekly, the current day
353 // must be selected!!! 353 // must be selected!!!
354 if ( i == keepMe && !( (*it)->isOn() ) ) 354 if ( i == keepMe && !( (*it)->isOn() ) )
355 (*it)->setOn( TRUE ); 355 (*it)->setOn( TRUE );
356 if ( (*it)->isOn() ) { 356 if ( (*it)->isOn() ) {
357 if ( startWeekOnMonday ) 357 if ( startWeekOnMonday )
358 list.append( dayLabel[i] ); 358 list.append( dayLabel[i] );
359 else { 359 else {
360 if ( i == 0 ) 360 if ( i == 0 )
361 list.append( dayLabel[6] ); 361 list.append( dayLabel[6] );
362 else 362 else
363 list.append( dayLabel[i - 1] ); 363 list.append( dayLabel[i - 1] );
364 } 364 }
365 } 365 }
366 } 366 }
367 QStringList::Iterator itStr; 367 QStringList::Iterator itStr;
368 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) { 368 for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) {
369 if ( i == 3 ) 369 if ( i == 3 )
370 bNeedCarriage = TRUE; 370 bNeedCarriage = TRUE;
371 else 371 else
372 bNeedCarriage = FALSE; 372 bNeedCarriage = FALSE;
373 if ( str.isNull() ) 373 if ( str.isNull() )
374 str = *itStr; 374 str = *itStr;
375 else if ( i == list.count() - 1 ) { 375 else if ( i == list.count() - 1 ) {
376 if ( i < 2 ) 376 if ( i < 2 )
377 str += tr(" and ") + *itStr; 377 str += tr(" and ") + *itStr;
378 else { 378 else {
379 if ( bNeedCarriage ) 379 if ( bNeedCarriage )
380 str += tr( ",\nand " ) + *itStr; 380 str += tr( ",\nand " ) + *itStr;
381 else 381 else
382 str += tr( ", and " ) + *itStr; 382 str += tr( ", and " ) + *itStr;
383 } 383 }
384 } else { 384 } else {
385 if ( bNeedCarriage ) 385 if ( bNeedCarriage )
386 str += ",\n" + *itStr; 386 str += ",\n" + *itStr;
387 else 387 else
388 str += ", " + *itStr; 388 str += ", " + *itStr;
389 } 389 }
390 } 390 }
391 str = str.prepend( tr("on ") ); 391 str = str.prepend( tr("on ") );
392 392
393 lblWeekVar->setText( str ); 393 lblWeekVar->setText( str );
394} 394}
395void OPimRecurrenceWidget::slotMonthLabel(int type) { 395void OPimRecurrenceWidget::slotMonthLabel(int type) {
396 QString str; 396 QString str;
397 if ( currInterval != Month || type > 1 ) 397 if ( currInterval != Month || type > 1 )
398 return; 398 return;
399 if ( type == 1 ) 399 if ( type == 1 )
400 str = strMonthDateTemplate.arg( numberPlacing(start.day()) ); 400 str = strMonthDateTemplate.arg( numberPlacing(start.day()) );
401 else 401 else
402 str = strMonthDayTemplate.arg( numberPlacing(week(start))) 402 str = strMonthDayTemplate.arg( numberPlacing(week(start)))
403 .arg( dayLabel[start.dayOfWeek() - 1] ); 403 .arg( dayLabel[start.dayOfWeek() - 1] );
404 lblRepeat->setText( str ); 404 lblRepeat->setText( str );
405} 405}
406void OPimRecurrenceWidget::slotChangeStartOfWeek( bool onMonday ) { 406void OPimRecurrenceWidget::slotChangeStartOfWeek( bool onMonday ) {
407 startWeekOnMonday = onMonday; 407 startWeekOnMonday = onMonday;
408 // we need to make this unintrusive as possible... 408 // we need to make this unintrusive as possible...
409 int saveSpin = spinFreq->value(); 409 int saveSpin = spinFreq->value();
410 char days = 0; 410 char days = 0;
411 int day; 411 int day;
412 QListIterator<QToolButton> itExtra( listExtra ); 412 QListIterator<QToolButton> itExtra( listExtra );
413 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { 413 for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) {
414 if ( (*itExtra)->isOn() ) { 414 if ( (*itExtra)->isOn() ) {
415 if ( !startWeekOnMonday ) 415 if ( !startWeekOnMonday )
416 days |= day; 416 days |= day;
417 else { 417 else {
418 if ( day == 1 ) 418 if ( day == 1 )
419 days |= OPimRecurrence::SUN; 419 days |= OPimRecurrence::SUN;
420 else 420 else
421 days |= day >> 1; 421 days |= day >> 1;
422 } 422 }
423 } 423 }
424 } 424 }
425 setupWeekly(); 425 setupWeekly();
426 spinFreq->setValue( saveSpin ); 426 spinFreq->setValue( saveSpin );
427 int buttons; 427 int buttons;
428 for ( day = 0x01, buttons = 0; buttons < 7; 428 for ( day = 0x01, buttons = 0; buttons < 7;
429 day = day << 1, buttons++ ) { 429 day = day << 1, buttons++ ) {
430 if ( days & day ) { 430 if ( days & day ) {
431 if ( startWeekOnMonday ) 431 if ( startWeekOnMonday )
432 fraExtra->setButton( buttons ); 432 fraExtra->setButton( buttons );
433 else { 433 else {
434 if ( buttons == 7 ) 434 if ( buttons == 7 )
435 fraExtra->setButton( 0 ); 435 fraExtra->setButton( 0 );
436 else 436 else
437 fraExtra->setButton( buttons + 1 ); 437 fraExtra->setButton( buttons + 1 );
438 } 438 }
439 } 439 }
440 } 440 }
441 slotWeekLabel(); 441 slotWeekLabel();
442} 442}
443void OPimRecurrenceWidget::setupNone() { 443void OPimRecurrenceWidget::setupNone() {
444 lblRepeat->setText( tr("No Repeat") ); 444 lblRepeat->setText( tr("No Repeat") );
445 lblVar1->hide(); 445 lblVar1->hide();
446 lblVar2->hide(); 446 lblVar2->hide();
447 hideExtras(); 447 hideExtras();
448 cmdEnd->hide(); 448 cmdEnd->hide();
449 lblFreq->hide(); 449 lblFreq->hide();
450 lblEvery->hide(); 450 lblEvery->hide();
451 lblFreq->hide(); 451 lblFreq->hide();
452 spinFreq->hide(); 452 spinFreq->hide();
453 lblEnd->hide(); 453 lblEnd->hide();
454 lblWeekVar->hide(); 454 lblWeekVar->hide();
455} 455}
456void OPimRecurrenceWidget::setupDaily() { 456void OPimRecurrenceWidget::setupDaily() {
457 hideExtras(); 457 hideExtras();
458 lblWeekVar->hide(); 458 lblWeekVar->hide();
459 spinFreq->setValue( 1 ); 459 spinFreq->setValue( 1 );
460 lblFreq->setText( tr("day(s)") ); 460 lblFreq->setText( tr("day(s)") );
461 lblVar2->show(); 461 lblVar2->show();
462 showRepeatStuff(); 462 showRepeatStuff();
463 lblRepeat->setText( strDayTemplate ); 463 lblRepeat->setText( strDayTemplate );
464 setupRepeatLabel( 1 ); 464 setupRepeatLabel( 1 );
465} 465}
466void OPimRecurrenceWidget::setupWeekly() { 466void OPimRecurrenceWidget::setupWeekly() {
467// reshow the buttons... 467// reshow the buttons...
468 fraExtra->setTitle( tr("Repeat On") ); 468 fraExtra->setTitle( tr("Repeat On") );
469 fraExtra->setExclusive( FALSE ); 469 fraExtra->setExclusive( FALSE );
470 fraExtra->show(); 470 fraExtra->show();
471 if ( startWeekOnMonday ) { 471 if ( startWeekOnMonday ) {
472 cmdExtra1->setText( tr("Mon") ); 472 cmdExtra1->setText( tr("Mon") );
473 cmdExtra2->setText( tr("Tue") ); 473 cmdExtra2->setText( tr("Tue") );
474 cmdExtra3->setText( tr("Wed") ); 474 cmdExtra3->setText( tr("Wed") );
475 cmdExtra4->setText( tr("Thu") ); 475 cmdExtra4->setText( tr("Thu") );
476 cmdExtra5->setText( tr("Fri") ); 476 cmdExtra5->setText( tr("Fri") );
477 cmdExtra6->setText( tr("Sat") ); 477 cmdExtra6->setText( tr("Sat") );
478 cmdExtra7->setText( tr("Sun") ); 478 cmdExtra7->setText( tr("Sun") );
479 } else { 479 } else {
480 cmdExtra1->setText( tr("Sun") ); 480 cmdExtra1->setText( tr("Sun") );
481 cmdExtra2->setText( tr("Mon") ); 481 cmdExtra2->setText( tr("Mon") );
482 cmdExtra3->setText( tr("Tue") ); 482 cmdExtra3->setText( tr("Tue") );
483 cmdExtra4->setText( tr("Wed") ); 483 cmdExtra4->setText( tr("Wed") );
484 cmdExtra5->setText( tr("Thu") ); 484 cmdExtra5->setText( tr("Thu") );
485 cmdExtra6->setText( tr("Fri") ); 485 cmdExtra6->setText( tr("Fri") );
486 cmdExtra7->setText( tr("Sat") ); 486 cmdExtra7->setText( tr("Sat") );
487 } 487 }
488 // I hope clustering these improve performance.... 488 // I hope clustering these improve performance....
489 cmdExtra1->setOn( FALSE ); 489 cmdExtra1->setOn( FALSE );
490 cmdExtra2->setOn( FALSE ); 490 cmdExtra2->setOn( FALSE );
491 cmdExtra3->setOn( FALSE ); 491 cmdExtra3->setOn( FALSE );
492 cmdExtra4->setOn( FALSE ); 492 cmdExtra4->setOn( FALSE );
493 cmdExtra5->setOn( FALSE ); 493 cmdExtra5->setOn( FALSE );
494 cmdExtra6->setOn( FALSE ); 494 cmdExtra6->setOn( FALSE );
495 cmdExtra7->setOn( FALSE ); 495 cmdExtra7->setOn( FALSE );
496 496
497 cmdExtra1->show(); 497 cmdExtra1->show();
498 cmdExtra2->show(); 498 cmdExtra2->show();
499 cmdExtra3->show(); 499 cmdExtra3->show();
500 cmdExtra4->show(); 500 cmdExtra4->show();
501 cmdExtra5->show(); 501 cmdExtra5->show();
502 cmdExtra6->show(); 502 cmdExtra6->show();
503 cmdExtra7->show(); 503 cmdExtra7->show();
504 504
505 lblWeekVar->show(); 505 lblWeekVar->show();
506 spinFreq->setValue( 1 ); 506 spinFreq->setValue( 1 );
507 // might as well set the day too... 507 // might as well set the day too...
508 if ( startWeekOnMonday ) { 508 if ( startWeekOnMonday ) {
509 fraExtra->setButton( start.dayOfWeek() - 1 ); 509 fraExtra->setButton( start.dayOfWeek() - 1 );
510 } else { 510 } else {
511 fraExtra->setButton( start.dayOfWeek() % 7 ); 511 fraExtra->setButton( start.dayOfWeek() % 7 );
512 } 512 }
513 lblFreq->setText( tr("week(s)") ); 513 lblFreq->setText( tr("week(s)") );
514 lblVar2->show(); 514 lblVar2->show();
515 showRepeatStuff(); 515 showRepeatStuff();
516 setupRepeatLabel( 1 ); 516 setupRepeatLabel( 1 );
517} 517}
518void OPimRecurrenceWidget::setupMonthly() { 518void OPimRecurrenceWidget::setupMonthly() {
519 hideExtras(); 519 hideExtras();
520 lblWeekVar->hide(); 520 lblWeekVar->hide();
521 fraExtra->setTitle( tr("Repeat By") ); 521 fraExtra->setTitle( tr("Repeat By") );
522 fraExtra->setExclusive( TRUE ); 522 fraExtra->setExclusive( TRUE );
523 fraExtra->show(); 523 fraExtra->show();
524 cmdExtra1->setText( tr("Day") ); 524 cmdExtra1->setText( tr("Day") );
525 cmdExtra1->show(); 525 cmdExtra1->show();
526 cmdExtra2->setText( tr("Date") ); 526 cmdExtra2->setText( tr("Date") );
527 cmdExtra2->show(); 527 cmdExtra2->show();
528 spinFreq->setValue( 1 ); 528 spinFreq->setValue( 1 );
529 lblFreq->setText( tr("month(s)") ); 529 lblFreq->setText( tr("month(s)") );
530 lblVar2->show(); 530 lblVar2->show();
531 showRepeatStuff(); 531 showRepeatStuff();
532 setupRepeatLabel( 1 ); 532 setupRepeatLabel( 1 );
533} 533}
534void OPimRecurrenceWidget::setupYearly() { 534void OPimRecurrenceWidget::setupYearly() {
535hideExtras(); 535hideExtras();
536 lblWeekVar->hide(); 536 lblWeekVar->hide();
537 spinFreq->setValue( 1 ); 537 spinFreq->setValue( 1 );
538 lblFreq->setText( tr("year(s)") ); 538 lblFreq->setText( tr("year(s)") );
539 lblFreq->show(); 539 lblFreq->show();
540 lblFreq->show(); 540 lblFreq->show();
541 showRepeatStuff(); 541 showRepeatStuff();
542 lblVar2->show(); 542 lblVar2->show();
543 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) ); 543 QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) );
544 lblRepeat->setText( strEvery ); 544 lblRepeat->setText( strEvery );
545 setupRepeatLabel( 1 ); 545 setupRepeatLabel( 1 );
546 546
547} 547}
548void OPimRecurrenceWidget::init() { 548void OPimRecurrenceWidget::init() {
549 QPopupMenu *m1 = new QPopupMenu( this ); 549 QPopupMenu *m1 = new QPopupMenu( this );
550 repeatPicker = new DateBookMonth( m1, 0, TRUE ); 550 repeatPicker = new DateBookMonth( m1, 0, TRUE );
551 m1->insertItem( repeatPicker ); 551 m1->insertItem( repeatPicker );
552 cmdEnd->setPopup( m1 ); 552 cmdEnd->setPopup( m1 );
553 cmdEnd->setPopupDelay( 0 ); 553 cmdEnd->setPopupDelay( 0 );
554 554
555 QObject::connect( repeatPicker, SIGNAL(dateClicked(int, int, int)), 555 QObject::connect( repeatPicker, SIGNAL(dateClicked(int,int,int)),
556 this, SLOT(endDateChanged(int, int, int)) ); 556 this, SLOT(endDateChanged(int,int,int)) );
557 QObject::connect( qApp, SIGNAL(weekChanged(bool)), 557 QObject::connect( qApp, SIGNAL(weekChanged(bool)),
558 this, SLOT(slotChangeStartOfWeek(bool)) ); 558 this, SLOT(slotChangeStartOfWeek(bool)) );
559 559
560 listRTypeButtons.setAutoDelete( TRUE ); 560 listRTypeButtons.setAutoDelete( TRUE );
561 listRTypeButtons.append( cmdNone ); 561 listRTypeButtons.append( cmdNone );
562 listRTypeButtons.append( cmdDay ); 562 listRTypeButtons.append( cmdDay );
563 listRTypeButtons.append( cmdWeek ); 563 listRTypeButtons.append( cmdWeek );
564 listRTypeButtons.append( cmdMonth ); 564 listRTypeButtons.append( cmdMonth );
565 listRTypeButtons.append( cmdYear ); 565 listRTypeButtons.append( cmdYear );
566 566
567 listExtra.setAutoDelete( TRUE ); 567 listExtra.setAutoDelete( TRUE );
568 listExtra.append( cmdExtra1 ); 568 listExtra.append( cmdExtra1 );
569 listExtra.append( cmdExtra2 ); 569 listExtra.append( cmdExtra2 );
570 listExtra.append( cmdExtra3 ); 570 listExtra.append( cmdExtra3 );
571 listExtra.append( cmdExtra4 ); 571 listExtra.append( cmdExtra4 );
572 listExtra.append( cmdExtra5 ); 572 listExtra.append( cmdExtra5 );
573 listExtra.append( cmdExtra6 ); 573 listExtra.append( cmdExtra6 );
574 listExtra.append( cmdExtra7 ); 574 listExtra.append( cmdExtra7 );
575} 575}
576void OPimRecurrenceWidget::hideExtras() { 576void OPimRecurrenceWidget::hideExtras() {
577 // hide the extra buttons... 577 // hide the extra buttons...
578 fraExtra->hide(); 578 fraExtra->hide();
579 chkNoEnd->hide(); 579 chkNoEnd->hide();
580 QListIterator<QToolButton> it( listExtra ); 580 QListIterator<QToolButton> it( listExtra );
581 for ( ; *it; ++it ) { 581 for ( ; *it; ++it ) {
582 (*it)->hide(); 582 (*it)->hide();
583 (*it)->setOn( FALSE ); 583 (*it)->setOn( FALSE );
584 } 584 }
585} 585}
586void OPimRecurrenceWidget::showRepeatStuff() { 586void OPimRecurrenceWidget::showRepeatStuff() {
587 cmdEnd->show(); 587 cmdEnd->show();
588 chkNoEnd->show(); 588 chkNoEnd->show();
589 lblFreq->show(); 589 lblFreq->show();
590 lblEvery->show(); 590 lblEvery->show();
591 lblFreq->show(); 591 lblFreq->show();
592 spinFreq->show(); 592 spinFreq->show();
593 lblEnd->show(); 593 lblEnd->show();
594 lblRepeat->setText( tr("Every") ); 594 lblRepeat->setText( tr("Every") );
595} 595}
596 596
597 597
598static int week( const QDate &start ) 598static int week( const QDate &start )
599{ 599{
600 // figure out the week... 600 // figure out the week...
601 int stop = start.day(), 601 int stop = start.day(),
602 sentinel = start.dayOfWeek(), 602 sentinel = start.dayOfWeek(),
603 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(), 603 dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(),
604 week = 1, 604 week = 1,
605 i; 605 i;
606 for ( i = 1; i < stop; i++ ) { 606 for ( i = 1; i < stop; i++ ) {
607 if ( dayOfWeek++ == sentinel ) 607 if ( dayOfWeek++ == sentinel )
608 week++; 608 week++;
609 if ( dayOfWeek > 7 ) 609 if ( dayOfWeek > 7 )
610 dayOfWeek = 0; 610 dayOfWeek = 0;
611 } 611 }
612 return week; 612 return week;
613} 613}
614 614
615static QString numberPlacing( int x ) 615static QString numberPlacing( int x )
616{ 616{
617 // I hope this works in other languages besides english... 617 // I hope this works in other languages besides english...
618 QString str = QString::number( x ); 618 QString str = QString::number( x );
619 switch ( x % 10 ) { 619 switch ( x % 10 ) {
620 case 1: 620 case 1:
621 str += QWidget::tr( "st" ); 621 str += QWidget::tr( "st" );
622 break; 622 break;
623 case 2: 623 case 2:
624 str += QWidget::tr( "nd" ); 624 str += QWidget::tr( "nd" );
625 break; 625 break;
626 case 3: 626 case 3:
627 str += QWidget::tr( "rd" ); 627 str += QWidget::tr( "rd" );
628 break; 628 break;
629 default: 629 default:
630 str += QWidget::tr( "th" ); 630 str += QWidget::tr( "th" );
631 break; 631 break;
632 } 632 }
633 return str; 633 return str;
634} 634}