48 files changed, 678 insertions, 263 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 34bf7f1..6819085 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -1,1052 +1,1057 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) | ||
3 | ** | 4 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 5 | ** This file is part of the Open Palmtop Environment (see www.opie.info). |
5 | ** | 6 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 7 | ** 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 | 8 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 10 | ** packaging of this file. |
10 | ** | 11 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** 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. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 14 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 16 | ** |
16 | ** OContact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | 17 | ** |
19 | **********************************************************************/ | 18 | **********************************************************************/ |
20 | 19 | ||
21 | #define QTOPIA_INTERNAL_FD | 20 | #define QTOPIA_INTERNAL_FD |
22 | 21 | ||
23 | #include "contacteditor.h" | 22 | #include "contacteditor.h" |
24 | #include "ablabel.h" | 23 | #include "ablabel.h" |
25 | #include "abview.h" | 24 | #include "abview.h" |
26 | #include "abtable.h" | 25 | #include "abtable.h" |
27 | // #include "addresssettings.h" | 26 | // #include "addresssettings.h" |
28 | #include "addressbook.h" | 27 | #include "addressbook.h" |
29 | 28 | ||
30 | 29 | ||
31 | #include <opie/ofileselector.h> | 30 | #include <opie/ofileselector.h> |
32 | #include <opie/ofiledialog.h> | 31 | #include <opie/ofiledialog.h> |
33 | #include <opie/ocontact.h> | 32 | #include <opie/ocontact.h> |
34 | #include <opie/ocontactaccessbackend_vcard.h> | 33 | #include <opie/ocontactaccessbackend_vcard.h> |
35 | 34 | ||
36 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
37 | #include <qpe/ir.h> | 36 | #include <qpe/ir.h> |
38 | #include <qpe/qpemessagebox.h> | 37 | #include <qpe/qpemessagebox.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 38 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/qpetoolbar.h> | 39 | #include <qpe/qpetoolbar.h> |
41 | #include <qpe/qpemenubar.h> | 40 | #include <qpe/qpemenubar.h> |
42 | // #include <qtoolbar.h> | 41 | // #include <qtoolbar.h> |
43 | // #include <qmenubar.h> | 42 | // #include <qmenubar.h> |
44 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
45 | #include <qpe/config.h> | 44 | #include <qpe/config.h> |
46 | 45 | ||
47 | #include <qaction.h> | 46 | #include <qaction.h> |
48 | #include <qdialog.h> | 47 | #include <qdialog.h> |
49 | #include <qdir.h> | 48 | #include <qdir.h> |
50 | #include <qfile.h> | 49 | #include <qfile.h> |
51 | #include <qimage.h> | 50 | #include <qimage.h> |
52 | #include <qlayout.h> | 51 | #include <qlayout.h> |
53 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
54 | #include <qpixmap.h> | 53 | #include <qpixmap.h> |
55 | #include <qpopupmenu.h> | 54 | #include <qpopupmenu.h> |
56 | #include <qstringlist.h> | 55 | #include <qstringlist.h> |
57 | #include <qtoolbutton.h> | 56 | #include <qtoolbutton.h> |
58 | #include <qwhatsthis.h> | 57 | #include <qwhatsthis.h> |
59 | #include <qdatetime.h> | 58 | #include <qdatetime.h> |
60 | 59 | ||
61 | #include <stdlib.h> | 60 | #include <stdlib.h> |
62 | #include <sys/stat.h> | 61 | #include <sys/stat.h> |
63 | #include <sys/types.h> | 62 | #include <sys/types.h> |
64 | #include <fcntl.h> | 63 | #include <fcntl.h> |
65 | #include <unistd.h> | 64 | #include <unistd.h> |
66 | 65 | ||
67 | 66 | ||
68 | #include "picker.h" | 67 | #include "picker.h" |
69 | #include "configdlg.h" | 68 | #include "configdlg.h" |
70 | 69 | ||
71 | extern QString addressbookPersonalVCardName(); | 70 | extern QString addressbookPersonalVCardName(); |
72 | 71 | ||
73 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, | 72 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, |
74 | WFlags f ) | 73 | WFlags f ) |
75 | : QMainWindow( parent, name, f ), | 74 | : QMainWindow( parent, name, f ), |
76 | catMenu (0l), | 75 | catMenu (0l), |
77 | abEditor(0l), | 76 | abEditor(0l), |
78 | syncing(FALSE), | 77 | syncing(FALSE), |
79 | m_tableViewButton(0l), | 78 | m_tableViewButton(0l), |
80 | m_cardViewButton(0l) | 79 | m_cardViewButton(0l) |
81 | { | 80 | { |
82 | isLoading = true; | 81 | isLoading = true; |
83 | 82 | ||
84 | m_config.load(); | 83 | m_config.load(); |
85 | 84 | ||
86 | setCaption( tr("Contacts") ); | 85 | setCaption( tr("Contacts") ); |
87 | setIcon( Resource::loadPixmap( "AddressBook" ) ); | 86 | setIcon( Resource::loadPixmap( "AddressBook" ) ); |
88 | 87 | ||
89 | // Settings for Main Menu | 88 | // Settings for Main Menu |
90 | // setToolBarsMovable( false ); | 89 | // setToolBarsMovable( false ); |
91 | setToolBarsMovable( !m_config.fixedBars() ); | 90 | setToolBarsMovable( !m_config.fixedBars() ); |
92 | setRightJustification( true ); | 91 | setRightJustification( true ); |
93 | 92 | ||
94 | QPEToolBar *bar = new QPEToolBar( this ); | 93 | QPEToolBar *bar = new QPEToolBar( this ); |
95 | bar->setHorizontalStretchable( TRUE ); | 94 | bar->setHorizontalStretchable( TRUE ); |
96 | 95 | ||
97 | QPEMenuBar *mbList = new QPEMenuBar( bar ); | 96 | QPEMenuBar *mbList = new QPEMenuBar( bar ); |
98 | mbList->setMargin( 0 ); | 97 | mbList->setMargin( 0 ); |
99 | 98 | ||
100 | QPopupMenu *edit = new QPopupMenu( mbList ); | 99 | QPopupMenu *edit = new QPopupMenu( mbList ); |
101 | mbList->insertItem( tr( "Contact" ), edit ); | 100 | mbList->insertItem( tr( "Contact" ), edit ); |
102 | 101 | ||
103 | // Category Menu | 102 | // Category Menu |
104 | catMenu = new QPopupMenu( this ); | 103 | catMenu = new QPopupMenu( this ); |
105 | catMenu->setCheckable( TRUE ); | 104 | catMenu->setCheckable( TRUE ); |
106 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); | 105 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); |
107 | mbList->insertItem( tr("View"), catMenu ); | 106 | mbList->insertItem( tr("View"), catMenu ); |
108 | 107 | ||
109 | // Create Toolbar | 108 | // Create Toolbar |
110 | listTools = new QPEToolBar( this, "list operations" ); | 109 | listTools = new QPEToolBar( this, "list operations" ); |
111 | listTools->setHorizontalStretchable( true ); | 110 | listTools->setHorizontalStretchable( true ); |
112 | addToolBar( listTools ); | 111 | addToolBar( listTools ); |
113 | moveToolBar( listTools, m_config.getToolBarPos() ); | 112 | moveToolBar( listTools, m_config.getToolBarPos() ); |
114 | 113 | ||
115 | // View Icons | 114 | // View Icons |
116 | m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/weeklst" ), | 115 | m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/listview" ), |
117 | QString::null, 0, this, 0 ); | 116 | QString::null, 0, this, 0 ); |
118 | connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); | 117 | connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); |
119 | m_tableViewButton->setToggleAction( true ); | 118 | m_tableViewButton->setToggleAction( true ); |
120 | m_tableViewButton->addTo( listTools ); | 119 | m_tableViewButton->addTo( listTools ); |
121 | m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "day" ), QString::null, 0, this, 0 ); | 120 | m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "addressbook/cardview" ), QString::null, 0, this, 0 ); |
122 | connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); | 121 | connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); |
123 | m_cardViewButton->setToggleAction( true ); | 122 | m_cardViewButton->setToggleAction( true ); |
124 | m_cardViewButton->addTo( listTools ); | 123 | m_cardViewButton->addTo( listTools ); |
125 | 124 | ||
126 | listTools->addSeparator(); | 125 | listTools->addSeparator(); |
127 | 126 | ||
128 | // Other Buttons | 127 | // Other Buttons |
129 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, | 128 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, |
130 | 0, this, 0 ); | 129 | 0, this, 0 ); |
131 | actionNew = a; | 130 | actionNew = a; |
132 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); | 131 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); |
133 | a->addTo( edit ); | 132 | a->addTo( edit ); |
134 | a->addTo( listTools ); | 133 | a->addTo( listTools ); |
135 | 134 | ||
136 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 135 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
137 | 0, this, 0 ); | 136 | 0, this, 0 ); |
138 | actionEdit = a; | 137 | actionEdit = a; |
139 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); | 138 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); |
140 | a->addTo( edit ); | 139 | a->addTo( edit ); |
141 | a->addTo( listTools ); | 140 | a->addTo( listTools ); |
142 | 141 | ||
143 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 142 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
144 | 0, this, 0 ); | 143 | 0, this, 0 ); |
145 | actionTrash = a; | 144 | actionTrash = a; |
146 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); | 145 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); |
147 | a->addTo( edit ); | 146 | a->addTo( edit ); |
148 | a->addTo( listTools ); | 147 | a->addTo( listTools ); |
149 | 148 | ||
150 | 149 | ||
151 | // make it possible to go directly to businesscard via qcop call | 150 | // make it possible to go directly to businesscard via qcop call |
152 | //#if defined(Q_WS_QWS) // Why this ? (se) | 151 | //#if defined(Q_WS_QWS) // Why this ? (se) |
153 | #if !defined(QT_NO_COP) | 152 | #if !defined(QT_NO_COP) |
154 | QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); | 153 | QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); |
155 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), | 154 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), |
156 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); | 155 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); |
157 | #endif | 156 | #endif |
158 | // #endif | 157 | // #endif |
159 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), | 158 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), |
160 | QString::null, 0, this, 0 ); | 159 | QString::null, 0, this, 0 ); |
161 | actionFind = a; | 160 | actionFind = a; |
162 | connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); | 161 | connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); |
163 | a->addTo( edit ); | 162 | a->addTo( edit ); |
164 | a->addTo( listTools ); | 163 | a->addTo( listTools ); |
165 | 164 | ||
166 | // Much better search widget, taken from QTReader.. (se) | 165 | // Much better search widget, taken from QTReader.. (se) |
167 | searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); | 166 | searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); |
168 | searchBar->setHorizontalStretchable( TRUE ); | 167 | searchBar->setHorizontalStretchable( TRUE ); |
169 | searchBar->hide(); | 168 | searchBar->hide(); |
170 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 169 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
171 | 170 | ||
172 | // QFont f("unifont", 16 /*, QFont::Bold*/); | 171 | // QFont f("unifont", 16 /*, QFont::Bold*/); |
173 | // searchEdit->setFont( f ); | 172 | // searchEdit->setFont( f ); |
174 | 173 | ||
175 | searchBar->setStretchableWidget( searchEdit ); | 174 | searchBar->setStretchableWidget( searchEdit ); |
176 | connect( searchEdit, SIGNAL( returnPressed( ) ), | 175 | connect( searchEdit, SIGNAL( returnPressed( ) ), |
177 | this, SLOT( slotFind( ) ) ); | 176 | this, SLOT( slotFind( ) ) ); |
178 | 177 | ||
179 | a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); | 178 | a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); |
180 | connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | 179 | connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); |
181 | a->addTo( searchBar ); | 180 | a->addTo( searchBar ); |
182 | 181 | ||
183 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 182 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
184 | connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); | 183 | connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); |
185 | a->addTo( searchBar ); | 184 | a->addTo( searchBar ); |
186 | 185 | ||
187 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), | 186 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), |
188 | QString::null, 0, this, 0 ); | 187 | QString::null, 0, this, 0 ); |
189 | //a->setEnabled( FALSE ); we got support for it now :) zecke | 188 | //a->setEnabled( FALSE ); we got support for it now :) zecke |
190 | actionMail = a; | 189 | actionMail = a; |
191 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); | 190 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); |
192 | a->addTo( edit ); | 191 | a->addTo( edit ); |
193 | a->addTo( listTools ); | 192 | a->addTo( listTools ); |
194 | 193 | ||
195 | if ( Ir::supported() ) { | 194 | if ( Ir::supported() ) { |
196 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, | 195 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, |
197 | 0, this, 0 ); | 196 | 0, this, 0 ); |
198 | actionBeam = a; | 197 | actionBeam = a; |
199 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 198 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
200 | a->addTo( edit ); | 199 | a->addTo( edit ); |
201 | a->addTo( listTools ); | 200 | a->addTo( listTools ); |
202 | } | 201 | } |
203 | 202 | ||
204 | edit->insertSeparator(); | 203 | edit->insertSeparator(); |
205 | 204 | ||
206 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, | 205 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, |
207 | 0, this, 0); | 206 | 0, this, 0); |
208 | actionPersonal = a; | 207 | actionPersonal = a; |
209 | connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); | 208 | connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); |
210 | a->addTo( edit ); | 209 | a->addTo( edit ); |
211 | 210 | ||
212 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, | 211 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, |
213 | 0, this, 0); | 212 | 0, this, 0); |
214 | actionPersonal = a; | 213 | actionPersonal = a; |
215 | connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); | 214 | connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); |
216 | a->addTo( edit ); | 215 | a->addTo( edit ); |
217 | 216 | ||
218 | edit->insertSeparator(); | 217 | edit->insertSeparator(); |
219 | 218 | ||
220 | a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), | 219 | a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), |
221 | QString::null, 0, this, 0 , TRUE ); | 220 | QString::null, 0, this, 0 , TRUE ); |
222 | actionPersonal = a; | 221 | actionPersonal = a; |
223 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); | 222 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); |
224 | a->addTo( edit ); | 223 | a->addTo( edit ); |
225 | 224 | ||
226 | 225 | ||
227 | #ifdef __DEBUG_RELEASE | 226 | #ifdef __DEBUG_RELEASE |
228 | // Remove this function for public Release ! This is only | 227 | // Remove this function for public Release ! This is only |
229 | // for debug purposes .. | 228 | // for debug purposes .. |
230 | a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); | 229 | a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); |
231 | connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); | 230 | connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); |
232 | a->addTo( edit ); | 231 | a->addTo( edit ); |
233 | #endif | 232 | #endif |
234 | a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, | 233 | a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, |
235 | 0, this, 0 ); | 234 | 0, this, 0 ); |
236 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); | 235 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); |
237 | a->addTo( edit ); | 236 | a->addTo( edit ); |
238 | 237 | ||
239 | // Create Views | 238 | // Create Views |
240 | listContainer = new QWidget( this ); | 239 | listContainer = new QWidget( this ); |
241 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); | 240 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); |
242 | 241 | ||
243 | m_abView = new AbView( listContainer, m_config.orderList() ); | 242 | m_abView = new AbView( listContainer, m_config.orderList() ); |
244 | vb->addWidget( m_abView ); | 243 | vb->addWidget( m_abView ); |
245 | // abList->setHScrollBarMode( QScrollView::AlwaysOff ); | 244 | // abList->setHScrollBarMode( QScrollView::AlwaysOff ); |
246 | connect( m_abView, SIGNAL( signalViewSwitched ( int ) ), | 245 | connect( m_abView, SIGNAL( signalViewSwitched ( int ) ), |
247 | this, SLOT( slotViewSwitched( int ) ) ); | 246 | this, SLOT( slotViewSwitched( int ) ) ); |
248 | 247 | ||
249 | 248 | ||
250 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); | 249 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); |
251 | 250 | ||
252 | m_abView->load(); | 251 | m_abView->load(); |
253 | 252 | ||
254 | // Letter Picker | 253 | // Letter Picker |
255 | pLabel = new LetterPicker( listContainer ); | 254 | pLabel = new LetterPicker( listContainer ); |
256 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); | 255 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); |
257 | connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); | 256 | connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); |
258 | 257 | ||
259 | vb->addWidget( pLabel ); | 258 | vb->addWidget( pLabel ); |
260 | 259 | ||
261 | // All Categories into view-menu.. | 260 | // All Categories into view-menu.. |
262 | populateCategories(); | 261 | populateCategories(); |
263 | 262 | ||
264 | // Fontsize | 263 | // Fontsize |
265 | defaultFont = new QFont( m_abView->font() ); | 264 | defaultFont = new QFont( m_abView->font() ); |
266 | slotSetFont(m_config.fontSize()); | 265 | slotSetFont(m_config.fontSize()); |
267 | m_curFontSize = m_config.fontSize(); | 266 | m_curFontSize = m_config.fontSize(); |
268 | 267 | ||
269 | setCentralWidget(listContainer); | 268 | setCentralWidget(listContainer); |
270 | 269 | ||
271 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); | 270 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); |
272 | 271 | ||
273 | 272 | ||
274 | isLoading = false; | 273 | isLoading = false; |
275 | } | 274 | } |
276 | 275 | ||
277 | 276 | ||
278 | void AddressbookWindow::slotConfig() | 277 | void AddressbookWindow::slotConfig() |
279 | { | 278 | { |
280 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); | 279 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); |
281 | dlg -> setConfig( m_config ); | 280 | dlg -> setConfig( m_config ); |
282 | dlg -> showMaximized(); | 281 | dlg -> showMaximized(); |
283 | if ( dlg -> exec() ) { | 282 | if ( dlg -> exec() ) { |
284 | qWarning ("Config Dialog accepted!"); | 283 | qWarning ("Config Dialog accepted!"); |
285 | m_config = dlg -> getConfig(); | 284 | m_config = dlg -> getConfig(); |
286 | if ( m_curFontSize != m_config.fontSize() ){ | 285 | if ( m_curFontSize != m_config.fontSize() ){ |
287 | qWarning("Font was changed!"); | 286 | qWarning("Font was changed!"); |
288 | m_curFontSize = m_config.fontSize(); | 287 | m_curFontSize = m_config.fontSize(); |
289 | emit slotSetFont( m_curFontSize ); | 288 | emit slotSetFont( m_curFontSize ); |
290 | } | 289 | } |
291 | m_abView -> setListOrder( m_config.orderList() ); | 290 | m_abView -> setListOrder( m_config.orderList() ); |
292 | } | 291 | } |
293 | 292 | ||
294 | delete dlg; | 293 | delete dlg; |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
298 | void AddressbookWindow::slotSetFont( int size ) | 297 | void AddressbookWindow::slotSetFont( int size ) |
299 | { | 298 | { |
300 | qWarning("void AddressbookWindow::slotSetFont( %d )", size); | 299 | qWarning("void AddressbookWindow::slotSetFont( %d )", size); |
301 | 300 | ||
302 | if (size > 2 || size < 0) | 301 | if (size > 2 || size < 0) |
303 | size = 1; | 302 | size = 1; |
304 | 303 | ||
305 | m_config.setFontSize( size ); | 304 | m_config.setFontSize( size ); |
306 | 305 | ||
307 | QFont *currentFont; | 306 | QFont *currentFont; |
308 | 307 | ||
309 | switch (size) { | 308 | switch (size) { |
310 | case 0: | 309 | case 0: |
311 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 310 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
312 | currentFont = new QFont (m_abView->font()); | 311 | currentFont = new QFont (m_abView->font()); |
313 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX | 312 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX |
314 | // abList->resizeRows(); | 313 | // abList->resizeRows(); |
315 | break; | 314 | break; |
316 | case 1: | 315 | case 1: |
317 | m_abView->setFont( *defaultFont ); | 316 | m_abView->setFont( *defaultFont ); |
318 | currentFont = new QFont (m_abView->font()); | 317 | currentFont = new QFont (m_abView->font()); |
319 | // // abList->resizeRows(currentFont->pixelSize() + 7); | 318 | // // abList->resizeRows(currentFont->pixelSize() + 7); |
320 | // abList->resizeRows(); | 319 | // abList->resizeRows(); |
321 | break; | 320 | break; |
322 | case 2: | 321 | case 2: |
323 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); | 322 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); |
324 | currentFont = new QFont (m_abView->font()); | 323 | currentFont = new QFont (m_abView->font()); |
325 | // //abList->resizeRows(currentFont->pixelSize() + 7); | 324 | // //abList->resizeRows(currentFont->pixelSize() + 7); |
326 | // abList->resizeRows(); | 325 | // abList->resizeRows(); |
327 | break; | 326 | break; |
328 | } | 327 | } |
329 | } | 328 | } |
330 | 329 | ||
331 | 330 | ||
332 | 331 | ||
333 | void AddressbookWindow::importvCard() { | 332 | void AddressbookWindow::importvCard() { |
334 | QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); | 333 | QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); |
335 | if(!str.isEmpty() ){ | 334 | if(!str.isEmpty() ){ |
336 | setDocument((const QString&) str ); | 335 | setDocument((const QString&) str ); |
337 | } | 336 | } |
338 | 337 | ||
339 | } | 338 | } |
340 | void AddressbookWindow::exportvCard() | 339 | void AddressbookWindow::exportvCard() |
341 | { | 340 | { |
342 | qWarning(" void AddressbookWindow::exportvCard()"); | 341 | qWarning(" void AddressbookWindow::exportvCard()"); |
343 | QString filename = OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); | 342 | QString filename = OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); |
344 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ | 343 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ |
345 | qWarning(" Save to file %s, (%d)", filename.latin1(), filename.length()-1 ); | 344 | qWarning(" Save to file %s, (%d)", filename.latin1(), filename.length()-1 ); |
346 | OContact curCont = m_abView->currentEntry(); | 345 | OContact curCont = m_abView->currentEntry(); |
347 | if ( !curCont.isEmpty() ){ | 346 | if ( !curCont.isEmpty() ){ |
348 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 347 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
349 | filename ); | 348 | filename ); |
350 | OContactAccess* access = new OContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); | 349 | OContactAccess* access = new OContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); |
351 | if ( access ){ | 350 | if ( access ){ |
352 | access->add( curCont ); | 351 | access->add( curCont ); |
353 | access->save(); | 352 | access->save(); |
354 | } | 353 | } |
355 | delete access; | 354 | delete access; |
356 | }else | 355 | }else |
357 | QMessageBox::critical( 0, "Export VCard", | 356 | QMessageBox::critical( 0, "Export VCard", |
358 | QString( tr( "You have to select a contact !") ) ); | 357 | QString( tr( "You have to select a contact !") ) ); |
359 | 358 | ||
360 | }else | 359 | }else |
361 | QMessageBox::critical( 0, "Export VCard", | 360 | QMessageBox::critical( 0, "Export VCard", |
362 | QString( tr( "You have to set a filename !") ) ); | 361 | QString( tr( "You have to set a filename !") ) ); |
363 | } | 362 | } |
364 | 363 | ||
365 | void AddressbookWindow::setDocument( const QString &filename ) | 364 | void AddressbookWindow::setDocument( const QString &filename ) |
366 | { | 365 | { |
367 | qWarning( "void AddressbookWindow::setDocument( %s )", filename.latin1() ); | 366 | qWarning( "void AddressbookWindow::setDocument( %s )", filename.latin1() ); |
368 | 367 | ||
369 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ | 368 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ |
370 | 369 | ||
371 | 370 | ||
372 | 371 | ||
373 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), | 372 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), |
374 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), | 373 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), |
375 | tr( "&Yes" ), tr( "&No" ), QString::null, | 374 | tr( "&Yes" ), tr( "&No" ), QString::null, |
376 | 0, // Enter == button 0 | 375 | 0, // Enter == button 0 |
377 | 2 ) ) { // Escape == button 2 | 376 | 2 ) ) { // Escape == button 2 |
378 | case 0: | 377 | case 0: |
379 | qWarning("YES clicked"); | 378 | qWarning("YES clicked"); |
380 | break; | 379 | break; |
381 | case 1: | 380 | case 1: |
382 | qWarning("NO clicked"); | 381 | qWarning("NO clicked"); |
383 | return; | 382 | return; |
384 | break; | 383 | break; |
385 | } | 384 | } |
386 | } | 385 | } |
387 | 386 | ||
388 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 387 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
389 | filename ); | 388 | filename ); |
390 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 389 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
391 | OContactAccess::List allList = access->allRecords(); | 390 | OContactAccess::List allList = access->allRecords(); |
392 | qWarning( "Found number of contacts in File: %d", allList.count() ); | 391 | qWarning( "Found number of contacts in File: %d", allList.count() ); |
393 | 392 | ||
394 | if ( !allList.count() ) { | 393 | if ( !allList.count() ) { |
395 | QMessageBox::information( this, "Import VCard", | 394 | QMessageBox::information( this, "Import VCard", |
396 | "It was impossible to import\nthe VCard.\n" | 395 | "It was impossible to import\nthe VCard.\n" |
397 | "The VCard may be corrupted!" ); | 396 | "The VCard may be corrupted!" ); |
398 | } | 397 | } |
399 | 398 | ||
400 | bool doAsk = true; | 399 | bool doAsk = true; |
401 | OContactAccess::List::Iterator it; | 400 | OContactAccess::List::Iterator it; |
402 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 401 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
403 | qWarning("Adding Contact from: %s", (*it).fullName().latin1() ); | 402 | qWarning("Adding Contact from: %s", (*it).fullName().latin1() ); |
404 | if ( doAsk ){ | 403 | if ( doAsk ){ |
405 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), | 404 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), |
406 | tr( "Do you really want add contact for \n%1?" ) | 405 | tr( "Do you really want add contact for \n%1?" ) |
407 | .arg( (*it).fullName().latin1() ), | 406 | .arg( (*it).fullName().latin1() ), |
408 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), | 407 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), |
409 | 0, // Enter == button 0 | 408 | 0, // Enter == button 0 |
410 | 2 ) ) { // Escape == button 2 | 409 | 2 ) ) { // Escape == button 2 |
411 | case 0: | 410 | case 0: |
412 | qWarning("YES clicked"); | 411 | qWarning("YES clicked"); |
413 | m_abView->addEntry( *it ); | 412 | m_abView->addEntry( *it ); |
414 | break; | 413 | break; |
415 | case 1: | 414 | case 1: |
416 | qWarning("NO clicked"); | 415 | qWarning("NO clicked"); |
417 | break; | 416 | break; |
418 | case 2: | 417 | case 2: |
419 | qWarning("YesAll clicked"); | 418 | qWarning("YesAll clicked"); |
420 | doAsk = false; | 419 | doAsk = false; |
421 | break; | 420 | break; |
422 | } | 421 | } |
423 | }else | 422 | }else |
424 | m_abView->addEntry( *it ); | 423 | m_abView->addEntry( *it ); |
425 | 424 | ||
426 | } | 425 | } |
427 | 426 | ||
428 | delete access; | 427 | delete access; |
429 | } | 428 | } |
430 | 429 | ||
431 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 430 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
432 | { | 431 | { |
433 | QMainWindow::resizeEvent( e ); | 432 | QMainWindow::resizeEvent( e ); |
434 | 433 | ||
435 | 434 | ||
436 | } | 435 | } |
437 | 436 | ||
438 | AddressbookWindow::~AddressbookWindow() | 437 | AddressbookWindow::~AddressbookWindow() |
439 | { | 438 | { |
440 | ToolBarDock dock; | 439 | ToolBarDock dock; |
441 | int dummy; | 440 | int dummy; |
442 | bool bDummy; | 441 | bool bDummy; |
443 | getLocation ( listTools, dock, dummy, bDummy, dummy ); | 442 | getLocation ( listTools, dock, dummy, bDummy, dummy ); |
444 | m_config.setToolBarDock( dock ); | 443 | m_config.setToolBarDock( dock ); |
445 | m_config.save(); | 444 | m_config.save(); |
446 | } | 445 | } |
447 | 446 | ||
448 | void AddressbookWindow::slotUpdateToolbar() | 447 | void AddressbookWindow::slotUpdateToolbar() |
449 | { | 448 | { |
450 | OContact ce = m_abView->currentEntry(); | 449 | OContact ce = m_abView->currentEntry(); |
451 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); | 450 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); |
452 | } | 451 | } |
453 | 452 | ||
454 | void AddressbookWindow::slotListNew() | 453 | void AddressbookWindow::slotListNew() |
455 | { | 454 | { |
456 | OContact cnt; | 455 | OContact cnt; |
457 | if( !syncing ) { | 456 | if( !syncing ) { |
458 | editEntry( NewEntry ); | 457 | editEntry( NewEntry ); |
459 | } else { | 458 | } else { |
460 | QMessageBox::warning(this, tr("Contacts"), | 459 | QMessageBox::warning(this, tr("Contacts"), |
461 | tr("Can not edit data, currently syncing")); | 460 | tr("Can not edit data, currently syncing")); |
462 | } | 461 | } |
463 | } | 462 | } |
464 | 463 | ||
465 | // void AddressbookWindow::slotListView() | 464 | // void AddressbookWindow::slotListView() |
466 | // { | 465 | // { |
467 | // m_abView -> init( abList->currentEntry() ); | 466 | // m_abView -> init( abList->currentEntry() ); |
468 | // // :SX mView->sync(); | 467 | // // :SX mView->sync(); |
469 | // //:SXshowView(); | 468 | // //:SXshowView(); |
470 | // } | 469 | // } |
471 | 470 | ||
472 | void AddressbookWindow::slotListDelete() | 471 | void AddressbookWindow::slotListDelete() |
473 | { | 472 | { |
474 | if(!syncing) { | 473 | if(!syncing) { |
475 | OContact tmpEntry = m_abView ->currentEntry(); | 474 | OContact tmpEntry = m_abView ->currentEntry(); |
476 | 475 | ||
477 | // get a name, do the best we can... | 476 | // get a name, do the best we can... |
478 | QString strName = tmpEntry.fullName(); | 477 | QString strName = tmpEntry.fullName(); |
479 | if ( strName.isEmpty() ) { | 478 | if ( strName.isEmpty() ) { |
480 | strName = tmpEntry.company(); | 479 | strName = tmpEntry.company(); |
481 | if ( strName.isEmpty() ) | 480 | if ( strName.isEmpty() ) |
482 | strName = "No Name"; | 481 | strName = "No Name"; |
483 | } | 482 | } |
484 | 483 | ||
485 | 484 | ||
486 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 485 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
487 | strName ) ) { | 486 | strName ) ) { |
488 | m_abView->removeEntry( tmpEntry.uid() ); | 487 | m_abView->removeEntry( tmpEntry.uid() ); |
489 | } | 488 | } |
490 | } else { | 489 | } else { |
491 | QMessageBox::warning( this, tr("Contacts"), | 490 | QMessageBox::warning( this, tr("Contacts"), |
492 | tr("Can not edit data, currently syncing") ); | 491 | tr("Can not edit data, currently syncing") ); |
493 | } | 492 | } |
494 | } | 493 | } |
495 | 494 | ||
496 | void AddressbookWindow::slotFindOpen() | 495 | void AddressbookWindow::slotFindOpen() |
497 | { | 496 | { |
498 | searchBar->show(); | 497 | searchBar->show(); |
499 | m_abView -> inSearch(); | 498 | m_abView -> inSearch(); |
500 | searchEdit->setFocus(); | 499 | searchEdit->setFocus(); |
501 | } | 500 | } |
502 | void AddressbookWindow::slotFindClose() | 501 | void AddressbookWindow::slotFindClose() |
503 | { | 502 | { |
504 | searchBar->hide(); | 503 | searchBar->hide(); |
505 | m_abView -> offSearch(); | 504 | m_abView -> offSearch(); |
506 | // m_abView->setFocus(); | 505 | // m_abView->setFocus(); |
507 | } | 506 | } |
508 | 507 | ||
509 | 508 | ||
510 | void AddressbookWindow::slotFind() | 509 | void AddressbookWindow::slotFind() |
511 | { | 510 | { |
512 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); | 511 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); |
513 | 512 | ||
514 | searchEdit->clearFocus(); | 513 | searchEdit->clearFocus(); |
515 | // m_abView->setFocus(); | 514 | // m_abView->setFocus(); |
516 | 515 | ||
517 | } | 516 | } |
518 | 517 | ||
519 | void AddressbookWindow::slotViewBack() | 518 | void AddressbookWindow::slotViewBack() |
520 | { | 519 | { |
521 | // :SX showList(); | 520 | // :SX showList(); |
522 | } | 521 | } |
523 | 522 | ||
524 | void AddressbookWindow::slotViewEdit() | 523 | void AddressbookWindow::slotViewEdit() |
525 | { | 524 | { |
526 | if(!syncing) { | 525 | if(!syncing) { |
527 | if (actionPersonal->isOn()) { | 526 | if (actionPersonal->isOn()) { |
528 | editPersonal(); | 527 | editPersonal(); |
529 | } else { | 528 | } else { |
530 | editEntry( EditEntry ); | 529 | editEntry( EditEntry ); |
531 | } | 530 | } |
532 | } else { | 531 | } else { |
533 | QMessageBox::warning( this, tr("Contacts"), | 532 | QMessageBox::warning( this, tr("Contacts"), |
534 | tr("Can not edit data, currently syncing") ); | 533 | tr("Can not edit data, currently syncing") ); |
535 | } | 534 | } |
536 | } | 535 | } |
537 | 536 | ||
538 | 537 | ||
539 | 538 | ||
540 | void AddressbookWindow::writeMail() | 539 | void AddressbookWindow::writeMail() |
541 | { | 540 | { |
542 | OContact c = m_abView -> currentEntry(); | 541 | OContact c = m_abView -> currentEntry(); |
543 | QString name = c.fileAs(); | 542 | QString name = c.fileAs(); |
544 | QString email = c.defaultEmail(); | 543 | QString email = c.defaultEmail(); |
545 | 544 | ||
546 | // I prefer the OPIE-Environment variable before the | 545 | // I prefer the OPIE-Environment variable before the |
547 | // QPE-one.. | 546 | // QPE-one.. |
548 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); | 547 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); |
549 | if ( basepath.isEmpty() ) | 548 | if ( basepath.isEmpty() ) |
550 | basepath = QString::fromLatin1( getenv("QPEDIR") ); | 549 | basepath = QString::fromLatin1( getenv("QPEDIR") ); |
551 | 550 | ||
552 | // Try to access the preferred. If not possible, try to | 551 | // Try to access the preferred. If not possible, try to |
553 | // switch to the other one.. | 552 | // switch to the other one.. |
554 | if ( m_config.useQtMail() ){ | 553 | if ( m_config.useQtMail() ){ |
555 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); | 554 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); |
556 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ | 555 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ |
557 | qWarning ("QCop"); | 556 | qWarning ("QCop"); |
558 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 557 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
559 | e << name << email; | 558 | e << name << email; |
560 | return; | 559 | return; |
561 | } else | 560 | } else |
562 | m_config.setUseOpieMail( true ); | 561 | m_config.setUseOpieMail( true ); |
563 | } | 562 | } |
564 | if ( m_config.useOpieMail() ){ | 563 | if ( m_config.useOpieMail() ){ |
565 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); | 564 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); |
566 | if ( QFile::exists( basepath + "/bin/mail" ) ){ | 565 | if ( QFile::exists( basepath + "/bin/mail" ) ){ |
567 | qWarning ("QCop"); | 566 | qWarning ("QCop"); |
568 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); | 567 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); |
569 | e << name << email; | 568 | e << name << email; |
570 | return; | 569 | return; |
571 | } else | 570 | } else |
572 | m_config.setUseQtMail( true ); | 571 | m_config.setUseQtMail( true ); |
573 | } | 572 | } |
574 | 573 | ||
575 | } | 574 | } |
576 | 575 | ||
577 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 576 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
578 | 577 | ||
579 | void AddressbookWindow::slotBeam() | 578 | void AddressbookWindow::slotBeam() |
580 | { | 579 | { |
581 | QString beamFilename; | 580 | QString beamFilename; |
582 | OContact c; | 581 | OContact c; |
583 | if ( actionPersonal->isOn() ) { | 582 | if ( actionPersonal->isOn() ) { |
584 | beamFilename = addressbookPersonalVCardName(); | 583 | beamFilename = addressbookPersonalVCardName(); |
585 | if ( !QFile::exists( beamFilename ) ) | 584 | if ( !QFile::exists( beamFilename ) ) |
586 | return; // can't beam a non-existent file | 585 | return; // can't beam a non-existent file |
587 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 586 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
588 | beamFilename ); | 587 | beamFilename ); |
589 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 588 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
590 | OContactAccess::List allList = access->allRecords(); | 589 | OContactAccess::List allList = access->allRecords(); |
591 | OContactAccess::List::Iterator it = allList.begin(); // Just take first | 590 | OContactAccess::List::Iterator it = allList.begin(); // Just take first |
592 | c = *it; | 591 | c = *it; |
593 | 592 | ||
594 | delete access; | 593 | delete access; |
595 | } else { | 594 | } else { |
596 | unlink( beamfile ); // delete if exists | 595 | unlink( beamfile ); // delete if exists |
597 | mkdir("/tmp/obex/", 0755); | 596 | mkdir("/tmp/obex/", 0755); |
598 | c = m_abView -> currentEntry(); | 597 | c = m_abView -> currentEntry(); |
599 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 598 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
600 | beamfile ); | 599 | beamfile ); |
601 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 600 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
602 | access->add( c ); | 601 | access->add( c ); |
603 | access->save(); | 602 | access->save(); |
604 | delete access; | 603 | delete access; |
605 | 604 | ||
606 | beamFilename = beamfile; | 605 | beamFilename = beamfile; |
607 | } | 606 | } |
608 | 607 | ||
609 | qWarning("Beaming: %s", beamFilename.latin1() ); | 608 | qWarning("Beaming: %s", beamFilename.latin1() ); |
610 | 609 | ||
611 | Ir *ir = new Ir( this ); | 610 | Ir *ir = new Ir( this ); |
612 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 611 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
613 | QString description = c.fullName(); | 612 | QString description = c.fullName(); |
614 | ir->send( beamFilename, description, "text/x-vCard" ); | 613 | ir->send( beamFilename, description, "text/x-vCard" ); |
615 | } | 614 | } |
616 | 615 | ||
617 | void AddressbookWindow::beamDone( Ir *ir ) | 616 | void AddressbookWindow::beamDone( Ir *ir ) |
618 | { | 617 | { |
619 | 618 | ||
620 | delete ir; | 619 | delete ir; |
621 | unlink( beamfile ); | 620 | unlink( beamfile ); |
622 | } | 621 | } |
623 | 622 | ||
624 | 623 | ||
625 | static void parseName( const QString& name, QString *first, QString *middle, | 624 | static void parseName( const QString& name, QString *first, QString *middle, |
626 | QString * last ) | 625 | QString * last ) |
627 | { | 626 | { |
628 | 627 | ||
629 | int comma = name.find ( "," ); | 628 | int comma = name.find ( "," ); |
630 | QString rest; | 629 | QString rest; |
631 | if ( comma > 0 ) { | 630 | if ( comma > 0 ) { |
632 | *last = name.left( comma ); | 631 | *last = name.left( comma ); |
633 | comma++; | 632 | comma++; |
634 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 633 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
635 | comma++; | 634 | comma++; |
636 | rest = name.mid( comma ); | 635 | rest = name.mid( comma ); |
637 | } else { | 636 | } else { |
638 | int space = name.findRev( ' ' ); | 637 | int space = name.findRev( ' ' ); |
639 | *last = name.mid( space+1 ); | 638 | *last = name.mid( space+1 ); |
640 | rest = name.left( space ); | 639 | rest = name.left( space ); |
641 | } | 640 | } |
642 | int space = rest.find( ' ' ); | 641 | int space = rest.find( ' ' ); |
643 | if ( space <= 0 ) { | 642 | if ( space <= 0 ) { |
644 | *first = rest; | 643 | *first = rest; |
645 | } else { | 644 | } else { |
646 | *first = rest.left( space ); | 645 | *first = rest.left( space ); |
647 | *middle = rest.mid( space+1 ); | 646 | *middle = rest.mid( space+1 ); |
648 | } | 647 | } |
649 | 648 | ||
650 | } | 649 | } |
651 | 650 | ||
652 | 651 | ||
653 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 652 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
654 | { | 653 | { |
655 | qWarning("Receiving QCop-Call with message %s", QString( msg ).latin1() ); | 654 | bool needShow = FALSE; |
655 | qWarning("Receiving QCop-Call with message %s", QString( msg ).latin1() ); | ||
656 | |||
656 | 657 | ||
657 | if (msg == "editPersonal()") { | 658 | if (msg == "editPersonal()") { |
658 | editPersonal(); | 659 | editPersonal(); |
659 | } else if (msg == "editPersonalAndClose()") { | 660 | } else if (msg == "editPersonalAndClose()") { |
660 | editPersonal(); | 661 | editPersonal(); |
661 | close(); | 662 | close(); |
662 | } else if ( msg == "addContact(QString,QString)" ) { | 663 | } else if ( msg == "addContact(QString,QString)" ) { |
663 | QDataStream stream(data,IO_ReadOnly); | 664 | QDataStream stream(data,IO_ReadOnly); |
664 | QString name, email; | 665 | QString name, email; |
665 | stream >> name >> email; | 666 | stream >> name >> email; |
666 | 667 | ||
667 | OContact cnt; | 668 | OContact cnt; |
668 | QString fn, mn, ln; | 669 | QString fn, mn, ln; |
669 | parseName( name, &fn, &mn, &ln ); | 670 | parseName( name, &fn, &mn, &ln ); |
670 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); | 671 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); |
671 | cnt.setFirstName( fn ); | 672 | cnt.setFirstName( fn ); |
672 | cnt.setMiddleName( mn ); | 673 | cnt.setMiddleName( mn ); |
673 | cnt.setLastName( ln ); | 674 | cnt.setLastName( ln ); |
674 | cnt.insertEmails( email ); | 675 | cnt.insertEmails( email ); |
675 | cnt.setDefaultEmail( email ); | 676 | cnt.setDefaultEmail( email ); |
676 | cnt.setFileAs(); | 677 | cnt.setFileAs(); |
677 | 678 | ||
678 | m_abView -> addEntry( cnt ); | 679 | m_abView -> addEntry( cnt ); |
679 | 680 | ||
680 | // :SXm_abView()->init( cnt ); | 681 | // :SXm_abView()->init( cnt ); |
681 | editEntry( EditEntry ); | 682 | editEntry( EditEntry ); |
682 | } else if ( msg == "beamBusinessCard()" ) { | 683 | } else if ( msg == "beamBusinessCard()" ) { |
683 | QString beamFilename = addressbookPersonalVCardName(); | 684 | QString beamFilename = addressbookPersonalVCardName(); |
684 | if ( !QFile::exists( beamFilename ) ) | 685 | if ( !QFile::exists( beamFilename ) ) |
685 | return; // can't beam a non-existent file | 686 | return; // can't beam a non-existent file |
686 | 687 | ||
687 | Ir *ir = new Ir( this ); | 688 | Ir *ir = new Ir( this ); |
688 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 689 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
689 | QString description = "mycard.vcf"; | 690 | QString description = "mycard.vcf"; |
690 | ir->send( beamFilename, description, "text/x-vCard" ); | 691 | ir->send( beamFilename, description, "text/x-vCard" ); |
691 | } else if ( msg == "show(int)" ) { | 692 | } else if ( msg == "show(int)" ) { |
693 | raise(); | ||
692 | QDataStream stream(data,IO_ReadOnly); | 694 | QDataStream stream(data,IO_ReadOnly); |
693 | int uid; | 695 | int uid; |
694 | stream >> uid; | 696 | stream >> uid; |
695 | 697 | ||
696 | qWarning( "Showing uid: %d" , uid ); | 698 | qWarning( "Showing uid: %d" , uid ); |
697 | 699 | ||
698 | // Deactivate Personal View.. | 700 | // Deactivate Personal View.. |
699 | if ( actionPersonal->isOn() ){ | 701 | if ( actionPersonal->isOn() ){ |
700 | actionPersonal->setOn( false ); | 702 | actionPersonal->setOn( false ); |
701 | slotPersonalView(); | 703 | slotPersonalView(); |
702 | } | 704 | } |
703 | 705 | ||
704 | // Reset category and show as card.. | 706 | // Reset category and show as card.. |
705 | m_abView -> setShowByCategory( QString::null ); | 707 | m_abView -> setShowByCategory( QString::null ); |
706 | m_abView -> setCurrentUid( uid ); | 708 | m_abView -> setCurrentUid( uid ); |
707 | slotViewSwitched ( AbView::CardView ); | 709 | slotViewSwitched ( AbView::CardView ); |
708 | 710 | ||
709 | showMaximized(); | 711 | needShow = true; |
710 | qApp->exec(); | 712 | |
711 | 713 | ||
712 | } else if ( msg == "edit(int)" ) { | 714 | } else if ( msg == "edit(int)" ) { |
713 | QDataStream stream(data,IO_ReadOnly); | 715 | QDataStream stream(data,IO_ReadOnly); |
714 | int uid; | 716 | int uid; |
715 | stream >> uid; | 717 | stream >> uid; |
716 | 718 | ||
717 | // Deactivate Personal View.. | 719 | // Deactivate Personal View.. |
718 | if ( actionPersonal->isOn() ){ | 720 | if ( actionPersonal->isOn() ){ |
719 | actionPersonal->setOn( false ); | 721 | actionPersonal->setOn( false ); |
720 | slotPersonalView(); | 722 | slotPersonalView(); |
721 | } | 723 | } |
722 | 724 | ||
723 | // Reset category and edit.. | 725 | // Reset category and edit.. |
724 | m_abView -> setShowByCategory( QString::null ); | 726 | m_abView -> setShowByCategory( QString::null ); |
725 | m_abView -> setCurrentUid( uid ); | 727 | m_abView -> setCurrentUid( uid ); |
726 | slotViewEdit(); | 728 | slotViewEdit(); |
727 | } | 729 | } |
730 | |||
731 | if (needShow) | ||
732 | QPEApplication::setKeepRunning(); | ||
728 | 733 | ||
729 | } | 734 | } |
730 | 735 | ||
731 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 736 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
732 | { | 737 | { |
733 | OContact entry; | 738 | OContact entry; |
734 | if ( !abEditor ) { | 739 | if ( !abEditor ) { |
735 | abEditor = new ContactEditor( entry, this, "editor" ); | 740 | abEditor = new ContactEditor( entry, this, "editor" ); |
736 | } | 741 | } |
737 | if ( entryMode == EditEntry ) | 742 | if ( entryMode == EditEntry ) |
738 | abEditor->setEntry( m_abView -> currentEntry() ); | 743 | abEditor->setEntry( m_abView -> currentEntry() ); |
739 | else if ( entryMode == NewEntry ) | 744 | else if ( entryMode == NewEntry ) |
740 | abEditor->setEntry( entry ); | 745 | abEditor->setEntry( entry ); |
741 | // other things may change the caption. | 746 | // other things may change the caption. |
742 | abEditor->setCaption( tr("Edit Address") ); | 747 | abEditor->setCaption( tr("Edit Address") ); |
743 | 748 | ||
744 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 749 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
745 | abEditor->showMaximized(); | 750 | abEditor->showMaximized(); |
746 | #endif | 751 | #endif |
747 | // fix the foxus... | 752 | // fix the foxus... |
748 | abEditor->setNameFocus(); | 753 | abEditor->setNameFocus(); |
749 | if ( abEditor->exec() ) { | 754 | if ( abEditor->exec() ) { |
750 | setFocus(); | 755 | setFocus(); |
751 | if ( entryMode == NewEntry ) { | 756 | if ( entryMode == NewEntry ) { |
752 | OContact insertEntry = abEditor->entry(); | 757 | OContact insertEntry = abEditor->entry(); |
753 | insertEntry.assignUid(); | 758 | insertEntry.assignUid(); |
754 | m_abView -> addEntry( insertEntry ); | 759 | m_abView -> addEntry( insertEntry ); |
755 | m_abView -> setCurrentUid( insertEntry.uid() ); | 760 | m_abView -> setCurrentUid( insertEntry.uid() ); |
756 | } else { | 761 | } else { |
757 | OContact replEntry = abEditor->entry(); | 762 | OContact replEntry = abEditor->entry(); |
758 | 763 | ||
759 | if ( !replEntry.isValidUid() ) | 764 | if ( !replEntry.isValidUid() ) |
760 | replEntry.assignUid(); | 765 | replEntry.assignUid(); |
761 | 766 | ||
762 | m_abView -> replaceEntry( replEntry ); | 767 | m_abView -> replaceEntry( replEntry ); |
763 | } | 768 | } |
764 | } | 769 | } |
765 | // populateCategories(); | 770 | // populateCategories(); |
766 | 771 | ||
767 | } | 772 | } |
768 | 773 | ||
769 | void AddressbookWindow::editPersonal() | 774 | void AddressbookWindow::editPersonal() |
770 | { | 775 | { |
771 | OContact entry; | 776 | OContact entry; |
772 | 777 | ||
773 | // Switch to personal view if not selected | 778 | // Switch to personal view if not selected |
774 | // but take care of the menu, too | 779 | // but take care of the menu, too |
775 | if ( ! actionPersonal->isOn() ){ | 780 | if ( ! actionPersonal->isOn() ){ |
776 | qWarning("*** ++++"); | 781 | qWarning("*** ++++"); |
777 | actionPersonal->setOn( true ); | 782 | actionPersonal->setOn( true ); |
778 | slotPersonalView(); | 783 | slotPersonalView(); |
779 | } | 784 | } |
780 | 785 | ||
781 | if ( !abEditor ) { | 786 | if ( !abEditor ) { |
782 | abEditor = new ContactEditor( entry, this, "editor" ); | 787 | abEditor = new ContactEditor( entry, this, "editor" ); |
783 | } | 788 | } |
784 | 789 | ||
785 | abEditor->setCaption(tr("Edit My Personal Details")); | 790 | abEditor->setCaption(tr("Edit My Personal Details")); |
786 | abEditor->setPersonalView( true ); | 791 | abEditor->setPersonalView( true ); |
787 | editEntry( EditEntry ); | 792 | editEntry( EditEntry ); |
788 | abEditor->setPersonalView( false ); | 793 | abEditor->setPersonalView( false ); |
789 | 794 | ||
790 | } | 795 | } |
791 | 796 | ||
792 | 797 | ||
793 | void AddressbookWindow::slotPersonalView() | 798 | void AddressbookWindow::slotPersonalView() |
794 | { | 799 | { |
795 | qWarning("slotPersonalView()"); | 800 | qWarning("slotPersonalView()"); |
796 | if (!actionPersonal->isOn()) { | 801 | if (!actionPersonal->isOn()) { |
797 | // we just turned it off | 802 | // we just turned it off |
798 | qWarning("slotPersonalView()-> OFF"); | 803 | qWarning("slotPersonalView()-> OFF"); |
799 | setCaption( tr("Contacts") ); | 804 | setCaption( tr("Contacts") ); |
800 | actionNew->setEnabled(TRUE); | 805 | actionNew->setEnabled(TRUE); |
801 | actionTrash->setEnabled(TRUE); | 806 | actionTrash->setEnabled(TRUE); |
802 | actionFind->setEnabled(TRUE); | 807 | actionFind->setEnabled(TRUE); |
803 | actionMail->setEnabled(TRUE); | 808 | actionMail->setEnabled(TRUE); |
804 | // slotUpdateToolbar(); | 809 | // slotUpdateToolbar(); |
805 | 810 | ||
806 | m_abView->showPersonal( false ); | 811 | m_abView->showPersonal( false ); |
807 | 812 | ||
808 | return; | 813 | return; |
809 | } | 814 | } |
810 | 815 | ||
811 | qWarning("slotPersonalView()-> ON"); | 816 | qWarning("slotPersonalView()-> ON"); |
812 | // XXX need to disable some QActions. | 817 | // XXX need to disable some QActions. |
813 | actionNew->setEnabled(FALSE); | 818 | actionNew->setEnabled(FALSE); |
814 | actionTrash->setEnabled(FALSE); | 819 | actionTrash->setEnabled(FALSE); |
815 | actionFind->setEnabled(FALSE); | 820 | actionFind->setEnabled(FALSE); |
816 | actionMail->setEnabled(FALSE); | 821 | actionMail->setEnabled(FALSE); |
817 | 822 | ||
818 | setCaption( tr("Contacts - My Personal Details") ); | 823 | setCaption( tr("Contacts - My Personal Details") ); |
819 | 824 | ||
820 | m_abView->showPersonal( true ); | 825 | m_abView->showPersonal( true ); |
821 | 826 | ||
822 | } | 827 | } |
823 | 828 | ||
824 | 829 | ||
825 | void AddressbookWindow::listIsEmpty( bool empty ) | 830 | void AddressbookWindow::listIsEmpty( bool empty ) |
826 | { | 831 | { |
827 | if ( !empty ) { | 832 | if ( !empty ) { |
828 | deleteButton->setEnabled( TRUE ); | 833 | deleteButton->setEnabled( TRUE ); |
829 | } | 834 | } |
830 | } | 835 | } |
831 | 836 | ||
832 | void AddressbookWindow::reload() | 837 | void AddressbookWindow::reload() |
833 | { | 838 | { |
834 | syncing = FALSE; | 839 | syncing = FALSE; |
835 | m_abView->clear(); | 840 | m_abView->clear(); |
836 | m_abView->reload(); | 841 | m_abView->reload(); |
837 | } | 842 | } |
838 | 843 | ||
839 | void AddressbookWindow::flush() | 844 | void AddressbookWindow::flush() |
840 | { | 845 | { |
841 | syncing = TRUE; | 846 | syncing = TRUE; |
842 | m_abView->save(); | 847 | m_abView->save(); |
843 | } | 848 | } |
844 | 849 | ||
845 | 850 | ||
846 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 851 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
847 | { | 852 | { |
848 | if(active_view == AbView::CardView){ | 853 | if(active_view == AbView::CardView){ |
849 | slotViewSwitched( AbView::TableView ); | 854 | slotViewSwitched( AbView::TableView ); |
850 | e->ignore(); | 855 | e->ignore(); |
851 | return; | 856 | return; |
852 | } | 857 | } |
853 | if(syncing) { | 858 | if(syncing) { |
854 | /* shouldn't we save, I hear you say? well its already been set | 859 | /* shouldn't we save, I hear you say? well its already been set |
855 | so that an edit can not occur during a sync, and we flushed | 860 | so that an edit can not occur during a sync, and we flushed |
856 | at the start of the sync, so there is no need to save | 861 | at the start of the sync, so there is no need to save |
857 | Saving however itself would cause problems. */ | 862 | Saving however itself would cause problems. */ |
858 | e->accept(); | 863 | e->accept(); |
859 | return; | 864 | return; |
860 | } | 865 | } |
861 | //################## shouldn't always save | 866 | //################## shouldn't always save |
862 | // True, but the database handles this automatically ! (se) | 867 | // True, but the database handles this automatically ! (se) |
863 | if ( save() ) | 868 | if ( save() ) |
864 | e->accept(); | 869 | e->accept(); |
865 | else | 870 | else |
866 | e->ignore(); | 871 | e->ignore(); |
867 | } | 872 | } |
868 | 873 | ||
869 | /* | 874 | /* |
870 | Returns TRUE if it is OK to exit | 875 | Returns TRUE if it is OK to exit |
871 | */ | 876 | */ |
872 | 877 | ||
873 | bool AddressbookWindow::save() | 878 | bool AddressbookWindow::save() |
874 | { | 879 | { |
875 | if ( !m_abView->save() ) { | 880 | if ( !m_abView->save() ) { |
876 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 881 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
877 | tr("Unable to save information.\n" | 882 | tr("Unable to save information.\n" |
878 | "Free up some space\n" | 883 | "Free up some space\n" |
879 | "and try again.\n" | 884 | "and try again.\n" |
880 | "\nQuit anyway?"), | 885 | "\nQuit anyway?"), |
881 | QMessageBox::Yes|QMessageBox::Escape, | 886 | QMessageBox::Yes|QMessageBox::Escape, |
882 | QMessageBox::No|QMessageBox::Default ) | 887 | QMessageBox::No|QMessageBox::Default ) |
883 | != QMessageBox::No ) | 888 | != QMessageBox::No ) |
884 | return TRUE; | 889 | return TRUE; |
885 | else | 890 | else |
886 | return FALSE; | 891 | return FALSE; |
887 | } | 892 | } |
888 | return TRUE; | 893 | return TRUE; |
889 | } | 894 | } |
890 | 895 | ||
891 | #ifdef __DEBUG_RELEASE | 896 | #ifdef __DEBUG_RELEASE |
892 | void AddressbookWindow::slotSave() | 897 | void AddressbookWindow::slotSave() |
893 | { | 898 | { |
894 | save(); | 899 | save(); |
895 | } | 900 | } |
896 | #endif | 901 | #endif |
897 | 902 | ||
898 | 903 | ||
899 | void AddressbookWindow::slotNotFound() | 904 | void AddressbookWindow::slotNotFound() |
900 | { | 905 | { |
901 | qWarning("Got notfound signal!"); | 906 | qWarning("Got notfound signal!"); |
902 | QMessageBox::information( this, tr( "Not Found" ), | 907 | QMessageBox::information( this, tr( "Not Found" ), |
903 | tr( "Unable to find a contact for this \n search pattern!" ) ); | 908 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); |
904 | 909 | ||
905 | 910 | ||
906 | } | 911 | } |
907 | void AddressbookWindow::slotWrapAround() | 912 | void AddressbookWindow::slotWrapAround() |
908 | { | 913 | { |
909 | qWarning("Got wrap signal!"); | 914 | qWarning("Got wrap signal!"); |
910 | // if ( doNotifyWrapAround ) | 915 | // if ( doNotifyWrapAround ) |
911 | // QMessageBox::information( this, tr( "End of list" ), | 916 | // QMessageBox::information( this, tr( "End of list" ), |
912 | // tr( "End of list. Wrap around now...!" ) + "\n" ); | 917 | // tr( "End of list. Wrap around now...!" ) + "\n" ); |
913 | 918 | ||
914 | } | 919 | } |
915 | 920 | ||
916 | void AddressbookWindow::slotSetCategory( int c ) | 921 | void AddressbookWindow::slotSetCategory( int c ) |
917 | { | 922 | { |
918 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); | 923 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); |
919 | 924 | ||
920 | QString cat, book; | 925 | QString cat, book; |
921 | AbView::Views view = AbView::TableView; | 926 | AbView::Views view = AbView::TableView; |
922 | 927 | ||
923 | if ( c <= 0 ) | 928 | if ( c <= 0 ) |
924 | return; | 929 | return; |
925 | 930 | ||
926 | // Switch view | 931 | // Switch view |
927 | if ( c < 3 ) | 932 | if ( c < 3 ) |
928 | for ( unsigned int i = 1; i < 3; i++ ){ | 933 | for ( unsigned int i = 1; i < 3; i++ ){ |
929 | if ( catMenu ) | 934 | if ( catMenu ) |
930 | catMenu->setItemChecked( i, c == (int)i ); | 935 | catMenu->setItemChecked( i, c == (int)i ); |
931 | } | 936 | } |
932 | else | 937 | else |
933 | // Checkmark Category Menu Item Selected | 938 | // Checkmark Category Menu Item Selected |
934 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) | 939 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) |
935 | catMenu->setItemChecked( i, c == (int)i ); | 940 | catMenu->setItemChecked( i, c == (int)i ); |
936 | 941 | ||
937 | // Now switch to the selected category | 942 | // Now switch to the selected category |
938 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { | 943 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { |
939 | if (catMenu->isItemChecked( i )) { | 944 | if (catMenu->isItemChecked( i )) { |
940 | if ( i == 1 ){ // default List view | 945 | if ( i == 1 ){ // default List view |
941 | book = QString::null; | 946 | book = QString::null; |
942 | view = AbView::TableView; | 947 | view = AbView::TableView; |
943 | }else if ( i == 2 ){ | 948 | }else if ( i == 2 ){ |
944 | book = tr( "Cards" ); | 949 | book = tr( "Cards" ); |
945 | view = AbView::CardView; | 950 | view = AbView::CardView; |
946 | // }else if ( i == 3 ){ | 951 | // }else if ( i == 3 ){ |
947 | // book = tr( "Personal" ); | 952 | // book = tr( "Personal" ); |
948 | // view = AbView:: PersonalView; | 953 | // view = AbView:: PersonalView; |
949 | }else if ( i == 3 ){ // default All Categories | 954 | }else if ( i == 3 ){ // default All Categories |
950 | cat = QString::null; | 955 | cat = QString::null; |
951 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled | 956 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled |
952 | cat = "Unfiled"; | 957 | cat = "Unfiled"; |
953 | qWarning ("Unfiled selected!!!"); | 958 | qWarning ("Unfiled selected!"); |
954 | }else{ | 959 | }else{ |
955 | cat = m_abView->categories()[i - 4]; | 960 | cat = m_abView->categories()[i - 4]; |
956 | } | 961 | } |
957 | } | 962 | } |
958 | } | 963 | } |
959 | 964 | ||
960 | // Switch to the selected View | 965 | // Switch to the selected View |
961 | slotViewSwitched( view ); | 966 | slotViewSwitched( view ); |
962 | 967 | ||
963 | // Tell the view about the selected category | 968 | // Tell the view about the selected category |
964 | m_abView -> setShowByCategory( cat ); | 969 | m_abView -> setShowByCategory( cat ); |
965 | 970 | ||
966 | if ( book.isEmpty() ) | 971 | if ( book.isEmpty() ) |
967 | book = "List"; | 972 | book = "List"; |
968 | if ( cat.isEmpty() ) | 973 | if ( cat.isEmpty() ) |
969 | cat = "All"; | 974 | cat = "All"; |
970 | 975 | ||
971 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); | 976 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); |
972 | } | 977 | } |
973 | 978 | ||
974 | void AddressbookWindow::slotViewSwitched( int view ) | 979 | void AddressbookWindow::slotViewSwitched( int view ) |
975 | { | 980 | { |
976 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); | 981 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); |
977 | int menu = 0; | 982 | int menu = 0; |
978 | 983 | ||
979 | // Switch to selected view | 984 | // Switch to selected view |
980 | switch ( view ){ | 985 | switch ( view ){ |
981 | case AbView::TableView: | 986 | case AbView::TableView: |
982 | menu = 1; | 987 | menu = 1; |
983 | m_tableViewButton->setOn(true); | 988 | m_tableViewButton->setOn(true); |
984 | m_cardViewButton->setOn(false); | 989 | m_cardViewButton->setOn(false); |
985 | break; | 990 | break; |
986 | case AbView::CardView: | 991 | case AbView::CardView: |
987 | menu = 2; | 992 | menu = 2; |
988 | m_tableViewButton->setOn(false); | 993 | m_tableViewButton->setOn(false); |
989 | m_cardViewButton->setOn(true); | 994 | m_cardViewButton->setOn(true); |
990 | break; | 995 | break; |
991 | } | 996 | } |
992 | for ( unsigned int i = 1; i < 3; i++ ){ | 997 | for ( unsigned int i = 1; i < 3; i++ ){ |
993 | if ( catMenu ) | 998 | if ( catMenu ) |
994 | catMenu->setItemChecked( i, menu == (int)i ); | 999 | catMenu->setItemChecked( i, menu == (int)i ); |
995 | } | 1000 | } |
996 | 1001 | ||
997 | // Tell the view about the selected view | 1002 | // Tell the view about the selected view |
998 | m_abView -> setShowToView ( (AbView::Views) view ); | 1003 | m_abView -> setShowToView ( (AbView::Views) view ); |
999 | active_view = view; | 1004 | active_view = view; |
1000 | } | 1005 | } |
1001 | 1006 | ||
1002 | 1007 | ||
1003 | void AddressbookWindow::slotListView() | 1008 | void AddressbookWindow::slotListView() |
1004 | { | 1009 | { |
1005 | slotViewSwitched( AbView::TableView ); | 1010 | slotViewSwitched( AbView::TableView ); |
1006 | } | 1011 | } |
1007 | 1012 | ||
1008 | void AddressbookWindow::slotCardView() | 1013 | void AddressbookWindow::slotCardView() |
1009 | { | 1014 | { |
1010 | slotViewSwitched( AbView::CardView ); | 1015 | slotViewSwitched( AbView::CardView ); |
1011 | } | 1016 | } |
1012 | 1017 | ||
1013 | void AddressbookWindow::slotSetLetter( char c ) { | 1018 | void AddressbookWindow::slotSetLetter( char c ) { |
1014 | 1019 | ||
1015 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); | 1020 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); |
1016 | 1021 | ||
1017 | } | 1022 | } |
1018 | 1023 | ||
1019 | 1024 | ||
1020 | void AddressbookWindow::populateCategories() | 1025 | void AddressbookWindow::populateCategories() |
1021 | { | 1026 | { |
1022 | catMenu->clear(); | 1027 | catMenu->clear(); |
1023 | 1028 | ||
1024 | int id, rememberId; | 1029 | int id, rememberId; |
1025 | id = 1; | 1030 | id = 1; |
1026 | rememberId = 0; | 1031 | rememberId = 0; |
1027 | 1032 | ||
1028 | catMenu->insertItem( Resource::loadPixmap( "datebook/weeklst" ), tr( "List" ), id++ ); | 1033 | catMenu->insertItem( Resource::loadPixmap( "datebook/weeklst" ), tr( "List" ), id++ ); |
1029 | catMenu->insertItem( Resource::loadPixmap( "day" ), tr( "Cards" ), id++ ); | 1034 | catMenu->insertItem( Resource::loadPixmap( "day" ), tr( "Cards" ), id++ ); |
1030 | // catMenu->insertItem( tr( "Personal" ), id++ ); | 1035 | // catMenu->insertItem( tr( "Personal" ), id++ ); |
1031 | catMenu->insertSeparator(); | 1036 | catMenu->insertSeparator(); |
1032 | 1037 | ||
1033 | catMenu->insertItem( tr( "All" ), id++ ); | 1038 | catMenu->insertItem( tr( "All" ), id++ ); |
1034 | QStringList categories = m_abView->categories(); | 1039 | QStringList categories = m_abView->categories(); |
1035 | categories.append( tr( "Unfiled" ) ); | 1040 | categories.append( tr( "Unfiled" ) ); |
1036 | for ( QStringList::Iterator it = categories.begin(); | 1041 | for ( QStringList::Iterator it = categories.begin(); |
1037 | it != categories.end(); ++it ) { | 1042 | it != categories.end(); ++it ) { |
1038 | catMenu->insertItem( *it, id ); | 1043 | catMenu->insertItem( *it, id ); |
1039 | if ( *it == m_abView -> showCategory() ) | 1044 | if ( *it == m_abView -> showCategory() ) |
1040 | rememberId = id; | 1045 | rememberId = id; |
1041 | ++id; | 1046 | ++id; |
1042 | } | 1047 | } |
1043 | 1048 | ||
1044 | 1049 | ||
1045 | if ( m_abView -> showCategory().isEmpty() ) { | 1050 | if ( m_abView -> showCategory().isEmpty() ) { |
1046 | slotSetCategory( 3 ); | 1051 | slotSetCategory( 3 ); |
1047 | } | 1052 | } |
1048 | else { | 1053 | else { |
1049 | slotSetCategory( rememberId ); | 1054 | slotSetCategory( rememberId ); |
1050 | } | 1055 | } |
1051 | } | 1056 | } |
1052 | 1057 | ||
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp index ce14f98..9d1a1c7 100644 --- a/core/pim/addressbook/contacteditor.cpp +++ b/core/pim/addressbook/contacteditor.cpp | |||
@@ -1,1760 +1,1760 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2002 Michael R. Crawford <mike@tuxnami.org> | 2 | * Copyright (c) 2002 Michael R. Crawford <mike@tuxnami.org> |
3 | * Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) | 3 | * Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) |
4 | * | 4 | * |
5 | * This file is an add-on for the OPIE Palmtop Environment | 5 | * This file is an add-on for the OPIE Palmtop Environment |
6 | * | 6 | * |
7 | * This file may be distributed and/or modified under the terms of the | 7 | * This file may be distributed and/or modified under the terms of the |
8 | * GNU General Public License version 2 as published by the Free Software | 8 | * GNU General Public License version 2 as published by the Free Software |
9 | * Foundation and appearing in the file LICENSE.GPL included in the pacakaging | 9 | * Foundation and appearing in the file LICENSE.GPL included in the pacakaging |
10 | * of this file. | 10 | * of this file. |
11 | * | 11 | * |
12 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | * | 14 | * |
15 | * | 15 | * |
16 | * This is a rewrite of the abeditor.h file, modified to provide a more | 16 | * This is a rewrite of the abeditor.h file, modified to provide a more |
17 | * intuitive interface to TrollTech's original Address Book editor. This | 17 | * intuitive interface to TrollTech's original Address Book editor. This |
18 | * is made to operate exactly in interface with the exception of name. | 18 | * is made to operate exactly in interface with the exception of name. |
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "contacteditor.h" | 22 | #include "contacteditor.h" |
23 | #include "addresspicker.h" | 23 | #include "addresspicker.h" |
24 | #include "ocontactfields.h" | 24 | #include "ocontactfields.h" |
25 | 25 | ||
26 | #include <qpe/categoryselect.h> | 26 | #include <qpe/categoryselect.h> |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/qpedialog.h> | 28 | #include <qpe/qpedialog.h> |
29 | #include <qpe/timeconversion.h> | 29 | #include <qpe/timeconversion.h> |
30 | #include <opie/ocontact.h> | 30 | #include <opie/ocontact.h> |
31 | #include <qpe/resource.h> | 31 | #include <qpe/resource.h> |
32 | 32 | ||
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qlabel.h> | 34 | #include <qlabel.h> |
35 | #include <qtabwidget.h> | 35 | #include <qtabwidget.h> |
36 | #include <qlayout.h> | 36 | #include <qlayout.h> |
37 | #include <qlineedit.h> | 37 | #include <qlineedit.h> |
38 | #include <qmultilineedit.h> | 38 | #include <qmultilineedit.h> |
39 | #include <qscrollview.h> | 39 | #include <qscrollview.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
42 | #include <qmainwindow.h> | 42 | #include <qmainwindow.h> |
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qlistbox.h> | 45 | #include <qlistbox.h> |
46 | #include <qhbox.h> | 46 | #include <qhbox.h> |
47 | #include <qaction.h> | 47 | #include <qaction.h> |
48 | #include <qiconset.h> | 48 | #include <qiconset.h> |
49 | #include <qmessagebox.h> | 49 | #include <qmessagebox.h> |
50 | #include <qwhatsthis.h> | 50 | #include <qwhatsthis.h> |
51 | 51 | ||
52 | #include <assert.h> | 52 | #include <assert.h> |
53 | 53 | ||
54 | static inline bool containsAlphaNum( const QString &str ); | 54 | static inline bool containsAlphaNum( const QString &str ); |
55 | static inline bool constainsWhiteSpace( const QString &str ); | 55 | static inline bool constainsWhiteSpace( const QString &str ); |
56 | 56 | ||
57 | // helper functions, convert our comma delimited list to proper | 57 | // helper functions, convert our comma delimited list to proper |
58 | // file format... | 58 | // file format... |
59 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, | 59 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, |
60 | QString &strAll ); | 60 | QString &strAll ); |
61 | 61 | ||
62 | // helper convert from file format to comma delimited... | 62 | // helper convert from file format to comma delimited... |
63 | void parseEmailTo( const QString &strDefaultEmail, | 63 | void parseEmailTo( const QString &strDefaultEmail, |
64 | const QString &strOtherEmail, QString &strBack ); | 64 | const QString &strOtherEmail, QString &strBack ); |
65 | 65 | ||
66 | ContactEditor::ContactEditor(const OContact &entry, | 66 | ContactEditor::ContactEditor(const OContact &entry, |
67 | QWidget *parent, | 67 | QWidget *parent, |
68 | const char *name, | 68 | const char *name, |
69 | WFlags ) | 69 | WFlags ) |
70 | : QDialog( parent, name, TRUE, WStyle_ContextHelp ), | 70 | : QDialog( parent, name, TRUE, WStyle_ContextHelp ), |
71 | defaultEmailChooserPosition( -1 ), | 71 | defaultEmailChooserPosition( -1 ), |
72 | m_personalView ( false ), | 72 | m_personalView ( false ), |
73 | cmbDefaultEmail( 0 ), | 73 | cmbDefaultEmail( 0 ), |
74 | initializing ( false ) | 74 | initializing ( false ) |
75 | { | 75 | { |
76 | 76 | ||
77 | initializing = true; | 77 | initializing = true; |
78 | 78 | ||
79 | init(); | 79 | init(); |
80 | setEntry( entry ); | 80 | setEntry( entry ); |
81 | // cmbDefaultEmail = 0; | 81 | // cmbDefaultEmail = 0; |
82 | // defaultEmailChooserPosition = -1; | 82 | // defaultEmailChooserPosition = -1; |
83 | 83 | ||
84 | initializing = false; | 84 | initializing = false; |
85 | } | 85 | } |
86 | 86 | ||
87 | ContactEditor::~ContactEditor() { | 87 | ContactEditor::~ContactEditor() { |
88 | } | 88 | } |
89 | 89 | ||
90 | void ContactEditor::init() { | 90 | void ContactEditor::init() { |
91 | qWarning("init() START"); | 91 | qWarning("init() START"); |
92 | 92 | ||
93 | uint i = 0; | 93 | uint i = 0; |
94 | 94 | ||
95 | QStringList trlChooserNames; | 95 | QStringList trlChooserNames; |
96 | 96 | ||
97 | for (i = 0; i <= 6; i++) { | 97 | for (i = 0; i <= 6; i++) { |
98 | slHomeAddress.append( "" ); | 98 | slHomeAddress.append( "" ); |
99 | slBusinessAddress.append( "" ); | 99 | slBusinessAddress.append( "" ); |
100 | } | 100 | } |
101 | 101 | ||
102 | trlChooserNames = OContactFields::trphonefields( false ); | 102 | trlChooserNames = OContactFields::trphonefields( false ); |
103 | slChooserNames = OContactFields::untrphonefields( false ); | 103 | slChooserNames = OContactFields::untrphonefields( false ); |
104 | slDynamicEntries = OContactFields::untrdetailsfields( false ); | 104 | slDynamicEntries = OContactFields::untrdetailsfields( false ); |
105 | trlDynamicEntries = OContactFields::trdetailsfields( false ); | 105 | trlDynamicEntries = OContactFields::trdetailsfields( false ); |
106 | 106 | ||
107 | // Ok, we have to remove elements from the list of dynamic entries | 107 | // Ok, we have to remove elements from the list of dynamic entries |
108 | // which are now stored in special (not dynamic) widgets.. | 108 | // which are now stored in special (not dynamic) widgets.. |
109 | // Otherwise we will get problems with field assignments! (se) | 109 | // Otherwise we will get problems with field assignments! (se) |
110 | slDynamicEntries.remove("Anniversary"); | 110 | slDynamicEntries.remove("Anniversary"); |
111 | slDynamicEntries.remove("Birthday"); | 111 | slDynamicEntries.remove("Birthday"); |
112 | slDynamicEntries.remove("Gender"); | 112 | slDynamicEntries.remove("Gender"); |
113 | 113 | ||
114 | // The same with translated fields.. But I will | 114 | // The same with translated fields.. But I will |
115 | // use the translation map to avoid mismatches.. | 115 | // use the translation map to avoid mismatches.. |
116 | QMap<int, QString> translMap = OContactFields::idToTrFields(); | 116 | QMap<int, QString> translMap = OContactFields::idToTrFields(); |
117 | trlDynamicEntries.remove( translMap[Qtopia::Anniversary] ); | 117 | trlDynamicEntries.remove( translMap[Qtopia::Anniversary] ); |
118 | trlDynamicEntries.remove( translMap[Qtopia::Birthday] ); | 118 | trlDynamicEntries.remove( translMap[Qtopia::Birthday] ); |
119 | trlDynamicEntries.remove( translMap[Qtopia::Gender] ); | 119 | trlDynamicEntries.remove( translMap[Qtopia::Gender] ); |
120 | 120 | ||
121 | // Last Check to be sure.. | 121 | // Last Check to be sure.. |
122 | assert( slDynamicEntries.count() == trlDynamicEntries.count() ); | 122 | assert( slDynamicEntries.count() == trlDynamicEntries.count() ); |
123 | assert( slChooserNames.count() == trlChooserNames.count() ); | 123 | assert( slChooserNames.count() == trlChooserNames.count() ); |
124 | 124 | ||
125 | for (i = 0; i < slChooserNames.count(); i++) | 125 | for (i = 0; i < slChooserNames.count(); i++) |
126 | slChooserValues.append(""); | 126 | slChooserValues.append(""); |
127 | 127 | ||
128 | 128 | ||
129 | QVBoxLayout *vb = new QVBoxLayout( this ); | 129 | QVBoxLayout *vb = new QVBoxLayout( this ); |
130 | 130 | ||
131 | tabMain = new QTabWidget( this ); | 131 | tabMain = new QTabWidget( this ); |
132 | vb->addWidget( tabMain ); | 132 | vb->addWidget( tabMain ); |
133 | 133 | ||
134 | QWidget *tabViewport = new QWidget ( tabMain ); | 134 | QWidget *tabViewport = new QWidget ( tabMain ); |
135 | 135 | ||
136 | vb = new QVBoxLayout( tabViewport ); | 136 | vb = new QVBoxLayout( tabViewport ); |
137 | 137 | ||
138 | svGeneral = new QScrollView( tabViewport ); | 138 | svGeneral = new QScrollView( tabViewport ); |
139 | vb->addWidget( svGeneral, 0, 0 ); | 139 | vb->addWidget( svGeneral, 0, 0 ); |
140 | svGeneral->setResizePolicy( QScrollView::AutoOneFit ); | 140 | svGeneral->setResizePolicy( QScrollView::AutoOneFit ); |
141 | // svGeneral->setHScrollBarMode( QScrollView::AlwaysOff ); | 141 | // svGeneral->setHScrollBarMode( QScrollView::AlwaysOff ); |
142 | // svGeneral->setVScrollBarMode( QScrollView::AlwaysOff ); | 142 | // svGeneral->setVScrollBarMode( QScrollView::AlwaysOff ); |
143 | svGeneral->setFrameStyle( QFrame::NoFrame ); | 143 | svGeneral->setFrameStyle( QFrame::NoFrame ); |
144 | 144 | ||
145 | QWidget *container = new QWidget( svGeneral->viewport() ); | 145 | QWidget *container = new QWidget( svGeneral->viewport() ); |
146 | svGeneral->addChild( container ); | 146 | svGeneral->addChild( container ); |
147 | 147 | ||
148 | QGridLayout *gl = new QGridLayout( container, 1, 1, 2, 4 ); | 148 | QGridLayout *gl = new QGridLayout( container, 1, 1, 2, 4 ); |
149 | gl->setResizeMode( QLayout::FreeResize ); | 149 | gl->setResizeMode( QLayout::FreeResize ); |
150 | 150 | ||
151 | btnFullName = new QPushButton( tr( "Full Name..." ), container ); | 151 | btnFullName = new QPushButton( tr( "Full Name..." ), container ); |
152 | QWhatsThis::add( btnFullName, tr( "Press to enter last- middle and firstname" ) ); | 152 | QWhatsThis::add( btnFullName, tr( "Press to enter last- middle and firstname" ) ); |
153 | gl->addWidget( btnFullName, 0, 0 ); | 153 | gl->addWidget( btnFullName, 0, 0 ); |
154 | txtFullName = new QLineEdit( container ); | 154 | txtFullName = new QLineEdit( container ); |
155 | QWhatsThis::add( txtFullName, tr( "Enter fullname directly ! If you have a lastname with multiple words ( for instance \"de la Guerra\"), please write <lastname>,<firstnames> like this: \"de la Guerra, Carlos Pedro\"" ) ); | 155 | QWhatsThis::add( txtFullName, tr( "Enter fullname directly ! If you have a lastname with multiple words ( for instance \"de la Guerra\"), please write <lastname>,<firstnames> like this: \"de la Guerra, Carlos Pedro\"" ) ); |
156 | gl->addWidget( txtFullName, 0, 1 ); | 156 | gl->addWidget( txtFullName, 0, 1 ); |
157 | 157 | ||
158 | QLabel *l = new QLabel( tr( "Job Title" ), container ); | 158 | QLabel *l = new QLabel( tr( "Job Title" ), container ); |
159 | QWhatsThis::add( l, tr( "The jobtitle.." ) ); | 159 | QWhatsThis::add( l, tr( "The jobtitle.." ) ); |
160 | gl->addWidget( l, 1, 0 ); | 160 | gl->addWidget( l, 1, 0 ); |
161 | txtJobTitle = new QLineEdit( container ); | 161 | txtJobTitle = new QLineEdit( container ); |
162 | QWhatsThis::add( txtJobTitle, tr( "The jobtitle.." ) ); | 162 | QWhatsThis::add( txtJobTitle, tr( "The jobtitle.." ) ); |
163 | gl->addWidget( txtJobTitle, 1, 1 ); | 163 | gl->addWidget( txtJobTitle, 1, 1 ); |
164 | 164 | ||
165 | l = new QLabel( tr("Suffix"), container ); | 165 | l = new QLabel( tr("Suffix"), container ); |
166 | QWhatsThis::add( l, tr( "Something like \"jr.\".." ) ); | 166 | QWhatsThis::add( l, tr( "Something like \"jr.\".." ) ); |
167 | gl->addWidget( l, 2, 0 ); | 167 | gl->addWidget( l, 2, 0 ); |
168 | txtSuffix = new QLineEdit( container ); | 168 | txtSuffix = new QLineEdit( container ); |
169 | QWhatsThis::add( txtSuffix, tr( "Something like \"jr.\".." ) ); | 169 | QWhatsThis::add( txtSuffix, tr( "Something like \"jr.\".." ) ); |
170 | gl->addWidget( txtSuffix, 2, 1 ); | 170 | gl->addWidget( txtSuffix, 2, 1 ); |
171 | 171 | ||
172 | l = new QLabel( tr( "Organization" ), container ); | 172 | l = new QLabel( tr( "Organization" ), container ); |
173 | QWhatsThis::add( l, tr( "The working place of the contact" ) ); | 173 | QWhatsThis::add( l, tr( "The working place of the contact" ) ); |
174 | gl->addWidget( l, 3, 0 ); | 174 | gl->addWidget( l, 3, 0 ); |
175 | txtOrganization = new QLineEdit( container ); | 175 | txtOrganization = new QLineEdit( container ); |
176 | QWhatsThis::add( txtOrganization, tr( "The working place of the contact" ) ); | 176 | QWhatsThis::add( txtOrganization, tr( "The working place of the contact" ) ); |
177 | gl->addWidget( txtOrganization, 3, 1 ); | 177 | gl->addWidget( txtOrganization, 3, 1 ); |
178 | 178 | ||
179 | // Chooser 1 | 179 | // Chooser 1 |
180 | cmbChooserField1 = new QComboBox( FALSE, container ); | 180 | cmbChooserField1 = new QComboBox( FALSE, container ); |
181 | QWhatsThis::add( cmbChooserField1, tr( "Press to select attribute to change" ) ); | 181 | QWhatsThis::add( cmbChooserField1, tr( "Press to select attribute to change" ) ); |
182 | cmbChooserField1->setMaximumWidth( 90 ); | 182 | cmbChooserField1->setMaximumWidth( 90 ); |
183 | gl->addWidget( cmbChooserField1, 4, 0 ); | 183 | gl->addWidget( cmbChooserField1, 4, 0 ); |
184 | // Textfield for chooser 1. | 184 | // Textfield for chooser 1. |
185 | // Now use Widgetstack to contain the textfield and the default-email combo ! | 185 | // Now use Widgetstack to contain the textfield and the default-email combo ! |
186 | m_widgetStack1 = new QWidgetStack( container ); | 186 | m_widgetStack1 = new QWidgetStack( container ); |
187 | txtChooserField1 = new QLineEdit( m_widgetStack1 ); | 187 | txtChooserField1 = new QLineEdit( m_widgetStack1 ); |
188 | m_widgetStack1 -> addWidget( txtChooserField1, TextField ); | 188 | m_widgetStack1 -> addWidget( txtChooserField1, TextField ); |
189 | gl->addWidget( m_widgetStack1, 4, 1 ); | 189 | gl->addWidget( m_widgetStack1, 4, 1 ); |
190 | m_widgetStack1 -> raiseWidget( TextField ); | 190 | m_widgetStack1 -> raiseWidget( TextField ); |
191 | 191 | ||
192 | // Chooser 2 | 192 | // Chooser 2 |
193 | cmbChooserField2 = new QComboBox( FALSE, container ); | 193 | cmbChooserField2 = new QComboBox( FALSE, container ); |
194 | QWhatsThis::add( cmbChooserField2, tr( "Press to select attribute to change" ) ); | 194 | QWhatsThis::add( cmbChooserField2, tr( "Press to select attribute to change" ) ); |
195 | cmbChooserField2->setMaximumWidth( 90 ); | 195 | cmbChooserField2->setMaximumWidth( 90 ); |
196 | gl->addWidget( cmbChooserField2, 5, 0 ); | 196 | gl->addWidget( cmbChooserField2, 5, 0 ); |
197 | // Textfield for chooser 2 | 197 | // Textfield for chooser 2 |
198 | // Now use WidgetStack to contain the textfield and the default-email combo! | 198 | // Now use WidgetStack to contain the textfield and the default-email combo! |
199 | m_widgetStack2 = new QWidgetStack( container ); | 199 | m_widgetStack2 = new QWidgetStack( container ); |
200 | txtChooserField2 = new QLineEdit( m_widgetStack2 ); | 200 | txtChooserField2 = new QLineEdit( m_widgetStack2 ); |
201 | m_widgetStack2 -> addWidget( txtChooserField2, TextField ); | 201 | m_widgetStack2 -> addWidget( txtChooserField2, TextField ); |
202 | gl->addWidget( m_widgetStack2, 5, 1 ); | 202 | gl->addWidget( m_widgetStack2, 5, 1 ); |
203 | m_widgetStack2 -> raiseWidget( TextField ); | 203 | m_widgetStack2 -> raiseWidget( TextField ); |
204 | 204 | ||
205 | // Chooser 3 | 205 | // Chooser 3 |
206 | cmbChooserField3 = new QComboBox( FALSE, container ); | 206 | cmbChooserField3 = new QComboBox( FALSE, container ); |
207 | QWhatsThis::add( cmbChooserField3, tr( "Press to select attribute to change" ) ); | 207 | QWhatsThis::add( cmbChooserField3, tr( "Press to select attribute to change" ) ); |
208 | cmbChooserField3->setMaximumWidth( 90 ); | 208 | cmbChooserField3->setMaximumWidth( 90 ); |
209 | gl->addWidget( cmbChooserField3, 6, 0 ); | 209 | gl->addWidget( cmbChooserField3, 6, 0 ); |
210 | // Textfield for chooser 2 | 210 | // Textfield for chooser 2 |
211 | // Now use WidgetStack to contain the textfield and the default-email combo! | 211 | // Now use WidgetStack to contain the textfield and the default-email combo! |
212 | m_widgetStack3 = new QWidgetStack( container ); | 212 | m_widgetStack3 = new QWidgetStack( container ); |
213 | txtChooserField3 = new QLineEdit( m_widgetStack3 ); | 213 | txtChooserField3 = new QLineEdit( m_widgetStack3 ); |
214 | m_widgetStack3 -> addWidget( txtChooserField3, TextField ); | 214 | m_widgetStack3 -> addWidget( txtChooserField3, TextField ); |
215 | gl->addWidget( m_widgetStack3, 6, 1 ); | 215 | gl->addWidget( m_widgetStack3, 6, 1 ); |
216 | m_widgetStack3 -> raiseWidget( TextField ); | 216 | m_widgetStack3 -> raiseWidget( TextField ); |
217 | 217 | ||
218 | l = new QLabel( tr( "File As" ), container ); | 218 | l = new QLabel( tr( "File As" ), container ); |
219 | QWhatsThis::add( l, tr( "Press to select how to store the name (and howto show it in the listview)" ) ); | 219 | QWhatsThis::add( l, tr( "Press to select how to store the name (and howto show it in the listview)" ) ); |
220 | gl->addWidget( l, 7, 0 ); | 220 | gl->addWidget( l, 7, 0 ); |
221 | cmbFileAs = new QComboBox( TRUE, container ); | 221 | cmbFileAs = new QComboBox( TRUE, container ); |
222 | gl->addWidget( cmbFileAs, 7, 1 ); | 222 | gl->addWidget( cmbFileAs, 7, 1 ); |
223 | 223 | ||
224 | labCat = new QLabel( tr( "Category" ), container ); | 224 | labCat = new QLabel( tr( "Category" ), container ); |
225 | gl->addWidget( labCat, 8, 0 ); | 225 | gl->addWidget( labCat, 8, 0 ); |
226 | cmbCat = new CategorySelect( container ); | 226 | cmbCat = new CategorySelect( container ); |
227 | gl->addWidget( cmbCat, 8, 1 ); | 227 | gl->addWidget( cmbCat, 8, 1 ); |
228 | labCat->show(); | 228 | labCat->show(); |
229 | cmbCat->show(); | 229 | cmbCat->show(); |
230 | 230 | ||
231 | btnNote = new QPushButton( tr( "Notes..." ), container ); | 231 | btnNote = new QPushButton( tr( "Notes..." ), container ); |
232 | gl->addWidget( btnNote, 9, 1 ); | 232 | gl->addWidget( btnNote, 9, 1 ); |
233 | 233 | ||
234 | tabMain->insertTab( tabViewport, tr( "General" ) ); | 234 | tabMain->insertTab( tabViewport, tr( "General" ) ); |
235 | 235 | ||
236 | tabViewport = new QWidget ( tabMain ); | 236 | tabViewport = new QWidget ( tabMain ); |
237 | 237 | ||
238 | vb = new QVBoxLayout( tabViewport ); | 238 | vb = new QVBoxLayout( tabViewport ); |
239 | 239 | ||
240 | svAddress = new QScrollView( tabViewport ); | 240 | svAddress = new QScrollView( tabViewport ); |
241 | vb->addWidget( svAddress, 0, 0 ); | 241 | vb->addWidget( svAddress, 0, 0 ); |
242 | svAddress->setResizePolicy( QScrollView::AutoOneFit ); | 242 | svAddress->setResizePolicy( QScrollView::AutoOneFit ); |
243 | svAddress->setFrameStyle( QFrame::NoFrame ); | 243 | svAddress->setFrameStyle( QFrame::NoFrame ); |
244 | 244 | ||
245 | container = new QWidget( svAddress->viewport() ); | 245 | container = new QWidget( svAddress->viewport() ); |
246 | svAddress->addChild( container ); | 246 | svAddress->addChild( container ); |
247 | 247 | ||
248 | gl = new QGridLayout( container, 8, 3, 2, 4 ); // row 7 QSpacerItem | 248 | gl = new QGridLayout( container, 8, 3, 2, 4 ); // row 7 QSpacerItem |
249 | 249 | ||
250 | cmbAddress = new QComboBox( FALSE, container ); | 250 | cmbAddress = new QComboBox( FALSE, container ); |
251 | cmbAddress->insertItem( tr( "Business" ) ); | 251 | cmbAddress->insertItem( tr( "Business" ) ); |
252 | cmbAddress->insertItem( tr( "Home" ) ); | 252 | cmbAddress->insertItem( tr( "Home" ) ); |
253 | gl->addMultiCellWidget( cmbAddress, 0, 0, 0, 1 ); | 253 | gl->addMultiCellWidget( cmbAddress, 0, 0, 0, 1 ); |
254 | 254 | ||
255 | l = new QLabel( tr( "Address" ), container ); | 255 | l = new QLabel( tr( "Address" ), container ); |
256 | gl->addWidget( l, 1, 0 ); | 256 | gl->addWidget( l, 1, 0 ); |
257 | txtAddress = new QLineEdit( container ); | 257 | txtAddress = new QLineEdit( container ); |
258 | gl->addMultiCellWidget( txtAddress, 1, 1, 1, 2 ); | 258 | gl->addMultiCellWidget( txtAddress, 1, 1, 1, 2 ); |
259 | 259 | ||
260 | l = new QLabel( tr( "City" ), container ); | 260 | l = new QLabel( tr( "City" ), container ); |
261 | gl->addWidget( l, 2, 0 ); | 261 | gl->addWidget( l, 2, 0 ); |
262 | txtCity = new QLineEdit( container ); | 262 | txtCity = new QLineEdit( container ); |
263 | gl->addMultiCellWidget( txtCity, 2, 2, 1, 2 ); | 263 | gl->addMultiCellWidget( txtCity, 2, 2, 1, 2 ); |
264 | 264 | ||
265 | l = new QLabel( tr( "State" ), container ); | 265 | l = new QLabel( tr( "State" ), container ); |
266 | gl->addWidget( l, 3, 0 ); | 266 | gl->addWidget( l, 3, 0 ); |
267 | txtState = new QLineEdit( container ); | 267 | txtState = new QLineEdit( container ); |
268 | gl->addMultiCellWidget( txtState, 3, 3, 1, 2 ); | 268 | gl->addMultiCellWidget( txtState, 3, 3, 1, 2 ); |
269 | 269 | ||
270 | l = new QLabel( tr( "Zip Code" ), container ); | 270 | l = new QLabel( tr( "Zip Code" ), container ); |
271 | gl->addWidget( l, 4, 0 ); | 271 | gl->addWidget( l, 4, 0 ); |
272 | txtZip = new QLineEdit( container ); | 272 | txtZip = new QLineEdit( container ); |
273 | gl->addMultiCellWidget( txtZip, 4, 4, 1, 2 ); | 273 | gl->addMultiCellWidget( txtZip, 4, 4, 1, 2 ); |
274 | 274 | ||
275 | l = new QLabel( tr( "Country" ), container ); | 275 | l = new QLabel( tr( "Country" ), container ); |
276 | gl->addWidget( l, 5, 0 ); | 276 | gl->addWidget( l, 5, 0 ); |
277 | cmbCountry = new QComboBox( TRUE, container ); | 277 | cmbCountry = new QComboBox( TRUE, container ); |
278 | cmbCountry->insertItem( tr( "" ) ); | 278 | cmbCountry->insertItem( tr( "" ) ); |
279 | cmbCountry->insertItem( tr ( "United States" ) ); | 279 | cmbCountry->insertItem( tr ( "United States" ) ); |
280 | cmbCountry->insertItem( tr ( "United Kingdom" ) ); | 280 | cmbCountry->insertItem( tr ( "United Kingdom" ) ); |
281 | cmbCountry->insertItem( tr ( "Afghanistan" ) ); | 281 | cmbCountry->insertItem( tr ( "Afghanistan" ) ); |
282 | cmbCountry->insertItem( tr ( "Albania" ) ); | 282 | cmbCountry->insertItem( tr ( "Albania" ) ); |
283 | cmbCountry->insertItem( tr ( "Algeria" ) ); | 283 | cmbCountry->insertItem( tr ( "Algeria" ) ); |
284 | cmbCountry->insertItem( tr ( "American Samoa" ) ); | 284 | cmbCountry->insertItem( tr ( "American Samoa" ) ); |
285 | cmbCountry->insertItem( tr ( "Andorra" ) ); | 285 | cmbCountry->insertItem( tr ( "Andorra" ) ); |
286 | cmbCountry->insertItem( tr ( "Angola" ) ); | 286 | cmbCountry->insertItem( tr ( "Angola" ) ); |
287 | cmbCountry->insertItem( tr ( "Anguilla" ) ); | 287 | cmbCountry->insertItem( tr ( "Anguilla" ) ); |
288 | cmbCountry->insertItem( tr ( "Antarctica" ) ); | 288 | cmbCountry->insertItem( tr ( "Antarctica" ) ); |
289 | cmbCountry->insertItem( tr ( "Argentina" ) ); | 289 | cmbCountry->insertItem( tr ( "Argentina" ) ); |
290 | cmbCountry->insertItem( tr ( "Armenia" ) ); | 290 | cmbCountry->insertItem( tr ( "Armenia" ) ); |
291 | cmbCountry->insertItem( tr ( "Aruba" ) ); | 291 | cmbCountry->insertItem( tr ( "Aruba" ) ); |
292 | cmbCountry->insertItem( tr ( "Australia" ) ); | 292 | cmbCountry->insertItem( tr ( "Australia" ) ); |
293 | cmbCountry->insertItem( tr ( "Austria" ) ); | 293 | cmbCountry->insertItem( tr ( "Austria" ) ); |
294 | cmbCountry->insertItem( tr ( "Azerbaijan" ) ); | 294 | cmbCountry->insertItem( tr ( "Azerbaijan" ) ); |
295 | cmbCountry->insertItem( tr ( "Bahamas" ) ); | 295 | cmbCountry->insertItem( tr ( "Bahamas" ) ); |
296 | cmbCountry->insertItem( tr ( "Bahrain" ) ); | 296 | cmbCountry->insertItem( tr ( "Bahrain" ) ); |
297 | cmbCountry->insertItem( tr ( "Bangladesh" ) ); | 297 | cmbCountry->insertItem( tr ( "Bangladesh" ) ); |
298 | cmbCountry->insertItem( tr ( "Barbados" ) ); | 298 | cmbCountry->insertItem( tr ( "Barbados" ) ); |
299 | cmbCountry->insertItem( tr ( "Belarus" ) ); | 299 | cmbCountry->insertItem( tr ( "Belarus" ) ); |
300 | cmbCountry->insertItem( tr ( "Belgium" ) ); | 300 | cmbCountry->insertItem( tr ( "Belgium" ) ); |
301 | cmbCountry->insertItem( tr ( "Belize" ) ); | 301 | cmbCountry->insertItem( tr ( "Belize" ) ); |
302 | cmbCountry->insertItem( tr ( "Benin" ) ); | 302 | cmbCountry->insertItem( tr ( "Benin" ) ); |
303 | cmbCountry->insertItem( tr ( "Bermuda" ) ); | 303 | cmbCountry->insertItem( tr ( "Bermuda" ) ); |
304 | cmbCountry->insertItem( tr ( "Bhutan" ) ); | 304 | cmbCountry->insertItem( tr ( "Bhutan" ) ); |
305 | cmbCountry->insertItem( tr ( "Bolivia" ) ); | 305 | cmbCountry->insertItem( tr ( "Bolivia" ) ); |
306 | cmbCountry->insertItem( tr ( "Botswana" ) ); | 306 | cmbCountry->insertItem( tr ( "Botswana" ) ); |
307 | cmbCountry->insertItem( tr ( "Bouvet Island" ) ); | 307 | cmbCountry->insertItem( tr ( "Bouvet Island" ) ); |
308 | cmbCountry->insertItem( tr ( "Brazil" ) ); | 308 | cmbCountry->insertItem( tr ( "Brazil" ) ); |
309 | cmbCountry->insertItem( tr ( "Brunei Darussalam" ) ); | 309 | cmbCountry->insertItem( tr ( "Brunei Darussalam" ) ); |
310 | cmbCountry->insertItem( tr ( "Bulgaria" ) ); | 310 | cmbCountry->insertItem( tr ( "Bulgaria" ) ); |
311 | cmbCountry->insertItem( tr ( "Burkina Faso" ) ); | 311 | cmbCountry->insertItem( tr ( "Burkina Faso" ) ); |
312 | cmbCountry->insertItem( tr ( "Burundi" ) ); | 312 | cmbCountry->insertItem( tr ( "Burundi" ) ); |
313 | cmbCountry->insertItem( tr ( "Cambodia" ) ); | 313 | cmbCountry->insertItem( tr ( "Cambodia" ) ); |
314 | cmbCountry->insertItem( tr ( "Cameroon" ) ); | 314 | cmbCountry->insertItem( tr ( "Cameroon" ) ); |
315 | cmbCountry->insertItem( tr ( "Canada" ) ); | 315 | cmbCountry->insertItem( tr ( "Canada" ) ); |
316 | cmbCountry->insertItem( tr ( "Cape Verde" ) ); | 316 | cmbCountry->insertItem( tr ( "Cape Verde" ) ); |
317 | cmbCountry->insertItem( tr ( "Cayman Islands" ) ); | 317 | cmbCountry->insertItem( tr ( "Cayman Islands" ) ); |
318 | cmbCountry->insertItem( tr ( "Chad" ) ); | 318 | cmbCountry->insertItem( tr ( "Chad" ) ); |
319 | cmbCountry->insertItem( tr ( "Chile" ) ); | 319 | cmbCountry->insertItem( tr ( "Chile" ) ); |
320 | cmbCountry->insertItem( tr ( "China" ) ); | 320 | cmbCountry->insertItem( tr ( "China" ) ); |
321 | cmbCountry->insertItem( tr ( "Christmas Island" ) ); | 321 | cmbCountry->insertItem( tr ( "Christmas Island" ) ); |
322 | cmbCountry->insertItem( tr ( "Colombia" ) ); | 322 | cmbCountry->insertItem( tr ( "Colombia" ) ); |
323 | cmbCountry->insertItem( tr ( "Comoros" ) ); | 323 | cmbCountry->insertItem( tr ( "Comoros" ) ); |
324 | cmbCountry->insertItem( tr ( "Congo" ) ); | 324 | cmbCountry->insertItem( tr ( "Congo" ) ); |
325 | cmbCountry->insertItem( tr ( "Cook Island" ) ); | 325 | cmbCountry->insertItem( tr ( "Cook Island" ) ); |
326 | cmbCountry->insertItem( tr ( "Costa Rica" ) ); | 326 | cmbCountry->insertItem( tr ( "Costa Rica" ) ); |
327 | cmbCountry->insertItem( tr ( "Cote d'Ivoire" ) ); | 327 | cmbCountry->insertItem( tr ( "Cote d'Ivoire" ) ); |
328 | cmbCountry->insertItem( tr ( "Croatia" ) ); | 328 | cmbCountry->insertItem( tr ( "Croatia" ) ); |
329 | cmbCountry->insertItem( tr ( "Cuba" ) ); | 329 | cmbCountry->insertItem( tr ( "Cuba" ) ); |
330 | cmbCountry->insertItem( tr ( "Cyprus" ) ); | 330 | cmbCountry->insertItem( tr ( "Cyprus" ) ); |
331 | cmbCountry->insertItem( tr ( "Czech Republic" ) ); | 331 | cmbCountry->insertItem( tr ( "Czech Republic" ) ); |
332 | cmbCountry->insertItem( tr ( "Denmark" ) ); | 332 | cmbCountry->insertItem( tr ( "Denmark" ) ); |
333 | cmbCountry->insertItem( tr ( "Djibouti" ) ); | 333 | cmbCountry->insertItem( tr ( "Djibouti" ) ); |
334 | cmbCountry->insertItem( tr ( "Dominica" ) ); | 334 | cmbCountry->insertItem( tr ( "Dominica" ) ); |
335 | cmbCountry->insertItem( tr ( "Dominican Republic" ) ); | 335 | cmbCountry->insertItem( tr ( "Dominican Republic" ) ); |
336 | cmbCountry->insertItem( tr ( "East Timor" ) ); | 336 | cmbCountry->insertItem( tr ( "East Timor" ) ); |
337 | cmbCountry->insertItem( tr ( "Ecuador" ) ); | 337 | cmbCountry->insertItem( tr ( "Ecuador" ) ); |
338 | cmbCountry->insertItem( tr ( "Egypt" ) ); | 338 | cmbCountry->insertItem( tr ( "Egypt" ) ); |
339 | cmbCountry->insertItem( tr ( "El Salvador" ) ); | 339 | cmbCountry->insertItem( tr ( "El Salvador" ) ); |
340 | cmbCountry->insertItem( tr ( "Equatorial Guinea" ) ); | 340 | cmbCountry->insertItem( tr ( "Equatorial Guinea" ) ); |
341 | cmbCountry->insertItem( tr ( "Eritrea" ) ); | 341 | cmbCountry->insertItem( tr ( "Eritrea" ) ); |
342 | cmbCountry->insertItem( tr ( "Estonia" ) ); | 342 | cmbCountry->insertItem( tr ( "Estonia" ) ); |
343 | cmbCountry->insertItem( tr ( "Ethiopia" ) ); | 343 | cmbCountry->insertItem( tr ( "Ethiopia" ) ); |
344 | cmbCountry->insertItem( tr ( "Falkland Islands" ) ); | 344 | cmbCountry->insertItem( tr ( "Falkland Islands" ) ); |
345 | cmbCountry->insertItem( tr ( "Faroe Islands" ) ); | 345 | cmbCountry->insertItem( tr ( "Faroe Islands" ) ); |
346 | cmbCountry->insertItem( tr ( "Fiji" ) ); | 346 | cmbCountry->insertItem( tr ( "Fiji" ) ); |
347 | cmbCountry->insertItem( tr ( "Finland" ) ); | 347 | cmbCountry->insertItem( tr ( "Finland" ) ); |
348 | cmbCountry->insertItem( tr ( "France" ) ); | 348 | cmbCountry->insertItem( tr ( "France" ) ); |
349 | cmbCountry->insertItem( tr ( "French Guiana" ) ); | 349 | cmbCountry->insertItem( tr ( "French Guiana" ) ); |
350 | cmbCountry->insertItem( tr ( "French Polynesia" ) ); | 350 | cmbCountry->insertItem( tr ( "French Polynesia" ) ); |
351 | cmbCountry->insertItem( tr ( "Gabon" ) ); | 351 | cmbCountry->insertItem( tr ( "Gabon" ) ); |
352 | cmbCountry->insertItem( tr ( "Gambia" ) ); | 352 | cmbCountry->insertItem( tr ( "Gambia" ) ); |
353 | cmbCountry->insertItem( tr ( "Georgia" ) ); | 353 | cmbCountry->insertItem( tr ( "Georgia" ) ); |
354 | cmbCountry->insertItem( tr ( "Germany" ) ); | 354 | cmbCountry->insertItem( tr ( "Germany" ) ); |
355 | cmbCountry->insertItem( tr ( "Ghana" ) ); | 355 | cmbCountry->insertItem( tr ( "Ghana" ) ); |
356 | cmbCountry->insertItem( tr ( "Gibraltar" ) ); | 356 | cmbCountry->insertItem( tr ( "Gibraltar" ) ); |
357 | cmbCountry->insertItem( tr ( "Greece" ) ); | 357 | cmbCountry->insertItem( tr ( "Greece" ) ); |
358 | cmbCountry->insertItem( tr ( "Greenland" ) ); | 358 | cmbCountry->insertItem( tr ( "Greenland" ) ); |
359 | cmbCountry->insertItem( tr ( "Grenada" ) ); | 359 | cmbCountry->insertItem( tr ( "Grenada" ) ); |
360 | cmbCountry->insertItem( tr ( "Guadeloupe" ) ); | 360 | cmbCountry->insertItem( tr ( "Guadeloupe" ) ); |
361 | cmbCountry->insertItem( tr ( "Guam" ) ); | 361 | cmbCountry->insertItem( tr ( "Guam" ) ); |
362 | cmbCountry->insertItem( tr ( "Guatemala" ) ); | 362 | cmbCountry->insertItem( tr ( "Guatemala" ) ); |
363 | cmbCountry->insertItem( tr ( "Guinea" ) ); | 363 | cmbCountry->insertItem( tr ( "Guinea" ) ); |
364 | cmbCountry->insertItem( tr ( "Guinea-Bissau" ) ); | 364 | cmbCountry->insertItem( tr ( "Guinea-Bissau" ) ); |
365 | cmbCountry->insertItem( tr ( "Guyana" ) ); | 365 | cmbCountry->insertItem( tr ( "Guyana" ) ); |
366 | cmbCountry->insertItem( tr ( "Haiti" ) ); | 366 | cmbCountry->insertItem( tr ( "Haiti" ) ); |
367 | cmbCountry->insertItem( tr ( "Holy See" ) ); | 367 | cmbCountry->insertItem( tr ( "Holy See" ) ); |
368 | cmbCountry->insertItem( tr ( "Honduras" ) ); | 368 | cmbCountry->insertItem( tr ( "Honduras" ) ); |
369 | cmbCountry->insertItem( tr ( "Hong Kong" ) ); | 369 | cmbCountry->insertItem( tr ( "Hong Kong" ) ); |
370 | cmbCountry->insertItem( tr ( "Hungary" ) ); | 370 | cmbCountry->insertItem( tr ( "Hungary" ) ); |
371 | cmbCountry->insertItem( tr ( "Iceland" ) ); | 371 | cmbCountry->insertItem( tr ( "Iceland" ) ); |
372 | cmbCountry->insertItem( tr ( "India" ) ); | 372 | cmbCountry->insertItem( tr ( "India" ) ); |
373 | cmbCountry->insertItem( tr ( "Indonesia" ) ); | 373 | cmbCountry->insertItem( tr ( "Indonesia" ) ); |
374 | cmbCountry->insertItem( tr ( "Ireland" ) ); | 374 | cmbCountry->insertItem( tr ( "Ireland" ) ); |
375 | cmbCountry->insertItem( tr ( "Israel" ) ); | 375 | cmbCountry->insertItem( tr ( "Israel" ) ); |
376 | cmbCountry->insertItem( tr ( "Italy" ) ); | 376 | cmbCountry->insertItem( tr ( "Italy" ) ); |
377 | cmbCountry->insertItem( tr ( "Jamaica" ) ); | 377 | cmbCountry->insertItem( tr ( "Jamaica" ) ); |
378 | cmbCountry->insertItem( tr ( "Japan" ) ); | 378 | cmbCountry->insertItem( tr ( "Japan" ) ); |
379 | cmbCountry->insertItem( tr ( "Jordan" ) ); | 379 | cmbCountry->insertItem( tr ( "Jordan" ) ); |
380 | cmbCountry->insertItem( tr ( "Kazakhstan" ) ); | 380 | cmbCountry->insertItem( tr ( "Kazakhstan" ) ); |
381 | cmbCountry->insertItem( tr ( "Kenya" ) ); | 381 | cmbCountry->insertItem( tr ( "Kenya" ) ); |
382 | cmbCountry->insertItem( tr ( "Kiribati" ) ); | 382 | cmbCountry->insertItem( tr ( "Kiribati" ) ); |
383 | cmbCountry->insertItem( tr ( "Korea" ) ); | 383 | cmbCountry->insertItem( tr ( "Korea" ) ); |
384 | cmbCountry->insertItem( tr ( "Kuwait" ) ); | 384 | cmbCountry->insertItem( tr ( "Kuwait" ) ); |
385 | cmbCountry->insertItem( tr ( "Kyrgyzstan" ) ); | 385 | cmbCountry->insertItem( tr ( "Kyrgyzstan" ) ); |
386 | cmbCountry->insertItem( tr ( "Laos" ) ); | 386 | cmbCountry->insertItem( tr ( "Laos" ) ); |
387 | cmbCountry->insertItem( tr ( "Latvia" ) ); | 387 | cmbCountry->insertItem( tr ( "Latvia" ) ); |
388 | cmbCountry->insertItem( tr ( "Lebanon" ) ); | 388 | cmbCountry->insertItem( tr ( "Lebanon" ) ); |
389 | cmbCountry->insertItem( tr ( "Lesotho" ) ); | 389 | cmbCountry->insertItem( tr ( "Lesotho" ) ); |
390 | cmbCountry->insertItem( tr ( "Liberia" ) ); | 390 | cmbCountry->insertItem( tr ( "Liberia" ) ); |
391 | cmbCountry->insertItem( tr ( "Liechtenstein" ) ); | 391 | cmbCountry->insertItem( tr ( "Liechtenstein" ) ); |
392 | cmbCountry->insertItem( tr ( "Lithuania" ) ); | 392 | cmbCountry->insertItem( tr ( "Lithuania" ) ); |
393 | cmbCountry->insertItem( tr ( "Luxembourg" ) ); | 393 | cmbCountry->insertItem( tr ( "Luxembourg" ) ); |
394 | cmbCountry->insertItem( tr ( "Macau" ) ); | 394 | cmbCountry->insertItem( tr ( "Macau" ) ); |
395 | cmbCountry->insertItem( tr ( "Macedonia" ) ); | 395 | cmbCountry->insertItem( tr ( "Macedonia" ) ); |
396 | cmbCountry->insertItem( tr ( "Madagascar" ) ); | 396 | cmbCountry->insertItem( tr ( "Madagascar" ) ); |
397 | cmbCountry->insertItem( tr ( "Malawi" ) ); | 397 | cmbCountry->insertItem( tr ( "Malawi" ) ); |
398 | cmbCountry->insertItem( tr ( "Malaysia" ) ); | 398 | cmbCountry->insertItem( tr ( "Malaysia" ) ); |
399 | cmbCountry->insertItem( tr ( "Maldives" ) ); | 399 | cmbCountry->insertItem( tr ( "Maldives" ) ); |
400 | cmbCountry->insertItem( tr ( "Mali" ) ); | 400 | cmbCountry->insertItem( tr ( "Mali" ) ); |
401 | cmbCountry->insertItem( tr ( "Malta" ) ); | 401 | cmbCountry->insertItem( tr ( "Malta" ) ); |
402 | cmbCountry->insertItem( tr ( "Martinique" ) ); | 402 | cmbCountry->insertItem( tr ( "Martinique" ) ); |
403 | cmbCountry->insertItem( tr ( "Mauritania" ) ); | 403 | cmbCountry->insertItem( tr ( "Mauritania" ) ); |
404 | cmbCountry->insertItem( tr ( "Mauritius" ) ); | 404 | cmbCountry->insertItem( tr ( "Mauritius" ) ); |
405 | cmbCountry->insertItem( tr ( "Mayotte" ) ); | 405 | cmbCountry->insertItem( tr ( "Mayotte" ) ); |
406 | cmbCountry->insertItem( tr ( "Mexico" ) ); | 406 | cmbCountry->insertItem( tr ( "Mexico" ) ); |
407 | cmbCountry->insertItem( tr ( "Micronesia" ) ); | 407 | cmbCountry->insertItem( tr ( "Micronesia" ) ); |
408 | cmbCountry->insertItem( tr ( "Moldova" ) ); | 408 | cmbCountry->insertItem( tr ( "Moldova" ) ); |
409 | cmbCountry->insertItem( tr ( "Monaco" ) ); | 409 | cmbCountry->insertItem( tr ( "Monaco" ) ); |
410 | cmbCountry->insertItem( tr ( "Mongolia" ) ); | 410 | cmbCountry->insertItem( tr ( "Mongolia" ) ); |
411 | cmbCountry->insertItem( tr ( "Montserrat" ) ); | 411 | cmbCountry->insertItem( tr ( "Montserrat" ) ); |
412 | cmbCountry->insertItem( tr ( "Morocco" ) ); | 412 | cmbCountry->insertItem( tr ( "Morocco" ) ); |
413 | cmbCountry->insertItem( tr ( "Mozambique" ) ); | 413 | cmbCountry->insertItem( tr ( "Mozambique" ) ); |
414 | cmbCountry->insertItem( tr ( "Myanmar" ) ); | 414 | cmbCountry->insertItem( tr ( "Myanmar" ) ); |
415 | cmbCountry->insertItem( tr ( "Namibia" ) ); | 415 | cmbCountry->insertItem( tr ( "Namibia" ) ); |
416 | cmbCountry->insertItem( tr ( "Nauru" ) ); | 416 | cmbCountry->insertItem( tr ( "Nauru" ) ); |
417 | cmbCountry->insertItem( tr ( "Nepal" ) ); | 417 | cmbCountry->insertItem( tr ( "Nepal" ) ); |
418 | cmbCountry->insertItem( tr ( "Netherlands" ) ); | 418 | cmbCountry->insertItem( tr ( "Netherlands" ) ); |
419 | cmbCountry->insertItem( tr ( "New Caledonia" ) ); | 419 | cmbCountry->insertItem( tr ( "New Caledonia" ) ); |
420 | cmbCountry->insertItem( tr ( "New Zealand" ) ); | 420 | cmbCountry->insertItem( tr ( "New Zealand" ) ); |
421 | cmbCountry->insertItem( tr ( "Nicaragua" ) ); | 421 | cmbCountry->insertItem( tr ( "Nicaragua" ) ); |
422 | cmbCountry->insertItem( tr ( "Niger" ) ); | 422 | cmbCountry->insertItem( tr ( "Niger" ) ); |
423 | cmbCountry->insertItem( tr ( "Nigeria" ) ); | 423 | cmbCountry->insertItem( tr ( "Nigeria" ) ); |
424 | cmbCountry->insertItem( tr ( "Niue" ) ); | 424 | cmbCountry->insertItem( tr ( "Niue" ) ); |
425 | cmbCountry->insertItem( tr ( "Norway" ) ); | 425 | cmbCountry->insertItem( tr ( "Norway" ) ); |
426 | cmbCountry->insertItem( tr ( "Oman" ) ); | 426 | cmbCountry->insertItem( tr ( "Oman" ) ); |
427 | cmbCountry->insertItem( tr ( "Pakistan" ) ); | 427 | cmbCountry->insertItem( tr ( "Pakistan" ) ); |
428 | cmbCountry->insertItem( tr ( "Palau" ) ); | 428 | cmbCountry->insertItem( tr ( "Palau" ) ); |
429 | cmbCountry->insertItem( tr ( "Palestinian Sovereign Areas" ) ); | 429 | cmbCountry->insertItem( tr ( "Palestinian Sovereign Areas" ) ); |
430 | cmbCountry->insertItem( tr ( "Panama" ) ); | 430 | cmbCountry->insertItem( tr ( "Panama" ) ); |
431 | cmbCountry->insertItem( tr ( "Papua New Guinea" ) ); | 431 | cmbCountry->insertItem( tr ( "Papua New Guinea" ) ); |
432 | cmbCountry->insertItem( tr ( "Paraguay" ) ); | 432 | cmbCountry->insertItem( tr ( "Paraguay" ) ); |
433 | cmbCountry->insertItem( tr ( "Peru" ) ); | 433 | cmbCountry->insertItem( tr ( "Peru" ) ); |
434 | cmbCountry->insertItem( tr ( "Philippines" ) ); | 434 | cmbCountry->insertItem( tr ( "Philippines" ) ); |
435 | cmbCountry->insertItem( tr ( "Pitcairn Islands" ) ); | 435 | cmbCountry->insertItem( tr ( "Pitcairn Islands" ) ); |
436 | cmbCountry->insertItem( tr ( "Poland" ) ); | 436 | cmbCountry->insertItem( tr ( "Poland" ) ); |
437 | cmbCountry->insertItem( tr ( "Portugal" ) ); | 437 | cmbCountry->insertItem( tr ( "Portugal" ) ); |
438 | cmbCountry->insertItem( tr ( "Puerto Rico" ) ); | 438 | cmbCountry->insertItem( tr ( "Puerto Rico" ) ); |
439 | cmbCountry->insertItem( tr ( "Qatar" ) ); | 439 | cmbCountry->insertItem( tr ( "Qatar" ) ); |
440 | cmbCountry->insertItem( tr ( "Reunion" ) ); | 440 | cmbCountry->insertItem( tr ( "Reunion" ) ); |
441 | cmbCountry->insertItem( tr ( "Romania" ) ); | 441 | cmbCountry->insertItem( tr ( "Romania" ) ); |
442 | cmbCountry->insertItem( tr ( "Russia" ) ); | 442 | cmbCountry->insertItem( tr ( "Russia" ) ); |
443 | cmbCountry->insertItem( tr ( "Rwanda" ) ); | 443 | cmbCountry->insertItem( tr ( "Rwanda" ) ); |
444 | cmbCountry->insertItem( tr ( "Saint Lucia" ) ); | 444 | cmbCountry->insertItem( tr ( "Saint Lucia" ) ); |
445 | cmbCountry->insertItem( tr ( "Samoa" ) ); | 445 | cmbCountry->insertItem( tr ( "Samoa" ) ); |
446 | cmbCountry->insertItem( tr ( "San Marino" ) ); | 446 | cmbCountry->insertItem( tr ( "San Marino" ) ); |
447 | cmbCountry->insertItem( tr ( "Saudi Arabia" ) ); | 447 | cmbCountry->insertItem( tr ( "Saudi Arabia" ) ); |
448 | cmbCountry->insertItem( tr ( "Senegal" ) ); | 448 | cmbCountry->insertItem( tr ( "Senegal" ) ); |
449 | cmbCountry->insertItem( tr ( "Seychelles" ) ); | 449 | cmbCountry->insertItem( tr ( "Seychelles" ) ); |
450 | cmbCountry->insertItem( tr ( "Sierra Leone" ) ); | 450 | cmbCountry->insertItem( tr ( "Sierra Leone" ) ); |
451 | cmbCountry->insertItem( tr ( "Singapore" ) ); | 451 | cmbCountry->insertItem( tr ( "Singapore" ) ); |
452 | cmbCountry->insertItem( tr ( "Slovakia" ) ); | 452 | cmbCountry->insertItem( tr ( "Slovakia" ) ); |
453 | cmbCountry->insertItem( tr ( "Slovenia" ) ); | 453 | cmbCountry->insertItem( tr ( "Slovenia" ) ); |
454 | cmbCountry->insertItem( tr ( "Solomon Islands" ) ); | 454 | cmbCountry->insertItem( tr ( "Solomon Islands" ) ); |
455 | cmbCountry->insertItem( tr ( "Somalia" ) ); | 455 | cmbCountry->insertItem( tr ( "Somalia" ) ); |
456 | cmbCountry->insertItem( tr ( "South Africa" ) ); | 456 | cmbCountry->insertItem( tr ( "South Africa" ) ); |
457 | cmbCountry->insertItem( tr ( "Spain" ) ); | 457 | cmbCountry->insertItem( tr ( "Spain" ) ); |
458 | cmbCountry->insertItem( tr ( "Sri Lanka" ) ); | 458 | cmbCountry->insertItem( tr ( "Sri Lanka" ) ); |
459 | cmbCountry->insertItem( tr ( "St. Helena" ) ); | 459 | cmbCountry->insertItem( tr ( "St. Helena" ) ); |
460 | cmbCountry->insertItem( tr ( "Sudan" ) ); | 460 | cmbCountry->insertItem( tr ( "Sudan" ) ); |
461 | cmbCountry->insertItem( tr ( "Suriname" ) ); | 461 | cmbCountry->insertItem( tr ( "Suriname" ) ); |
462 | cmbCountry->insertItem( tr ( "Swaziland" ) ); | 462 | cmbCountry->insertItem( tr ( "Swaziland" ) ); |
463 | cmbCountry->insertItem( tr ( "Sweden" ) ); | 463 | cmbCountry->insertItem( tr ( "Sweden" ) ); |
464 | cmbCountry->insertItem( tr ( "Switzerland" ) ); | 464 | cmbCountry->insertItem( tr ( "Switzerland" ) ); |
465 | cmbCountry->insertItem( tr ( "Taiwan" ) ); | 465 | cmbCountry->insertItem( tr ( "Taiwan" ) ); |
466 | cmbCountry->insertItem( tr ( "Tajikistan" ) ); | 466 | cmbCountry->insertItem( tr ( "Tajikistan" ) ); |
467 | cmbCountry->insertItem( tr ( "Tanzania" ) ); | 467 | cmbCountry->insertItem( tr ( "Tanzania" ) ); |
468 | cmbCountry->insertItem( tr ( "Thailand" ) ); | 468 | cmbCountry->insertItem( tr ( "Thailand" ) ); |
469 | cmbCountry->insertItem( tr ( "Togo" ) ); | 469 | cmbCountry->insertItem( tr ( "Togo" ) ); |
470 | cmbCountry->insertItem( tr ( "Tokelau" ) ); | 470 | cmbCountry->insertItem( tr ( "Tokelau" ) ); |
471 | cmbCountry->insertItem( tr ( "Tonga" ) ); | 471 | cmbCountry->insertItem( tr ( "Tonga" ) ); |
472 | cmbCountry->insertItem( tr ( "Tunisia" ) ); | 472 | cmbCountry->insertItem( tr ( "Tunisia" ) ); |
473 | cmbCountry->insertItem( tr ( "Turkey" ) ); | 473 | cmbCountry->insertItem( tr ( "Turkey" ) ); |
474 | cmbCountry->insertItem( tr ( "Turkmenistan" ) ); | 474 | cmbCountry->insertItem( tr ( "Turkmenistan" ) ); |
475 | cmbCountry->insertItem( tr ( "Tuvalu" ) ); | 475 | cmbCountry->insertItem( tr ( "Tuvalu" ) ); |
476 | cmbCountry->insertItem( tr ( "Uganda" ) ); | 476 | cmbCountry->insertItem( tr ( "Uganda" ) ); |
477 | cmbCountry->insertItem( tr ( "Ukraine" ) ); | 477 | cmbCountry->insertItem( tr ( "Ukraine" ) ); |
478 | cmbCountry->insertItem( tr ( "Uruguay" ) ); | 478 | cmbCountry->insertItem( tr ( "Uruguay" ) ); |
479 | cmbCountry->insertItem( tr ( "Uzbekistan" ) ); | 479 | cmbCountry->insertItem( tr ( "Uzbekistan" ) ); |
480 | cmbCountry->insertItem( tr ( "Vanuatu" ) ); | 480 | cmbCountry->insertItem( tr ( "Vanuatu" ) ); |
481 | cmbCountry->insertItem( tr ( "Venezuela" ) ); | 481 | cmbCountry->insertItem( tr ( "Venezuela" ) ); |
482 | cmbCountry->insertItem( tr ( "Vietnam" ) ); | 482 | cmbCountry->insertItem( tr ( "Vietnam" ) ); |
483 | cmbCountry->insertItem( tr ( "Virgin Islands" ) ); | 483 | cmbCountry->insertItem( tr ( "Virgin Islands" ) ); |
484 | cmbCountry->insertItem( tr ( "Western Sahara" ) ); | 484 | cmbCountry->insertItem( tr ( "Western Sahara" ) ); |
485 | cmbCountry->insertItem( tr ( "Yemen" ) ); | 485 | cmbCountry->insertItem( tr ( "Yemen" ) ); |
486 | cmbCountry->insertItem( tr ( "Yugoslavia" ) ); | 486 | cmbCountry->insertItem( tr ( "Yugoslavia" ) ); |
487 | cmbCountry->insertItem( tr ( "Zambia" ) ); | 487 | cmbCountry->insertItem( tr ( "Zambia" ) ); |
488 | cmbCountry->insertItem( tr ( "Zimbabwe" ) ); | 488 | cmbCountry->insertItem( tr ( "Zimbabwe" ) ); |
489 | if (cmbCountry->listBox()!=0) | 489 | if (cmbCountry->listBox()!=0) |
490 | cmbCountry->listBox()->sort(); | 490 | cmbCountry->listBox()->sort(); |
491 | 491 | ||
492 | cmbCountry->setMaximumWidth( 135 ); | 492 | cmbCountry->setMaximumWidth( 135 ); |
493 | 493 | ||
494 | gl->addMultiCellWidget( cmbCountry, 5, 5, 1, 2 ); | 494 | gl->addMultiCellWidget( cmbCountry, 5, 5, 1, 2 ); |
495 | 495 | ||
496 | // Chooser 4 | 496 | // Chooser 4 |
497 | cmbChooserField4 = new QComboBox( FALSE, container ); | 497 | cmbChooserField4 = new QComboBox( FALSE, container ); |
498 | cmbChooserField4->setMaximumWidth( 90 ); | 498 | cmbChooserField4->setMaximumWidth( 90 ); |
499 | gl->addWidget( cmbChooserField4, 6, 0 ); | 499 | gl->addWidget( cmbChooserField4, 6, 0 ); |
500 | // Textfield for chooser 2 | 500 | // Textfield for chooser 2 |
501 | // Now use WidgetStack to contain the textfield and the default-email combo! | 501 | // Now use WidgetStack to contain the textfield and the default-email combo! |
502 | m_widgetStack4 = new QWidgetStack( container ); | 502 | m_widgetStack4 = new QWidgetStack( container ); |
503 | txtChooserField4 = new QLineEdit( m_widgetStack4 ); | 503 | txtChooserField4 = new QLineEdit( m_widgetStack4 ); |
504 | m_widgetStack4 -> addWidget( txtChooserField4, TextField ); | 504 | m_widgetStack4 -> addWidget( txtChooserField4, TextField ); |
505 | gl->addMultiCellWidget( m_widgetStack4, 6, 6, 1, 2 ); | 505 | gl->addMultiCellWidget( m_widgetStack4, 6, 6, 1, 2 ); |
506 | m_widgetStack4 -> raiseWidget( TextField ); | 506 | m_widgetStack4 -> raiseWidget( TextField ); |
507 | 507 | ||
508 | QSpacerItem *space = new QSpacerItem(1,1, | 508 | QSpacerItem *space = new QSpacerItem(1,1, |
509 | QSizePolicy::Maximum, | 509 | QSizePolicy::Maximum, |
510 | QSizePolicy::MinimumExpanding ); | 510 | QSizePolicy::MinimumExpanding ); |
511 | gl->addItem( space, 7, 0 ); | 511 | gl->addItem( space, 7, 0 ); |
512 | 512 | ||
513 | tabMain->insertTab( tabViewport, tr( "Address" ) ); | 513 | tabMain->insertTab( tabViewport, tr( "Address" ) ); |
514 | 514 | ||
515 | tabViewport = new QWidget ( tabMain ); | 515 | tabViewport = new QWidget ( tabMain ); |
516 | 516 | ||
517 | vb = new QVBoxLayout( tabViewport ); | 517 | vb = new QVBoxLayout( tabViewport ); |
518 | 518 | ||
519 | svDetails = new QScrollView( tabViewport ); | 519 | svDetails = new QScrollView( tabViewport ); |
520 | vb->addWidget( svDetails, 0, 0 ); | 520 | vb->addWidget( svDetails, 0, 0 ); |
521 | svDetails->setResizePolicy( QScrollView::AutoOneFit ); | 521 | svDetails->setResizePolicy( QScrollView::AutoOneFit ); |
522 | svDetails->setFrameStyle( QFrame::NoFrame ); | 522 | svDetails->setFrameStyle( QFrame::NoFrame ); |
523 | 523 | ||
524 | container = new QWidget( svDetails->viewport() ); | 524 | container = new QWidget( svDetails->viewport() ); |
525 | svDetails->addChild( container ); | 525 | svDetails->addChild( container ); |
526 | 526 | ||
527 | gl = new QGridLayout( container, 1, 2, 2, 4 ); | 527 | gl = new QGridLayout( container, 1, 2, 2, 4 ); |
528 | 528 | ||
529 | int counter = 0; | 529 | int counter = 0; |
530 | 530 | ||
531 | // Birthday | 531 | // Birthday |
532 | QHBox* hBox = new QHBox( container ); | 532 | QHBox* hBox = new QHBox( container ); |
533 | l = new QLabel( tr("Birthday"), container ); | 533 | l = new QLabel( tr("Birthday"), container ); |
534 | gl->addWidget( l, counter, 0 ); | 534 | gl->addWidget( l, counter, 0 ); |
535 | 535 | ||
536 | QPopupMenu* m1 = new QPopupMenu( container ); | 536 | QPopupMenu* m1 = new QPopupMenu( container ); |
537 | birthdayPicker = new DateBookMonth( m1, 0, TRUE ); | 537 | birthdayPicker = new DateBookMonth( m1, 0, TRUE ); |
538 | m1->insertItem( birthdayPicker ); | 538 | m1->insertItem( birthdayPicker ); |
539 | 539 | ||
540 | birthdayButton= new QToolButton( hBox, "buttonStart" ); | 540 | birthdayButton= new QToolButton( hBox, "buttonStart" ); |
541 | birthdayButton->setPopup( m1 ); | 541 | birthdayButton->setPopup( m1 ); |
542 | birthdayButton->setPopupDelay(0); | 542 | birthdayButton->setPopupDelay(0); |
543 | 543 | ||
544 | QPushButton* deleteButton = new QPushButton( QIconSet( Resource::loadPixmap( "trash" ) ), | 544 | QPushButton* deleteButton = new QPushButton( QIconSet( Resource::loadPixmap( "trash" ) ), |
545 | tr( "Delete" ), | 545 | tr( "Delete" ), |
546 | hBox, 0 ); | 546 | hBox, 0 ); |
547 | 547 | ||
548 | gl->addWidget( hBox, counter , 1 ); | 548 | gl->addWidget( hBox, counter , 1 ); |
549 | 549 | ||
550 | connect( birthdayPicker, SIGNAL( dateClicked( int, int, int ) ), | 550 | connect( birthdayPicker, SIGNAL( dateClicked( int, int, int ) ), |
551 | this, SLOT( slotBirthdayDateChanged( int, int, int ) ) ); | 551 | this, SLOT( slotBirthdayDateChanged( int, int, int ) ) ); |
552 | connect( deleteButton, SIGNAL( clicked() ), this, SLOT( slotRemoveBirthday() ) ); | 552 | connect( deleteButton, SIGNAL( clicked() ), this, SLOT( slotRemoveBirthday() ) ); |
553 | 553 | ||
554 | ++counter; | 554 | ++counter; |
555 | 555 | ||
556 | // Anniversary | 556 | // Anniversary |
557 | hBox = new QHBox( container ); | 557 | hBox = new QHBox( container ); |
558 | l = new QLabel( tr("Anniversary"), container ); | 558 | l = new QLabel( tr("Anniversary"), container ); |
559 | gl->addWidget( l, counter, 0 ); | 559 | gl->addWidget( l, counter, 0 ); |
560 | 560 | ||
561 | m1 = new QPopupMenu( container ); | 561 | m1 = new QPopupMenu( container ); |
562 | anniversaryPicker = new DateBookMonth( m1, 0, TRUE ); | 562 | anniversaryPicker = new DateBookMonth( m1, 0, TRUE ); |
563 | m1->insertItem( anniversaryPicker ); | 563 | m1->insertItem( anniversaryPicker ); |
564 | 564 | ||
565 | anniversaryButton= new QToolButton( hBox, "buttonStart" ); | 565 | anniversaryButton= new QToolButton( hBox, "buttonStart" ); |
566 | anniversaryButton->setPopup( m1 ); | 566 | anniversaryButton->setPopup( m1 ); |
567 | anniversaryButton->setPopupDelay(0); | 567 | anniversaryButton->setPopupDelay(0); |
568 | 568 | ||
569 | deleteButton = new QPushButton( QIconSet( Resource::loadPixmap( "trash" ) ), | 569 | deleteButton = new QPushButton( QIconSet( Resource::loadPixmap( "trash" ) ), |
570 | tr( "Delete" ), | 570 | tr( "Delete" ), |
571 | hBox, 0 ); | 571 | hBox, 0 ); |
572 | gl->addWidget( hBox, counter , 1 ); | 572 | gl->addWidget( hBox, counter , 1 ); |
573 | 573 | ||
574 | connect( anniversaryPicker, SIGNAL( dateClicked( int, int, int ) ), | 574 | connect( anniversaryPicker, SIGNAL( dateClicked( int, int, int ) ), |
575 | this, SLOT( slotAnniversaryDateChanged( int, int, int ) ) ); | 575 | this, SLOT( slotAnniversaryDateChanged( int, int, int ) ) ); |
576 | connect( deleteButton, SIGNAL( clicked() ), this, SLOT( slotRemoveAnniversary() ) ); | 576 | connect( deleteButton, SIGNAL( clicked() ), this, SLOT( slotRemoveAnniversary() ) ); |
577 | 577 | ||
578 | ++counter; | 578 | ++counter; |
579 | 579 | ||
580 | // Gender | 580 | // Gender |
581 | l = new QLabel( tr("Gender"), container ); | 581 | l = new QLabel( tr("Gender"), container ); |
582 | gl->addWidget( l, counter, 0 ); | 582 | gl->addWidget( l, counter, 0 ); |
583 | cmbGender = new QComboBox( container ); | 583 | cmbGender = new QComboBox( container ); |
584 | cmbGender->insertItem( "", 0 ); | 584 | cmbGender->insertItem( "", 0 ); |
585 | cmbGender->insertItem( tr("Male"), 1); | 585 | cmbGender->insertItem( tr("Male"), 1); |
586 | cmbGender->insertItem( tr("Female"), 2); | 586 | cmbGender->insertItem( tr("Female"), 2); |
587 | gl->addWidget( cmbGender, counter, 1 ); | 587 | gl->addWidget( cmbGender, counter, 1 ); |
588 | 588 | ||
589 | ++counter; | 589 | ++counter; |
590 | 590 | ||
591 | // Create Labels and lineedit fields for every dynamic entry | 591 | // Create Labels and lineedit fields for every dynamic entry |
592 | QStringList::ConstIterator it = slDynamicEntries.begin(); | 592 | QStringList::ConstIterator it = slDynamicEntries.begin(); |
593 | QMap<QString, int> mapStrToID = OContactFields::untrFieldsToId(); | 593 | QMap<QString, int> mapStrToID = OContactFields::untrFieldsToId(); |
594 | QMap<int, QString> mapIdToStr = OContactFields::idToTrFields(); | 594 | QMap<int, QString> mapIdToStr = OContactFields::idToTrFields(); |
595 | for (i = counter; it != slDynamicEntries.end(); i++, ++it ) { | 595 | for (i = counter; it != slDynamicEntries.end(); i++, ++it ) { |
596 | 596 | ||
597 | if (((*it) == "Anniversary") || | 597 | if (((*it) == "Anniversary") || |
598 | ((*it) == "Birthday")|| ((*it) == "Gender")) continue; | 598 | ((*it) == "Birthday")|| ((*it) == "Gender")) continue; |
599 | 599 | ||
600 | l = new QLabel( mapIdToStr[mapStrToID[*it]].utf8() , container ); | 600 | l = new QLabel( mapIdToStr[mapStrToID[*it]], container ); |
601 | listName.append( l ); | 601 | listName.append( l ); |
602 | gl->addWidget( l, i, 0 ); | 602 | gl->addWidget( l, i, 0 ); |
603 | QLineEdit *e = new QLineEdit( container ); | 603 | QLineEdit *e = new QLineEdit( container ); |
604 | listValue.append( e ); | 604 | listValue.append( e ); |
605 | gl->addWidget( e, i, 1); | 605 | gl->addWidget( e, i, 1); |
606 | } | 606 | } |
607 | // Fill labels with names.. | 607 | // Fill labels with names.. |
608 | //loadFields(); | 608 | //loadFields(); |
609 | 609 | ||
610 | 610 | ||
611 | tabMain->insertTab( tabViewport, tr( "Details" ) ); | 611 | tabMain->insertTab( tabViewport, tr( "Details" ) ); |
612 | 612 | ||
613 | dlgNote = new QDialog( this, "Note Dialog", TRUE ); | 613 | dlgNote = new QDialog( this, "Note Dialog", TRUE ); |
614 | dlgNote->setCaption( tr("Enter Note") ); | 614 | dlgNote->setCaption( tr("Enter Note") ); |
615 | QVBoxLayout *vbNote = new QVBoxLayout( dlgNote ); | 615 | QVBoxLayout *vbNote = new QVBoxLayout( dlgNote ); |
616 | txtNote = new QMultiLineEdit( dlgNote ); | 616 | txtNote = new QMultiLineEdit( dlgNote ); |
617 | vbNote->addWidget( txtNote ); | 617 | vbNote->addWidget( txtNote ); |
618 | connect( btnNote, SIGNAL(clicked()), this, SLOT(slotNote()) ); | 618 | connect( btnNote, SIGNAL(clicked()), this, SLOT(slotNote()) ); |
619 | 619 | ||
620 | dlgName = new QDialog( this, "Name Dialog", TRUE ); | 620 | dlgName = new QDialog( this, "Name Dialog", TRUE ); |
621 | dlgName->setCaption( tr("Edit Name") ); | 621 | dlgName->setCaption( tr("Edit Name") ); |
622 | gl = new QGridLayout( dlgName, 5, 2, 2, 3 ); | 622 | gl = new QGridLayout( dlgName, 5, 2, 2, 3 ); |
623 | 623 | ||
624 | l = new QLabel( tr("First Name"), dlgName ); | 624 | l = new QLabel( tr("First Name"), dlgName ); |
625 | gl->addWidget( l, 0, 0 ); | 625 | gl->addWidget( l, 0, 0 ); |
626 | txtFirstName = new QLineEdit( dlgName ); | 626 | txtFirstName = new QLineEdit( dlgName ); |
627 | gl->addWidget( txtFirstName, 0, 1 ); | 627 | gl->addWidget( txtFirstName, 0, 1 ); |
628 | 628 | ||
629 | l = new QLabel( tr("Middle Name"), dlgName ); | 629 | l = new QLabel( tr("Middle Name"), dlgName ); |
630 | gl->addWidget( l, 1, 0 ); | 630 | gl->addWidget( l, 1, 0 ); |
631 | txtMiddleName = new QLineEdit( dlgName ); | 631 | txtMiddleName = new QLineEdit( dlgName ); |
632 | gl->addWidget( txtMiddleName, 1, 1 ); | 632 | gl->addWidget( txtMiddleName, 1, 1 ); |
633 | 633 | ||
634 | l = new QLabel( tr("Last Name"), dlgName ); | 634 | l = new QLabel( tr("Last Name"), dlgName ); |
635 | gl->addWidget( l, 2, 0 ); | 635 | gl->addWidget( l, 2, 0 ); |
636 | txtLastName = new QLineEdit( dlgName ); | 636 | txtLastName = new QLineEdit( dlgName ); |
637 | gl->addWidget( txtLastName, 2, 1 ); | 637 | gl->addWidget( txtLastName, 2, 1 ); |
638 | 638 | ||
639 | // l = new QLabel( tr("Suffix"), dlgName ); | 639 | // l = new QLabel( tr("Suffix"), dlgName ); |
640 | // gl->addWidget( l, 3, 0 ); | 640 | // gl->addWidget( l, 3, 0 ); |
641 | // txtSuffix = new QLineEdit( dlgName ); | 641 | // txtSuffix = new QLineEdit( dlgName ); |
642 | // gl->addWidget( txtSuffix, 3, 1 ); | 642 | // gl->addWidget( txtSuffix, 3, 1 ); |
643 | space = new QSpacerItem(1,1, | 643 | space = new QSpacerItem(1,1, |
644 | QSizePolicy::Maximum, | 644 | QSizePolicy::Maximum, |
645 | QSizePolicy::MinimumExpanding ); | 645 | QSizePolicy::MinimumExpanding ); |
646 | gl->addItem( space, 4, 0 ); | 646 | gl->addItem( space, 4, 0 ); |
647 | 647 | ||
648 | cmbChooserField1->insertStringList( trlChooserNames ); | 648 | cmbChooserField1->insertStringList( trlChooserNames ); |
649 | cmbChooserField2->insertStringList( trlChooserNames ); | 649 | cmbChooserField2->insertStringList( trlChooserNames ); |
650 | cmbChooserField3->insertStringList( trlChooserNames ); | 650 | cmbChooserField3->insertStringList( trlChooserNames ); |
651 | cmbChooserField4->insertStringList( trlChooserNames ); | 651 | cmbChooserField4->insertStringList( trlChooserNames ); |
652 | 652 | ||
653 | cmbChooserField1->setCurrentItem( 0 ); | 653 | cmbChooserField1->setCurrentItem( 0 ); |
654 | cmbChooserField2->setCurrentItem( 1 ); | 654 | cmbChooserField2->setCurrentItem( 1 ); |
655 | cmbChooserField3->setCurrentItem( 2 ); | 655 | cmbChooserField3->setCurrentItem( 2 ); |
656 | 656 | ||
657 | connect( btnFullName, SIGNAL(clicked()), this, SLOT(slotName()) ); | 657 | connect( btnFullName, SIGNAL(clicked()), this, SLOT(slotName()) ); |
658 | 658 | ||
659 | connect( txtFullName, SIGNAL(textChanged(const QString &)), | 659 | connect( txtFullName, SIGNAL(textChanged(const QString &)), |
660 | this, SLOT(slotFullNameChange(const QString &)) ); | 660 | this, SLOT(slotFullNameChange(const QString &)) ); |
661 | connect( txtSuffix, SIGNAL(textChanged(const QString &)), | 661 | connect( txtSuffix, SIGNAL(textChanged(const QString &)), |
662 | this, SLOT(slotSuffixChange(const QString &)) ); | 662 | this, SLOT(slotSuffixChange(const QString &)) ); |
663 | connect( txtOrganization, SIGNAL(textChanged(const QString &)), | 663 | connect( txtOrganization, SIGNAL(textChanged(const QString &)), |
664 | this, SLOT(slotOrganizationChange(const QString &)) ); | 664 | this, SLOT(slotOrganizationChange(const QString &)) ); |
665 | connect( txtChooserField1, SIGNAL(textChanged(const QString &)), | 665 | connect( txtChooserField1, SIGNAL(textChanged(const QString &)), |
666 | this, SLOT(slotChooser1Change(const QString &)) ); | 666 | this, SLOT(slotChooser1Change(const QString &)) ); |
667 | connect( txtChooserField2, SIGNAL(textChanged(const QString &)), | 667 | connect( txtChooserField2, SIGNAL(textChanged(const QString &)), |
668 | this, SLOT(slotChooser2Change(const QString &)) ); | 668 | this, SLOT(slotChooser2Change(const QString &)) ); |
669 | connect( txtChooserField3, SIGNAL(textChanged(const QString &)), | 669 | connect( txtChooserField3, SIGNAL(textChanged(const QString &)), |
670 | this, SLOT(slotChooser3Change(const QString &)) ); | 670 | this, SLOT(slotChooser3Change(const QString &)) ); |
671 | connect( txtChooserField4, SIGNAL(textChanged(const QString &)), | 671 | connect( txtChooserField4, SIGNAL(textChanged(const QString &)), |
672 | this, SLOT(slotChooser4Change(const QString &)) ); | 672 | this, SLOT(slotChooser4Change(const QString &)) ); |
673 | connect( txtAddress, SIGNAL(textChanged(const QString &)), | 673 | connect( txtAddress, SIGNAL(textChanged(const QString &)), |
674 | this, SLOT(slotAddressChange(const QString &)) ); | 674 | this, SLOT(slotAddressChange(const QString &)) ); |
675 | connect( txtCity, SIGNAL(textChanged(const QString &)), | 675 | connect( txtCity, SIGNAL(textChanged(const QString &)), |
676 | this, SLOT(slotCityChange(const QString &)) ); | 676 | this, SLOT(slotCityChange(const QString &)) ); |
677 | connect( txtState, SIGNAL(textChanged(const QString &)), | 677 | connect( txtState, SIGNAL(textChanged(const QString &)), |
678 | this, SLOT(slotStateChange(const QString &)) ); | 678 | this, SLOT(slotStateChange(const QString &)) ); |
679 | connect( txtZip, SIGNAL(textChanged(const QString &)), | 679 | connect( txtZip, SIGNAL(textChanged(const QString &)), |
680 | this, SLOT(slotZipChange(const QString &)) ); | 680 | this, SLOT(slotZipChange(const QString &)) ); |
681 | connect( cmbCountry, SIGNAL(textChanged(const QString &)), | 681 | connect( cmbCountry, SIGNAL(textChanged(const QString &)), |
682 | this, SLOT(slotCountryChange(const QString &)) ); | 682 | this, SLOT(slotCountryChange(const QString &)) ); |
683 | connect( cmbCountry, SIGNAL(activated(const QString &)), | 683 | connect( cmbCountry, SIGNAL(activated(const QString &)), |
684 | this, SLOT(slotCountryChange(const QString &)) ); | 684 | this, SLOT(slotCountryChange(const QString &)) ); |
685 | connect( cmbChooserField1, SIGNAL(activated(int)), | 685 | connect( cmbChooserField1, SIGNAL(activated(int)), |
686 | this, SLOT(slotCmbChooser1Change(int)) ); | 686 | this, SLOT(slotCmbChooser1Change(int)) ); |
687 | connect( cmbChooserField2, SIGNAL(activated(int)), | 687 | connect( cmbChooserField2, SIGNAL(activated(int)), |
688 | this, SLOT(slotCmbChooser2Change(int)) ); | 688 | this, SLOT(slotCmbChooser2Change(int)) ); |
689 | connect( cmbChooserField3, SIGNAL(activated(int)), | 689 | connect( cmbChooserField3, SIGNAL(activated(int)), |
690 | this, SLOT(slotCmbChooser3Change(int)) ); | 690 | this, SLOT(slotCmbChooser3Change(int)) ); |
691 | connect( cmbChooserField4, SIGNAL(activated(int)), | 691 | connect( cmbChooserField4, SIGNAL(activated(int)), |
692 | this, SLOT(slotCmbChooser4Change(int)) ); | 692 | this, SLOT(slotCmbChooser4Change(int)) ); |
693 | connect( cmbAddress, SIGNAL(activated(int)), | 693 | connect( cmbAddress, SIGNAL(activated(int)), |
694 | this, SLOT(slotAddressTypeChange(int)) ); | 694 | this, SLOT(slotAddressTypeChange(int)) ); |
695 | 695 | ||
696 | new QPEDialogListener(this); | 696 | new QPEDialogListener(this); |
697 | 697 | ||
698 | setPersonalView ( m_personalView ); | 698 | setPersonalView ( m_personalView ); |
699 | 699 | ||
700 | qWarning("init() END"); | 700 | qWarning("init() END"); |
701 | } | 701 | } |
702 | 702 | ||
703 | void ContactEditor::defaultEmailChanged(int i){ | 703 | void ContactEditor::defaultEmailChanged(int i){ |
704 | qDebug("defaultEmailChanged"); | 704 | qDebug("defaultEmailChanged"); |
705 | 705 | ||
706 | // was sollte das ? (se) | 706 | // was sollte das ? (se) |
707 | // int index = cmbChooserField1->currentItem(); | 707 | // int index = cmbChooserField1->currentItem(); |
708 | // slChooserValues[index] = cmbDefaultEmail->text(i); | 708 | // slChooserValues[index] = cmbDefaultEmail->text(i); |
709 | 709 | ||
710 | defaultEmail = cmbDefaultEmail->text(i); | 710 | defaultEmail = cmbDefaultEmail->text(i); |
711 | qDebug ("Changed to: %s", defaultEmail.latin1()); | 711 | qDebug ("Changed to: %s", defaultEmail.latin1()); |
712 | 712 | ||
713 | } | 713 | } |
714 | 714 | ||
715 | void ContactEditor::populateDefaultEmailCmb(){ | 715 | void ContactEditor::populateDefaultEmailCmb(){ |
716 | 716 | ||
717 | // if the default-email combo was not selected and therfore not created | 717 | // if the default-email combo was not selected and therfore not created |
718 | // we get a lot of trouble.. Therfore create an invisible one.. | 718 | // we get a lot of trouble.. Therfore create an invisible one.. |
719 | if ( !cmbDefaultEmail ){ | 719 | if ( !cmbDefaultEmail ){ |
720 | cmbDefaultEmail = new QComboBox(this); | 720 | cmbDefaultEmail = new QComboBox(this); |
721 | cmbDefaultEmail -> hide(); | 721 | cmbDefaultEmail -> hide(); |
722 | } | 722 | } |
723 | cmbDefaultEmail->clear(); | 723 | cmbDefaultEmail->clear(); |
724 | cmbDefaultEmail->insertStringList( emails ); | 724 | cmbDefaultEmail->insertStringList( emails ); |
725 | // cmbDefaultEmail->show(); | 725 | // cmbDefaultEmail->show(); |
726 | 726 | ||
727 | // Select default email in combo.. | 727 | // Select default email in combo.. |
728 | bool found = false; | 728 | bool found = false; |
729 | for ( int i = 0; i < cmbDefaultEmail->count(); i++){ | 729 | for ( int i = 0; i < cmbDefaultEmail->count(); i++){ |
730 | qDebug(" populateDefaultEmailCmb text >%s< defaultEmail >%s<", | 730 | qDebug(" populateDefaultEmailCmb text >%s< defaultEmail >%s<", |
731 | cmbDefaultEmail->text( i ).latin1(), defaultEmail.latin1()); | 731 | cmbDefaultEmail->text( i ).latin1(), defaultEmail.latin1()); |
732 | 732 | ||
733 | if ( cmbDefaultEmail->text( i ).stripWhiteSpace() == defaultEmail.stripWhiteSpace() ){ | 733 | if ( cmbDefaultEmail->text( i ).stripWhiteSpace() == defaultEmail.stripWhiteSpace() ){ |
734 | cmbDefaultEmail->setCurrentItem( i ); | 734 | cmbDefaultEmail->setCurrentItem( i ); |
735 | qDebug("set"); | 735 | qDebug("set"); |
736 | found = true; | 736 | found = true; |
737 | } | 737 | } |
738 | } | 738 | } |
739 | 739 | ||
740 | // If the current default email is not found in the list, we choose the | 740 | // If the current default email is not found in the list, we choose the |
741 | // first one.. | 741 | // first one.. |
742 | if ( !found ) | 742 | if ( !found ) |
743 | defaultEmail = cmbDefaultEmail->text(0); | 743 | defaultEmail = cmbDefaultEmail->text(0); |
744 | } | 744 | } |
745 | 745 | ||
746 | // Called when any combobox was changed. | 746 | // Called when any combobox was changed. |
747 | // "true" returned if the change was chandled by this function, else it should | 747 | // "true" returned if the change was chandled by this function, else it should |
748 | // be handled by something else.. | 748 | // be handled by something else.. |
749 | bool ContactEditor::cmbChooserChange( int index, QWidgetStack* inputStack, int widgetPos ) { | 749 | bool ContactEditor::cmbChooserChange( int index, QWidgetStack* inputStack, int widgetPos ) { |
750 | QString type = slChooserNames[index]; | 750 | QString type = slChooserNames[index]; |
751 | qWarning("ContactEditor::cmbChooserChange -> Type: %s, WidgetPos: %d", type.latin1(), widgetPos ); | 751 | qWarning("ContactEditor::cmbChooserChange -> Type: %s, WidgetPos: %d", type.latin1(), widgetPos ); |
752 | 752 | ||
753 | if ( !initializing ) | 753 | if ( !initializing ) |
754 | contactfields.setFieldOrder( widgetPos-1, index ); | 754 | contactfields.setFieldOrder( widgetPos-1, index ); |
755 | 755 | ||
756 | // Create and connect combobox for selecting the default email | 756 | // Create and connect combobox for selecting the default email |
757 | if ( type == "Default Email"){ | 757 | if ( type == "Default Email"){ |
758 | qWarning("Choosing default-email (defaultEmailChooserPosition= %d) ", defaultEmailChooserPosition); | 758 | qWarning("Choosing default-email (defaultEmailChooserPosition= %d) ", defaultEmailChooserPosition); |
759 | 759 | ||
760 | // More than one default-email chooser is not allowed ! | 760 | // More than one default-email chooser is not allowed ! |
761 | if ( ( defaultEmailChooserPosition != -1 ) && | 761 | if ( ( defaultEmailChooserPosition != -1 ) && |
762 | defaultEmailChooserPosition != widgetPos && !initializing){ | 762 | defaultEmailChooserPosition != widgetPos && !initializing){ |
763 | chooserError( widgetPos ); | 763 | chooserError( widgetPos ); |
764 | return true; | 764 | return true; |
765 | } | 765 | } |
766 | 766 | ||
767 | QComboBox* cmbo = ( QComboBox* ) inputStack -> widget( Combo ); | 767 | QComboBox* cmbo = ( QComboBox* ) inputStack -> widget( Combo ); |
768 | if ( cmbo ){ | 768 | if ( cmbo ){ |
769 | inputStack->raiseWidget( TextField ); | 769 | inputStack->raiseWidget( TextField ); |
770 | inputStack -> removeWidget( cmbo ); | 770 | inputStack -> removeWidget( cmbo ); |
771 | delete cmbo; | 771 | delete cmbo; |
772 | } | 772 | } |
773 | cmbo = new QComboBox( inputStack ); | 773 | cmbo = new QComboBox( inputStack ); |
774 | cmbo -> insertStringList( emails ); | 774 | cmbo -> insertStringList( emails ); |
775 | 775 | ||
776 | inputStack -> addWidget( cmbo, Combo ); | 776 | inputStack -> addWidget( cmbo, Combo ); |
777 | inputStack -> raiseWidget( Combo ); | 777 | inputStack -> raiseWidget( Combo ); |
778 | 778 | ||
779 | defaultEmailChooserPosition = widgetPos; | 779 | defaultEmailChooserPosition = widgetPos; |
780 | cmbDefaultEmail = cmbo; | 780 | cmbDefaultEmail = cmbo; |
781 | 781 | ||
782 | connect( cmbo,SIGNAL( activated(int) ), | 782 | connect( cmbo,SIGNAL( activated(int) ), |
783 | SLOT( defaultEmailChanged(int) ) ); | 783 | SLOT( defaultEmailChanged(int) ) ); |
784 | 784 | ||
785 | // Set current default email | 785 | // Set current default email |
786 | populateDefaultEmailCmb(); | 786 | populateDefaultEmailCmb(); |
787 | 787 | ||
788 | 788 | ||
789 | } else { | 789 | } else { |
790 | // Something else was selected: Hide combo.. | 790 | // Something else was selected: Hide combo.. |
791 | qWarning(" Hiding default-email combo" ); | 791 | qWarning(" Hiding default-email combo" ); |
792 | if ( defaultEmailChooserPosition == widgetPos ){ | 792 | if ( defaultEmailChooserPosition == widgetPos ){ |
793 | defaultEmailChooserPosition = -1; | 793 | defaultEmailChooserPosition = -1; |
794 | } | 794 | } |
795 | QComboBox* cmbo = ( QComboBox* ) inputStack -> widget( Combo ); | 795 | QComboBox* cmbo = ( QComboBox* ) inputStack -> widget( Combo ); |
796 | if ( cmbo ){ | 796 | if ( cmbo ){ |
797 | inputStack->raiseWidget( TextField ); | 797 | inputStack->raiseWidget( TextField ); |
798 | inputStack -> removeWidget( cmbo ); | 798 | inputStack -> removeWidget( cmbo ); |
799 | cmbDefaultEmail = 0l; | 799 | cmbDefaultEmail = 0l; |
800 | delete cmbo; | 800 | delete cmbo; |
801 | } | 801 | } |
802 | 802 | ||
803 | // Caller should initialize the responsible textfield, therefore | 803 | // Caller should initialize the responsible textfield, therefore |
804 | // "false" is returned | 804 | // "false" is returned |
805 | return false; | 805 | return false; |
806 | } | 806 | } |
807 | 807 | ||
808 | // Everything is worked off .. | 808 | // Everything is worked off .. |
809 | return true; | 809 | return true; |
810 | 810 | ||
811 | } | 811 | } |
812 | 812 | ||
813 | // Currently accessed when we select default-email more than once ! | 813 | // Currently accessed when we select default-email more than once ! |
814 | void ContactEditor::chooserError( int index ) | 814 | void ContactEditor::chooserError( int index ) |
815 | { | 815 | { |
816 | qWarning("ContactEditor::chooserError( %d )", index); | 816 | qWarning("ContactEditor::chooserError( %d )", index); |
817 | QMessageBox::warning( this, "Chooser Error", | 817 | QMessageBox::warning( this, "Chooser Error", |
818 | "Multiple selection of this\n" | 818 | "Multiple selection of this\n" |
819 | "Item is not allowed !\n\n" | 819 | "Item is not allowed !\n\n" |
820 | "First deselect the previous one !", | 820 | "First deselect the previous one !", |
821 | "&OK", 0, 0, | 821 | "&OK", 0, 0, |
822 | 0, 0 ); | 822 | 0, 0 ); |
823 | 823 | ||
824 | // Reset the selected Chooser. Unfortunately the chooser | 824 | // Reset the selected Chooser. Unfortunately the chooser |
825 | // generates no signal, therfore we have to | 825 | // generates no signal, therfore we have to |
826 | // call the cmbChooserChange function manually.. | 826 | // call the cmbChooserChange function manually.. |
827 | switch( index ){ | 827 | switch( index ){ |
828 | case 1: | 828 | case 1: |
829 | cmbChooserField1 -> setCurrentItem( 0 ); | 829 | cmbChooserField1 -> setCurrentItem( 0 ); |
830 | slotCmbChooser1Change( 0 ); | 830 | slotCmbChooser1Change( 0 ); |
831 | break; | 831 | break; |
832 | case 2: | 832 | case 2: |
833 | cmbChooserField2 -> setCurrentItem( 0 ); | 833 | cmbChooserField2 -> setCurrentItem( 0 ); |
834 | slotCmbChooser2Change( 0 ); | 834 | slotCmbChooser2Change( 0 ); |
835 | break; | 835 | break; |
836 | case 3: | 836 | case 3: |
837 | cmbChooserField3 -> setCurrentItem( 0 ); | 837 | cmbChooserField3 -> setCurrentItem( 0 ); |
838 | slotCmbChooser3Change( 0 ); | 838 | slotCmbChooser3Change( 0 ); |
839 | break; | 839 | break; |
840 | case 4: | 840 | case 4: |
841 | cmbChooserField4 -> setCurrentItem( 0 ); | 841 | cmbChooserField4 -> setCurrentItem( 0 ); |
842 | slotCmbChooser4Change( 0 ); | 842 | slotCmbChooser4Change( 0 ); |
843 | break; | 843 | break; |
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
847 | // Called when something was changed in a textfield (shouldn't it called textchanged? (se)) | 847 | // Called when something was changed in a textfield (shouldn't it called textchanged? (se)) |
848 | void ContactEditor::chooserChange( const QString &textChanged, int index, | 848 | void ContactEditor::chooserChange( const QString &textChanged, int index, |
849 | QLineEdit* , int widgetPos ) { | 849 | QLineEdit* , int widgetPos ) { |
850 | 850 | ||
851 | QString type = slChooserNames[index]; // :SX | 851 | QString type = slChooserNames[index]; // :SX |
852 | qDebug("ContactEditor::chooserChange( type=>%s<, textChanged=>%s< index=%i, widgetPos=%i", | 852 | qDebug("ContactEditor::chooserChange( type=>%s<, textChanged=>%s< index=%i, widgetPos=%i", |
853 | type.latin1(),textChanged.latin1(), index, widgetPos ); | 853 | type.latin1(),textChanged.latin1(), index, widgetPos ); |
854 | 854 | ||
855 | if ( type == "Default Email"){ | 855 | if ( type == "Default Email"){ |
856 | qWarning ("??? Wozu??: %s", textChanged.latin1()); | 856 | qWarning ("??? Wozu??: %s", textChanged.latin1()); |
857 | defaultEmail = textChanged; | 857 | defaultEmail = textChanged; |
858 | 858 | ||
859 | populateDefaultEmailCmb(); | 859 | populateDefaultEmailCmb(); |
860 | 860 | ||
861 | }else if (type == "Emails"){ | 861 | }else if (type == "Emails"){ |
862 | qDebug("emails"); | 862 | qDebug("emails"); |
863 | 863 | ||
864 | QString de; | 864 | QString de; |
865 | emails = QStringList::split (",", textChanged ); | 865 | emails = QStringList::split (",", textChanged ); |
866 | 866 | ||
867 | populateDefaultEmailCmb(); | 867 | populateDefaultEmailCmb(); |
868 | } | 868 | } |
869 | 869 | ||
870 | slChooserValues[index] = textChanged; | 870 | slChooserValues[index] = textChanged; |
871 | 871 | ||
872 | } | 872 | } |
873 | 873 | ||
874 | void ContactEditor::slotChooser1Change( const QString &textChanged ) { | 874 | void ContactEditor::slotChooser1Change( const QString &textChanged ) { |
875 | qWarning("ContactEditor::slotChooser1Change( %s )", textChanged.latin1()); | 875 | qWarning("ContactEditor::slotChooser1Change( %s )", textChanged.latin1()); |
876 | chooserChange( textChanged, cmbChooserField1->currentItem(), txtChooserField1, 1); | 876 | chooserChange( textChanged, cmbChooserField1->currentItem(), txtChooserField1, 1); |
877 | } | 877 | } |
878 | 878 | ||
879 | void ContactEditor::slotChooser2Change( const QString &textChanged ) { | 879 | void ContactEditor::slotChooser2Change( const QString &textChanged ) { |
880 | qWarning("ContactEditor::slotChooser2Change( %s )", textChanged.latin1()); | 880 | qWarning("ContactEditor::slotChooser2Change( %s )", textChanged.latin1()); |
881 | chooserChange( textChanged, cmbChooserField2->currentItem(), txtChooserField2, 2); | 881 | chooserChange( textChanged, cmbChooserField2->currentItem(), txtChooserField2, 2); |
882 | 882 | ||
883 | } | 883 | } |
884 | 884 | ||
885 | void ContactEditor::slotChooser3Change( const QString &textChanged ) { | 885 | void ContactEditor::slotChooser3Change( const QString &textChanged ) { |
886 | qWarning("ContactEditor::slotChooser3Change( %s )", textChanged.latin1()); | 886 | qWarning("ContactEditor::slotChooser3Change( %s )", textChanged.latin1()); |
887 | chooserChange( textChanged, cmbChooserField3->currentItem(), txtChooserField3, 3); | 887 | chooserChange( textChanged, cmbChooserField3->currentItem(), txtChooserField3, 3); |
888 | } | 888 | } |
889 | 889 | ||
890 | void ContactEditor::slotChooser4Change( const QString &textChanged ) { | 890 | void ContactEditor::slotChooser4Change( const QString &textChanged ) { |
891 | qWarning("ContactEditor::slotChooser4Change( %s )", textChanged.latin1()); | 891 | qWarning("ContactEditor::slotChooser4Change( %s )", textChanged.latin1()); |
892 | chooserChange( textChanged, cmbChooserField4->currentItem(), txtChooserField4, 4); | 892 | chooserChange( textChanged, cmbChooserField4->currentItem(), txtChooserField4, 4); |
893 | } | 893 | } |
894 | 894 | ||
895 | void ContactEditor::slotAddressChange( const QString &textChanged ) { | 895 | void ContactEditor::slotAddressChange( const QString &textChanged ) { |
896 | 896 | ||
897 | if ( cmbAddress->currentItem() == 0 ) { | 897 | if ( cmbAddress->currentItem() == 0 ) { |
898 | slBusinessAddress[0] = textChanged; | 898 | slBusinessAddress[0] = textChanged; |
899 | } else { | 899 | } else { |
900 | slHomeAddress[0] = textChanged; | 900 | slHomeAddress[0] = textChanged; |
901 | } | 901 | } |
902 | } | 902 | } |
903 | 903 | ||
904 | void ContactEditor::slotAddress2Change( const QString &textChanged ) { | 904 | void ContactEditor::slotAddress2Change( const QString &textChanged ) { |
905 | 905 | ||
906 | if ( cmbAddress->currentItem() == 0 ) { | 906 | if ( cmbAddress->currentItem() == 0 ) { |
907 | slBusinessAddress[1] = textChanged; | 907 | slBusinessAddress[1] = textChanged; |
908 | } else { | 908 | } else { |
909 | slHomeAddress[1] = textChanged; | 909 | slHomeAddress[1] = textChanged; |
910 | } | 910 | } |
911 | } | 911 | } |
912 | 912 | ||
913 | void ContactEditor::slotPOBoxChange( const QString &textChanged ) { | 913 | void ContactEditor::slotPOBoxChange( const QString &textChanged ) { |
914 | 914 | ||
915 | if ( cmbAddress->currentItem() == 0 ) { | 915 | if ( cmbAddress->currentItem() == 0 ) { |
916 | slBusinessAddress[2] = textChanged; | 916 | slBusinessAddress[2] = textChanged; |
917 | } else { | 917 | } else { |
918 | slHomeAddress[2] = textChanged; | 918 | slHomeAddress[2] = textChanged; |
919 | } | 919 | } |
920 | } | 920 | } |
921 | 921 | ||
922 | void ContactEditor::slotCityChange( const QString &textChanged ) { | 922 | void ContactEditor::slotCityChange( const QString &textChanged ) { |
923 | 923 | ||
924 | if ( cmbAddress->currentItem() == 0 ) { | 924 | if ( cmbAddress->currentItem() == 0 ) { |
925 | slBusinessAddress[3] = textChanged; | 925 | slBusinessAddress[3] = textChanged; |
926 | } else { | 926 | } else { |
927 | slHomeAddress[3] = textChanged; | 927 | slHomeAddress[3] = textChanged; |
928 | } | 928 | } |
929 | } | 929 | } |
930 | 930 | ||
931 | void ContactEditor::slotStateChange( const QString &textChanged ) { | 931 | void ContactEditor::slotStateChange( const QString &textChanged ) { |
932 | 932 | ||
933 | 933 | ||
934 | if ( cmbAddress->currentItem() == 0 ) { | 934 | if ( cmbAddress->currentItem() == 0 ) { |
935 | slBusinessAddress[4] = textChanged; | 935 | slBusinessAddress[4] = textChanged; |
936 | } else { | 936 | } else { |
937 | slHomeAddress[4] = textChanged; | 937 | slHomeAddress[4] = textChanged; |
938 | } | 938 | } |
939 | } | 939 | } |
940 | 940 | ||
941 | void ContactEditor::slotZipChange( const QString &textChanged ) { | 941 | void ContactEditor::slotZipChange( const QString &textChanged ) { |
942 | 942 | ||
943 | if ( cmbAddress->currentItem() == 0 ) { | 943 | if ( cmbAddress->currentItem() == 0 ) { |
944 | slBusinessAddress[5] = textChanged; | 944 | slBusinessAddress[5] = textChanged; |
945 | } else { | 945 | } else { |
946 | slHomeAddress[5] = textChanged; | 946 | slHomeAddress[5] = textChanged; |
947 | } | 947 | } |
948 | } | 948 | } |
949 | 949 | ||
950 | void ContactEditor::slotCountryChange( const QString &textChanged ) { | 950 | void ContactEditor::slotCountryChange( const QString &textChanged ) { |
951 | 951 | ||
952 | if ( cmbAddress->currentItem() == 0 ) { | 952 | if ( cmbAddress->currentItem() == 0 ) { |
953 | slBusinessAddress[6] = textChanged; | 953 | slBusinessAddress[6] = textChanged; |
954 | } else { | 954 | } else { |
955 | slHomeAddress[6] = textChanged; | 955 | slHomeAddress[6] = textChanged; |
956 | } | 956 | } |
957 | } | 957 | } |
958 | 958 | ||
959 | 959 | ||
960 | void ContactEditor::slotCmbChooser1Change( int index ) { | 960 | void ContactEditor::slotCmbChooser1Change( int index ) { |
961 | qWarning("ContactEditor::slotCmbChooser1Change( %d )", index); | 961 | qWarning("ContactEditor::slotCmbChooser1Change( %d )", index); |
962 | if ( !cmbChooserChange( cmbChooserField1->currentItem(), m_widgetStack1, 1) ){ | 962 | if ( !cmbChooserChange( cmbChooserField1->currentItem(), m_widgetStack1, 1) ){ |
963 | 963 | ||
964 | txtChooserField1->setText( slChooserValues[index] ); | 964 | txtChooserField1->setText( slChooserValues[index] ); |
965 | txtChooserField1->setFocus(); | 965 | txtChooserField1->setFocus(); |
966 | 966 | ||
967 | } | 967 | } |
968 | 968 | ||
969 | } | 969 | } |
970 | 970 | ||
971 | void ContactEditor::slotCmbChooser2Change( int index ) { | 971 | void ContactEditor::slotCmbChooser2Change( int index ) { |
972 | qWarning("ContactEditor::slotCmbChooser2Change( %d )", index); | 972 | qWarning("ContactEditor::slotCmbChooser2Change( %d )", index); |
973 | 973 | ||
974 | if ( !cmbChooserChange( cmbChooserField2->currentItem(), m_widgetStack2, 2) ){ | 974 | if ( !cmbChooserChange( cmbChooserField2->currentItem(), m_widgetStack2, 2) ){ |
975 | 975 | ||
976 | txtChooserField2->setText( slChooserValues[index] ); | 976 | txtChooserField2->setText( slChooserValues[index] ); |
977 | txtChooserField2->setFocus(); | 977 | txtChooserField2->setFocus(); |
978 | 978 | ||
979 | } | 979 | } |
980 | } | 980 | } |
981 | 981 | ||
982 | void ContactEditor::slotCmbChooser3Change( int index ) { | 982 | void ContactEditor::slotCmbChooser3Change( int index ) { |
983 | qWarning("ContactEditor::slotCmbChooser3Change( %d )", index); | 983 | qWarning("ContactEditor::slotCmbChooser3Change( %d )", index); |
984 | 984 | ||
985 | if ( !cmbChooserChange( cmbChooserField3->currentItem(), m_widgetStack3, 3) ){ | 985 | if ( !cmbChooserChange( cmbChooserField3->currentItem(), m_widgetStack3, 3) ){ |
986 | 986 | ||
987 | txtChooserField3->setText( slChooserValues[index] ); | 987 | txtChooserField3->setText( slChooserValues[index] ); |
988 | txtChooserField3->setFocus(); | 988 | txtChooserField3->setFocus(); |
989 | 989 | ||
990 | } | 990 | } |
991 | } | 991 | } |
992 | 992 | ||
993 | void ContactEditor::slotCmbChooser4Change( int index ) { | 993 | void ContactEditor::slotCmbChooser4Change( int index ) { |
994 | qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); | 994 | qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); |
995 | 995 | ||
996 | if ( !cmbChooserChange( cmbChooserField4->currentItem(), m_widgetStack4, 4) ){ | 996 | if ( !cmbChooserChange( cmbChooserField4->currentItem(), m_widgetStack4, 4) ){ |
997 | 997 | ||
998 | txtChooserField4->setText( slChooserValues[index] ); | 998 | txtChooserField4->setText( slChooserValues[index] ); |
999 | txtChooserField4->setFocus(); | 999 | txtChooserField4->setFocus(); |
1000 | 1000 | ||
1001 | } | 1001 | } |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | void ContactEditor::slotAddressTypeChange( int index ) { | 1004 | void ContactEditor::slotAddressTypeChange( int index ) { |
1005 | 1005 | ||
1006 | 1006 | ||
1007 | if ( !initializing ) | 1007 | if ( !initializing ) |
1008 | contactfields.setFieldOrder( 4, index ); | 1008 | contactfields.setFieldOrder( 4, index ); |
1009 | 1009 | ||
1010 | 1010 | ||
1011 | if ( index == 0 ) { | 1011 | if ( index == 0 ) { |
1012 | 1012 | ||
1013 | txtAddress->setText( slBusinessAddress[0] ); | 1013 | txtAddress->setText( slBusinessAddress[0] ); |
1014 | //txtAddress2->setText( (*slBusinessAddress)[1] ); | 1014 | //txtAddress2->setText( (*slBusinessAddress)[1] ); |
1015 | //txtPOBox->setText( (*slBusinessAddress)[2] ); | 1015 | //txtPOBox->setText( (*slBusinessAddress)[2] ); |
1016 | txtCity->setText( slBusinessAddress[3] ); | 1016 | txtCity->setText( slBusinessAddress[3] ); |
1017 | txtState->setText( slBusinessAddress[4] ); | 1017 | txtState->setText( slBusinessAddress[4] ); |
1018 | txtZip->setText( slBusinessAddress[5] ); | 1018 | txtZip->setText( slBusinessAddress[5] ); |
1019 | QLineEdit *txtTmp = cmbCountry->lineEdit(); | 1019 | QLineEdit *txtTmp = cmbCountry->lineEdit(); |
1020 | txtTmp->setText( slBusinessAddress[6] ); | 1020 | txtTmp->setText( slBusinessAddress[6] ); |
1021 | 1021 | ||
1022 | } else { | 1022 | } else { |
1023 | 1023 | ||
1024 | txtAddress->setText( slHomeAddress[0] ); | 1024 | txtAddress->setText( slHomeAddress[0] ); |
1025 | //txtAddress2->setText( (*slHomeAddress)[1] ); | 1025 | //txtAddress2->setText( (*slHomeAddress)[1] ); |
1026 | //txtPOBox->setText( (*slHomeAddress)[2] ); | 1026 | //txtPOBox->setText( (*slHomeAddress)[2] ); |
1027 | txtCity->setText( slHomeAddress[3] ); | 1027 | txtCity->setText( slHomeAddress[3] ); |
1028 | txtState->setText( slHomeAddress[4] ); | 1028 | txtState->setText( slHomeAddress[4] ); |
1029 | txtZip->setText( slHomeAddress[5] ); | 1029 | txtZip->setText( slHomeAddress[5] ); |
1030 | QLineEdit *txtTmp = cmbCountry->lineEdit(); | 1030 | QLineEdit *txtTmp = cmbCountry->lineEdit(); |
1031 | txtTmp->setText( slHomeAddress[6] ); | 1031 | txtTmp->setText( slHomeAddress[6] ); |
1032 | 1032 | ||
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | } | 1035 | } |
1036 | 1036 | ||
1037 | void ContactEditor::slotFullNameChange( const QString &textChanged ) { | 1037 | void ContactEditor::slotFullNameChange( const QString &textChanged ) { |
1038 | 1038 | ||
1039 | qWarning( "ContactEditor::slotFullNameChange( %s )", textChanged.latin1() ); | 1039 | qWarning( "ContactEditor::slotFullNameChange( %s )", textChanged.latin1() ); |
1040 | 1040 | ||
1041 | int index = cmbFileAs->currentItem(); | 1041 | int index = cmbFileAs->currentItem(); |
1042 | 1042 | ||
1043 | cmbFileAs->clear(); | 1043 | cmbFileAs->clear(); |
1044 | 1044 | ||
1045 | cmbFileAs->insertItem( parseName( textChanged, NAME_LF ) ); | 1045 | cmbFileAs->insertItem( parseName( textChanged, NAME_LF ) ); |
1046 | cmbFileAs->insertItem( parseName( textChanged, NAME_LFM ) ); | 1046 | cmbFileAs->insertItem( parseName( textChanged, NAME_LFM ) ); |
1047 | cmbFileAs->insertItem( parseName( textChanged, NAME_FL ) ); | 1047 | cmbFileAs->insertItem( parseName( textChanged, NAME_FL ) ); |
1048 | cmbFileAs->insertItem( parseName( textChanged, NAME_FML ) ); | 1048 | cmbFileAs->insertItem( parseName( textChanged, NAME_FML ) ); |
1049 | if ( ! txtSuffix->text().isEmpty() ) | 1049 | if ( ! txtSuffix->text().isEmpty() ) |
1050 | cmbFileAs->insertItem( parseName( textChanged, NAME_FML ) + " " + txtSuffix->text() ); | 1050 | cmbFileAs->insertItem( parseName( textChanged, NAME_FML ) + " " + txtSuffix->text() ); |
1051 | 1051 | ||
1052 | cmbFileAs->setCurrentItem( index ); | 1052 | cmbFileAs->setCurrentItem( index ); |
1053 | 1053 | ||
1054 | 1054 | ||
1055 | } | 1055 | } |
1056 | 1056 | ||
1057 | void ContactEditor::slotSuffixChange( const QString& ) { | 1057 | void ContactEditor::slotSuffixChange( const QString& ) { |
1058 | // Just want to update the FileAs combo if the suffix was changed.. | 1058 | // Just want to update the FileAs combo if the suffix was changed.. |
1059 | slotFullNameChange( txtFullName->text() ); | 1059 | slotFullNameChange( txtFullName->text() ); |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | void ContactEditor::slotOrganizationChange( const QString &textChanged ){ | 1062 | void ContactEditor::slotOrganizationChange( const QString &textChanged ){ |
1063 | qWarning( "ContactEditor::slotOrganizationChange( %s )", textChanged.latin1() ); | 1063 | qWarning( "ContactEditor::slotOrganizationChange( %s )", textChanged.latin1() ); |
1064 | // Special handling for storing Companies: | 1064 | // Special handling for storing Companies: |
1065 | // If no Fullname is given, we store the Company-Name as lastname | 1065 | // If no Fullname is given, we store the Company-Name as lastname |
1066 | // to handle it like a person.. | 1066 | // to handle it like a person.. |
1067 | if ( txtFullName->text() == txtOrganization->text().left( txtFullName->text().length() ) ) | 1067 | if ( txtFullName->text() == txtOrganization->text().left( txtFullName->text().length() ) ) |
1068 | txtFullName->setText( textChanged ); | 1068 | txtFullName->setText( textChanged ); |
1069 | 1069 | ||
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | void ContactEditor::accept() { | 1072 | void ContactEditor::accept() { |
1073 | 1073 | ||
1074 | if ( isEmpty() ) { | 1074 | if ( isEmpty() ) { |
1075 | cleanupFields(); | 1075 | cleanupFields(); |
1076 | reject(); | 1076 | reject(); |
1077 | } else { | 1077 | } else { |
1078 | saveEntry(); | 1078 | saveEntry(); |
1079 | cleanupFields(); | 1079 | cleanupFields(); |
1080 | QDialog::accept(); | 1080 | QDialog::accept(); |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | void ContactEditor::slotNote() { | 1085 | void ContactEditor::slotNote() { |
1086 | 1086 | ||
1087 | dlgNote->showMaximized(); | 1087 | dlgNote->showMaximized(); |
1088 | if ( !dlgNote->exec() ) { | 1088 | if ( !dlgNote->exec() ) { |
1089 | txtNote->setText( ent.notes() ); | 1089 | txtNote->setText( ent.notes() ); |
1090 | } | 1090 | } |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | void ContactEditor::slotName() { | 1093 | void ContactEditor::slotName() { |
1094 | 1094 | ||
1095 | QString tmpName; | 1095 | QString tmpName; |
1096 | 1096 | ||
1097 | txtFirstName->setText( parseName(txtFullName->text(), NAME_F) ); | 1097 | txtFirstName->setText( parseName(txtFullName->text(), NAME_F) ); |
1098 | txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) ); | 1098 | txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) ); |
1099 | txtLastName->setText( parseName(txtFullName->text(), NAME_L) ); | 1099 | txtLastName->setText( parseName(txtFullName->text(), NAME_L) ); |
1100 | // txtSuffix->setText( parseName(txtFullName->text(), NAME_S) ); | 1100 | // txtSuffix->setText( parseName(txtFullName->text(), NAME_S) ); |
1101 | 1101 | ||
1102 | dlgName->showMaximized(); | 1102 | dlgName->showMaximized(); |
1103 | if ( dlgName->exec() ) { | 1103 | if ( dlgName->exec() ) { |
1104 | if ( txtLastName->text().contains( ' ', TRUE ) ) | 1104 | if ( txtLastName->text().contains( ' ', TRUE ) ) |
1105 | tmpName = txtLastName->text() + ", " + txtFirstName->text() + " " + txtMiddleName->text(); | 1105 | tmpName = txtLastName->text() + ", " + txtFirstName->text() + " " + txtMiddleName->text(); |
1106 | else | 1106 | else |
1107 | tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text(); | 1107 | tmpName = txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text(); |
1108 | 1108 | ||
1109 | txtFullName->setText( tmpName.simplifyWhiteSpace() ); | 1109 | txtFullName->setText( tmpName.simplifyWhiteSpace() ); |
1110 | slotFullNameChange( txtFullName->text() ); | 1110 | slotFullNameChange( txtFullName->text() ); |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | void ContactEditor::setNameFocus() { | 1115 | void ContactEditor::setNameFocus() { |
1116 | 1116 | ||
1117 | txtFullName->setFocus(); | 1117 | txtFullName->setFocus(); |
1118 | 1118 | ||
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | bool ContactEditor::isEmpty() { | 1121 | bool ContactEditor::isEmpty() { |
1122 | // Test and see if the record should be saved. | 1122 | // Test and see if the record should be saved. |
1123 | // More strict than the original qtopia, needs name or fileas to save | 1123 | // More strict than the original qtopia, needs name or fileas to save |
1124 | 1124 | ||
1125 | QString t = txtFullName->text(); | 1125 | QString t = txtFullName->text(); |
1126 | if ( !t.isEmpty() && containsAlphaNum( t ) ) | 1126 | if ( !t.isEmpty() && containsAlphaNum( t ) ) |
1127 | return false; | 1127 | return false; |
1128 | 1128 | ||
1129 | t = cmbFileAs->currentText(); | 1129 | t = cmbFileAs->currentText(); |
1130 | if ( !t.isEmpty() && containsAlphaNum( t ) ) | 1130 | if ( !t.isEmpty() && containsAlphaNum( t ) ) |
1131 | return false; | 1131 | return false; |
1132 | 1132 | ||
1133 | return true; | 1133 | return true; |
1134 | 1134 | ||
1135 | } | 1135 | } |
1136 | 1136 | ||
1137 | QString ContactEditor::parseName( const QString fullName, int type ) { | 1137 | QString ContactEditor::parseName( const QString fullName, int type ) { |
1138 | 1138 | ||
1139 | QString simplifiedName( fullName.simplifyWhiteSpace() ); | 1139 | QString simplifiedName( fullName.simplifyWhiteSpace() ); |
1140 | QString strFirstName; | 1140 | QString strFirstName; |
1141 | QString strMiddleName; | 1141 | QString strMiddleName; |
1142 | QString strLastName; | 1142 | QString strLastName; |
1143 | QString strTitle; | 1143 | QString strTitle; |
1144 | int commapos; | 1144 | int commapos; |
1145 | bool haveLastName = false; | 1145 | bool haveLastName = false; |
1146 | 1146 | ||
1147 | qWarning("Fullname: %s", simplifiedName.latin1()); | 1147 | qWarning("Fullname: %s", simplifiedName.latin1()); |
1148 | 1148 | ||
1149 | commapos = simplifiedName.find( ',', 0, TRUE); | 1149 | commapos = simplifiedName.find( ',', 0, TRUE); |
1150 | if ( commapos >= 0 ) { | 1150 | if ( commapos >= 0 ) { |
1151 | qWarning(" Commapos: %d", commapos ); | 1151 | qWarning(" Commapos: %d", commapos ); |
1152 | 1152 | ||
1153 | // A comma (",") separates the lastname from one or | 1153 | // A comma (",") separates the lastname from one or |
1154 | // many first names. Thus, remove the lastname from the | 1154 | // many first names. Thus, remove the lastname from the |
1155 | // String and parse the firstnames. | 1155 | // String and parse the firstnames. |
1156 | 1156 | ||
1157 | strLastName = simplifiedName.left( commapos ); | 1157 | strLastName = simplifiedName.left( commapos ); |
1158 | simplifiedName= simplifiedName.mid( commapos + 1 ); | 1158 | simplifiedName= simplifiedName.mid( commapos + 1 ); |
1159 | haveLastName = true; | 1159 | haveLastName = true; |
1160 | qWarning("Fullname without ',': %s", simplifiedName.latin1()); | 1160 | qWarning("Fullname without ',': %s", simplifiedName.latin1()); |
1161 | 1161 | ||
1162 | // If we have any lastname, we should now split all first names. | 1162 | // If we have any lastname, we should now split all first names. |
1163 | // The first one will be the used as first, the rest as "middle names" | 1163 | // The first one will be the used as first, the rest as "middle names" |
1164 | 1164 | ||
1165 | QStringList allFirstNames = QStringList::split(" ", simplifiedName); | 1165 | QStringList allFirstNames = QStringList::split(" ", simplifiedName); |
1166 | QStringList::Iterator it = allFirstNames.begin(); | 1166 | QStringList::Iterator it = allFirstNames.begin(); |
1167 | strFirstName = *it++; | 1167 | strFirstName = *it++; |
1168 | QStringList allSecondNames; | 1168 | QStringList allSecondNames; |
1169 | for ( ; it != allFirstNames.end(); ++it ) | 1169 | for ( ; it != allFirstNames.end(); ++it ) |
1170 | allSecondNames.append( *it ); | 1170 | allSecondNames.append( *it ); |
1171 | 1171 | ||
1172 | strMiddleName = allSecondNames.join(" "); | 1172 | strMiddleName = allSecondNames.join(" "); |
1173 | 1173 | ||
1174 | } else { | 1174 | } else { |
1175 | 1175 | ||
1176 | // No comma separator used: We use the first word as firstname, the | 1176 | // No comma separator used: We use the first word as firstname, the |
1177 | // last as second/lastname and everything in the middle as middlename | 1177 | // last as second/lastname and everything in the middle as middlename |
1178 | 1178 | ||
1179 | QStringList allNames = QStringList::split(" ", simplifiedName); | 1179 | QStringList allNames = QStringList::split(" ", simplifiedName); |
1180 | QStringList::Iterator it = allNames.begin(); | 1180 | QStringList::Iterator it = allNames.begin(); |
1181 | strFirstName = *it++; | 1181 | strFirstName = *it++; |
1182 | QStringList allSecondNames; | 1182 | QStringList allSecondNames; |
1183 | for ( ; it != --allNames.end(); ++it ) | 1183 | for ( ; it != --allNames.end(); ++it ) |
1184 | allSecondNames.append( *it ); | 1184 | allSecondNames.append( *it ); |
1185 | 1185 | ||
1186 | strMiddleName = allSecondNames.join(" "); | 1186 | strMiddleName = allSecondNames.join(" "); |
1187 | strLastName = *(--allNames.end()); | 1187 | strLastName = *(--allNames.end()); |
1188 | 1188 | ||
1189 | } | 1189 | } |
1190 | 1190 | ||
1191 | if ( strFirstName == strLastName ) | 1191 | if ( strFirstName == strLastName ) |
1192 | strFirstName = ""; | 1192 | strFirstName = ""; |
1193 | 1193 | ||
1194 | qWarning(" strFirstName: %s", strFirstName.latin1()); | 1194 | qWarning(" strFirstName: %s", strFirstName.latin1()); |
1195 | qWarning(" strMiddleName: %s", strMiddleName.latin1()); | 1195 | qWarning(" strMiddleName: %s", strMiddleName.latin1()); |
1196 | qWarning(" strLastName: %s", strLastName.latin1()); | 1196 | qWarning(" strLastName: %s", strLastName.latin1()); |
1197 | qWarning(" strTitle: %s", strTitle.latin1()); | 1197 | qWarning(" strTitle: %s", strTitle.latin1()); |
1198 | 1198 | ||
1199 | switch (type) { | 1199 | switch (type) { |
1200 | case NAME_FL: | 1200 | case NAME_FL: |
1201 | return strFirstName + " " + strLastName; | 1201 | return strFirstName + " " + strLastName; |
1202 | 1202 | ||
1203 | case NAME_LF: | 1203 | case NAME_LF: |
1204 | return strLastName + ", " + strFirstName; | 1204 | return strLastName + ", " + strFirstName; |
1205 | 1205 | ||
1206 | case NAME_LFM: | 1206 | case NAME_LFM: |
1207 | return strLastName + ", " + strFirstName + " " + strMiddleName; | 1207 | return strLastName + ", " + strFirstName + " " + strMiddleName; |
1208 | 1208 | ||
1209 | case NAME_FML: | 1209 | case NAME_FML: |
1210 | return strFirstName + " " + strMiddleName + " " + strLastName ; | 1210 | return strFirstName + " " + strMiddleName + " " + strLastName ; |
1211 | 1211 | ||
1212 | case NAME_F: | 1212 | case NAME_F: |
1213 | return strFirstName; | 1213 | return strFirstName; |
1214 | 1214 | ||
1215 | case NAME_M: | 1215 | case NAME_M: |
1216 | return strMiddleName; | 1216 | return strMiddleName; |
1217 | 1217 | ||
1218 | case NAME_L: | 1218 | case NAME_L: |
1219 | return strLastName; | 1219 | return strLastName; |
1220 | 1220 | ||
1221 | case NAME_S: | 1221 | case NAME_S: |
1222 | return txtSuffix->text(); | 1222 | return txtSuffix->text(); |
1223 | 1223 | ||
1224 | } | 1224 | } |
1225 | return QString::null; | 1225 | return QString::null; |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | void ContactEditor::cleanupFields() { | 1228 | void ContactEditor::cleanupFields() { |
1229 | QStringList::Iterator it = slChooserValues.begin(); | 1229 | QStringList::Iterator it = slChooserValues.begin(); |
1230 | 1230 | ||
1231 | for ( int i = 0; it != slChooserValues.end(); i++, ++it ) { | 1231 | for ( int i = 0; it != slChooserValues.end(); i++, ++it ) { |
1232 | (*it) = ""; | 1232 | (*it) = ""; |
1233 | } | 1233 | } |
1234 | 1234 | ||
1235 | for ( int i = 0; i < 7; i++ ) { | 1235 | for ( int i = 0; i < 7; i++ ) { |
1236 | slHomeAddress[i] = ""; | 1236 | slHomeAddress[i] = ""; |
1237 | slBusinessAddress[i] = ""; | 1237 | slBusinessAddress[i] = ""; |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | QListIterator<QLineEdit> itLV( listValue ); | 1240 | QListIterator<QLineEdit> itLV( listValue ); |
1241 | for ( ; itLV.current(); ++itLV ) { | 1241 | for ( ; itLV.current(); ++itLV ) { |
1242 | (*itLV)->setText( "" ); | 1242 | (*itLV)->setText( "" ); |
1243 | } | 1243 | } |
1244 | 1244 | ||
1245 | txtFirstName->setText(""); | 1245 | txtFirstName->setText(""); |
1246 | txtMiddleName->setText(""); | 1246 | txtMiddleName->setText(""); |
1247 | txtLastName->setText(""); | 1247 | txtLastName->setText(""); |
1248 | txtSuffix->setText(""); | 1248 | txtSuffix->setText(""); |
1249 | txtNote->setText(""); | 1249 | txtNote->setText(""); |
1250 | txtFullName->setText(""); | 1250 | txtFullName->setText(""); |
1251 | txtJobTitle->setText(""); | 1251 | txtJobTitle->setText(""); |
1252 | txtOrganization->setText(""); | 1252 | txtOrganization->setText(""); |
1253 | txtChooserField1->setText(""); | 1253 | txtChooserField1->setText(""); |
1254 | txtChooserField2->setText(""); | 1254 | txtChooserField2->setText(""); |
1255 | txtChooserField3->setText(""); | 1255 | txtChooserField3->setText(""); |
1256 | txtAddress->setText(""); | 1256 | txtAddress->setText(""); |
1257 | txtCity->setText(""); | 1257 | txtCity->setText(""); |
1258 | txtState->setText(""); | 1258 | txtState->setText(""); |
1259 | txtZip->setText(""); | 1259 | txtZip->setText(""); |
1260 | QLineEdit *txtTmp = cmbCountry->lineEdit(); | 1260 | QLineEdit *txtTmp = cmbCountry->lineEdit(); |
1261 | txtTmp->setText(""); | 1261 | txtTmp->setText(""); |
1262 | txtTmp = cmbFileAs->lineEdit(); | 1262 | txtTmp = cmbFileAs->lineEdit(); |
1263 | txtTmp->setText(""); | 1263 | txtTmp->setText(""); |
1264 | 1264 | ||
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | void ContactEditor::setEntry( const OContact &entry ) { | 1267 | void ContactEditor::setEntry( const OContact &entry ) { |
1268 | 1268 | ||
1269 | initializing = true; | 1269 | initializing = true; |
1270 | 1270 | ||
1271 | // Cleanup and activate the general Page .. | 1271 | // Cleanup and activate the general Page .. |
1272 | cleanupFields(); | 1272 | cleanupFields(); |
1273 | tabMain->setCurrentPage( 0 ); | 1273 | tabMain->setCurrentPage( 0 ); |
1274 | 1274 | ||
1275 | ent = entry; | 1275 | ent = entry; |
1276 | 1276 | ||
1277 | emails = QStringList(ent.emailList()); | 1277 | emails = QStringList(ent.emailList()); |
1278 | defaultEmail = ent.defaultEmail(); | 1278 | defaultEmail = ent.defaultEmail(); |
1279 | if (defaultEmail.isEmpty()) defaultEmail = emails[0]; | 1279 | if (defaultEmail.isEmpty()) defaultEmail = emails[0]; |
1280 | qDebug("default email=%s",defaultEmail.latin1()); | 1280 | qDebug("default email=%s",defaultEmail.latin1()); |
1281 | 1281 | ||
1282 | txtFirstName->setText( ent.firstName() ); | 1282 | txtFirstName->setText( ent.firstName() ); |
1283 | txtMiddleName->setText( ent.middleName() ); | 1283 | txtMiddleName->setText( ent.middleName() ); |
1284 | txtLastName->setText( ent.lastName() ); | 1284 | txtLastName->setText( ent.lastName() ); |
1285 | txtSuffix->setText( ent.suffix() ); | 1285 | txtSuffix->setText( ent.suffix() ); |
1286 | 1286 | ||
1287 | // QString *tmpString = new QString; | 1287 | // QString *tmpString = new QString; |
1288 | // *tmpString = ent.firstName() + " " + ent.middleName() + | 1288 | // *tmpString = ent.firstName() + " " + ent.middleName() + |
1289 | // + " " + ent.lastName() + " " + ent.suffix(); | 1289 | // + " " + ent.lastName() + " " + ent.suffix(); |
1290 | //txtFullName->setText( tmpString->simplifyWhiteSpace() ); | 1290 | //txtFullName->setText( tmpString->simplifyWhiteSpace() ); |
1291 | 1291 | ||
1292 | if ( !ent.isEmpty() ){ | 1292 | if ( !ent.isEmpty() ){ |
1293 | // Lastnames with multiple words need to be protected by a comma ! | 1293 | // Lastnames with multiple words need to be protected by a comma ! |
1294 | if ( ent.lastName().contains( ' ', TRUE ) ) | 1294 | if ( ent.lastName().contains( ' ', TRUE ) ) |
1295 | txtFullName->setText( ent.lastName() + ", " + ent.firstName() + " " + ent.middleName() ); | 1295 | txtFullName->setText( ent.lastName() + ", " + ent.firstName() + " " + ent.middleName() ); |
1296 | else | 1296 | else |
1297 | txtFullName->setText( ent.firstName() + " " + ent.middleName() + " " + ent.lastName() ); | 1297 | txtFullName->setText( ent.firstName() + " " + ent.middleName() + " " + ent.lastName() ); |
1298 | } | 1298 | } |
1299 | 1299 | ||
1300 | cmbFileAs->setEditText( ent.fileAs() ); | 1300 | cmbFileAs->setEditText( ent.fileAs() ); |
1301 | 1301 | ||
1302 | //if (hasTitle) | 1302 | //if (hasTitle) |
1303 | txtJobTitle->setText( ent.jobTitle() ); | 1303 | txtJobTitle->setText( ent.jobTitle() ); |
1304 | 1304 | ||
1305 | //if (hasCompany) | 1305 | //if (hasCompany) |
1306 | txtOrganization->setText( ent.company() ); | 1306 | txtOrganization->setText( ent.company() ); |
1307 | 1307 | ||
1308 | //if (hasNotes) | 1308 | //if (hasNotes) |
1309 | txtNote->setText( ent.notes() ); | 1309 | txtNote->setText( ent.notes() ); |
1310 | 1310 | ||
1311 | //if (hasStreet) { | 1311 | //if (hasStreet) { |
1312 | slHomeAddress[0] = ent.homeStreet(); | 1312 | slHomeAddress[0] = ent.homeStreet(); |
1313 | slBusinessAddress[0] = ent.businessStreet(); | 1313 | slBusinessAddress[0] = ent.businessStreet(); |
1314 | //} | 1314 | //} |
1315 | 1315 | ||
1316 | //if (hasCity) { | 1316 | //if (hasCity) { |
1317 | slHomeAddress[3] = ent.homeCity(); | 1317 | slHomeAddress[3] = ent.homeCity(); |
1318 | slBusinessAddress[3] = ent.businessCity(); | 1318 | slBusinessAddress[3] = ent.businessCity(); |
1319 | //} | 1319 | //} |
1320 | 1320 | ||
1321 | //if (hasState) { | 1321 | //if (hasState) { |
1322 | slHomeAddress[4] = ent.homeState(); | 1322 | slHomeAddress[4] = ent.homeState(); |
1323 | slBusinessAddress[4] = ent.businessState(); | 1323 | slBusinessAddress[4] = ent.businessState(); |
1324 | //} | 1324 | //} |
1325 | 1325 | ||
1326 | //if (hasZip) { | 1326 | //if (hasZip) { |
1327 | slHomeAddress[5] = ent.homeZip(); | 1327 | slHomeAddress[5] = ent.homeZip(); |
1328 | slBusinessAddress[5] = ent.businessZip(); | 1328 | slBusinessAddress[5] = ent.businessZip(); |
1329 | //} | 1329 | //} |
1330 | 1330 | ||
1331 | //if (hasCountry) { | 1331 | //if (hasCountry) { |
1332 | slHomeAddress[6] = ent.homeCountry(); | 1332 | slHomeAddress[6] = ent.homeCountry(); |
1333 | slBusinessAddress[6] = ent.businessCountry(); | 1333 | slBusinessAddress[6] = ent.businessCountry(); |
1334 | //} | 1334 | //} |
1335 | 1335 | ||
1336 | QStringList::ConstIterator it; | 1336 | QStringList::ConstIterator it; |
1337 | QListIterator<QLineEdit> itLE( listValue ); | 1337 | QListIterator<QLineEdit> itLE( listValue ); |
1338 | for ( it = slDynamicEntries.begin(); itLE.current()/* != slDynamicEntries.end()*/; ++it, ++itLE) { | 1338 | for ( it = slDynamicEntries.begin(); itLE.current()/* != slDynamicEntries.end()*/; ++it, ++itLE) { |
1339 | 1339 | ||
1340 | qWarning(" Filling dynamic Field: %s", (*it).latin1() ); | 1340 | qWarning(" Filling dynamic Field: %s", (*it).latin1() ); |
1341 | 1341 | ||
1342 | if ( *it == "Department" ) | 1342 | if ( *it == "Department" ) |
1343 | (*itLE)->setText( ent.department() ); | 1343 | (*itLE)->setText( ent.department() ); |
1344 | 1344 | ||
1345 | if ( *it == "Company" ) | 1345 | if ( *it == "Company" ) |
1346 | (*itLE)->setText( ent.company() ); | 1346 | (*itLE)->setText( ent.company() ); |
1347 | 1347 | ||
1348 | if ( *it == "Office" ) | 1348 | if ( *it == "Office" ) |
1349 | (*itLE)->setText( ent.office() ); | 1349 | (*itLE)->setText( ent.office() ); |
1350 | 1350 | ||
1351 | if ( *it == "Profession" ) | 1351 | if ( *it == "Profession" ) |
1352 | (*itLE)->setText( ent.profession() ); | 1352 | (*itLE)->setText( ent.profession() ); |
1353 | 1353 | ||
1354 | if ( *it == "Assistant" ) | 1354 | if ( *it == "Assistant" ) |
1355 | (*itLE)->setText( ent.assistant() ); | 1355 | (*itLE)->setText( ent.assistant() ); |
1356 | 1356 | ||
1357 | if ( *it == "Manager" ) | 1357 | if ( *it == "Manager" ) |
1358 | (*itLE)->setText( ent.manager() ); | 1358 | (*itLE)->setText( ent.manager() ); |
1359 | 1359 | ||
1360 | if ( *it == "Spouse" ) | 1360 | if ( *it == "Spouse" ) |
1361 | (*itLE)->setText( ent.spouse() ); | 1361 | (*itLE)->setText( ent.spouse() ); |
1362 | 1362 | ||
1363 | if ( *it == "Nickname" ){ | 1363 | if ( *it == "Nickname" ){ |
1364 | qWarning("**** Nichname: %s", ent.nickname().latin1() ); | 1364 | qWarning("**** Nichname: %s", ent.nickname().latin1() ); |
1365 | (*itLE)->setText( ent.nickname() ); | 1365 | (*itLE)->setText( ent.nickname() ); |
1366 | } | 1366 | } |
1367 | 1367 | ||
1368 | if ( *it == "Children" ) | 1368 | if ( *it == "Children" ) |
1369 | (*itLE)->setText( ent.children() ); | 1369 | (*itLE)->setText( ent.children() ); |
1370 | 1370 | ||
1371 | } | 1371 | } |
1372 | 1372 | ||
1373 | QStringList::Iterator itV; | 1373 | QStringList::Iterator itV; |
1374 | for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) { | 1374 | for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) { |
1375 | 1375 | ||
1376 | if ( ( *it == "Business Phone") || ( *it == "Work Phone" ) ) | 1376 | if ( ( *it == "Business Phone") || ( *it == "Work Phone" ) ) |
1377 | *itV = ent.businessPhone(); | 1377 | *itV = ent.businessPhone(); |
1378 | /* | 1378 | /* |
1379 | if ( *it == "Business 2 Phone" ) | 1379 | if ( *it == "Business 2 Phone" ) |
1380 | *itV = ent.business2Phone(); | 1380 | *itV = ent.business2Phone(); |
1381 | */ | 1381 | */ |
1382 | if ( ( *it == "Business Fax") || ( *it == "Work Fax" ) ) | 1382 | if ( ( *it == "Business Fax") || ( *it == "Work Fax" ) ) |
1383 | *itV = ent.businessFax(); | 1383 | *itV = ent.businessFax(); |
1384 | 1384 | ||
1385 | if ( ( *it == "Business Mobile" ) || ( *it == "work Mobile" ) ) | 1385 | if ( ( *it == "Business Mobile" ) || ( *it == "work Mobile" ) ) |
1386 | *itV = ent.businessMobile(); | 1386 | *itV = ent.businessMobile(); |
1387 | /* | 1387 | /* |
1388 | if ( *it == "Company Phone" ) | 1388 | if ( *it == "Company Phone" ) |
1389 | *itV = ent.companyPhone(); | 1389 | *itV = ent.companyPhone(); |
1390 | */ | 1390 | */ |
1391 | if ( *it == "Default Email" ) | 1391 | if ( *it == "Default Email" ) |
1392 | *itV = ent.defaultEmail(); | 1392 | *itV = ent.defaultEmail(); |
1393 | 1393 | ||
1394 | if ( *it == "Emails" ) | 1394 | if ( *it == "Emails" ) |
1395 | *itV = ent.emailList().join(", "); // :SX | 1395 | *itV = ent.emailList().join(", "); // :SX |
1396 | 1396 | ||
1397 | if ( *it == "Home Phone" ) | 1397 | if ( *it == "Home Phone" ) |
1398 | *itV = ent.homePhone(); | 1398 | *itV = ent.homePhone(); |
1399 | /* | 1399 | /* |
1400 | if ( *it == "Home 2 Phone" ) | 1400 | if ( *it == "Home 2 Phone" ) |
1401 | *itV = ent.home2Phone(); | 1401 | *itV = ent.home2Phone(); |
1402 | */ | 1402 | */ |
1403 | if ( *it == "Home Fax" ) | 1403 | if ( *it == "Home Fax" ) |
1404 | *itV = ent.homeFax(); | 1404 | *itV = ent.homeFax(); |
1405 | 1405 | ||
1406 | if ( *it == "Home Mobile" ) | 1406 | if ( *it == "Home Mobile" ) |
1407 | *itV = ent.homeMobile(); | 1407 | *itV = ent.homeMobile(); |
1408 | /* | 1408 | /* |
1409 | if ( *it == "Car Phone" ) | 1409 | if ( *it == "Car Phone" ) |
1410 | *itV = ent.carPhone(); | 1410 | *itV = ent.carPhone(); |
1411 | 1411 | ||
1412 | if ( *it == "ISDN Phone" ) | 1412 | if ( *it == "ISDN Phone" ) |
1413 | *itV = ent.ISDNPhone(); | 1413 | *itV = ent.ISDNPhone(); |
1414 | 1414 | ||
1415 | if ( *it == "Other Phone" ) | 1415 | if ( *it == "Other Phone" ) |
1416 | *itV = ent.otherPhone(); | 1416 | *itV = ent.otherPhone(); |
1417 | */ | 1417 | */ |
1418 | if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) ) | 1418 | if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) ) |
1419 | *itV = ent.businessPager(); | 1419 | *itV = ent.businessPager(); |
1420 | /* | 1420 | /* |
1421 | if ( *it == "Home Pager") | 1421 | if ( *it == "Home Pager") |
1422 | *itV = ent.homePager(); | 1422 | *itV = ent.homePager(); |
1423 | 1423 | ||
1424 | if ( *it == "AIM IM" ) | 1424 | if ( *it == "AIM IM" ) |
1425 | *itV = ent.AIMIM(); | 1425 | *itV = ent.AIMIM(); |
1426 | 1426 | ||
1427 | if ( *it == "ICQ IM" ) | 1427 | if ( *it == "ICQ IM" ) |
1428 | *itV = ent.ICQIM(); | 1428 | *itV = ent.ICQIM(); |
1429 | 1429 | ||
1430 | if ( *it == "Jabber IM" ) | 1430 | if ( *it == "Jabber IM" ) |
1431 | *itV = ent.jabberIM(); | 1431 | *itV = ent.jabberIM(); |
1432 | 1432 | ||
1433 | if ( *it == "MSN IM" ) | 1433 | if ( *it == "MSN IM" ) |
1434 | *itV = ent.MSNIM(); | 1434 | *itV = ent.MSNIM(); |
1435 | 1435 | ||
1436 | if ( *it == "Yahoo IM" ) | 1436 | if ( *it == "Yahoo IM" ) |
1437 | *itV = ent.yahooIM(); | 1437 | *itV = ent.yahooIM(); |
1438 | */ | 1438 | */ |
1439 | if ( *it == "Home Web Page" ) | 1439 | if ( *it == "Home Web Page" ) |
1440 | *itV = ent.homeWebpage(); | 1440 | *itV = ent.homeWebpage(); |
1441 | 1441 | ||
1442 | if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) ) | 1442 | if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) ) |
1443 | *itV = ent.businessWebpage(); | 1443 | *itV = ent.businessWebpage(); |
1444 | 1444 | ||
1445 | 1445 | ||
1446 | } | 1446 | } |
1447 | 1447 | ||
1448 | 1448 | ||
1449 | cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); | 1449 | cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); |
1450 | 1450 | ||
1451 | QString gender = ent.gender(); | 1451 | QString gender = ent.gender(); |
1452 | cmbGender->setCurrentItem( gender.toInt() ); | 1452 | cmbGender->setCurrentItem( gender.toInt() ); |
1453 | 1453 | ||
1454 | txtNote->setText( ent.notes() ); | 1454 | txtNote->setText( ent.notes() ); |
1455 | 1455 | ||
1456 | slotAddressTypeChange( cmbAddress->currentItem() ); | 1456 | slotAddressTypeChange( cmbAddress->currentItem() ); |
1457 | 1457 | ||
1458 | // Get combo-settings from contact and set preset.. | 1458 | // Get combo-settings from contact and set preset.. |
1459 | contactfields.loadFromRecord( ent ); | 1459 | contactfields.loadFromRecord( ent ); |
1460 | cmbChooserField1->setCurrentItem( contactfields.getFieldOrder(0, 7) ); | 1460 | cmbChooserField1->setCurrentItem( contactfields.getFieldOrder(0, 7) ); |
1461 | cmbChooserField2->setCurrentItem( contactfields.getFieldOrder(1, 9) ); | 1461 | cmbChooserField2->setCurrentItem( contactfields.getFieldOrder(1, 9) ); |
1462 | cmbChooserField3->setCurrentItem( contactfields.getFieldOrder(2, 0) ); | 1462 | cmbChooserField3->setCurrentItem( contactfields.getFieldOrder(2, 0) ); |
1463 | cmbChooserField4->setCurrentItem( contactfields.getFieldOrder(3, 6) ); | 1463 | cmbChooserField4->setCurrentItem( contactfields.getFieldOrder(3, 6) ); |
1464 | cmbAddress->setCurrentItem( contactfields.getFieldOrder(4, 1) ); | 1464 | cmbAddress->setCurrentItem( contactfields.getFieldOrder(4, 1) ); |
1465 | slotCmbChooser1Change( cmbChooserField1->currentItem() ); | 1465 | slotCmbChooser1Change( cmbChooserField1->currentItem() ); |
1466 | slotCmbChooser2Change( cmbChooserField2->currentItem() ); | 1466 | slotCmbChooser2Change( cmbChooserField2->currentItem() ); |
1467 | slotCmbChooser3Change( cmbChooserField3->currentItem() ); | 1467 | slotCmbChooser3Change( cmbChooserField3->currentItem() ); |
1468 | slotCmbChooser4Change( cmbChooserField4->currentItem() ); | 1468 | slotCmbChooser4Change( cmbChooserField4->currentItem() ); |
1469 | slotAddressTypeChange( cmbAddress->currentItem() ); | 1469 | slotAddressTypeChange( cmbAddress->currentItem() ); |
1470 | 1470 | ||
1471 | updateDatePicker(); | 1471 | updateDatePicker(); |
1472 | 1472 | ||
1473 | initializing = false; | 1473 | initializing = false; |
1474 | } | 1474 | } |
1475 | void ContactEditor::updateDatePicker() | 1475 | void ContactEditor::updateDatePicker() |
1476 | { | 1476 | { |
1477 | // Set DatePicker | 1477 | // Set DatePicker |
1478 | if ( !ent.birthday().isNull() ){ | 1478 | if ( !ent.birthday().isNull() ){ |
1479 | birthdayButton->setText( TimeString::numberDateString( ent.birthday() ) ); | 1479 | birthdayButton->setText( TimeString::numberDateString( ent.birthday() ) ); |
1480 | birthdayPicker->setDate( ent.birthday() ); | 1480 | birthdayPicker->setDate( ent.birthday() ); |
1481 | } else | 1481 | } else |
1482 | birthdayButton->setText( tr ("Unknown") ); | 1482 | birthdayButton->setText( tr ("Unknown") ); |
1483 | 1483 | ||
1484 | if ( !ent.anniversary().isNull() ){ | 1484 | if ( !ent.anniversary().isNull() ){ |
1485 | anniversaryButton->setText( TimeString::numberDateString( ent.anniversary() ) ); | 1485 | anniversaryButton->setText( TimeString::numberDateString( ent.anniversary() ) ); |
1486 | anniversaryPicker->setDate( ent.anniversary() ); | 1486 | anniversaryPicker->setDate( ent.anniversary() ); |
1487 | } else | 1487 | } else |
1488 | anniversaryButton->setText( tr ("Unknown") ); | 1488 | anniversaryButton->setText( tr ("Unknown") ); |
1489 | 1489 | ||
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | void ContactEditor::saveEntry() { | 1492 | void ContactEditor::saveEntry() { |
1493 | 1493 | ||
1494 | // Store current combo into contact | 1494 | // Store current combo into contact |
1495 | contactfields.saveToRecord( ent ); | 1495 | contactfields.saveToRecord( ent ); |
1496 | 1496 | ||
1497 | txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) ); | 1497 | txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) ); |
1498 | txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) ); | 1498 | txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) ); |
1499 | txtLastName->setText( parseName( txtFullName->text(), NAME_L ) ); | 1499 | txtLastName->setText( parseName( txtFullName->text(), NAME_L ) ); |
1500 | // txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); | 1500 | // txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); |
1501 | 1501 | ||
1502 | ent.setFirstName( txtFirstName->text() ); | 1502 | ent.setFirstName( txtFirstName->text() ); |
1503 | ent.setLastName( txtLastName->text() ); | 1503 | ent.setLastName( txtLastName->text() ); |
1504 | ent.setMiddleName( txtMiddleName->text() ); | 1504 | ent.setMiddleName( txtMiddleName->text() ); |
1505 | ent.setSuffix( txtSuffix->text() ); | 1505 | ent.setSuffix( txtSuffix->text() ); |
1506 | 1506 | ||
1507 | ent.setFileAs( cmbFileAs->currentText() ); | 1507 | ent.setFileAs( cmbFileAs->currentText() ); |
1508 | 1508 | ||
1509 | ent.setCategories( cmbCat->currentCategories() ); | 1509 | ent.setCategories( cmbCat->currentCategories() ); |
1510 | 1510 | ||
1511 | 1511 | ||
1512 | //if (hasTitle) | 1512 | //if (hasTitle) |
1513 | ent.setJobTitle( txtJobTitle->text() ); | 1513 | ent.setJobTitle( txtJobTitle->text() ); |
1514 | 1514 | ||
1515 | //if (hasCompany) | 1515 | //if (hasCompany) |
1516 | ent.setCompany( txtOrganization->text() ); | 1516 | ent.setCompany( txtOrganization->text() ); |
1517 | 1517 | ||
1518 | //if (hasNotes) | 1518 | //if (hasNotes) |
1519 | ent.setNotes( txtNote->text() ); | 1519 | ent.setNotes( txtNote->text() ); |
1520 | 1520 | ||
1521 | //if (hasStreet) { | 1521 | //if (hasStreet) { |
1522 | ent.setHomeStreet( slHomeAddress[0] ); | 1522 | ent.setHomeStreet( slHomeAddress[0] ); |
1523 | ent.setBusinessStreet( slBusinessAddress[0] ); | 1523 | ent.setBusinessStreet( slBusinessAddress[0] ); |
1524 | //} | 1524 | //} |
1525 | 1525 | ||
1526 | //if (hasCity) { | 1526 | //if (hasCity) { |
1527 | ent.setHomeCity( slHomeAddress[3] ); | 1527 | ent.setHomeCity( slHomeAddress[3] ); |
1528 | ent.setBusinessCity( slBusinessAddress[3] ); | 1528 | ent.setBusinessCity( slBusinessAddress[3] ); |
1529 | //} | 1529 | //} |
1530 | 1530 | ||
1531 | //if (hasState) { | 1531 | //if (hasState) { |
1532 | ent.setHomeState( slHomeAddress[4] ); | 1532 | ent.setHomeState( slHomeAddress[4] ); |
1533 | ent.setBusinessState( slBusinessAddress[4] ); | 1533 | ent.setBusinessState( slBusinessAddress[4] ); |
1534 | //} | 1534 | //} |
1535 | 1535 | ||
1536 | //if (hasZip) { | 1536 | //if (hasZip) { |
1537 | ent.setHomeZip( slHomeAddress[5] ); | 1537 | ent.setHomeZip( slHomeAddress[5] ); |
1538 | ent.setBusinessZip( slBusinessAddress[5] ); | 1538 | ent.setBusinessZip( slBusinessAddress[5] ); |
1539 | //} | 1539 | //} |
1540 | 1540 | ||
1541 | //if (hasCountry) { | 1541 | //if (hasCountry) { |
1542 | ent.setHomeCountry( slHomeAddress[6] ); | 1542 | ent.setHomeCountry( slHomeAddress[6] ); |
1543 | ent.setBusinessCountry( slBusinessAddress[6] ); | 1543 | ent.setBusinessCountry( slBusinessAddress[6] ); |
1544 | //} | 1544 | //} |
1545 | 1545 | ||
1546 | QStringList::ConstIterator it; | 1546 | QStringList::ConstIterator it; |
1547 | QListIterator<QLineEdit> itLE( listValue ); | 1547 | QListIterator<QLineEdit> itLE( listValue ); |
1548 | for ( it = slDynamicEntries.begin(); itLE.current() && it != slDynamicEntries.end(); ++it, ++itLE) { | 1548 | for ( it = slDynamicEntries.begin(); itLE.current() && it != slDynamicEntries.end(); ++it, ++itLE) { |
1549 | 1549 | ||
1550 | if ( *it == "Department" ) | 1550 | if ( *it == "Department" ) |
1551 | ent.setDepartment( (*itLE)->text() ); | 1551 | ent.setDepartment( (*itLE)->text() ); |
1552 | 1552 | ||
1553 | if ( *it == "Company" ) | 1553 | if ( *it == "Company" ) |
1554 | ent.setCompany( (*itLE)->text() ); | 1554 | ent.setCompany( (*itLE)->text() ); |
1555 | 1555 | ||
1556 | if ( *it == "Office" ) | 1556 | if ( *it == "Office" ) |
1557 | ent.setOffice( (*itLE)->text() ); | 1557 | ent.setOffice( (*itLE)->text() ); |
1558 | 1558 | ||
1559 | if ( *it == "Profession" ) | 1559 | if ( *it == "Profession" ) |
1560 | ent.setProfession( (*itLE)->text() ); | 1560 | ent.setProfession( (*itLE)->text() ); |
1561 | 1561 | ||
1562 | if ( *it == "Assistant" ) | 1562 | if ( *it == "Assistant" ) |
1563 | ent.setAssistant( (*itLE)->text() ); | 1563 | ent.setAssistant( (*itLE)->text() ); |
1564 | 1564 | ||
1565 | if ( *it == "Manager" ) | 1565 | if ( *it == "Manager" ) |
1566 | ent.setManager( (*itLE)->text() ); | 1566 | ent.setManager( (*itLE)->text() ); |
1567 | 1567 | ||
1568 | if ( *it == "Spouse" ) | 1568 | if ( *it == "Spouse" ) |
1569 | ent.setSpouse( (*itLE)->text() ); | 1569 | ent.setSpouse( (*itLE)->text() ); |
1570 | 1570 | ||
1571 | if ( *it == "Nickname" ) | 1571 | if ( *it == "Nickname" ) |
1572 | ent.setNickname( (*itLE)->text() ); | 1572 | ent.setNickname( (*itLE)->text() ); |
1573 | 1573 | ||
1574 | if ( *it == "Children" ) | 1574 | if ( *it == "Children" ) |
1575 | ent.setChildren( (*itLE)->text() ); | 1575 | ent.setChildren( (*itLE)->text() ); |
1576 | 1576 | ||
1577 | } | 1577 | } |
1578 | 1578 | ||
1579 | 1579 | ||
1580 | QStringList::ConstIterator itV; | 1580 | QStringList::ConstIterator itV; |
1581 | for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) { | 1581 | for ( it = slChooserNames.begin(), itV = slChooserValues.begin(); it != slChooserNames.end(); ++it, ++itV ) { |
1582 | 1582 | ||
1583 | if ( ( *it == "Business Phone" ) || ( *it == "Work Phone" ) ) | 1583 | if ( ( *it == "Business Phone" ) || ( *it == "Work Phone" ) ) |
1584 | ent.setBusinessPhone( *itV ); | 1584 | ent.setBusinessPhone( *itV ); |
1585 | 1585 | ||
1586 | if ( ( *it == "Business Fax" ) || ( *it == "Work Fax" ) ) | 1586 | if ( ( *it == "Business Fax" ) || ( *it == "Work Fax" ) ) |
1587 | ent.setBusinessFax( *itV ); | 1587 | ent.setBusinessFax( *itV ); |
1588 | 1588 | ||
1589 | if ( ( *it == "Business Mobile" ) || ( *it == "Work Mobile" ) ) | 1589 | if ( ( *it == "Business Mobile" ) || ( *it == "Work Mobile" ) ) |
1590 | ent.setBusinessMobile( *itV ); | 1590 | ent.setBusinessMobile( *itV ); |
1591 | 1591 | ||
1592 | if ( *it == "Emails" ){ | 1592 | if ( *it == "Emails" ){ |
1593 | QString allemail; | 1593 | QString allemail; |
1594 | QString defaultmail; | 1594 | QString defaultmail; |
1595 | parseEmailFrom( emails.join(","), defaultmail, allemail ); | 1595 | parseEmailFrom( emails.join(","), defaultmail, allemail ); |
1596 | if ( defaultEmail.isEmpty() ){ | 1596 | if ( defaultEmail.isEmpty() ){ |
1597 | qWarning("Default email was not set by user!"); | 1597 | qWarning("Default email was not set by user!"); |
1598 | qWarning("Using first email in list: %s", defaultmail.latin1()); | 1598 | qWarning("Using first email in list: %s", defaultmail.latin1()); |
1599 | ent.setDefaultEmail( defaultmail ); | 1599 | ent.setDefaultEmail( defaultmail ); |
1600 | } | 1600 | } |
1601 | ent.setEmails( allemail ); | 1601 | ent.setEmails( allemail ); |
1602 | } | 1602 | } |
1603 | 1603 | ||
1604 | if ( *it == "Default Email") | 1604 | if ( *it == "Default Email") |
1605 | ent.setDefaultEmail( defaultEmail /* *itV */ ); | 1605 | ent.setDefaultEmail( defaultEmail /* *itV */ ); |
1606 | 1606 | ||
1607 | if ( *it == "Home Phone" ) | 1607 | if ( *it == "Home Phone" ) |
1608 | ent.setHomePhone( *itV ); | 1608 | ent.setHomePhone( *itV ); |
1609 | 1609 | ||
1610 | if ( *it == "Home Fax" ) | 1610 | if ( *it == "Home Fax" ) |
1611 | ent.setHomeFax( *itV ); | 1611 | ent.setHomeFax( *itV ); |
1612 | 1612 | ||
1613 | if ( *it == "Home Mobile" ) | 1613 | if ( *it == "Home Mobile" ) |
1614 | ent.setHomeMobile( *itV ); | 1614 | ent.setHomeMobile( *itV ); |
1615 | 1615 | ||
1616 | if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) ) | 1616 | if ( ( *it == "Business Pager" ) || ( *it == "Work Pager" ) ) |
1617 | ent.setBusinessPager( *itV ); | 1617 | ent.setBusinessPager( *itV ); |
1618 | 1618 | ||
1619 | if ( *it == "Home Web Page" ) | 1619 | if ( *it == "Home Web Page" ) |
1620 | ent.setHomeWebpage( *itV ); | 1620 | ent.setHomeWebpage( *itV ); |
1621 | 1621 | ||
1622 | if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) ) | 1622 | if ( ( *it == "Business WebPage" ) || ( *it == "Work Web Page" ) ) |
1623 | ent.setBusinessWebpage( *itV ); | 1623 | ent.setBusinessWebpage( *itV ); |
1624 | 1624 | ||
1625 | 1625 | ||
1626 | } | 1626 | } |
1627 | 1627 | ||
1628 | int gender = cmbGender->currentItem(); | 1628 | int gender = cmbGender->currentItem(); |
1629 | ent.setGender( QString::number( gender ) ); | 1629 | ent.setGender( QString::number( gender ) ); |
1630 | 1630 | ||
1631 | QString str = txtNote->text(); | 1631 | QString str = txtNote->text(); |
1632 | if ( !str.isNull() ) | 1632 | if ( !str.isNull() ) |
1633 | ent.setNotes( str ); | 1633 | ent.setNotes( str ); |
1634 | 1634 | ||
1635 | } | 1635 | } |
1636 | 1636 | ||
1637 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, | 1637 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, |
1638 | QString &strAll ) | 1638 | QString &strAll ) |
1639 | { | 1639 | { |
1640 | int where, | 1640 | int where, |
1641 | start; | 1641 | start; |
1642 | if ( txt.isEmpty() ) | 1642 | if ( txt.isEmpty() ) |
1643 | return; | 1643 | return; |
1644 | // find the first | 1644 | // find the first |
1645 | where = txt.find( ',' ); | 1645 | where = txt.find( ',' ); |
1646 | if ( where < 0 ) { | 1646 | if ( where < 0 ) { |
1647 | strDefaultEmail = txt; | 1647 | strDefaultEmail = txt; |
1648 | strAll = txt; | 1648 | strAll = txt; |
1649 | } else { | 1649 | } else { |
1650 | strDefaultEmail = txt.left( where ).stripWhiteSpace(); | 1650 | strDefaultEmail = txt.left( where ).stripWhiteSpace(); |
1651 | strAll = strDefaultEmail; | 1651 | strAll = strDefaultEmail; |
1652 | while ( where > -1 ) { | 1652 | while ( where > -1 ) { |
1653 | strAll.append(" "); | 1653 | strAll.append(" "); |
1654 | start = where; | 1654 | start = where; |
1655 | where = txt.find( ',', where + 1 ); | 1655 | where = txt.find( ',', where + 1 ); |
1656 | if ( where > - 1 ) | 1656 | if ( where > - 1 ) |
1657 | strAll.append( txt.mid(start + 1, where - start - 1).stripWhiteSpace() ); | 1657 | strAll.append( txt.mid(start + 1, where - start - 1).stripWhiteSpace() ); |
1658 | else // grab until the end... | 1658 | else // grab until the end... |
1659 | strAll.append( txt.right(txt.length() - start - 1).stripWhiteSpace() ); | 1659 | strAll.append( txt.right(txt.length() - start - 1).stripWhiteSpace() ); |
1660 | } | 1660 | } |
1661 | } | 1661 | } |
1662 | } | 1662 | } |
1663 | 1663 | ||
1664 | void parseEmailTo( const QString &strDefaultEmail, | 1664 | void parseEmailTo( const QString &strDefaultEmail, |
1665 | const QString &strOtherEmail, QString &strBack ) | 1665 | const QString &strOtherEmail, QString &strBack ) |
1666 | { | 1666 | { |
1667 | // create a comma dilimeted set of emails... | 1667 | // create a comma dilimeted set of emails... |
1668 | // use the power of short circuiting... | 1668 | // use the power of short circuiting... |
1669 | bool foundDefault = false; | 1669 | bool foundDefault = false; |
1670 | QString strTmp; | 1670 | QString strTmp; |
1671 | int start = 0; | 1671 | int start = 0; |
1672 | int where; | 1672 | int where; |
1673 | // start at the beginng. | 1673 | // start at the beginng. |
1674 | strBack = strDefaultEmail; | 1674 | strBack = strDefaultEmail; |
1675 | where = 0; | 1675 | where = 0; |
1676 | while ( where > -1 ) { | 1676 | while ( where > -1 ) { |
1677 | start = where; | 1677 | start = where; |
1678 | where = strOtherEmail.find( ' ', where + 1 ); | 1678 | where = strOtherEmail.find( ' ', where + 1 ); |
1679 | if ( where > 0 ) { | 1679 | if ( where > 0 ) { |
1680 | strTmp = strOtherEmail.mid( start, where - start ).stripWhiteSpace(); | 1680 | strTmp = strOtherEmail.mid( start, where - start ).stripWhiteSpace(); |
1681 | } else | 1681 | } else |
1682 | strTmp = strOtherEmail.right( strOtherEmail.length() - start ).stripWhiteSpace(); | 1682 | strTmp = strOtherEmail.right( strOtherEmail.length() - start ).stripWhiteSpace(); |
1683 | if ( foundDefault || strTmp != strDefaultEmail ) { | 1683 | if ( foundDefault || strTmp != strDefaultEmail ) { |
1684 | strBack.append( ", " ); | 1684 | strBack.append( ", " ); |
1685 | strBack.append( strTmp ); | 1685 | strBack.append( strTmp ); |
1686 | } else | 1686 | } else |
1687 | foundDefault = true; | 1687 | foundDefault = true; |
1688 | } | 1688 | } |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | 1691 | ||
1692 | static inline bool containsAlphaNum( const QString &str ) | 1692 | static inline bool containsAlphaNum( const QString &str ) |
1693 | { | 1693 | { |
1694 | int i, | 1694 | int i, |
1695 | count = str.length(); | 1695 | count = str.length(); |
1696 | for ( i = 0; i < count; i++ ) | 1696 | for ( i = 0; i < count; i++ ) |
1697 | if ( !str[i].isSpace() ) | 1697 | if ( !str[i].isSpace() ) |
1698 | return TRUE; | 1698 | return TRUE; |
1699 | return FALSE; | 1699 | return FALSE; |
1700 | } | 1700 | } |
1701 | 1701 | ||
1702 | static inline bool constainsWhiteSpace( const QString &str ) | 1702 | static inline bool constainsWhiteSpace( const QString &str ) |
1703 | { | 1703 | { |
1704 | int i, | 1704 | int i, |
1705 | count = str.length(); | 1705 | count = str.length(); |
1706 | for (i = 0; i < count; i++ ) | 1706 | for (i = 0; i < count; i++ ) |
1707 | if ( str[i].isSpace() ) | 1707 | if ( str[i].isSpace() ) |
1708 | return TRUE; | 1708 | return TRUE; |
1709 | return FALSE; | 1709 | return FALSE; |
1710 | } | 1710 | } |
1711 | 1711 | ||
1712 | void ContactEditor::setPersonalView( bool personal ) | 1712 | void ContactEditor::setPersonalView( bool personal ) |
1713 | { | 1713 | { |
1714 | m_personalView = personal; | 1714 | m_personalView = personal; |
1715 | 1715 | ||
1716 | // Currently disbled due to the fact that | 1716 | // Currently disbled due to the fact that |
1717 | // show will not work... | 1717 | // show will not work... |
1718 | return; | 1718 | return; |
1719 | 1719 | ||
1720 | if ( personal ){ | 1720 | if ( personal ){ |
1721 | cmbCat->hide(); | 1721 | cmbCat->hide(); |
1722 | labCat->hide(); | 1722 | labCat->hide(); |
1723 | 1723 | ||
1724 | } else{ | 1724 | } else{ |
1725 | cmbCat->show(); | 1725 | cmbCat->show(); |
1726 | labCat->show(); | 1726 | labCat->show(); |
1727 | } | 1727 | } |
1728 | } | 1728 | } |
1729 | 1729 | ||
1730 | void ContactEditor::slotAnniversaryDateChanged( int year, int month, int day) | 1730 | void ContactEditor::slotAnniversaryDateChanged( int year, int month, int day) |
1731 | { | 1731 | { |
1732 | QDate date; | 1732 | QDate date; |
1733 | date.setYMD( year, month, day ); | 1733 | date.setYMD( year, month, day ); |
1734 | QString dateString = TimeString::numberDateString( date ); | 1734 | QString dateString = TimeString::numberDateString( date ); |
1735 | anniversaryButton->setText( dateString ); | 1735 | anniversaryButton->setText( dateString ); |
1736 | ent.setAnniversary ( date ); | 1736 | ent.setAnniversary ( date ); |
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | void ContactEditor::slotBirthdayDateChanged( int year, int month, int day) | 1739 | void ContactEditor::slotBirthdayDateChanged( int year, int month, int day) |
1740 | { | 1740 | { |
1741 | QDate date; | 1741 | QDate date; |
1742 | date.setYMD( year, month, day ); | 1742 | date.setYMD( year, month, day ); |
1743 | QString dateString = TimeString::numberDateString( date ); | 1743 | QString dateString = TimeString::numberDateString( date ); |
1744 | birthdayButton->setText( dateString ); | 1744 | birthdayButton->setText( dateString ); |
1745 | ent.setBirthday ( date ); | 1745 | ent.setBirthday ( date ); |
1746 | } | 1746 | } |
1747 | 1747 | ||
1748 | void ContactEditor::slotRemoveBirthday() | 1748 | void ContactEditor::slotRemoveBirthday() |
1749 | { | 1749 | { |
1750 | qWarning("void ContactEditor::slotRemoveBirthday()"); | 1750 | qWarning("void ContactEditor::slotRemoveBirthday()"); |
1751 | ent.setBirthday( QDate() ); | 1751 | ent.setBirthday( QDate() ); |
1752 | updateDatePicker(); | 1752 | updateDatePicker(); |
1753 | } | 1753 | } |
1754 | 1754 | ||
1755 | void ContactEditor::slotRemoveAnniversary() | 1755 | void ContactEditor::slotRemoveAnniversary() |
1756 | { | 1756 | { |
1757 | qWarning("void ContactEditor::slotRemoveAnniversary()"); | 1757 | qWarning("void ContactEditor::slotRemoveAnniversary()"); |
1758 | ent.setAnniversary( QDate() ); | 1758 | ent.setAnniversary( QDate() ); |
1759 | updateDatePicker(); | 1759 | updateDatePicker(); |
1760 | } | 1760 | } |
diff --git a/core/pim/addressbook/opie-addressbook.control b/core/pim/addressbook/opie-addressbook.control index f06fa91..d949bd4 100644 --- a/core/pim/addressbook/opie-addressbook.control +++ b/core/pim/addressbook/opie-addressbook.control | |||
@@ -1,11 +1,11 @@ | |||
1 | Package: opie-addressbook | 1 | Package: opie-addressbook |
2 | Files: bin/addressbook apps/1Pim/addressbook.desktop pics/addressbook/*.png | 2 | Files: bin/addressbook apps/1Pim/addressbook.desktop |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/applications | 4 | Section: opie/applications |
5 | Conflicts: qpe-tkcaddressbook | 5 | Conflicts: qpe-tkcaddressbook |
6 | Maintainer: Stefan Eilers <eilers.stefan@epost.de> | 6 | Maintainer: Stefan Eilers <eilers.stefan@epost.de> |
7 | Architecture: arm | 7 | Architecture: arm |
8 | Version: $QPE_VERSION-$SUB_VERSION | 8 | Depends: task-opie-minimal, libopie1, opie-pics |
9 | Depends: task-opie-minimal, libopie1 | ||
10 | Description: Contacts | 9 | Description: Contacts |
11 | A simple addressbook for the Opie environment. | 10 | A simple addressbook for the Opie environment. |
11 | Version: $QPE_VERSION$EXTRAVERSION | ||
diff --git a/core/pim/addressbook/version.h b/core/pim/addressbook/version.h index 4c93584..9621826 100644 --- a/core/pim/addressbook/version.h +++ b/core/pim/addressbook/version.h | |||
@@ -1,10 +1,10 @@ | |||
1 | #ifndef _VERSION_H_ | 1 | #ifndef _VERSION_H_ |
2 | #define _VERSION_H_ | 2 | #define _VERSION_H_ |
3 | 3 | ||
4 | #define MAINVERSION "0" | 4 | #define MAINVERSION "1" |
5 | #define SUBVERSION "9" | 5 | #define SUBVERSION "0" |
6 | #define PATCHVERSION "5" | 6 | #define PATCHVERSION "0" |
7 | 7 | ||
8 | #define APPNAME "OPIE_ADDRESSBOOK" | 8 | #define APPNAME "OPIE_ADDRESSBOOK" |
9 | 9 | ||
10 | #endif | 10 | #endif |
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h index ad6cf5a..f3c339d 100644 --- a/libopie/pim/obackendfactory.h +++ b/libopie/pim/obackendfactory.h | |||
@@ -1,154 +1,166 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | * Class to manage Backends. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; | 9 | * License as published by the Free Software Foundation; |
10 | * either version 2 of the License, or (at your option) any later | 10 | * either version 2 of the License, or (at your option) any later |
11 | * version. | 11 | * version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: Use plugins | 13 | * ToDo: Use plugins |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * Version: $Id$ | 15 | * Version: $Id$ |
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
20 | * Merging changes from BRANCH_1_0 to HEAD | ||
21 | * | ||
22 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers | ||
23 | * Patches from Zecke: | ||
24 | * Fixing and cleaning up extraMap handling | ||
25 | * Adding d_ptr for binary compatibility in the future | ||
26 | * | ||
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | 27 | * Revision 1.6 2003/04/13 18:07:10 zecke |
20 | * More API doc | 28 | * More API doc |
21 | * QString -> const QString& | 29 | * QString -> const QString& |
22 | * QString = 0l -> QString::null | 30 | * QString = 0l -> QString::null |
23 | * | 31 | * |
24 | * Revision 1.5 2003/02/21 23:31:52 zecke | 32 | * Revision 1.5 2003/02/21 23:31:52 zecke |
25 | * Add XML datebookresource | 33 | * Add XML datebookresource |
26 | * -clean up todoaccessxml header | 34 | * -clean up todoaccessxml header |
27 | * -implement some more stuff in the oeven tester | 35 | * -implement some more stuff in the oeven tester |
28 | * -extend DefaultFactory to not crash and to use datebook | 36 | * -extend DefaultFactory to not crash and to use datebook |
29 | * | 37 | * |
30 | * -reading of OEvents is working nicely.. saving will be added | 38 | * -reading of OEvents is working nicely.. saving will be added |
31 | * tomorrow | 39 | * tomorrow |
32 | * -fix spelling in ODateBookAcces | 40 | * -fix spelling in ODateBookAcces |
33 | * | 41 | * |
34 | * Revision 1.4 2002/10/14 15:55:18 eilers | 42 | * Revision 1.4 2002/10/14 15:55:18 eilers |
35 | * Redeactivate SQL.. ;) | 43 | * Redeactivate SQL.. ;) |
36 | * | 44 | * |
37 | * Revision 1.3 2002/10/10 17:08:58 zecke | 45 | * Revision 1.3 2002/10/10 17:08:58 zecke |
38 | * The Cache is finally in place | 46 | * The Cache is finally in place |
39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 47 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
40 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... | 48 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... |
41 | * I still have to fully implement read ahead | 49 | * I still have to fully implement read ahead |
42 | * This change is bic but sc | 50 | * This change is bic but sc |
43 | * | 51 | * |
44 | * Revision 1.2 2002/10/08 09:27:36 eilers | 52 | * Revision 1.2 2002/10/08 09:27:36 eilers |
45 | * Fixed libopie.pro to include the new pim-API. | 53 | * Fixed libopie.pro to include the new pim-API. |
46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 54 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
47 | * compile itself would need to install libsqlite, libopiesql... | 55 | * compile itself would need to install libsqlite, libopiesql... |
48 | * Therefore, the backend currently uses XML only.. | 56 | * Therefore, the backend currently uses XML only.. |
49 | * | 57 | * |
50 | * Revision 1.1 2002/10/07 17:35:01 eilers | 58 | * Revision 1.1 2002/10/07 17:35:01 eilers |
51 | * added OBackendFactory for advanced backend access | 59 | * added OBackendFactory for advanced backend access |
52 | * | 60 | * |
53 | * | 61 | * |
54 | * ===================================================================== | 62 | * ===================================================================== |
55 | */ | 63 | */ |
56 | #ifndef OPIE_BACKENDFACTORY_H_ | 64 | #ifndef OPIE_BACKENDFACTORY_H_ |
57 | #define OPIE_BACKENDFACTORY_H_ | 65 | #define OPIE_BACKENDFACTORY_H_ |
58 | 66 | ||
59 | #include <qstring.h> | 67 | #include <qstring.h> |
60 | #include <qasciidict.h> | 68 | #include <qasciidict.h> |
61 | #include <qpe/config.h> | 69 | #include <qpe/config.h> |
62 | 70 | ||
63 | #include "otodoaccessxml.h" | 71 | #include "otodoaccessxml.h" |
64 | #include "ocontactaccessbackend_xml.h" | 72 | #include "ocontactaccessbackend_xml.h" |
65 | #include "odatebookaccessbackend_xml.h" | 73 | #include "odatebookaccessbackend_xml.h" |
66 | 74 | ||
67 | #ifdef __USE_SQL | 75 | #ifdef __USE_SQL |
68 | #include "otodoaccesssql.h" | 76 | #include "otodoaccesssql.h" |
69 | #endif | 77 | #endif |
70 | 78 | ||
79 | class OBackendPrivate; | ||
80 | |||
71 | /** | 81 | /** |
72 | * This class is our factory. It will give us the default implementations | 82 | * This class is our factory. It will give us the default implementations |
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | 83 | * of at least Todolist, Contacts and Datebook. In the future this class will |
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | 84 | * allow users to switch the backend with ( XML->SQLite ) without the need |
75 | * to recompile.# | 85 | * to recompile.# |
76 | * This class as the whole PIM Api is making use of templates | 86 | * This class as the whole PIM Api is making use of templates |
77 | * | 87 | * |
78 | * <pre> | 88 | * <pre> |
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | 89 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); |
80 | * backend->load(); | 90 | * backend->load(); |
81 | * </pre> | 91 | * </pre> |
82 | * | 92 | * |
83 | * @author Stefan Eilers | 93 | * @author Stefan Eilers |
84 | * @version 0.1 | 94 | * @version 0.1 |
85 | */ | 95 | */ |
86 | template<class T> | 96 | template<class T> |
87 | class OBackendFactory | 97 | class OBackendFactory |
88 | { | 98 | { |
89 | public: | 99 | public: |
90 | OBackendFactory() {}; | 100 | OBackendFactory() {}; |
91 | 101 | ||
92 | enum BACKENDS { | 102 | enum BACKENDS { |
93 | TODO, | 103 | TODO, |
94 | CONTACT, | 104 | CONTACT, |
95 | DATE | 105 | DATE |
96 | }; | 106 | }; |
97 | 107 | ||
98 | /** | 108 | /** |
99 | * Returns a backend implementation for backendName | 109 | * Returns a backend implementation for backendName |
100 | * @param backendName the type of the backend | 110 | * @param backendName the type of the backend |
101 | * @param appName will be passed on to the backend | 111 | * @param appName will be passed on to the backend |
102 | */ | 112 | */ |
103 | static T* Default( const QString backendName, const QString& appName ){ | 113 | static T* Default( const QString backendName, const QString& appName ){ |
104 | 114 | ||
105 | // __asm__("int3"); | 115 | // __asm__("int3"); |
106 | 116 | ||
107 | Config config( "pimaccess" ); | 117 | Config config( "pimaccess" ); |
108 | config.setGroup ( backendName ); | 118 | config.setGroup ( backendName ); |
109 | QString backend = config.readEntry( "usebackend" ); | 119 | QString backend = config.readEntry( "usebackend" ); |
110 | 120 | ||
111 | QAsciiDict<int> dict ( 3 ); | 121 | QAsciiDict<int> dict ( 3 ); |
112 | dict.setAutoDelete ( TRUE ); | 122 | dict.setAutoDelete ( TRUE ); |
113 | 123 | ||
114 | dict.insert( "todo", new int (TODO) ); | 124 | dict.insert( "todo", new int (TODO) ); |
115 | dict.insert( "contact", new int (CONTACT) ); | 125 | dict.insert( "contact", new int (CONTACT) ); |
116 | dict.insert( "datebook", new int(DATE) ); | 126 | dict.insert( "datebook", new int(DATE) ); |
117 | 127 | ||
118 | qWarning ("TODO is: %d", TODO); | 128 | qWarning ("TODO is: %d", TODO); |
119 | qWarning ("CONTACT is: %d", CONTACT); | 129 | qWarning ("CONTACT is: %d", CONTACT); |
120 | 130 | ||
121 | int *find = dict[ backendName ]; | 131 | int *find = dict[ backendName ]; |
122 | if (!find ) return 0; | 132 | if (!find ) return 0; |
123 | 133 | ||
124 | switch ( *find ){ | 134 | switch ( *find ){ |
125 | case TODO: | 135 | case TODO: |
126 | #ifdef __USE_SQL | 136 | #ifdef __USE_SQL |
127 | if ( backend == "sql" ) | 137 | if ( backend == "sql" ) |
128 | return (T*) new OTodoAccessBackendSQL(""); | 138 | return (T*) new OTodoAccessBackendSQL(""); |
129 | #else | 139 | #else |
130 | if ( backend == "sql" ) | 140 | if ( backend == "sql" ) |
131 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 141 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
132 | #endif | 142 | #endif |
133 | 143 | ||
134 | return (T*) new OTodoAccessXML( appName ); | 144 | return (T*) new OTodoAccessXML( appName ); |
135 | case CONTACT: | 145 | case CONTACT: |
136 | if ( backend == "sql" ) | 146 | if ( backend == "sql" ) |
137 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 147 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
138 | 148 | ||
139 | return (T*) new OContactAccessBackend_XML( appName ); | 149 | return (T*) new OContactAccessBackend_XML( appName ); |
140 | case DATE: | 150 | case DATE: |
141 | if ( backend == "sql" ) | 151 | if ( backend == "sql" ) |
142 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 152 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
143 | 153 | ||
144 | return (T*) new ODateBookAccessBackend_XML( appName ); | 154 | return (T*) new ODateBookAccessBackend_XML( appName ); |
145 | default: | 155 | default: |
146 | return NULL; | 156 | return NULL; |
147 | } | 157 | } |
148 | 158 | ||
149 | 159 | ||
150 | } | 160 | } |
161 | private: | ||
162 | OBackendPrivate* d; | ||
151 | }; | 163 | }; |
152 | 164 | ||
153 | 165 | ||
154 | #endif | 166 | #endif |
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp index be4ce0a..3473baa 100644 --- a/libopie/pim/ocontact.cpp +++ b/libopie/pim/ocontact.cpp | |||
@@ -1,1138 +1,1211 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #define QTOPIA_INTERNAL_CONTACT_MRE | 20 | #define QTOPIA_INTERNAL_CONTACT_MRE |
21 | 21 | ||
22 | #include "ocontact.h" | 22 | #include "ocontact.h" |
23 | #include "opimresolver.h" | 23 | #include "opimresolver.h" |
24 | #include "oconversion.h" | ||
24 | 25 | ||
25 | #include <qpe/stringutil.h> | 26 | #include <qpe/stringutil.h> |
26 | #include "oconversion.h" | ||
27 | #include <qpe/timestring.h> | 27 | #include <qpe/timestring.h> |
28 | #include <qpe/config.h> | ||
28 | 29 | ||
29 | #include <qobject.h> | 30 | #include <qobject.h> |
30 | #include <qregexp.h> | 31 | #include <qregexp.h> |
31 | #include <qstylesheet.h> | 32 | #include <qstylesheet.h> |
32 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
33 | #include <qmap.h> | 34 | #include <qmap.h> |
34 | 35 | ||
35 | #include <stdio.h> | 36 | #include <stdio.h> |
36 | 37 | ||
37 | /*! | 38 | /*! |
38 | \class Contact contact.h | 39 | \class Contact contact.h |
39 | \brief The Contact class holds the data of an address book entry. | 40 | \brief The Contact class holds the data of an address book entry. |
40 | 41 | ||
41 | This data includes information the name of the person, contact | 42 | This data includes information the name of the person, contact |
42 | information, and business information such as deparment and job title. | 43 | information, and business information such as deparment and job title. |
43 | 44 | ||
44 | \ingroup qtopiaemb | 45 | \ingroup qtopiaemb |
45 | \ingroup qtopiadesktop | 46 | \ingroup qtopiadesktop |
46 | */ | 47 | */ |
47 | 48 | ||
48 | 49 | ||
49 | /*! | 50 | /*! |
50 | Creates a new, empty contact. | 51 | Creates a new, empty contact. |
51 | */ | 52 | */ |
52 | OContact::OContact() | 53 | OContact::OContact() |
53 | : OPimRecord(), mMap(), d( 0 ) | 54 | : OPimRecord(), mMap(), d( 0 ) |
54 | { | 55 | { |
55 | } | 56 | } |
56 | 57 | ||
57 | /*! | 58 | /*! |
58 | \internal | 59 | \internal |
59 | Creates a new contact. The properties of the contact are | 60 | Creates a new contact. The properties of the contact are |
60 | set from \a fromMap. | 61 | set from \a fromMap. |
61 | */ | 62 | */ |
62 | OContact::OContact( const QMap<int, QString> &fromMap ) : | 63 | OContact::OContact( const QMap<int, QString> &fromMap ) : |
63 | OPimRecord(), mMap( fromMap ), d( 0 ) | 64 | OPimRecord(), mMap( fromMap ), d( 0 ) |
64 | { | 65 | { |
65 | QString cats = mMap[ Qtopia::AddressCategory ]; | 66 | QString cats = mMap[ Qtopia::AddressCategory ]; |
66 | if ( !cats.isEmpty() ) | 67 | if ( !cats.isEmpty() ) |
67 | setCategories( idsFromString( cats ) ); | 68 | setCategories( idsFromString( cats ) ); |
68 | 69 | ||
69 | QString uidStr = find( Qtopia::AddressUid ); | 70 | QString uidStr = find( Qtopia::AddressUid ); |
70 | 71 | ||
71 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ | 72 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ |
72 | qWarning( "Invalid UID found. Generate new one.." ); | 73 | qWarning( "Invalid UID found. Generate new one.." ); |
73 | setUid( uidGen().generate() ); | 74 | setUid( uidGen().generate() ); |
74 | }else | 75 | }else |
75 | setUid( uidStr.toInt() ); | 76 | setUid( uidStr.toInt() ); |
76 | 77 | ||
77 | // if ( !uidStr.isEmpty() ) | 78 | // if ( !uidStr.isEmpty() ) |
78 | // setUid( uidStr.toInt() ); | 79 | // setUid( uidStr.toInt() ); |
79 | } | 80 | } |
80 | 81 | ||
81 | /*! | 82 | /*! |
82 | Destroys a contact. | 83 | Destroys a contact. |
83 | */ | 84 | */ |
84 | OContact::~OContact() | 85 | OContact::~OContact() |
85 | { | 86 | { |
86 | } | 87 | } |
87 | 88 | ||
88 | /*! \fn void OContact::setTitle( const QString &str ) | 89 | /*! \fn void OContact::setTitle( const QString &str ) |
89 | Sets the title of the contact to \a str. | 90 | Sets the title of the contact to \a str. |
90 | */ | 91 | */ |
91 | 92 | ||
92 | /*! \fn void OContact::setFirstName( const QString &str ) | 93 | /*! \fn void OContact::setFirstName( const QString &str ) |
93 | Sets the first name of the contact to \a str. | 94 | Sets the first name of the contact to \a str. |
94 | */ | 95 | */ |
95 | 96 | ||
96 | /*! \fn void OContact::setMiddleName( const QString &str ) | 97 | /*! \fn void OContact::setMiddleName( const QString &str ) |
97 | Sets the middle name of the contact to \a str. | 98 | Sets the middle name of the contact to \a str. |
98 | */ | 99 | */ |
99 | 100 | ||
100 | /*! \fn void OContact::setLastName( const QString &str ) | 101 | /*! \fn void OContact::setLastName( const QString &str ) |
101 | Sets the last name of the contact to \a str. | 102 | Sets the last name of the contact to \a str. |
102 | */ | 103 | */ |
103 | 104 | ||
104 | /*! \fn void OContact::setSuffix( const QString &str ) | 105 | /*! \fn void OContact::setSuffix( const QString &str ) |
105 | Sets the suffix of the contact to \a str. | 106 | Sets the suffix of the contact to \a str. |
106 | */ | 107 | */ |
107 | 108 | ||
108 | /*! \fn void OContact::setFileAs( const QString &str ) | 109 | /*! \fn void OContact::setFileAs( const QString &str ) |
109 | Sets the contact to filed as \a str. | 110 | Sets the contact to filed as \a str. |
110 | */ | 111 | */ |
111 | 112 | ||
112 | /*! \fn void OContact::setDefaultEmail( const QString &str ) | 113 | /*! \fn void OContact::setDefaultEmail( const QString &str ) |
113 | Sets the default email of the contact to \a str. | 114 | Sets the default email of the contact to \a str. |
114 | */ | 115 | */ |
115 | 116 | ||
116 | /*! \fn void OContact::setHomeStreet( const QString &str ) | 117 | /*! \fn void OContact::setHomeStreet( const QString &str ) |
117 | Sets the home street address of the contact to \a str. | 118 | Sets the home street address of the contact to \a str. |
118 | */ | 119 | */ |
119 | 120 | ||
120 | /*! \fn void OContact::setHomeCity( const QString &str ) | 121 | /*! \fn void OContact::setHomeCity( const QString &str ) |
121 | Sets the home city of the contact to \a str. | 122 | Sets the home city of the contact to \a str. |
122 | */ | 123 | */ |
123 | 124 | ||
124 | /*! \fn void OContact::setHomeState( const QString &str ) | 125 | /*! \fn void OContact::setHomeState( const QString &str ) |
125 | Sets the home state of the contact to \a str. | 126 | Sets the home state of the contact to \a str. |
126 | */ | 127 | */ |
127 | 128 | ||
128 | /*! \fn void OContact::setHomeZip( const QString &str ) | 129 | /*! \fn void OContact::setHomeZip( const QString &str ) |
129 | Sets the home zip code of the contact to \a str. | 130 | Sets the home zip code of the contact to \a str. |
130 | */ | 131 | */ |
131 | 132 | ||
132 | /*! \fn void OContact::setHomeCountry( const QString &str ) | 133 | /*! \fn void OContact::setHomeCountry( const QString &str ) |
133 | Sets the home country of the contact to \a str. | 134 | Sets the home country of the contact to \a str. |
134 | */ | 135 | */ |
135 | 136 | ||
136 | /*! \fn void OContact::setHomePhone( const QString &str ) | 137 | /*! \fn void OContact::setHomePhone( const QString &str ) |
137 | Sets the home phone number of the contact to \a str. | 138 | Sets the home phone number of the contact to \a str. |
138 | */ | 139 | */ |
139 | 140 | ||
140 | /*! \fn void OContact::setHomeFax( const QString &str ) | 141 | /*! \fn void OContact::setHomeFax( const QString &str ) |
141 | Sets the home fax number of the contact to \a str. | 142 | Sets the home fax number of the contact to \a str. |
142 | */ | 143 | */ |
143 | 144 | ||
144 | /*! \fn void OContact::setHomeMobile( const QString &str ) | 145 | /*! \fn void OContact::setHomeMobile( const QString &str ) |
145 | Sets the home mobile phone number of the contact to \a str. | 146 | Sets the home mobile phone number of the contact to \a str. |
146 | */ | 147 | */ |
147 | 148 | ||
148 | /*! \fn void OContact::setHomeWebpage( const QString &str ) | 149 | /*! \fn void OContact::setHomeWebpage( const QString &str ) |
149 | Sets the home webpage of the contact to \a str. | 150 | Sets the home webpage of the contact to \a str. |
150 | */ | 151 | */ |
151 | 152 | ||
152 | /*! \fn void OContact::setCompany( const QString &str ) | 153 | /*! \fn void OContact::setCompany( const QString &str ) |
153 | Sets the company for contact to \a str. | 154 | Sets the company for contact to \a str. |
154 | */ | 155 | */ |
155 | 156 | ||
156 | /*! \fn void OContact::setJobTitle( const QString &str ) | 157 | /*! \fn void OContact::setJobTitle( const QString &str ) |
157 | Sets the job title of the contact to \a str. | 158 | Sets the job title of the contact to \a str. |
158 | */ | 159 | */ |
159 | 160 | ||
160 | /*! \fn void OContact::setDepartment( const QString &str ) | 161 | /*! \fn void OContact::setDepartment( const QString &str ) |
161 | Sets the department for contact to \a str. | 162 | Sets the department for contact to \a str. |
162 | */ | 163 | */ |
163 | 164 | ||
164 | /*! \fn void OContact::setOffice( const QString &str ) | 165 | /*! \fn void OContact::setOffice( const QString &str ) |
165 | Sets the office for contact to \a str. | 166 | Sets the office for contact to \a str. |
166 | */ | 167 | */ |
167 | 168 | ||
168 | /*! \fn void OContact::setBusinessStreet( const QString &str ) | 169 | /*! \fn void OContact::setBusinessStreet( const QString &str ) |
169 | Sets the business street address of the contact to \a str. | 170 | Sets the business street address of the contact to \a str. |
170 | */ | 171 | */ |
171 | 172 | ||
172 | /*! \fn void OContact::setBusinessCity( const QString &str ) | 173 | /*! \fn void OContact::setBusinessCity( const QString &str ) |
173 | Sets the business city of the contact to \a str. | 174 | Sets the business city of the contact to \a str. |
174 | */ | 175 | */ |
175 | 176 | ||
176 | /*! \fn void OContact::setBusinessState( const QString &str ) | 177 | /*! \fn void OContact::setBusinessState( const QString &str ) |
177 | Sets the business state of the contact to \a str. | 178 | Sets the business state of the contact to \a str. |
178 | */ | 179 | */ |
179 | 180 | ||
180 | /*! \fn void OContact::setBusinessZip( const QString &str ) | 181 | /*! \fn void OContact::setBusinessZip( const QString &str ) |
181 | Sets the business zip code of the contact to \a str. | 182 | Sets the business zip code of the contact to \a str. |
182 | */ | 183 | */ |
183 | 184 | ||
184 | /*! \fn void OContact::setBusinessCountry( const QString &str ) | 185 | /*! \fn void OContact::setBusinessCountry( const QString &str ) |
185 | Sets the business country of the contact to \a str. | 186 | Sets the business country of the contact to \a str. |
186 | */ | 187 | */ |
187 | 188 | ||
188 | /*! \fn void OContact::setBusinessPhone( const QString &str ) | 189 | /*! \fn void OContact::setBusinessPhone( const QString &str ) |
189 | Sets the business phone number of the contact to \a str. | 190 | Sets the business phone number of the contact to \a str. |
190 | */ | 191 | */ |
191 | 192 | ||
192 | /*! \fn void OContact::setBusinessFax( const QString &str ) | 193 | /*! \fn void OContact::setBusinessFax( const QString &str ) |
193 | Sets the business fax number of the contact to \a str. | 194 | Sets the business fax number of the contact to \a str. |
194 | */ | 195 | */ |
195 | 196 | ||
196 | /*! \fn void OContact::setBusinessMobile( const QString &str ) | 197 | /*! \fn void OContact::setBusinessMobile( const QString &str ) |
197 | Sets the business mobile phone number of the contact to \a str. | 198 | Sets the business mobile phone number of the contact to \a str. |
198 | */ | 199 | */ |
199 | 200 | ||
200 | /*! \fn void OContact::setBusinessPager( const QString &str ) | 201 | /*! \fn void OContact::setBusinessPager( const QString &str ) |
201 | Sets the business pager number of the contact to \a str. | 202 | Sets the business pager number of the contact to \a str. |
202 | */ | 203 | */ |
203 | 204 | ||
204 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) | 205 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) |
205 | Sets the business webpage of the contact to \a str. | 206 | Sets the business webpage of the contact to \a str. |
206 | */ | 207 | */ |
207 | 208 | ||
208 | /*! \fn void OContact::setProfession( const QString &str ) | 209 | /*! \fn void OContact::setProfession( const QString &str ) |
209 | Sets the profession of the contact to \a str. | 210 | Sets the profession of the contact to \a str. |
210 | */ | 211 | */ |
211 | 212 | ||
212 | /*! \fn void OContact::setAssistant( const QString &str ) | 213 | /*! \fn void OContact::setAssistant( const QString &str ) |
213 | Sets the assistant of the contact to \a str. | 214 | Sets the assistant of the contact to \a str. |
214 | */ | 215 | */ |
215 | 216 | ||
216 | /*! \fn void OContact::setManager( const QString &str ) | 217 | /*! \fn void OContact::setManager( const QString &str ) |
217 | Sets the manager of the contact to \a str. | 218 | Sets the manager of the contact to \a str. |
218 | */ | 219 | */ |
219 | 220 | ||
220 | /*! \fn void OContact::setSpouse( const QString &str ) | 221 | /*! \fn void OContact::setSpouse( const QString &str ) |
221 | Sets the spouse of the contact to \a str. | 222 | Sets the spouse of the contact to \a str. |
222 | */ | 223 | */ |
223 | 224 | ||
224 | /*! \fn void OContact::setGender( const QString &str ) | 225 | /*! \fn void OContact::setGender( const QString &str ) |
225 | Sets the gender of the contact to \a str. | 226 | Sets the gender of the contact to \a str. |
226 | */ | 227 | */ |
227 | 228 | ||
228 | /*! \fn void OContact::setNickname( const QString &str ) | 229 | /*! \fn void OContact::setNickname( const QString &str ) |
229 | Sets the nickname of the contact to \a str. | 230 | Sets the nickname of the contact to \a str. |
230 | */ | 231 | */ |
231 | 232 | ||
232 | /*! \fn void OContact::setNotes( const QString &str ) | 233 | /*! \fn void OContact::setNotes( const QString &str ) |
233 | Sets the notes about the contact to \a str. | 234 | Sets the notes about the contact to \a str. |
234 | */ | 235 | */ |
235 | 236 | ||
236 | /*! \fn QString OContact::title() const | 237 | /*! \fn QString OContact::title() const |
237 | Returns the title of the contact. | 238 | Returns the title of the contact. |
238 | */ | 239 | */ |
239 | 240 | ||
240 | /*! \fn QString OContact::firstName() const | 241 | /*! \fn QString OContact::firstName() const |
241 | Returns the first name of the contact. | 242 | Returns the first name of the contact. |
242 | */ | 243 | */ |
243 | 244 | ||
244 | /*! \fn QString OContact::middleName() const | 245 | /*! \fn QString OContact::middleName() const |
245 | Returns the middle name of the contact. | 246 | Returns the middle name of the contact. |
246 | */ | 247 | */ |
247 | 248 | ||
248 | /*! \fn QString OContact::lastName() const | 249 | /*! \fn QString OContact::lastName() const |
249 | Returns the last name of the contact. | 250 | Returns the last name of the contact. |
250 | */ | 251 | */ |
251 | 252 | ||
252 | /*! \fn QString OContact::suffix() const | 253 | /*! \fn QString OContact::suffix() const |
253 | Returns the suffix of the contact. | 254 | Returns the suffix of the contact. |
254 | */ | 255 | */ |
255 | 256 | ||
256 | /*! \fn QString OContact::fileAs() const | 257 | /*! \fn QString OContact::fileAs() const |
257 | Returns the string the contact is filed as. | 258 | Returns the string the contact is filed as. |
258 | */ | 259 | */ |
259 | 260 | ||
260 | /*! \fn QString OContact::defaultEmail() const | 261 | /*! \fn QString OContact::defaultEmail() const |
261 | Returns the default email address of the contact. | 262 | Returns the default email address of the contact. |
262 | */ | 263 | */ |
263 | 264 | ||
264 | /*! \fn QString OContact::emails() const | 265 | /*! \fn QString OContact::emails() const |
265 | Returns the list of email address for a contact separated by ';'s in a single | 266 | Returns the list of email address for a contact separated by ';'s in a single |
266 | string. | 267 | string. |
267 | */ | 268 | */ |
268 | 269 | ||
269 | /*! \fn QString OContact::homeStreet() const | 270 | /*! \fn QString OContact::homeStreet() const |
270 | Returns the home street address of the contact. | 271 | Returns the home street address of the contact. |
271 | */ | 272 | */ |
272 | 273 | ||
273 | /*! \fn QString OContact::homeCity() const | 274 | /*! \fn QString OContact::homeCity() const |
274 | Returns the home city of the contact. | 275 | Returns the home city of the contact. |
275 | */ | 276 | */ |
276 | 277 | ||
277 | /*! \fn QString OContact::homeState() const | 278 | /*! \fn QString OContact::homeState() const |
278 | Returns the home state of the contact. | 279 | Returns the home state of the contact. |
279 | */ | 280 | */ |
280 | 281 | ||
281 | /*! \fn QString OContact::homeZip() const | 282 | /*! \fn QString OContact::homeZip() const |
282 | Returns the home zip of the contact. | 283 | Returns the home zip of the contact. |
283 | */ | 284 | */ |
284 | 285 | ||
285 | /*! \fn QString OContact::homeCountry() const | 286 | /*! \fn QString OContact::homeCountry() const |
286 | Returns the home country of the contact. | 287 | Returns the home country of the contact. |
287 | */ | 288 | */ |
288 | 289 | ||
289 | /*! \fn QString OContact::homePhone() const | 290 | /*! \fn QString OContact::homePhone() const |
290 | Returns the home phone number of the contact. | 291 | Returns the home phone number of the contact. |
291 | */ | 292 | */ |
292 | 293 | ||
293 | /*! \fn QString OContact::homeFax() const | 294 | /*! \fn QString OContact::homeFax() const |
294 | Returns the home fax number of the contact. | 295 | Returns the home fax number of the contact. |
295 | */ | 296 | */ |
296 | 297 | ||
297 | /*! \fn QString OContact::homeMobile() const | 298 | /*! \fn QString OContact::homeMobile() const |
298 | Returns the home mobile number of the contact. | 299 | Returns the home mobile number of the contact. |
299 | */ | 300 | */ |
300 | 301 | ||
301 | /*! \fn QString OContact::homeWebpage() const | 302 | /*! \fn QString OContact::homeWebpage() const |
302 | Returns the home webpage of the contact. | 303 | Returns the home webpage of the contact. |
303 | */ | 304 | */ |
304 | 305 | ||
305 | /*! \fn QString OContact::company() const | 306 | /*! \fn QString OContact::company() const |
306 | Returns the company for the contact. | 307 | Returns the company for the contact. |
307 | */ | 308 | */ |
308 | 309 | ||
309 | /*! \fn QString OContact::department() const | 310 | /*! \fn QString OContact::department() const |
310 | Returns the department for the contact. | 311 | Returns the department for the contact. |
311 | */ | 312 | */ |
312 | 313 | ||
313 | /*! \fn QString OContact::office() const | 314 | /*! \fn QString OContact::office() const |
314 | Returns the office for the contact. | 315 | Returns the office for the contact. |
315 | */ | 316 | */ |
316 | 317 | ||
317 | /*! \fn QString OContact::jobTitle() const | 318 | /*! \fn QString OContact::jobTitle() const |
318 | Returns the job title of the contact. | 319 | Returns the job title of the contact. |
319 | */ | 320 | */ |
320 | 321 | ||
321 | /*! \fn QString OContact::profession() const | 322 | /*! \fn QString OContact::profession() const |
322 | Returns the profession of the contact. | 323 | Returns the profession of the contact. |
323 | */ | 324 | */ |
324 | 325 | ||
325 | /*! \fn QString OContact::assistant() const | 326 | /*! \fn QString OContact::assistant() const |
326 | Returns the assistant of the contact. | 327 | Returns the assistant of the contact. |
327 | */ | 328 | */ |
328 | 329 | ||
329 | /*! \fn QString OContact::manager() const | 330 | /*! \fn QString OContact::manager() const |
330 | Returns the manager of the contact. | 331 | Returns the manager of the contact. |
331 | */ | 332 | */ |
332 | 333 | ||
333 | /*! \fn QString OContact::businessStreet() const | 334 | /*! \fn QString OContact::businessStreet() const |
334 | Returns the business street address of the contact. | 335 | Returns the business street address of the contact. |
335 | */ | 336 | */ |
336 | 337 | ||
337 | /*! \fn QString OContact::businessCity() const | 338 | /*! \fn QString OContact::businessCity() const |
338 | Returns the business city of the contact. | 339 | Returns the business city of the contact. |
339 | */ | 340 | */ |
340 | 341 | ||
341 | /*! \fn QString OContact::businessState() const | 342 | /*! \fn QString OContact::businessState() const |
342 | Returns the business state of the contact. | 343 | Returns the business state of the contact. |
343 | */ | 344 | */ |
344 | 345 | ||
345 | /*! \fn QString OContact::businessZip() const | 346 | /*! \fn QString OContact::businessZip() const |
346 | Returns the business zip of the contact. | 347 | Returns the business zip of the contact. |
347 | */ | 348 | */ |
348 | 349 | ||
349 | /*! \fn QString OContact::businessCountry() const | 350 | /*! \fn QString OContact::businessCountry() const |
350 | Returns the business country of the contact. | 351 | Returns the business country of the contact. |
351 | */ | 352 | */ |
352 | 353 | ||
353 | /*! \fn QString OContact::businessPhone() const | 354 | /*! \fn QString OContact::businessPhone() const |
354 | Returns the business phone number of the contact. | 355 | Returns the business phone number of the contact. |
355 | */ | 356 | */ |
356 | 357 | ||
357 | /*! \fn QString OContact::businessFax() const | 358 | /*! \fn QString OContact::businessFax() const |
358 | Returns the business fax number of the contact. | 359 | Returns the business fax number of the contact. |
359 | */ | 360 | */ |
360 | 361 | ||
361 | /*! \fn QString OContact::businessMobile() const | 362 | /*! \fn QString OContact::businessMobile() const |
362 | Returns the business mobile number of the contact. | 363 | Returns the business mobile number of the contact. |
363 | */ | 364 | */ |
364 | 365 | ||
365 | /*! \fn QString OContact::businessPager() const | 366 | /*! \fn QString OContact::businessPager() const |
366 | Returns the business pager number of the contact. | 367 | Returns the business pager number of the contact. |
367 | */ | 368 | */ |
368 | 369 | ||
369 | /*! \fn QString OContact::businessWebpage() const | 370 | /*! \fn QString OContact::businessWebpage() const |
370 | Returns the business webpage of the contact. | 371 | Returns the business webpage of the contact. |
371 | */ | 372 | */ |
372 | 373 | ||
373 | /*! \fn QString OContact::spouse() const | 374 | /*! \fn QString OContact::spouse() const |
374 | Returns the spouse of the contact. | 375 | Returns the spouse of the contact. |
375 | */ | 376 | */ |
376 | 377 | ||
377 | /*! \fn QString OContact::gender() const | 378 | /*! \fn QString OContact::gender() const |
378 | Returns the gender of the contact. | 379 | Returns the gender of the contact. |
379 | */ | 380 | */ |
380 | 381 | ||
381 | /*! \fn QString OContact::nickname() const | 382 | /*! \fn QString OContact::nickname() const |
382 | Returns the nickname of the contact. | 383 | Returns the nickname of the contact. |
383 | */ | 384 | */ |
384 | 385 | ||
385 | /*! \fn QString OContact::children() const | 386 | /*! \fn QString OContact::children() const |
386 | Returns the children of the contact. | 387 | Returns the children of the contact. |
387 | */ | 388 | */ |
388 | 389 | ||
389 | /*! \fn QString OContact::notes() const | 390 | /*! \fn QString OContact::notes() const |
390 | Returns the notes relating to the the contact. | 391 | Returns the notes relating to the the contact. |
391 | */ | 392 | */ |
392 | 393 | ||
393 | /*! \fn QString OContact::groups() const | 394 | /*! \fn QString OContact::groups() const |
394 | \internal | 395 | \internal |
395 | Returns the groups for the contact. | 396 | Returns the groups for the contact. |
396 | */ | 397 | */ |
397 | 398 | ||
398 | /*! \fn QStringList OContact::groupList() const | 399 | /*! \fn QStringList OContact::groupList() const |
399 | \internal | 400 | \internal |
400 | */ | 401 | */ |
401 | 402 | ||
402 | /*! \fn QString OContact::field(int) const | 403 | /*! \fn QString OContact::field(int) const |
403 | \internal | 404 | \internal |
404 | */ | 405 | */ |
405 | 406 | ||
406 | /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) | 407 | /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) |
407 | \internal | 408 | \internal |
408 | */ | 409 | */ |
409 | 410 | ||
410 | /*! \fn void OContact::setUid( int id ) | 411 | /*! \fn void OContact::setUid( int id ) |
411 | \internal | 412 | \internal |
412 | Sets the uid for this record to \a id. | 413 | Sets the uid for this record to \a id. |
413 | */ | 414 | */ |
414 | 415 | ||
415 | /*! \enum OContact::journal_action | 416 | /*! \enum OContact::journal_action |
416 | \internal | 417 | \internal |
417 | */ | 418 | */ |
418 | 419 | ||
419 | /*! | 420 | /*! |
420 | \internal | 421 | \internal |
421 | */ | 422 | */ |
422 | QMap<int, QString> OContact::toMap() const | 423 | QMap<int, QString> OContact::toMap() const |
423 | { | 424 | { |
424 | QMap<int, QString> map = mMap; | 425 | QMap<int, QString> map = mMap; |
425 | QString cats = idsToString( categories() ); | 426 | QString cats = idsToString( categories() ); |
426 | if ( !cats.isEmpty() ) | 427 | if ( !cats.isEmpty() ) |
427 | map.insert( Qtopia::AddressCategory, cats ); | 428 | map.insert( Qtopia::AddressCategory, cats ); |
428 | return map; | 429 | return map; |
429 | } | 430 | } |
430 | 431 | ||
431 | /*! | 432 | /*! |
432 | Returns a rich text formatted QString representing the contents the contact. | 433 | Returns a rich text formatted QString representing the contents the contact. |
433 | */ | 434 | */ |
434 | QString OContact::toRichText() const | 435 | QString OContact::toRichText() const |
435 | { | 436 | { |
436 | QString text; | 437 | QString text; |
437 | QString value, comp, state; | 438 | QString value, comp, state; |
438 | QString str; | 439 | QString str; |
439 | bool marker = false; | 440 | bool marker = false; |
440 | 441 | ||
442 | Config cfg("qpe"); | ||
443 | cfg.setGroup("Appearance"); | ||
444 | int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); | ||
445 | |||
441 | // name, jobtitle and company | 446 | // name, jobtitle and company |
442 | if ( !(value = fullName()).isEmpty() ) | 447 | if ( !(value = fullName()).isEmpty() ) |
443 | text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>"; | 448 | text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString(value) + "</h3></b>"; |
444 | 449 | ||
445 | if ( !(value = jobTitle()).isEmpty() ) | 450 | if ( !(value = jobTitle()).isEmpty() ) |
446 | text += Qtopia::escapeString(value) + "<br>"; | 451 | text += Qtopia::escapeString(value); |
447 | 452 | ||
448 | comp = company(); | 453 | comp = company(); |
449 | if ( !(value = department()).isEmpty() ) { | 454 | if ( !(value = department()).isEmpty() ) { |
450 | text += Qtopia::escapeString(value); | 455 | text += Qtopia::escapeString(value); |
451 | if ( comp ) | 456 | if ( comp ) |
452 | text += ", "; | 457 | text += ", "; |
453 | else | 458 | else |
454 | text += "<br>"; | 459 | text += "<br>"; |
455 | } | 460 | } |
456 | if ( !comp.isEmpty() ) | 461 | if ( !comp.isEmpty() ) |
457 | text += Qtopia::escapeString(comp) + "<br>"; | 462 | text += Qtopia::escapeString(comp); |
458 | 463 | ||
459 | text += "<hr><br>"; | 464 | text += "<br><hr>"; |
460 | 465 | ||
461 | // defailt email | 466 | // defailt email |
462 | QString defEmail = defaultEmail(); | 467 | QString defEmail = defaultEmail(); |
463 | if ( !defEmail.isEmpty() ) | 468 | if ( !defEmail.isEmpty() ){ |
464 | text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>" | 469 | text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>" |
465 | + Qtopia::escapeString(defEmail) + "<br>"; | 470 | + Qtopia::escapeString(defEmail); |
466 | 471 | marker = true; | |
467 | text += "<br>"; | 472 | } |
468 | 473 | ||
469 | // business address | 474 | // business address |
470 | if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || | 475 | if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || |
471 | !businessZip().isEmpty() || !businessCountry().isEmpty() ) { | 476 | !businessZip().isEmpty() || !businessCountry().isEmpty() ) { |
472 | text += QObject::tr( "<b>Work Address:</b>" ); | 477 | text += QObject::tr( "<br><br><b>Work Address:</b>" ); |
473 | text += "<br>"; | ||
474 | marker = true; | 478 | marker = true; |
475 | } | 479 | } |
476 | 480 | ||
477 | if ( !(value = businessStreet()).isEmpty() ) | 481 | if ( !(value = businessStreet()).isEmpty() ){ |
478 | text += Qtopia::escapeString(value) + "<br>"; | 482 | text += "<br>" + Qtopia::escapeString(value); |
479 | state = businessState(); | 483 | marker = true; |
480 | if ( !(value = businessZip()).isEmpty() ) | 484 | } |
481 | text += Qtopia::escapeString(value) + " "; | 485 | |
482 | if ( !(value = businessCity()).isEmpty() ) { | 486 | switch( addressformat ){ |
483 | text += Qtopia::escapeString(value); | 487 | case Zip_City_State:{ // Zip_Code City, State |
484 | if ( state ) | 488 | state = businessState(); |
485 | text += ", " + Qtopia::escapeString(state); | 489 | if ( !(value = businessZip()).isEmpty() ){ |
486 | text += "<br>"; | 490 | text += "<br>" + Qtopia::escapeString(value) + " "; |
487 | } else if ( !state.isEmpty() ) | 491 | marker = true; |
488 | text += Qtopia::escapeString(state) + "<br>"; | 492 | |
493 | } else | ||
494 | text += "<br>"; | ||
495 | |||
496 | if ( !(value = businessCity()).isEmpty() ) { | ||
497 | marker = true; | ||
498 | text += Qtopia::escapeString(value); | ||
499 | if ( state ) | ||
500 | text += ", " + Qtopia::escapeString(state); | ||
501 | } else if ( !state.isEmpty() ){ | ||
502 | text += "<br>" + Qtopia::escapeString(state); | ||
503 | marker = true; | ||
504 | } | ||
505 | break; | ||
506 | } | ||
507 | case City_State_Zip:{ // City, State Zip_Code | ||
508 | state = businessState(); | ||
509 | if ( !(value = businessCity()).isEmpty() ) { | ||
510 | marker = true; | ||
511 | text += "<br>" + Qtopia::escapeString(value); | ||
512 | if ( state ) | ||
513 | text += ", " + Qtopia::escapeString(state); | ||
514 | } else if ( !state.isEmpty() ){ | ||
515 | text += "<br>" + Qtopia::escapeString(state); | ||
516 | marker = true; | ||
517 | } | ||
518 | if ( !(value = businessZip()).isEmpty() ){ | ||
519 | text += " " + Qtopia::escapeString(value); | ||
520 | marker = true; | ||
521 | } | ||
522 | break; | ||
523 | } | ||
524 | } | ||
489 | 525 | ||
490 | if ( !(value = businessCountry()).isEmpty() ) | 526 | if ( !(value = businessCountry()).isEmpty() ){ |
491 | text += Qtopia::escapeString(value) + "<br>"; | 527 | text += "<br>" + Qtopia::escapeString(value); |
528 | marker = true; | ||
529 | } | ||
492 | 530 | ||
493 | // rest of Business data | 531 | // rest of Business data |
494 | str = office(); | 532 | str = office(); |
495 | if ( !str.isEmpty() ){ | 533 | if ( !str.isEmpty() ){ |
496 | text += "<b>" + QObject::tr("Office: ") + "</b>" | 534 | text += "<br><b>" + QObject::tr("Office: ") + "</b>" |
497 | + Qtopia::escapeString(str) + "<br>"; | 535 | + Qtopia::escapeString(str); |
498 | marker = true; | 536 | marker = true; |
499 | } | 537 | } |
500 | str = businessWebpage(); | 538 | str = businessWebpage(); |
501 | if ( !str.isEmpty() ){ | 539 | if ( !str.isEmpty() ){ |
502 | text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>" | 540 | text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>" |
503 | + Qtopia::escapeString(str) + "<br>"; | 541 | + Qtopia::escapeString(str); |
504 | marker = true; | 542 | marker = true; |
505 | } | 543 | } |
506 | str = businessPhone(); | 544 | str = businessPhone(); |
507 | if ( !str.isEmpty() ){ | 545 | if ( !str.isEmpty() ){ |
508 | text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>" | 546 | text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>" |
509 | + Qtopia::escapeString(str) + "<br>"; | 547 | + Qtopia::escapeString(str); |
510 | marker = true; | 548 | marker = true; |
511 | } | 549 | } |
512 | str = businessFax(); | 550 | str = businessFax(); |
513 | if ( !str.isEmpty() ){ | 551 | if ( !str.isEmpty() ){ |
514 | text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>" | 552 | text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>" |
515 | + Qtopia::escapeString(str) + "<br>"; | 553 | + Qtopia::escapeString(str); |
516 | marker = true; | 554 | marker = true; |
517 | } | 555 | } |
518 | str = businessMobile(); | 556 | str = businessMobile(); |
519 | if ( !str.isEmpty() ){ | 557 | if ( !str.isEmpty() ){ |
520 | text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>" | 558 | text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>" |
521 | + Qtopia::escapeString(str) + "<br>"; | 559 | + Qtopia::escapeString(str); |
522 | marker = true; | 560 | marker = true; |
523 | } | 561 | } |
524 | str = businessPager(); | 562 | str = businessPager(); |
525 | if ( !str.isEmpty() ){ | 563 | if ( !str.isEmpty() ){ |
526 | text += "<b>" + QObject::tr("Business Pager: ") + "</b>" | 564 | text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>" |
527 | + Qtopia::escapeString(str) + "<br>"; | 565 | + Qtopia::escapeString(str); |
528 | marker = true; | 566 | marker = true; |
529 | } | 567 | } |
530 | 568 | ||
531 | text += "<br>"; | 569 | text += "<br>"; |
532 | 570 | ||
533 | // home address | 571 | // home address |
534 | if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || | 572 | if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || |
535 | !homeZip().isEmpty() || !homeCountry().isEmpty() ) { | 573 | !homeZip().isEmpty() || !homeCountry().isEmpty() ) { |
536 | text += QObject::tr( "<b>Home Address:</b>" ); | 574 | text += QObject::tr( "<br><br><b>Home Address:</b>" ); |
537 | text += "<br>"; | 575 | marker = true; |
538 | } | 576 | } |
539 | 577 | ||
540 | if ( !(value = homeStreet()).isEmpty() ) | 578 | if ( !(value = homeStreet()).isEmpty() ){ |
541 | text += Qtopia::escapeString(value) + "<br>"; | 579 | text += "<br>" + Qtopia::escapeString(value); |
542 | state = homeState(); | 580 | marker = true; |
543 | if ( !(value = homeZip()).isEmpty() ) | 581 | } |
544 | text += Qtopia::escapeString(value) + " "; | 582 | |
545 | if ( !(value = homeCity()).isEmpty() ) { | 583 | switch( addressformat ){ |
546 | text += Qtopia::escapeString(value); | 584 | case Zip_City_State:{ // Zip_Code City, State |
547 | if ( !state.isEmpty() ) | 585 | state = homeState(); |
548 | text += ", " + Qtopia::escapeString(state); | 586 | if ( !(value = homeZip()).isEmpty() ){ |
549 | text += "<br>"; | 587 | text += "<br>" + Qtopia::escapeString(value) + " "; |
550 | } else if (!state.isEmpty()) | 588 | marker = true; |
551 | text += Qtopia::escapeString(state) + "<br>"; | 589 | } else |
552 | if ( !(value = homeCountry()).isEmpty() ) | 590 | text += "<br>"; |
553 | text += Qtopia::escapeString(value) + "<br>"; | 591 | |
592 | if ( !(value = homeCity()).isEmpty() ) { | ||
593 | marker = true; | ||
594 | text += Qtopia::escapeString(value); | ||
595 | if ( !state.isEmpty() ) | ||
596 | text += ", " + Qtopia::escapeString(state); | ||
597 | } else if (!state.isEmpty()) { | ||
598 | text += "<br>" + Qtopia::escapeString(state); | ||
599 | marker = true; | ||
600 | } | ||
601 | break; | ||
602 | } | ||
603 | case City_State_Zip:{ // City, State Zip_Code | ||
604 | state = homeState(); | ||
605 | if ( !(value = homeCity()).isEmpty() ) { | ||
606 | marker = true; | ||
607 | text += "<br>" + Qtopia::escapeString(value); | ||
608 | if ( state ) | ||
609 | text += ", " + Qtopia::escapeString(state); | ||
610 | } else if ( !state.isEmpty() ){ | ||
611 | text += "<br>" + Qtopia::escapeString(state); | ||
612 | marker = true; | ||
613 | } | ||
614 | if ( !(value = homeZip()).isEmpty() ){ | ||
615 | text += " " + Qtopia::escapeString(value); | ||
616 | marker = true; | ||
617 | } | ||
618 | break; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | if ( !(value = homeCountry()).isEmpty() ){ | ||
623 | text += "<br>" + Qtopia::escapeString(value); | ||
624 | marker = true; | ||
625 | } | ||
554 | 626 | ||
555 | // rest of Home data | 627 | // rest of Home data |
556 | str = homeWebpage(); | 628 | str = homeWebpage(); |
557 | if ( !str.isEmpty() ){ | 629 | if ( !str.isEmpty() ){ |
558 | text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>" | 630 | text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>" |
559 | + Qtopia::escapeString(str) + "<br>"; | 631 | + Qtopia::escapeString(str); |
560 | marker = true; | 632 | marker = true; |
561 | } | 633 | } |
562 | str = homePhone(); | 634 | str = homePhone(); |
563 | if ( !str.isEmpty() ){ | 635 | if ( !str.isEmpty() ){ |
564 | text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>" | 636 | text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>" |
565 | + Qtopia::escapeString(str) + "<br>"; | 637 | + Qtopia::escapeString(str); |
566 | marker = true; | 638 | marker = true; |
567 | } | 639 | } |
568 | str = homeFax(); | 640 | str = homeFax(); |
569 | if ( !str.isEmpty() ){ | 641 | if ( !str.isEmpty() ){ |
570 | text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>" | 642 | text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>" |
571 | + Qtopia::escapeString(str) + "<br>"; | 643 | + Qtopia::escapeString(str); |
572 | marker = true; | 644 | marker = true; |
573 | } | 645 | } |
574 | str = homeMobile(); | 646 | str = homeMobile(); |
575 | if ( !str.isEmpty() ){ | 647 | if ( !str.isEmpty() ){ |
576 | text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>" | 648 | text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>" |
577 | + Qtopia::escapeString(str) + "<br>"; | 649 | + Qtopia::escapeString(str); |
578 | marker = true; | 650 | marker = true; |
579 | } | 651 | } |
580 | 652 | ||
581 | if ( marker ) | 653 | if ( marker ) |
582 | text += "<br><hr><br>"; | 654 | text += "<br><hr>"; |
583 | // the others... | 655 | |
656 | // the rest... | ||
584 | str = emails(); | 657 | str = emails(); |
585 | if ( !str.isEmpty() && ( str != defEmail ) ) | 658 | if ( !str.isEmpty() && ( str != defEmail ) ) |
586 | text += "<b>" + QObject::tr("All Emails: ") + "</b>" | 659 | text += "<br><b>" + QObject::tr("All Emails: ") + "</b>" |
587 | + Qtopia::escapeString(str) + "<br>"; | 660 | + Qtopia::escapeString(str); |
588 | str = profession(); | 661 | str = profession(); |
589 | if ( !str.isEmpty() ) | 662 | if ( !str.isEmpty() ) |
590 | text += "<b>" + QObject::tr("Profession: ") + "</b>" | 663 | text += "<br><b>" + QObject::tr("Profession: ") + "</b>" |
591 | + Qtopia::escapeString(str) + "<br>"; | 664 | + Qtopia::escapeString(str); |
592 | str = assistant(); | 665 | str = assistant(); |
593 | if ( !str.isEmpty() ) | 666 | if ( !str.isEmpty() ) |
594 | text += "<b>" + QObject::tr("Assistant: ") + "</b>" | 667 | text += "<br><b>" + QObject::tr("Assistant: ") + "</b>" |
595 | + Qtopia::escapeString(str) + "<br>"; | 668 | + Qtopia::escapeString(str); |
596 | str = manager(); | 669 | str = manager(); |
597 | if ( !str.isEmpty() ) | 670 | if ( !str.isEmpty() ) |
598 | text += "<b>" + QObject::tr("Manager: ") + "</b>" | 671 | text += "<br><b>" + QObject::tr("Manager: ") + "</b>" |
599 | + Qtopia::escapeString(str) + "<br>"; | 672 | + Qtopia::escapeString(str); |
600 | str = gender(); | 673 | str = gender(); |
601 | if ( !str.isEmpty() && str.toInt() != 0 ) { | 674 | if ( !str.isEmpty() && str.toInt() != 0 ) { |
602 | if ( str.toInt() == 1 ) | 675 | text += "<br>"; |
603 | str = QObject::tr( "Male" ); | 676 | if ( str.toInt() == 1 ) |
604 | else if ( str.toInt() == 2 ) | 677 | str = QObject::tr( "Male" ); |
605 | str = QObject::tr( "Female" ); | 678 | else if ( str.toInt() == 2 ) |
606 | text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; | 679 | str = QObject::tr( "Female" ); |
680 | text += "<b>" + QObject::tr("Gender: ") + "</b>" + str; | ||
607 | } | 681 | } |
608 | str = spouse(); | 682 | str = spouse(); |
609 | if ( !str.isEmpty() ) | 683 | if ( !str.isEmpty() ) |
610 | text += "<b>" + QObject::tr("Spouse: ") + "</b>" | 684 | text += "<br><b>" + QObject::tr("Spouse: ") + "</b>" |
611 | + Qtopia::escapeString(str) + "<br>"; | 685 | + Qtopia::escapeString(str); |
612 | if ( birthday().isValid() ){ | 686 | if ( birthday().isValid() ){ |
613 | str = TimeString::numberDateString( birthday() ); | 687 | str = TimeString::numberDateString( birthday() ); |
614 | text += "<b>" + QObject::tr("Birthday: ") + "</b>" | 688 | text += "<br><b>" + QObject::tr("Birthday: ") + "</b>" |
615 | + Qtopia::escapeString(str) + "<br>"; | 689 | + Qtopia::escapeString(str); |
616 | } | 690 | } |
617 | if ( anniversary().isValid() ){ | 691 | if ( anniversary().isValid() ){ |
618 | str = TimeString::numberDateString( anniversary() ); | 692 | str = TimeString::numberDateString( anniversary() ); |
619 | text += "<b>" + QObject::tr("Anniversary: ") + "</b>" | 693 | text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>" |
620 | + Qtopia::escapeString(str) + "<br>"; | 694 | + Qtopia::escapeString(str); |
621 | } | 695 | } |
622 | str = children(); | 696 | str = children(); |
623 | if ( !str.isEmpty() ) | 697 | if ( !str.isEmpty() ) |
624 | text += "<b>" + QObject::tr("Children: ") + "</b>" | 698 | text += "<br><b>" + QObject::tr("Children: ") + "</b>" |
625 | + Qtopia::escapeString(str) + "<br>"; | 699 | + Qtopia::escapeString(str); |
626 | 700 | ||
627 | str = nickname(); | 701 | str = nickname(); |
628 | if ( !str.isEmpty() ) | 702 | if ( !str.isEmpty() ) |
629 | text += "<b>" + QObject::tr("Nickname: ") + "</b>" | 703 | text += "<br><b>" + QObject::tr("Nickname: ") + "</b>" |
630 | + Qtopia::escapeString(str) + "<br>"; | 704 | + Qtopia::escapeString(str); |
631 | 705 | ||
632 | // categories | 706 | // categories |
633 | if ( categoryNames("Contacts").count() ){ | 707 | if ( categoryNames("Contacts").count() ){ |
634 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 708 | text += "<br><b>" + QObject::tr( "Category:") + "</b> "; |
635 | text += categoryNames("Contacts").join(", "); | 709 | text += categoryNames("Contacts").join(", "); |
636 | text += "<br>"; | ||
637 | } | 710 | } |
638 | 711 | ||
639 | // notes last | 712 | // notes last |
640 | if ( !(value = notes()).isEmpty() ) { | 713 | if ( !(value = notes()).isEmpty() ) { |
641 | text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; | 714 | text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; |
642 | QRegExp reg("\n"); | 715 | QRegExp reg("\n"); |
643 | 716 | ||
644 | //QString tmp = Qtopia::escapeString(value); | 717 | //QString tmp = Qtopia::escapeString(value); |
645 | QString tmp = QStyleSheet::convertFromPlainText(value); | 718 | QString tmp = QStyleSheet::convertFromPlainText(value); |
646 | //tmp.replace( reg, "<br>" ); | 719 | //tmp.replace( reg, "<br>" ); |
647 | text += "<br>" + tmp + "<br>"; | 720 | text += "<br>" + tmp + "<br>"; |
648 | } | 721 | } |
649 | return text; | 722 | return text; |
650 | } | 723 | } |
651 | 724 | ||
652 | /*! | 725 | /*! |
653 | \internal | 726 | \internal |
654 | */ | 727 | */ |
655 | void OContact::insert( int key, const QString &v ) | 728 | void OContact::insert( int key, const QString &v ) |
656 | { | 729 | { |
657 | QString value = v.stripWhiteSpace(); | 730 | QString value = v.stripWhiteSpace(); |
658 | if ( value.isEmpty() ) | 731 | if ( value.isEmpty() ) |
659 | mMap.remove( key ); | 732 | mMap.remove( key ); |
660 | else | 733 | else |
661 | mMap.insert( key, value ); | 734 | mMap.insert( key, value ); |
662 | } | 735 | } |
663 | 736 | ||
664 | /*! | 737 | /*! |
665 | \internal | 738 | \internal |
666 | */ | 739 | */ |
667 | void OContact::replace( int key, const QString & v ) | 740 | void OContact::replace( int key, const QString & v ) |
668 | { | 741 | { |
669 | QString value = v.stripWhiteSpace(); | 742 | QString value = v.stripWhiteSpace(); |
670 | if ( value.isEmpty() ) | 743 | if ( value.isEmpty() ) |
671 | mMap.remove( key ); | 744 | mMap.remove( key ); |
672 | else | 745 | else |
673 | mMap.replace( key, value ); | 746 | mMap.replace( key, value ); |
674 | } | 747 | } |
675 | 748 | ||
676 | /*! | 749 | /*! |
677 | \internal | 750 | \internal |
678 | */ | 751 | */ |
679 | QString OContact::find( int key ) const | 752 | QString OContact::find( int key ) const |
680 | { | 753 | { |
681 | return mMap[key]; | 754 | return mMap[key]; |
682 | } | 755 | } |
683 | 756 | ||
684 | /*! | 757 | /*! |
685 | \internal | 758 | \internal |
686 | */ | 759 | */ |
687 | QString OContact::displayAddress( const QString &street, | 760 | QString OContact::displayAddress( const QString &street, |
688 | const QString &city, | 761 | const QString &city, |
689 | const QString &state, | 762 | const QString &state, |
690 | const QString &zip, | 763 | const QString &zip, |
691 | const QString &country ) const | 764 | const QString &country ) const |
692 | { | 765 | { |
693 | QString s = street; | 766 | QString s = street; |
694 | if ( !street.isEmpty() ) | 767 | if ( !street.isEmpty() ) |
695 | s+= "\n"; | 768 | s+= "\n"; |
696 | s += city; | 769 | s += city; |
697 | if ( !city.isEmpty() && !state.isEmpty() ) | 770 | if ( !city.isEmpty() && !state.isEmpty() ) |
698 | s += ", "; | 771 | s += ", "; |
699 | s += state; | 772 | s += state; |
700 | if ( !state.isEmpty() && !zip.isEmpty() ) | 773 | if ( !state.isEmpty() && !zip.isEmpty() ) |
701 | s += " "; | 774 | s += " "; |
702 | s += zip; | 775 | s += zip; |
703 | if ( !country.isEmpty() && !s.isEmpty() ) | 776 | if ( !country.isEmpty() && !s.isEmpty() ) |
704 | s += "\n"; | 777 | s += "\n"; |
705 | s += country; | 778 | s += country; |
706 | return s; | 779 | return s; |
707 | } | 780 | } |
708 | 781 | ||
709 | /*! | 782 | /*! |
710 | \internal | 783 | \internal |
711 | */ | 784 | */ |
712 | QString OContact::displayBusinessAddress() const | 785 | QString OContact::displayBusinessAddress() const |
713 | { | 786 | { |
714 | return displayAddress( businessStreet(), businessCity(), | 787 | return displayAddress( businessStreet(), businessCity(), |
715 | businessState(), businessZip(), | 788 | businessState(), businessZip(), |
716 | businessCountry() ); | 789 | businessCountry() ); |
717 | } | 790 | } |
718 | 791 | ||
719 | /*! | 792 | /*! |
720 | \internal | 793 | \internal |
721 | */ | 794 | */ |
722 | QString OContact::displayHomeAddress() const | 795 | QString OContact::displayHomeAddress() const |
723 | { | 796 | { |
724 | return displayAddress( homeStreet(), homeCity(), | 797 | return displayAddress( homeStreet(), homeCity(), |
725 | homeState(), homeZip(), | 798 | homeState(), homeZip(), |
726 | homeCountry() ); | 799 | homeCountry() ); |
727 | } | 800 | } |
728 | 801 | ||
729 | /*! | 802 | /*! |
730 | Returns the full name of the contact | 803 | Returns the full name of the contact |
731 | */ | 804 | */ |
732 | QString OContact::fullName() const | 805 | QString OContact::fullName() const |
733 | { | 806 | { |
734 | QString title = find( Qtopia::Title ); | 807 | QString title = find( Qtopia::Title ); |
735 | QString firstName = find( Qtopia::FirstName ); | 808 | QString firstName = find( Qtopia::FirstName ); |
736 | QString middleName = find( Qtopia::MiddleName ); | 809 | QString middleName = find( Qtopia::MiddleName ); |
737 | QString lastName = find( Qtopia::LastName ); | 810 | QString lastName = find( Qtopia::LastName ); |
738 | QString suffix = find( Qtopia::Suffix ); | 811 | QString suffix = find( Qtopia::Suffix ); |
739 | 812 | ||
740 | QString name = title; | 813 | QString name = title; |
741 | if ( !firstName.isEmpty() ) { | 814 | if ( !firstName.isEmpty() ) { |
742 | if ( !name.isEmpty() ) | 815 | if ( !name.isEmpty() ) |
743 | name += " "; | 816 | name += " "; |
744 | name += firstName; | 817 | name += firstName; |
745 | } | 818 | } |
746 | if ( !middleName.isEmpty() ) { | 819 | if ( !middleName.isEmpty() ) { |
747 | if ( !name.isEmpty() ) | 820 | if ( !name.isEmpty() ) |
748 | name += " "; | 821 | name += " "; |
749 | name += middleName; | 822 | name += middleName; |
750 | } | 823 | } |
751 | if ( !lastName.isEmpty() ) { | 824 | if ( !lastName.isEmpty() ) { |
752 | if ( !name.isEmpty() ) | 825 | if ( !name.isEmpty() ) |
753 | name += " "; | 826 | name += " "; |
754 | name += lastName; | 827 | name += lastName; |
755 | } | 828 | } |
756 | if ( !suffix.isEmpty() ) { | 829 | if ( !suffix.isEmpty() ) { |
757 | if ( !name.isEmpty() ) | 830 | if ( !name.isEmpty() ) |
758 | name += " "; | 831 | name += " "; |
759 | name += suffix; | 832 | name += suffix; |
760 | } | 833 | } |
761 | return name.simplifyWhiteSpace(); | 834 | return name.simplifyWhiteSpace(); |
762 | } | 835 | } |
763 | 836 | ||
764 | /*! | 837 | /*! |
765 | Returns a list of the names of the children of the contact. | 838 | Returns a list of the names of the children of the contact. |
766 | */ | 839 | */ |
767 | QStringList OContact::childrenList() const | 840 | QStringList OContact::childrenList() const |
768 | { | 841 | { |
769 | return QStringList::split( " ", find( Qtopia::Children ) ); | 842 | return QStringList::split( " ", find( Qtopia::Children ) ); |
770 | } | 843 | } |
771 | 844 | ||
772 | /*! \fn void OContact::insertEmail( const QString &email ) | 845 | /*! \fn void OContact::insertEmail( const QString &email ) |
773 | 846 | ||
774 | Insert \a email into the email list. Ensures \a email can only be added | 847 | Insert \a email into the email list. Ensures \a email can only be added |
775 | once. If there is no default email address set, it sets it to the \a email. | 848 | once. If there is no default email address set, it sets it to the \a email. |
776 | */ | 849 | */ |
777 | 850 | ||
778 | /*! \fn void OContact::removeEmail( const QString &email ) | 851 | /*! \fn void OContact::removeEmail( const QString &email ) |
779 | 852 | ||
780 | Removes the \a email from the email list. If the default email was \a email, | 853 | Removes the \a email from the email list. If the default email was \a email, |
781 | then the default email address is assigned to the first email in the | 854 | then the default email address is assigned to the first email in the |
782 | email list | 855 | email list |
783 | */ | 856 | */ |
784 | 857 | ||
785 | /*! \fn void OContact::clearEmails() | 858 | /*! \fn void OContact::clearEmails() |
786 | 859 | ||
787 | Clears the email list. | 860 | Clears the email list. |
788 | */ | 861 | */ |
789 | 862 | ||
790 | /*! \fn void OContact::insertEmails( const QStringList &emailList ) | 863 | /*! \fn void OContact::insertEmails( const QStringList &emailList ) |
791 | 864 | ||
792 | Appends the \a emailList to the exiting email list | 865 | Appends the \a emailList to the exiting email list |
793 | */ | 866 | */ |
794 | 867 | ||
795 | /*! | 868 | /*! |
796 | Returns a list of email addresses belonging to the contact, including | 869 | Returns a list of email addresses belonging to the contact, including |
797 | the default email address. | 870 | the default email address. |
798 | */ | 871 | */ |
799 | QStringList OContact::emailList() const | 872 | QStringList OContact::emailList() const |
800 | { | 873 | { |
801 | QString emailStr = emails(); | 874 | QString emailStr = emails(); |
802 | 875 | ||
803 | QStringList r; | 876 | QStringList r; |
804 | if ( !emailStr.isEmpty() ) { | 877 | if ( !emailStr.isEmpty() ) { |
805 | qDebug(" emailstr "); | 878 | qDebug(" emailstr "); |
806 | QStringList l = QStringList::split( emailSeparator(), emailStr ); | 879 | QStringList l = QStringList::split( emailSeparator(), emailStr ); |
807 | for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) | 880 | for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) |
808 | r += (*it).simplifyWhiteSpace(); | 881 | r += (*it).simplifyWhiteSpace(); |
809 | } | 882 | } |
810 | 883 | ||
811 | return r; | 884 | return r; |
812 | } | 885 | } |
813 | 886 | ||
814 | /*! | 887 | /*! |
815 | \overload | 888 | \overload |
816 | 889 | ||
817 | Generates the string for the contact to be filed as from the first, | 890 | Generates the string for the contact to be filed as from the first, |
818 | middle and last name of the contact. | 891 | middle and last name of the contact. |
819 | */ | 892 | */ |
820 | void OContact::setFileAs() | 893 | void OContact::setFileAs() |
821 | { | 894 | { |
822 | QString lastName, firstName, middleName, fileas; | 895 | QString lastName, firstName, middleName, fileas; |
823 | 896 | ||
824 | lastName = find( Qtopia::LastName ); | 897 | lastName = find( Qtopia::LastName ); |
825 | firstName = find( Qtopia::FirstName ); | 898 | firstName = find( Qtopia::FirstName ); |
826 | middleName = find( Qtopia::MiddleName ); | 899 | middleName = find( Qtopia::MiddleName ); |
827 | if ( !lastName.isEmpty() && !firstName.isEmpty() | 900 | if ( !lastName.isEmpty() && !firstName.isEmpty() |
828 | && !middleName.isEmpty() ) | 901 | && !middleName.isEmpty() ) |
829 | fileas = lastName + ", " + firstName + " " + middleName; | 902 | fileas = lastName + ", " + firstName + " " + middleName; |
830 | else if ( !lastName.isEmpty() && !firstName.isEmpty() ) | 903 | else if ( !lastName.isEmpty() && !firstName.isEmpty() ) |
831 | fileas = lastName + ", " + firstName; | 904 | fileas = lastName + ", " + firstName; |
832 | else if ( !lastName.isEmpty() || !firstName.isEmpty() || | 905 | else if ( !lastName.isEmpty() || !firstName.isEmpty() || |
833 | !middleName.isEmpty() ) | 906 | !middleName.isEmpty() ) |
834 | fileas = firstName + ( firstName.isEmpty() ? "" : " " ) | 907 | fileas = firstName + ( firstName.isEmpty() ? "" : " " ) |
835 | + middleName + ( middleName.isEmpty() ? "" : " " ) | 908 | + middleName + ( middleName.isEmpty() ? "" : " " ) |
836 | + lastName; | 909 | + lastName; |
837 | 910 | ||
838 | replace( Qtopia::FileAs, fileas ); | 911 | replace( Qtopia::FileAs, fileas ); |
839 | } | 912 | } |
840 | 913 | ||
841 | /*! | 914 | /*! |
842 | \internal | 915 | \internal |
843 | Appends the contact information to \a buf. | 916 | Appends the contact information to \a buf. |
844 | */ | 917 | */ |
845 | void OContact::save( QString &buf ) const | 918 | void OContact::save( QString &buf ) const |
846 | { | 919 | { |
847 | static const QStringList SLFIELDS = fields(); | 920 | static const QStringList SLFIELDS = fields(); |
848 | // I'm expecting "<Contact " in front of this... | 921 | // I'm expecting "<Contact " in front of this... |
849 | for ( QMap<int, QString>::ConstIterator it = mMap.begin(); | 922 | for ( QMap<int, QString>::ConstIterator it = mMap.begin(); |
850 | it != mMap.end(); ++it ) { | 923 | it != mMap.end(); ++it ) { |
851 | const QString &value = it.data(); | 924 | const QString &value = it.data(); |
852 | int key = it.key(); | 925 | int key = it.key(); |
853 | if ( !value.isEmpty() ) { | 926 | if ( !value.isEmpty() ) { |
854 | if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) | 927 | if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) |
855 | continue; | 928 | continue; |
856 | 929 | ||
857 | key -= Qtopia::AddressCategory+1; | 930 | key -= Qtopia::AddressCategory+1; |
858 | buf += SLFIELDS[key]; | 931 | buf += SLFIELDS[key]; |
859 | buf += "=\"" + Qtopia::escapeString(value) + "\" "; | 932 | buf += "=\"" + Qtopia::escapeString(value) + "\" "; |
860 | } | 933 | } |
861 | } | 934 | } |
862 | buf += customToXml(); | 935 | buf += customToXml(); |
863 | if ( categories().count() > 0 ) | 936 | if ( categories().count() > 0 ) |
864 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; | 937 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; |
865 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; | 938 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; |
866 | // You need to close this yourself | 939 | // You need to close this yourself |
867 | } | 940 | } |
868 | 941 | ||
869 | 942 | ||
870 | /*! | 943 | /*! |
871 | \internal | 944 | \internal |
872 | Returns the list of fields belonging to a contact | 945 | Returns the list of fields belonging to a contact |
873 | Never change order of this list ! It has to be regarding | 946 | Never change order of this list ! It has to be regarding |
874 | enum AddressBookFields !! | 947 | enum AddressBookFields !! |
875 | */ | 948 | */ |
876 | QStringList OContact::fields() | 949 | QStringList OContact::fields() |
877 | { | 950 | { |
878 | QStringList list; | 951 | QStringList list; |
879 | 952 | ||
880 | list.append( "Title" ); // Not Used! | 953 | list.append( "Title" ); // Not Used! |
881 | list.append( "FirstName" ); | 954 | list.append( "FirstName" ); |
882 | list.append( "MiddleName" ); | 955 | list.append( "MiddleName" ); |
883 | list.append( "LastName" ); | 956 | list.append( "LastName" ); |
884 | list.append( "Suffix" ); | 957 | list.append( "Suffix" ); |
885 | list.append( "FileAs" ); | 958 | list.append( "FileAs" ); |
886 | 959 | ||
887 | list.append( "JobTitle" ); | 960 | list.append( "JobTitle" ); |
888 | list.append( "Department" ); | 961 | list.append( "Department" ); |
889 | list.append( "Company" ); | 962 | list.append( "Company" ); |
890 | list.append( "BusinessPhone" ); | 963 | list.append( "BusinessPhone" ); |
891 | list.append( "BusinessFax" ); | 964 | list.append( "BusinessFax" ); |
892 | list.append( "BusinessMobile" ); | 965 | list.append( "BusinessMobile" ); |
893 | 966 | ||
894 | list.append( "DefaultEmail" ); | 967 | list.append( "DefaultEmail" ); |
895 | list.append( "Emails" ); | 968 | list.append( "Emails" ); |
896 | 969 | ||
897 | list.append( "HomePhone" ); | 970 | list.append( "HomePhone" ); |
898 | list.append( "HomeFax" ); | 971 | list.append( "HomeFax" ); |
899 | list.append( "HomeMobile" ); | 972 | list.append( "HomeMobile" ); |
900 | 973 | ||
901 | list.append( "BusinessStreet" ); | 974 | list.append( "BusinessStreet" ); |
902 | list.append( "BusinessCity" ); | 975 | list.append( "BusinessCity" ); |
903 | list.append( "BusinessState" ); | 976 | list.append( "BusinessState" ); |
904 | list.append( "BusinessZip" ); | 977 | list.append( "BusinessZip" ); |
905 | list.append( "BusinessCountry" ); | 978 | list.append( "BusinessCountry" ); |
906 | list.append( "BusinessPager" ); | 979 | list.append( "BusinessPager" ); |
907 | list.append( "BusinessWebPage" ); | 980 | list.append( "BusinessWebPage" ); |
908 | 981 | ||
909 | list.append( "Office" ); | 982 | list.append( "Office" ); |
910 | list.append( "Profession" ); | 983 | list.append( "Profession" ); |
911 | list.append( "Assistant" ); | 984 | list.append( "Assistant" ); |
912 | list.append( "Manager" ); | 985 | list.append( "Manager" ); |
913 | 986 | ||
914 | list.append( "HomeStreet" ); | 987 | list.append( "HomeStreet" ); |
915 | list.append( "HomeCity" ); | 988 | list.append( "HomeCity" ); |
916 | list.append( "HomeState" ); | 989 | list.append( "HomeState" ); |
917 | list.append( "HomeZip" ); | 990 | list.append( "HomeZip" ); |
918 | list.append( "HomeCountry" ); | 991 | list.append( "HomeCountry" ); |
919 | list.append( "HomeWebPage" ); | 992 | list.append( "HomeWebPage" ); |
920 | 993 | ||
921 | list.append( "Spouse" ); | 994 | list.append( "Spouse" ); |
922 | list.append( "Gender" ); | 995 | list.append( "Gender" ); |
923 | list.append( "Birthday" ); | 996 | list.append( "Birthday" ); |
924 | list.append( "Anniversary" ); | 997 | list.append( "Anniversary" ); |
925 | list.append( "Nickname" ); | 998 | list.append( "Nickname" ); |
926 | list.append( "Children" ); | 999 | list.append( "Children" ); |
927 | 1000 | ||
928 | list.append( "Notes" ); | 1001 | list.append( "Notes" ); |
929 | list.append( "Groups" ); | 1002 | list.append( "Groups" ); |
930 | 1003 | ||
931 | return list; | 1004 | return list; |
932 | } | 1005 | } |
933 | 1006 | ||
934 | 1007 | ||
935 | /*! | 1008 | /*! |
936 | Sets the list of email address for contact to those contained in \a str. | 1009 | Sets the list of email address for contact to those contained in \a str. |
937 | Email address should be separated by ';'s. | 1010 | Email address should be separated by ';'s. |
938 | */ | 1011 | */ |
939 | void OContact::setEmails( const QString &str ) | 1012 | void OContact::setEmails( const QString &str ) |
940 | { | 1013 | { |
941 | replace( Qtopia::Emails, str ); | 1014 | replace( Qtopia::Emails, str ); |
942 | if ( str.isEmpty() ) | 1015 | if ( str.isEmpty() ) |
943 | setDefaultEmail( QString::null ); | 1016 | setDefaultEmail( QString::null ); |
944 | } | 1017 | } |
945 | 1018 | ||
946 | /*! | 1019 | /*! |
947 | Sets the list of children for the contact to those contained in \a str. | 1020 | Sets the list of children for the contact to those contained in \a str. |
948 | */ | 1021 | */ |
949 | void OContact::setChildren( const QString &str ) | 1022 | void OContact::setChildren( const QString &str ) |
950 | { | 1023 | { |
951 | replace( Qtopia::Children, str ); | 1024 | replace( Qtopia::Children, str ); |
952 | } | 1025 | } |
953 | 1026 | ||
954 | /*! | 1027 | /*! |
955 | \overload | 1028 | \overload |
956 | Returns TRUE if the contact matches the regular expression \a regexp. | 1029 | Returns TRUE if the contact matches the regular expression \a regexp. |
957 | Otherwise returns FALSE. | 1030 | Otherwise returns FALSE. |
958 | */ | 1031 | */ |
959 | bool OContact::match( const QRegExp &r ) const | 1032 | bool OContact::match( const QRegExp &r ) const |
960 | { | 1033 | { |
961 | setLastHitField( -1 ); | 1034 | setLastHitField( -1 ); |
962 | bool match; | 1035 | bool match; |
963 | match = false; | 1036 | match = false; |
964 | QMap<int, QString>::ConstIterator it; | 1037 | QMap<int, QString>::ConstIterator it; |
965 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 1038 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
966 | if ( (*it).find( r ) > -1 ) { | 1039 | if ( (*it).find( r ) > -1 ) { |
967 | setLastHitField( it.key() ); | 1040 | setLastHitField( it.key() ); |
968 | match = true; | 1041 | match = true; |
969 | break; | 1042 | break; |
970 | } | 1043 | } |
971 | } | 1044 | } |
972 | return match; | 1045 | return match; |
973 | } | 1046 | } |
974 | 1047 | ||
975 | 1048 | ||
976 | QString OContact::toShortText() const | 1049 | QString OContact::toShortText() const |
977 | { | 1050 | { |
978 | return ( fullName() ); | 1051 | return ( fullName() ); |
979 | } | 1052 | } |
980 | QString OContact::type() const | 1053 | QString OContact::type() const |
981 | { | 1054 | { |
982 | return QString::fromLatin1( "OContact" ); | 1055 | return QString::fromLatin1( "OContact" ); |
983 | } | 1056 | } |
984 | 1057 | ||
985 | 1058 | ||
986 | 1059 | ||
987 | class QString OContact::recordField( int pos ) const | 1060 | class QString OContact::recordField( int pos ) const |
988 | { | 1061 | { |
989 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
990 | return SLFIELDS[pos]; | 1063 | return SLFIELDS[pos]; |
991 | } | 1064 | } |
992 | 1065 | ||
993 | // In future releases, we should store birthday and anniversary | 1066 | // In future releases, we should store birthday and anniversary |
994 | // internally as QDate instead of QString ! | 1067 | // internally as QDate instead of QString ! |
995 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
996 | 1069 | ||
997 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1070 | /*! \fn void OContact::setBirthday( const QDate& date ) |
998 | Sets the birthday for the contact to \a date. If date is null | 1071 | Sets the birthday for the contact to \a date. If date is null |
999 | the current stored date will be removed. | 1072 | the current stored date will be removed. |
1000 | */ | 1073 | */ |
1001 | void OContact::setBirthday( const QDate &v ) | 1074 | void OContact::setBirthday( const QDate &v ) |
1002 | { | 1075 | { |
1003 | if ( v.isNull() ){ | 1076 | if ( v.isNull() ){ |
1004 | qWarning( "Remove Birthday"); | 1077 | qWarning( "Remove Birthday"); |
1005 | replace( Qtopia::Birthday, QString::null ); | 1078 | replace( Qtopia::Birthday, QString::null ); |
1006 | return; | 1079 | return; |
1007 | } | 1080 | } |
1008 | 1081 | ||
1009 | if ( v.isValid() ) | 1082 | if ( v.isValid() ) |
1010 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); | 1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); |
1011 | 1084 | ||
1012 | } | 1085 | } |
1013 | 1086 | ||
1014 | 1087 | ||
1015 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1016 | Sets the anniversary of the contact to \a date. If date is | 1089 | Sets the anniversary of the contact to \a date. If date is |
1017 | null, the current stored date will be removed. | 1090 | null, the current stored date will be removed. |
1018 | */ | 1091 | */ |
1019 | void OContact::setAnniversary( const QDate &v ) | 1092 | void OContact::setAnniversary( const QDate &v ) |
1020 | { | 1093 | { |
1021 | if ( v.isNull() ){ | 1094 | if ( v.isNull() ){ |
1022 | qWarning( "Remove Anniversary"); | 1095 | qWarning( "Remove Anniversary"); |
1023 | replace( Qtopia::Anniversary, QString::null ); | 1096 | replace( Qtopia::Anniversary, QString::null ); |
1024 | return; | 1097 | return; |
1025 | } | 1098 | } |
1026 | 1099 | ||
1027 | if ( v.isValid() ) | 1100 | if ( v.isValid() ) |
1028 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); | 1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); |
1029 | } | 1102 | } |
1030 | 1103 | ||
1031 | /*! \fn QDate OContact::birthday() const | 1104 | /*! \fn QDate OContact::birthday() const |
1032 | Returns the birthday of the contact. | 1105 | Returns the birthday of the contact. |
1033 | */ | 1106 | */ |
1034 | QDate OContact::birthday() const | 1107 | QDate OContact::birthday() const |
1035 | { | 1108 | { |
1036 | QString str = find( Qtopia::Birthday ); | 1109 | QString str = find( Qtopia::Birthday ); |
1037 | qWarning ("Birthday %s", str.latin1() ); | 1110 | qWarning ("Birthday %s", str.latin1() ); |
1038 | if ( !str.isEmpty() ) | 1111 | if ( !str.isEmpty() ) |
1039 | return OConversion::dateFromString ( str ); | 1112 | return OConversion::dateFromString ( str ); |
1040 | else | 1113 | else |
1041 | return QDate(); | 1114 | return QDate(); |
1042 | } | 1115 | } |
1043 | 1116 | ||
1044 | 1117 | ||
1045 | /*! \fn QDate OContact::anniversary() const | 1118 | /*! \fn QDate OContact::anniversary() const |
1046 | Returns the anniversary of the contact. | 1119 | Returns the anniversary of the contact. |
1047 | */ | 1120 | */ |
1048 | QDate OContact::anniversary() const | 1121 | QDate OContact::anniversary() const |
1049 | { | 1122 | { |
1050 | QDate empty; | 1123 | QDate empty; |
1051 | QString str = find( Qtopia::Anniversary ); | 1124 | QString str = find( Qtopia::Anniversary ); |
1052 | qWarning ("Anniversary %s", str.latin1() ); | 1125 | qWarning ("Anniversary %s", str.latin1() ); |
1053 | if ( !str.isEmpty() ) | 1126 | if ( !str.isEmpty() ) |
1054 | return OConversion::dateFromString ( str ); | 1127 | return OConversion::dateFromString ( str ); |
1055 | else | 1128 | else |
1056 | return empty; | 1129 | return empty; |
1057 | } | 1130 | } |
1058 | 1131 | ||
1059 | 1132 | ||
1060 | void OContact::insertEmail( const QString &v ) | 1133 | void OContact::insertEmail( const QString &v ) |
1061 | { | 1134 | { |
1062 | //qDebug("insertEmail %s", v.latin1()); | 1135 | //qDebug("insertEmail %s", v.latin1()); |
1063 | QString e = v.simplifyWhiteSpace(); | 1136 | QString e = v.simplifyWhiteSpace(); |
1064 | QString def = defaultEmail(); | 1137 | QString def = defaultEmail(); |
1065 | 1138 | ||
1066 | // if no default, set it as the default email and don't insert | 1139 | // if no default, set it as the default email and don't insert |
1067 | if ( def.isEmpty() ) { | 1140 | if ( def.isEmpty() ) { |
1068 | setDefaultEmail( e ); // will insert into the list for us | 1141 | setDefaultEmail( e ); // will insert into the list for us |
1069 | return; | 1142 | return; |
1070 | } | 1143 | } |
1071 | 1144 | ||
1072 | // otherwise, insert assuming doesn't already exist | 1145 | // otherwise, insert assuming doesn't already exist |
1073 | QString emailsStr = find( Qtopia::Emails ); | 1146 | QString emailsStr = find( Qtopia::Emails ); |
1074 | if ( emailsStr.contains( e )) | 1147 | if ( emailsStr.contains( e )) |
1075 | return; | 1148 | return; |
1076 | if ( !emailsStr.isEmpty() ) | 1149 | if ( !emailsStr.isEmpty() ) |
1077 | emailsStr += emailSeparator(); | 1150 | emailsStr += emailSeparator(); |
1078 | emailsStr += e; | 1151 | emailsStr += e; |
1079 | replace( Qtopia::Emails, emailsStr ); | 1152 | replace( Qtopia::Emails, emailsStr ); |
1080 | } | 1153 | } |
1081 | 1154 | ||
1082 | void OContact::removeEmail( const QString &v ) | 1155 | void OContact::removeEmail( const QString &v ) |
1083 | { | 1156 | { |
1084 | QString e = v.simplifyWhiteSpace(); | 1157 | QString e = v.simplifyWhiteSpace(); |
1085 | QString def = defaultEmail(); | 1158 | QString def = defaultEmail(); |
1086 | QString emailsStr = find( Qtopia::Emails ); | 1159 | QString emailsStr = find( Qtopia::Emails ); |
1087 | QStringList emails = emailList(); | 1160 | QStringList emails = emailList(); |
1088 | 1161 | ||
1089 | // otherwise, must first contain it | 1162 | // otherwise, must first contain it |
1090 | if ( !emailsStr.contains( e ) ) | 1163 | if ( !emailsStr.contains( e ) ) |
1091 | return; | 1164 | return; |
1092 | 1165 | ||
1093 | // remove it | 1166 | // remove it |
1094 | //qDebug(" removing email from list %s", e.latin1()); | 1167 | //qDebug(" removing email from list %s", e.latin1()); |
1095 | emails.remove( e ); | 1168 | emails.remove( e ); |
1096 | // reset the string | 1169 | // reset the string |
1097 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1098 | replace( Qtopia::Emails, emailsStr ); | 1171 | replace( Qtopia::Emails, emailsStr ); |
1099 | 1172 | ||
1100 | // if default, then replace the default email with the first one | 1173 | // if default, then replace the default email with the first one |
1101 | if ( def == e ) { | 1174 | if ( def == e ) { |
1102 | //qDebug("removeEmail is default; setting new default"); | 1175 | //qDebug("removeEmail is default; setting new default"); |
1103 | if ( !emails.count() ) | 1176 | if ( !emails.count() ) |
1104 | clearEmails(); | 1177 | clearEmails(); |
1105 | else // setDefaultEmail will remove e from the list | 1178 | else // setDefaultEmail will remove e from the list |
1106 | setDefaultEmail( emails.first() ); | 1179 | setDefaultEmail( emails.first() ); |
1107 | } | 1180 | } |
1108 | } | 1181 | } |
1109 | void OContact::clearEmails() | 1182 | void OContact::clearEmails() |
1110 | { | 1183 | { |
1111 | mMap.remove( Qtopia::DefaultEmail ); | 1184 | mMap.remove( Qtopia::DefaultEmail ); |
1112 | mMap.remove( Qtopia::Emails ); | 1185 | mMap.remove( Qtopia::Emails ); |
1113 | } | 1186 | } |
1114 | void OContact::setDefaultEmail( const QString &v ) | 1187 | void OContact::setDefaultEmail( const QString &v ) |
1115 | { | 1188 | { |
1116 | QString e = v.simplifyWhiteSpace(); | 1189 | QString e = v.simplifyWhiteSpace(); |
1117 | 1190 | ||
1118 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); | 1191 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); |
1119 | replace( Qtopia::DefaultEmail, e ); | 1192 | replace( Qtopia::DefaultEmail, e ); |
1120 | 1193 | ||
1121 | if ( !e.isEmpty() ) | 1194 | if ( !e.isEmpty() ) |
1122 | insertEmail( e ); | 1195 | insertEmail( e ); |
1123 | 1196 | ||
1124 | } | 1197 | } |
1125 | 1198 | ||
1126 | void OContact::insertEmails( const QStringList &v ) | 1199 | void OContact::insertEmails( const QStringList &v ) |
1127 | { | 1200 | { |
1128 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | 1201 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) |
1129 | insertEmail( *it ); | 1202 | insertEmail( *it ); |
1130 | } | 1203 | } |
1131 | int OContact::rtti() { | 1204 | int OContact::rtti() { |
1132 | return OPimResolver::AddressBook; | 1205 | return OPimResolver::AddressBook; |
1133 | } | 1206 | } |
1134 | void OContact::setUid( int i ) | 1207 | void OContact::setUid( int i ) |
1135 | { | 1208 | { |
1136 | OPimRecord::setUid(i); | 1209 | OPimRecord::setUid(i); |
1137 | replace( Qtopia::AddressUid , QString::number(i)); | 1210 | replace( Qtopia::AddressUid , QString::number(i)); |
1138 | } | 1211 | } |
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h index dd2de17..9a1a8dc 100644 --- a/libopie/pim/ocontact.h +++ b/libopie/pim/ocontact.h | |||
@@ -1,240 +1,245 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #ifndef __OCONTACT_H__ | 20 | #ifndef __OCONTACT_H__ |
21 | #define __OCONTACT_H__ | 21 | #define __OCONTACT_H__ |
22 | 22 | ||
23 | #include <opie/opimrecord.h> | 23 | #include <opie/opimrecord.h> |
24 | #include <qpe/recordfields.h> | 24 | #include <qpe/recordfields.h> |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | 28 | ||
29 | #if defined(QPC_TEMPLATEDLL) | 29 | #if defined(QPC_TEMPLATEDLL) |
30 | // MOC_SKIP_BEGIN | 30 | // MOC_SKIP_BEGIN |
31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
32 | // MOC_SKIP_END | 32 | // MOC_SKIP_END |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | class ContactPrivate; | 35 | class OContactPrivate; |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * OContact class represents a specialised PIM Record for contacts. | 38 | * OContact class represents a specialised PIM Record for contacts. |
39 | * It does store all kind of persopn related information. | 39 | * It does store all kind of persopn related information. |
40 | * | 40 | * |
41 | * @short Contact Container | 41 | * @short Contact Container |
42 | * @author TT, Stefan Eiler, Holger Freyther | 42 | * @author TT, Stefan Eiler, Holger Freyther |
43 | */ | 43 | */ |
44 | class QPC_EXPORT OContact : public OPimRecord | 44 | class QPC_EXPORT OContact : public OPimRecord |
45 | { | 45 | { |
46 | friend class DataSet; | 46 | friend class DataSet; |
47 | public: | 47 | public: |
48 | OContact(); | 48 | OContact(); |
49 | OContact( const QMap<int, QString> &fromMap ); | 49 | OContact( const QMap<int, QString> &fromMap ); |
50 | virtual ~OContact(); | 50 | virtual ~OContact(); |
51 | 51 | ||
52 | enum DateFormat{ | ||
53 | Zip_City_State = 0, | ||
54 | City_State_Zip | ||
55 | }; | ||
56 | |||
52 | /* | 57 | /* |
53 | * do we need to inline them | 58 | * do we need to inline them |
54 | * if yes do we need to inline them this way? | 59 | * if yes do we need to inline them this way? |
55 | * -zecke | 60 | * -zecke |
56 | */ | 61 | */ |
57 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 62 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
58 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 63 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
59 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 64 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
60 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 65 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
61 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 66 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
62 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 67 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
63 | void setFileAs(); | 68 | void setFileAs(); |
64 | 69 | ||
65 | // default email address | 70 | // default email address |
66 | void setDefaultEmail( const QString &v ); | 71 | void setDefaultEmail( const QString &v ); |
67 | // inserts email to list and ensure's doesn't already exist | 72 | // inserts email to list and ensure's doesn't already exist |
68 | void insertEmail( const QString &v ); | 73 | void insertEmail( const QString &v ); |
69 | void removeEmail( const QString &v ); | 74 | void removeEmail( const QString &v ); |
70 | void clearEmails(); | 75 | void clearEmails(); |
71 | void insertEmails( const QStringList &v ); | 76 | void insertEmails( const QStringList &v ); |
72 | 77 | ||
73 | // home | 78 | // home |
74 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 79 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
75 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 80 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
76 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 81 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
77 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 82 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
78 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 83 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
79 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 84 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
80 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 85 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
81 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 86 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
82 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 87 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
83 | 88 | ||
84 | // business | 89 | // business |
85 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 90 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
86 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 91 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
87 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 92 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
88 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 93 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
89 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 94 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
90 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 95 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
91 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 96 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
92 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 97 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
93 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 98 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
94 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 99 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
95 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 100 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
96 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } | 101 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } |
97 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } | 102 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } |
98 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } | 103 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } |
99 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } | 104 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } |
100 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } | 105 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } |
101 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } | 106 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } |
102 | 107 | ||
103 | // personal | 108 | // personal |
104 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } | 109 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } |
105 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } | 110 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } |
106 | void setBirthday( const QDate &v ); | 111 | void setBirthday( const QDate &v ); |
107 | void setAnniversary( const QDate &v ); | 112 | void setAnniversary( const QDate &v ); |
108 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } | 113 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } |
109 | void setChildren( const QString &v ); | 114 | void setChildren( const QString &v ); |
110 | 115 | ||
111 | // other | 116 | // other |
112 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 117 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
113 | 118 | ||
114 | virtual bool match( const QRegExp ®exp ) const; | 119 | virtual bool match( const QRegExp ®exp ) const; |
115 | 120 | ||
116 | // // custom | 121 | // // custom |
117 | // void setCustomField( const QString &key, const QString &v ) | 122 | // void setCustomField( const QString &key, const QString &v ) |
118 | // { replace(Custom- + key, v ); } | 123 | // { replace(Custom- + key, v ); } |
119 | 124 | ||
120 | // name | 125 | // name |
121 | QString fullName() const; | 126 | QString fullName() const; |
122 | QString title() const { return find( Qtopia::Title ); } | 127 | QString title() const { return find( Qtopia::Title ); } |
123 | QString firstName() const { return find( Qtopia::FirstName ); } | 128 | QString firstName() const { return find( Qtopia::FirstName ); } |
124 | QString middleName() const { return find( Qtopia::MiddleName ); } | 129 | QString middleName() const { return find( Qtopia::MiddleName ); } |
125 | QString lastName() const { return find( Qtopia::LastName ); } | 130 | QString lastName() const { return find( Qtopia::LastName ); } |
126 | QString suffix() const { return find( Qtopia::Suffix ); } | 131 | QString suffix() const { return find( Qtopia::Suffix ); } |
127 | QString fileAs() const { return find( Qtopia::FileAs ); } | 132 | QString fileAs() const { return find( Qtopia::FileAs ); } |
128 | 133 | ||
129 | 134 | ||
130 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 135 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
131 | QStringList emailList() const; | 136 | QStringList emailList() const; |
132 | 137 | ||
133 | // home | 138 | // home |
134 | /* | 139 | /* |
135 | * OPimAddress address(enum Location)const; | 140 | * OPimAddress address(enum Location)const; |
136 | * would be some how nicer... | 141 | * would be some how nicer... |
137 | * -zecke | 142 | * -zecke |
138 | */ | 143 | */ |
139 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 144 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
140 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 145 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
141 | QString homeState() const { return find( Qtopia::HomeState ); } | 146 | QString homeState() const { return find( Qtopia::HomeState ); } |
142 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 147 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
143 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 148 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
144 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 149 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
145 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 150 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
146 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 151 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
147 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 152 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
148 | /** Multi line string containing all non-empty address info in the form | 153 | /** Multi line string containing all non-empty address info in the form |
149 | * Street | 154 | * Street |
150 | * City, State Zip | 155 | * City, State Zip |
151 | * Country | 156 | * Country |
152 | */ | 157 | */ |
153 | QString displayHomeAddress() const; | 158 | QString displayHomeAddress() const; |
154 | 159 | ||
155 | // business | 160 | // business |
156 | QString company() const { return find( Qtopia::Company ); } | 161 | QString company() const { return find( Qtopia::Company ); } |
157 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 162 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
158 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 163 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
159 | QString businessState() const { return find( Qtopia::BusinessState ); } | 164 | QString businessState() const { return find( Qtopia::BusinessState ); } |
160 | QString businessZip() const { return find( Qtopia::BusinessZip ); } | 165 | QString businessZip() const { return find( Qtopia::BusinessZip ); } |
161 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } | 166 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } |
162 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } | 167 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } |
163 | QString jobTitle() const { return find( Qtopia::JobTitle ); } | 168 | QString jobTitle() const { return find( Qtopia::JobTitle ); } |
164 | QString department() const { return find( Qtopia::Department ); } | 169 | QString department() const { return find( Qtopia::Department ); } |
165 | QString office() const { return find( Qtopia::Office ); } | 170 | QString office() const { return find( Qtopia::Office ); } |
166 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } | 171 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } |
167 | QString businessFax() const { return find( Qtopia::BusinessFax ); } | 172 | QString businessFax() const { return find( Qtopia::BusinessFax ); } |
168 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } | 173 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } |
169 | QString businessPager() const { return find( Qtopia::BusinessPager ); } | 174 | QString businessPager() const { return find( Qtopia::BusinessPager ); } |
170 | QString profession() const { return find( Qtopia::Profession ); } | 175 | QString profession() const { return find( Qtopia::Profession ); } |
171 | QString assistant() const { return find( Qtopia::Assistant ); } | 176 | QString assistant() const { return find( Qtopia::Assistant ); } |
172 | QString manager() const { return find( Qtopia::Manager ); } | 177 | QString manager() const { return find( Qtopia::Manager ); } |
173 | /** Multi line string containing all non-empty address info in the form | 178 | /** Multi line string containing all non-empty address info in the form |
174 | * Street | 179 | * Street |
175 | * City, State Zip | 180 | * City, State Zip |
176 | * Country | 181 | * Country |
177 | */ | 182 | */ |
178 | QString displayBusinessAddress() const; | 183 | QString displayBusinessAddress() const; |
179 | 184 | ||
180 | //personal | 185 | //personal |
181 | QString spouse() const { return find( Qtopia::Spouse ); } | 186 | QString spouse() const { return find( Qtopia::Spouse ); } |
182 | QString gender() const { return find( Qtopia::Gender ); } | 187 | QString gender() const { return find( Qtopia::Gender ); } |
183 | QDate birthday() const; | 188 | QDate birthday() const; |
184 | QDate anniversary() const; | 189 | QDate anniversary() const; |
185 | QString nickname() const { return find( Qtopia::Nickname ); } | 190 | QString nickname() const { return find( Qtopia::Nickname ); } |
186 | QString children() const { return find( Qtopia::Children ); } | 191 | QString children() const { return find( Qtopia::Children ); } |
187 | QStringList childrenList() const; | 192 | QStringList childrenList() const; |
188 | 193 | ||
189 | // other | 194 | // other |
190 | QString notes() const { return find( Qtopia::Notes ); } | 195 | QString notes() const { return find( Qtopia::Notes ); } |
191 | QString groups() const { return find( Qtopia::Groups ); } | 196 | QString groups() const { return find( Qtopia::Groups ); } |
192 | QStringList groupList() const; | 197 | QStringList groupList() const; |
193 | 198 | ||
194 | // // custom | 199 | // // custom |
195 | // const QString &customField( const QString &key ) | 200 | // const QString &customField( const QString &key ) |
196 | // { return find( Custom- + key ); } | 201 | // { return find( Custom- + key ); } |
197 | 202 | ||
198 | 203 | ||
199 | QString toRichText() const; | 204 | QString toRichText() const; |
200 | QMap<int, QString> toMap() const; | 205 | QMap<int, QString> toMap() const; |
201 | QString field( int key ) const { return find( key ); } | 206 | QString field( int key ) const { return find( key ); } |
202 | 207 | ||
203 | 208 | ||
204 | void setUid( int i ); | 209 | void setUid( int i ); |
205 | 210 | ||
206 | QString toShortText()const; | 211 | QString toShortText()const; |
207 | QString OContact::type()const; | 212 | QString OContact::type()const; |
208 | QMap<QString,QString> OContact::toExtraMap() const; | 213 | QMap<QString,QString> OContact::toExtraMap() const; |
209 | class QString OContact::recordField(int) const; | 214 | class QString OContact::recordField(int) const; |
210 | 215 | ||
211 | // Why private ? (eilers,se) | 216 | // Why private ? (eilers,se) |
212 | QString emailSeparator() const { return " "; } | 217 | QString emailSeparator() const { return " "; } |
213 | // the emails should be seperated by a comma | 218 | // the emails should be seperated by a comma |
214 | void setEmails( const QString &v ); | 219 | void setEmails( const QString &v ); |
215 | QString emails() const { return find( Qtopia::Emails ); } | 220 | QString emails() const { return find( Qtopia::Emails ); } |
216 | static int rtti(); | 221 | static int rtti(); |
217 | 222 | ||
218 | private: | 223 | private: |
219 | // The XML-Backend needs some access to the private functions | 224 | // The XML-Backend needs some access to the private functions |
220 | friend class OContactAccessBackend_XML; | 225 | friend class OContactAccessBackend_XML; |
221 | 226 | ||
222 | void insert( int key, const QString &value ); | 227 | void insert( int key, const QString &value ); |
223 | void replace( int key, const QString &value ); | 228 | void replace( int key, const QString &value ); |
224 | QString find( int key ) const; | 229 | QString find( int key ) const; |
225 | static QStringList fields(); | 230 | static QStringList fields(); |
226 | 231 | ||
227 | void save( QString &buf ) const; | 232 | void save( QString &buf ) const; |
228 | 233 | ||
229 | QString displayAddress( const QString &street, | 234 | QString displayAddress( const QString &street, |
230 | const QString &city, | 235 | const QString &city, |
231 | const QString &state, | 236 | const QString &state, |
232 | const QString &zip, | 237 | const QString &zip, |
233 | const QString &country ) const; | 238 | const QString &country ) const; |
234 | 239 | ||
235 | QMap<int, QString> mMap; | 240 | QMap<int, QString> mMap; |
236 | ContactPrivate *d; | 241 | OContactPrivate *d; |
237 | }; | 242 | }; |
238 | 243 | ||
239 | 244 | ||
240 | #endif | 245 | #endif |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index e90db32..9b0a719 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -1,170 +1,181 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | * Class to manage the Contacts. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.9 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.8.2.1 2003/06/30 14:34:19 eilers | ||
24 | * Patches from Zecke: | ||
25 | * Fixing and cleaning up extraMap handling | ||
26 | * Adding d_ptr for binary compatibility in the future | ||
27 | * | ||
20 | * Revision 1.8 2003/05/08 13:55:09 tille | 28 | * Revision 1.8 2003/05/08 13:55:09 tille |
21 | * search stuff | 29 | * search stuff |
22 | * and match, toRichText & toShortText in oevent | 30 | * and match, toRichText & toShortText in oevent |
23 | * | 31 | * |
24 | * Revision 1.7 2003/04/13 18:07:10 zecke | 32 | * Revision 1.7 2003/04/13 18:07:10 zecke |
25 | * More API doc | 33 | * More API doc |
26 | * QString -> const QString& | 34 | * QString -> const QString& |
27 | * QString = 0l -> QString::null | 35 | * QString = 0l -> QString::null |
28 | * | 36 | * |
29 | * Revision 1.6 2003/01/02 14:27:12 eilers | 37 | * Revision 1.6 2003/01/02 14:27:12 eilers |
30 | * Improved query by example: Search by date is possible.. First step | 38 | * Improved query by example: Search by date is possible.. First step |
31 | * for a today plugin for birthdays.. | 39 | * for a today plugin for birthdays.. |
32 | * | 40 | * |
33 | * Revision 1.5 2002/11/13 14:14:51 eilers | 41 | * Revision 1.5 2002/11/13 14:14:51 eilers |
34 | * Added sorted for Contacts.. | 42 | * Added sorted for Contacts.. |
35 | * | 43 | * |
36 | * Revision 1.4 2002/11/01 15:10:42 eilers | 44 | * Revision 1.4 2002/11/01 15:10:42 eilers |
37 | * Added regExp-search in database for all fields in a contact. | 45 | * Added regExp-search in database for all fields in a contact. |
38 | * | 46 | * |
39 | * Revision 1.3 2002/10/16 10:52:40 eilers | 47 | * Revision 1.3 2002/10/16 10:52:40 eilers |
40 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 48 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
41 | * | 49 | * |
42 | * Revision 1.2 2002/10/14 16:21:54 eilers | 50 | * Revision 1.2 2002/10/14 16:21:54 eilers |
43 | * Some minor interface updates | 51 | * Some minor interface updates |
44 | * | 52 | * |
45 | * Revision 1.1 2002/09/27 17:11:44 eilers | 53 | * Revision 1.1 2002/09/27 17:11:44 eilers |
46 | * Added API for accessing the Contact-Database ! It is compiling, but | 54 | * Added API for accessing the Contact-Database ! It is compiling, but |
47 | * please do not expect that anything is working ! | 55 | * please do not expect that anything is working ! |
48 | * I will debug that stuff in the next time .. | 56 | * I will debug that stuff in the next time .. |
49 | * Please read README_COMPILE for compiling ! | 57 | * Please read README_COMPILE for compiling ! |
50 | * | 58 | * |
51 | * ===================================================================== | 59 | * ===================================================================== |
52 | */ | 60 | */ |
53 | #ifndef _OCONTACTACCESS_H | 61 | #ifndef _OCONTACTACCESS_H |
54 | #define _OCONTACTACCESS_H | 62 | #define _OCONTACTACCESS_H |
55 | 63 | ||
56 | #include <qobject.h> | 64 | #include <qobject.h> |
57 | 65 | ||
58 | #include <qpe/qcopenvelope_qws.h> | 66 | #include <qpe/qcopenvelope_qws.h> |
59 | 67 | ||
60 | #include <qvaluelist.h> | 68 | #include <qvaluelist.h> |
61 | #include <qfileinfo.h> | 69 | #include <qfileinfo.h> |
62 | 70 | ||
63 | #include "ocontact.h" | 71 | #include "ocontact.h" |
64 | #include "ocontactaccessbackend.h" | 72 | #include "ocontactaccessbackend.h" |
65 | #include "opimaccesstemplate.h" | 73 | #include "opimaccesstemplate.h" |
66 | 74 | ||
67 | /** | 75 | /** |
68 | * Class to access the contacts database. | 76 | * Class to access the contacts database. |
69 | * This is just a frontend for the real database handling which is | 77 | * This is just a frontend for the real database handling which is |
70 | * done by the backend. | 78 | * done by the backend. |
71 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | 79 | * This class is used to access the Contacts on a system. This class as any OPIE PIM |
72 | * class is backend independent. | 80 | * class is backend independent. |
73 | 81 | ||
74 | * @see OPimAccessTemplate | 82 | * @see OPimAccessTemplate |
75 | */ | 83 | */ |
76 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 84 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
77 | { | 85 | { |
78 | Q_OBJECT | 86 | Q_OBJECT |
79 | 87 | ||
80 | public: | 88 | public: |
81 | /** | 89 | /** |
82 | * Create Database with contacts (addressbook). | 90 | * Create Database with contacts (addressbook). |
83 | * @param appname Name of application which wants access to the database | 91 | * @param appname Name of application which wants access to the database |
84 | * (i.e. "todolist") | 92 | * (i.e. "todolist") |
85 | * @param filename The name of the database file. If not set, the default one | 93 | * @param filename The name of the database file. If not set, the default one |
86 | * is used. | 94 | * is used. |
87 | * @param backend Pointer to an alternative Backend. If not set, we will use | 95 | * @param backend Pointer to an alternative Backend. If not set, we will use |
88 | * the default backend. | 96 | * the default backend. |
89 | * @param handlesync If <b>true</b> the database stores the current state | 97 | * @param handlesync If <b>true</b> the database stores the current state |
90 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 98 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
91 | * which are used before and after synchronisation. If the application wants | 99 | * which are used before and after synchronisation. If the application wants |
92 | * to react itself, it should be disabled by setting it to <b>false</b> | 100 | * to react itself, it should be disabled by setting it to <b>false</b> |
93 | * @see OContactAccessBackend | 101 | * @see OContactAccessBackend |
94 | */ | 102 | */ |
95 | OContactAccess (const QString appname, const QString filename = 0l, | 103 | OContactAccess (const QString appname, const QString filename = 0l, |
96 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 104 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
97 | ~OContactAccess (); | 105 | ~OContactAccess (); |
98 | 106 | ||
99 | /** Constants for query. | 107 | /** Constants for query. |
100 | * Use this constants to set the query parameters. | 108 | * Use this constants to set the query parameters. |
101 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 109 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
102 | * @see queryByExample() | 110 | * @see queryByExample() |
103 | */ | 111 | */ |
104 | enum QuerySettings { | 112 | enum QuerySettings { |
105 | WildCards = 0x0001, | 113 | WildCards = 0x0001, |
106 | IgnoreCase = 0x0002, | 114 | IgnoreCase = 0x0002, |
107 | RegExp = 0x0004, | 115 | RegExp = 0x0004, |
108 | ExactMatch = 0x0008, | 116 | ExactMatch = 0x0008, |
109 | MatchOne = 0x0010, // Only one Entry must match | 117 | MatchOne = 0x0010, // Only one Entry must match |
110 | DateDiff = 0x0020, // Find all entries from today until given date | 118 | DateDiff = 0x0020, // Find all entries from today until given date |
111 | DateYear = 0x0040, // The year matches | 119 | DateYear = 0x0040, // The year matches |
112 | DateMonth = 0x0080, // The month matches | 120 | DateMonth = 0x0080, // The month matches |
113 | DateDay = 0x0100, // The day matches | 121 | DateDay = 0x0100, // The day matches |
114 | }; | 122 | }; |
115 | 123 | ||
116 | 124 | ||
117 | /** Return all Contacts in a sorted manner. | 125 | /** Return all Contacts in a sorted manner. |
118 | * @param ascending true: Sorted in acending order. | 126 | * @param ascending true: Sorted in acending order. |
119 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 127 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
120 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 128 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
121 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 129 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
122 | */ | 130 | */ |
123 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 131 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
124 | 132 | ||
125 | /** Return all possible settings. | 133 | /** Return all possible settings. |
126 | * @return All settings provided by the current backend | 134 | * @return All settings provided by the current backend |
127 | * (i.e.: query_WildCards & query_IgnoreCase) | 135 | * (i.e.: query_WildCards & query_IgnoreCase) |
128 | */ | 136 | */ |
129 | const uint querySettings(); | 137 | const uint querySettings(); |
130 | 138 | ||
131 | /** Check whether settings are correct. | 139 | /** Check whether settings are correct. |
132 | * @return <i>true</i> if the given settings are correct and possible. | 140 | * @return <i>true</i> if the given settings are correct and possible. |
133 | */ | 141 | */ |
134 | bool hasQuerySettings ( int querySettings ) const; | 142 | bool hasQuerySettings ( int querySettings ) const; |
135 | 143 | ||
136 | /** | 144 | /** |
137 | * if the resource was changed externally. | 145 | * if the resource was changed externally. |
138 | * You should use the signal instead of polling possible changes ! | 146 | * You should use the signal instead of polling possible changes ! |
139 | */ | 147 | */ |
140 | bool wasChangedExternally()const; | 148 | bool wasChangedExternally()const; |
141 | 149 | ||
142 | 150 | ||
143 | /** Save contacts database. | 151 | /** Save contacts database. |
144 | * Save is more a "commit". After calling this function, all changes are public available. | 152 | * Save is more a "commit". After calling this function, all changes are public available. |
145 | * @return true if successful | 153 | * @return true if successful |
146 | */ | 154 | */ |
147 | bool save(); | 155 | bool save(); |
148 | 156 | ||
149 | signals: | 157 | signals: |
150 | /* Signal is emitted if the database was changed. Therefore | 158 | /* Signal is emitted if the database was changed. Therefore |
151 | * we may need to reload to stay consistent. | 159 | * we may need to reload to stay consistent. |
152 | * @param which Pointer to the database who created this event. This pointer | 160 | * @param which Pointer to the database who created this event. This pointer |
153 | * is useful if an application has to handle multiple databases at the same time. | 161 | * is useful if an application has to handle multiple databases at the same time. |
154 | * @see reload() | 162 | * @see reload() |
155 | */ | 163 | */ |
156 | void signalChanged ( const OContactAccess *which ); | 164 | void signalChanged ( const OContactAccess *which ); |
157 | 165 | ||
158 | 166 | ||
159 | private: | 167 | private: |
160 | // class OContactAccessPrivate; | 168 | // class OContactAccessPrivate; |
161 | // OContactAccessPrivate* d; | 169 | // OContactAccessPrivate* d; |
162 | OContactAccessBackend *m_backEnd; | 170 | OContactAccessBackend *m_backEnd; |
163 | bool m_loading:1; | 171 | bool m_loading:1; |
164 | 172 | ||
165 | private slots: | 173 | private slots: |
166 | void copMessage( const QCString &msg, const QByteArray &data ); | 174 | void copMessage( const QCString &msg, const QByteArray &data ); |
167 | 175 | ||
176 | private: | ||
177 | class Private; | ||
178 | Private *d; | ||
168 | 179 | ||
169 | }; | 180 | }; |
170 | #endif | 181 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h index ebeb42d..280e05c 100644 --- a/libopie/pim/ocontactaccessbackend.h +++ b/libopie/pim/ocontactaccessbackend.h | |||
@@ -1,107 +1,119 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.6 2003/08/01 12:30:16 eilers | ||
23 | * Merging changes from BRANCH_1_0 to HEAD | ||
24 | * | ||
25 | * Revision 1.5.4.1 2003/06/30 14:34:19 eilers | ||
26 | * Patches from Zecke: | ||
27 | * Fixing and cleaning up extraMap handling | ||
28 | * Adding d_ptr for binary compatibility in the future | ||
29 | * | ||
22 | * Revision 1.5 2003/04/13 18:07:10 zecke | 30 | * Revision 1.5 2003/04/13 18:07:10 zecke |
23 | * More API doc | 31 | * More API doc |
24 | * QString -> const QString& | 32 | * QString -> const QString& |
25 | * QString = 0l -> QString::null | 33 | * QString = 0l -> QString::null |
26 | * | 34 | * |
27 | * Revision 1.4 2002/11/13 14:14:51 eilers | 35 | * Revision 1.4 2002/11/13 14:14:51 eilers |
28 | * Added sorted for Contacts.. | 36 | * Added sorted for Contacts.. |
29 | * | 37 | * |
30 | * Revision 1.3 2002/11/01 15:10:42 eilers | 38 | * Revision 1.3 2002/11/01 15:10:42 eilers |
31 | * Added regExp-search in database for all fields in a contact. | 39 | * Added regExp-search in database for all fields in a contact. |
32 | * | 40 | * |
33 | * Revision 1.2 2002/10/07 17:34:24 eilers | 41 | * Revision 1.2 2002/10/07 17:34:24 eilers |
34 | * added OBackendFactory for advanced backend access | 42 | * added OBackendFactory for advanced backend access |
35 | * | 43 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 44 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 45 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 46 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 47 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 48 | * Please read README_COMPILE for compiling ! |
41 | * | 49 | * |
42 | * ===================================================================== | 50 | * ===================================================================== |
43 | * | 51 | * |
44 | */ | 52 | */ |
45 | 53 | ||
46 | #ifndef _OCONTACTACCESSBACKEND_H_ | 54 | #ifndef _OCONTACTACCESSBACKEND_H_ |
47 | #define _OCONTACTACCESSBACKEND_H_ | 55 | #define _OCONTACTACCESSBACKEND_H_ |
48 | 56 | ||
49 | #include "ocontact.h" | 57 | #include "ocontact.h" |
50 | #include "opimaccessbackend.h" | 58 | #include "opimaccessbackend.h" |
51 | 59 | ||
52 | #include <qregexp.h> | 60 | #include <qregexp.h> |
53 | 61 | ||
54 | /** | 62 | /** |
55 | * This class represents the interface of all Contact Backends. | 63 | * This class represents the interface of all Contact Backends. |
56 | * Derivates of this class will be used to access the contacts. | 64 | * Derivates of this class will be used to access the contacts. |
57 | * As implementation currently XML and vCard exist. This class needs to be implemented | 65 | * As implementation currently XML and vCard exist. This class needs to be implemented |
58 | * if you want to provide your own storage. | 66 | * if you want to provide your own storage. |
59 | * In all queries a list of uids is passed on instead of loading the actual record! | 67 | * In all queries a list of uids is passed on instead of loading the actual record! |
60 | * | 68 | * |
61 | * @see OContactAccessBackend_VCard | 69 | * @see OContactAccessBackend_VCard |
62 | * @see OContactAccessBackend_XML | 70 | * @see OContactAccessBackend_XML |
63 | */ | 71 | */ |
64 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 72 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
65 | public: | 73 | public: |
66 | OContactAccessBackend() {} | 74 | OContactAccessBackend() {} |
67 | virtual ~OContactAccessBackend() {} | 75 | virtual ~OContactAccessBackend() {} |
68 | 76 | ||
69 | 77 | ||
70 | /** | 78 | /** |
71 | * Return if database was changed externally. | 79 | * Return if database was changed externally. |
72 | * This may just make sense on file based databases like a XML-File. | 80 | * This may just make sense on file based databases like a XML-File. |
73 | * It is used to prevent to overwrite the current database content | 81 | * It is used to prevent to overwrite the current database content |
74 | * if the file was already changed by something else ! | 82 | * if the file was already changed by something else ! |
75 | * If this happens, we have to reload before save our data. | 83 | * If this happens, we have to reload before save our data. |
76 | * If we use real databases, this should be handled by the database | 84 | * If we use real databases, this should be handled by the database |
77 | * management system themselve, therefore this function should always return false in | 85 | * management system themselve, therefore this function should always return false in |
78 | * this case. It is not our problem to handle this conflict ... | 86 | * this case. It is not our problem to handle this conflict ... |
79 | * @return <i>true</i> if the database was changed and if save without reload will | 87 | * @return <i>true</i> if the database was changed and if save without reload will |
80 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 88 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
81 | * in this situation. | 89 | * in this situation. |
82 | */ | 90 | */ |
83 | virtual bool wasChangedExternally() = 0; | 91 | virtual bool wasChangedExternally() = 0; |
84 | 92 | ||
85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 93 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
86 | 94 | ||
87 | /** | 95 | /** |
88 | * Return all possible settings. | 96 | * Return all possible settings. |
89 | * @return All settings provided by the current backend | 97 | * @return All settings provided by the current backend |
90 | * (i.e.: query_WildCards & query_IgnoreCase) | 98 | * (i.e.: query_WildCards & query_IgnoreCase) |
91 | */ | 99 | */ |
92 | virtual const uint querySettings() = 0; | 100 | virtual const uint querySettings() = 0; |
93 | 101 | ||
94 | /** | 102 | /** |
95 | * Check whether settings are correct. | 103 | * Check whether settings are correct. |
96 | * @return <i>true</i> if the given settings are correct and possible. | 104 | * @return <i>true</i> if the given settings are correct and possible. |
97 | */ | 105 | */ |
98 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 106 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
99 | 107 | ||
100 | /** | 108 | /** |
101 | * FIXME!!! | 109 | * FIXME!!! |
102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | 110 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category |
103 | */ | 111 | */ |
104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 112 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; |
105 | 113 | ||
114 | |||
115 | private: | ||
116 | class Private; | ||
117 | Private *d; | ||
106 | }; | 118 | }; |
107 | #endif | 119 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index 270bef3..b60c5be 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,628 +1,646 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.11 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.10.4.3 2003/07/23 08:54:37 eilers | ||
24 | * Default email was added to the list of all emails, which already contains | ||
25 | * the default email.. | ||
26 | * This closes bug #1045 | ||
27 | * | ||
28 | * Revision 1.10.4.2 2003/07/23 08:44:45 eilers | ||
29 | * Importing of Notes in vcard files wasn't implemented. | ||
30 | * Closes bug #1044 | ||
31 | * | ||
32 | * Revision 1.10.4.1 2003/06/02 13:37:49 eilers | ||
33 | * Fixing memory leak | ||
34 | * | ||
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | 35 | * Revision 1.10 2003/04/13 18:07:10 zecke |
21 | * More API doc | 36 | * More API doc |
22 | * QString -> const QString& | 37 | * QString -> const QString& |
23 | * QString = 0l -> QString::null | 38 | * QString = 0l -> QString::null |
24 | * | 39 | * |
25 | * Revision 1.9 2003/03/21 10:33:09 eilers | 40 | * Revision 1.9 2003/03/21 10:33:09 eilers |
26 | * Merged speed optimized xml backend for contacts to main. | 41 | * Merged speed optimized xml backend for contacts to main. |
27 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 42 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
28 | * all Birthdays/Anniversaries between two dates. This should be used | 43 | * all Birthdays/Anniversaries between two dates. This should be used |
29 | * to show all birthdays in the datebook.. | 44 | * to show all birthdays in the datebook.. |
30 | * This change is sourcecode backward compatible but you have to upgrade | 45 | * This change is sourcecode backward compatible but you have to upgrade |
31 | * the binaries for today-addressbook. | 46 | * the binaries for today-addressbook. |
32 | * | 47 | * |
33 | * Revision 1.8 2003/02/21 16:52:49 zecke | 48 | * Revision 1.8 2003/02/21 16:52:49 zecke |
34 | * -Remove old Todo classes they're deprecated and today I already using the | 49 | * -Remove old Todo classes they're deprecated and today I already using the |
35 | * new API | 50 | * new API |
36 | * -Guard against self assignment in OTodo | 51 | * -Guard against self assignment in OTodo |
37 | * -Add test apps for OPIM | 52 | * -Add test apps for OPIM |
38 | * -Opiefied Event classes | 53 | * -Opiefied Event classes |
39 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 54 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
40 | * -Adjust ORecur and the widget to better timezone behaviour | 55 | * -Adjust ORecur and the widget to better timezone behaviour |
41 | * | 56 | * |
42 | * Revision 1.7 2003/02/16 22:25:46 zecke | 57 | * Revision 1.7 2003/02/16 22:25:46 zecke |
43 | * 0000276 Fix for that bug.. or better temp workaround | 58 | * 0000276 Fix for that bug.. or better temp workaround |
44 | * A Preferred Number is HOME|VOICE | 59 | * A Preferred Number is HOME|VOICE |
45 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | 60 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test |
46 | * triggers both | 61 | * triggers both |
47 | * and the cell phone number overrides the other entries.. | 62 | * and the cell phone number overrides the other entries.. |
48 | * | 63 | * |
49 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 64 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
50 | * number | 65 | * number |
51 | * | 66 | * |
52 | * The right and final fix would be to reorder the if statement to make it | 67 | * The right and final fix would be to reorder the if statement to make it |
53 | * if else based and the less common thing put to the bottom | 68 | * if else based and the less common thing put to the bottom |
54 | * | 69 | * |
55 | * OTodoAccessVcal fix the date for beaming | 70 | * OTodoAccessVcal fix the date for beaming |
56 | * | 71 | * |
57 | * Revision 1.6 2003/01/13 15:49:31 eilers | 72 | * Revision 1.6 2003/01/13 15:49:31 eilers |
58 | * Fixing crash when businesscard.vcf is missing.. | 73 | * Fixing crash when businesscard.vcf is missing.. |
59 | * | 74 | * |
60 | * Revision 1.5 2002/12/07 13:26:22 eilers | 75 | * Revision 1.5 2002/12/07 13:26:22 eilers |
61 | * Fixing bug in storing anniversary.. | 76 | * Fixing bug in storing anniversary.. |
62 | * | 77 | * |
63 | * Revision 1.4 2002/11/13 14:14:51 eilers | 78 | * Revision 1.4 2002/11/13 14:14:51 eilers |
64 | * Added sorted for Contacts.. | 79 | * Added sorted for Contacts.. |
65 | * | 80 | * |
66 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 81 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
67 | * no default arguments in implementation | 82 | * no default arguments in implementation |
68 | * | 83 | * |
69 | * Revision 1.2 2002/11/10 15:41:53 eilers | 84 | * Revision 1.2 2002/11/10 15:41:53 eilers |
70 | * Bugfixes.. | 85 | * Bugfixes.. |
71 | * | 86 | * |
72 | * Revision 1.1 2002/11/09 14:34:52 eilers | 87 | * Revision 1.1 2002/11/09 14:34:52 eilers |
73 | * Added VCard Backend. | 88 | * Added VCard Backend. |
74 | * | 89 | * |
75 | */ | 90 | */ |
76 | #include "ocontactaccessbackend_vcard.h" | 91 | #include "ocontactaccessbackend_vcard.h" |
77 | #include "../../library/backend/vobject_p.h" | 92 | #include "../../library/backend/vobject_p.h" |
78 | #include "../../library/backend/qfiledirect_p.h" | 93 | #include "../../library/backend/qfiledirect_p.h" |
79 | 94 | ||
80 | #include <qpe/timeconversion.h> | 95 | #include <qpe/timeconversion.h> |
81 | 96 | ||
82 | #include <qfile.h> | 97 | #include <qfile.h> |
83 | 98 | ||
84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): | 99 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
85 | m_dirty( false ), | 100 | m_dirty( false ), |
86 | m_file( filename ) | 101 | m_file( filename ) |
87 | { | 102 | { |
88 | load(); | 103 | load(); |
89 | } | 104 | } |
90 | 105 | ||
91 | 106 | ||
92 | bool OContactAccessBackend_VCard::load () | 107 | bool OContactAccessBackend_VCard::load () |
93 | { | 108 | { |
94 | m_map.clear(); | 109 | m_map.clear(); |
95 | m_dirty = false; | 110 | m_dirty = false; |
96 | 111 | ||
97 | VObject* obj = 0l; | 112 | VObject* obj = 0l; |
98 | 113 | ||
99 | if ( QFile::exists(m_file) ){ | 114 | if ( QFile::exists(m_file) ){ |
100 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 115 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
101 | if ( !obj ) | 116 | if ( !obj ) |
102 | return false; | 117 | return false; |
103 | }else{ | 118 | }else{ |
104 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 119 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
105 | return false; | 120 | return false; |
106 | } | 121 | } |
107 | 122 | ||
108 | while ( obj ) { | 123 | while ( obj ) { |
109 | OContact con = parseVObject( obj ); | 124 | OContact con = parseVObject( obj ); |
110 | /* | 125 | /* |
111 | * if uid is 0 assign a new one | 126 | * if uid is 0 assign a new one |
112 | * this at least happens on | 127 | * this at least happens on |
113 | * Nokia6210 | 128 | * Nokia6210 |
114 | */ | 129 | */ |
115 | if ( con.uid() == 0 ){ | 130 | if ( con.uid() == 0 ){ |
116 | con.setUid( 1 ); | 131 | con.setUid( 1 ); |
117 | qWarning("assigned new uid %d",con.uid() ); | 132 | qWarning("assigned new uid %d",con.uid() ); |
118 | } | 133 | } |
119 | 134 | ||
120 | m_map.insert( con.uid(), con ); | 135 | m_map.insert( con.uid(), con ); |
121 | 136 | ||
122 | VObject *t = obj; | 137 | VObject *t = obj; |
123 | obj = nextVObjectInList(obj); | 138 | obj = nextVObjectInList(obj); |
124 | cleanVObject( t ); | 139 | cleanVObject( t ); |
125 | } | 140 | } |
126 | 141 | ||
127 | return true; | 142 | return true; |
128 | 143 | ||
129 | } | 144 | } |
130 | bool OContactAccessBackend_VCard::reload() | 145 | bool OContactAccessBackend_VCard::reload() |
131 | { | 146 | { |
132 | return load(); | 147 | return load(); |
133 | } | 148 | } |
134 | bool OContactAccessBackend_VCard::save() | 149 | bool OContactAccessBackend_VCard::save() |
135 | { | 150 | { |
136 | if (!m_dirty ) | 151 | if (!m_dirty ) |
137 | return true; | 152 | return true; |
138 | 153 | ||
139 | QFileDirect file( m_file ); | 154 | QFileDirect file( m_file ); |
140 | if (!file.open(IO_WriteOnly ) ) | 155 | if (!file.open(IO_WriteOnly ) ) |
141 | return false; | 156 | return false; |
142 | 157 | ||
143 | VObject *obj; | 158 | VObject *obj; |
144 | obj = newVObject( VCCalProp ); | 159 | obj = newVObject( VCCalProp ); |
145 | addPropValue( obj, VCVersionProp, "1.0" ); | 160 | addPropValue( obj, VCVersionProp, "1.0" ); |
146 | 161 | ||
147 | VObject *vo; | 162 | VObject *vo; |
148 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 163 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
149 | vo = createVObject( *it ); | 164 | vo = createVObject( *it ); |
150 | writeVObject( file.directHandle() , vo ); | 165 | writeVObject( file.directHandle() , vo ); |
151 | cleanVObject( vo ); | 166 | cleanVObject( vo ); |
152 | } | 167 | } |
153 | cleanStrTbl(); | 168 | cleanStrTbl(); |
169 | deleteVObject( obj ); | ||
154 | 170 | ||
155 | m_dirty = false; | 171 | m_dirty = false; |
156 | return true; | 172 | return true; |
157 | 173 | ||
158 | 174 | ||
159 | } | 175 | } |
160 | void OContactAccessBackend_VCard::clear () | 176 | void OContactAccessBackend_VCard::clear () |
161 | { | 177 | { |
162 | m_map.clear(); | 178 | m_map.clear(); |
163 | m_dirty = true; // ??? sure ? (se) | 179 | m_dirty = true; // ??? sure ? (se) |
164 | } | 180 | } |
165 | 181 | ||
166 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 182 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
167 | { | 183 | { |
168 | m_map.insert( newcontact.uid(), newcontact ); | 184 | m_map.insert( newcontact.uid(), newcontact ); |
169 | m_dirty = true; | 185 | m_dirty = true; |
170 | return true; | 186 | return true; |
171 | } | 187 | } |
172 | 188 | ||
173 | bool OContactAccessBackend_VCard::remove ( int uid ) | 189 | bool OContactAccessBackend_VCard::remove ( int uid ) |
174 | { | 190 | { |
175 | m_map.remove( uid ); | 191 | m_map.remove( uid ); |
176 | m_dirty = true; | 192 | m_dirty = true; |
177 | return true; | 193 | return true; |
178 | } | 194 | } |
179 | 195 | ||
180 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 196 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
181 | { | 197 | { |
182 | m_map.replace( contact.uid(), contact ); | 198 | m_map.replace( contact.uid(), contact ); |
183 | m_dirty = true; | 199 | m_dirty = true; |
184 | return true; | 200 | return true; |
185 | } | 201 | } |
186 | 202 | ||
187 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 203 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
188 | { | 204 | { |
189 | return m_map[uid]; | 205 | return m_map[uid]; |
190 | } | 206 | } |
191 | 207 | ||
192 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 208 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
193 | { | 209 | { |
194 | QArray<int> ar( m_map.count() ); | 210 | QArray<int> ar( m_map.count() ); |
195 | QMap<int, OContact>::ConstIterator it; | 211 | QMap<int, OContact>::ConstIterator it; |
196 | int i = 0; | 212 | int i = 0; |
197 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 213 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
198 | ar[i] = it.key(); | 214 | ar[i] = it.key(); |
199 | i++; | 215 | i++; |
200 | } | 216 | } |
201 | return ar; | 217 | return ar; |
202 | } | 218 | } |
203 | 219 | ||
204 | // Not implemented | 220 | // Not implemented |
205 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) | 221 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) |
206 | { | 222 | { |
207 | QArray<int> ar(0); | 223 | QArray<int> ar(0); |
208 | return ar; | 224 | return ar; |
209 | } | 225 | } |
210 | 226 | ||
211 | // Not implemented | 227 | // Not implemented |
212 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 228 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
213 | { | 229 | { |
214 | QArray<int> ar(0); | 230 | QArray<int> ar(0); |
215 | return ar; | 231 | return ar; |
216 | } | 232 | } |
217 | 233 | ||
218 | const uint OContactAccessBackend_VCard::querySettings() | 234 | const uint OContactAccessBackend_VCard::querySettings() |
219 | { | 235 | { |
220 | return 0; // No search possible | 236 | return 0; // No search possible |
221 | } | 237 | } |
222 | 238 | ||
223 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 239 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
224 | { | 240 | { |
225 | return false; // No search possible, therefore all settings invalid ;) | 241 | return false; // No search possible, therefore all settings invalid ;) |
226 | } | 242 | } |
227 | 243 | ||
228 | bool OContactAccessBackend_VCard::wasChangedExternally() | 244 | bool OContactAccessBackend_VCard::wasChangedExternally() |
229 | { | 245 | { |
230 | return false; // Don't expect concurrent access | 246 | return false; // Don't expect concurrent access |
231 | } | 247 | } |
232 | 248 | ||
233 | // Not implemented | 249 | // Not implemented |
234 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 250 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) |
235 | { | 251 | { |
236 | QArray<int> ar(0); | 252 | QArray<int> ar(0); |
237 | return ar; | 253 | return ar; |
238 | } | 254 | } |
239 | 255 | ||
240 | // *** Private stuff *** | 256 | // *** Private stuff *** |
241 | 257 | ||
242 | 258 | ||
243 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 259 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
244 | { | 260 | { |
245 | OContact c; | 261 | OContact c; |
246 | 262 | ||
247 | VObjectIterator it; | 263 | VObjectIterator it; |
248 | initPropIterator( &it, obj ); | 264 | initPropIterator( &it, obj ); |
249 | while( moreIteration( &it ) ) { | 265 | while( moreIteration( &it ) ) { |
250 | VObject *o = nextVObject( &it ); | 266 | VObject *o = nextVObject( &it ); |
251 | QCString name = vObjectName( o ); | 267 | QCString name = vObjectName( o ); |
252 | QCString value = vObjectStringZValue( o ); | 268 | QCString value = vObjectStringZValue( o ); |
253 | if ( name == VCNameProp ) { | 269 | if ( name == VCNameProp ) { |
254 | VObjectIterator nit; | 270 | VObjectIterator nit; |
255 | initPropIterator( &nit, o ); | 271 | initPropIterator( &nit, o ); |
256 | while( moreIteration( &nit ) ) { | 272 | while( moreIteration( &nit ) ) { |
257 | VObject *o = nextVObject( &nit ); | 273 | VObject *o = nextVObject( &nit ); |
258 | QCString name = vObjectTypeInfo( o ); | 274 | QCString name = vObjectTypeInfo( o ); |
259 | QString value = vObjectStringZValue( o ); | 275 | QString value = vObjectStringZValue( o ); |
260 | if ( name == VCNamePrefixesProp ) | 276 | if ( name == VCNamePrefixesProp ) |
261 | c.setTitle( value ); | 277 | c.setTitle( value ); |
262 | else if ( name == VCNameSuffixesProp ) | 278 | else if ( name == VCNameSuffixesProp ) |
263 | c.setSuffix( value ); | 279 | c.setSuffix( value ); |
264 | else if ( name == VCFamilyNameProp ) | 280 | else if ( name == VCFamilyNameProp ) |
265 | c.setLastName( value ); | 281 | c.setLastName( value ); |
266 | else if ( name == VCGivenNameProp ) | 282 | else if ( name == VCGivenNameProp ) |
267 | c.setFirstName( value ); | 283 | c.setFirstName( value ); |
268 | else if ( name == VCAdditionalNamesProp ) | 284 | else if ( name == VCAdditionalNamesProp ) |
269 | c.setMiddleName( value ); | 285 | c.setMiddleName( value ); |
270 | } | 286 | } |
271 | } | 287 | } |
272 | else if ( name == VCAdrProp ) { | 288 | else if ( name == VCAdrProp ) { |
273 | bool work = TRUE; // default address is work address | 289 | bool work = TRUE; // default address is work address |
274 | QString street; | 290 | QString street; |
275 | QString city; | 291 | QString city; |
276 | QString region; | 292 | QString region; |
277 | QString postal; | 293 | QString postal; |
278 | QString country; | 294 | QString country; |
279 | 295 | ||
280 | VObjectIterator nit; | 296 | VObjectIterator nit; |
281 | initPropIterator( &nit, o ); | 297 | initPropIterator( &nit, o ); |
282 | while( moreIteration( &nit ) ) { | 298 | while( moreIteration( &nit ) ) { |
283 | VObject *o = nextVObject( &nit ); | 299 | VObject *o = nextVObject( &nit ); |
284 | QCString name = vObjectName( o ); | 300 | QCString name = vObjectName( o ); |
285 | QString value = vObjectStringZValue( o ); | 301 | QString value = vObjectStringZValue( o ); |
286 | if ( name == VCHomeProp ) | 302 | if ( name == VCHomeProp ) |
287 | work = FALSE; | 303 | work = FALSE; |
288 | else if ( name == VCWorkProp ) | 304 | else if ( name == VCWorkProp ) |
289 | work = TRUE; | 305 | work = TRUE; |
290 | else if ( name == VCStreetAddressProp ) | 306 | else if ( name == VCStreetAddressProp ) |
291 | street = value; | 307 | street = value; |
292 | else if ( name == VCCityProp ) | 308 | else if ( name == VCCityProp ) |
293 | city = value; | 309 | city = value; |
294 | else if ( name == VCRegionProp ) | 310 | else if ( name == VCRegionProp ) |
295 | region = value; | 311 | region = value; |
296 | else if ( name == VCPostalCodeProp ) | 312 | else if ( name == VCPostalCodeProp ) |
297 | postal = value; | 313 | postal = value; |
298 | else if ( name == VCCountryNameProp ) | 314 | else if ( name == VCCountryNameProp ) |
299 | country = value; | 315 | country = value; |
300 | } | 316 | } |
301 | if ( work ) { | 317 | if ( work ) { |
302 | c.setBusinessStreet( street ); | 318 | c.setBusinessStreet( street ); |
303 | c.setBusinessCity( city ); | 319 | c.setBusinessCity( city ); |
304 | c.setBusinessCountry( country ); | 320 | c.setBusinessCountry( country ); |
305 | c.setBusinessZip( postal ); | 321 | c.setBusinessZip( postal ); |
306 | c.setBusinessState( region ); | 322 | c.setBusinessState( region ); |
307 | } else { | 323 | } else { |
308 | c.setHomeStreet( street ); | 324 | c.setHomeStreet( street ); |
309 | c.setHomeCity( city ); | 325 | c.setHomeCity( city ); |
310 | c.setHomeCountry( country ); | 326 | c.setHomeCountry( country ); |
311 | c.setHomeZip( postal ); | 327 | c.setHomeZip( postal ); |
312 | c.setHomeState( region ); | 328 | c.setHomeState( region ); |
313 | } | 329 | } |
314 | } | 330 | } |
315 | else if ( name == VCTelephoneProp ) { | 331 | else if ( name == VCTelephoneProp ) { |
316 | enum { | 332 | enum { |
317 | HOME = 0x01, | 333 | HOME = 0x01, |
318 | WORK = 0x02, | 334 | WORK = 0x02, |
319 | VOICE = 0x04, | 335 | VOICE = 0x04, |
320 | CELL = 0x08, | 336 | CELL = 0x08, |
321 | FAX = 0x10, | 337 | FAX = 0x10, |
322 | PAGER = 0x20, | 338 | PAGER = 0x20, |
323 | UNKNOWN = 0x80 | 339 | UNKNOWN = 0x80 |
324 | }; | 340 | }; |
325 | int type = 0; | 341 | int type = 0; |
326 | 342 | ||
327 | VObjectIterator nit; | 343 | VObjectIterator nit; |
328 | initPropIterator( &nit, o ); | 344 | initPropIterator( &nit, o ); |
329 | while( moreIteration( &nit ) ) { | 345 | while( moreIteration( &nit ) ) { |
330 | VObject *o = nextVObject( &nit ); | 346 | VObject *o = nextVObject( &nit ); |
331 | QCString name = vObjectTypeInfo( o ); | 347 | QCString name = vObjectTypeInfo( o ); |
332 | if ( name == VCHomeProp ) | 348 | if ( name == VCHomeProp ) |
333 | type |= HOME; | 349 | type |= HOME; |
334 | else if ( name == VCWorkProp ) | 350 | else if ( name == VCWorkProp ) |
335 | type |= WORK; | 351 | type |= WORK; |
336 | else if ( name == VCVoiceProp ) | 352 | else if ( name == VCVoiceProp ) |
337 | type |= VOICE; | 353 | type |= VOICE; |
338 | else if ( name == VCCellularProp ) | 354 | else if ( name == VCCellularProp ) |
339 | type |= CELL; | 355 | type |= CELL; |
340 | else if ( name == VCFaxProp ) | 356 | else if ( name == VCFaxProp ) |
341 | type |= FAX; | 357 | type |= FAX; |
342 | else if ( name == VCPagerProp ) | 358 | else if ( name == VCPagerProp ) |
343 | type |= PAGER; | 359 | type |= PAGER; |
344 | else if ( name == VCPreferredProp ) | 360 | else if ( name == VCPreferredProp ) |
345 | ; | 361 | ; |
346 | else | 362 | else |
347 | type |= UNKNOWN; | 363 | type |= UNKNOWN; |
348 | } | 364 | } |
349 | if ( (type & UNKNOWN) != UNKNOWN ) { | 365 | if ( (type & UNKNOWN) != UNKNOWN ) { |
350 | if ( ( type & (HOME|WORK) ) == 0 ) // default | 366 | if ( ( type & (HOME|WORK) ) == 0 ) // default |
351 | type |= HOME; | 367 | type |= HOME; |
352 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | 368 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default |
353 | type |= VOICE; | 369 | type |= VOICE; |
354 | 370 | ||
355 | qWarning("value %s %d", value.data(), type ); | 371 | qWarning("value %s %d", value.data(), type ); |
356 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) | 372 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) |
357 | c.setHomePhone( value ); | 373 | c.setHomePhone( value ); |
358 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 374 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
359 | c.setHomeFax( value ); | 375 | c.setHomeFax( value ); |
360 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 376 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
361 | c.setHomeMobile( value ); | 377 | c.setHomeMobile( value ); |
362 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) | 378 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) |
363 | c.setBusinessPhone( value ); | 379 | c.setBusinessPhone( value ); |
364 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | 380 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) |
365 | c.setBusinessFax( value ); | 381 | c.setBusinessFax( value ); |
366 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | 382 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) |
367 | c.setBusinessMobile( value ); | 383 | c.setBusinessMobile( value ); |
368 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 384 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
369 | c.setBusinessPager( value ); | 385 | c.setBusinessPager( value ); |
370 | } | 386 | } |
371 | } | 387 | } |
372 | else if ( name == VCEmailAddressProp ) { | 388 | else if ( name == VCEmailAddressProp ) { |
373 | QString email = vObjectStringZValue( o ); | 389 | QString email = vObjectStringZValue( o ); |
374 | bool valid = TRUE; | 390 | bool valid = TRUE; |
375 | VObjectIterator nit; | 391 | VObjectIterator nit; |
376 | initPropIterator( &nit, o ); | 392 | initPropIterator( &nit, o ); |
377 | while( moreIteration( &nit ) ) { | 393 | while( moreIteration( &nit ) ) { |
378 | VObject *o = nextVObject( &nit ); | 394 | VObject *o = nextVObject( &nit ); |
379 | QCString name = vObjectTypeInfo( o ); | 395 | QCString name = vObjectTypeInfo( o ); |
380 | if ( name != VCInternetProp && name != VCHomeProp && | 396 | if ( name != VCInternetProp && name != VCHomeProp && |
381 | name != VCWorkProp && | 397 | name != VCWorkProp && |
382 | name != VCPreferredProp ) | 398 | name != VCPreferredProp ) |
383 | // ### preffered should map to default email | 399 | // ### preffered should map to default email |
384 | valid = FALSE; | 400 | valid = FALSE; |
385 | } | 401 | } |
386 | if ( valid ) { | 402 | if ( valid ) { |
387 | c.insertEmail( email ); | 403 | c.insertEmail( email ); |
388 | } | 404 | } |
389 | } | 405 | } |
390 | else if ( name == VCURLProp ) { | 406 | else if ( name == VCURLProp ) { |
391 | VObjectIterator nit; | 407 | VObjectIterator nit; |
392 | initPropIterator( &nit, o ); | 408 | initPropIterator( &nit, o ); |
393 | while( moreIteration( &nit ) ) { | 409 | while( moreIteration( &nit ) ) { |
394 | VObject *o = nextVObject( &nit ); | 410 | VObject *o = nextVObject( &nit ); |
395 | QCString name = vObjectTypeInfo( o ); | 411 | QCString name = vObjectTypeInfo( o ); |
396 | if ( name == VCHomeProp ) | 412 | if ( name == VCHomeProp ) |
397 | c.setHomeWebpage( value ); | 413 | c.setHomeWebpage( value ); |
398 | else if ( name == VCWorkProp ) | 414 | else if ( name == VCWorkProp ) |
399 | c.setBusinessWebpage( value ); | 415 | c.setBusinessWebpage( value ); |
400 | } | 416 | } |
401 | } | 417 | } |
402 | else if ( name == VCOrgProp ) { | 418 | else if ( name == VCOrgProp ) { |
403 | VObjectIterator nit; | 419 | VObjectIterator nit; |
404 | initPropIterator( &nit, o ); | 420 | initPropIterator( &nit, o ); |
405 | while( moreIteration( &nit ) ) { | 421 | while( moreIteration( &nit ) ) { |
406 | VObject *o = nextVObject( &nit ); | 422 | VObject *o = nextVObject( &nit ); |
407 | QCString name = vObjectName( o ); | 423 | QCString name = vObjectName( o ); |
408 | QString value = vObjectStringZValue( o ); | 424 | QString value = vObjectStringZValue( o ); |
409 | if ( name == VCOrgNameProp ) | 425 | if ( name == VCOrgNameProp ) |
410 | c.setCompany( value ); | 426 | c.setCompany( value ); |
411 | else if ( name == VCOrgUnitProp ) | 427 | else if ( name == VCOrgUnitProp ) |
412 | c.setDepartment( value ); | 428 | c.setDepartment( value ); |
413 | else if ( name == VCOrgUnit2Prop ) | 429 | else if ( name == VCOrgUnit2Prop ) |
414 | c.setOffice( value ); | 430 | c.setOffice( value ); |
415 | } | 431 | } |
416 | } | 432 | } |
417 | else if ( name == VCTitleProp ) { | 433 | else if ( name == VCTitleProp ) { |
418 | c.setJobTitle( value ); | 434 | c.setJobTitle( value ); |
419 | } | 435 | } |
420 | else if ( name == "X-Qtopia-Profession" ) { | 436 | else if ( name == "X-Qtopia-Profession" ) { |
421 | c.setProfession( value ); | 437 | c.setProfession( value ); |
422 | } | 438 | } |
423 | else if ( name == "X-Qtopia-Manager" ) { | 439 | else if ( name == "X-Qtopia-Manager" ) { |
424 | c.setManager( value ); | 440 | c.setManager( value ); |
425 | } | 441 | } |
426 | else if ( name == "X-Qtopia-Assistant" ) { | 442 | else if ( name == "X-Qtopia-Assistant" ) { |
427 | c.setAssistant( value ); | 443 | c.setAssistant( value ); |
428 | } | 444 | } |
429 | else if ( name == "X-Qtopia-Spouse" ) { | 445 | else if ( name == "X-Qtopia-Spouse" ) { |
430 | c.setSpouse( value ); | 446 | c.setSpouse( value ); |
431 | } | 447 | } |
432 | else if ( name == "X-Qtopia-Gender" ) { | 448 | else if ( name == "X-Qtopia-Gender" ) { |
433 | c.setGender( value ); | 449 | c.setGender( value ); |
434 | } | 450 | } |
435 | else if ( name == "X-Qtopia-Anniversary" ) { | 451 | else if ( name == "X-Qtopia-Anniversary" ) { |
436 | c.setAnniversary( convVCardDateToDate( value ) ); | 452 | c.setAnniversary( convVCardDateToDate( value ) ); |
437 | } | 453 | } |
438 | else if ( name == "X-Qtopia-Nickname" ) { | 454 | else if ( name == "X-Qtopia-Nickname" ) { |
439 | c.setNickname( value ); | 455 | c.setNickname( value ); |
440 | } | 456 | } |
441 | else if ( name == "X-Qtopia-Children" ) { | 457 | else if ( name == "X-Qtopia-Children" ) { |
442 | c.setChildren( value ); | 458 | c.setChildren( value ); |
443 | } | 459 | } |
444 | else if ( name == VCBirthDateProp ) { | 460 | else if ( name == VCBirthDateProp ) { |
445 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 461 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
446 | c.setBirthday( convVCardDateToDate( value ) ); | 462 | c.setBirthday( convVCardDateToDate( value ) ); |
447 | 463 | ||
448 | } | 464 | } |
449 | 465 | else if ( name == VCCommentProp ) { | |
466 | c.setNotes( value ); | ||
467 | } | ||
450 | #if 0 | 468 | #if 0 |
451 | else { | 469 | else { |
452 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 470 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
453 | VObjectIterator nit; | 471 | VObjectIterator nit; |
454 | initPropIterator( &nit, o ); | 472 | initPropIterator( &nit, o ); |
455 | while( moreIteration( &nit ) ) { | 473 | while( moreIteration( &nit ) ) { |
456 | VObject *o = nextVObject( &nit ); | 474 | VObject *o = nextVObject( &nit ); |
457 | QCString name = vObjectName( o ); | 475 | QCString name = vObjectName( o ); |
458 | QString value = vObjectStringZValue( o ); | 476 | QString value = vObjectStringZValue( o ); |
459 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 477 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
460 | } | 478 | } |
461 | } | 479 | } |
462 | #endif | 480 | #endif |
463 | } | 481 | } |
464 | c.setFileAs(); | 482 | c.setFileAs(); |
465 | return c; | 483 | return c; |
466 | } | 484 | } |
467 | 485 | ||
468 | 486 | ||
469 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 487 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
470 | { | 488 | { |
471 | VObject *vcard = newVObject( VCCardProp ); | 489 | VObject *vcard = newVObject( VCCardProp ); |
472 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 490 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
473 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 491 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
474 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 492 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
475 | 493 | ||
476 | // full name | 494 | // full name |
477 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 495 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
478 | 496 | ||
479 | // name properties | 497 | // name properties |
480 | VObject *name = safeAddProp( vcard, VCNameProp ); | 498 | VObject *name = safeAddProp( vcard, VCNameProp ); |
481 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 499 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
482 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 500 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
483 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 501 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
484 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 502 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
485 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 503 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
486 | 504 | ||
487 | // home properties | 505 | // home properties |
488 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 506 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
489 | safeAddProp( home_adr, VCHomeProp ); | 507 | safeAddProp( home_adr, VCHomeProp ); |
490 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 508 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
491 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 509 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |
492 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); | 510 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); |
493 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); | 511 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); |
494 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); | 512 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); |
495 | 513 | ||
496 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); | 514 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); |
497 | safeAddProp( home_phone, VCHomeProp ); | 515 | safeAddProp( home_phone, VCHomeProp ); |
498 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); | 516 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); |
499 | safeAddProp( home_phone, VCHomeProp ); | 517 | safeAddProp( home_phone, VCHomeProp ); |
500 | safeAddProp( home_phone, VCCellularProp ); | 518 | safeAddProp( home_phone, VCCellularProp ); |
501 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); | 519 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); |
502 | safeAddProp( home_phone, VCHomeProp ); | 520 | safeAddProp( home_phone, VCHomeProp ); |
503 | safeAddProp( home_phone, VCFaxProp ); | 521 | safeAddProp( home_phone, VCFaxProp ); |
504 | 522 | ||
505 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); | 523 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); |
506 | safeAddProp( url, VCHomeProp ); | 524 | safeAddProp( url, VCHomeProp ); |
507 | 525 | ||
508 | // work properties | 526 | // work properties |
509 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); | 527 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); |
510 | safeAddProp( work_adr, VCWorkProp ); | 528 | safeAddProp( work_adr, VCWorkProp ); |
511 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); | 529 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); |
512 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); | 530 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); |
513 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | 531 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); |
514 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | 532 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); |
515 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 533 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
516 | 534 | ||
517 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 535 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
518 | safeAddProp( work_phone, VCWorkProp ); | 536 | safeAddProp( work_phone, VCWorkProp ); |
519 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 537 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
520 | safeAddProp( work_phone, VCWorkProp ); | 538 | safeAddProp( work_phone, VCWorkProp ); |
521 | safeAddProp( work_phone, VCCellularProp ); | 539 | safeAddProp( work_phone, VCCellularProp ); |
522 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 540 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
523 | safeAddProp( work_phone, VCWorkProp ); | 541 | safeAddProp( work_phone, VCWorkProp ); |
524 | safeAddProp( work_phone, VCFaxProp ); | 542 | safeAddProp( work_phone, VCFaxProp ); |
525 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 543 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
526 | safeAddProp( work_phone, VCWorkProp ); | 544 | safeAddProp( work_phone, VCWorkProp ); |
527 | safeAddProp( work_phone, VCPagerProp ); | 545 | safeAddProp( work_phone, VCPagerProp ); |
528 | 546 | ||
529 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 547 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
530 | safeAddProp( url, VCWorkProp ); | 548 | safeAddProp( url, VCWorkProp ); |
531 | 549 | ||
532 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 550 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
533 | safeAddProp( title, VCWorkProp ); | 551 | safeAddProp( title, VCWorkProp ); |
534 | 552 | ||
535 | 553 | ||
536 | QStringList emails = c.emailList(); | 554 | QStringList emails = c.emailList(); |
537 | emails.prepend( c.defaultEmail() ); | 555 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 |
538 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 556 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
539 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 557 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
540 | safeAddProp( email, VCInternetProp ); | 558 | safeAddProp( email, VCInternetProp ); |
541 | } | 559 | } |
542 | 560 | ||
543 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 561 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
544 | 562 | ||
545 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 563 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
546 | if ( c.birthday().isValid() ){ | 564 | if ( c.birthday().isValid() ){ |
547 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); | 565 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
548 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); | 566 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
549 | } | 567 | } |
550 | 568 | ||
551 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 569 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
552 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 570 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
553 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 571 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
554 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 572 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
555 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 573 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
556 | } | 574 | } |
557 | 575 | ||
558 | // some values we have to export as custom fields | 576 | // some values we have to export as custom fields |
559 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 577 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
560 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 578 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
561 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 579 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
562 | 580 | ||
563 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 581 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
564 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 582 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
565 | if ( c.anniversary().isValid() ){ | 583 | if ( c.anniversary().isValid() ){ |
566 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | 584 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); |
567 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | 585 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); |
568 | } | 586 | } |
569 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 587 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
570 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 588 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
571 | 589 | ||
572 | return vcard; | 590 | return vcard; |
573 | } | 591 | } |
574 | 592 | ||
575 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | 593 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const |
576 | { | 594 | { |
577 | QString str_rfc2425 = QString("%1-%2-%3") | 595 | QString str_rfc2425 = QString("%1-%2-%3") |
578 | .arg( d.year() ) | 596 | .arg( d.year() ) |
579 | .arg( d.month(), 2 ) | 597 | .arg( d.month(), 2 ) |
580 | .arg( d.day(), 2 ); | 598 | .arg( d.day(), 2 ); |
581 | // Now replace spaces with "0"... | 599 | // Now replace spaces with "0"... |
582 | int pos = 0; | 600 | int pos = 0; |
583 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | 601 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) |
584 | str_rfc2425.replace( pos, 1, "0" ); | 602 | str_rfc2425.replace( pos, 1, "0" ); |
585 | 603 | ||
586 | return str_rfc2425; | 604 | return str_rfc2425; |
587 | } | 605 | } |
588 | 606 | ||
589 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 607 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
590 | { | 608 | { |
591 | int monthPos = datestr.find('-'); | 609 | int monthPos = datestr.find('-'); |
592 | int dayPos = datestr.find('-', monthPos+1 ); | 610 | int dayPos = datestr.find('-', monthPos+1 ); |
593 | int sep_ignore = 1; | 611 | int sep_ignore = 1; |
594 | if ( monthPos == -1 || dayPos == -1 ) { | 612 | if ( monthPos == -1 || dayPos == -1 ) { |
595 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 613 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
596 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 614 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
597 | if ( datestr.length() == 8 ){ | 615 | if ( datestr.length() == 8 ){ |
598 | monthPos = 4; | 616 | monthPos = 4; |
599 | dayPos = 6; | 617 | dayPos = 6; |
600 | sep_ignore = 0; | 618 | sep_ignore = 0; |
601 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 619 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
602 | } else { | 620 | } else { |
603 | return QDate(); | 621 | return QDate(); |
604 | } | 622 | } |
605 | } | 623 | } |
606 | int y = datestr.left( monthPos ).toInt(); | 624 | int y = datestr.left( monthPos ).toInt(); |
607 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 625 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
608 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 626 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
609 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 627 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
610 | QDate date ( y,m,d ); | 628 | QDate date ( y,m,d ); |
611 | return date; | 629 | return date; |
612 | } | 630 | } |
613 | 631 | ||
614 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 632 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
615 | { | 633 | { |
616 | VObject *ret = 0; | 634 | VObject *ret = 0; |
617 | if ( o && !value.isEmpty() ) | 635 | if ( o && !value.isEmpty() ) |
618 | ret = addPropValue( o, prop, value.latin1() ); | 636 | ret = addPropValue( o, prop, value.latin1() ); |
619 | return ret; | 637 | return ret; |
620 | } | 638 | } |
621 | 639 | ||
622 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 640 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
623 | { | 641 | { |
624 | VObject *ret = 0; | 642 | VObject *ret = 0; |
625 | if ( o ) | 643 | if ( o ) |
626 | ret = addProp( o, prop ); | 644 | ret = addProp( o, prop ); |
627 | return ret; | 645 | return ret; |
628 | } | 646 | } |
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index 097142b..1c21619 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -1,811 +1,814 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
20 | * Revision 1.6 2003/07/07 16:19:47 eilers | 23 | * Revision 1.6 2003/07/07 16:19:47 eilers |
21 | * Fixing serious bug in hasQuerySettings() | 24 | * Fixing serious bug in hasQuerySettings() |
22 | * | 25 | * |
23 | * Revision 1.5 2003/04/13 18:07:10 zecke | 26 | * Revision 1.5 2003/04/13 18:07:10 zecke |
24 | * More API doc | 27 | * More API doc |
25 | * QString -> const QString& | 28 | * QString -> const QString& |
26 | * QString = 0l -> QString::null | 29 | * QString = 0l -> QString::null |
27 | * | 30 | * |
28 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 31 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
29 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 32 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
30 | * | 33 | * |
31 | * Revision 1.3 2003/03/21 12:26:28 eilers | 34 | * Revision 1.3 2003/03/21 12:26:28 eilers |
32 | * Fixing small bug: If we search a birthday from today to today, it returned | 35 | * Fixing small bug: If we search a birthday from today to today, it returned |
33 | * every contact .. | 36 | * every contact .. |
34 | * | 37 | * |
35 | * Revision 1.2 2003/03/21 10:33:09 eilers | 38 | * Revision 1.2 2003/03/21 10:33:09 eilers |
36 | * Merged speed optimized xml backend for contacts to main. | 39 | * Merged speed optimized xml backend for contacts to main. |
37 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 40 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
38 | * all Birthdays/Anniversaries between two dates. This should be used | 41 | * all Birthdays/Anniversaries between two dates. This should be used |
39 | * to show all birthdays in the datebook.. | 42 | * to show all birthdays in the datebook.. |
40 | * This change is sourcecode backward compatible but you have to upgrade | 43 | * This change is sourcecode backward compatible but you have to upgrade |
41 | * the binaries for today-addressbook. | 44 | * the binaries for today-addressbook. |
42 | * | 45 | * |
43 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 46 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
44 | * Speed optimization. Removed the sequential search loops. | 47 | * Speed optimization. Removed the sequential search loops. |
45 | * | 48 | * |
46 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 49 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
47 | * Writing offsets to debug output.. | 50 | * Writing offsets to debug output.. |
48 | * | 51 | * |
49 | * Revision 1.1 2003/02/09 15:05:01 eilers | 52 | * Revision 1.1 2003/02/09 15:05:01 eilers |
50 | * Nothing happened.. Just some cleanup before I will start.. | 53 | * Nothing happened.. Just some cleanup before I will start.. |
51 | * | 54 | * |
52 | * Revision 1.12 2003/01/03 16:58:03 eilers | 55 | * Revision 1.12 2003/01/03 16:58:03 eilers |
53 | * Reenable debug output | 56 | * Reenable debug output |
54 | * | 57 | * |
55 | * Revision 1.11 2003/01/03 12:31:28 eilers | 58 | * Revision 1.11 2003/01/03 12:31:28 eilers |
56 | * Bugfix for calculating data diffs.. | 59 | * Bugfix for calculating data diffs.. |
57 | * | 60 | * |
58 | * Revision 1.10 2003/01/02 14:27:12 eilers | 61 | * Revision 1.10 2003/01/02 14:27:12 eilers |
59 | * Improved query by example: Search by date is possible.. First step | 62 | * Improved query by example: Search by date is possible.. First step |
60 | * for a today plugin for birthdays.. | 63 | * for a today plugin for birthdays.. |
61 | * | 64 | * |
62 | * Revision 1.9 2002/12/08 12:48:57 eilers | 65 | * Revision 1.9 2002/12/08 12:48:57 eilers |
63 | * Moved journal-enum from ocontact into i the xml-backend.. | 66 | * Moved journal-enum from ocontact into i the xml-backend.. |
64 | * | 67 | * |
65 | * Revision 1.8 2002/11/14 17:04:24 eilers | 68 | * Revision 1.8 2002/11/14 17:04:24 eilers |
66 | * Sorting will now work if fullname is identical on some entries | 69 | * Sorting will now work if fullname is identical on some entries |
67 | * | 70 | * |
68 | * Revision 1.7 2002/11/13 15:02:46 eilers | 71 | * Revision 1.7 2002/11/13 15:02:46 eilers |
69 | * Small Bug in sorted fixed | 72 | * Small Bug in sorted fixed |
70 | * | 73 | * |
71 | * Revision 1.6 2002/11/13 14:14:51 eilers | 74 | * Revision 1.6 2002/11/13 14:14:51 eilers |
72 | * Added sorted for Contacts.. | 75 | * Added sorted for Contacts.. |
73 | * | 76 | * |
74 | * Revision 1.5 2002/11/01 15:10:42 eilers | 77 | * Revision 1.5 2002/11/01 15:10:42 eilers |
75 | * Added regExp-search in database for all fields in a contact. | 78 | * Added regExp-search in database for all fields in a contact. |
76 | * | 79 | * |
77 | * Revision 1.4 2002/10/16 10:52:40 eilers | 80 | * Revision 1.4 2002/10/16 10:52:40 eilers |
78 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 81 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
79 | * | 82 | * |
80 | * Revision 1.3 2002/10/14 16:21:54 eilers | 83 | * Revision 1.3 2002/10/14 16:21:54 eilers |
81 | * Some minor interface updates | 84 | * Some minor interface updates |
82 | * | 85 | * |
83 | * Revision 1.2 2002/10/07 17:34:24 eilers | 86 | * Revision 1.2 2002/10/07 17:34:24 eilers |
84 | * added OBackendFactory for advanced backend access | 87 | * added OBackendFactory for advanced backend access |
85 | * | 88 | * |
86 | * Revision 1.1 2002/09/27 17:11:44 eilers | 89 | * Revision 1.1 2002/09/27 17:11:44 eilers |
87 | * Added API for accessing the Contact-Database ! It is compiling, but | 90 | * Added API for accessing the Contact-Database ! It is compiling, but |
88 | * please do not expect that anything is working ! | 91 | * please do not expect that anything is working ! |
89 | * I will debug that stuff in the next time .. | 92 | * I will debug that stuff in the next time .. |
90 | * Please read README_COMPILE for compiling ! | 93 | * Please read README_COMPILE for compiling ! |
91 | * | 94 | * |
92 | * | 95 | * |
93 | */ | 96 | */ |
94 | 97 | ||
95 | #include "ocontactaccessbackend_xml.h" | 98 | #include "ocontactaccessbackend_xml.h" |
96 | 99 | ||
97 | #include <qasciidict.h> | 100 | #include <qasciidict.h> |
98 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
99 | #include <qfile.h> | 102 | #include <qfile.h> |
100 | #include <qfileinfo.h> | 103 | #include <qfileinfo.h> |
101 | #include <qregexp.h> | 104 | #include <qregexp.h> |
102 | #include <qarray.h> | 105 | #include <qarray.h> |
103 | #include <qmap.h> | 106 | #include <qmap.h> |
104 | #include <qdatetime.h> | 107 | #include <qdatetime.h> |
105 | 108 | ||
106 | #include <qpe/global.h> | 109 | #include <qpe/global.h> |
107 | 110 | ||
108 | #include <opie/xmltree.h> | 111 | #include <opie/xmltree.h> |
109 | #include "ocontactaccessbackend.h" | 112 | #include "ocontactaccessbackend.h" |
110 | #include "ocontactaccess.h" | 113 | #include "ocontactaccess.h" |
111 | 114 | ||
112 | #include <stdlib.h> | 115 | #include <stdlib.h> |
113 | #include <errno.h> | 116 | #include <errno.h> |
114 | 117 | ||
115 | using namespace Opie; | 118 | using namespace Opie; |
116 | 119 | ||
117 | 120 | ||
118 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): | 121 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
119 | m_changed( false ) | 122 | m_changed( false ) |
120 | { | 123 | { |
121 | // Just m_contactlist should call delete if an entry | 124 | // Just m_contactlist should call delete if an entry |
122 | // is removed. | 125 | // is removed. |
123 | m_contactList.setAutoDelete( true ); | 126 | m_contactList.setAutoDelete( true ); |
124 | m_uidToContact.setAutoDelete( false ); | 127 | m_uidToContact.setAutoDelete( false ); |
125 | 128 | ||
126 | m_appName = appname; | 129 | m_appName = appname; |
127 | 130 | ||
128 | /* Set journalfile name ... */ | 131 | /* Set journalfile name ... */ |
129 | m_journalName = getenv("HOME"); | 132 | m_journalName = getenv("HOME"); |
130 | m_journalName +="/.abjournal" + appname; | 133 | m_journalName +="/.abjournal" + appname; |
131 | 134 | ||
132 | /* Expecting to access the default filename if nothing else is set */ | 135 | /* Expecting to access the default filename if nothing else is set */ |
133 | if ( filename.isEmpty() ){ | 136 | if ( filename.isEmpty() ){ |
134 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 137 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
135 | } else | 138 | } else |
136 | m_fileName = filename; | 139 | m_fileName = filename; |
137 | 140 | ||
138 | /* Load Database now */ | 141 | /* Load Database now */ |
139 | load (); | 142 | load (); |
140 | } | 143 | } |
141 | 144 | ||
142 | bool OContactAccessBackend_XML::save() | 145 | bool OContactAccessBackend_XML::save() |
143 | { | 146 | { |
144 | 147 | ||
145 | if ( !m_changed ) | 148 | if ( !m_changed ) |
146 | return true; | 149 | return true; |
147 | 150 | ||
148 | QString strNewFile = m_fileName + ".new"; | 151 | QString strNewFile = m_fileName + ".new"; |
149 | QFile f( strNewFile ); | 152 | QFile f( strNewFile ); |
150 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 153 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
151 | return false; | 154 | return false; |
152 | 155 | ||
153 | int total_written; | 156 | int total_written; |
154 | int idx_offset = 0; | 157 | int idx_offset = 0; |
155 | QString out; | 158 | QString out; |
156 | 159 | ||
157 | // Write Header | 160 | // Write Header |
158 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 161 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
159 | " <Groups>\n" | 162 | " <Groups>\n" |
160 | " </Groups>\n" | 163 | " </Groups>\n" |
161 | " <Contacts>\n"; | 164 | " <Contacts>\n"; |
162 | QCString cstr = out.utf8(); | 165 | QCString cstr = out.utf8(); |
163 | f.writeBlock( cstr.data(), cstr.length() ); | 166 | f.writeBlock( cstr.data(), cstr.length() ); |
164 | idx_offset += cstr.length(); | 167 | idx_offset += cstr.length(); |
165 | out = ""; | 168 | out = ""; |
166 | 169 | ||
167 | // Write all contacts | 170 | // Write all contacts |
168 | QListIterator<OContact> it( m_contactList ); | 171 | QListIterator<OContact> it( m_contactList ); |
169 | for ( ; it.current(); ++it ) { | 172 | for ( ; it.current(); ++it ) { |
170 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 173 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
171 | out += "<Contact "; | 174 | out += "<Contact "; |
172 | (*it)->save( out ); | 175 | (*it)->save( out ); |
173 | out += "/>\n"; | 176 | out += "/>\n"; |
174 | cstr = out.utf8(); | 177 | cstr = out.utf8(); |
175 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 178 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
176 | idx_offset += cstr.length(); | 179 | idx_offset += cstr.length(); |
177 | if ( total_written != int(cstr.length()) ) { | 180 | if ( total_written != int(cstr.length()) ) { |
178 | f.close(); | 181 | f.close(); |
179 | QFile::remove( strNewFile ); | 182 | QFile::remove( strNewFile ); |
180 | return false; | 183 | return false; |
181 | } | 184 | } |
182 | out = ""; | 185 | out = ""; |
183 | } | 186 | } |
184 | out += " </Contacts>\n</AddressBook>\n"; | 187 | out += " </Contacts>\n</AddressBook>\n"; |
185 | 188 | ||
186 | // Write Footer | 189 | // Write Footer |
187 | cstr = out.utf8(); | 190 | cstr = out.utf8(); |
188 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 191 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
189 | if ( total_written != int( cstr.length() ) ) { | 192 | if ( total_written != int( cstr.length() ) ) { |
190 | f.close(); | 193 | f.close(); |
191 | QFile::remove( strNewFile ); | 194 | QFile::remove( strNewFile ); |
192 | return false; | 195 | return false; |
193 | } | 196 | } |
194 | f.close(); | 197 | f.close(); |
195 | 198 | ||
196 | // move the file over, I'm just going to use the system call | 199 | // move the file over, I'm just going to use the system call |
197 | // because, I don't feel like using QDir. | 200 | // because, I don't feel like using QDir. |
198 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 201 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
199 | qWarning( "problem renaming file %s to %s, errno: %d", | 202 | qWarning( "problem renaming file %s to %s, errno: %d", |
200 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 203 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
201 | // remove the tmp file... | 204 | // remove the tmp file... |
202 | QFile::remove( strNewFile ); | 205 | QFile::remove( strNewFile ); |
203 | } | 206 | } |
204 | 207 | ||
205 | /* The journalfile should be removed now... */ | 208 | /* The journalfile should be removed now... */ |
206 | removeJournal(); | 209 | removeJournal(); |
207 | 210 | ||
208 | m_changed = false; | 211 | m_changed = false; |
209 | return true; | 212 | return true; |
210 | } | 213 | } |
211 | 214 | ||
212 | bool OContactAccessBackend_XML::load () | 215 | bool OContactAccessBackend_XML::load () |
213 | { | 216 | { |
214 | m_contactList.clear(); | 217 | m_contactList.clear(); |
215 | m_uidToContact.clear(); | 218 | m_uidToContact.clear(); |
216 | 219 | ||
217 | /* Load XML-File and journal if it exists */ | 220 | /* Load XML-File and journal if it exists */ |
218 | if ( !load ( m_fileName, false ) ) | 221 | if ( !load ( m_fileName, false ) ) |
219 | return false; | 222 | return false; |
220 | /* The returncode of the journalfile is ignored due to the | 223 | /* The returncode of the journalfile is ignored due to the |
221 | * fact that it does not exist when this class is instantiated ! | 224 | * fact that it does not exist when this class is instantiated ! |
222 | * But there may such a file exist, if the application crashed. | 225 | * But there may such a file exist, if the application crashed. |
223 | * Therefore we try to load it to get the changes before the # | 226 | * Therefore we try to load it to get the changes before the # |
224 | * crash happened... | 227 | * crash happened... |
225 | */ | 228 | */ |
226 | load (m_journalName, true); | 229 | load (m_journalName, true); |
227 | 230 | ||
228 | return true; | 231 | return true; |
229 | } | 232 | } |
230 | 233 | ||
231 | void OContactAccessBackend_XML::clear () | 234 | void OContactAccessBackend_XML::clear () |
232 | { | 235 | { |
233 | m_contactList.clear(); | 236 | m_contactList.clear(); |
234 | m_uidToContact.clear(); | 237 | m_uidToContact.clear(); |
235 | 238 | ||
236 | m_changed = false; | 239 | m_changed = false; |
237 | } | 240 | } |
238 | 241 | ||
239 | bool OContactAccessBackend_XML::wasChangedExternally() | 242 | bool OContactAccessBackend_XML::wasChangedExternally() |
240 | { | 243 | { |
241 | QFileInfo fi( m_fileName ); | 244 | QFileInfo fi( m_fileName ); |
242 | 245 | ||
243 | QDateTime lastmod = fi.lastModified (); | 246 | QDateTime lastmod = fi.lastModified (); |
244 | 247 | ||
245 | return (lastmod != m_readtime); | 248 | return (lastmod != m_readtime); |
246 | } | 249 | } |
247 | 250 | ||
248 | QArray<int> OContactAccessBackend_XML::allRecords() const | 251 | QArray<int> OContactAccessBackend_XML::allRecords() const |
249 | { | 252 | { |
250 | QArray<int> uid_list( m_contactList.count() ); | 253 | QArray<int> uid_list( m_contactList.count() ); |
251 | 254 | ||
252 | uint counter = 0; | 255 | uint counter = 0; |
253 | QListIterator<OContact> it( m_contactList ); | 256 | QListIterator<OContact> it( m_contactList ); |
254 | for( ; it.current(); ++it ){ | 257 | for( ; it.current(); ++it ){ |
255 | uid_list[counter++] = (*it)->uid(); | 258 | uid_list[counter++] = (*it)->uid(); |
256 | } | 259 | } |
257 | 260 | ||
258 | return ( uid_list ); | 261 | return ( uid_list ); |
259 | } | 262 | } |
260 | 263 | ||
261 | OContact OContactAccessBackend_XML::find ( int uid ) const | 264 | OContact OContactAccessBackend_XML::find ( int uid ) const |
262 | { | 265 | { |
263 | OContact foundContact; //Create empty contact | 266 | OContact foundContact; //Create empty contact |
264 | 267 | ||
265 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 268 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
266 | 269 | ||
267 | if ( found ){ | 270 | if ( found ){ |
268 | foundContact = *found; | 271 | foundContact = *found; |
269 | } | 272 | } |
270 | 273 | ||
271 | return ( foundContact ); | 274 | return ( foundContact ); |
272 | } | 275 | } |
273 | 276 | ||
274 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 277 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
275 | const QDateTime& d ) | 278 | const QDateTime& d ) |
276 | { | 279 | { |
277 | 280 | ||
278 | QArray<int> m_currentQuery( m_contactList.count() ); | 281 | QArray<int> m_currentQuery( m_contactList.count() ); |
279 | QListIterator<OContact> it( m_contactList ); | 282 | QListIterator<OContact> it( m_contactList ); |
280 | uint arraycounter = 0; | 283 | uint arraycounter = 0; |
281 | 284 | ||
282 | for( ; it.current(); ++it ){ | 285 | for( ; it.current(); ++it ){ |
283 | /* Search all fields and compare them with query object. Store them into list | 286 | /* Search all fields and compare them with query object. Store them into list |
284 | * if all fields matches. | 287 | * if all fields matches. |
285 | */ | 288 | */ |
286 | QDate* queryDate = 0l; | 289 | QDate* queryDate = 0l; |
287 | QDate* checkDate = 0l; | 290 | QDate* checkDate = 0l; |
288 | bool allcorrect = true; | 291 | bool allcorrect = true; |
289 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 292 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
290 | // Birthday and anniversary are special nonstring fields and should | 293 | // Birthday and anniversary are special nonstring fields and should |
291 | // be handled specially | 294 | // be handled specially |
292 | switch ( i ){ | 295 | switch ( i ){ |
293 | case Qtopia::Birthday: | 296 | case Qtopia::Birthday: |
294 | queryDate = new QDate( query.birthday() ); | 297 | queryDate = new QDate( query.birthday() ); |
295 | checkDate = new QDate( (*it)->birthday() ); | 298 | checkDate = new QDate( (*it)->birthday() ); |
296 | case Qtopia::Anniversary: | 299 | case Qtopia::Anniversary: |
297 | if ( queryDate == 0l ){ | 300 | if ( queryDate == 0l ){ |
298 | queryDate = new QDate( query.anniversary() ); | 301 | queryDate = new QDate( query.anniversary() ); |
299 | checkDate = new QDate( (*it)->anniversary() ); | 302 | checkDate = new QDate( (*it)->anniversary() ); |
300 | } | 303 | } |
301 | 304 | ||
302 | if ( queryDate->isValid() ){ | 305 | if ( queryDate->isValid() ){ |
303 | if( checkDate->isValid() ){ | 306 | if( checkDate->isValid() ){ |
304 | if ( settings & OContactAccess::DateYear ){ | 307 | if ( settings & OContactAccess::DateYear ){ |
305 | if ( queryDate->year() != checkDate->year() ) | 308 | if ( queryDate->year() != checkDate->year() ) |
306 | allcorrect = false; | 309 | allcorrect = false; |
307 | } | 310 | } |
308 | if ( settings & OContactAccess::DateMonth ){ | 311 | if ( settings & OContactAccess::DateMonth ){ |
309 | if ( queryDate->month() != checkDate->month() ) | 312 | if ( queryDate->month() != checkDate->month() ) |
310 | allcorrect = false; | 313 | allcorrect = false; |
311 | } | 314 | } |
312 | if ( settings & OContactAccess::DateDay ){ | 315 | if ( settings & OContactAccess::DateDay ){ |
313 | if ( queryDate->day() != checkDate->day() ) | 316 | if ( queryDate->day() != checkDate->day() ) |
314 | allcorrect = false; | 317 | allcorrect = false; |
315 | } | 318 | } |
316 | if ( settings & OContactAccess::DateDiff ) { | 319 | if ( settings & OContactAccess::DateDiff ) { |
317 | QDate current; | 320 | QDate current; |
318 | // If we get an additional date, we | 321 | // If we get an additional date, we |
319 | // will take this date instead of | 322 | // will take this date instead of |
320 | // the current one.. | 323 | // the current one.. |
321 | if ( !d.date().isValid() ) | 324 | if ( !d.date().isValid() ) |
322 | current = QDate::currentDate(); | 325 | current = QDate::currentDate(); |
323 | else | 326 | else |
324 | current = d.date(); | 327 | current = d.date(); |
325 | 328 | ||
326 | // We have to equalize the year, otherwise | 329 | // We have to equalize the year, otherwise |
327 | // the search will fail.. | 330 | // the search will fail.. |
328 | checkDate->setYMD( current.year(), | 331 | checkDate->setYMD( current.year(), |
329 | checkDate->month(), | 332 | checkDate->month(), |
330 | checkDate->day() ); | 333 | checkDate->day() ); |
331 | if ( *checkDate < current ) | 334 | if ( *checkDate < current ) |
332 | checkDate->setYMD( current.year()+1, | 335 | checkDate->setYMD( current.year()+1, |
333 | checkDate->month(), | 336 | checkDate->month(), |
334 | checkDate->day() ); | 337 | checkDate->day() ); |
335 | 338 | ||
336 | // Check whether the birthday/anniversary date is between | 339 | // Check whether the birthday/anniversary date is between |
337 | // the current/given date and the maximum date | 340 | // the current/given date and the maximum date |
338 | // ( maximum time range ) ! | 341 | // ( maximum time range ) ! |
339 | qWarning("Checking if %s is between %s and %s ! ", | 342 | qWarning("Checking if %s is between %s and %s ! ", |
340 | checkDate->toString().latin1(), | 343 | checkDate->toString().latin1(), |
341 | current.toString().latin1(), | 344 | current.toString().latin1(), |
342 | queryDate->toString().latin1() ); | 345 | queryDate->toString().latin1() ); |
343 | if ( current.daysTo( *queryDate ) >= 0 ){ | 346 | if ( current.daysTo( *queryDate ) >= 0 ){ |
344 | if ( !( ( *checkDate >= current ) && | 347 | if ( !( ( *checkDate >= current ) && |
345 | ( *checkDate <= *queryDate ) ) ){ | 348 | ( *checkDate <= *queryDate ) ) ){ |
346 | allcorrect = false; | 349 | allcorrect = false; |
347 | qWarning (" Nope!.."); | 350 | qWarning (" Nope!.."); |
348 | } | 351 | } |
349 | } | 352 | } |
350 | } | 353 | } |
351 | } else{ | 354 | } else{ |
352 | // checkDate is invalid. Therefore this entry is always rejected | 355 | // checkDate is invalid. Therefore this entry is always rejected |
353 | allcorrect = false; | 356 | allcorrect = false; |
354 | } | 357 | } |
355 | } | 358 | } |
356 | 359 | ||
357 | delete queryDate; | 360 | delete queryDate; |
358 | queryDate = 0l; | 361 | queryDate = 0l; |
359 | delete checkDate; | 362 | delete checkDate; |
360 | checkDate = 0l; | 363 | checkDate = 0l; |
361 | break; | 364 | break; |
362 | default: | 365 | default: |
363 | /* Just compare fields which are not empty in the query object */ | 366 | /* Just compare fields which are not empty in the query object */ |
364 | if ( !query.field(i).isEmpty() ){ | 367 | if ( !query.field(i).isEmpty() ){ |
365 | switch ( settings & ~( OContactAccess::IgnoreCase | 368 | switch ( settings & ~( OContactAccess::IgnoreCase |
366 | | OContactAccess::DateDiff | 369 | | OContactAccess::DateDiff |
367 | | OContactAccess::DateYear | 370 | | OContactAccess::DateYear |
368 | | OContactAccess::DateMonth | 371 | | OContactAccess::DateMonth |
369 | | OContactAccess::DateDay | 372 | | OContactAccess::DateDay |
370 | | OContactAccess::MatchOne | 373 | | OContactAccess::MatchOne |
371 | ) ){ | 374 | ) ){ |
372 | 375 | ||
373 | case OContactAccess::RegExp:{ | 376 | case OContactAccess::RegExp:{ |
374 | QRegExp expr ( query.field(i), | 377 | QRegExp expr ( query.field(i), |
375 | !(settings & OContactAccess::IgnoreCase), | 378 | !(settings & OContactAccess::IgnoreCase), |
376 | false ); | 379 | false ); |
377 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 380 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
378 | allcorrect = false; | 381 | allcorrect = false; |
379 | } | 382 | } |
380 | break; | 383 | break; |
381 | case OContactAccess::WildCards:{ | 384 | case OContactAccess::WildCards:{ |
382 | QRegExp expr ( query.field(i), | 385 | QRegExp expr ( query.field(i), |
383 | !(settings & OContactAccess::IgnoreCase), | 386 | !(settings & OContactAccess::IgnoreCase), |
384 | true ); | 387 | true ); |
385 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 388 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
386 | allcorrect = false; | 389 | allcorrect = false; |
387 | } | 390 | } |
388 | break; | 391 | break; |
389 | case OContactAccess::ExactMatch:{ | 392 | case OContactAccess::ExactMatch:{ |
390 | if (settings & OContactAccess::IgnoreCase){ | 393 | if (settings & OContactAccess::IgnoreCase){ |
391 | if ( query.field(i).upper() != | 394 | if ( query.field(i).upper() != |
392 | (*it)->field(i).upper() ) | 395 | (*it)->field(i).upper() ) |
393 | allcorrect = false; | 396 | allcorrect = false; |
394 | }else{ | 397 | }else{ |
395 | if ( query.field(i) != (*it)->field(i) ) | 398 | if ( query.field(i) != (*it)->field(i) ) |
396 | allcorrect = false; | 399 | allcorrect = false; |
397 | } | 400 | } |
398 | } | 401 | } |
399 | break; | 402 | break; |
400 | } | 403 | } |
401 | } | 404 | } |
402 | } | 405 | } |
403 | } | 406 | } |
404 | if ( allcorrect ){ | 407 | if ( allcorrect ){ |
405 | m_currentQuery[arraycounter++] = (*it)->uid(); | 408 | m_currentQuery[arraycounter++] = (*it)->uid(); |
406 | } | 409 | } |
407 | } | 410 | } |
408 | 411 | ||
409 | // Shrink to fit.. | 412 | // Shrink to fit.. |
410 | m_currentQuery.resize(arraycounter); | 413 | m_currentQuery.resize(arraycounter); |
411 | 414 | ||
412 | return m_currentQuery; | 415 | return m_currentQuery; |
413 | } | 416 | } |
414 | 417 | ||
415 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 418 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
416 | { | 419 | { |
417 | QArray<int> m_currentQuery( m_contactList.count() ); | 420 | QArray<int> m_currentQuery( m_contactList.count() ); |
418 | QListIterator<OContact> it( m_contactList ); | 421 | QListIterator<OContact> it( m_contactList ); |
419 | uint arraycounter = 0; | 422 | uint arraycounter = 0; |
420 | 423 | ||
421 | for( ; it.current(); ++it ){ | 424 | for( ; it.current(); ++it ){ |
422 | if ( (*it)->match( r ) ){ | 425 | if ( (*it)->match( r ) ){ |
423 | m_currentQuery[arraycounter++] = (*it)->uid(); | 426 | m_currentQuery[arraycounter++] = (*it)->uid(); |
424 | } | 427 | } |
425 | 428 | ||
426 | } | 429 | } |
427 | // Shrink to fit.. | 430 | // Shrink to fit.. |
428 | m_currentQuery.resize(arraycounter); | 431 | m_currentQuery.resize(arraycounter); |
429 | 432 | ||
430 | return m_currentQuery; | 433 | return m_currentQuery; |
431 | } | 434 | } |
432 | 435 | ||
433 | const uint OContactAccessBackend_XML::querySettings() | 436 | const uint OContactAccessBackend_XML::querySettings() |
434 | { | 437 | { |
435 | return ( OContactAccess::WildCards | 438 | return ( OContactAccess::WildCards |
436 | | OContactAccess::IgnoreCase | 439 | | OContactAccess::IgnoreCase |
437 | | OContactAccess::RegExp | 440 | | OContactAccess::RegExp |
438 | | OContactAccess::ExactMatch | 441 | | OContactAccess::ExactMatch |
439 | | OContactAccess::DateDiff | 442 | | OContactAccess::DateDiff |
440 | | OContactAccess::DateYear | 443 | | OContactAccess::DateYear |
441 | | OContactAccess::DateMonth | 444 | | OContactAccess::DateMonth |
442 | | OContactAccess::DateDay | 445 | | OContactAccess::DateDay |
443 | ); | 446 | ); |
444 | } | 447 | } |
445 | 448 | ||
446 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 449 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const |
447 | { | 450 | { |
448 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 451 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
449 | * may be added with any of the other settings. IgnoreCase should never used alone. | 452 | * may be added with any of the other settings. IgnoreCase should never used alone. |
450 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 453 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
451 | */ | 454 | */ |
452 | 455 | ||
453 | // Step 1: Check whether the given settings are supported by this backend | 456 | // Step 1: Check whether the given settings are supported by this backend |
454 | if ( ( querySettings & ( | 457 | if ( ( querySettings & ( |
455 | OContactAccess::IgnoreCase | 458 | OContactAccess::IgnoreCase |
456 | | OContactAccess::WildCards | 459 | | OContactAccess::WildCards |
457 | | OContactAccess::DateDiff | 460 | | OContactAccess::DateDiff |
458 | | OContactAccess::DateYear | 461 | | OContactAccess::DateYear |
459 | | OContactAccess::DateMonth | 462 | | OContactAccess::DateMonth |
460 | | OContactAccess::DateDay | 463 | | OContactAccess::DateDay |
461 | | OContactAccess::RegExp | 464 | | OContactAccess::RegExp |
462 | | OContactAccess::ExactMatch | 465 | | OContactAccess::ExactMatch |
463 | ) ) != querySettings ) | 466 | ) ) != querySettings ) |
464 | return false; | 467 | return false; |
465 | 468 | ||
466 | // Step 2: Check whether the given combinations are ok.. | 469 | // Step 2: Check whether the given combinations are ok.. |
467 | 470 | ||
468 | // IngoreCase alone is invalid | 471 | // IngoreCase alone is invalid |
469 | if ( querySettings == OContactAccess::IgnoreCase ) | 472 | if ( querySettings == OContactAccess::IgnoreCase ) |
470 | return false; | 473 | return false; |
471 | 474 | ||
472 | // WildCards, RegExp and ExactMatch should never used at the same time | 475 | // WildCards, RegExp and ExactMatch should never used at the same time |
473 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 476 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
474 | | OContactAccess::DateDiff | 477 | | OContactAccess::DateDiff |
475 | | OContactAccess::DateYear | 478 | | OContactAccess::DateYear |
476 | | OContactAccess::DateMonth | 479 | | OContactAccess::DateMonth |
477 | | OContactAccess::DateDay | 480 | | OContactAccess::DateDay |
478 | ) | 481 | ) |
479 | ){ | 482 | ){ |
480 | case OContactAccess::RegExp: | 483 | case OContactAccess::RegExp: |
481 | return ( true ); | 484 | return ( true ); |
482 | case OContactAccess::WildCards: | 485 | case OContactAccess::WildCards: |
483 | return ( true ); | 486 | return ( true ); |
484 | case OContactAccess::ExactMatch: | 487 | case OContactAccess::ExactMatch: |
485 | return ( true ); | 488 | return ( true ); |
486 | case 0: // one of the upper removed bits were set.. | 489 | case 0: // one of the upper removed bits were set.. |
487 | return ( true ); | 490 | return ( true ); |
488 | default: | 491 | default: |
489 | return ( false ); | 492 | return ( false ); |
490 | } | 493 | } |
491 | } | 494 | } |
492 | 495 | ||
493 | // Currently only asc implemented.. | 496 | // Currently only asc implemented.. |
494 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 497 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
495 | { | 498 | { |
496 | QMap<QString, int> nameToUid; | 499 | QMap<QString, int> nameToUid; |
497 | QStringList names; | 500 | QStringList names; |
498 | QArray<int> m_currentQuery( m_contactList.count() ); | 501 | QArray<int> m_currentQuery( m_contactList.count() ); |
499 | 502 | ||
500 | // First fill map and StringList with all Names | 503 | // First fill map and StringList with all Names |
501 | // Afterwards sort namelist and use map to fill array to return.. | 504 | // Afterwards sort namelist and use map to fill array to return.. |
502 | QListIterator<OContact> it( m_contactList ); | 505 | QListIterator<OContact> it( m_contactList ); |
503 | for( ; it.current(); ++it ){ | 506 | for( ; it.current(); ++it ){ |
504 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); | 507 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); |
505 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); | 508 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); |
506 | } | 509 | } |
507 | names.sort(); | 510 | names.sort(); |
508 | 511 | ||
509 | int i = 0; | 512 | int i = 0; |
510 | if ( asc ){ | 513 | if ( asc ){ |
511 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 514 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
512 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 515 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
513 | }else{ | 516 | }else{ |
514 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | 517 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) |
515 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 518 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
516 | } | 519 | } |
517 | 520 | ||
518 | return m_currentQuery; | 521 | return m_currentQuery; |
519 | 522 | ||
520 | } | 523 | } |
521 | 524 | ||
522 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 525 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) |
523 | { | 526 | { |
524 | //qWarning("odefaultbackend: ACTION::ADD"); | 527 | //qWarning("odefaultbackend: ACTION::ADD"); |
525 | updateJournal (newcontact, ACTION_ADD); | 528 | updateJournal (newcontact, ACTION_ADD); |
526 | addContact_p( newcontact ); | 529 | addContact_p( newcontact ); |
527 | 530 | ||
528 | m_changed = true; | 531 | m_changed = true; |
529 | 532 | ||
530 | return true; | 533 | return true; |
531 | } | 534 | } |
532 | 535 | ||
533 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 536 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
534 | { | 537 | { |
535 | m_changed = true; | 538 | m_changed = true; |
536 | 539 | ||
537 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 540 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
538 | 541 | ||
539 | if ( found ) { | 542 | if ( found ) { |
540 | OContact* newCont = new OContact( contact ); | 543 | OContact* newCont = new OContact( contact ); |
541 | 544 | ||
542 | updateJournal ( *newCont, ACTION_REPLACE); | 545 | updateJournal ( *newCont, ACTION_REPLACE); |
543 | m_contactList.removeRef ( found ); | 546 | m_contactList.removeRef ( found ); |
544 | m_contactList.append ( newCont ); | 547 | m_contactList.append ( newCont ); |
545 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); | 548 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
546 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); | 549 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
547 | 550 | ||
548 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); | 551 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); |
549 | 552 | ||
550 | return true; | 553 | return true; |
551 | } else | 554 | } else |
552 | return false; | 555 | return false; |
553 | } | 556 | } |
554 | 557 | ||
555 | bool OContactAccessBackend_XML::remove ( int uid ) | 558 | bool OContactAccessBackend_XML::remove ( int uid ) |
556 | { | 559 | { |
557 | m_changed = true; | 560 | m_changed = true; |
558 | 561 | ||
559 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 562 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
560 | 563 | ||
561 | if ( found ) { | 564 | if ( found ) { |
562 | updateJournal ( *found, ACTION_REMOVE); | 565 | updateJournal ( *found, ACTION_REMOVE); |
563 | m_contactList.removeRef ( found ); | 566 | m_contactList.removeRef ( found ); |
564 | m_uidToContact.remove( QString().setNum( uid ) ); | 567 | m_uidToContact.remove( QString().setNum( uid ) ); |
565 | 568 | ||
566 | return true; | 569 | return true; |
567 | } else | 570 | } else |
568 | return false; | 571 | return false; |
569 | } | 572 | } |
570 | 573 | ||
571 | bool OContactAccessBackend_XML::reload(){ | 574 | bool OContactAccessBackend_XML::reload(){ |
572 | /* Reload is the same as load in this implementation */ | 575 | /* Reload is the same as load in this implementation */ |
573 | return ( load() ); | 576 | return ( load() ); |
574 | } | 577 | } |
575 | 578 | ||
576 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 579 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) |
577 | { | 580 | { |
578 | OContact* contRef = new OContact( newcontact ); | 581 | OContact* contRef = new OContact( newcontact ); |
579 | 582 | ||
580 | m_contactList.append ( contRef ); | 583 | m_contactList.append ( contRef ); |
581 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 584 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
582 | } | 585 | } |
583 | 586 | ||
584 | /* This function loads the xml-database and the journalfile */ | 587 | /* This function loads the xml-database and the journalfile */ |
585 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 588 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
586 | { | 589 | { |
587 | 590 | ||
588 | /* We use the time of the last read to check if the file was | 591 | /* We use the time of the last read to check if the file was |
589 | * changed externally. | 592 | * changed externally. |
590 | */ | 593 | */ |
591 | if ( !isJournal ){ | 594 | if ( !isJournal ){ |
592 | QFileInfo fi( filename ); | 595 | QFileInfo fi( filename ); |
593 | m_readtime = fi.lastModified (); | 596 | m_readtime = fi.lastModified (); |
594 | } | 597 | } |
595 | 598 | ||
596 | const int JOURNALACTION = Qtopia::Notes + 1; | 599 | const int JOURNALACTION = Qtopia::Notes + 1; |
597 | const int JOURNALROW = JOURNALACTION + 1; | 600 | const int JOURNALROW = JOURNALACTION + 1; |
598 | 601 | ||
599 | bool foundAction = false; | 602 | bool foundAction = false; |
600 | journal_action action = ACTION_ADD; | 603 | journal_action action = ACTION_ADD; |
601 | int journalKey = 0; | 604 | int journalKey = 0; |
602 | QMap<int, QString> contactMap; | 605 | QMap<int, QString> contactMap; |
603 | QMap<QString, QString> customMap; | 606 | QMap<QString, QString> customMap; |
604 | QMap<QString, QString>::Iterator customIt; | 607 | QMap<QString, QString>::Iterator customIt; |
605 | QAsciiDict<int> dict( 47 ); | 608 | QAsciiDict<int> dict( 47 ); |
606 | 609 | ||
607 | dict.setAutoDelete( TRUE ); | 610 | dict.setAutoDelete( TRUE ); |
608 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 611 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
609 | dict.insert( "Title", new int(Qtopia::Title) ); | 612 | dict.insert( "Title", new int(Qtopia::Title) ); |
610 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 613 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
611 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 614 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
612 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 615 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
613 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 616 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
614 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 617 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
615 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 618 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
616 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 619 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
617 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 620 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
618 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 621 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
619 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 622 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
620 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 623 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
621 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 624 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
622 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 625 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
623 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 626 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
624 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 627 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
625 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 628 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
626 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 629 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
627 | dict.insert( "Company", new int(Qtopia::Company) ); | 630 | dict.insert( "Company", new int(Qtopia::Company) ); |
628 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 631 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
629 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 632 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
630 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 633 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
631 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 634 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
632 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 635 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
633 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 636 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
634 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 637 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
635 | dict.insert( "Department", new int(Qtopia::Department) ); | 638 | dict.insert( "Department", new int(Qtopia::Department) ); |
636 | dict.insert( "Office", new int(Qtopia::Office) ); | 639 | dict.insert( "Office", new int(Qtopia::Office) ); |
637 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 640 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
638 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 641 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
639 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 642 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
640 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 643 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
641 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 644 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
642 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 645 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
643 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 646 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
644 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 647 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
645 | dict.insert( "Children", new int(Qtopia::Children) ); | 648 | dict.insert( "Children", new int(Qtopia::Children) ); |
646 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 649 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
647 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 650 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
648 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 651 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
649 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 652 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
650 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 653 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
651 | dict.insert( "action", new int(JOURNALACTION) ); | 654 | dict.insert( "action", new int(JOURNALACTION) ); |
652 | dict.insert( "actionrow", new int(JOURNALROW) ); | 655 | dict.insert( "actionrow", new int(JOURNALROW) ); |
653 | 656 | ||
654 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 657 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
655 | 658 | ||
656 | XMLElement *root = XMLElement::load( filename ); | 659 | XMLElement *root = XMLElement::load( filename ); |
657 | if(root != 0l ){ // start parsing | 660 | if(root != 0l ){ // start parsing |
658 | /* Parse all XML-Elements and put the data into the | 661 | /* Parse all XML-Elements and put the data into the |
659 | * Contact-Class | 662 | * Contact-Class |
660 | */ | 663 | */ |
661 | XMLElement *element = root->firstChild(); | 664 | XMLElement *element = root->firstChild(); |
662 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 665 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
663 | element = element->firstChild(); | 666 | element = element->firstChild(); |
664 | 667 | ||
665 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 668 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
666 | while( element && !isJournal ){ | 669 | while( element && !isJournal ){ |
667 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 670 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
668 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 671 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
669 | // element->tagName().latin1()); | 672 | // element->tagName().latin1()); |
670 | element = element->nextChild(); | 673 | element = element->nextChild(); |
671 | } else { | 674 | } else { |
672 | element = element->firstChild(); | 675 | element = element->firstChild(); |
673 | break; | 676 | break; |
674 | } | 677 | } |
675 | } | 678 | } |
676 | /* Parse all Contacts and ignore unknown tags */ | 679 | /* Parse all Contacts and ignore unknown tags */ |
677 | while( element ){ | 680 | while( element ){ |
678 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 681 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
679 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 682 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
680 | // element->tagName().latin1()); | 683 | // element->tagName().latin1()); |
681 | element = element->nextChild(); | 684 | element = element->nextChild(); |
682 | continue; | 685 | continue; |
683 | } | 686 | } |
684 | /* Found alement with tagname "contact", now parse and store all | 687 | /* Found alement with tagname "contact", now parse and store all |
685 | * attributes contained | 688 | * attributes contained |
686 | */ | 689 | */ |
687 | //qWarning("OContactDefBack::load element tagName() : %s", | 690 | //qWarning("OContactDefBack::load element tagName() : %s", |
688 | // element->tagName().latin1() ); | 691 | // element->tagName().latin1() ); |
689 | QString dummy; | 692 | QString dummy; |
690 | foundAction = false; | 693 | foundAction = false; |
691 | 694 | ||
692 | XMLElement::AttributeMap aMap = element->attributes(); | 695 | XMLElement::AttributeMap aMap = element->attributes(); |
693 | XMLElement::AttributeMap::Iterator it; | 696 | XMLElement::AttributeMap::Iterator it; |
694 | contactMap.clear(); | 697 | contactMap.clear(); |
695 | customMap.clear(); | 698 | customMap.clear(); |
696 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 699 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
697 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 700 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
698 | 701 | ||
699 | int *find = dict[ it.key() ]; | 702 | int *find = dict[ it.key() ]; |
700 | /* Unknown attributes will be stored as "Custom" elements */ | 703 | /* Unknown attributes will be stored as "Custom" elements */ |
701 | if ( !find ) { | 704 | if ( !find ) { |
702 | qWarning("Attribute %s not known.", it.key().latin1()); | 705 | qWarning("Attribute %s not known.", it.key().latin1()); |
703 | //contact.setCustomField(it.key(), it.data()); | 706 | //contact.setCustomField(it.key(), it.data()); |
704 | customMap.insert( it.key(), it.data() ); | 707 | customMap.insert( it.key(), it.data() ); |
705 | continue; | 708 | continue; |
706 | } | 709 | } |
707 | 710 | ||
708 | /* Check if special conversion is needed and add attribute | 711 | /* Check if special conversion is needed and add attribute |
709 | * into Contact class | 712 | * into Contact class |
710 | */ | 713 | */ |
711 | switch( *find ) { | 714 | switch( *find ) { |
712 | /* | 715 | /* |
713 | case Qtopia::AddressUid: | 716 | case Qtopia::AddressUid: |
714 | contact.setUid( it.data().toInt() ); | 717 | contact.setUid( it.data().toInt() ); |
715 | break; | 718 | break; |
716 | case Qtopia::AddressCategory: | 719 | case Qtopia::AddressCategory: |
717 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 720 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
718 | break; | 721 | break; |
719 | */ | 722 | */ |
720 | case JOURNALACTION: | 723 | case JOURNALACTION: |
721 | action = journal_action(it.data().toInt()); | 724 | action = journal_action(it.data().toInt()); |
722 | foundAction = true; | 725 | foundAction = true; |
723 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 726 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
724 | break; | 727 | break; |
725 | case JOURNALROW: | 728 | case JOURNALROW: |
726 | journalKey = it.data().toInt(); | 729 | journalKey = it.data().toInt(); |
727 | break; | 730 | break; |
728 | default: // no conversion needed add them to the map | 731 | default: // no conversion needed add them to the map |
729 | contactMap.insert( *find, it.data() ); | 732 | contactMap.insert( *find, it.data() ); |
730 | break; | 733 | break; |
731 | } | 734 | } |
732 | } | 735 | } |
733 | /* now generate the Contact contact */ | 736 | /* now generate the Contact contact */ |
734 | OContact contact( contactMap ); | 737 | OContact contact( contactMap ); |
735 | 738 | ||
736 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 739 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
737 | contact.setCustomField( customIt.key(), customIt.data() ); | 740 | contact.setCustomField( customIt.key(), customIt.data() ); |
738 | } | 741 | } |
739 | 742 | ||
740 | if (foundAction){ | 743 | if (foundAction){ |
741 | foundAction = false; | 744 | foundAction = false; |
742 | switch ( action ) { | 745 | switch ( action ) { |
743 | case ACTION_ADD: | 746 | case ACTION_ADD: |
744 | addContact_p (contact); | 747 | addContact_p (contact); |
745 | break; | 748 | break; |
746 | case ACTION_REMOVE: | 749 | case ACTION_REMOVE: |
747 | if ( !remove (contact.uid()) ) | 750 | if ( !remove (contact.uid()) ) |
748 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 751 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
749 | contact.uid() ); | 752 | contact.uid() ); |
750 | break; | 753 | break; |
751 | case ACTION_REPLACE: | 754 | case ACTION_REPLACE: |
752 | if ( !replace ( contact ) ) | 755 | if ( !replace ( contact ) ) |
753 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 756 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
754 | contact.uid() ); | 757 | contact.uid() ); |
755 | break; | 758 | break; |
756 | default: | 759 | default: |
757 | qWarning ("Unknown action: ignored !"); | 760 | qWarning ("Unknown action: ignored !"); |
758 | break; | 761 | break; |
759 | } | 762 | } |
760 | }else{ | 763 | }else{ |
761 | /* Add contact to list */ | 764 | /* Add contact to list */ |
762 | addContact_p (contact); | 765 | addContact_p (contact); |
763 | } | 766 | } |
764 | 767 | ||
765 | /* Move to next element */ | 768 | /* Move to next element */ |
766 | element = element->nextChild(); | 769 | element = element->nextChild(); |
767 | } | 770 | } |
768 | }else { | 771 | }else { |
769 | qWarning("ODefBack::could not load"); | 772 | qWarning("ODefBack::could not load"); |
770 | } | 773 | } |
771 | delete root; | 774 | delete root; |
772 | qWarning("returning from loading" ); | 775 | qWarning("returning from loading" ); |
773 | return true; | 776 | return true; |
774 | } | 777 | } |
775 | 778 | ||
776 | 779 | ||
777 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 780 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
778 | journal_action action ) | 781 | journal_action action ) |
779 | { | 782 | { |
780 | QFile f( m_journalName ); | 783 | QFile f( m_journalName ); |
781 | bool created = !f.exists(); | 784 | bool created = !f.exists(); |
782 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 785 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
783 | return; | 786 | return; |
784 | 787 | ||
785 | QString buf; | 788 | QString buf; |
786 | QCString str; | 789 | QCString str; |
787 | 790 | ||
788 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 791 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
789 | // get a XML-File which is readable by our parser. | 792 | // get a XML-File which is readable by our parser. |
790 | // This is just a cheat, but better than rewrite the parser. | 793 | // This is just a cheat, but better than rewrite the parser. |
791 | if ( created ){ | 794 | if ( created ){ |
792 | buf = "<Contacts>"; | 795 | buf = "<Contacts>"; |
793 | QCString cstr = buf.utf8(); | 796 | QCString cstr = buf.utf8(); |
794 | f.writeBlock( cstr.data(), cstr.length() ); | 797 | f.writeBlock( cstr.data(), cstr.length() ); |
795 | } | 798 | } |
796 | 799 | ||
797 | buf = "<Contact "; | 800 | buf = "<Contact "; |
798 | cnt.save( buf ); | 801 | cnt.save( buf ); |
799 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 802 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
800 | buf += "/>\n"; | 803 | buf += "/>\n"; |
801 | QCString cstr = buf.utf8(); | 804 | QCString cstr = buf.utf8(); |
802 | f.writeBlock( cstr.data(), cstr.length() ); | 805 | f.writeBlock( cstr.data(), cstr.length() ); |
803 | } | 806 | } |
804 | 807 | ||
805 | void OContactAccessBackend_XML::removeJournal() | 808 | void OContactAccessBackend_XML::removeJournal() |
806 | { | 809 | { |
807 | QFile f ( m_journalName ); | 810 | QFile f ( m_journalName ); |
808 | if ( f.exists() ) | 811 | if ( f.exists() ) |
809 | f.remove(); | 812 | f.remove(); |
810 | } | 813 | } |
811 | 814 | ||
diff --git a/libopie/pim/oconversion.h b/libopie/pim/oconversion.h index 13367e1..4c0a497 100644 --- a/libopie/pim/oconversion.h +++ b/libopie/pim/oconversion.h | |||
@@ -1,43 +1,48 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | **********************************************************************/ | 17 | **********************************************************************/ |
18 | 18 | ||
19 | #ifndef __oconversion_h__ | 19 | #ifndef __oconversion_h__ |
20 | #define __oconversion_h__ | 20 | #define __oconversion_h__ |
21 | 21 | ||
22 | /* #include <time.h> */ | 22 | /* #include <time.h> */ |
23 | /* #include <sys/types.h> */ | 23 | /* #include <sys/types.h> */ |
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | 25 | ||
26 | /* FIXME namespace? -zecke */ | 26 | /* FIXME namespace? -zecke */ |
27 | class OConversion | 27 | class OConversion |
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | static QString dateToString( const QDate &d ); | 30 | static QString dateToString( const QDate &d ); |
31 | static QDate dateFromString( const QString &datestr ); | 31 | static QDate dateFromString( const QString &datestr ); |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * simple function to store DateTime as string and read from string | 34 | * simple function to store DateTime as string and read from string |
35 | * no timezone changing is done | 35 | * no timezone changing is done |
36 | * DDMMYYYYHHMMSS is the simple format | 36 | * DDMMYYYYHHMMSS is the simple format |
37 | */ | 37 | */ |
38 | static QString dateTimeToString( const QDateTime& ); | 38 | static QString dateTimeToString( const QDateTime& ); |
39 | static QDateTime dateTimeFromString( const QString& ); | 39 | static QDateTime dateTimeFromString( const QString& ); |
40 | |||
41 | private: | ||
42 | class Private; | ||
43 | Private* d; | ||
44 | |||
40 | }; | 45 | }; |
41 | 46 | ||
42 | #endif // __oconversion_h__ | 47 | #endif // __oconversion_h__ |
43 | 48 | ||
diff --git a/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h index 86ff298..3c02c42 100644 --- a/libopie/pim/odatebookaccessbackend.h +++ b/libopie/pim/odatebookaccessbackend.h | |||
@@ -1,73 +1,77 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include "opimaccessbackend.h" | 6 | #include "opimaccessbackend.h" |
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * This class is the interface to the storage of Events. | 10 | * This class is the interface to the storage of Events. |
11 | * @see OPimAccessBackend | 11 | * @see OPimAccessBackend |
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
15 | public: | 15 | public: |
16 | typedef int UID; | 16 | typedef int UID; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * c'tor without parameter | 19 | * c'tor without parameter |
20 | */ | 20 | */ |
21 | ODateBookAccessBackend(); | 21 | ODateBookAccessBackend(); |
22 | ~ODateBookAccessBackend(); | 22 | ~ODateBookAccessBackend(); |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * This method should return a list of UIDs containing | 25 | * This method should return a list of UIDs containing |
26 | * all events. No filter should be applied | 26 | * all events. No filter should be applied |
27 | * @return list of events | 27 | * @return list of events |
28 | */ | 28 | */ |
29 | virtual QArray<UID> rawEvents()const = 0; | 29 | virtual QArray<UID> rawEvents()const = 0; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * This method should return a list of UIDs containing | 32 | * This method should return a list of UIDs containing |
33 | * all repeating events. No filter should be applied | 33 | * all repeating events. No filter should be applied |
34 | * @return list of repeating events | 34 | * @return list of repeating events |
35 | */ | 35 | */ |
36 | virtual QArray<UID> rawRepeats()const = 0; | 36 | virtual QArray<UID> rawRepeats()const = 0; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * This mthod should return a list of UIDs containing all non | 39 | * This mthod should return a list of UIDs containing all non |
40 | * repeating events. No filter should be applied | 40 | * repeating events. No filter should be applied |
41 | * @return list of nonrepeating events | 41 | * @return list of nonrepeating events |
42 | */ | 42 | */ |
43 | virtual QArray<UID> nonRepeats() const = 0; | 43 | virtual QArray<UID> nonRepeats() const = 0; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * If you do not want to implement the effectiveEvents methods below | 46 | * If you do not want to implement the effectiveEvents methods below |
47 | * you need to supply it with directNonRepeats. | 47 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | 48 | * This method can return empty lists if effectiveEvents is implememted |
49 | */ | 49 | */ |
50 | virtual OEvent::ValueList directNonRepeats() = 0; | 50 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Same as above but return raw repeats! | 53 | * Same as above but return raw repeats! |
54 | */ | 54 | */ |
55 | virtual OEvent::ValueList directRawRepeats() = 0; | 55 | virtual OEvent::ValueList directRawRepeats() = 0; |
56 | 56 | ||
57 | /* is implemented by default but you can reimplement it*/ | 57 | /* is implemented by default but you can reimplement it*/ |
58 | /** | 58 | /** |
59 | * Effective Events are special event occuring during a time frame. This method does calcualte | 59 | * Effective Events are special event occuring during a time frame. This method does calcualte |
60 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method | 60 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method |
61 | * yourself | 61 | * yourself |
62 | */ | 62 | */ |
63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); | 63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * this is an overloaded member function | 66 | * this is an overloaded member function |
67 | * @see effecticeEvents | 67 | * @see effecticeEvents |
68 | */ | 68 | */ |
69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); | 69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); |
70 | 70 | ||
71 | private: | ||
72 | class Private; | ||
73 | Private *d; | ||
74 | |||
71 | }; | 75 | }; |
72 | 76 | ||
73 | #endif | 77 | #endif |
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index ab2eea4..5ea945c 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -1,606 +1,606 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | 6 | ||
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
9 | #include <sys/stat.h> | 9 | #include <sys/stat.h> |
10 | 10 | ||
11 | #include <unistd.h> | 11 | #include <unistd.h> |
12 | 12 | ||
13 | #include <qasciidict.h> | 13 | #include <qasciidict.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | 15 | ||
16 | #include <qtopia/global.h> | 16 | #include <qtopia/global.h> |
17 | #include <qtopia/stringutil.h> | 17 | #include <qtopia/stringutil.h> |
18 | #include <qtopia/timeconversion.h> | 18 | #include <qtopia/timeconversion.h> |
19 | 19 | ||
20 | #include "opimnotifymanager.h" | 20 | #include "opimnotifymanager.h" |
21 | #include "orecur.h" | 21 | #include "orecur.h" |
22 | #include "otimezone.h" | 22 | #include "otimezone.h" |
23 | #include "odatebookaccessbackend_xml.h" | 23 | #include "odatebookaccessbackend_xml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | // FROM TT again | 26 | // FROM TT again |
27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
28 | { | 28 | { |
29 | char needleChar; | 29 | char needleChar; |
30 | char haystackChar; | 30 | char haystackChar; |
31 | if (!needle || !haystack || !hLen || !nLen) | 31 | if (!needle || !haystack || !hLen || !nLen) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | const char* hsearch = haystack; | 34 | const char* hsearch = haystack; |
35 | 35 | ||
36 | if ((needleChar = *needle++) != 0) { | 36 | if ((needleChar = *needle++) != 0) { |
37 | nLen--; //(to make up for needle++) | 37 | nLen--; //(to make up for needle++) |
38 | do { | 38 | do { |
39 | do { | 39 | do { |
40 | if ((haystackChar = *hsearch++) == 0) | 40 | if ((haystackChar = *hsearch++) == 0) |
41 | return (0); | 41 | return (0); |
42 | if (hsearch >= haystack + hLen) | 42 | if (hsearch >= haystack + hLen) |
43 | return (0); | 43 | return (0); |
44 | } while (haystackChar != needleChar); | 44 | } while (haystackChar != needleChar); |
45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
46 | hsearch--; | 46 | hsearch--; |
47 | } | 47 | } |
48 | return ((char *)hsearch); | 48 | return ((char *)hsearch); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | namespace { | 52 | namespace { |
53 | time_t start, end, created, rp_end; | 53 | time_t start, end, created, rp_end; |
54 | ORecur* rec; | 54 | ORecur* rec; |
55 | ORecur* recur() { | 55 | ORecur* recur() { |
56 | if (!rec) | 56 | if (!rec) |
57 | rec = new ORecur; | 57 | rec = new ORecur; |
58 | 58 | ||
59 | return rec; | 59 | return rec; |
60 | } | 60 | } |
61 | int alarmTime; | 61 | int alarmTime; |
62 | int snd; | 62 | int snd; |
63 | enum Attribute{ | 63 | enum Attribute{ |
64 | FDescription = 0, | 64 | FDescription = 0, |
65 | FLocation, | 65 | FLocation, |
66 | FCategories, | 66 | FCategories, |
67 | FUid, | 67 | FUid, |
68 | FType, | 68 | FType, |
69 | FAlarm, | 69 | FAlarm, |
70 | FSound, | 70 | FSound, |
71 | FRType, | 71 | FRType, |
72 | FRWeekdays, | 72 | FRWeekdays, |
73 | FRPosition, | 73 | FRPosition, |
74 | FRFreq, | 74 | FRFreq, |
75 | FRHasEndDate, | 75 | FRHasEndDate, |
76 | FREndDate, | 76 | FREndDate, |
77 | FRStart, | 77 | FRStart, |
78 | FREnd, | 78 | FREnd, |
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, |
81 | FTimeZone, | 81 | FTimeZone, |
82 | FRecParent, | 82 | FRecParent, |
83 | FRecChildren, | 83 | FRecChildren, |
84 | FExceptions | 84 | FExceptions |
85 | }; | 85 | }; |
86 | inline void save( const OEvent& ev, QString& buf ) { | 86 | inline void save( const OEvent& ev, QString& buf ) { |
87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); | 87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); |
88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
89 | if (!ev.location().isEmpty() ) | 89 | if (!ev.location().isEmpty() ) |
90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
91 | 91 | ||
92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
94 | 94 | ||
95 | if (ev.isAllDay() ) | 95 | if (ev.isAllDay() ) |
96 | buf += " type=\"AllDay\""; | 96 | buf += " type=\"AllDay\""; |
97 | 97 | ||
98 | if (ev.hasNotifiers() ) { | 98 | if (ev.hasNotifiers() ) { |
99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
102 | if ( alarm.sound() == OPimAlarm::Loud ) | 102 | if ( alarm.sound() == OPimAlarm::Loud ) |
103 | buf += "loud"; | 103 | buf += "loud"; |
104 | else | 104 | else |
105 | buf += "silent"; | 105 | buf += "silent"; |
106 | buf += "\""; | 106 | buf += "\""; |
107 | } | 107 | } |
108 | if ( ev.hasRecurrence() ) { | 108 | if ( ev.hasRecurrence() ) { |
109 | buf += ev.recurrence().toString(); | 109 | buf += ev.recurrence().toString(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /* | 112 | /* |
113 | * fscking timezones :) well, we'll first convert | 113 | * fscking timezones :) well, we'll first convert |
114 | * the QDateTime to a QDateTime in UTC time | 114 | * the QDateTime to a QDateTime in UTC time |
115 | * and then we'll create a nice time_t | 115 | * and then we'll create a nice time_t |
116 | */ | 116 | */ |
117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
120 | if (!ev.note().isEmpty() ) { | 120 | if (!ev.note().isEmpty() ) { |
121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
122 | } | 122 | } |
123 | 123 | ||
124 | buf += " timezone=\""; | 124 | buf += " timezone=\""; |
125 | if ( ev.timeZone().isEmpty() ) | 125 | if ( ev.timeZone().isEmpty() ) |
126 | buf += "None"; | 126 | buf += "None"; |
127 | else | 127 | else |
128 | buf += ev.timeZone(); | 128 | buf += ev.timeZone(); |
129 | buf += "\""; | 129 | buf += "\""; |
130 | 130 | ||
131 | if (ev.parent() != 0 ) { | 131 | if (ev.parent() != 0 ) { |
132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
133 | } | 133 | } |
134 | 134 | ||
135 | if (ev.children().count() != 0 ) { | 135 | if (ev.children().count() != 0 ) { |
136 | QArray<int> children = ev.children(); | 136 | QArray<int> children = ev.children(); |
137 | buf += " recchildren=\""; | 137 | buf += " recchildren=\""; |
138 | for ( uint i = 0; i < children.count(); i++ ) { | 138 | for ( uint i = 0; i < children.count(); i++ ) { |
139 | if ( i != 0 ) buf += " "; | 139 | if ( i != 0 ) buf += " "; |
140 | buf += QString::number( children[i] ); | 140 | buf += QString::number( children[i] ); |
141 | } | 141 | } |
142 | buf+= "\""; | 142 | buf+= "\""; |
143 | } | 143 | } |
144 | 144 | ||
145 | // skip custom writing | 145 | // skip custom writing |
146 | } | 146 | } |
147 | 147 | ||
148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
149 | QMap<int, OEvent>::ConstIterator it; | 149 | QMap<int, OEvent>::ConstIterator it; |
150 | QString buf; | 150 | QString buf; |
151 | QCString str; | 151 | QCString str; |
152 | int total_written; | 152 | int total_written; |
153 | for ( it = list.begin(); it != list.end(); ++it ) { | 153 | for ( it = list.begin(); it != list.end(); ++it ) { |
154 | buf = "<event"; | 154 | buf = "<event"; |
155 | save( it.data(), buf ); | 155 | save( it.data(), buf ); |
156 | buf += " />\n"; | 156 | buf += " />\n"; |
157 | str = buf.utf8(); | 157 | str = buf.utf8(); |
158 | 158 | ||
159 | total_written = file.writeBlock(str.data(), str.length() ); | 159 | total_written = file.writeBlock(str.data(), str.length() ); |
160 | if ( total_written != int(str.length() ) ) | 160 | if ( total_written != int(str.length() ) ) |
161 | return false; | 161 | return false; |
162 | } | 162 | } |
163 | return true; | 163 | return true; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
168 | const QString& fileName ) | 168 | const QString& fileName ) |
169 | : ODateBookAccessBackend() { | 169 | : ODateBookAccessBackend() { |
170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
171 | m_changed = false; | 171 | m_changed = false; |
172 | } | 172 | } |
173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
174 | } | 174 | } |
175 | bool ODateBookAccessBackend_XML::load() { | 175 | bool ODateBookAccessBackend_XML::load() { |
176 | return loadFile(); | 176 | return loadFile(); |
177 | } | 177 | } |
178 | bool ODateBookAccessBackend_XML::reload() { | 178 | bool ODateBookAccessBackend_XML::reload() { |
179 | clear(); | 179 | clear(); |
180 | return load(); | 180 | return load(); |
181 | } | 181 | } |
182 | bool ODateBookAccessBackend_XML::save() { | 182 | bool ODateBookAccessBackend_XML::save() { |
183 | if (!m_changed) return true; | 183 | if (!m_changed) return true; |
184 | 184 | ||
185 | int total_written; | 185 | int total_written; |
186 | QString strFileNew = m_name + ".new"; | 186 | QString strFileNew = m_name + ".new"; |
187 | 187 | ||
188 | QFile f( strFileNew ); | 188 | QFile f( strFileNew ); |
189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
190 | 190 | ||
191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
193 | buf += "<events>\n"; | 193 | buf += "<events>\n"; |
194 | QCString str = buf.utf8(); | 194 | QCString str = buf.utf8(); |
195 | total_written = f.writeBlock( str.data(), str.length() ); | 195 | total_written = f.writeBlock( str.data(), str.length() ); |
196 | if ( total_written != int(str.length() ) ) { | 196 | if ( total_written != int(str.length() ) ) { |
197 | f.close(); | 197 | f.close(); |
198 | QFile::remove( strFileNew ); | 198 | QFile::remove( strFileNew ); |
199 | return false; | 199 | return false; |
200 | } | 200 | } |
201 | 201 | ||
202 | if (!forAll( m_raw, f ) ) { | 202 | if (!forAll( m_raw, f ) ) { |
203 | f.close(); | 203 | f.close(); |
204 | QFile::remove( strFileNew ); | 204 | QFile::remove( strFileNew ); |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | if (!forAll( m_rep, f ) ) { | 207 | if (!forAll( m_rep, f ) ) { |
208 | f.close(); | 208 | f.close(); |
209 | QFile::remove( strFileNew ); | 209 | QFile::remove( strFileNew ); |
210 | return false; | 210 | return false; |
211 | } | 211 | } |
212 | 212 | ||
213 | buf = "</events>\n</DATEBOOK>\n"; | 213 | buf = "</events>\n</DATEBOOK>\n"; |
214 | str = buf.utf8(); | 214 | str = buf.utf8(); |
215 | total_written = f.writeBlock( str.data(), str.length() ); | 215 | total_written = f.writeBlock( str.data(), str.length() ); |
216 | if ( total_written != int(str.length() ) ) { | 216 | if ( total_written != int(str.length() ) ) { |
217 | f.close(); | 217 | f.close(); |
218 | QFile::remove( strFileNew ); | 218 | QFile::remove( strFileNew ); |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | f.close(); | 221 | f.close(); |
222 | 222 | ||
223 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 223 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
224 | QFile::remove( strFileNew ); | 224 | QFile::remove( strFileNew ); |
225 | return false; | 225 | return false; |
226 | } | 226 | } |
227 | 227 | ||
228 | m_changed = false; | 228 | m_changed = false; |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
233 | uint i = 0; | 233 | uint i = 0; |
234 | QMap<int, OEvent>::ConstIterator it; | 234 | QMap<int, OEvent>::ConstIterator it; |
235 | 235 | ||
236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
237 | ints[i] = it.key(); | 237 | ints[i] = it.key(); |
238 | i++; | 238 | i++; |
239 | } | 239 | } |
240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
241 | ints[i] = it.key(); | 241 | ints[i] = it.key(); |
242 | i++; | 242 | i++; |
243 | } | 243 | } |
244 | 244 | ||
245 | return ints; | 245 | return ints; |
246 | } | 246 | } |
247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { | 247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { |
248 | return QArray<int>(); | 248 | return QArray<int>(); |
249 | } | 249 | } |
250 | void ODateBookAccessBackend_XML::clear() { | 250 | void ODateBookAccessBackend_XML::clear() { |
251 | m_changed = true; | 251 | m_changed = true; |
252 | m_raw.clear(); | 252 | m_raw.clear(); |
253 | m_rep.clear(); | 253 | m_rep.clear(); |
254 | } | 254 | } |
255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
256 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
257 | return m_raw[uid]; | 257 | return m_raw[uid]; |
258 | else | 258 | else |
259 | return m_rep[uid]; | 259 | return m_rep[uid]; |
260 | } | 260 | } |
261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
262 | m_changed = true; | 262 | m_changed = true; |
263 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
264 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
265 | else | 265 | else |
266 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
267 | 267 | ||
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
271 | m_changed = true; | 271 | m_changed = true; |
272 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
273 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
274 | 274 | ||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
279 | return add( ev ); | 279 | return add( ev ); |
280 | } | 280 | } |
281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
282 | return allRecords(); | 282 | return allRecords(); |
283 | } | 283 | } |
284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
285 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
286 | uint i = 0; | 286 | uint i = 0; |
287 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
288 | 288 | ||
289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
290 | ints[i] = it.key(); | 290 | ints[i] = it.key(); |
291 | i++; | 291 | i++; |
292 | } | 292 | } |
293 | 293 | ||
294 | return ints; | 294 | return ints; |
295 | } | 295 | } |
296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
297 | QArray<int> ints( m_raw.count() ); | 297 | QArray<int> ints( m_raw.count() ); |
298 | uint i = 0; | 298 | uint i = 0; |
299 | QMap<int, OEvent>::ConstIterator it; | 299 | QMap<int, OEvent>::ConstIterator it; |
300 | 300 | ||
301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
302 | ints[i] = it.key(); | 302 | ints[i] = it.key(); |
303 | i++; | 303 | i++; |
304 | } | 304 | } |
305 | 305 | ||
306 | return ints; | 306 | return ints; |
307 | } | 307 | } |
308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
309 | OEvent::ValueList list; | 309 | OEvent::ValueList list; |
310 | QMap<int, OEvent>::ConstIterator it; | 310 | QMap<int, OEvent>::ConstIterator it; |
311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
312 | list.append( it.data() ); | 312 | list.append( it.data() ); |
313 | 313 | ||
314 | return list; | 314 | return list; |
315 | } | 315 | } |
316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
317 | OEvent::ValueList list; | 317 | OEvent::ValueList list; |
318 | QMap<int, OEvent>::ConstIterator it; | 318 | QMap<int, OEvent>::ConstIterator it; |
319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
320 | list.append( it.data() ); | 320 | list.append( it.data() ); |
321 | 321 | ||
322 | return list; | 322 | return list; |
323 | } | 323 | } |
324 | bool ODateBookAccessBackend_XML::loadFile() { | 324 | bool ODateBookAccessBackend_XML::loadFile() { |
325 | m_changed = false; | 325 | m_changed = false; |
326 | 326 | ||
327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
328 | if ( fd < 0 ) return false; | 328 | if ( fd < 0 ) return false; |
329 | 329 | ||
330 | struct stat attribute; | 330 | struct stat attribute; |
331 | if ( ::fstat(fd, &attribute ) == -1 ) { | 331 | if ( ::fstat(fd, &attribute ) == -1 ) { |
332 | ::close( fd ); | 332 | ::close( fd ); |
333 | return false; | 333 | return false; |
334 | } | 334 | } |
335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
336 | if ( map_addr == ( (caddr_t)-1) ) { | 336 | if ( map_addr == ( (caddr_t)-1) ) { |
337 | ::close( fd ); | 337 | ::close( fd ); |
338 | return false; | 338 | return false; |
339 | } | 339 | } |
340 | 340 | ||
341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
342 | ::close( fd ); | 342 | ::close( fd ); |
343 | 343 | ||
344 | QAsciiDict<int> dict(FExceptions+1); | 344 | QAsciiDict<int> dict(FExceptions+1); |
345 | dict.setAutoDelete( true ); | 345 | dict.setAutoDelete( true ); |
346 | dict.insert( "description", new int(FDescription) ); | 346 | dict.insert( "description", new int(FDescription) ); |
347 | dict.insert( "location", new int(FLocation) ); | 347 | dict.insert( "location", new int(FLocation) ); |
348 | dict.insert( "categories", new int(FCategories) ); | 348 | dict.insert( "categories", new int(FCategories) ); |
349 | dict.insert( "uid", new int(FUid) ); | 349 | dict.insert( "uid", new int(FUid) ); |
350 | dict.insert( "type", new int(FType) ); | 350 | dict.insert( "type", new int(FType) ); |
351 | dict.insert( "alarm", new int(FAlarm) ); | 351 | dict.insert( "alarm", new int(FAlarm) ); |
352 | dict.insert( "sound", new int(FSound) ); | 352 | dict.insert( "sound", new int(FSound) ); |
353 | dict.insert( "rtype", new int(FRType) ); | 353 | dict.insert( "rtype", new int(FRType) ); |
354 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 354 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
355 | dict.insert( "rposition", new int(FRPosition) ); | 355 | dict.insert( "rposition", new int(FRPosition) ); |
356 | dict.insert( "rfreq", new int(FRFreq) ); | 356 | dict.insert( "rfreq", new int(FRFreq) ); |
357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
358 | dict.insert( "enddt", new int(FREndDate) ); | 358 | dict.insert( "enddt", new int(FREndDate) ); |
359 | dict.insert( "start", new int(FRStart) ); | 359 | dict.insert( "start", new int(FRStart) ); |
360 | dict.insert( "end", new int(FREnd) ); | 360 | dict.insert( "end", new int(FREnd) ); |
361 | dict.insert( "note", new int(FNote) ); | 361 | dict.insert( "note", new int(FNote) ); |
362 | dict.insert( "created", new int(FCreated) ); | 362 | dict.insert( "created", new int(FCreated) ); |
363 | dict.insert( "recparent", new int(FRecParent) ); | 363 | dict.insert( "recparent", new int(FRecParent) ); |
364 | dict.insert( "recchildren", new int(FRecChildren) ); | 364 | dict.insert( "recchildren", new int(FRecChildren) ); |
365 | dict.insert( "exceptions", new int(FExceptions) ); | 365 | dict.insert( "exceptions", new int(FExceptions) ); |
366 | dict.insert( "timezone", new int(FTimeZone) ); | 366 | dict.insert( "timezone", new int(FTimeZone) ); |
367 | 367 | ||
368 | char* dt = (char*)map_addr; | 368 | char* dt = (char*)map_addr; |
369 | int len = attribute.st_size; | 369 | int len = attribute.st_size; |
370 | int i = 0; | 370 | int i = 0; |
371 | char* point; | 371 | char* point; |
372 | const char* collectionString = "<event "; | 372 | const char* collectionString = "<event "; |
373 | int strLen = ::strlen(collectionString); | 373 | int strLen = ::strlen(collectionString); |
374 | int *find; | 374 | int *find; |
375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
376 | i = point -dt; | 376 | i = point -dt; |
377 | i+= strLen; | 377 | i+= strLen; |
378 | 378 | ||
379 | alarmTime = -1; | 379 | alarmTime = -1; |
380 | snd = 0; // silent | 380 | snd = 0; // silent |
381 | 381 | ||
382 | OEvent ev; | 382 | OEvent ev; |
383 | rec = 0; | 383 | rec = 0; |
384 | 384 | ||
385 | while ( TRUE ) { | 385 | while ( TRUE ) { |
386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
387 | ++i; | 387 | ++i; |
388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
389 | break; | 389 | break; |
390 | 390 | ||
391 | 391 | ||
392 | // we have another attribute, read it. | 392 | // we have another attribute, read it. |
393 | int j = i; | 393 | int j = i; |
394 | while ( j < len && dt[j] != '=' ) | 394 | while ( j < len && dt[j] != '=' ) |
395 | ++j; | 395 | ++j; |
396 | QCString attr( dt+i, j-i+1); | 396 | QCString attr( dt+i, j-i+1); |
397 | 397 | ||
398 | i = ++j; // skip = | 398 | i = ++j; // skip = |
399 | 399 | ||
400 | // find the start of quotes | 400 | // find the start of quotes |
401 | while ( i < len && dt[i] != '"' ) | 401 | while ( i < len && dt[i] != '"' ) |
402 | ++i; | 402 | ++i; |
403 | j = ++i; | 403 | j = ++i; |
404 | 404 | ||
405 | bool haveUtf = FALSE; | 405 | bool haveUtf = FALSE; |
406 | bool haveEnt = FALSE; | 406 | bool haveEnt = FALSE; |
407 | while ( j < len && dt[j] != '"' ) { | 407 | while ( j < len && dt[j] != '"' ) { |
408 | if ( ((unsigned char)dt[j]) > 0x7f ) | 408 | if ( ((unsigned char)dt[j]) > 0x7f ) |
409 | haveUtf = TRUE; | 409 | haveUtf = TRUE; |
410 | if ( dt[j] == '&' ) | 410 | if ( dt[j] == '&' ) |
411 | haveEnt = TRUE; | 411 | haveEnt = TRUE; |
412 | ++j; | 412 | ++j; |
413 | } | 413 | } |
414 | if ( i == j ) { | 414 | if ( i == j ) { |
415 | // empty value | 415 | // empty value |
416 | i = j + 1; | 416 | i = j + 1; |
417 | continue; | 417 | continue; |
418 | } | 418 | } |
419 | 419 | ||
420 | QCString value( dt+i, j-i+1 ); | 420 | QCString value( dt+i, j-i+1 ); |
421 | i = j + 1; | 421 | i = j + 1; |
422 | 422 | ||
423 | QString str = (haveUtf ? QString::fromUtf8( value ) | 423 | QString str = (haveUtf ? QString::fromUtf8( value ) |
424 | : QString::fromLatin1( value ) ); | 424 | : QString::fromLatin1( value ) ); |
425 | if ( haveEnt ) | 425 | if ( haveEnt ) |
426 | str = Qtopia::plainString( str ); | 426 | str = Qtopia::plainString( str ); |
427 | 427 | ||
428 | /* | 428 | /* |
429 | * add key + value | 429 | * add key + value |
430 | */ | 430 | */ |
431 | find = dict[attr.data()]; | 431 | find = dict[attr.data()]; |
432 | if (!find) | 432 | if (!find) |
433 | ev.setCustomField( attr, value ); | 433 | ev.setCustomField( attr, str ); |
434 | else { | 434 | else { |
435 | setField( ev, *find, value ); | 435 | setField( ev, *find, str ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | /* time to finalize */ | 438 | /* time to finalize */ |
439 | finalizeRecord( ev ); | 439 | finalizeRecord( ev ); |
440 | delete rec; | 440 | delete rec; |
441 | } | 441 | } |
442 | ::munmap(map_addr, attribute.st_size ); | 442 | ::munmap(map_addr, attribute.st_size ); |
443 | m_changed = false; // changed during add | 443 | m_changed = false; // changed during add |
444 | 444 | ||
445 | return true; | 445 | return true; |
446 | } | 446 | } |
447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
448 | /* AllDay is alway in UTC */ | 448 | /* AllDay is alway in UTC */ |
449 | if ( ev.isAllDay() ) { | 449 | if ( ev.isAllDay() ) { |
450 | OTimeZone utc = OTimeZone::utc(); | 450 | OTimeZone utc = OTimeZone::utc(); |
451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
453 | ev.setTimeZone( "UTC"); // make sure it is really utc | 453 | ev.setTimeZone( "UTC"); // make sure it is really utc |
454 | }else { | 454 | }else { |
455 | /* to current date time */ | 455 | /* to current date time */ |
456 | qWarning(" Start is %d", start ); | 456 | // qWarning(" Start is %d", start ); |
457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
458 | QDateTime date = zone.toDateTime( start ); | 458 | QDateTime date = zone.toDateTime( start ); |
459 | qWarning(" Start is %s", date.toString().latin1() ); | 459 | qWarning(" Start is %s", date.toString().latin1() ); |
460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
461 | 461 | ||
462 | date = zone.toDateTime( end ); | 462 | date = zone.toDateTime( end ); |
463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
464 | } | 464 | } |
465 | if ( rec && rec->doesRecur() ) { | 465 | if ( rec && rec->doesRecur() ) { |
466 | OTimeZone utc = OTimeZone::utc(); | 466 | OTimeZone utc = OTimeZone::utc(); |
467 | ORecur recu( *rec ); // call copy c'tor; | 467 | ORecur recu( *rec ); // call copy c'tor; |
468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
470 | recu.setStart( ev.startDateTime().date() ); | 470 | recu.setStart( ev.startDateTime().date() ); |
471 | ev.setRecurrence( recu ); | 471 | ev.setRecurrence( recu ); |
472 | } | 472 | } |
473 | 473 | ||
474 | if (alarmTime != -1 ) { | 474 | if (alarmTime != -1 ) { |
475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
476 | OPimAlarm al( snd , dt ); | 476 | OPimAlarm al( snd , dt ); |
477 | ev.notifiers().add( al ); | 477 | ev.notifiers().add( al ); |
478 | } | 478 | } |
479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
480 | qWarning("already contains assign uid"); | 480 | qWarning("already contains assign uid"); |
481 | ev.setUid( 1 ); | 481 | ev.setUid( 1 ); |
482 | } | 482 | } |
483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); | 483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); |
484 | if ( ev.hasRecurrence() ) | 484 | if ( ev.hasRecurrence() ) |
485 | m_rep.insert( ev.uid(), ev ); | 485 | m_rep.insert( ev.uid(), ev ); |
486 | else | 486 | else |
487 | m_raw.insert( ev.uid(), ev ); | 487 | m_raw.insert( ev.uid(), ev ); |
488 | 488 | ||
489 | } | 489 | } |
490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
491 | // qWarning(" setting %s", value.latin1() ); | 491 | // qWarning(" setting %s", value.latin1() ); |
492 | switch( id ) { | 492 | switch( id ) { |
493 | case FDescription: | 493 | case FDescription: |
494 | e.setDescription( value ); | 494 | e.setDescription( value ); |
495 | break; | 495 | break; |
496 | case FLocation: | 496 | case FLocation: |
497 | e.setLocation( value ); | 497 | e.setLocation( value ); |
498 | break; | 498 | break; |
499 | case FCategories: | 499 | case FCategories: |
500 | e.setCategories( e.idsFromString( value ) ); | 500 | e.setCategories( e.idsFromString( value ) ); |
501 | break; | 501 | break; |
502 | case FUid: | 502 | case FUid: |
503 | e.setUid( value.toInt() ); | 503 | e.setUid( value.toInt() ); |
504 | break; | 504 | break; |
505 | case FType: | 505 | case FType: |
506 | if ( value == "AllDay" ) { | 506 | if ( value == "AllDay" ) { |
507 | e.setAllDay( true ); | 507 | e.setAllDay( true ); |
508 | e.setTimeZone( "UTC" ); | 508 | e.setTimeZone( "UTC" ); |
509 | } | 509 | } |
510 | break; | 510 | break; |
511 | case FAlarm: | 511 | case FAlarm: |
512 | alarmTime = value.toInt(); | 512 | alarmTime = value.toInt(); |
513 | break; | 513 | break; |
514 | case FSound: | 514 | case FSound: |
515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
516 | break; | 516 | break; |
517 | // recurrence stuff | 517 | // recurrence stuff |
518 | case FRType: | 518 | case FRType: |
519 | if ( value == "Daily" ) | 519 | if ( value == "Daily" ) |
520 | recur()->setType( ORecur::Daily ); | 520 | recur()->setType( ORecur::Daily ); |
521 | else if ( value == "Weekly" ) | 521 | else if ( value == "Weekly" ) |
522 | recur()->setType( ORecur::Weekly); | 522 | recur()->setType( ORecur::Weekly); |
523 | else if ( value == "MonthlyDay" ) | 523 | else if ( value == "MonthlyDay" ) |
524 | recur()->setType( ORecur::MonthlyDay ); | 524 | recur()->setType( ORecur::MonthlyDay ); |
525 | else if ( value == "MonthlyDate" ) | 525 | else if ( value == "MonthlyDate" ) |
526 | recur()->setType( ORecur::MonthlyDate ); | 526 | recur()->setType( ORecur::MonthlyDate ); |
527 | else if ( value == "Yearly" ) | 527 | else if ( value == "Yearly" ) |
528 | recur()->setType( ORecur::Yearly ); | 528 | recur()->setType( ORecur::Yearly ); |
529 | else | 529 | else |
530 | recur()->setType( ORecur::NoRepeat ); | 530 | recur()->setType( ORecur::NoRepeat ); |
531 | break; | 531 | break; |
532 | case FRWeekdays: | 532 | case FRWeekdays: |
533 | recur()->setDays( value.toInt() ); | 533 | recur()->setDays( value.toInt() ); |
534 | break; | 534 | break; |
535 | case FRPosition: | 535 | case FRPosition: |
536 | recur()->setPosition( value.toInt() ); | 536 | recur()->setPosition( value.toInt() ); |
537 | break; | 537 | break; |
538 | case FRFreq: | 538 | case FRFreq: |
539 | recur()->setFrequency( value.toInt() ); | 539 | recur()->setFrequency( value.toInt() ); |
540 | break; | 540 | break; |
541 | case FRHasEndDate: | 541 | case FRHasEndDate: |
542 | recur()->setHasEndDate( value.toInt() ); | 542 | recur()->setHasEndDate( value.toInt() ); |
543 | break; | 543 | break; |
544 | case FREndDate: { | 544 | case FREndDate: { |
545 | rp_end = (time_t) value.toLong(); | 545 | rp_end = (time_t) value.toLong(); |
546 | break; | 546 | break; |
547 | } | 547 | } |
548 | case FRStart: { | 548 | case FRStart: { |
549 | start = (time_t) value.toLong(); | 549 | start = (time_t) value.toLong(); |
550 | break; | 550 | break; |
551 | } | 551 | } |
552 | case FREnd: { | 552 | case FREnd: { |
553 | end = ( (time_t) value.toLong() ); | 553 | end = ( (time_t) value.toLong() ); |
554 | break; | 554 | break; |
555 | } | 555 | } |
556 | case FNote: | 556 | case FNote: |
557 | e.setNote( value ); | 557 | e.setNote( value ); |
558 | break; | 558 | break; |
559 | case FCreated: | 559 | case FCreated: |
560 | created = value.toInt(); | 560 | created = value.toInt(); |
561 | break; | 561 | break; |
562 | case FRecParent: | 562 | case FRecParent: |
563 | e.setParent( value.toInt() ); | 563 | e.setParent( value.toInt() ); |
564 | break; | 564 | break; |
565 | case FRecChildren:{ | 565 | case FRecChildren:{ |
566 | QStringList list = QStringList::split(' ', value ); | 566 | QStringList list = QStringList::split(' ', value ); |
567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
568 | e.addChild( (*it).toInt() ); | 568 | e.addChild( (*it).toInt() ); |
569 | } | 569 | } |
570 | } | 570 | } |
571 | break; | 571 | break; |
572 | case FExceptions:{ | 572 | case FExceptions:{ |
573 | QStringList list = QStringList::split(' ', value ); | 573 | QStringList list = QStringList::split(' ', value ); |
574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
576 | qWarning("adding exception %s", date.toString().latin1() ); | 576 | qWarning("adding exception %s", date.toString().latin1() ); |
577 | recur()->exceptions().append( date ); | 577 | recur()->exceptions().append( date ); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | break; | 580 | break; |
581 | case FTimeZone: | 581 | case FTimeZone: |
582 | if ( value != "None" ) | 582 | if ( value != "None" ) |
583 | e.setTimeZone( value ); | 583 | e.setTimeZone( value ); |
584 | break; | 584 | break; |
585 | default: | 585 | default: |
586 | break; | 586 | break; |
587 | } | 587 | } |
588 | } | 588 | } |
589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
590 | { | 590 | { |
591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); | 591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); |
592 | uint arraycounter = 0; | 592 | uint arraycounter = 0; |
593 | QMap<int, OEvent>::ConstIterator it; | 593 | QMap<int, OEvent>::ConstIterator it; |
594 | 594 | ||
595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) | 595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) |
596 | if ( it.data().match( r ) ) | 596 | if ( it.data().match( r ) ) |
597 | m_currentQuery[arraycounter++] = it.data().uid(); | 597 | m_currentQuery[arraycounter++] = it.data().uid(); |
598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) | 598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) |
599 | if ( it.data().match( r ) ) | 599 | if ( it.data().match( r ) ) |
600 | m_currentQuery[arraycounter++] = it.data().uid(); | 600 | m_currentQuery[arraycounter++] = it.data().uid(); |
601 | 601 | ||
602 | // Shrink to fit.. | 602 | // Shrink to fit.. |
603 | m_currentQuery.resize(arraycounter); | 603 | m_currentQuery.resize(arraycounter); |
604 | 604 | ||
605 | return m_currentQuery; | 605 | return m_currentQuery; |
606 | } | 606 | } |
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h index f4bbe35..c3d91f7 100644 --- a/libopie/pim/opimaccessbackend.h +++ b/libopie/pim/opimaccessbackend.h | |||
@@ -1,159 +1,159 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_BACKEND | 1 | #ifndef OPIE_PIM_ACCESS_BACKEND |
2 | #define OPIE_PIM_ACCESS_BACKEND | 2 | #define OPIE_PIM_ACCESS_BACKEND |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/otemplatebase.h> | 6 | #include <opie/otemplatebase.h> |
7 | #include <opie/opimrecord.h> | 7 | #include <opie/opimrecord.h> |
8 | 8 | ||
9 | 9 | ||
10 | class OPimAccessBackendPrivate; | ||
10 | /** | 11 | /** |
11 | * OPimAccessBackend is the base class | 12 | * OPimAccessBackend is the base class |
12 | * for all private backends | 13 | * for all private backends |
13 | * it operates on OPimRecord as the base class | 14 | * it operates on OPimRecord as the base class |
14 | * and it's responsible for fast manipulating | 15 | * and it's responsible for fast manipulating |
15 | * the resource the implementation takes care | 16 | * the resource the implementation takes care |
16 | * of | 17 | * of |
17 | */ | 18 | */ |
18 | template <class T = OPimRecord> | 19 | template <class T = OPimRecord> |
19 | class OPimAccessBackend { | 20 | class OPimAccessBackend { |
20 | public: | 21 | public: |
21 | typedef OTemplateBase<T> Frontend; | 22 | typedef OTemplateBase<T> Frontend; |
22 | 23 | ||
23 | /** The access hint from the frontend */ | 24 | /** The access hint from the frontend */ |
24 | OPimAccessBackend(int access = 0); | 25 | OPimAccessBackend(int access = 0); |
25 | virtual ~OPimAccessBackend(); | 26 | virtual ~OPimAccessBackend(); |
26 | 27 | ||
27 | /** | 28 | /** |
28 | * load the resource | 29 | * load the resource |
29 | */ | 30 | */ |
30 | virtual bool load() = 0; | 31 | virtual bool load() = 0; |
31 | 32 | ||
32 | /** | 33 | /** |
33 | * reload the resource | 34 | * reload the resource |
34 | */ | 35 | */ |
35 | virtual bool reload() = 0; | 36 | virtual bool reload() = 0; |
36 | 37 | ||
37 | /** | 38 | /** |
38 | * save the resource and | 39 | * save the resource and |
39 | * all it's changes | 40 | * all it's changes |
40 | */ | 41 | */ |
41 | virtual bool save() = 0; | 42 | virtual bool save() = 0; |
42 | 43 | ||
43 | /** | 44 | /** |
44 | * return an array of | 45 | * return an array of |
45 | * all available uids | 46 | * all available uids |
46 | */ | 47 | */ |
47 | virtual QArray<int> allRecords()const = 0; | 48 | virtual QArray<int> allRecords()const = 0; |
48 | 49 | ||
49 | /** | 50 | /** |
50 | * return a List of records | 51 | * return a List of records |
51 | * that match the regex | 52 | * that match the regex |
52 | */ | 53 | */ |
53 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; | 54 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * queryByExample for T with the given Settings | 57 | * queryByExample for T with the given Settings |
57 | * | 58 | * |
58 | */ | 59 | */ |
59 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; | 60 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * find the OPimRecord with uid @param uid | 63 | * find the OPimRecord with uid @param uid |
63 | * returns T and T.isEmpty() if nothing was found | 64 | * returns T and T.isEmpty() if nothing was found |
64 | */ | 65 | */ |
65 | virtual T find(int uid )const = 0; | 66 | virtual T find(int uid )const = 0; |
66 | 67 | ||
67 | virtual T find(int uid, const QArray<int>& items, | 68 | virtual T find(int uid, const QArray<int>& items, |
68 | uint current, typename Frontend::CacheDirection )const ; | 69 | uint current, typename Frontend::CacheDirection )const ; |
69 | /** | 70 | /** |
70 | * clear the back end | 71 | * clear the back end |
71 | */ | 72 | */ |
72 | virtual void clear() = 0; | 73 | virtual void clear() = 0; |
73 | 74 | ||
74 | /** | 75 | /** |
75 | * add T | 76 | * add T |
76 | */ | 77 | */ |
77 | virtual bool add( const T& t ) = 0; | 78 | virtual bool add( const T& t ) = 0; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * remove | 81 | * remove |
81 | */ | 82 | */ |
82 | virtual bool remove( int uid ) = 0; | 83 | virtual bool remove( int uid ) = 0; |
83 | 84 | ||
84 | /** | 85 | /** |
85 | * replace a record with T.uid() | 86 | * replace a record with T.uid() |
86 | */ | 87 | */ |
87 | virtual bool replace( const T& t ) = 0; | 88 | virtual bool replace( const T& t ) = 0; |
88 | 89 | ||
89 | /* | 90 | /* |
90 | * setTheFrontEnd!!! | 91 | * setTheFrontEnd!!! |
91 | */ | 92 | */ |
92 | void setFrontend( Frontend* front ); | 93 | void setFrontend( Frontend* front ); |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * set the read ahead count | 96 | * set the read ahead count |
96 | */ | 97 | */ |
97 | void setReadAhead( uint count ); | 98 | void setReadAhead( uint count ); |
98 | protected: | 99 | protected: |
99 | int access()const; | 100 | int access()const; |
100 | void cache( const T& t )const; | 101 | void cache( const T& t )const; |
101 | 102 | ||
102 | /** | 103 | /** |
103 | * use a prime number here! | 104 | * use a prime number here! |
104 | */ | 105 | */ |
105 | void setSaneCacheSize( int ); | 106 | void setSaneCacheSize( int ); |
106 | 107 | ||
107 | uint readAhead()const; | 108 | uint readAhead()const; |
108 | 109 | ||
109 | private: | 110 | private: |
110 | class Private; | 111 | OPimAccessBackendPrivate *d; |
111 | Private* d; | ||
112 | Frontend* m_front; | 112 | Frontend* m_front; |
113 | uint m_read; | 113 | uint m_read; |
114 | int m_acc; | 114 | int m_acc; |
115 | 115 | ||
116 | }; | 116 | }; |
117 | 117 | ||
118 | template <class T> | 118 | template <class T> |
119 | OPimAccessBackend<T>::OPimAccessBackend(int acc) | 119 | OPimAccessBackend<T>::OPimAccessBackend(int acc) |
120 | : m_acc( acc ) | 120 | : m_acc( acc ) |
121 | { | 121 | { |
122 | m_front = 0l; | 122 | m_front = 0l; |
123 | } | 123 | } |
124 | template <class T> | 124 | template <class T> |
125 | OPimAccessBackend<T>::~OPimAccessBackend() { | 125 | OPimAccessBackend<T>::~OPimAccessBackend() { |
126 | 126 | ||
127 | } | 127 | } |
128 | template <class T> | 128 | template <class T> |
129 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 129 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
130 | m_front = fr; | 130 | m_front = fr; |
131 | } | 131 | } |
132 | template <class T> | 132 | template <class T> |
133 | void OPimAccessBackend<T>::cache( const T& t )const { | 133 | void OPimAccessBackend<T>::cache( const T& t )const { |
134 | if (m_front ) | 134 | if (m_front ) |
135 | m_front->cache( t ); | 135 | m_front->cache( t ); |
136 | } | 136 | } |
137 | template <class T> | 137 | template <class T> |
138 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 138 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
139 | if (m_front ) | 139 | if (m_front ) |
140 | m_front->setSaneCacheSize( size ); | 140 | m_front->setSaneCacheSize( size ); |
141 | } | 141 | } |
142 | template <class T> | 142 | template <class T> |
143 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 143 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
144 | uint, typename Frontend::CacheDirection )const { | 144 | uint, typename Frontend::CacheDirection )const { |
145 | return find( uid ); | 145 | return find( uid ); |
146 | } | 146 | } |
147 | template <class T> | 147 | template <class T> |
148 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | 148 | void OPimAccessBackend<T>::setReadAhead( uint count ) { |
149 | m_read = count; | 149 | m_read = count; |
150 | } | 150 | } |
151 | template <class T> | 151 | template <class T> |
152 | uint OPimAccessBackend<T>::readAhead()const { | 152 | uint OPimAccessBackend<T>::readAhead()const { |
153 | return m_read; | 153 | return m_read; |
154 | } | 154 | } |
155 | template <class T> | 155 | template <class T> |
156 | int OPimAccessBackend<T>::access()const { | 156 | int OPimAccessBackend<T>::access()const { |
157 | return m_acc; | 157 | return m_acc; |
158 | } | 158 | } |
159 | #endif | 159 | #endif |
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 8ff205c..ecbeb68 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -1,298 +1,302 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "opimcache.h" | 10 | #include "opimcache.h" |
11 | #include "otemplatebase.h" | 11 | #include "otemplatebase.h" |
12 | 12 | ||
13 | class OPimAccessTemplatePrivate; | ||
13 | /** | 14 | /** |
14 | * Thats the frontend to our OPIE PIM | 15 | * Thats the frontend to our OPIE PIM |
15 | * Library. Either you want to use it's | 16 | * Library. Either you want to use it's |
16 | * interface or you want to implement | 17 | * interface or you want to implement |
17 | * your own Access lib | 18 | * your own Access lib |
18 | * Just create a OPimRecord and inherit from | 19 | * Just create a OPimRecord and inherit from |
19 | * the plugins | 20 | * the plugins |
20 | */ | 21 | */ |
21 | 22 | ||
22 | template <class T = OPimRecord > | 23 | template <class T = OPimRecord > |
23 | class OPimAccessTemplate : public OTemplateBase<T> { | 24 | class OPimAccessTemplate : public OTemplateBase<T> { |
24 | public: | 25 | public: |
25 | enum Access { | 26 | enum Access { |
26 | Random = 0, | 27 | Random = 0, |
27 | SortedAccess | 28 | SortedAccess |
28 | }; | 29 | }; |
29 | typedef ORecordList<T> List; | 30 | typedef ORecordList<T> List; |
30 | typedef OPimAccessBackend<T> BackEnd; | 31 | typedef OPimAccessBackend<T> BackEnd; |
31 | typedef OPimCache<T> Cache; | 32 | typedef OPimCache<T> Cache; |
32 | 33 | ||
33 | /** | 34 | /** |
34 | * c'tor BackEnd | 35 | * c'tor BackEnd |
35 | * enum Access a small hint on how to handle the backend | 36 | * enum Access a small hint on how to handle the backend |
36 | */ | 37 | */ |
37 | OPimAccessTemplate( BackEnd* end); | 38 | OPimAccessTemplate( BackEnd* end); |
38 | 39 | ||
39 | virtual ~OPimAccessTemplate(); | 40 | virtual ~OPimAccessTemplate(); |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * load from the backend | 43 | * load from the backend |
43 | */ | 44 | */ |
44 | bool load(); | 45 | bool load(); |
45 | 46 | ||
46 | /** Reload database. | 47 | /** Reload database. |
47 | * You should execute this function if the external database | 48 | * You should execute this function if the external database |
48 | * was changed. | 49 | * was changed. |
49 | * This function will load the external database and afterwards | 50 | * This function will load the external database and afterwards |
50 | * rejoin the local changes. Therefore the local database will be set consistent. | 51 | * rejoin the local changes. Therefore the local database will be set consistent. |
51 | */ | 52 | */ |
52 | virtual bool reload(); | 53 | virtual bool reload(); |
53 | 54 | ||
54 | /** Save contacts database. | 55 | /** Save contacts database. |
55 | * Save is more a "commit". After calling this function, all changes are public available. | 56 | * Save is more a "commit". After calling this function, all changes are public available. |
56 | * @return true if successful | 57 | * @return true if successful |
57 | */ | 58 | */ |
58 | bool save(); | 59 | bool save(); |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * if the resource was changed externally | 62 | * if the resource was changed externally |
62 | * You should use the signal handling instead of polling possible changes ! | 63 | * You should use the signal handling instead of polling possible changes ! |
63 | * zecke: Do you implement a signal for otodoaccess ? | 64 | * zecke: Do you implement a signal for otodoaccess ? |
64 | */ | 65 | */ |
65 | bool wasChangedExternally()const; | 66 | bool wasChangedExternally()const; |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * return a List of records | 69 | * return a List of records |
69 | * you can iterate over them | 70 | * you can iterate over them |
70 | */ | 71 | */ |
71 | virtual List allRecords()const; | 72 | virtual List allRecords()const; |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * return a List of records | 75 | * return a List of records |
75 | * that match the regex | 76 | * that match the regex |
76 | */ | 77 | */ |
77 | virtual List matchRegexp( const QRegExp &r ) const; | 78 | virtual List matchRegexp( const QRegExp &r ) const; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * queryByExample. | 81 | * queryByExample. |
81 | * @see otodoaccess, ocontactaccess | 82 | * @see otodoaccess, ocontactaccess |
82 | */ | 83 | */ |
83 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); | 84 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * find the OPimRecord uid | 87 | * find the OPimRecord uid |
87 | */ | 88 | */ |
88 | virtual T find( int uid )const; | 89 | virtual T find( int uid )const; |
89 | 90 | ||
90 | /** | 91 | /** |
91 | * read ahead cache find method ;) | 92 | * read ahead cache find method ;) |
92 | */ | 93 | */ |
93 | virtual T find( int uid, const QArray<int>&, | 94 | virtual T find( int uid, const QArray<int>&, |
94 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 95 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
95 | 96 | ||
96 | /* invalidate cache here */ | 97 | /* invalidate cache here */ |
97 | /** | 98 | /** |
98 | * clears the backend and invalidates the backend | 99 | * clears the backend and invalidates the backend |
99 | */ | 100 | */ |
100 | void clear() ; | 101 | void clear() ; |
101 | 102 | ||
102 | /** | 103 | /** |
103 | * add T to the backend | 104 | * add T to the backend |
104 | * @param t The item to add. | 105 | * @param t The item to add. |
105 | * @return <i>true</i> if added successfully. | 106 | * @return <i>true</i> if added successfully. |
106 | */ | 107 | */ |
107 | virtual bool add( const T& t ) ; | 108 | virtual bool add( const T& t ) ; |
108 | bool add( const OPimRecord& ); | 109 | bool add( const OPimRecord& ); |
109 | 110 | ||
110 | /* only the uid matters */ | 111 | /* only the uid matters */ |
111 | /** | 112 | /** |
112 | * remove T from the backend | 113 | * remove T from the backend |
113 | * @param t The item to remove | 114 | * @param t The item to remove |
114 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
115 | */ | 116 | */ |
116 | virtual bool remove( const T& t ); | 117 | virtual bool remove( const T& t ); |
117 | 118 | ||
118 | /** | 119 | /** |
119 | * remove the OPimRecord with uid | 120 | * remove the OPimRecord with uid |
120 | * @param uid The ID of the item to remove | 121 | * @param uid The ID of the item to remove |
121 | * @return <i>true</i> if successful. | 122 | * @return <i>true</i> if successful. |
122 | */ | 123 | */ |
123 | bool remove( int uid ); | 124 | bool remove( int uid ); |
124 | bool remove( const OPimRecord& ); | 125 | bool remove( const OPimRecord& ); |
125 | 126 | ||
126 | /** | 127 | /** |
127 | * replace T from backend | 128 | * replace T from backend |
128 | * @param t The item to replace | 129 | * @param t The item to replace |
129 | * @return <i>true</i> if successful. | 130 | * @return <i>true</i> if successful. |
130 | */ | 131 | */ |
131 | virtual bool replace( const T& t) ; | 132 | virtual bool replace( const T& t) ; |
132 | 133 | ||
133 | void setReadAhead( uint count ); | 134 | void setReadAhead( uint count ); |
134 | /** | 135 | /** |
135 | * @internal | 136 | * @internal |
136 | */ | 137 | */ |
137 | void cache( const T& )const; | 138 | void cache( const T& )const; |
138 | void setSaneCacheSize( int ); | 139 | void setSaneCacheSize( int ); |
139 | 140 | ||
140 | QArray<int> records()const; | 141 | QArray<int> records()const; |
141 | protected: | 142 | protected: |
142 | /** | 143 | /** |
143 | * invalidate the cache | 144 | * invalidate the cache |
144 | */ | 145 | */ |
145 | void invalidateCache(); | 146 | void invalidateCache(); |
146 | 147 | ||
147 | void setBackEnd( BackEnd* end ); | 148 | void setBackEnd( BackEnd* end ); |
148 | /** | 149 | /** |
149 | * returns the backend | 150 | * returns the backend |
150 | */ | 151 | */ |
151 | BackEnd* backEnd(); | 152 | BackEnd* backEnd(); |
152 | BackEnd* m_backEnd; | 153 | BackEnd* m_backEnd; |
153 | Cache m_cache; | 154 | Cache m_cache; |
154 | 155 | ||
156 | private: | ||
157 | OPimAccessTemplatePrivate *d; | ||
158 | |||
155 | }; | 159 | }; |
156 | 160 | ||
157 | template <class T> | 161 | template <class T> |
158 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 162 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
159 | : OTemplateBase<T>(), m_backEnd( end ) | 163 | : OTemplateBase<T>(), m_backEnd( end ) |
160 | { | 164 | { |
161 | if (end ) | 165 | if (end ) |
162 | end->setFrontend( this ); | 166 | end->setFrontend( this ); |
163 | } | 167 | } |
164 | template <class T> | 168 | template <class T> |
165 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 169 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
166 | qWarning("~OPimAccessTemplate<T>"); | 170 | qWarning("~OPimAccessTemplate<T>"); |
167 | delete m_backEnd; | 171 | delete m_backEnd; |
168 | } | 172 | } |
169 | template <class T> | 173 | template <class T> |
170 | bool OPimAccessTemplate<T>::load() { | 174 | bool OPimAccessTemplate<T>::load() { |
171 | invalidateCache(); | 175 | invalidateCache(); |
172 | return m_backEnd->load(); | 176 | return m_backEnd->load(); |
173 | } | 177 | } |
174 | template <class T> | 178 | template <class T> |
175 | bool OPimAccessTemplate<T>::reload() { | 179 | bool OPimAccessTemplate<T>::reload() { |
176 | invalidateCache(); // zecke: I think this should be added (se) | 180 | invalidateCache(); // zecke: I think this should be added (se) |
177 | return m_backEnd->reload(); | 181 | return m_backEnd->reload(); |
178 | } | 182 | } |
179 | template <class T> | 183 | template <class T> |
180 | bool OPimAccessTemplate<T>::save() { | 184 | bool OPimAccessTemplate<T>::save() { |
181 | return m_backEnd->save(); | 185 | return m_backEnd->save(); |
182 | } | 186 | } |
183 | template <class T> | 187 | template <class T> |
184 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 188 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
185 | QArray<int> ints = m_backEnd->allRecords(); | 189 | QArray<int> ints = m_backEnd->allRecords(); |
186 | List lis(ints, this ); | 190 | List lis(ints, this ); |
187 | return lis; | 191 | return lis; |
188 | } | 192 | } |
189 | template <class T> | 193 | template <class T> |
190 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 194 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
191 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 195 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
192 | List lis(ints, this ); | 196 | List lis(ints, this ); |
193 | return lis; | 197 | return lis; |
194 | } | 198 | } |
195 | template <class T> | 199 | template <class T> |
196 | QArray<int> OPimAccessTemplate<T>::records()const { | 200 | QArray<int> OPimAccessTemplate<T>::records()const { |
197 | return m_backEnd->allRecords(); | 201 | return m_backEnd->allRecords(); |
198 | } | 202 | } |
199 | template <class T> | 203 | template <class T> |
200 | typename OPimAccessTemplate<T>::List | 204 | typename OPimAccessTemplate<T>::List |
201 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 205 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { |
202 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | 206 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); |
203 | 207 | ||
204 | List lis(ints, this ); | 208 | List lis(ints, this ); |
205 | return lis; | 209 | return lis; |
206 | } | 210 | } |
207 | template <class T> | 211 | template <class T> |
208 | T OPimAccessTemplate<T>::find( int uid ) const{ | 212 | T OPimAccessTemplate<T>::find( int uid ) const{ |
209 | T t = m_backEnd->find( uid ); | 213 | T t = m_backEnd->find( uid ); |
210 | cache( t ); | 214 | cache( t ); |
211 | return t; | 215 | return t; |
212 | } | 216 | } |
213 | template <class T> | 217 | template <class T> |
214 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 218 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
215 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 219 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
216 | /* | 220 | /* |
217 | * better do T.isEmpty() | 221 | * better do T.isEmpty() |
218 | * after a find this way we would | 222 | * after a find this way we would |
219 | * avoid two finds in QCache... | 223 | * avoid two finds in QCache... |
220 | */ | 224 | */ |
221 | // qWarning("find it now %d", uid ); | 225 | // qWarning("find it now %d", uid ); |
222 | if (m_cache.contains( uid ) ) { | 226 | if (m_cache.contains( uid ) ) { |
223 | return m_cache.find( uid ); | 227 | return m_cache.find( uid ); |
224 | } | 228 | } |
225 | 229 | ||
226 | T t = m_backEnd->find( uid, ar, current, dir ); | 230 | T t = m_backEnd->find( uid, ar, current, dir ); |
227 | cache( t ); | 231 | cache( t ); |
228 | return t; | 232 | return t; |
229 | } | 233 | } |
230 | template <class T> | 234 | template <class T> |
231 | void OPimAccessTemplate<T>::clear() { | 235 | void OPimAccessTemplate<T>::clear() { |
232 | invalidateCache(); | 236 | invalidateCache(); |
233 | m_backEnd->clear(); | 237 | m_backEnd->clear(); |
234 | } | 238 | } |
235 | template <class T> | 239 | template <class T> |
236 | bool OPimAccessTemplate<T>::add( const T& t ) { | 240 | bool OPimAccessTemplate<T>::add( const T& t ) { |
237 | cache( t ); | 241 | cache( t ); |
238 | return m_backEnd->add( t ); | 242 | return m_backEnd->add( t ); |
239 | } | 243 | } |
240 | template <class T> | 244 | template <class T> |
241 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 245 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
242 | /* same type */ | 246 | /* same type */ |
243 | if ( rec.rtti() == T::rtti() ) { | 247 | if ( rec.rtti() == T::rtti() ) { |
244 | const T &t = static_cast<const T&>(rec); | 248 | const T &t = static_cast<const T&>(rec); |
245 | return add(t); | 249 | return add(t); |
246 | } | 250 | } |
247 | return false; | 251 | return false; |
248 | } | 252 | } |
249 | template <class T> | 253 | template <class T> |
250 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 254 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
251 | return remove( t.uid() ); | 255 | return remove( t.uid() ); |
252 | } | 256 | } |
253 | template <class T> | 257 | template <class T> |
254 | bool OPimAccessTemplate<T>::remove( int uid ) { | 258 | bool OPimAccessTemplate<T>::remove( int uid ) { |
255 | m_cache.remove( uid ); | 259 | m_cache.remove( uid ); |
256 | return m_backEnd->remove( uid ); | 260 | return m_backEnd->remove( uid ); |
257 | } | 261 | } |
258 | template <class T> | 262 | template <class T> |
259 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 263 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
260 | return remove( rec.uid() ); | 264 | return remove( rec.uid() ); |
261 | } | 265 | } |
262 | template <class T> | 266 | template <class T> |
263 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 267 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
264 | m_cache.replace( t ); | 268 | m_cache.replace( t ); |
265 | return m_backEnd->replace( t ); | 269 | return m_backEnd->replace( t ); |
266 | } | 270 | } |
267 | template <class T> | 271 | template <class T> |
268 | void OPimAccessTemplate<T>::invalidateCache() { | 272 | void OPimAccessTemplate<T>::invalidateCache() { |
269 | m_cache.invalidate(); | 273 | m_cache.invalidate(); |
270 | } | 274 | } |
271 | template <class T> | 275 | template <class T> |
272 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 276 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
273 | return m_backEnd; | 277 | return m_backEnd; |
274 | } | 278 | } |
275 | template <class T> | 279 | template <class T> |
276 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 280 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
277 | return false; | 281 | return false; |
278 | } | 282 | } |
279 | template <class T> | 283 | template <class T> |
280 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 284 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
281 | m_backEnd = end; | 285 | m_backEnd = end; |
282 | if (m_backEnd ) | 286 | if (m_backEnd ) |
283 | m_backEnd->setFrontend( this ); | 287 | m_backEnd->setFrontend( this ); |
284 | } | 288 | } |
285 | template <class T> | 289 | template <class T> |
286 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 290 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
287 | /* hacky we need to work around the const*/ | 291 | /* hacky we need to work around the const*/ |
288 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 292 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
289 | } | 293 | } |
290 | template <class T> | 294 | template <class T> |
291 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 295 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
292 | m_cache.setSize( size ); | 296 | m_cache.setSize( size ); |
293 | } | 297 | } |
294 | template <class T> | 298 | template <class T> |
295 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | 299 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { |
296 | m_backEnd->setReadAhead( count ); | 300 | m_backEnd->setReadAhead( count ); |
297 | } | 301 | } |
298 | #endif | 302 | #endif |
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h index 73414e5..7f7cff5 100644 --- a/libopie/pim/opimcache.h +++ b/libopie/pim/opimcache.h | |||
@@ -1,125 +1,131 @@ | |||
1 | #ifndef OPIE_PIM_CACHE_H | 1 | #ifndef OPIE_PIM_CACHE_H |
2 | #define OPIE_PIM_CACHE_H | 2 | #define OPIE_PIM_CACHE_H |
3 | 3 | ||
4 | #include <qintcache.h> | 4 | #include <qintcache.h> |
5 | 5 | ||
6 | #include "opimrecord.h" | 6 | #include "opimrecord.h" |
7 | 7 | ||
8 | class OPimCacheItemPrivate; | ||
9 | |||
8 | template <class T = OPimRecord> | 10 | template <class T = OPimRecord> |
9 | class OPimCacheItem { | 11 | class OPimCacheItem { |
10 | public: | 12 | public: |
11 | OPimCacheItem( const T& t = T() ); | 13 | OPimCacheItem( const T& t = T() ); |
12 | OPimCacheItem( const OPimCacheItem& ); | 14 | OPimCacheItem( const OPimCacheItem& ); |
13 | ~OPimCacheItem(); | 15 | ~OPimCacheItem(); |
14 | 16 | ||
15 | OPimCacheItem &operator=( const OPimCacheItem& ); | 17 | OPimCacheItem &operator=( const OPimCacheItem& ); |
16 | 18 | ||
17 | T record()const; | 19 | T record()const; |
18 | void setRecord( const T& ); | 20 | void setRecord( const T& ); |
19 | private: | 21 | private: |
20 | T m_t; | 22 | T m_t; |
23 | OPimCacheItemPrivate *d; | ||
21 | }; | 24 | }; |
22 | 25 | ||
26 | |||
27 | class OPimCachePrivate; | ||
23 | /** | 28 | /** |
24 | * OPimCache for caching the items | 29 | * OPimCache for caching the items |
25 | * We support adding, removing | 30 | * We support adding, removing |
26 | * and finding | 31 | * and finding |
27 | */ | 32 | */ |
28 | template <class T = OPimRecord> | 33 | template <class T = OPimRecord> |
29 | class OPimCache { | 34 | class OPimCache { |
30 | public: | 35 | public: |
31 | typedef OPimCacheItem<T> Item; | 36 | typedef OPimCacheItem<T> Item; |
32 | OPimCache(); | 37 | OPimCache(); |
33 | OPimCache( const OPimCache& ); | 38 | OPimCache( const OPimCache& ); |
34 | ~OPimCache(); | 39 | ~OPimCache(); |
35 | 40 | ||
36 | OPimCache &operator=( const OPimCache& ); | 41 | OPimCache &operator=( const OPimCache& ); |
37 | 42 | ||
38 | bool contains(int uid)const; | 43 | bool contains(int uid)const; |
39 | void invalidate(); | 44 | void invalidate(); |
40 | void setSize( int size ); | 45 | void setSize( int size ); |
41 | 46 | ||
42 | T find(int uid )const; | 47 | T find(int uid )const; |
43 | void add( const T& ); | 48 | void add( const T& ); |
44 | void remove( int uid ); | 49 | void remove( int uid ); |
45 | void replace( const T& ); | 50 | void replace( const T& ); |
46 | 51 | ||
47 | private: | 52 | private: |
48 | QIntCache<Item> m_cache; | 53 | QIntCache<Item> m_cache; |
54 | OPimCachePrivate* d; | ||
49 | }; | 55 | }; |
50 | 56 | ||
51 | // Implementation | 57 | // Implementation |
52 | template <class T> | 58 | template <class T> |
53 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 59 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
54 | : m_t(t) { | 60 | : m_t(t) { |
55 | } | 61 | } |
56 | template <class T> | 62 | template <class T> |
57 | OPimCacheItem<T>::~OPimCacheItem() { | 63 | OPimCacheItem<T>::~OPimCacheItem() { |
58 | 64 | ||
59 | } | 65 | } |
60 | template <class T> | 66 | template <class T> |
61 | T OPimCacheItem<T>::record()const { | 67 | T OPimCacheItem<T>::record()const { |
62 | return m_t; | 68 | return m_t; |
63 | } | 69 | } |
64 | template <class T> | 70 | template <class T> |
65 | void OPimCacheItem<T>::setRecord( const T& t ) { | 71 | void OPimCacheItem<T>::setRecord( const T& t ) { |
66 | m_t = t; | 72 | m_t = t; |
67 | } | 73 | } |
68 | // Cache | 74 | // Cache |
69 | template <class T> | 75 | template <class T> |
70 | OPimCache<T>::OPimCache() | 76 | OPimCache<T>::OPimCache() |
71 | : m_cache(100, 53 ) | 77 | : m_cache(100, 53 ) |
72 | { | 78 | { |
73 | m_cache.setAutoDelete( TRUE ); | 79 | m_cache.setAutoDelete( TRUE ); |
74 | } | 80 | } |
75 | template <class T> | 81 | template <class T> |
76 | OPimCache<T>::~OPimCache() { | 82 | OPimCache<T>::~OPimCache() { |
77 | 83 | ||
78 | } | 84 | } |
79 | template <class T> | 85 | template <class T> |
80 | bool OPimCache<T>::contains(int uid )const { | 86 | bool OPimCache<T>::contains(int uid )const { |
81 | Item* it = m_cache.find( uid, FALSE ); | 87 | Item* it = m_cache.find( uid, FALSE ); |
82 | if (!it) | 88 | if (!it) |
83 | return false; | 89 | return false; |
84 | return true; | 90 | return true; |
85 | } | 91 | } |
86 | template <class T> | 92 | template <class T> |
87 | void OPimCache<T>::invalidate() { | 93 | void OPimCache<T>::invalidate() { |
88 | m_cache.clear(); | 94 | m_cache.clear(); |
89 | } | 95 | } |
90 | template <class T> | 96 | template <class T> |
91 | void OPimCache<T>::setSize( int size ) { | 97 | void OPimCache<T>::setSize( int size ) { |
92 | m_cache.setMaxCost( size ); | 98 | m_cache.setMaxCost( size ); |
93 | } | 99 | } |
94 | template <class T> | 100 | template <class T> |
95 | T OPimCache<T>::find(int uid )const { | 101 | T OPimCache<T>::find(int uid )const { |
96 | Item *it = m_cache.find( uid ); | 102 | Item *it = m_cache.find( uid ); |
97 | if (it) | 103 | if (it) |
98 | return it->record(); | 104 | return it->record(); |
99 | return T(); | 105 | return T(); |
100 | } | 106 | } |
101 | template <class T> | 107 | template <class T> |
102 | void OPimCache<T>::add( const T& t ) { | 108 | void OPimCache<T>::add( const T& t ) { |
103 | Item* it = 0l; | 109 | Item* it = 0l; |
104 | it = m_cache.find(t.uid(), FALSE ); | 110 | it = m_cache.find(t.uid(), FALSE ); |
105 | 111 | ||
106 | if (it ) | 112 | if (it ) |
107 | it->setRecord( t ); | 113 | it->setRecord( t ); |
108 | 114 | ||
109 | it = new Item( t ); | 115 | it = new Item( t ); |
110 | if (!m_cache.insert( t.uid(), it ) ) | 116 | if (!m_cache.insert( t.uid(), it ) ) |
111 | delete it; | 117 | delete it; |
112 | } | 118 | } |
113 | template <class T> | 119 | template <class T> |
114 | void OPimCache<T>::remove( int uid ) { | 120 | void OPimCache<T>::remove( int uid ) { |
115 | m_cache.remove( uid ); | 121 | m_cache.remove( uid ); |
116 | } | 122 | } |
117 | template <class T> | 123 | template <class T> |
118 | void OPimCache<T>::replace( const T& t) { | 124 | void OPimCache<T>::replace( const T& t) { |
119 | Item *it = m_cache.find( t.uid() ); | 125 | Item *it = m_cache.find( t.uid() ); |
120 | if ( it ) { | 126 | if ( it ) { |
121 | it->setRecord( t ); | 127 | it->setRecord( t ); |
122 | } | 128 | } |
123 | } | 129 | } |
124 | 130 | ||
125 | #endif | 131 | #endif |
diff --git a/libopie/pim/opimmainwindow.cpp b/libopie/pim/opimmainwindow.cpp index 4044bc1..2739e26 100644 --- a/libopie/pim/opimmainwindow.cpp +++ b/libopie/pim/opimmainwindow.cpp | |||
@@ -1,138 +1,150 @@ | |||
1 | #include <qapplication.h> | 1 | #include <qapplication.h> |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | #include <qcopchannel_qws.h> | 3 | #include <qcopchannel_qws.h> |
4 | 4 | ||
5 | #include <qpe/sound.h> | 5 | #include <qpe/sound.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | #include <qpe/qpeapplication.h> | ||
7 | 8 | ||
8 | #include "opimresolver.h" | 9 | #include "opimresolver.h" |
9 | #include "opimmainwindow.h" | 10 | #include "opimmainwindow.h" |
10 | 11 | ||
11 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 12 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, |
12 | const char* name, WFlags flag ) | 13 | const char* name, WFlags flag ) |
13 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { | 14 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { |
14 | 15 | ||
15 | /* | 16 | /* |
16 | * let's generate our QCopChannel | 17 | * let's generate our QCopChannel |
17 | */ | 18 | */ |
18 | m_str = QString("QPE/"+m_service).local8Bit(); | 19 | m_str = QString("QPE/"+m_service).local8Bit(); |
19 | m_channel= new QCopChannel(m_str, this ); | 20 | m_channel= new QCopChannel(m_str, this ); |
20 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | 21 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), |
21 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 22 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
22 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), | 23 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), |
23 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 24 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
24 | 25 | ||
25 | /* connect flush and reload */ | 26 | /* connect flush and reload */ |
26 | connect(qApp, SIGNAL(flush() ), | 27 | connect(qApp, SIGNAL(flush() ), |
27 | this, SLOT(flush() ) ); | 28 | this, SLOT(flush() ) ); |
28 | connect(qApp, SIGNAL(reload() ), | 29 | connect(qApp, SIGNAL(reload() ), |
29 | this, SLOT(reload() ) ); | 30 | this, SLOT(reload() ) ); |
30 | } | 31 | } |
31 | OPimMainWindow::~OPimMainWindow() { | 32 | OPimMainWindow::~OPimMainWindow() { |
32 | delete m_channel; | 33 | delete m_channel; |
33 | } | 34 | } |
34 | QCopChannel* OPimMainWindow::channel() { | 35 | QCopChannel* OPimMainWindow::channel() { |
35 | return m_channel; | 36 | return m_channel; |
36 | } | 37 | } |
37 | void OPimMainWindow::doSetDocument( const QString& ) { | 38 | void OPimMainWindow::doSetDocument( const QString& ) { |
38 | 39 | ||
39 | } | 40 | } |
40 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 41 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
42 | bool needShow = false; | ||
41 | /* | 43 | /* |
42 | * create demands to create | 44 | * create demands to create |
43 | * a new record... | 45 | * a new record... |
44 | */ | 46 | */ |
45 | QDataStream stream(array, IO_ReadOnly); | 47 | QDataStream stream(array, IO_ReadOnly); |
46 | if ( cmd == "create()" ) { | 48 | if ( cmd == "create()" ) { |
49 | raise(); | ||
47 | int uid = create(); | 50 | int uid = create(); |
48 | QCopEnvelope e(m_str, "created(int)" ); | 51 | QCopEnvelope e(m_str, "created(int)" ); |
49 | e << uid; | 52 | e << uid; |
53 | needShow = true; | ||
50 | }else if ( cmd == "remove(int)" ) { | 54 | }else if ( cmd == "remove(int)" ) { |
51 | int uid; | 55 | int uid; |
52 | stream >> uid; | 56 | stream >> uid; |
53 | bool rem = remove( uid ); | 57 | bool rem = remove( uid ); |
54 | QCopEnvelope e(m_str, "removed(bool)" ); | 58 | QCopEnvelope e(m_str, "removed(bool)" ); |
55 | e << rem; | 59 | e << rem; |
60 | needShow = true; | ||
56 | }else if ( cmd == "beam(int)" ) { | 61 | }else if ( cmd == "beam(int)" ) { |
57 | int uid; | 62 | int uid; |
58 | stream >> uid; | 63 | stream >> uid; |
59 | beam( uid); | 64 | beam( uid); |
60 | }else if ( cmd == "show(int)" ) { | 65 | }else if ( cmd == "show(int)" ) { |
66 | raise(); | ||
61 | int uid; | 67 | int uid; |
62 | stream >> uid; | 68 | stream >> uid; |
63 | show( uid ); | 69 | show( uid ); |
70 | needShow = true; | ||
64 | }else if ( cmd == "edit(int)" ) { | 71 | }else if ( cmd == "edit(int)" ) { |
72 | raise(); | ||
65 | int uid; | 73 | int uid; |
66 | stream >> uid; | 74 | stream >> uid; |
67 | edit( uid ); | 75 | edit( uid ); |
68 | }else if ( cmd == "add(int,QByteArray)" ) { | 76 | }else if ( cmd == "add(int,QByteArray)" ) { |
69 | int rtti; | 77 | int rtti; |
70 | QByteArray array; | 78 | QByteArray array; |
71 | stream >> rtti; | 79 | stream >> rtti; |
72 | stream >> array; | 80 | stream >> array; |
73 | m_fallBack = record(rtti, array ); | 81 | m_fallBack = record(rtti, array ); |
74 | if (!m_fallBack) return; | 82 | if (!m_fallBack) return; |
75 | add( *m_fallBack ); | 83 | add( *m_fallBack ); |
76 | delete m_fallBack; | 84 | delete m_fallBack; |
77 | }else if ( cmd == "alarm(QDateTime,int)" ) { | 85 | }else if ( cmd == "alarm(QDateTime,int)" ) { |
86 | raise(); | ||
78 | QDateTime dt; int uid; | 87 | QDateTime dt; int uid; |
79 | stream >> dt; | 88 | stream >> dt; |
80 | stream >> uid; | 89 | stream >> uid; |
81 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); | 90 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); |
82 | QDateTime current = QDateTime::currentDateTime(); | 91 | QDateTime current = QDateTime::currentDateTime(); |
83 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) | 92 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) |
84 | return; | 93 | return; |
85 | doAlarm( dt, uid ); | 94 | doAlarm( dt, uid ); |
86 | 95 | needShow = true; | |
87 | } | 96 | } |
97 | |||
98 | if (needShow ) | ||
99 | QPEApplication::setKeepRunning(); | ||
88 | } | 100 | } |
89 | /* implement the url scripting here */ | 101 | /* implement the url scripting here */ |
90 | void OPimMainWindow::setDocument( const QString& str) { | 102 | void OPimMainWindow::setDocument( const QString& str) { |
91 | doSetDocument( str ); | 103 | doSetDocument( str ); |
92 | } | 104 | } |
93 | /* | 105 | /* |
94 | * we now try to get the array demarshalled | 106 | * we now try to get the array demarshalled |
95 | * check if the rtti matches this one | 107 | * check if the rtti matches this one |
96 | */ | 108 | */ |
97 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | 109 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { |
98 | if ( service() != rtti ) | 110 | if ( service() != rtti ) |
99 | return 0l; | 111 | return 0l; |
100 | 112 | ||
101 | OPimRecord* record = OPimResolver::self()->record( rtti ); | 113 | OPimRecord* record = OPimResolver::self()->record( rtti ); |
102 | QDataStream str(array, IO_ReadOnly ); | 114 | QDataStream str(array, IO_ReadOnly ); |
103 | if ( !record || !record->loadFromStream(str) ) { | 115 | if ( !record || !record->loadFromStream(str) ) { |
104 | delete record; | 116 | delete record; |
105 | record = 0l; | 117 | record = 0l; |
106 | } | 118 | } |
107 | 119 | ||
108 | return record; | 120 | return record; |
109 | } | 121 | } |
110 | /* | 122 | /* |
111 | * get the rtti for the service | 123 | * get the rtti for the service |
112 | */ | 124 | */ |
113 | int OPimMainWindow::service() { | 125 | int OPimMainWindow::service() { |
114 | if ( m_rtti == -1 ) | 126 | if ( m_rtti == -1 ) |
115 | m_rtti = OPimResolver::self()->serviceId( m_service ); | 127 | m_rtti = OPimResolver::self()->serviceId( m_service ); |
116 | 128 | ||
117 | return m_rtti; | 129 | return m_rtti; |
118 | } | 130 | } |
119 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { | 131 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { |
120 | 132 | ||
121 | } | 133 | } |
122 | void OPimMainWindow::startAlarm(int count ) { | 134 | void OPimMainWindow::startAlarm(int count ) { |
123 | m_alarmCount = count; | 135 | m_alarmCount = count; |
124 | m_playedCount = 0; | 136 | m_playedCount = 0; |
125 | Sound::soundAlarm(); | 137 | Sound::soundAlarm(); |
126 | m_timerId = startTimer( 5000 ); | 138 | m_timerId = startTimer( 5000 ); |
127 | } | 139 | } |
128 | void OPimMainWindow::killAlarm() { | 140 | void OPimMainWindow::killAlarm() { |
129 | killTimer( m_timerId ); | 141 | killTimer( m_timerId ); |
130 | } | 142 | } |
131 | void OPimMainWindow::timerEvent( QTimerEvent* e) { | 143 | void OPimMainWindow::timerEvent( QTimerEvent* e) { |
132 | if ( m_playedCount <m_alarmCount ) { | 144 | if ( m_playedCount <m_alarmCount ) { |
133 | m_playedCount++; | 145 | m_playedCount++; |
134 | Sound::soundAlarm(); | 146 | Sound::soundAlarm(); |
135 | }else { | 147 | }else { |
136 | killTimer( e->timerId() ); | 148 | killTimer( e->timerId() ); |
137 | } | 149 | } |
138 | } | 150 | } |
diff --git a/libopie/pim/opimxrefmanager.h b/libopie/pim/opimxrefmanager.h index 39e5eef..c485e98 100644 --- a/libopie/pim/opimxrefmanager.h +++ b/libopie/pim/opimxrefmanager.h | |||
@@ -1,41 +1,43 @@ | |||
1 | #ifndef OPIM_XREF_MANAGER_H | 1 | #ifndef OPIM_XREF_MANAGER_H |
2 | #define OPIM_XREF_MANAGER_H | 2 | #define OPIM_XREF_MANAGER_H |
3 | 3 | ||
4 | #include <qstringlist.h> | 4 | #include <qstringlist.h> |
5 | 5 | ||
6 | #include <opie/opimxref.h> | 6 | #include <opie/opimxref.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * This is a simple manager for | 9 | * This is a simple manager for |
10 | * OPimXRefs. | 10 | * OPimXRefs. |
11 | * It allows addition, removing, replacing | 11 | * It allows addition, removing, replacing |
12 | * clearing and 'querying' the XRef... | 12 | * clearing and 'querying' the XRef... |
13 | */ | 13 | */ |
14 | class OPimXRefManager { | 14 | class OPimXRefManager { |
15 | public: | 15 | public: |
16 | OPimXRefManager(); | 16 | OPimXRefManager(); |
17 | OPimXRefManager( const OPimXRefManager& ); | 17 | OPimXRefManager( const OPimXRefManager& ); |
18 | ~OPimXRefManager(); | 18 | ~OPimXRefManager(); |
19 | 19 | ||
20 | OPimXRefManager& operator=( const OPimXRefManager& ); | 20 | OPimXRefManager& operator=( const OPimXRefManager& ); |
21 | bool operator==( const OPimXRefManager& ); | 21 | bool operator==( const OPimXRefManager& ); |
22 | 22 | ||
23 | void add( const OPimXRef& ); | 23 | void add( const OPimXRef& ); |
24 | void remove( const OPimXRef& ); | 24 | void remove( const OPimXRef& ); |
25 | void replace( const OPimXRef& ); | 25 | void replace( const OPimXRef& ); |
26 | 26 | ||
27 | void clear(); | 27 | void clear(); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * apps participating | 30 | * apps participating |
31 | */ | 31 | */ |
32 | QStringList apps()const; | 32 | QStringList apps()const; |
33 | OPimXRef::ValueList list()const; | 33 | OPimXRef::ValueList list()const; |
34 | OPimXRef::ValueList list( const QString& service )const; | 34 | OPimXRef::ValueList list( const QString& service )const; |
35 | OPimXRef::ValueList list( int uid )const; | 35 | OPimXRef::ValueList list( int uid )const; |
36 | 36 | ||
37 | private: | 37 | private: |
38 | OPimXRef::ValueList m_list; | 38 | OPimXRef::ValueList m_list; |
39 | class Private; | ||
40 | Private *d; | ||
39 | }; | 41 | }; |
40 | 42 | ||
41 | #endif | 43 | #endif |
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index edcd729..5211f57 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -1,300 +1,306 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | class ORecordListIteratorPrivate; | ||
10 | /** | 11 | /** |
11 | * Our List Iterator | 12 | * Our List Iterator |
12 | * it behaves like STL or Qt | 13 | * it behaves like STL or Qt |
13 | * | 14 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 15 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 16 | * doSomeCoolStuff( (*it) ); |
16 | */ | 17 | */ |
17 | template <class T> class ORecordList; | 18 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 19 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 20 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 21 | friend class ORecordList<T>; |
21 | public: | 22 | public: |
22 | typedef OTemplateBase<T> Base; | 23 | typedef OTemplateBase<T> Base; |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * The c'tor used internally from | 26 | * The c'tor used internally from |
26 | * ORecordList | 27 | * ORecordList |
27 | */ | 28 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 29 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 30 | ||
30 | /** | 31 | /** |
31 | * The standard c'tor | 32 | * The standard c'tor |
32 | */ | 33 | */ |
33 | ORecordListIterator(); | 34 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 35 | ~ORecordListIterator(); |
35 | 36 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 37 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 38 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * a * operator ;) | 41 | * a * operator ;) |
41 | * use it like this T = (*it); | 42 | * use it like this T = (*it); |
42 | */ | 43 | */ |
43 | T operator*(); | 44 | T operator*(); |
44 | ORecordListIterator &operator++(); | 45 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 46 | ORecordListIterator &operator--(); |
46 | 47 | ||
47 | bool operator==( const ORecordListIterator& it ); | 48 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 49 | bool operator!=( const ORecordListIterator& it ); |
49 | 50 | ||
50 | /** | 51 | /** |
51 | * the current item | 52 | * the current item |
52 | */ | 53 | */ |
53 | uint current()const; | 54 | uint current()const; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * the number of items | 57 | * the number of items |
57 | */ | 58 | */ |
58 | uint count()const; | 59 | uint count()const; |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * sets the current item | 62 | * sets the current item |
62 | */ | 63 | */ |
63 | void setCurrent( uint cur ); | 64 | void setCurrent( uint cur ); |
64 | 65 | ||
65 | private: | 66 | private: |
66 | QArray<int> m_uids; | 67 | QArray<int> m_uids; |
67 | uint m_current; | 68 | uint m_current; |
68 | const Base* m_temp; | 69 | const Base* m_temp; |
69 | bool m_end : 1; | 70 | bool m_end : 1; |
70 | T m_record; | 71 | T m_record; |
71 | bool m_direction :1; | 72 | bool m_direction :1; |
72 | 73 | ||
73 | /* d pointer for future versions */ | 74 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 75 | ORecordListIteratorPrivate *d; |
75 | IteratorPrivate *d; | ||
76 | }; | 76 | }; |
77 | |||
78 | class ORecordListPrivate; | ||
77 | /** | 79 | /** |
78 | * The recordlist used as a return type | 80 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 81 | * from OPimAccessTemplate |
80 | */ | 82 | */ |
81 | template <class T = OPimRecord > | 83 | template <class T = OPimRecord > |
82 | class ORecordList { | 84 | class ORecordList { |
83 | public: | 85 | public: |
84 | typedef OTemplateBase<T> Base; | 86 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 87 | typedef ORecordListIterator<T> Iterator; |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * c'tor | 90 | * c'tor |
89 | */ | 91 | */ |
90 | ORecordList () { | 92 | ORecordList () { |
91 | } | 93 | } |
92 | ORecordList( const QArray<int>& ids, | 94 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 95 | const Base* ); |
94 | ~ORecordList(); | 96 | ~ORecordList(); |
95 | 97 | ||
96 | /** | 98 | /** |
97 | * the first iterator | 99 | * the first iterator |
98 | */ | 100 | */ |
99 | Iterator begin(); | 101 | Iterator begin(); |
100 | 102 | ||
101 | /** | 103 | /** |
102 | * the end | 104 | * the end |
103 | */ | 105 | */ |
104 | Iterator end(); | 106 | Iterator end(); |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * the number of items in the list | 109 | * the number of items in the list |
108 | */ | 110 | */ |
109 | uint count()const; | 111 | uint count()const; |
110 | 112 | ||
111 | T operator[]( uint i ); | 113 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | 114 | int uidAt(uint i ); |
113 | 115 | ||
114 | /** | 116 | /** |
115 | * Remove the contact with given uid | 117 | * Remove the contact with given uid |
116 | */ | 118 | */ |
117 | bool remove( int uid ); | 119 | bool remove( int uid ); |
118 | 120 | ||
119 | /* | 121 | /* |
120 | ConstIterator begin()const; | 122 | ConstIterator begin()const; |
121 | ConstIterator end()const; | 123 | ConstIterator end()const; |
122 | */ | 124 | */ |
123 | private: | 125 | private: |
124 | QArray<int> m_ids; | 126 | QArray<int> m_ids; |
125 | const Base* m_acc; | 127 | const Base* m_acc; |
128 | ORecordListPrivate *d; | ||
126 | }; | 129 | }; |
127 | 130 | ||
128 | /* ok now implement it */ | 131 | /* ok now implement it */ |
129 | template <class T> | 132 | template <class T> |
130 | ORecordListIterator<T>::ORecordListIterator() { | 133 | ORecordListIterator<T>::ORecordListIterator() { |
131 | m_current = 0; | 134 | m_current = 0; |
132 | m_temp = 0l; | 135 | m_temp = 0l; |
133 | m_end = true; | 136 | m_end = true; |
134 | m_record = T(); | 137 | m_record = T(); |
135 | /* forward */ | 138 | /* forward */ |
136 | m_direction = TRUE; | 139 | m_direction = TRUE; |
137 | } | 140 | } |
138 | template <class T> | 141 | template <class T> |
139 | ORecordListIterator<T>::~ORecordListIterator() { | 142 | ORecordListIterator<T>::~ORecordListIterator() { |
140 | /* nothing to delete */ | 143 | /* nothing to delete */ |
141 | } | 144 | } |
142 | 145 | ||
143 | template <class T> | 146 | template <class T> |
144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 147 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
145 | // qWarning("ORecordListIterator copy c'tor"); | 148 | // qWarning("ORecordListIterator copy c'tor"); |
146 | m_uids = it.m_uids; | 149 | m_uids = it.m_uids; |
147 | m_current = it.m_current; | 150 | m_current = it.m_current; |
148 | m_temp = it.m_temp; | 151 | m_temp = it.m_temp; |
149 | m_end = it.m_end; | 152 | m_end = it.m_end; |
150 | m_record = it.m_record; | 153 | m_record = it.m_record; |
151 | m_direction = it.m_direction; | 154 | m_direction = it.m_direction; |
152 | } | 155 | } |
153 | 156 | ||
154 | template <class T> | 157 | template <class T> |
155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 158 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
156 | m_uids = it.m_uids; | 159 | m_uids = it.m_uids; |
157 | m_current = it.m_current; | 160 | m_current = it.m_current; |
158 | m_temp = it.m_temp; | 161 | m_temp = it.m_temp; |
159 | m_end = it.m_end; | 162 | m_end = it.m_end; |
160 | m_record = it.m_record; | 163 | m_record = it.m_record; |
161 | 164 | ||
162 | return *this; | 165 | return *this; |
163 | } | 166 | } |
164 | 167 | ||
165 | template <class T> | 168 | template <class T> |
166 | T ORecordListIterator<T>::operator*() { | 169 | T ORecordListIterator<T>::operator*() { |
167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 170 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
168 | if (!m_end ) | 171 | if (!m_end ) |
169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 172 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
170 | m_direction ? Base::Forward : | 173 | m_direction ? Base::Forward : |
171 | Base::Reverse ); | 174 | Base::Reverse ); |
172 | else | 175 | else |
173 | m_record = T(); | 176 | m_record = T(); |
174 | 177 | ||
175 | return m_record; | 178 | return m_record; |
176 | } | 179 | } |
177 | 180 | ||
178 | template <class T> | 181 | template <class T> |
179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 182 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
180 | m_direction = true; | 183 | m_direction = true; |
181 | if (m_current < m_uids.count() ) { | 184 | if (m_current < m_uids.count() ) { |
182 | m_end = false; | 185 | m_end = false; |
183 | ++m_current; | 186 | ++m_current; |
184 | }else | 187 | }else |
185 | m_end = true; | 188 | m_end = true; |
186 | 189 | ||
187 | return *this; | 190 | return *this; |
188 | } | 191 | } |
189 | template <class T> | 192 | template <class T> |
190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 193 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
191 | m_direction = false; | 194 | m_direction = false; |
192 | if ( m_current > 0 ) { | 195 | if ( m_current > 0 ) { |
193 | --m_current; | 196 | --m_current; |
194 | m_end = false; | 197 | m_end = false; |
195 | } else | 198 | } else |
196 | m_end = true; | 199 | m_end = true; |
197 | 200 | ||
198 | return *this; | 201 | return *this; |
199 | } | 202 | } |
200 | 203 | ||
201 | template <class T> | 204 | template <class T> |
202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 205 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
203 | 206 | ||
204 | /* if both are at we're the same.... */ | 207 | /* if both are at we're the same.... */ |
205 | if ( m_end == it.m_end ) return true; | 208 | if ( m_end == it.m_end ) return true; |
206 | 209 | ||
207 | if ( m_uids != it.m_uids ) return false; | 210 | if ( m_uids != it.m_uids ) return false; |
208 | if ( m_current != it.m_current ) return false; | 211 | if ( m_current != it.m_current ) return false; |
209 | if ( m_temp != it.m_temp ) return false; | 212 | if ( m_temp != it.m_temp ) return false; |
210 | 213 | ||
211 | return true; | 214 | return true; |
212 | } | 215 | } |
213 | template <class T> | 216 | template <class T> |
214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 217 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
215 | return !(*this == it ); | 218 | return !(*this == it ); |
216 | } | 219 | } |
217 | template <class T> | 220 | template <class T> |
218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 221 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
219 | const Base* t ) | 222 | const Base* t ) |
220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 223 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
221 | m_direction( false ) | 224 | m_direction( false ) |
222 | { | 225 | { |
226 | /* if the list is empty we're already at the end of the list */ | ||
227 | if (uids.count() == 0 ) | ||
228 | m_end = true; | ||
223 | } | 229 | } |
224 | template <class T> | 230 | template <class T> |
225 | uint ORecordListIterator<T>::current()const { | 231 | uint ORecordListIterator<T>::current()const { |
226 | return m_current; | 232 | return m_current; |
227 | } | 233 | } |
228 | template <class T> | 234 | template <class T> |
229 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 235 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
230 | if( cur < m_uids.count() ) { | 236 | if( cur < m_uids.count() ) { |
231 | m_end = false; | 237 | m_end = false; |
232 | m_current= cur; | 238 | m_current= cur; |
233 | } | 239 | } |
234 | } | 240 | } |
235 | template <class T> | 241 | template <class T> |
236 | uint ORecordListIterator<T>::count()const { | 242 | uint ORecordListIterator<T>::count()const { |
237 | return m_uids.count(); | 243 | return m_uids.count(); |
238 | } | 244 | } |
239 | template <class T> | 245 | template <class T> |
240 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 246 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
241 | const Base* acc ) | 247 | const Base* acc ) |
242 | : m_ids( ids ), m_acc( acc ) | 248 | : m_ids( ids ), m_acc( acc ) |
243 | { | 249 | { |
244 | } | 250 | } |
245 | template <class T> | 251 | template <class T> |
246 | ORecordList<T>::~ORecordList() { | 252 | ORecordList<T>::~ORecordList() { |
247 | /* nothing to do here */ | 253 | /* nothing to do here */ |
248 | } | 254 | } |
249 | template <class T> | 255 | template <class T> |
250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 256 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { |
251 | Iterator it( m_ids, m_acc ); | 257 | Iterator it( m_ids, m_acc ); |
252 | return it; | 258 | return it; |
253 | } | 259 | } |
254 | template <class T> | 260 | template <class T> |
255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 261 | typename ORecordList<T>::Iterator ORecordList<T>::end() { |
256 | Iterator it( m_ids, m_acc ); | 262 | Iterator it( m_ids, m_acc ); |
257 | it.m_end = true; | 263 | it.m_end = true; |
258 | it.m_current = m_ids.count(); | 264 | it.m_current = m_ids.count(); |
259 | 265 | ||
260 | return it; | 266 | return it; |
261 | } | 267 | } |
262 | template <class T> | 268 | template <class T> |
263 | uint ORecordList<T>::count()const { | 269 | uint ORecordList<T>::count()const { |
264 | return m_ids.count(); | 270 | return m_ids.count(); |
265 | } | 271 | } |
266 | template <class T> | 272 | template <class T> |
267 | T ORecordList<T>::operator[]( uint i ) { | 273 | T ORecordList<T>::operator[]( uint i ) { |
268 | if ( i >= m_ids.count() ) | 274 | if ( i >= m_ids.count() ) |
269 | return T(); | 275 | return T(); |
270 | /* forward */ | 276 | /* forward */ |
271 | return m_acc->find( m_ids[i], m_ids, i ); | 277 | return m_acc->find( m_ids[i], m_ids, i ); |
272 | } | 278 | } |
273 | template <class T> | 279 | template <class T> |
274 | int ORecordList<T>::uidAt( uint i ) { | 280 | int ORecordList<T>::uidAt( uint i ) { |
275 | return m_ids[i]; | 281 | return m_ids[i]; |
276 | } | 282 | } |
277 | 283 | ||
278 | template <class T> | 284 | template <class T> |
279 | bool ORecordList<T>::remove( int uid ) { | 285 | bool ORecordList<T>::remove( int uid ) { |
280 | QArray<int> copy( m_ids.count() ); | 286 | QArray<int> copy( m_ids.count() ); |
281 | int counter = 0; | 287 | int counter = 0; |
282 | bool ret_val = false; | 288 | bool ret_val = false; |
283 | 289 | ||
284 | for (uint i = 0; i < m_ids.count(); i++){ | 290 | for (uint i = 0; i < m_ids.count(); i++){ |
285 | if ( m_ids[i] != uid ){ | 291 | if ( m_ids[i] != uid ){ |
286 | copy[counter++] = m_ids[i]; | 292 | copy[counter++] = m_ids[i]; |
287 | 293 | ||
288 | }else | 294 | }else |
289 | ret_val = true; | 295 | ret_val = true; |
290 | } | 296 | } |
291 | 297 | ||
292 | copy.resize( counter ); | 298 | copy.resize( counter ); |
293 | m_ids = copy; | 299 | m_ids = copy; |
294 | 300 | ||
295 | 301 | ||
296 | return ret_val; | 302 | return ret_val; |
297 | } | 303 | } |
298 | 304 | ||
299 | 305 | ||
300 | #endif | 306 | #endif |
diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h index 29fb6ec..cadac74 100644 --- a/libopie/pim/otemplatebase.h +++ b/libopie/pim/otemplatebase.h | |||
@@ -1,91 +1,98 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 1 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 2 | #define OPIE_TEMPLATE_BASE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | 7 | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Templates do not have a base class, This is why | 10 | * Templates do not have a base class, This is why |
11 | * we've this class | 11 | * we've this class |
12 | * this is here to give us the possibility | 12 | * this is here to give us the possibility |
13 | * to have a common base class | 13 | * to have a common base class |
14 | * You may not want to use that interface internaly | 14 | * You may not want to use that interface internaly |
15 | * POOR mans interface | 15 | * POOR mans interface |
16 | */ | 16 | */ |
17 | class OPimBasePrivate; | ||
17 | struct OPimBase { | 18 | struct OPimBase { |
18 | /** | 19 | /** |
19 | * return the rtti | 20 | * return the rtti |
20 | */ | 21 | */ |
21 | virtual int rtti()= 0; | 22 | virtual int rtti()= 0; |
22 | virtual OPimRecord* record()const = 0; | 23 | virtual OPimRecord* record()const = 0; |
23 | virtual OPimRecord* record(int uid)const = 0; | 24 | virtual OPimRecord* record(int uid)const = 0; |
24 | virtual bool add( const OPimRecord& ) = 0; | 25 | virtual bool add( const OPimRecord& ) = 0; |
25 | virtual bool remove( int uid ) = 0; | 26 | virtual bool remove( int uid ) = 0; |
26 | virtual bool remove( const OPimRecord& ) = 0; | 27 | virtual bool remove( const OPimRecord& ) = 0; |
27 | virtual void clear() = 0; | 28 | virtual void clear() = 0; |
28 | virtual bool load() = 0; | 29 | virtual bool load() = 0; |
29 | virtual bool save() = 0; | 30 | virtual bool save() = 0; |
30 | virtual QArray<int> records()const = 0; | 31 | virtual QArray<int> records()const = 0; |
31 | /* | 32 | /* |
32 | * ADD editing here? | 33 | * ADD editing here? |
33 | * -zecke | 34 | * -zecke |
34 | */ | 35 | */ |
36 | private: | ||
37 | OPimBasePrivate* d; | ||
35 | 38 | ||
36 | }; | 39 | }; |
37 | /** | 40 | /** |
38 | * internal template base | 41 | * internal template base |
39 | * T needs to implement the copy c'tor!!! | 42 | * T needs to implement the copy c'tor!!! |
40 | */ | 43 | */ |
44 | class OTemplateBasePrivate; | ||
41 | template <class T = OPimRecord> | 45 | template <class T = OPimRecord> |
42 | class OTemplateBase : public OPimBase { | 46 | class OTemplateBase : public OPimBase { |
43 | public: | 47 | public: |
44 | enum CacheDirection { Forward=0, Reverse }; | 48 | enum CacheDirection { Forward=0, Reverse }; |
45 | OTemplateBase() { | 49 | OTemplateBase() { |
46 | }; | 50 | }; |
47 | virtual ~OTemplateBase() { | 51 | virtual ~OTemplateBase() { |
48 | } | 52 | } |
49 | virtual T find( int uid )const = 0; | 53 | virtual T find( int uid )const = 0; |
50 | 54 | ||
51 | /** | 55 | /** |
52 | * read ahead find | 56 | * read ahead find |
53 | */ | 57 | */ |
54 | virtual T find( int uid, const QArray<int>& items, | 58 | virtual T find( int uid, const QArray<int>& items, |
55 | uint current, CacheDirection dir = Forward )const = 0; | 59 | uint current, CacheDirection dir = Forward )const = 0; |
56 | virtual void cache( const T& )const = 0; | 60 | virtual void cache( const T& )const = 0; |
57 | virtual void setSaneCacheSize( int ) = 0; | 61 | virtual void setSaneCacheSize( int ) = 0; |
58 | 62 | ||
59 | /* reimplement of OPimBase */ | 63 | /* reimplement of OPimBase */ |
60 | int rtti(); | 64 | int rtti(); |
61 | OPimRecord* record()const; | 65 | OPimRecord* record()const; |
62 | OPimRecord* record(int uid )const; | 66 | OPimRecord* record(int uid )const; |
63 | static T* rec(); | 67 | static T* rec(); |
68 | |||
69 | private: | ||
70 | OTemplateBasePrivate *d; | ||
64 | }; | 71 | }; |
65 | 72 | ||
66 | /* | 73 | /* |
67 | * implementation | 74 | * implementation |
68 | */ | 75 | */ |
69 | template <class T> | 76 | template <class T> |
70 | int | 77 | int |
71 | OTemplateBase<T>::rtti() { | 78 | OTemplateBase<T>::rtti() { |
72 | return T::rtti(); | 79 | return T::rtti(); |
73 | } | 80 | } |
74 | template <class T> | 81 | template <class T> |
75 | OPimRecord* OTemplateBase<T>::record()const { | 82 | OPimRecord* OTemplateBase<T>::record()const { |
76 | T* t = new T; | 83 | T* t = new T; |
77 | return t; | 84 | return t; |
78 | } | 85 | } |
79 | template <class T> | 86 | template <class T> |
80 | OPimRecord* OTemplateBase<T>::record(int uid )const { | 87 | OPimRecord* OTemplateBase<T>::record(int uid )const { |
81 | T t2 = find(uid ); | 88 | T t2 = find(uid ); |
82 | T* t1 = new T(t2); | 89 | T* t1 = new T(t2); |
83 | 90 | ||
84 | return t1; | 91 | return t1; |
85 | }; | 92 | }; |
86 | template <class T> | 93 | template <class T> |
87 | T* OTemplateBase<T>::rec() { | 94 | T* OTemplateBase<T>::rec() { |
88 | return new T; | 95 | return new T; |
89 | } | 96 | } |
90 | 97 | ||
91 | #endif | 98 | #endif |
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index 38b93f7..5a18c37 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -1,516 +1,520 @@ | |||
1 | 1 | ||
2 | #include <qobject.h> | 2 | #include <qobject.h> |
3 | #include <qshared.h> | 3 | #include <qshared.h> |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
7 | #include <qpe/palmtopuidgen.h> | 7 | #include <qpe/palmtopuidgen.h> |
8 | #include <qpe/stringutil.h> | 8 | #include <qpe/stringutil.h> |
9 | #include <qpe/palmtoprecord.h> | 9 | #include <qpe/palmtoprecord.h> |
10 | #include <qpe/stringutil.h> | 10 | #include <qpe/stringutil.h> |
11 | #include <qpe/categories.h> | 11 | #include <qpe/categories.h> |
12 | #include <qpe/categoryselect.h> | 12 | #include <qpe/categoryselect.h> |
13 | 13 | ||
14 | 14 | ||
15 | #include "opimstate.h" | 15 | #include "opimstate.h" |
16 | #include "orecur.h" | 16 | #include "orecur.h" |
17 | #include "opimmaintainer.h" | 17 | #include "opimmaintainer.h" |
18 | #include "opimnotifymanager.h" | 18 | #include "opimnotifymanager.h" |
19 | #include "opimresolver.h" | 19 | #include "opimresolver.h" |
20 | 20 | ||
21 | #include "otodo.h" | 21 | #include "otodo.h" |
22 | 22 | ||
23 | 23 | ||
24 | struct OTodo::OTodoData : public QShared { | 24 | struct OTodo::OTodoData : public QShared { |
25 | OTodoData() : QShared() { | 25 | OTodoData() : QShared() { |
26 | recur = 0; | 26 | recur = 0; |
27 | state = 0; | 27 | state = 0; |
28 | maintainer = 0; | 28 | maintainer = 0; |
29 | notifiers = 0; | 29 | notifiers = 0; |
30 | }; | 30 | }; |
31 | ~OTodoData() { | ||
32 | delete recur; | ||
33 | delete maintainer; | ||
34 | delete notifiers; | ||
35 | } | ||
31 | 36 | ||
32 | QDate date; | 37 | QDate date; |
33 | bool isCompleted:1; | 38 | bool isCompleted:1; |
34 | bool hasDate:1; | 39 | bool hasDate:1; |
35 | int priority; | 40 | int priority; |
36 | QString desc; | 41 | QString desc; |
37 | QString sum; | 42 | QString sum; |
38 | QMap<QString, QString> extra; | 43 | QMap<QString, QString> extra; |
39 | ushort prog; | 44 | ushort prog; |
40 | OPimState *state; | 45 | OPimState *state; |
41 | ORecur *recur; | 46 | ORecur *recur; |
42 | OPimMaintainer *maintainer; | 47 | OPimMaintainer *maintainer; |
43 | QDate start; | 48 | QDate start; |
44 | QDate completed; | 49 | QDate completed; |
45 | OPimNotifyManager *notifiers; | 50 | OPimNotifyManager *notifiers; |
46 | }; | 51 | }; |
47 | 52 | ||
48 | OTodo::OTodo(const OTodo &event ) | 53 | OTodo::OTodo(const OTodo &event ) |
49 | : OPimRecord( event ), data( event.data ) | 54 | : OPimRecord( event ), data( event.data ) |
50 | { | 55 | { |
51 | data->ref(); | 56 | data->ref(); |
52 | // qWarning("ref up"); | 57 | // qWarning("ref up"); |
53 | } | 58 | } |
54 | OTodo::~OTodo() { | 59 | OTodo::~OTodo() { |
55 | 60 | ||
56 | // qWarning("~OTodo " ); | 61 | // qWarning("~OTodo " ); |
57 | if ( data->deref() ) { | 62 | if ( data->deref() ) { |
58 | // qWarning("OTodo::dereffing"); | 63 | // qWarning("OTodo::dereffing"); |
59 | delete data; | 64 | delete data; |
60 | data = 0l; | 65 | data = 0l; |
61 | } | 66 | } |
62 | } | 67 | } |
63 | OTodo::OTodo(bool completed, int priority, | 68 | OTodo::OTodo(bool completed, int priority, |
64 | const QArray<int> &category, | 69 | const QArray<int> &category, |
65 | const QString& summary, | 70 | const QString& summary, |
66 | const QString &description, | 71 | const QString &description, |
67 | ushort progress, | 72 | ushort progress, |
68 | bool hasDate, QDate date, int uid ) | 73 | bool hasDate, QDate date, int uid ) |
69 | : OPimRecord( uid ) | 74 | : OPimRecord( uid ) |
70 | { | 75 | { |
71 | // qWarning("OTodoData " + summary); | 76 | // qWarning("OTodoData " + summary); |
72 | setCategories( category ); | 77 | setCategories( category ); |
73 | 78 | ||
74 | data = new OTodoData; | 79 | data = new OTodoData; |
75 | 80 | ||
76 | data->date = date; | 81 | data->date = date; |
77 | data->isCompleted = completed; | 82 | data->isCompleted = completed; |
78 | data->hasDate = hasDate; | 83 | data->hasDate = hasDate; |
79 | data->priority = priority; | 84 | data->priority = priority; |
80 | data->sum = summary; | 85 | data->sum = summary; |
81 | data->prog = progress; | 86 | data->prog = progress; |
82 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 87 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
83 | } | 88 | } |
84 | OTodo::OTodo(bool completed, int priority, | 89 | OTodo::OTodo(bool completed, int priority, |
85 | const QStringList &category, | 90 | const QStringList &category, |
86 | const QString& summary, | 91 | const QString& summary, |
87 | const QString &description, | 92 | const QString &description, |
88 | ushort progress, | 93 | ushort progress, |
89 | bool hasDate, QDate date, int uid ) | 94 | bool hasDate, QDate date, int uid ) |
90 | : OPimRecord( uid ) | 95 | : OPimRecord( uid ) |
91 | { | 96 | { |
92 | // qWarning("OTodoData" + summary); | 97 | // qWarning("OTodoData" + summary); |
93 | setCategories( idsFromString( category.join(";") ) ); | 98 | setCategories( idsFromString( category.join(";") ) ); |
94 | 99 | ||
95 | data = new OTodoData; | 100 | data = new OTodoData; |
96 | 101 | ||
97 | data->date = date; | 102 | data->date = date; |
98 | data->isCompleted = completed; | 103 | data->isCompleted = completed; |
99 | data->hasDate = hasDate; | 104 | data->hasDate = hasDate; |
100 | data->priority = priority; | 105 | data->priority = priority; |
101 | data->sum = summary; | 106 | data->sum = summary; |
102 | data->prog = progress; | 107 | data->prog = progress; |
103 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 108 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
104 | } | 109 | } |
105 | bool OTodo::match( const QRegExp ®Exp )const | 110 | bool OTodo::match( const QRegExp ®Exp )const |
106 | { | 111 | { |
107 | if( QString::number( data->priority ).find( regExp ) != -1 ){ | 112 | if( QString::number( data->priority ).find( regExp ) != -1 ){ |
108 | setLastHitField( Priority ); | 113 | setLastHitField( Priority ); |
109 | return true; | 114 | return true; |
110 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ | 115 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ |
111 | setLastHitField( HasDate ); | 116 | setLastHitField( HasDate ); |
112 | return true; | 117 | return true; |
113 | }else if(data->desc.find( regExp ) != -1 ){ | 118 | }else if(data->desc.find( regExp ) != -1 ){ |
114 | setLastHitField( Description ); | 119 | setLastHitField( Description ); |
115 | return true; | 120 | return true; |
116 | }else if(data->sum.find( regExp ) != -1 ) { | 121 | }else if(data->sum.find( regExp ) != -1 ) { |
117 | setLastHitField( Summary ); | 122 | setLastHitField( Summary ); |
118 | return true; | 123 | return true; |
119 | } | 124 | } |
120 | return false; | 125 | return false; |
121 | } | 126 | } |
122 | bool OTodo::isCompleted() const | 127 | bool OTodo::isCompleted() const |
123 | { | 128 | { |
124 | return data->isCompleted; | 129 | return data->isCompleted; |
125 | } | 130 | } |
126 | bool OTodo::hasDueDate() const | 131 | bool OTodo::hasDueDate() const |
127 | { | 132 | { |
128 | return data->hasDate; | 133 | return data->hasDate; |
129 | } | 134 | } |
130 | bool OTodo::hasStartDate()const { | 135 | bool OTodo::hasStartDate()const { |
131 | return data->start.isValid(); | 136 | return data->start.isValid(); |
132 | } | 137 | } |
133 | bool OTodo::hasCompletedDate()const { | 138 | bool OTodo::hasCompletedDate()const { |
134 | return data->completed.isValid(); | 139 | return data->completed.isValid(); |
135 | } | 140 | } |
136 | int OTodo::priority()const | 141 | int OTodo::priority()const |
137 | { | 142 | { |
138 | return data->priority; | 143 | return data->priority; |
139 | } | 144 | } |
140 | QString OTodo::summary() const | 145 | QString OTodo::summary() const |
141 | { | 146 | { |
142 | return data->sum; | 147 | return data->sum; |
143 | } | 148 | } |
144 | ushort OTodo::progress() const | 149 | ushort OTodo::progress() const |
145 | { | 150 | { |
146 | return data->prog; | 151 | return data->prog; |
147 | } | 152 | } |
148 | QDate OTodo::dueDate()const | 153 | QDate OTodo::dueDate()const |
149 | { | 154 | { |
150 | return data->date; | 155 | return data->date; |
151 | } | 156 | } |
152 | QDate OTodo::startDate()const { | 157 | QDate OTodo::startDate()const { |
153 | return data->start; | 158 | return data->start; |
154 | } | 159 | } |
155 | QDate OTodo::completedDate()const { | 160 | QDate OTodo::completedDate()const { |
156 | return data->completed; | 161 | return data->completed; |
157 | } | 162 | } |
158 | QString OTodo::description()const | 163 | QString OTodo::description()const |
159 | { | 164 | { |
160 | return data->desc; | 165 | return data->desc; |
161 | } | 166 | } |
162 | bool OTodo::hasState() const{ | 167 | bool OTodo::hasState() const{ |
163 | if (!data->state ) return false; | 168 | if (!data->state ) return false; |
164 | return ( data->state->state() != OPimState::Undefined ); | 169 | return ( data->state->state() != OPimState::Undefined ); |
165 | } | 170 | } |
166 | OPimState OTodo::state()const { | 171 | OPimState OTodo::state()const { |
167 | if (!data->state ) { | 172 | if (!data->state ) { |
168 | OPimState state; | 173 | OPimState state; |
169 | return state; | 174 | return state; |
170 | } | 175 | } |
171 | 176 | ||
172 | return (*data->state); | 177 | return (*data->state); |
173 | } | 178 | } |
174 | bool OTodo::hasRecurrence()const { | 179 | bool OTodo::hasRecurrence()const { |
175 | if (!data->recur) return false; | 180 | if (!data->recur) return false; |
176 | return data->recur->doesRecur(); | 181 | return data->recur->doesRecur(); |
177 | } | 182 | } |
178 | ORecur OTodo::recurrence()const { | 183 | ORecur OTodo::recurrence()const { |
179 | if (!data->recur) return ORecur(); | 184 | if (!data->recur) return ORecur(); |
180 | 185 | ||
181 | return (*data->recur); | 186 | return (*data->recur); |
182 | } | 187 | } |
183 | bool OTodo::hasMaintainer()const { | 188 | bool OTodo::hasMaintainer()const { |
184 | if (!data->maintainer) return false; | 189 | if (!data->maintainer) return false; |
185 | 190 | ||
186 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); | 191 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); |
187 | } | 192 | } |
188 | OPimMaintainer OTodo::maintainer()const { | 193 | OPimMaintainer OTodo::maintainer()const { |
189 | if (!data->maintainer) return OPimMaintainer(); | 194 | if (!data->maintainer) return OPimMaintainer(); |
190 | 195 | ||
191 | return (*data->maintainer); | 196 | return (*data->maintainer); |
192 | } | 197 | } |
193 | void OTodo::setCompleted( bool completed ) | 198 | void OTodo::setCompleted( bool completed ) |
194 | { | 199 | { |
195 | changeOrModify(); | 200 | changeOrModify(); |
196 | data->isCompleted = completed; | 201 | data->isCompleted = completed; |
197 | } | 202 | } |
198 | void OTodo::setHasDueDate( bool hasDate ) | 203 | void OTodo::setHasDueDate( bool hasDate ) |
199 | { | 204 | { |
200 | changeOrModify(); | 205 | changeOrModify(); |
201 | data->hasDate = hasDate; | 206 | data->hasDate = hasDate; |
202 | } | 207 | } |
203 | void OTodo::setDescription(const QString &desc ) | 208 | void OTodo::setDescription(const QString &desc ) |
204 | { | 209 | { |
205 | // qWarning( "desc " + desc ); | 210 | // qWarning( "desc " + desc ); |
206 | changeOrModify(); | 211 | changeOrModify(); |
207 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); | 212 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); |
208 | } | 213 | } |
209 | void OTodo::setSummary( const QString& sum ) | 214 | void OTodo::setSummary( const QString& sum ) |
210 | { | 215 | { |
211 | changeOrModify(); | 216 | changeOrModify(); |
212 | data->sum = sum; | 217 | data->sum = sum; |
213 | } | 218 | } |
214 | void OTodo::setPriority(int prio ) | 219 | void OTodo::setPriority(int prio ) |
215 | { | 220 | { |
216 | changeOrModify(); | 221 | changeOrModify(); |
217 | data->priority = prio; | 222 | data->priority = prio; |
218 | } | 223 | } |
219 | void OTodo::setDueDate( const QDate& date ) | 224 | void OTodo::setDueDate( const QDate& date ) |
220 | { | 225 | { |
221 | changeOrModify(); | 226 | changeOrModify(); |
222 | data->date = date; | 227 | data->date = date; |
223 | } | 228 | } |
224 | void OTodo::setStartDate( const QDate& date ) { | 229 | void OTodo::setStartDate( const QDate& date ) { |
225 | changeOrModify(); | 230 | changeOrModify(); |
226 | data->start = date; | 231 | data->start = date; |
227 | } | 232 | } |
228 | void OTodo::setCompletedDate( const QDate& date ) { | 233 | void OTodo::setCompletedDate( const QDate& date ) { |
229 | changeOrModify(); | 234 | changeOrModify(); |
230 | data->completed = date; | 235 | data->completed = date; |
231 | } | 236 | } |
232 | void OTodo::setState( const OPimState& state ) { | 237 | void OTodo::setState( const OPimState& state ) { |
233 | changeOrModify(); | 238 | changeOrModify(); |
234 | if (data->state ) | 239 | if (data->state ) |
235 | (*data->state) = state; | 240 | (*data->state) = state; |
236 | else | 241 | else |
237 | data->state = new OPimState( state ); | 242 | data->state = new OPimState( state ); |
238 | } | 243 | } |
239 | void OTodo::setRecurrence( const ORecur& rec) { | 244 | void OTodo::setRecurrence( const ORecur& rec) { |
240 | changeOrModify(); | 245 | changeOrModify(); |
241 | if (data->recur ) | 246 | if (data->recur ) |
242 | (*data->recur) = rec; | 247 | (*data->recur) = rec; |
243 | else | 248 | else |
244 | data->recur = new ORecur( rec ); | 249 | data->recur = new ORecur( rec ); |
245 | } | 250 | } |
246 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { | 251 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { |
247 | changeOrModify(); | 252 | changeOrModify(); |
248 | 253 | ||
249 | if (data->maintainer ) | 254 | if (data->maintainer ) |
250 | (*data->maintainer) = pim; | 255 | (*data->maintainer) = pim; |
251 | else | 256 | else |
252 | data->maintainer = new OPimMaintainer( pim ); | 257 | data->maintainer = new OPimMaintainer( pim ); |
253 | } | 258 | } |
254 | bool OTodo::isOverdue( ) | 259 | bool OTodo::isOverdue( ) |
255 | { | 260 | { |
256 | if( data->hasDate && !data->isCompleted) | 261 | if( data->hasDate && !data->isCompleted) |
257 | return QDate::currentDate() > data->date; | 262 | return QDate::currentDate() > data->date; |
258 | return false; | 263 | return false; |
259 | } | 264 | } |
260 | void OTodo::setProgress(ushort progress ) | 265 | void OTodo::setProgress(ushort progress ) |
261 | { | 266 | { |
262 | changeOrModify(); | 267 | changeOrModify(); |
263 | data->prog = progress; | 268 | data->prog = progress; |
264 | } | 269 | } |
265 | QString OTodo::toShortText() const { | 270 | QString OTodo::toShortText() const { |
266 | return summary(); | 271 | return summary(); |
267 | } | 272 | } |
268 | /*! | 273 | /*! |
269 | Returns a richt text string | 274 | Returns a richt text string |
270 | */ | 275 | */ |
271 | QString OTodo::toRichText() const | 276 | QString OTodo::toRichText() const |
272 | { | 277 | { |
273 | QString text; | 278 | QString text; |
274 | QStringList catlist; | 279 | QStringList catlist; |
275 | 280 | ||
276 | // summary | 281 | // summary |
277 | text += "<b><h3><img src=\"todo/TodoList\">"; | 282 | text += "<b><h3><img src=\"todo/TodoList\"> "; |
278 | if ( !summary().isEmpty() ) { | 283 | if ( !summary().isEmpty() ) { |
279 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); | 284 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); |
280 | } | 285 | } |
281 | text += "</h3></b><br><hr><br>"; | 286 | text += "</h3></b><br><hr><br>"; |
282 | 287 | ||
283 | // description | 288 | // description |
284 | if( !description().isEmpty() ){ | 289 | if( !description().isEmpty() ){ |
285 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 290 | text += "<b>" + QObject::tr( "Notes:" ) + "</b><br>"; |
286 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; | 291 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
287 | } | 292 | } |
288 | 293 | ||
289 | // priority | 294 | // priority |
290 | int priorityval = priority(); | 295 | int priorityval = priority(); |
291 | text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + | 296 | text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + |
292 | QString::number( priorityval ) + "\">"; | 297 | QString::number( priorityval ) + "\"> "; |
293 | // text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" + | 298 | |
294 | // QString::number( priority() ) + "\"><br>"; | ||
295 | switch ( priorityval ) | 299 | switch ( priorityval ) |
296 | { | 300 | { |
297 | case 1 : text += QObject::tr( "Very high" ); | 301 | case 1 : text += QObject::tr( "Very high" ); |
298 | break; | 302 | break; |
299 | case 2 : text += QObject::tr( "High" ); | 303 | case 2 : text += QObject::tr( "High" ); |
300 | break; | 304 | break; |
301 | case 3 : text += QObject::tr( "Normal" ); | 305 | case 3 : text += QObject::tr( "Normal" ); |
302 | break; | 306 | break; |
303 | case 4 : text += QObject::tr( "Low" ); | 307 | case 4 : text += QObject::tr( "Low" ); |
304 | break; | 308 | break; |
305 | case 5 : text += QObject::tr( "Very low" ); | 309 | case 5 : text += QObject::tr( "Very low" ); |
306 | break; | 310 | break; |
307 | }; | 311 | }; |
308 | text += "<br>"; | 312 | text += "<br>"; |
309 | 313 | ||
310 | // progress | 314 | // progress |
311 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 315 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
312 | + QString::number( progress() ) + " %<br>"; | 316 | + QString::number( progress() ) + " %<br>"; |
313 | 317 | ||
314 | // due date | 318 | // due date |
315 | if (hasDueDate() ){ | 319 | if (hasDueDate() ){ |
316 | QDate dd = dueDate(); | 320 | QDate dd = dueDate(); |
317 | int off = QDate::currentDate().daysTo( dd ); | 321 | int off = QDate::currentDate().daysTo( dd ); |
318 | 322 | ||
319 | text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; | 323 | text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; |
320 | if ( off < 0 ) | 324 | if ( off < 0 ) |
321 | text += "#FF0000"; | 325 | text += "#FF0000"; |
322 | else if ( off == 0 ) | 326 | else if ( off == 0 ) |
323 | text += "#FFFF00"; | 327 | text += "#FFFF00"; |
324 | else if ( off > 0 ) | 328 | else if ( off > 0 ) |
325 | text += "#00FF00"; | 329 | text += "#00FF00"; |
326 | 330 | ||
327 | text += "\">" + dd.toString() + "</font><br>"; | 331 | text += "\">" + dd.toString() + "</font><br>"; |
328 | } | 332 | } |
329 | 333 | ||
330 | // categories | 334 | // categories |
331 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 335 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
332 | text += categoryNames( "Todo List" ).join(", "); | 336 | text += categoryNames( "Todo List" ).join(", "); |
333 | text += "<br>"; | 337 | text += "<br>"; |
334 | 338 | ||
335 | return text; | 339 | return text; |
336 | } | 340 | } |
337 | bool OTodo::hasNotifiers()const { | 341 | bool OTodo::hasNotifiers()const { |
338 | if (!data->notifiers) return false; | 342 | if (!data->notifiers) return false; |
339 | return !data->notifiers->isEmpty(); | 343 | return !data->notifiers->isEmpty(); |
340 | } | 344 | } |
341 | OPimNotifyManager& OTodo::notifiers() { | 345 | OPimNotifyManager& OTodo::notifiers() { |
342 | if (!data->notifiers ) | 346 | if (!data->notifiers ) |
343 | data->notifiers = new OPimNotifyManager; | 347 | data->notifiers = new OPimNotifyManager; |
344 | return (*data->notifiers); | 348 | return (*data->notifiers); |
345 | } | 349 | } |
346 | const OPimNotifyManager& OTodo::notifiers()const{ | 350 | const OPimNotifyManager& OTodo::notifiers()const{ |
347 | if (!data->notifiers ) | 351 | if (!data->notifiers ) |
348 | data->notifiers = new OPimNotifyManager; | 352 | data->notifiers = new OPimNotifyManager; |
349 | 353 | ||
350 | return (*data->notifiers); | 354 | return (*data->notifiers); |
351 | } | 355 | } |
352 | 356 | ||
353 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 357 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
354 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 358 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
355 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 359 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
356 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 360 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
357 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 361 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
358 | return priority() < toDoEvent.priority(); | 362 | return priority() < toDoEvent.priority(); |
359 | }else{ | 363 | }else{ |
360 | return dueDate() < toDoEvent.dueDate(); | 364 | return dueDate() < toDoEvent.dueDate(); |
361 | } | 365 | } |
362 | } | 366 | } |
363 | return false; | 367 | return false; |
364 | } | 368 | } |
365 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 369 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
366 | { | 370 | { |
367 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 371 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
368 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 372 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
369 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 373 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
370 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 374 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
371 | return priority() <= toDoEvent.priority(); | 375 | return priority() <= toDoEvent.priority(); |
372 | }else{ | 376 | }else{ |
373 | return dueDate() <= toDoEvent.dueDate(); | 377 | return dueDate() <= toDoEvent.dueDate(); |
374 | } | 378 | } |
375 | } | 379 | } |
376 | return true; | 380 | return true; |
377 | } | 381 | } |
378 | bool OTodo::operator>(const OTodo &toDoEvent )const | 382 | bool OTodo::operator>(const OTodo &toDoEvent )const |
379 | { | 383 | { |
380 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 384 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
381 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 385 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
382 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 386 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
383 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 387 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
384 | return priority() > toDoEvent.priority(); | 388 | return priority() > toDoEvent.priority(); |
385 | }else{ | 389 | }else{ |
386 | return dueDate() > toDoEvent.dueDate(); | 390 | return dueDate() > toDoEvent.dueDate(); |
387 | } | 391 | } |
388 | } | 392 | } |
389 | return false; | 393 | return false; |
390 | } | 394 | } |
391 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 395 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
392 | { | 396 | { |
393 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 397 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
394 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 398 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
395 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 399 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
396 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 400 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
397 | return priority() > toDoEvent.priority(); | 401 | return priority() > toDoEvent.priority(); |
398 | }else{ | 402 | }else{ |
399 | return dueDate() > toDoEvent.dueDate(); | 403 | return dueDate() > toDoEvent.dueDate(); |
400 | } | 404 | } |
401 | } | 405 | } |
402 | return true; | 406 | return true; |
403 | } | 407 | } |
404 | bool OTodo::operator==(const OTodo &toDoEvent )const | 408 | bool OTodo::operator==(const OTodo &toDoEvent )const |
405 | { | 409 | { |
406 | if ( data->priority != toDoEvent.data->priority ) return false; | 410 | if ( data->priority != toDoEvent.data->priority ) return false; |
407 | if ( data->priority != toDoEvent.data->prog ) return false; | 411 | if ( data->priority != toDoEvent.data->prog ) return false; |
408 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 412 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
409 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 413 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
410 | if ( data->date != toDoEvent.data->date ) return false; | 414 | if ( data->date != toDoEvent.data->date ) return false; |
411 | if ( data->sum != toDoEvent.data->sum ) return false; | 415 | if ( data->sum != toDoEvent.data->sum ) return false; |
412 | if ( data->desc != toDoEvent.data->desc ) return false; | 416 | if ( data->desc != toDoEvent.data->desc ) return false; |
413 | if ( data->maintainer != toDoEvent.data->maintainer ) | 417 | if ( data->maintainer != toDoEvent.data->maintainer ) |
414 | return false; | 418 | return false; |
415 | 419 | ||
416 | return OPimRecord::operator==( toDoEvent ); | 420 | return OPimRecord::operator==( toDoEvent ); |
417 | } | 421 | } |
418 | void OTodo::deref() { | 422 | void OTodo::deref() { |
419 | 423 | ||
420 | // qWarning("deref in ToDoEvent"); | 424 | // qWarning("deref in ToDoEvent"); |
421 | if ( data->deref() ) { | 425 | if ( data->deref() ) { |
422 | // qWarning("deleting"); | 426 | // qWarning("deleting"); |
423 | delete data; | 427 | delete data; |
424 | data= 0; | 428 | data= 0; |
425 | } | 429 | } |
426 | } | 430 | } |
427 | OTodo &OTodo::operator=(const OTodo &item ) | 431 | OTodo &OTodo::operator=(const OTodo &item ) |
428 | { | 432 | { |
429 | if ( this == &item ) return *this; | 433 | if ( this == &item ) return *this; |
430 | 434 | ||
431 | OPimRecord::operator=( item ); | 435 | OPimRecord::operator=( item ); |
432 | //qWarning("operator= ref "); | 436 | //qWarning("operator= ref "); |
433 | item.data->ref(); | 437 | item.data->ref(); |
434 | deref(); | 438 | deref(); |
435 | data = item.data; | 439 | data = item.data; |
436 | 440 | ||
437 | return *this; | 441 | return *this; |
438 | } | 442 | } |
439 | 443 | ||
440 | QMap<int, QString> OTodo::toMap() const { | 444 | QMap<int, QString> OTodo::toMap() const { |
441 | QMap<int, QString> map; | 445 | QMap<int, QString> map; |
442 | 446 | ||
443 | map.insert( Uid, QString::number( uid() ) ); | 447 | map.insert( Uid, QString::number( uid() ) ); |
444 | map.insert( Category, idsToString( categories() ) ); | 448 | map.insert( Category, idsToString( categories() ) ); |
445 | map.insert( HasDate, QString::number( data->hasDate ) ); | 449 | map.insert( HasDate, QString::number( data->hasDate ) ); |
446 | map.insert( Completed, QString::number( data->isCompleted ) ); | 450 | map.insert( Completed, QString::number( data->isCompleted ) ); |
447 | map.insert( Description, data->desc ); | 451 | map.insert( Description, data->desc ); |
448 | map.insert( Summary, data->sum ); | 452 | map.insert( Summary, data->sum ); |
449 | map.insert( Priority, QString::number( data->priority ) ); | 453 | map.insert( Priority, QString::number( data->priority ) ); |
450 | map.insert( DateDay, QString::number( data->date.day() ) ); | 454 | map.insert( DateDay, QString::number( data->date.day() ) ); |
451 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 455 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
452 | map.insert( DateYear, QString::number( data->date.year() ) ); | 456 | map.insert( DateYear, QString::number( data->date.year() ) ); |
453 | map.insert( Progress, QString::number( data->prog ) ); | 457 | map.insert( Progress, QString::number( data->prog ) ); |
454 | // map.insert( CrossReference, crossToString() ); | 458 | // map.insert( CrossReference, crossToString() ); |
455 | /* FIXME!!! map.insert( State, ); | 459 | /* FIXME!!! map.insert( State, ); |
456 | map.insert( Recurrence, ); | 460 | map.insert( Recurrence, ); |
457 | map.insert( Reminders, ); | 461 | map.insert( Reminders, ); |
458 | map. | 462 | map. |
459 | */ | 463 | */ |
460 | return map; | 464 | return map; |
461 | } | 465 | } |
462 | 466 | ||
463 | /** | 467 | /** |
464 | * change or modify looks at the ref count and either | 468 | * change or modify looks at the ref count and either |
465 | * creates a new QShared Object or it can modify it | 469 | * creates a new QShared Object or it can modify it |
466 | * right in place | 470 | * right in place |
467 | */ | 471 | */ |
468 | void OTodo::changeOrModify() { | 472 | void OTodo::changeOrModify() { |
469 | if ( data->count != 1 ) { | 473 | if ( data->count != 1 ) { |
470 | qWarning("changeOrModify"); | 474 | qWarning("changeOrModify"); |
471 | data->deref(); | 475 | data->deref(); |
472 | OTodoData* d2 = new OTodoData(); | 476 | OTodoData* d2 = new OTodoData(); |
473 | copy(data, d2 ); | 477 | copy(data, d2 ); |
474 | data = d2; | 478 | data = d2; |
475 | } | 479 | } |
476 | } | 480 | } |
477 | // WATCHOUT | 481 | // WATCHOUT |
478 | /* | 482 | /* |
479 | * if you add something to the Data struct | 483 | * if you add something to the Data struct |
480 | * be sure to copy it here | 484 | * be sure to copy it here |
481 | */ | 485 | */ |
482 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 486 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
483 | dest->date = src->date; | 487 | dest->date = src->date; |
484 | dest->isCompleted = src->isCompleted; | 488 | dest->isCompleted = src->isCompleted; |
485 | dest->hasDate = src->hasDate; | 489 | dest->hasDate = src->hasDate; |
486 | dest->priority = src->priority; | 490 | dest->priority = src->priority; |
487 | dest->desc = src->desc; | 491 | dest->desc = src->desc; |
488 | dest->sum = src->sum; | 492 | dest->sum = src->sum; |
489 | dest->extra = src->extra; | 493 | dest->extra = src->extra; |
490 | dest->prog = src->prog; | 494 | dest->prog = src->prog; |
491 | 495 | ||
492 | if (src->state ) | 496 | if (src->state ) |
493 | dest->state = new OPimState( *src->state ); | 497 | dest->state = new OPimState( *src->state ); |
494 | 498 | ||
495 | if (src->recur ) | 499 | if (src->recur ) |
496 | dest->recur = new ORecur( *src->recur ); | 500 | dest->recur = new ORecur( *src->recur ); |
497 | 501 | ||
498 | if (src->maintainer ) | 502 | if (src->maintainer ) |
499 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | 503 | dest->maintainer = new OPimMaintainer( *src->maintainer ) |
500 | ; | 504 | ; |
501 | dest->start = src->start; | 505 | dest->start = src->start; |
502 | dest->completed = src->completed; | 506 | dest->completed = src->completed; |
503 | 507 | ||
504 | if (src->notifiers ) | 508 | if (src->notifiers ) |
505 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | 509 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); |
506 | } | 510 | } |
507 | QString OTodo::type() const { | 511 | QString OTodo::type() const { |
508 | return QString::fromLatin1("OTodo"); | 512 | return QString::fromLatin1("OTodo"); |
509 | } | 513 | } |
510 | QString OTodo::recordField(int /*id*/ )const { | 514 | QString OTodo::recordField(int /*id*/ )const { |
511 | return QString::null; | 515 | return QString::null; |
512 | } | 516 | } |
513 | 517 | ||
514 | int OTodo::rtti(){ | 518 | int OTodo::rtti(){ |
515 | return OPimResolver::TodoList; | 519 | return OPimResolver::TodoList; |
516 | } | 520 | } |
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h index f9a345a..6df98b9 100644 --- a/libopie/pim/otodo.h +++ b/libopie/pim/otodo.h | |||
@@ -1,294 +1,285 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_TODO_EVENT_H | 2 | #ifndef OPIE_TODO_EVENT_H |
3 | #define OPIE_TODO_EVENT_H | 3 | #define OPIE_TODO_EVENT_H |
4 | 4 | ||
5 | 5 | ||
6 | #include <qarray.h> | 6 | #include <qarray.h> |
7 | #include <qmap.h> | 7 | #include <qmap.h> |
8 | #include <qregexp.h> | 8 | #include <qregexp.h> |
9 | #include <qstringlist.h> | 9 | #include <qstringlist.h> |
10 | #include <qdatetime.h> | 10 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 11 | #include <qvaluelist.h> |
12 | 12 | ||
13 | #include <qpe/recordfields.h> | 13 | #include <qpe/recordfields.h> |
14 | #include <qpe/palmtopuidgen.h> | 14 | #include <qpe/palmtopuidgen.h> |
15 | 15 | ||
16 | #include <opie/opimrecord.h> | 16 | #include <opie/opimrecord.h> |
17 | 17 | ||
18 | 18 | ||
19 | class OPimState; | 19 | class OPimState; |
20 | class ORecur; | 20 | class ORecur; |
21 | class OPimMaintainer; | 21 | class OPimMaintainer; |
22 | class OPimNotifyManager; | 22 | class OPimNotifyManager; |
23 | class OTodo : public OPimRecord { | 23 | class OTodo : public OPimRecord { |
24 | public: | 24 | public: |
25 | typedef QValueList<OTodo> ValueList; | 25 | typedef QValueList<OTodo> ValueList; |
26 | enum RecordFields { | 26 | enum RecordFields { |
27 | Uid = Qtopia::UID_ID, | 27 | Uid = Qtopia::UID_ID, |
28 | Category = Qtopia::CATEGORY_ID, | 28 | Category = Qtopia::CATEGORY_ID, |
29 | HasDate, | 29 | HasDate, |
30 | Completed, | 30 | Completed, |
31 | Description, | 31 | Description, |
32 | Summary, | 32 | Summary, |
33 | Priority, | 33 | Priority, |
34 | DateDay, | 34 | DateDay, |
35 | DateMonth, | 35 | DateMonth, |
36 | DateYear, | 36 | DateYear, |
37 | Progress, | 37 | Progress, |
38 | CrossReference, | 38 | CrossReference, |
39 | State, | 39 | State, |
40 | Recurrence, | 40 | Recurrence, |
41 | Alarms, | 41 | Alarms, |
42 | Reminders, | 42 | Reminders, |
43 | Notifiers, | 43 | Notifiers, |
44 | Maintainer, | 44 | Maintainer, |
45 | StartDate, | 45 | StartDate, |
46 | CompletedDate | 46 | CompletedDate |
47 | }; | 47 | }; |
48 | public: | 48 | public: |
49 | // priorities from Very low to very high | 49 | // priorities from Very low to very high |
50 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; | 50 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; |
51 | 51 | ||
52 | /* Constructs a new ToDoEvent | 52 | /* Constructs a new ToDoEvent |
53 | @param completed Is the TodoEvent completed | 53 | @param completed Is the TodoEvent completed |
54 | @param priority What is the priority of this ToDoEvent | 54 | @param priority What is the priority of this ToDoEvent |
55 | @param category Which category does it belong( uid ) | 55 | @param category Which category does it belong( uid ) |
56 | @param summary A small summary of the todo | 56 | @param summary A small summary of the todo |
57 | @param description What is this ToDoEvent about | 57 | @param description What is this ToDoEvent about |
58 | @param hasDate Does this Event got a deadline | 58 | @param hasDate Does this Event got a deadline |
59 | @param date what is the deadline? | 59 | @param date what is the deadline? |
60 | @param uid what is the UUID of this Event | 60 | @param uid what is the UUID of this Event |
61 | **/ | 61 | **/ |
62 | OTodo( bool completed = false, int priority = Normal, | 62 | OTodo( bool completed = false, int priority = Normal, |
63 | const QStringList &category = QStringList(), | 63 | const QStringList &category = QStringList(), |
64 | const QString &summary = QString::null , | 64 | const QString &summary = QString::null , |
65 | const QString &description = QString::null, | 65 | const QString &description = QString::null, |
66 | ushort progress = 0, | 66 | ushort progress = 0, |
67 | bool hasDate = false, QDate date = QDate::currentDate(), | 67 | bool hasDate = false, QDate date = QDate::currentDate(), |
68 | int uid = 0 /*empty*/ ); | 68 | int uid = 0 /*empty*/ ); |
69 | 69 | ||
70 | OTodo( bool completed, int priority, | 70 | OTodo( bool completed, int priority, |
71 | const QArray<int>& category, | 71 | const QArray<int>& category, |
72 | const QString& summary = QString::null, | 72 | const QString& summary = QString::null, |
73 | const QString& description = QString::null, | 73 | const QString& description = QString::null, |
74 | ushort progress = 0, | 74 | ushort progress = 0, |
75 | bool hasDate = false, QDate date = QDate::currentDate(), | 75 | bool hasDate = false, QDate date = QDate::currentDate(), |
76 | int uid = 0 /* empty */ ); | 76 | int uid = 0 /* empty */ ); |
77 | 77 | ||
78 | /** Copy c'tor | 78 | /** Copy c'tor |
79 | * | 79 | * |
80 | */ | 80 | */ |
81 | OTodo(const OTodo & ); | 81 | OTodo(const OTodo & ); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | *destructor | 84 | *destructor |
85 | */ | 85 | */ |
86 | ~OTodo(); | 86 | ~OTodo(); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Is this event completed? | 89 | * Is this event completed? |
90 | */ | 90 | */ |
91 | bool isCompleted() const; | 91 | bool isCompleted() const; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Does this Event have a deadline | 94 | * Does this Event have a deadline |
95 | */ | 95 | */ |
96 | bool hasDueDate() const; | 96 | bool hasDueDate() const; |
97 | bool hasStartDate()const; | 97 | bool hasStartDate()const; |
98 | bool hasCompletedDate()const; | 98 | bool hasCompletedDate()const; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Does this Event has an alarm time ? | ||
102 | */ | ||
103 | bool hasAlarmDateTime() const; | ||
104 | |||
105 | /** | ||
106 | * What is the priority? | 101 | * What is the priority? |
107 | */ | 102 | */ |
108 | int priority()const ; | 103 | int priority()const ; |
109 | 104 | ||
110 | /** | 105 | /** |
111 | * progress as ushort 0, 20, 40, 60, 80 or 100% | 106 | * progress as ushort 0, 20, 40, 60, 80 or 100% |
112 | */ | 107 | */ |
113 | ushort progress() const; | 108 | ushort progress() const; |
114 | 109 | ||
115 | /** | 110 | /** |
116 | * The due Date | 111 | * The due Date |
117 | */ | 112 | */ |
118 | QDate dueDate()const; | 113 | QDate dueDate()const; |
119 | 114 | ||
120 | /** | 115 | /** |
121 | * When did it start? | 116 | * When did it start? |
122 | */ | 117 | */ |
123 | QDate startDate()const; | 118 | QDate startDate()const; |
124 | 119 | ||
125 | /** | 120 | /** |
126 | * When was it completed? | 121 | * When was it completed? |
127 | */ | 122 | */ |
128 | QDate completedDate()const; | 123 | QDate completedDate()const; |
129 | 124 | ||
130 | /** | 125 | /** |
131 | * does it have a state? | 126 | * does it have a state? |
132 | */ | 127 | */ |
133 | bool hasState()const; | 128 | bool hasState()const; |
134 | 129 | ||
135 | /** | 130 | /** |
136 | * What is the state of this OTodo? | 131 | * What is the state of this OTodo? |
137 | */ | 132 | */ |
138 | OPimState state()const; | 133 | OPimState state()const; |
139 | 134 | ||
140 | /** | 135 | /** |
141 | * has recurrence? | 136 | * has recurrence? |
142 | */ | 137 | */ |
143 | bool hasRecurrence()const; | 138 | bool hasRecurrence()const; |
144 | 139 | ||
145 | /** | 140 | /** |
146 | * the recurrance of this | 141 | * the recurrance of this |
147 | */ | 142 | */ |
148 | ORecur recurrence()const; | 143 | ORecur recurrence()const; |
149 | 144 | ||
150 | /** | 145 | /** |
151 | * does this OTodo have a maintainer? | 146 | * does this OTodo have a maintainer? |
152 | */ | 147 | */ |
153 | bool hasMaintainer()const; | 148 | bool hasMaintainer()const; |
154 | 149 | ||
155 | /** | 150 | /** |
156 | * the Maintainer of this OTodo | 151 | * the Maintainer of this OTodo |
157 | */ | 152 | */ |
158 | OPimMaintainer maintainer()const; | 153 | OPimMaintainer maintainer()const; |
159 | 154 | ||
160 | /** | 155 | /** |
161 | * The description of the todo | 156 | * The description of the todo |
162 | */ | 157 | */ |
163 | QString description()const; | 158 | QString description()const; |
164 | 159 | ||
165 | /** | 160 | /** |
166 | * A small summary of the todo | 161 | * A small summary of the todo |
167 | */ | 162 | */ |
168 | QString summary() const; | 163 | QString summary() const; |
169 | 164 | ||
170 | /** | 165 | /** |
171 | * @reimplemented | 166 | * @reimplemented |
172 | * Return this todoevent in a RichText formatted QString | 167 | * Return this todoevent in a RichText formatted QString |
173 | */ | 168 | */ |
174 | QString toRichText() const; | 169 | QString toRichText() const; |
175 | 170 | ||
176 | bool hasNotifiers()const; | 171 | bool hasNotifiers()const; |
177 | /* | 172 | /* |
178 | * FIXME check if the sharing is still fine!! -zecke | 173 | * FIXME check if the sharing is still fine!! -zecke |
179 | * ### CHECK If API is fine | 174 | * ### CHECK If API is fine |
180 | */ | 175 | */ |
181 | /** | 176 | /** |
182 | * return a reference to our notifiers... | 177 | * return a reference to our notifiers... |
183 | */ | 178 | */ |
184 | OPimNotifyManager ¬ifiers(); | 179 | OPimNotifyManager ¬ifiers(); |
185 | 180 | ||
186 | /** | 181 | /** |
187 | * | 182 | * |
188 | */ | 183 | */ |
189 | const OPimNotifyManager ¬ifiers()const; | 184 | const OPimNotifyManager ¬ifiers()const; |
190 | 185 | ||
191 | /** | 186 | /** |
192 | * reimplementations | 187 | * reimplementations |
193 | */ | 188 | */ |
194 | QString type()const; | 189 | QString type()const; |
195 | QString toShortText()const; | 190 | QString toShortText()const; |
196 | QString recordField(int id )const; | 191 | QString recordField(int id )const; |
197 | 192 | ||
198 | /** | 193 | /** |
199 | * toMap puts all data into the map. int relates | 194 | * toMap puts all data into the map. int relates |
200 | * to ToDoEvent RecordFields enum | 195 | * to ToDoEvent RecordFields enum |
201 | */ | 196 | */ |
202 | QMap<int, QString> toMap()const; | 197 | QMap<int, QString> toMap()const; |
203 | 198 | ||
204 | /** | 199 | /** |
205 | * Set if this Todo is completed | 200 | * Set if this Todo is completed |
206 | */ | 201 | */ |
207 | void setCompleted(bool completed ); | 202 | void setCompleted(bool completed ); |
208 | 203 | ||
209 | /** | 204 | /** |
210 | * set if this todo got an end data | 205 | * set if this todo got an end data |
211 | */ | 206 | */ |
212 | void setHasDueDate( bool hasDate ); | 207 | void setHasDueDate( bool hasDate ); |
213 | // FIXME we do not have these for start, completed | 208 | // FIXME we do not have these for start, completed |
214 | // cause we'll use the isNull() of QDate for figuring | 209 | // cause we'll use the isNull() of QDate for figuring |
215 | // out if it's has a date... | 210 | // out if it's has a date... |
216 | // decide what to do here? -zecke | 211 | // decide what to do here? -zecke |
217 | 212 | ||
218 | /** | 213 | /** |
219 | * Set the priority of the Todo | 214 | * Set the priority of the Todo |
220 | */ | 215 | */ |
221 | void setPriority(int priority ); | 216 | void setPriority(int priority ); |
222 | 217 | ||
223 | /** | 218 | /** |
224 | * Set the progress. | 219 | * Set the progress. |
225 | */ | 220 | */ |
226 | void setProgress( ushort progress ); | 221 | void setProgress( ushort progress ); |
227 | 222 | ||
228 | /** | 223 | /** |
229 | * set the end date | 224 | * set the end date |
230 | */ | 225 | */ |
231 | void setDueDate( const QDate& date ); | 226 | void setDueDate( const QDate& date ); |
232 | 227 | ||
233 | /** | 228 | /** |
234 | * set the start date | 229 | * set the start date |
235 | */ | 230 | */ |
236 | void setStartDate( const QDate& date ); | 231 | void setStartDate( const QDate& date ); |
237 | 232 | ||
238 | /** | 233 | /** |
239 | * set the completed date | 234 | * set the completed date |
240 | */ | 235 | */ |
241 | void setCompletedDate( const QDate& date ); | 236 | void setCompletedDate( const QDate& date ); |
242 | 237 | ||
243 | void setRecurrence( const ORecur& ); | 238 | void setRecurrence( const ORecur& ); |
244 | /** | ||
245 | * set the alarm time | ||
246 | */ | ||
247 | void setAlarmDateTime ( const QDateTime& alarm ); | ||
248 | 239 | ||
249 | void setDescription(const QString& ); | 240 | void setDescription(const QString& ); |
250 | void setSummary(const QString& ); | 241 | void setSummary(const QString& ); |
251 | 242 | ||
252 | /** | 243 | /** |
253 | * set the state of a Todo | 244 | * set the state of a Todo |
254 | * @param state State what the todo should take | 245 | * @param state State what the todo should take |
255 | */ | 246 | */ |
256 | void setState( const OPimState& state); | 247 | void setState( const OPimState& state); |
257 | 248 | ||
258 | /** | 249 | /** |
259 | * set the Maintainer Mode | 250 | * set the Maintainer Mode |
260 | */ | 251 | */ |
261 | void setMaintainer( const OPimMaintainer& ); | 252 | void setMaintainer( const OPimMaintainer& ); |
262 | 253 | ||
263 | bool isOverdue(); | 254 | bool isOverdue(); |
264 | 255 | ||
265 | 256 | ||
266 | virtual bool match( const QRegExp &r )const; | 257 | virtual bool match( const QRegExp &r )const; |
267 | 258 | ||
268 | bool operator<(const OTodo &toDoEvent )const; | 259 | bool operator<(const OTodo &toDoEvent )const; |
269 | bool operator<=(const OTodo &toDoEvent )const; | 260 | bool operator<=(const OTodo &toDoEvent )const; |
270 | bool operator!=(const OTodo &toDoEvent )const; | 261 | bool operator!=(const OTodo &toDoEvent )const; |
271 | bool operator>(const OTodo &toDoEvent )const; | 262 | bool operator>(const OTodo &toDoEvent )const; |
272 | bool operator>=(const OTodo &toDoEvent)const; | 263 | bool operator>=(const OTodo &toDoEvent)const; |
273 | bool operator==(const OTodo &toDoEvent )const; | 264 | bool operator==(const OTodo &toDoEvent )const; |
274 | OTodo &operator=(const OTodo &toDoEvent ); | 265 | OTodo &operator=(const OTodo &toDoEvent ); |
275 | 266 | ||
276 | static int rtti(); | 267 | static int rtti(); |
277 | 268 | ||
278 | private: | 269 | private: |
279 | class OTodoPrivate; | 270 | class OTodoPrivate; |
280 | struct OTodoData; | 271 | struct OTodoData; |
281 | 272 | ||
282 | void deref(); | 273 | void deref(); |
283 | inline void changeOrModify(); | 274 | inline void changeOrModify(); |
284 | void copy( OTodoData* src, OTodoData* dest ); | 275 | void copy( OTodoData* src, OTodoData* dest ); |
285 | OTodoPrivate *d; | 276 | OTodoPrivate *d; |
286 | OTodoData *data; | 277 | OTodoData *data; |
287 | 278 | ||
288 | }; | 279 | }; |
289 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { | 280 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { |
290 | return !(*this == toDoEvent); | 281 | return !(*this == toDoEvent); |
291 | } | 282 | } |
292 | 283 | ||
293 | 284 | ||
294 | #endif | 285 | #endif |
diff --git a/libopie/pim/otodoaccessbackend.h b/libopie/pim/otodoaccessbackend.h index 05e8ca9..6be95bc 100644 --- a/libopie/pim/otodoaccessbackend.h +++ b/libopie/pim/otodoaccessbackend.h | |||
@@ -1,24 +1,28 @@ | |||
1 | #ifndef OPIE_TODO_ACCESS_BACKEND_H | 1 | #ifndef OPIE_TODO_ACCESS_BACKEND_H |
2 | #define OPIE_TODO_ACCESS_BACKEND_H | 2 | #define OPIE_TODO_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qbitarray.h> | 4 | #include <qbitarray.h> |
5 | 5 | ||
6 | #include "otodo.h" | 6 | #include "otodo.h" |
7 | #include "opimaccessbackend.h" | 7 | #include "opimaccessbackend.h" |
8 | 8 | ||
9 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { | 9 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { |
10 | public: | 10 | public: |
11 | OTodoAccessBackend(); | 11 | OTodoAccessBackend(); |
12 | ~OTodoAccessBackend(); | 12 | ~OTodoAccessBackend(); |
13 | virtual QArray<int> effectiveToDos( const QDate& start, | 13 | virtual QArray<int> effectiveToDos( const QDate& start, |
14 | const QDate& end, | 14 | const QDate& end, |
15 | bool includeNoDates ) = 0; | 15 | bool includeNoDates ) = 0; |
16 | virtual QArray<int> overDue() = 0; | 16 | virtual QArray<int> overDue() = 0; |
17 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, | 17 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, |
18 | int cat ) = 0; | 18 | int cat ) = 0; |
19 | virtual void removeAllCompleted() = 0; | 19 | virtual void removeAllCompleted() = 0; |
20 | virtual QBitArray supports()const = 0; | 20 | virtual QBitArray supports()const = 0; |
21 | |||
22 | private: | ||
23 | class Private; | ||
24 | Private *d; | ||
21 | 25 | ||
22 | }; | 26 | }; |
23 | 27 | ||
24 | #endif | 28 | #endif |
diff --git a/libopie/pim/otodoaccessvcal.cpp b/libopie/pim/otodoaccessvcal.cpp index 3577e14..6415952 100644 --- a/libopie/pim/otodoaccessvcal.cpp +++ b/libopie/pim/otodoaccessvcal.cpp | |||
@@ -1,225 +1,249 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | 2 | ||
3 | #include <qtopia/private/vobject_p.h> | 3 | #include <qtopia/private/vobject_p.h> |
4 | #include <qtopia/timeconversion.h> | 4 | #include <qtopia/timeconversion.h> |
5 | #include <qtopia/private/qfiledirect_p.h> | 5 | #include <qtopia/private/qfiledirect_p.h> |
6 | 6 | ||
7 | #include "otodoaccessvcal.h" | 7 | #include "otodoaccessvcal.h" |
8 | 8 | ||
9 | namespace { | 9 | namespace { |
10 | static OTodo eventByVObj( VObject *obj ){ | 10 | static OTodo eventByVObj( VObject *obj ){ |
11 | OTodo event; | 11 | OTodo event; |
12 | VObject *ob; | 12 | VObject *ob; |
13 | QCString name; | 13 | QCString name; |
14 | // no uid, attendees, ... and no fun | 14 | // no uid, attendees, ... and no fun |
15 | // description | 15 | // description |
16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | 16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ |
17 | name = vObjectStringZValue( ob ); | 17 | name = vObjectStringZValue( ob ); |
18 | #if 0 | ||
18 | event.setDescription( name ); | 19 | event.setDescription( name ); |
20 | #else | ||
21 | event.setSummary( name ); | ||
22 | #endif | ||
19 | } | 23 | } |
20 | // summary | 24 | // summary |
21 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { | 25 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { |
22 | name = vObjectStringZValue( ob ); | 26 | name = vObjectStringZValue( ob ); |
27 | #if 0 | ||
23 | event.setSummary( name ); | 28 | event.setSummary( name ); |
29 | #else | ||
30 | event.setDescription( name ); | ||
31 | #endif | ||
24 | } | 32 | } |
25 | // completed | 33 | // completed |
26 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | 34 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ |
27 | name = vObjectStringZValue( ob ); | 35 | name = vObjectStringZValue( ob ); |
28 | if( name == "COMPLETED" ){ | 36 | if( name == "COMPLETED" ){ |
29 | event.setCompleted( true ); | 37 | event.setCompleted( true ); |
30 | }else{ | 38 | }else{ |
31 | event.setCompleted( false ); | 39 | event.setCompleted( false ); |
32 | } | 40 | } |
33 | }else | 41 | }else |
34 | event.setCompleted( false ); | 42 | event.setCompleted( false ); |
35 | // priority | 43 | // priority |
36 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | 44 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { |
37 | name = vObjectStringZValue( ob ); | 45 | name = vObjectStringZValue( ob ); |
38 | bool ok; | 46 | bool ok; |
39 | event.setPriority(name.toInt(&ok) ); | 47 | event.setPriority(name.toInt(&ok) ); |
40 | } | 48 | } |
41 | //due date | 49 | //due date |
42 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | 50 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ |
43 | event.setHasDueDate( true ); | 51 | event.setHasDueDate( true ); |
44 | name = vObjectStringZValue( ob ); | 52 | name = vObjectStringZValue( ob ); |
45 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); | 53 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); |
46 | } | 54 | } |
47 | // categories | 55 | // categories |
48 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | 56 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ |
49 | name = vObjectStringZValue( ob ); | 57 | name = vObjectStringZValue( ob ); |
50 | qWarning("Categories:%s", name.data() ); | 58 | qWarning("Categories:%s", name.data() ); |
51 | } | 59 | } |
52 | 60 | ||
53 | event.setUid( 1 ); | 61 | event.setUid( 1 ); |
54 | return event; | 62 | return event; |
55 | }; | 63 | }; |
56 | static VObject *vobjByEvent( const OTodo &event ) { | 64 | static VObject *vobjByEvent( const OTodo &event ) { |
57 | VObject *task = newVObject( VCTodoProp ); | 65 | VObject *task = newVObject( VCTodoProp ); |
58 | if( task == 0 ) | 66 | if( task == 0 ) |
59 | return 0l; | 67 | return 0l; |
60 | 68 | ||
61 | if( event.hasDueDate() ) { | 69 | if( event.hasDueDate() ) { |
62 | QTime time(0, 0, 0); | 70 | QTime time(0, 0, 0); |
63 | QDateTime date(event.dueDate(), time ); | 71 | QDateTime date(event.dueDate(), time ); |
64 | addPropValue( task, VCDueProp, | 72 | addPropValue( task, VCDueProp, |
65 | TimeConversion::toISO8601( date ) ); | 73 | TimeConversion::toISO8601( date ) ); |
66 | } | 74 | } |
67 | 75 | ||
68 | if( event.isCompleted() ) | 76 | if( event.isCompleted() ) |
69 | addPropValue( task, VCStatusProp, "COMPLETED"); | 77 | addPropValue( task, VCStatusProp, "COMPLETED"); |
70 | 78 | ||
71 | QString string = QString::number(event.priority() ); | 79 | QString string = QString::number(event.priority() ); |
72 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | 80 | addPropValue( task, VCPriorityProp, string.local8Bit() ); |
73 | 81 | ||
74 | addPropValue( task, VCCategoriesProp, | 82 | addPropValue( task, VCCategoriesProp, |
75 | event.idsToString( event.categories() ).local8Bit() ); | 83 | event.idsToString( event.categories() ).local8Bit() ); |
76 | 84 | ||
85 | #if 0 | ||
86 | |||
87 | // There seems a misrepresentation between summary in otodoevent | ||
88 | // and summary in vcard. | ||
89 | // The same with description.. | ||
90 | // Description is summary and vice versa.. Argh.. (eilers) | ||
91 | |||
92 | |||
77 | addPropValue( task, VCDescriptionProp, | 93 | addPropValue( task, VCDescriptionProp, |
78 | event.description().local8Bit() ); | 94 | event.description().local8Bit() ); |
79 | 95 | ||
80 | addPropValue( task, VCSummaryProp, | 96 | addPropValue( task, VCSummaryProp, |
81 | event.summary().local8Bit() ); | 97 | event.summary().local8Bit() ); |
98 | |||
99 | #else | ||
100 | addPropValue( task, VCDescriptionProp, | ||
101 | event.summary().local8Bit() ); | ||
102 | |||
103 | addPropValue( task, VCSummaryProp, | ||
104 | event.description().local8Bit() ); | ||
105 | #endif | ||
82 | return task; | 106 | return task; |
83 | }; | 107 | }; |
84 | } | 108 | } |
85 | 109 | ||
86 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) | 110 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) |
87 | : m_dirty(false), m_file( path ) | 111 | : m_dirty(false), m_file( path ) |
88 | { | 112 | { |
89 | } | 113 | } |
90 | OTodoAccessVCal::~OTodoAccessVCal() { | 114 | OTodoAccessVCal::~OTodoAccessVCal() { |
91 | } | 115 | } |
92 | bool OTodoAccessVCal::load() { | 116 | bool OTodoAccessVCal::load() { |
93 | m_map.clear(); | 117 | m_map.clear(); |
94 | m_dirty = false; | 118 | m_dirty = false; |
95 | 119 | ||
96 | VObject* vcal = 0l; | 120 | VObject* vcal = 0l; |
97 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 121 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
98 | if (!vcal ) | 122 | if (!vcal ) |
99 | return false; | 123 | return false; |
100 | 124 | ||
101 | // Iterate over the list | 125 | // Iterate over the list |
102 | VObjectIterator it; | 126 | VObjectIterator it; |
103 | VObject* vobj; | 127 | VObject* vobj; |
104 | 128 | ||
105 | initPropIterator(&it, vcal); | 129 | initPropIterator(&it, vcal); |
106 | 130 | ||
107 | while( moreIteration( &it ) ) { | 131 | while( moreIteration( &it ) ) { |
108 | vobj = ::nextVObject( &it ); | 132 | vobj = ::nextVObject( &it ); |
109 | QCString name = ::vObjectName( vobj ); | 133 | QCString name = ::vObjectName( vobj ); |
110 | if( name == VCTodoProp ){ | 134 | if( name == VCTodoProp ){ |
111 | OTodo to = eventByVObj( vobj ); | 135 | OTodo to = eventByVObj( vobj ); |
112 | m_map.insert( to.uid(), to ); | 136 | m_map.insert( to.uid(), to ); |
113 | } | 137 | } |
114 | } | 138 | } |
115 | 139 | ||
116 | // Should I do a delete vcal? | 140 | // Should I do a delete vcal? |
117 | 141 | ||
118 | return true; | 142 | return true; |
119 | } | 143 | } |
120 | bool OTodoAccessVCal::reload() { | 144 | bool OTodoAccessVCal::reload() { |
121 | return load(); | 145 | return load(); |
122 | } | 146 | } |
123 | bool OTodoAccessVCal::save() { | 147 | bool OTodoAccessVCal::save() { |
124 | if (!m_dirty ) | 148 | if (!m_dirty ) |
125 | return true; | 149 | return true; |
126 | 150 | ||
127 | QFileDirect file( m_file ); | 151 | QFileDirect file( m_file ); |
128 | if (!file.open(IO_WriteOnly ) ) | 152 | if (!file.open(IO_WriteOnly ) ) |
129 | return false; | 153 | return false; |
130 | 154 | ||
131 | VObject *obj; | 155 | VObject *obj; |
132 | obj = newVObject( VCCalProp ); | 156 | obj = newVObject( VCCalProp ); |
133 | addPropValue( obj, VCVersionProp, "1.0" ); | 157 | addPropValue( obj, VCVersionProp, "1.0" ); |
134 | VObject *vo; | 158 | VObject *vo; |
135 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 159 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
136 | vo = vobjByEvent( it.data() ); | 160 | vo = vobjByEvent( it.data() ); |
137 | addVObjectProp(obj, vo ); | 161 | addVObjectProp(obj, vo ); |
138 | } | 162 | } |
139 | writeVObject( file.directHandle(), obj ); | 163 | writeVObject( file.directHandle(), obj ); |
140 | cleanVObject( obj ); | 164 | cleanVObject( obj ); |
141 | cleanStrTbl(); | 165 | cleanStrTbl(); |
142 | 166 | ||
143 | m_dirty = false; | 167 | m_dirty = false; |
144 | return true; | 168 | return true; |
145 | } | 169 | } |
146 | void OTodoAccessVCal::clear() { | 170 | void OTodoAccessVCal::clear() { |
147 | m_map.clear(); | 171 | m_map.clear(); |
148 | m_dirty = true; | 172 | m_dirty = true; |
149 | } | 173 | } |
150 | bool OTodoAccessVCal::add( const OTodo& to ) { | 174 | bool OTodoAccessVCal::add( const OTodo& to ) { |
151 | m_map.insert( to.uid(), to ); | 175 | m_map.insert( to.uid(), to ); |
152 | m_dirty = true; | 176 | m_dirty = true; |
153 | return true; | 177 | return true; |
154 | } | 178 | } |
155 | bool OTodoAccessVCal::remove( int uid ) { | 179 | bool OTodoAccessVCal::remove( int uid ) { |
156 | m_map.remove( uid ); | 180 | m_map.remove( uid ); |
157 | m_dirty = true; | 181 | m_dirty = true; |
158 | return true; | 182 | return true; |
159 | } | 183 | } |
160 | void OTodoAccessVCal::removeAllCompleted() { | 184 | void OTodoAccessVCal::removeAllCompleted() { |
161 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { | 185 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { |
162 | if ( (*it).isCompleted() ) | 186 | if ( (*it).isCompleted() ) |
163 | m_map.remove( it ); | 187 | m_map.remove( it ); |
164 | } | 188 | } |
165 | } | 189 | } |
166 | bool OTodoAccessVCal::replace( const OTodo& to ) { | 190 | bool OTodoAccessVCal::replace( const OTodo& to ) { |
167 | m_map.replace( to.uid(), to ); | 191 | m_map.replace( to.uid(), to ); |
168 | m_dirty = true; | 192 | m_dirty = true; |
169 | return true; | 193 | return true; |
170 | } | 194 | } |
171 | OTodo OTodoAccessVCal::find(int uid )const { | 195 | OTodo OTodoAccessVCal::find(int uid )const { |
172 | return m_map[uid]; | 196 | return m_map[uid]; |
173 | } | 197 | } |
174 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { | 198 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { |
175 | QArray<int> ar(0); | 199 | QArray<int> ar(0); |
176 | return ar; | 200 | return ar; |
177 | } | 201 | } |
178 | QArray<int> OTodoAccessVCal::allRecords()const { | 202 | QArray<int> OTodoAccessVCal::allRecords()const { |
179 | QArray<int> ar( m_map.count() ); | 203 | QArray<int> ar( m_map.count() ); |
180 | QMap<int, OTodo>::ConstIterator it; | 204 | QMap<int, OTodo>::ConstIterator it; |
181 | int i = 0; | 205 | int i = 0; |
182 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 206 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
183 | ar[i] = it.key(); | 207 | ar[i] = it.key(); |
184 | i++; | 208 | i++; |
185 | } | 209 | } |
186 | return ar; | 210 | return ar; |
187 | } | 211 | } |
188 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp &r)const { | 212 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { |
189 | QArray<int> ar(0); | 213 | QArray<int> ar(0); |
190 | return ar; | 214 | return ar; |
191 | } | 215 | } |
192 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { | 216 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { |
193 | QArray<int> ar(0); | 217 | QArray<int> ar(0); |
194 | return ar; | 218 | return ar; |
195 | } | 219 | } |
196 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , | 220 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , |
197 | const QDate& , | 221 | const QDate& , |
198 | bool ) { | 222 | bool ) { |
199 | QArray<int> ar(0); | 223 | QArray<int> ar(0); |
200 | return ar; | 224 | return ar; |
201 | } | 225 | } |
202 | QArray<int> OTodoAccessVCal::overDue() { | 226 | QArray<int> OTodoAccessVCal::overDue() { |
203 | QArray<int> ar(0); | 227 | QArray<int> ar(0); |
204 | return ar; | 228 | return ar; |
205 | } | 229 | } |
206 | QBitArray OTodoAccessVCal::supports()const { | 230 | QBitArray OTodoAccessVCal::supports()const { |
207 | static QBitArray ar = sup(); | 231 | static QBitArray ar = sup(); |
208 | 232 | ||
209 | return ar; | 233 | return ar; |
210 | } | 234 | } |
211 | QBitArray OTodoAccessVCal::sup() { | 235 | QBitArray OTodoAccessVCal::sup() { |
212 | QBitArray ar ( OTodo::CompletedDate +1 ); | 236 | QBitArray ar ( OTodo::CompletedDate +1 ); |
213 | ar.fill( true ); | 237 | ar.fill( true ); |
214 | 238 | ||
215 | ar[OTodo::CrossReference] = false; | 239 | ar[OTodo::CrossReference] = false; |
216 | ar[OTodo::State ] = false; | 240 | ar[OTodo::State ] = false; |
217 | ar[OTodo::Reminders] = false; | 241 | ar[OTodo::Reminders] = false; |
218 | ar[OTodo::Notifiers] = false; | 242 | ar[OTodo::Notifiers] = false; |
219 | ar[OTodo::Maintainer] = false; | 243 | ar[OTodo::Maintainer] = false; |
220 | ar[OTodo::Progress] = false; | 244 | ar[OTodo::Progress] = false; |
221 | ar[OTodo::Alarms ] = false; | 245 | ar[OTodo::Alarms ] = false; |
222 | ar[OTodo::Recurrence] = false; | 246 | ar[OTodo::Recurrence] = false; |
223 | 247 | ||
224 | return ar; | 248 | return ar; |
225 | } | 249 | } |
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 3d15354..f688735 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -1,874 +1,876 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <sys/mman.h> | 4 | #include <sys/mman.h> |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
7 | 7 | ||
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qvector.h> | 12 | #include <qvector.h> |
13 | 13 | ||
14 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
15 | #include <qpe/stringutil.h> | 15 | #include <qpe/stringutil.h> |
16 | #include <qpe/timeconversion.h> | 16 | #include <qpe/timeconversion.h> |
17 | 17 | ||
18 | #include "oconversion.h" | 18 | #include "oconversion.h" |
19 | #include "opimstate.h" | 19 | #include "opimstate.h" |
20 | #include "otimezone.h" | 20 | #include "otimezone.h" |
21 | #include "opimnotifymanager.h" | 21 | #include "opimnotifymanager.h" |
22 | #include "orecur.h" | 22 | #include "orecur.h" |
23 | #include "otodoaccessxml.h" | 23 | #include "otodoaccessxml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | time_t rp_end; | 26 | time_t rp_end; |
27 | ORecur* rec; | 27 | ORecur* rec; |
28 | ORecur *recur() { | 28 | ORecur *recur() { |
29 | if (!rec ) rec = new ORecur; | 29 | if (!rec ) rec = new ORecur; |
30 | return rec; | 30 | return rec; |
31 | } | 31 | } |
32 | int snd; | 32 | int snd; |
33 | enum MoreAttributes { | 33 | enum MoreAttributes { |
34 | FRType = OTodo::CompletedDate + 2, | 34 | FRType = OTodo::CompletedDate + 2, |
35 | FRWeekdays, | 35 | FRWeekdays, |
36 | FRPosition, | 36 | FRPosition, |
37 | FRFreq, | 37 | FRFreq, |
38 | FRHasEndDate, | 38 | FRHasEndDate, |
39 | FREndDate, | 39 | FREndDate, |
40 | FRStart, | 40 | FRStart, |
41 | FREnd | 41 | FREnd |
42 | }; | 42 | }; |
43 | // FROM TT again | 43 | // FROM TT again |
44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
45 | { | 45 | { |
46 | char needleChar; | 46 | char needleChar; |
47 | char haystackChar; | 47 | char haystackChar; |
48 | if (!needle || !haystack || !hLen || !nLen) | 48 | if (!needle || !haystack || !hLen || !nLen) |
49 | return 0; | 49 | return 0; |
50 | 50 | ||
51 | const char* hsearch = haystack; | 51 | const char* hsearch = haystack; |
52 | 52 | ||
53 | if ((needleChar = *needle++) != 0) { | 53 | if ((needleChar = *needle++) != 0) { |
54 | nLen--; //(to make up for needle++) | 54 | nLen--; //(to make up for needle++) |
55 | do { | 55 | do { |
56 | do { | 56 | do { |
57 | if ((haystackChar = *hsearch++) == 0) | 57 | if ((haystackChar = *hsearch++) == 0) |
58 | return (0); | 58 | return (0); |
59 | if (hsearch >= haystack + hLen) | 59 | if (hsearch >= haystack + hLen) |
60 | return (0); | 60 | return (0); |
61 | } while (haystackChar != needleChar); | 61 | } while (haystackChar != needleChar); |
62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
63 | hsearch--; | 63 | hsearch--; |
64 | } | 64 | } |
65 | return ((char *)hsearch); | 65 | return ((char *)hsearch); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
71 | const QString& fileName ) | 71 | const QString& fileName ) |
72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
73 | { | 73 | { |
74 | if (!fileName.isEmpty() ) | 74 | if (!fileName.isEmpty() ) |
75 | m_file = fileName; | 75 | m_file = fileName; |
76 | else | 76 | else |
77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
78 | } | 78 | } |
79 | OTodoAccessXML::~OTodoAccessXML() { | 79 | OTodoAccessXML::~OTodoAccessXML() { |
80 | 80 | ||
81 | } | 81 | } |
82 | bool OTodoAccessXML::load() { | 82 | bool OTodoAccessXML::load() { |
83 | rec = 0; | 83 | rec = 0; |
84 | m_opened = true; | 84 | m_opened = true; |
85 | m_changed = false; | 85 | m_changed = false; |
86 | /* initialize dict */ | 86 | /* initialize dict */ |
87 | /* | 87 | /* |
88 | * UPDATE dict if you change anything!!! | 88 | * UPDATE dict if you change anything!!! |
89 | */ | 89 | */ |
90 | QAsciiDict<int> dict(21); | 90 | QAsciiDict<int> dict(26); |
91 | dict.setAutoDelete( TRUE ); | 91 | dict.setAutoDelete( TRUE ); |
92 | dict.insert("Categories" , new int(OTodo::Category) ); | 92 | dict.insert("Categories" , new int(OTodo::Category) ); |
93 | dict.insert("Uid" , new int(OTodo::Uid) ); | 93 | dict.insert("Uid" , new int(OTodo::Uid) ); |
94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
95 | dict.insert("Completed" , new int(OTodo::Completed) ); | 95 | dict.insert("Completed" , new int(OTodo::Completed) ); |
96 | dict.insert("Description" , new int(OTodo::Description) ); | 96 | dict.insert("Description" , new int(OTodo::Description) ); |
97 | dict.insert("Summary" , new int(OTodo::Summary) ); | 97 | dict.insert("Summary" , new int(OTodo::Summary) ); |
98 | dict.insert("Priority" , new int(OTodo::Priority) ); | 98 | dict.insert("Priority" , new int(OTodo::Priority) ); |
99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
102 | dict.insert("Progress" , new int(OTodo::Progress) ); | 102 | dict.insert("Progress" , new int(OTodo::Progress) ); |
103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); | 103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); |
104 | dict.insert("StartDate", new int(OTodo::StartDate) ); | 104 | dict.insert("StartDate", new int(OTodo::StartDate) ); |
105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
106 | dict.insert("State", new int(OTodo::State) ); | 106 | dict.insert("State", new int(OTodo::State) ); |
107 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 107 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
108 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 108 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
111 | dict.insert("rtype", new int(FRType) ); | 111 | dict.insert("rtype", new int(FRType) ); |
112 | dict.insert("rweekdays", new int(FRWeekdays) ); | 112 | dict.insert("rweekdays", new int(FRWeekdays) ); |
113 | dict.insert("rposition", new int(FRPosition) ); | 113 | dict.insert("rposition", new int(FRPosition) ); |
114 | dict.insert("rfreq", new int(FRFreq) ); | 114 | dict.insert("rfreq", new int(FRFreq) ); |
115 | dict.insert("start", new int(FRStart) ); | 115 | dict.insert("start", new int(FRStart) ); |
116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
117 | dict.insert("enddt", new int(FREndDate) ); | 117 | dict.insert("enddt", new int(FREndDate) ); |
118 | 118 | ||
119 | // here the custom XML parser from TT it's GPL | 119 | // here the custom XML parser from TT it's GPL |
120 | // but we want to push OpiePIM... to TT..... | 120 | // but we want to push OpiePIM... to TT..... |
121 | // mmap part from zecke :) | 121 | // mmap part from zecke :) |
122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); | 122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
123 | struct stat attribut; | 123 | struct stat attribut; |
124 | if ( fd < 0 ) return false; | 124 | if ( fd < 0 ) return false; |
125 | 125 | ||
126 | if ( fstat(fd, &attribut ) == -1 ) { | 126 | if ( fstat(fd, &attribut ) == -1 ) { |
127 | ::close( fd ); | 127 | ::close( fd ); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
131 | if ( map_addr == ( (caddr_t)-1) ) { | 131 | if ( map_addr == ( (caddr_t)-1) ) { |
132 | ::close(fd ); | 132 | ::close(fd ); |
133 | return false; | 133 | return false; |
134 | } | 134 | } |
135 | /* advise the kernel who we want to read it */ | 135 | /* advise the kernel who we want to read it */ |
136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | 136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); |
137 | /* we do not the file any more */ | 137 | /* we do not the file any more */ |
138 | ::close( fd ); | 138 | ::close( fd ); |
139 | 139 | ||
140 | char* dt = (char*)map_addr; | 140 | char* dt = (char*)map_addr; |
141 | int len = attribut.st_size; | 141 | int len = attribut.st_size; |
142 | int i = 0; | 142 | int i = 0; |
143 | char *point; | 143 | char *point; |
144 | const char* collectionString = "<Task "; | 144 | const char* collectionString = "<Task "; |
145 | int strLen = strlen(collectionString); | 145 | int strLen = strlen(collectionString); |
146 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { | 146 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { |
147 | i = point -dt; | 147 | i = point -dt; |
148 | i+= strLen; | 148 | i+= strLen; |
149 | qWarning("Found a start at %d %d", i, (point-dt) ); | 149 | qWarning("Found a start at %d %d", i, (point-dt) ); |
150 | 150 | ||
151 | OTodo ev; | 151 | OTodo ev; |
152 | m_year = m_month = m_day = 0; | 152 | m_year = m_month = m_day = 0; |
153 | 153 | ||
154 | while ( TRUE ) { | 154 | while ( TRUE ) { |
155 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 155 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
156 | ++i; | 156 | ++i; |
157 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 157 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
158 | break; | 158 | break; |
159 | 159 | ||
160 | // we have another attribute, read it. | 160 | // we have another attribute, read it. |
161 | int j = i; | 161 | int j = i; |
162 | while ( j < len && dt[j] != '=' ) | 162 | while ( j < len && dt[j] != '=' ) |
163 | ++j; | 163 | ++j; |
164 | QCString attr( dt+i, j-i+1); | 164 | QCString attr( dt+i, j-i+1); |
165 | 165 | ||
166 | i = ++j; // skip = | 166 | i = ++j; // skip = |
167 | 167 | ||
168 | // find the start of quotes | 168 | // find the start of quotes |
169 | while ( i < len && dt[i] != '"' ) | 169 | while ( i < len && dt[i] != '"' ) |
170 | ++i; | 170 | ++i; |
171 | j = ++i; | 171 | j = ++i; |
172 | 172 | ||
173 | bool haveUtf = FALSE; | 173 | bool haveUtf = FALSE; |
174 | bool haveEnt = FALSE; | 174 | bool haveEnt = FALSE; |
175 | while ( j < len && dt[j] != '"' ) { | 175 | while ( j < len && dt[j] != '"' ) { |
176 | if ( ((unsigned char)dt[j]) > 0x7f ) | 176 | if ( ((unsigned char)dt[j]) > 0x7f ) |
177 | haveUtf = TRUE; | 177 | haveUtf = TRUE; |
178 | if ( dt[j] == '&' ) | 178 | if ( dt[j] == '&' ) |
179 | haveEnt = TRUE; | 179 | haveEnt = TRUE; |
180 | ++j; | 180 | ++j; |
181 | } | 181 | } |
182 | if ( i == j ) { | 182 | if ( i == j ) { |
183 | // empty value | 183 | // empty value |
184 | i = j + 1; | 184 | i = j + 1; |
185 | continue; | 185 | continue; |
186 | } | 186 | } |
187 | 187 | ||
188 | QCString value( dt+i, j-i+1 ); | 188 | QCString value( dt+i, j-i+1 ); |
189 | i = j + 1; | 189 | i = j + 1; |
190 | 190 | ||
191 | QString str = (haveUtf ? QString::fromUtf8( value ) | 191 | QString str = (haveUtf ? QString::fromUtf8( value ) |
192 | : QString::fromLatin1( value ) ); | 192 | : QString::fromLatin1( value ) ); |
193 | if ( haveEnt ) | 193 | if ( haveEnt ) |
194 | str = Qtopia::plainString( str ); | 194 | str = Qtopia::plainString( str ); |
195 | 195 | ||
196 | /* | 196 | /* |
197 | * add key + value | 197 | * add key + value |
198 | */ | 198 | */ |
199 | todo( &dict, ev, attr, str ); | 199 | todo( &dict, ev, attr, str ); |
200 | 200 | ||
201 | } | 201 | } |
202 | /* | 202 | /* |
203 | * now add it | 203 | * now add it |
204 | */ | 204 | */ |
205 | qWarning("End at %d", i ); | 205 | qWarning("End at %d", i ); |
206 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 206 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
207 | ev.setUid( 1 ); | 207 | ev.setUid( 1 ); |
208 | m_changed = true; | 208 | m_changed = true; |
209 | } | 209 | } |
210 | if ( ev.hasDueDate() ) { | 210 | if ( ev.hasDueDate() ) { |
211 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 211 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
212 | } | 212 | } |
213 | if ( rec && rec->doesRecur() ) { | 213 | if ( rec && rec->doesRecur() ) { |
214 | OTimeZone utc = OTimeZone::utc(); | 214 | OTimeZone utc = OTimeZone::utc(); |
215 | ORecur recu( *rec ); // call copy c'tor | 215 | ORecur recu( *rec ); // call copy c'tor |
216 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); | 216 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); |
217 | recu.setStart( ev.dueDate() ); | 217 | recu.setStart( ev.dueDate() ); |
218 | ev.setRecurrence( recu ); | 218 | ev.setRecurrence( recu ); |
219 | } | 219 | } |
220 | m_events.insert(ev.uid(), ev ); | 220 | m_events.insert(ev.uid(), ev ); |
221 | m_year = m_month = m_day = -1; | 221 | m_year = m_month = m_day = -1; |
222 | delete rec; | 222 | delete rec; |
223 | rec = 0; | 223 | rec = 0; |
224 | } | 224 | } |
225 | 225 | ||
226 | munmap(map_addr, attribut.st_size ); | 226 | munmap(map_addr, attribut.st_size ); |
227 | 227 | ||
228 | qWarning("counts %d records loaded!", m_events.count() ); | 228 | qWarning("counts %d records loaded!", m_events.count() ); |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | bool OTodoAccessXML::reload() { | 231 | bool OTodoAccessXML::reload() { |
232 | m_events.clear(); | 232 | m_events.clear(); |
233 | return load(); | 233 | return load(); |
234 | } | 234 | } |
235 | bool OTodoAccessXML::save() { | 235 | bool OTodoAccessXML::save() { |
236 | // qWarning("saving"); | 236 | // qWarning("saving"); |
237 | if (!m_opened || !m_changed ) { | 237 | if (!m_opened || !m_changed ) { |
238 | // qWarning("not saving"); | 238 | // qWarning("not saving"); |
239 | return true; | 239 | return true; |
240 | } | 240 | } |
241 | QString strNewFile = m_file + ".new"; | 241 | QString strNewFile = m_file + ".new"; |
242 | QFile f( strNewFile ); | 242 | QFile f( strNewFile ); |
243 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 243 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
244 | return false; | 244 | return false; |
245 | 245 | ||
246 | int written; | 246 | int written; |
247 | QString out; | 247 | QString out; |
248 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 248 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
249 | 249 | ||
250 | // for all todos | 250 | // for all todos |
251 | QMap<int, OTodo>::Iterator it; | 251 | QMap<int, OTodo>::Iterator it; |
252 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 252 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
253 | out+= "<Task " + toString( (*it) ) + " />\n"; | 253 | out+= "<Task " + toString( (*it) ) + " />\n"; |
254 | QCString cstr = out.utf8(); | 254 | QCString cstr = out.utf8(); |
255 | written = f.writeBlock( cstr.data(), cstr.length() ); | 255 | written = f.writeBlock( cstr.data(), cstr.length() ); |
256 | 256 | ||
257 | /* less written then we wanted */ | 257 | /* less written then we wanted */ |
258 | if ( written != (int)cstr.length() ) { | 258 | if ( written != (int)cstr.length() ) { |
259 | f.close(); | 259 | f.close(); |
260 | QFile::remove( strNewFile ); | 260 | QFile::remove( strNewFile ); |
261 | return false; | 261 | return false; |
262 | } | 262 | } |
263 | out = QString::null; | 263 | out = QString::null; |
264 | } | 264 | } |
265 | 265 | ||
266 | out += "</Tasks>"; | 266 | out += "</Tasks>"; |
267 | QCString cstr = out.utf8(); | 267 | QCString cstr = out.utf8(); |
268 | written = f.writeBlock( cstr.data(), cstr.length() ); | 268 | written = f.writeBlock( cstr.data(), cstr.length() ); |
269 | 269 | ||
270 | if ( written != (int)cstr.length() ) { | 270 | if ( written != (int)cstr.length() ) { |
271 | f.close(); | 271 | f.close(); |
272 | QFile::remove( strNewFile ); | 272 | QFile::remove( strNewFile ); |
273 | return false; | 273 | return false; |
274 | } | 274 | } |
275 | /* flush before renaming */ | 275 | /* flush before renaming */ |
276 | f.close(); | 276 | f.close(); |
277 | 277 | ||
278 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 278 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
279 | // qWarning("error renaming"); | 279 | // qWarning("error renaming"); |
280 | QFile::remove( strNewFile ); | 280 | QFile::remove( strNewFile ); |
281 | } | 281 | } |
282 | 282 | ||
283 | m_changed = false; | 283 | m_changed = false; |
284 | return true; | 284 | return true; |
285 | } | 285 | } |
286 | QArray<int> OTodoAccessXML::allRecords()const { | 286 | QArray<int> OTodoAccessXML::allRecords()const { |
287 | QArray<int> ids( m_events.count() ); | 287 | QArray<int> ids( m_events.count() ); |
288 | QMap<int, OTodo>::ConstIterator it; | 288 | QMap<int, OTodo>::ConstIterator it; |
289 | int i = 0; | 289 | int i = 0; |
290 | 290 | ||
291 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 291 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
292 | ids[i] = it.key(); | 292 | ids[i] = it.key(); |
293 | i++; | 293 | i++; |
294 | } | 294 | } |
295 | return ids; | 295 | return ids; |
296 | } | 296 | } |
297 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { | 297 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { |
298 | QArray<int> ids(0); | 298 | QArray<int> ids(0); |
299 | return ids; | 299 | return ids; |
300 | } | 300 | } |
301 | OTodo OTodoAccessXML::find( int uid )const { | 301 | OTodo OTodoAccessXML::find( int uid )const { |
302 | OTodo todo; | 302 | OTodo todo; |
303 | todo.setUid( 0 ); // isEmpty() | 303 | todo.setUid( 0 ); // isEmpty() |
304 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); | 304 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); |
305 | if ( it != m_events.end() ) | 305 | if ( it != m_events.end() ) |
306 | todo = it.data(); | 306 | todo = it.data(); |
307 | 307 | ||
308 | return todo; | 308 | return todo; |
309 | } | 309 | } |
310 | void OTodoAccessXML::clear() { | 310 | void OTodoAccessXML::clear() { |
311 | if (m_opened ) | 311 | if (m_opened ) |
312 | m_changed = true; | 312 | m_changed = true; |
313 | 313 | ||
314 | m_events.clear(); | 314 | m_events.clear(); |
315 | } | 315 | } |
316 | bool OTodoAccessXML::add( const OTodo& todo ) { | 316 | bool OTodoAccessXML::add( const OTodo& todo ) { |
317 | // qWarning("add"); | 317 | // qWarning("add"); |
318 | m_changed = true; | 318 | m_changed = true; |
319 | m_events.insert( todo.uid(), todo ); | 319 | m_events.insert( todo.uid(), todo ); |
320 | 320 | ||
321 | return true; | 321 | return true; |
322 | } | 322 | } |
323 | bool OTodoAccessXML::remove( int uid ) { | 323 | bool OTodoAccessXML::remove( int uid ) { |
324 | m_changed = true; | 324 | m_changed = true; |
325 | m_events.remove( uid ); | 325 | m_events.remove( uid ); |
326 | 326 | ||
327 | return true; | 327 | return true; |
328 | } | 328 | } |
329 | bool OTodoAccessXML::replace( const OTodo& todo) { | 329 | bool OTodoAccessXML::replace( const OTodo& todo) { |
330 | m_changed = true; | 330 | m_changed = true; |
331 | m_events.replace( todo.uid(), todo ); | 331 | m_events.replace( todo.uid(), todo ); |
332 | 332 | ||
333 | return true; | 333 | return true; |
334 | } | 334 | } |
335 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, | 335 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, |
336 | const QDate& end, | 336 | const QDate& end, |
337 | bool includeNoDates ) { | 337 | bool includeNoDates ) { |
338 | QArray<int> ids( m_events.count() ); | 338 | QArray<int> ids( m_events.count() ); |
339 | QMap<int, OTodo>::Iterator it; | 339 | QMap<int, OTodo>::Iterator it; |
340 | 340 | ||
341 | int i = 0; | 341 | int i = 0; |
342 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 342 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
343 | if ( !it.data().hasDueDate() ) { | 343 | if ( !it.data().hasDueDate() ) { |
344 | if ( includeNoDates ) { | 344 | if ( includeNoDates ) { |
345 | ids[i] = it.key(); | 345 | ids[i] = it.key(); |
346 | i++; | 346 | i++; |
347 | } | 347 | } |
348 | }else if ( it.data().dueDate() >= start && | 348 | }else if ( it.data().dueDate() >= start && |
349 | it.data().dueDate() <= end ) { | 349 | it.data().dueDate() <= end ) { |
350 | ids[i] = it.key(); | 350 | ids[i] = it.key(); |
351 | i++; | 351 | i++; |
352 | } | 352 | } |
353 | } | 353 | } |
354 | ids.resize( i ); | 354 | ids.resize( i ); |
355 | return ids; | 355 | return ids; |
356 | } | 356 | } |
357 | QArray<int> OTodoAccessXML::overDue() { | 357 | QArray<int> OTodoAccessXML::overDue() { |
358 | QArray<int> ids( m_events.count() ); | 358 | QArray<int> ids( m_events.count() ); |
359 | int i = 0; | 359 | int i = 0; |
360 | 360 | ||
361 | QMap<int, OTodo>::Iterator it; | 361 | QMap<int, OTodo>::Iterator it; |
362 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 362 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
363 | if ( it.data().isOverdue() ) { | 363 | if ( it.data().isOverdue() ) { |
364 | ids[i] = it.key(); | 364 | ids[i] = it.key(); |
365 | i++; | 365 | i++; |
366 | } | 366 | } |
367 | } | 367 | } |
368 | ids.resize( i ); | 368 | ids.resize( i ); |
369 | return ids; | 369 | return ids; |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | /* private */ | 373 | /* private */ |
374 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | 374 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, |
375 | const QCString& attr, const QString& val) { | 375 | const QCString& attr, const QString& val) { |
376 | // qWarning("parse to do from XMLElement" ); | 376 | // qWarning("parse to do from XMLElement" ); |
377 | 377 | ||
378 | int *find=0; | 378 | int *find=0; |
379 | 379 | ||
380 | find = (*dict)[ attr.data() ]; | 380 | find = (*dict)[ attr.data() ]; |
381 | if (!find ) { | 381 | if (!find ) { |
382 | // qWarning("Unknown option" + it.key() ); | 382 | // qWarning("Unknown option" + it.key() ); |
383 | ev.setCustomField( attr, val ); | 383 | ev.setCustomField( attr, val ); |
384 | return; | 384 | return; |
385 | } | 385 | } |
386 | 386 | ||
387 | switch( *find ) { | 387 | switch( *find ) { |
388 | case OTodo::Uid: | 388 | case OTodo::Uid: |
389 | ev.setUid( val.toInt() ); | 389 | ev.setUid( val.toInt() ); |
390 | break; | 390 | break; |
391 | case OTodo::Category: | 391 | case OTodo::Category: |
392 | ev.setCategories( ev.idsFromString( val ) ); | 392 | ev.setCategories( ev.idsFromString( val ) ); |
393 | break; | 393 | break; |
394 | case OTodo::HasDate: | 394 | case OTodo::HasDate: |
395 | ev.setHasDueDate( val.toInt() ); | 395 | ev.setHasDueDate( val.toInt() ); |
396 | break; | 396 | break; |
397 | case OTodo::Completed: | 397 | case OTodo::Completed: |
398 | ev.setCompleted( val.toInt() ); | 398 | ev.setCompleted( val.toInt() ); |
399 | break; | 399 | break; |
400 | case OTodo::Description: | 400 | case OTodo::Description: |
401 | ev.setDescription( val ); | 401 | ev.setDescription( val ); |
402 | break; | 402 | break; |
403 | case OTodo::Summary: | 403 | case OTodo::Summary: |
404 | ev.setSummary( val ); | 404 | ev.setSummary( val ); |
405 | break; | 405 | break; |
406 | case OTodo::Priority: | 406 | case OTodo::Priority: |
407 | ev.setPriority( val.toInt() ); | 407 | ev.setPriority( val.toInt() ); |
408 | break; | 408 | break; |
409 | case OTodo::DateDay: | 409 | case OTodo::DateDay: |
410 | m_day = val.toInt(); | 410 | m_day = val.toInt(); |
411 | break; | 411 | break; |
412 | case OTodo::DateMonth: | 412 | case OTodo::DateMonth: |
413 | m_month = val.toInt(); | 413 | m_month = val.toInt(); |
414 | break; | 414 | break; |
415 | case OTodo::DateYear: | 415 | case OTodo::DateYear: |
416 | m_year = val.toInt(); | 416 | m_year = val.toInt(); |
417 | break; | 417 | break; |
418 | case OTodo::Progress: | 418 | case OTodo::Progress: |
419 | ev.setProgress( val.toInt() ); | 419 | ev.setProgress( val.toInt() ); |
420 | break; | 420 | break; |
421 | case OTodo::CompletedDate: | 421 | case OTodo::CompletedDate: |
422 | ev.setCompletedDate( OConversion::dateFromString( val ) ); | 422 | ev.setCompletedDate( OConversion::dateFromString( val ) ); |
423 | break; | 423 | break; |
424 | case OTodo::StartDate: | 424 | case OTodo::StartDate: |
425 | ev.setStartDate( OConversion::dateFromString( val ) ); | 425 | ev.setStartDate( OConversion::dateFromString( val ) ); |
426 | break; | 426 | break; |
427 | case OTodo::State: | 427 | case OTodo::State: |
428 | ev.setState( val.toInt() ); | 428 | ev.setState( val.toInt() ); |
429 | break; | 429 | break; |
430 | case OTodo::Alarms:{ | 430 | case OTodo::Alarms:{ |
431 | OPimNotifyManager &manager = ev.notifiers(); | 431 | OPimNotifyManager &manager = ev.notifiers(); |
432 | QStringList als = QStringList::split(";", val ); | 432 | QStringList als = QStringList::split(";", val ); |
433 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | 433 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { |
434 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 434 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty |
435 | qWarning("alarm: %s", alarm.join("___").latin1() ); | 435 | qWarning("alarm: %s", alarm.join("___").latin1() ); |
436 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); | 436 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); |
437 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); | 437 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); |
438 | manager.add( al ); | 438 | manager.add( al ); |
439 | } | 439 | } |
440 | } | 440 | } |
441 | break; | 441 | break; |
442 | case OTodo::Reminders:{ | 442 | case OTodo::Reminders:{ |
443 | OPimNotifyManager &manager = ev.notifiers(); | 443 | OPimNotifyManager &manager = ev.notifiers(); |
444 | QStringList rems = QStringList::split(";", val ); | 444 | QStringList rems = QStringList::split(";", val ); |
445 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | 445 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { |
446 | OPimReminder rem( (*it).toInt() ); | 446 | OPimReminder rem( (*it).toInt() ); |
447 | manager.add( rem ); | 447 | manager.add( rem ); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | break; | 450 | break; |
451 | case OTodo::CrossReference: | 451 | case OTodo::CrossReference: |
452 | { | 452 | { |
453 | /* | 453 | /* |
454 | * A cross refernce looks like | 454 | * A cross refernce looks like |
455 | * appname,id;appname,id | 455 | * appname,id;appname,id |
456 | * we need to split it up | 456 | * we need to split it up |
457 | */ | 457 | */ |
458 | QStringList refs = QStringList::split(';', val ); | 458 | QStringList refs = QStringList::split(';', val ); |
459 | QStringList::Iterator strIt; | 459 | QStringList::Iterator strIt; |
460 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 460 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
461 | int pos = (*strIt).find(','); | 461 | int pos = (*strIt).find(','); |
462 | if ( pos > -1 ) | 462 | if ( pos > -1 ) |
463 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 463 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
464 | 464 | ||
465 | } | 465 | } |
466 | break; | 466 | break; |
467 | } | 467 | } |
468 | /* Recurrence stuff below + post processing later */ | 468 | /* Recurrence stuff below + post processing later */ |
469 | case FRType: | 469 | case FRType: |
470 | if ( val == "Daily" ) | 470 | if ( val == "Daily" ) |
471 | recur()->setType( ORecur::Daily ); | 471 | recur()->setType( ORecur::Daily ); |
472 | else if ( val == "Weekly" ) | 472 | else if ( val == "Weekly" ) |
473 | recur()->setType( ORecur::Weekly); | 473 | recur()->setType( ORecur::Weekly); |
474 | else if ( val == "MonthlyDay" ) | 474 | else if ( val == "MonthlyDay" ) |
475 | recur()->setType( ORecur::MonthlyDay ); | 475 | recur()->setType( ORecur::MonthlyDay ); |
476 | else if ( val == "MonthlyDate" ) | 476 | else if ( val == "MonthlyDate" ) |
477 | recur()->setType( ORecur::MonthlyDate ); | 477 | recur()->setType( ORecur::MonthlyDate ); |
478 | else if ( val == "Yearly" ) | 478 | else if ( val == "Yearly" ) |
479 | recur()->setType( ORecur::Yearly ); | 479 | recur()->setType( ORecur::Yearly ); |
480 | else | 480 | else |
481 | recur()->setType( ORecur::NoRepeat ); | 481 | recur()->setType( ORecur::NoRepeat ); |
482 | break; | 482 | break; |
483 | case FRWeekdays: | 483 | case FRWeekdays: |
484 | recur()->setDays( val.toInt() ); | 484 | recur()->setDays( val.toInt() ); |
485 | break; | 485 | break; |
486 | case FRPosition: | 486 | case FRPosition: |
487 | recur()->setPosition( val.toInt() ); | 487 | recur()->setPosition( val.toInt() ); |
488 | break; | 488 | break; |
489 | case FRFreq: | 489 | case FRFreq: |
490 | recur()->setFrequency( val.toInt() ); | 490 | recur()->setFrequency( val.toInt() ); |
491 | break; | 491 | break; |
492 | case FRHasEndDate: | 492 | case FRHasEndDate: |
493 | recur()->setHasEndDate( val.toInt() ); | 493 | recur()->setHasEndDate( val.toInt() ); |
494 | break; | 494 | break; |
495 | case FREndDate: { | 495 | case FREndDate: { |
496 | rp_end = (time_t) val.toLong(); | 496 | rp_end = (time_t) val.toLong(); |
497 | break; | 497 | break; |
498 | } | 498 | } |
499 | default: | 499 | default: |
500 | ev.setCustomField( attr, val ); | 500 | ev.setCustomField( attr, val ); |
501 | break; | 501 | break; |
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
505 | // from PalmtopRecord... GPL ### FIXME | 505 | // from PalmtopRecord... GPL ### FIXME |
506 | namespace { | 506 | namespace { |
507 | QString customToXml(const QMap<QString, QString>& customMap ) | 507 | QString customToXml(const QMap<QString, QString>& customMap ) |
508 | { | 508 | { |
509 | //qWarning(QString("writing custom %1").arg(customMap.count())); | 509 | //qWarning(QString("writing custom %1").arg(customMap.count())); |
510 | QString buf(" "); | 510 | QString buf(" "); |
511 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); | 511 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); |
512 | cit != customMap.end(); ++cit) { | 512 | cit != customMap.end(); ++cit) { |
513 | // qWarning(".ITEM."); | 513 | // qWarning(".ITEM."); |
514 | buf += cit.key(); | 514 | buf += cit.key(); |
515 | buf += "=\""; | 515 | buf += "=\""; |
516 | buf += Qtopia::escapeString(cit.data()); | 516 | buf += Qtopia::escapeString(cit.data()); |
517 | buf += "\" "; | 517 | buf += "\" "; |
518 | } | 518 | } |
519 | return buf; | 519 | return buf; |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | } | 523 | } |
524 | 524 | ||
525 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 525 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
526 | QString str; | 526 | QString str; |
527 | 527 | ||
528 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 528 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
529 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 529 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
530 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 530 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
531 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 531 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
532 | 532 | ||
533 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 533 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
534 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 534 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
535 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 535 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
536 | 536 | ||
537 | if ( ev.hasDueDate() ) { | 537 | if ( ev.hasDueDate() ) { |
538 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 538 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
539 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 539 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
540 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 540 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
541 | } | 541 | } |
542 | // qWarning( "Uid %d", ev.uid() ); | 542 | // qWarning( "Uid %d", ev.uid() ); |
543 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 543 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
544 | 544 | ||
545 | // append the extra options | 545 | // append the extra options |
546 | /* FIXME Qtopia::Record this is currently not | 546 | /* FIXME Qtopia::Record this is currently not |
547 | * possible you can set custom fields | 547 | * possible you can set custom fields |
548 | * but don' iterate over the list | 548 | * but don' iterate over the list |
549 | * I may do #define private protected | 549 | * I may do #define private protected |
550 | * for this case - cough --zecke | 550 | * for this case - cough --zecke |
551 | */ | 551 | */ |
552 | /* | 552 | /* |
553 | QMap<QString, QString> extras = ev.extras(); | 553 | QMap<QString, QString> extras = ev.extras(); |
554 | QMap<QString, QString>::Iterator extIt; | 554 | QMap<QString, QString>::Iterator extIt; |
555 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 555 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
556 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 556 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
557 | */ | 557 | */ |
558 | // cross refernce | 558 | // cross refernce |
559 | if ( ev.hasRecurrence() ) { | 559 | if ( ev.hasRecurrence() ) { |
560 | str += ev.recurrence().toString(); | 560 | str += ev.recurrence().toString(); |
561 | } | 561 | } |
562 | if ( ev.hasStartDate() ) | 562 | if ( ev.hasStartDate() ) |
563 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; | 563 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; |
564 | if ( ev.hasCompletedDate() ) | 564 | if ( ev.hasCompletedDate() ) |
565 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; | 565 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; |
566 | if ( ev.hasState() ) | 566 | if ( ev.hasState() ) |
567 | str += "State=\""+QString::number( ev.state().state() )+"\" "; | 567 | str += "State=\""+QString::number( ev.state().state() )+"\" "; |
568 | 568 | ||
569 | /* | 569 | /* |
570 | * save reminders and notifiers! | 570 | * save reminders and notifiers! |
571 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... | 571 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... |
572 | */ | 572 | */ |
573 | if ( ev.hasNotifiers() ) { | 573 | if ( ev.hasNotifiers() ) { |
574 | OPimNotifyManager manager = ev.notifiers(); | 574 | OPimNotifyManager manager = ev.notifiers(); |
575 | OPimNotifyManager::Alarms alarms = manager.alarms(); | 575 | OPimNotifyManager::Alarms alarms = manager.alarms(); |
576 | if (!alarms.isEmpty() ) { | 576 | if (!alarms.isEmpty() ) { |
577 | QStringList als; | 577 | QStringList als; |
578 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 578 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
579 | for ( ; it != alarms.end(); ++it ) { | 579 | for ( ; it != alarms.end(); ++it ) { |
580 | /* only if time is valid */ | 580 | /* only if time is valid */ |
581 | if ( (*it).dateTime().isValid() ) { | 581 | if ( (*it).dateTime().isValid() ) { |
582 | als << OConversion::dateTimeToString( (*it).dateTime() ) | 582 | als << OConversion::dateTimeToString( (*it).dateTime() ) |
583 | + ":" + QString::number( (*it).duration() ) | 583 | + ":" + QString::number( (*it).duration() ) |
584 | + ":" + QString::number( (*it).sound() ) | 584 | + ":" + QString::number( (*it).sound() ) |
585 | + ":"; | 585 | + ":"; |
586 | } | 586 | } |
587 | } | 587 | } |
588 | // now write the list | 588 | // now write the list |
589 | qWarning("als: %s", als.join("____________").latin1() ); | 589 | qWarning("als: %s", als.join("____________").latin1() ); |
590 | str += "Alarms=\""+als.join(";") +"\" "; | 590 | str += "Alarms=\""+als.join(";") +"\" "; |
591 | } | 591 | } |
592 | 592 | ||
593 | /* | 593 | /* |
594 | * now the same for reminders but more easy. We just save the uid of the OEvent. | 594 | * now the same for reminders but more easy. We just save the uid of the OEvent. |
595 | */ | 595 | */ |
596 | OPimNotifyManager::Reminders reminders = manager.reminders(); | 596 | OPimNotifyManager::Reminders reminders = manager.reminders(); |
597 | if (!reminders.isEmpty() ) { | 597 | if (!reminders.isEmpty() ) { |
598 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 598 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
599 | QStringList records; | 599 | QStringList records; |
600 | for ( ; it != reminders.end(); ++it ) { | 600 | for ( ; it != reminders.end(); ++it ) { |
601 | records << QString::number( (*it).recordUid() ); | 601 | records << QString::number( (*it).recordUid() ); |
602 | } | 602 | } |
603 | str += "Reminders=\""+ records.join(";") +"\" "; | 603 | str += "Reminders=\""+ records.join(";") +"\" "; |
604 | } | 604 | } |
605 | } | 605 | } |
606 | str += customToXml( ev.toExtraMap() ); | 606 | str += customToXml( ev.toExtraMap() ); |
607 | 607 | ||
608 | 608 | ||
609 | return str; | 609 | return str; |
610 | } | 610 | } |
611 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 611 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
612 | return Qtopia::Record::idsToString( ints ); | 612 | return Qtopia::Record::idsToString( ints ); |
613 | } | 613 | } |
614 | 614 | ||
615 | /* internal class for sorting | 615 | /* internal class for sorting |
616 | * | 616 | * |
617 | * Inspired by todoxmlio.cpp from TT | 617 | * Inspired by todoxmlio.cpp from TT |
618 | */ | 618 | */ |
619 | 619 | ||
620 | struct OTodoXMLContainer { | 620 | struct OTodoXMLContainer { |
621 | OTodo todo; | 621 | OTodo todo; |
622 | }; | 622 | }; |
623 | 623 | ||
624 | namespace { | 624 | namespace { |
625 | inline QString string( const OTodo& todo) { | 625 | inline QString string( const OTodo& todo) { |
626 | return todo.summary().isEmpty() ? | 626 | return todo.summary().isEmpty() ? |
627 | todo.description().left(20 ) : | 627 | todo.description().left(20 ) : |
628 | todo.summary(); | 628 | todo.summary(); |
629 | } | 629 | } |
630 | inline int completed( const OTodo& todo1, const OTodo& todo2) { | 630 | inline int completed( const OTodo& todo1, const OTodo& todo2) { |
631 | int ret = 0; | 631 | int ret = 0; |
632 | if ( todo1.isCompleted() ) ret++; | 632 | if ( todo1.isCompleted() ) ret++; |
633 | if ( todo2.isCompleted() ) ret--; | 633 | if ( todo2.isCompleted() ) ret--; |
634 | return ret; | 634 | return ret; |
635 | } | 635 | } |
636 | inline int priority( const OTodo& t1, const OTodo& t2) { | 636 | inline int priority( const OTodo& t1, const OTodo& t2) { |
637 | return ( t1.priority() - t2.priority() ); | 637 | return ( t1.priority() - t2.priority() ); |
638 | } | 638 | } |
639 | inline int description( const OTodo& t1, const OTodo& t2) { | 639 | inline int description( const OTodo& t1, const OTodo& t2) { |
640 | return QString::compare( string(t1), string(t2) ); | 640 | return QString::compare( string(t1), string(t2) ); |
641 | } | 641 | } |
642 | inline int deadline( const OTodo& t1, const OTodo& t2) { | 642 | inline int deadline( const OTodo& t1, const OTodo& t2) { |
643 | int ret = 0; | 643 | int ret = 0; |
644 | if ( t1.hasDueDate() && | 644 | if ( t1.hasDueDate() && |
645 | t2.hasDueDate() ) | 645 | t2.hasDueDate() ) |
646 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 646 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
647 | else if ( t1.hasDueDate() ) | 647 | else if ( t1.hasDueDate() ) |
648 | ret = -1; | 648 | ret = -1; |
649 | else if ( t2.hasDueDate() ) | 649 | else if ( t2.hasDueDate() ) |
650 | ret = 1; | 650 | ret = 1; |
651 | else | 651 | else |
652 | ret = 0; | 652 | ret = 0; |
653 | 653 | ||
654 | return ret; | 654 | return ret; |
655 | } | 655 | } |
656 | 656 | ||
657 | }; | 657 | }; |
658 | 658 | ||
659 | /* | 659 | /* |
660 | * Returns: | 660 | * Returns: |
661 | * 0 if item1 == item2 | 661 | * 0 if item1 == item2 |
662 | * | 662 | * |
663 | * non-zero if item1 != item2 | 663 | * non-zero if item1 != item2 |
664 | * | 664 | * |
665 | * This function returns int rather than bool so that reimplementations | 665 | * This function returns int rather than bool so that reimplementations |
666 | * can return one of three values and use it to sort by: | 666 | * can return one of three values and use it to sort by: |
667 | * | 667 | * |
668 | * 0 if item1 == item2 | 668 | * 0 if item1 == item2 |
669 | * | 669 | * |
670 | * > 0 (positive integer) if item1 > item2 | 670 | * > 0 (positive integer) if item1 > item2 |
671 | * | 671 | * |
672 | * < 0 (negative integer) if item1 < item2 | 672 | * < 0 (negative integer) if item1 < item2 |
673 | * | 673 | * |
674 | */ | 674 | */ |
675 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | 675 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { |
676 | public: | 676 | public: |
677 | OTodoXMLVector(int size, bool asc, int sort) | 677 | OTodoXMLVector(int size, bool asc, int sort) |
678 | : QVector<OTodoXMLContainer>( size ) | 678 | : QVector<OTodoXMLContainer>( size ) |
679 | { | 679 | { |
680 | setAutoDelete( true ); | 680 | setAutoDelete( true ); |
681 | m_asc = asc; | 681 | m_asc = asc; |
682 | m_sort = sort; | 682 | m_sort = sort; |
683 | } | 683 | } |
684 | /* return the summary/description */ | 684 | /* return the summary/description */ |
685 | QString string( const OTodo& todo) { | 685 | QString string( const OTodo& todo) { |
686 | return todo.summary().isEmpty() ? | 686 | return todo.summary().isEmpty() ? |
687 | todo.description().left(20 ) : | 687 | todo.description().left(20 ) : |
688 | todo.summary(); | 688 | todo.summary(); |
689 | } | 689 | } |
690 | /** | 690 | /** |
691 | * we take the sortorder( switch on it ) | 691 | * we take the sortorder( switch on it ) |
692 | * | 692 | * |
693 | */ | 693 | */ |
694 | int compareItems( Item d1, Item d2 ) { | 694 | int compareItems( Item d1, Item d2 ) { |
695 | bool seComp, sePrio, seDesc, seDeadline; | 695 | bool seComp, sePrio, seDesc, seDeadline; |
696 | seComp = sePrio = seDeadline = seDesc = false; | 696 | seComp = sePrio = seDeadline = seDesc = false; |
697 | int ret =0; | 697 | int ret =0; |
698 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | 698 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; |
699 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | 699 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; |
700 | 700 | ||
701 | /* same item */ | 701 | /* same item */ |
702 | if ( con1->todo.uid() == con2->todo.uid() ) | 702 | if ( con1->todo.uid() == con2->todo.uid() ) |
703 | return 0; | 703 | return 0; |
704 | 704 | ||
705 | switch ( m_sort ) { | 705 | switch ( m_sort ) { |
706 | /* completed */ | 706 | /* completed */ |
707 | case 0: { | 707 | case 0: { |
708 | ret = completed( con1->todo, con2->todo ); | 708 | ret = completed( con1->todo, con2->todo ); |
709 | seComp = TRUE; | 709 | seComp = TRUE; |
710 | break; | 710 | break; |
711 | } | 711 | } |
712 | /* priority */ | 712 | /* priority */ |
713 | case 1: { | 713 | case 1: { |
714 | ret = priority( con1->todo, con2->todo ); | 714 | ret = priority( con1->todo, con2->todo ); |
715 | sePrio = TRUE; | 715 | sePrio = TRUE; |
716 | break; | 716 | break; |
717 | } | 717 | } |
718 | /* description */ | 718 | /* description */ |
719 | case 2: { | 719 | case 2: { |
720 | ret = description( con1->todo, con2->todo ); | 720 | ret = description( con1->todo, con2->todo ); |
721 | seDesc = TRUE; | 721 | seDesc = TRUE; |
722 | break; | 722 | break; |
723 | } | 723 | } |
724 | /* deadline */ | 724 | /* deadline */ |
725 | case 3: { | 725 | case 3: { |
726 | ret = deadline( con1->todo, con2->todo ); | 726 | ret = deadline( con1->todo, con2->todo ); |
727 | seDeadline = TRUE; | 727 | seDeadline = TRUE; |
728 | break; | 728 | break; |
729 | } | 729 | } |
730 | default: | 730 | default: |
731 | ret = 0; | 731 | ret = 0; |
732 | break; | 732 | break; |
733 | }; | 733 | }; |
734 | /* | 734 | /* |
735 | * FIXME do better sorting if the first sort criteria | 735 | * FIXME do better sorting if the first sort criteria |
736 | * ret equals 0 start with complete and so on... | 736 | * ret equals 0 start with complete and so on... |
737 | */ | 737 | */ |
738 | 738 | ||
739 | /* twist it we're not ascending*/ | 739 | /* twist it we're not ascending*/ |
740 | if (!m_asc) | 740 | if (!m_asc) |
741 | ret = ret * -1; | 741 | ret = ret * -1; |
742 | 742 | ||
743 | if ( ret ) | 743 | if ( ret ) |
744 | return ret; | 744 | return ret; |
745 | 745 | ||
746 | // default did not gave difference let's try it other way around | 746 | // default did not gave difference let's try it other way around |
747 | /* | 747 | /* |
748 | * General try if already checked if not test | 748 | * General try if already checked if not test |
749 | * and return | 749 | * and return |
750 | * 1.Completed | 750 | * 1.Completed |
751 | * 2.Priority | 751 | * 2.Priority |
752 | * 3.Description | 752 | * 3.Description |
753 | * 4.DueDate | 753 | * 4.DueDate |
754 | */ | 754 | */ |
755 | if (!seComp ) { | 755 | if (!seComp ) { |
756 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { | 756 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { |
757 | if (!m_asc ) ret *= -1; | 757 | if (!m_asc ) ret *= -1; |
758 | return ret; | 758 | return ret; |
759 | } | 759 | } |
760 | } | 760 | } |
761 | if (!sePrio ) { | 761 | if (!sePrio ) { |
762 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { | 762 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { |
763 | if (!m_asc ) ret *= -1; | 763 | if (!m_asc ) ret *= -1; |
764 | return ret; | 764 | return ret; |
765 | } | 765 | } |
766 | } | 766 | } |
767 | if (!seDesc ) { | 767 | if (!seDesc ) { |
768 | if ( (ret = description(con1->todo, con2->todo ) ) ) { | 768 | if ( (ret = description(con1->todo, con2->todo ) ) ) { |
769 | if (!m_asc) ret *= -1; | 769 | if (!m_asc) ret *= -1; |
770 | return ret; | 770 | return ret; |
771 | } | 771 | } |
772 | } | 772 | } |
773 | if (!seDeadline) { | 773 | if (!seDeadline) { |
774 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { | 774 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { |
775 | if (!m_asc) ret *= -1; | 775 | if (!m_asc) ret *= -1; |
776 | return ret; | 776 | return ret; |
777 | } | 777 | } |
778 | } | 778 | } |
779 | 779 | ||
780 | return 0; | 780 | return 0; |
781 | } | 781 | } |
782 | private: | 782 | private: |
783 | bool m_asc; | 783 | bool m_asc; |
784 | int m_sort; | 784 | int m_sort; |
785 | 785 | ||
786 | }; | 786 | }; |
787 | 787 | ||
788 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | 788 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, |
789 | int sortFilter, int cat ) { | 789 | int sortFilter, int cat ) { |
790 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | 790 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); |
791 | QMap<int, OTodo>::Iterator it; | 791 | QMap<int, OTodo>::Iterator it; |
792 | int item = 0; | 792 | int item = 0; |
793 | 793 | ||
794 | bool bCat = sortFilter & 1 ? true : false; | 794 | bool bCat = sortFilter & 1 ? true : false; |
795 | bool bOnly = sortFilter & 2 ? true : false; | 795 | bool bOnly = sortFilter & 2 ? true : false; |
796 | bool comp = sortFilter & 4 ? true : false; | 796 | bool comp = sortFilter & 4 ? true : false; |
797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
798 | 798 | ||
799 | /* show category */ | 799 | /* show category */ |
800 | /* -1 == unfiled */ | 800 | /* -1 == unfiled */ |
801 | if ( bCat && cat == -1 ) { | 801 | if ( bCat && cat == -1 ) { |
802 | if(!(*it).categories().isEmpty() ) | 802 | if(!(*it).categories().isEmpty() ) |
803 | continue; | 803 | continue; |
804 | }else if ( bCat && cat != 0) | 804 | }else if ( bCat && cat != 0) |
805 | if (!(*it).categories().contains( cat ) ) { | 805 | if (!(*it).categories().contains( cat ) ) { |
806 | continue; | 806 | continue; |
807 | } | 807 | } |
808 | /* isOverdue but we should not show overdue - why?*/ | 808 | /* isOverdue but we should not show overdue - why?*/ |
809 | /* if ( (*it).isOverdue() && !bOnly ) { | 809 | /* if ( (*it).isOverdue() && !bOnly ) { |
810 | qWarning("item is overdue but !bOnly"); | 810 | qWarning("item is overdue but !bOnly"); |
811 | continue; | 811 | continue; |
812 | } | 812 | } |
813 | */ | 813 | */ |
814 | if ( !(*it).isOverdue() && bOnly ) { | 814 | if ( !(*it).isOverdue() && bOnly ) { |
815 | continue; | 815 | continue; |
816 | } | 816 | } |
817 | 817 | ||
818 | if ((*it).isCompleted() && comp ) { | 818 | if ((*it).isCompleted() && comp ) { |
819 | continue; | 819 | continue; |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | OTodoXMLContainer* con = new OTodoXMLContainer(); | 823 | OTodoXMLContainer* con = new OTodoXMLContainer(); |
824 | con->todo = (*it); | 824 | con->todo = (*it); |
825 | vector.insert(item, con ); | 825 | vector.insert(item, con ); |
826 | item++; | 826 | item++; |
827 | } | 827 | } |
828 | vector.resize( item ); | 828 | vector.resize( item ); |
829 | /* sort it now */ | 829 | /* sort it now */ |
830 | vector.sort(); | 830 | vector.sort(); |
831 | /* now get the uids */ | 831 | /* now get the uids */ |
832 | QArray<int> array( vector.count() ); | 832 | QArray<int> array( vector.count() ); |
833 | for (uint i= 0; i < vector.count(); i++ ) { | 833 | for (uint i= 0; i < vector.count(); i++ ) { |
834 | array[i] = ( vector.at(i) )->todo.uid(); | 834 | array[i] = ( vector.at(i) )->todo.uid(); |
835 | } | 835 | } |
836 | return array; | 836 | return array; |
837 | }; | 837 | }; |
838 | void OTodoAccessXML::removeAllCompleted() { | 838 | void OTodoAccessXML::removeAllCompleted() { |
839 | QMap<int, OTodo> events = m_events; | ||
839 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 840 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
840 | if ( (*it).isCompleted() ) | 841 | if ( (*it).isCompleted() ) |
841 | m_events.remove( it ); | 842 | events.remove( it.key() ); |
842 | } | 843 | } |
844 | m_events = events; | ||
843 | } | 845 | } |
844 | QBitArray OTodoAccessXML::supports()const { | 846 | QBitArray OTodoAccessXML::supports()const { |
845 | static QBitArray ar = sup(); | 847 | static QBitArray ar = sup(); |
846 | return ar; | 848 | return ar; |
847 | } | 849 | } |
848 | QBitArray OTodoAccessXML::sup() { | 850 | QBitArray OTodoAccessXML::sup() { |
849 | QBitArray ar( OTodo::CompletedDate +1 ); | 851 | QBitArray ar( OTodo::CompletedDate +1 ); |
850 | ar.fill( true ); | 852 | ar.fill( true ); |
851 | ar[OTodo::CrossReference] = false; | 853 | ar[OTodo::CrossReference] = false; |
852 | ar[OTodo::State ] = false; | 854 | ar[OTodo::State ] = false; |
853 | ar[OTodo::Reminders] = false; | 855 | ar[OTodo::Reminders] = false; |
854 | ar[OTodo::Notifiers] = false; | 856 | ar[OTodo::Notifiers] = false; |
855 | ar[OTodo::Maintainer] = false; | 857 | ar[OTodo::Maintainer] = false; |
856 | 858 | ||
857 | return ar; | 859 | return ar; |
858 | } | 860 | } |
859 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const | 861 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const |
860 | { | 862 | { |
861 | QArray<int> m_currentQuery( m_events.count() ); | 863 | QArray<int> m_currentQuery( m_events.count() ); |
862 | uint arraycounter = 0; | 864 | uint arraycounter = 0; |
863 | 865 | ||
864 | QMap<int, OTodo>::ConstIterator it; | 866 | QMap<int, OTodo>::ConstIterator it; |
865 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 867 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
866 | if ( it.data().match( r ) ) | 868 | if ( it.data().match( r ) ) |
867 | m_currentQuery[arraycounter++] = it.data().uid(); | 869 | m_currentQuery[arraycounter++] = it.data().uid(); |
868 | 870 | ||
869 | } | 871 | } |
870 | // Shrink to fit.. | 872 | // Shrink to fit.. |
871 | m_currentQuery.resize(arraycounter); | 873 | m_currentQuery.resize(arraycounter); |
872 | 874 | ||
873 | return m_currentQuery; | 875 | return m_currentQuery; |
874 | } | 876 | } |
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index ad6cf5a..f3c339d 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,154 +1,166 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | * Class to manage Backends. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; | 9 | * License as published by the Free Software Foundation; |
10 | * either version 2 of the License, or (at your option) any later | 10 | * either version 2 of the License, or (at your option) any later |
11 | * version. | 11 | * version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: Use plugins | 13 | * ToDo: Use plugins |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * Version: $Id$ | 15 | * Version: $Id$ |
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
20 | * Merging changes from BRANCH_1_0 to HEAD | ||
21 | * | ||
22 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers | ||
23 | * Patches from Zecke: | ||
24 | * Fixing and cleaning up extraMap handling | ||
25 | * Adding d_ptr for binary compatibility in the future | ||
26 | * | ||
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | 27 | * Revision 1.6 2003/04/13 18:07:10 zecke |
20 | * More API doc | 28 | * More API doc |
21 | * QString -> const QString& | 29 | * QString -> const QString& |
22 | * QString = 0l -> QString::null | 30 | * QString = 0l -> QString::null |
23 | * | 31 | * |
24 | * Revision 1.5 2003/02/21 23:31:52 zecke | 32 | * Revision 1.5 2003/02/21 23:31:52 zecke |
25 | * Add XML datebookresource | 33 | * Add XML datebookresource |
26 | * -clean up todoaccessxml header | 34 | * -clean up todoaccessxml header |
27 | * -implement some more stuff in the oeven tester | 35 | * -implement some more stuff in the oeven tester |
28 | * -extend DefaultFactory to not crash and to use datebook | 36 | * -extend DefaultFactory to not crash and to use datebook |
29 | * | 37 | * |
30 | * -reading of OEvents is working nicely.. saving will be added | 38 | * -reading of OEvents is working nicely.. saving will be added |
31 | * tomorrow | 39 | * tomorrow |
32 | * -fix spelling in ODateBookAcces | 40 | * -fix spelling in ODateBookAcces |
33 | * | 41 | * |
34 | * Revision 1.4 2002/10/14 15:55:18 eilers | 42 | * Revision 1.4 2002/10/14 15:55:18 eilers |
35 | * Redeactivate SQL.. ;) | 43 | * Redeactivate SQL.. ;) |
36 | * | 44 | * |
37 | * Revision 1.3 2002/10/10 17:08:58 zecke | 45 | * Revision 1.3 2002/10/10 17:08:58 zecke |
38 | * The Cache is finally in place | 46 | * The Cache is finally in place |
39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 47 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
40 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... | 48 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... |
41 | * I still have to fully implement read ahead | 49 | * I still have to fully implement read ahead |
42 | * This change is bic but sc | 50 | * This change is bic but sc |
43 | * | 51 | * |
44 | * Revision 1.2 2002/10/08 09:27:36 eilers | 52 | * Revision 1.2 2002/10/08 09:27:36 eilers |
45 | * Fixed libopie.pro to include the new pim-API. | 53 | * Fixed libopie.pro to include the new pim-API. |
46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 54 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
47 | * compile itself would need to install libsqlite, libopiesql... | 55 | * compile itself would need to install libsqlite, libopiesql... |
48 | * Therefore, the backend currently uses XML only.. | 56 | * Therefore, the backend currently uses XML only.. |
49 | * | 57 | * |
50 | * Revision 1.1 2002/10/07 17:35:01 eilers | 58 | * Revision 1.1 2002/10/07 17:35:01 eilers |
51 | * added OBackendFactory for advanced backend access | 59 | * added OBackendFactory for advanced backend access |
52 | * | 60 | * |
53 | * | 61 | * |
54 | * ===================================================================== | 62 | * ===================================================================== |
55 | */ | 63 | */ |
56 | #ifndef OPIE_BACKENDFACTORY_H_ | 64 | #ifndef OPIE_BACKENDFACTORY_H_ |
57 | #define OPIE_BACKENDFACTORY_H_ | 65 | #define OPIE_BACKENDFACTORY_H_ |
58 | 66 | ||
59 | #include <qstring.h> | 67 | #include <qstring.h> |
60 | #include <qasciidict.h> | 68 | #include <qasciidict.h> |
61 | #include <qpe/config.h> | 69 | #include <qpe/config.h> |
62 | 70 | ||
63 | #include "otodoaccessxml.h" | 71 | #include "otodoaccessxml.h" |
64 | #include "ocontactaccessbackend_xml.h" | 72 | #include "ocontactaccessbackend_xml.h" |
65 | #include "odatebookaccessbackend_xml.h" | 73 | #include "odatebookaccessbackend_xml.h" |
66 | 74 | ||
67 | #ifdef __USE_SQL | 75 | #ifdef __USE_SQL |
68 | #include "otodoaccesssql.h" | 76 | #include "otodoaccesssql.h" |
69 | #endif | 77 | #endif |
70 | 78 | ||
79 | class OBackendPrivate; | ||
80 | |||
71 | /** | 81 | /** |
72 | * This class is our factory. It will give us the default implementations | 82 | * This class is our factory. It will give us the default implementations |
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | 83 | * of at least Todolist, Contacts and Datebook. In the future this class will |
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | 84 | * allow users to switch the backend with ( XML->SQLite ) without the need |
75 | * to recompile.# | 85 | * to recompile.# |
76 | * This class as the whole PIM Api is making use of templates | 86 | * This class as the whole PIM Api is making use of templates |
77 | * | 87 | * |
78 | * <pre> | 88 | * <pre> |
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | 89 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); |
80 | * backend->load(); | 90 | * backend->load(); |
81 | * </pre> | 91 | * </pre> |
82 | * | 92 | * |
83 | * @author Stefan Eilers | 93 | * @author Stefan Eilers |
84 | * @version 0.1 | 94 | * @version 0.1 |
85 | */ | 95 | */ |
86 | template<class T> | 96 | template<class T> |
87 | class OBackendFactory | 97 | class OBackendFactory |
88 | { | 98 | { |
89 | public: | 99 | public: |
90 | OBackendFactory() {}; | 100 | OBackendFactory() {}; |
91 | 101 | ||
92 | enum BACKENDS { | 102 | enum BACKENDS { |
93 | TODO, | 103 | TODO, |
94 | CONTACT, | 104 | CONTACT, |
95 | DATE | 105 | DATE |
96 | }; | 106 | }; |
97 | 107 | ||
98 | /** | 108 | /** |
99 | * Returns a backend implementation for backendName | 109 | * Returns a backend implementation for backendName |
100 | * @param backendName the type of the backend | 110 | * @param backendName the type of the backend |
101 | * @param appName will be passed on to the backend | 111 | * @param appName will be passed on to the backend |
102 | */ | 112 | */ |
103 | static T* Default( const QString backendName, const QString& appName ){ | 113 | static T* Default( const QString backendName, const QString& appName ){ |
104 | 114 | ||
105 | // __asm__("int3"); | 115 | // __asm__("int3"); |
106 | 116 | ||
107 | Config config( "pimaccess" ); | 117 | Config config( "pimaccess" ); |
108 | config.setGroup ( backendName ); | 118 | config.setGroup ( backendName ); |
109 | QString backend = config.readEntry( "usebackend" ); | 119 | QString backend = config.readEntry( "usebackend" ); |
110 | 120 | ||
111 | QAsciiDict<int> dict ( 3 ); | 121 | QAsciiDict<int> dict ( 3 ); |
112 | dict.setAutoDelete ( TRUE ); | 122 | dict.setAutoDelete ( TRUE ); |
113 | 123 | ||
114 | dict.insert( "todo", new int (TODO) ); | 124 | dict.insert( "todo", new int (TODO) ); |
115 | dict.insert( "contact", new int (CONTACT) ); | 125 | dict.insert( "contact", new int (CONTACT) ); |
116 | dict.insert( "datebook", new int(DATE) ); | 126 | dict.insert( "datebook", new int(DATE) ); |
117 | 127 | ||
118 | qWarning ("TODO is: %d", TODO); | 128 | qWarning ("TODO is: %d", TODO); |
119 | qWarning ("CONTACT is: %d", CONTACT); | 129 | qWarning ("CONTACT is: %d", CONTACT); |
120 | 130 | ||
121 | int *find = dict[ backendName ]; | 131 | int *find = dict[ backendName ]; |
122 | if (!find ) return 0; | 132 | if (!find ) return 0; |
123 | 133 | ||
124 | switch ( *find ){ | 134 | switch ( *find ){ |
125 | case TODO: | 135 | case TODO: |
126 | #ifdef __USE_SQL | 136 | #ifdef __USE_SQL |
127 | if ( backend == "sql" ) | 137 | if ( backend == "sql" ) |
128 | return (T*) new OTodoAccessBackendSQL(""); | 138 | return (T*) new OTodoAccessBackendSQL(""); |
129 | #else | 139 | #else |
130 | if ( backend == "sql" ) | 140 | if ( backend == "sql" ) |
131 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 141 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
132 | #endif | 142 | #endif |
133 | 143 | ||
134 | return (T*) new OTodoAccessXML( appName ); | 144 | return (T*) new OTodoAccessXML( appName ); |
135 | case CONTACT: | 145 | case CONTACT: |
136 | if ( backend == "sql" ) | 146 | if ( backend == "sql" ) |
137 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 147 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
138 | 148 | ||
139 | return (T*) new OContactAccessBackend_XML( appName ); | 149 | return (T*) new OContactAccessBackend_XML( appName ); |
140 | case DATE: | 150 | case DATE: |
141 | if ( backend == "sql" ) | 151 | if ( backend == "sql" ) |
142 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 152 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
143 | 153 | ||
144 | return (T*) new ODateBookAccessBackend_XML( appName ); | 154 | return (T*) new ODateBookAccessBackend_XML( appName ); |
145 | default: | 155 | default: |
146 | return NULL; | 156 | return NULL; |
147 | } | 157 | } |
148 | 158 | ||
149 | 159 | ||
150 | } | 160 | } |
161 | private: | ||
162 | OBackendPrivate* d; | ||
151 | }; | 163 | }; |
152 | 164 | ||
153 | 165 | ||
154 | #endif | 166 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index ebeb42d..280e05c 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,107 +1,119 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.6 2003/08/01 12:30:16 eilers | ||
23 | * Merging changes from BRANCH_1_0 to HEAD | ||
24 | * | ||
25 | * Revision 1.5.4.1 2003/06/30 14:34:19 eilers | ||
26 | * Patches from Zecke: | ||
27 | * Fixing and cleaning up extraMap handling | ||
28 | * Adding d_ptr for binary compatibility in the future | ||
29 | * | ||
22 | * Revision 1.5 2003/04/13 18:07:10 zecke | 30 | * Revision 1.5 2003/04/13 18:07:10 zecke |
23 | * More API doc | 31 | * More API doc |
24 | * QString -> const QString& | 32 | * QString -> const QString& |
25 | * QString = 0l -> QString::null | 33 | * QString = 0l -> QString::null |
26 | * | 34 | * |
27 | * Revision 1.4 2002/11/13 14:14:51 eilers | 35 | * Revision 1.4 2002/11/13 14:14:51 eilers |
28 | * Added sorted for Contacts.. | 36 | * Added sorted for Contacts.. |
29 | * | 37 | * |
30 | * Revision 1.3 2002/11/01 15:10:42 eilers | 38 | * Revision 1.3 2002/11/01 15:10:42 eilers |
31 | * Added regExp-search in database for all fields in a contact. | 39 | * Added regExp-search in database for all fields in a contact. |
32 | * | 40 | * |
33 | * Revision 1.2 2002/10/07 17:34:24 eilers | 41 | * Revision 1.2 2002/10/07 17:34:24 eilers |
34 | * added OBackendFactory for advanced backend access | 42 | * added OBackendFactory for advanced backend access |
35 | * | 43 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 44 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 45 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 46 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 47 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 48 | * Please read README_COMPILE for compiling ! |
41 | * | 49 | * |
42 | * ===================================================================== | 50 | * ===================================================================== |
43 | * | 51 | * |
44 | */ | 52 | */ |
45 | 53 | ||
46 | #ifndef _OCONTACTACCESSBACKEND_H_ | 54 | #ifndef _OCONTACTACCESSBACKEND_H_ |
47 | #define _OCONTACTACCESSBACKEND_H_ | 55 | #define _OCONTACTACCESSBACKEND_H_ |
48 | 56 | ||
49 | #include "ocontact.h" | 57 | #include "ocontact.h" |
50 | #include "opimaccessbackend.h" | 58 | #include "opimaccessbackend.h" |
51 | 59 | ||
52 | #include <qregexp.h> | 60 | #include <qregexp.h> |
53 | 61 | ||
54 | /** | 62 | /** |
55 | * This class represents the interface of all Contact Backends. | 63 | * This class represents the interface of all Contact Backends. |
56 | * Derivates of this class will be used to access the contacts. | 64 | * Derivates of this class will be used to access the contacts. |
57 | * As implementation currently XML and vCard exist. This class needs to be implemented | 65 | * As implementation currently XML and vCard exist. This class needs to be implemented |
58 | * if you want to provide your own storage. | 66 | * if you want to provide your own storage. |
59 | * In all queries a list of uids is passed on instead of loading the actual record! | 67 | * In all queries a list of uids is passed on instead of loading the actual record! |
60 | * | 68 | * |
61 | * @see OContactAccessBackend_VCard | 69 | * @see OContactAccessBackend_VCard |
62 | * @see OContactAccessBackend_XML | 70 | * @see OContactAccessBackend_XML |
63 | */ | 71 | */ |
64 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 72 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
65 | public: | 73 | public: |
66 | OContactAccessBackend() {} | 74 | OContactAccessBackend() {} |
67 | virtual ~OContactAccessBackend() {} | 75 | virtual ~OContactAccessBackend() {} |
68 | 76 | ||
69 | 77 | ||
70 | /** | 78 | /** |
71 | * Return if database was changed externally. | 79 | * Return if database was changed externally. |
72 | * This may just make sense on file based databases like a XML-File. | 80 | * This may just make sense on file based databases like a XML-File. |
73 | * It is used to prevent to overwrite the current database content | 81 | * It is used to prevent to overwrite the current database content |
74 | * if the file was already changed by something else ! | 82 | * if the file was already changed by something else ! |
75 | * If this happens, we have to reload before save our data. | 83 | * If this happens, we have to reload before save our data. |
76 | * If we use real databases, this should be handled by the database | 84 | * If we use real databases, this should be handled by the database |
77 | * management system themselve, therefore this function should always return false in | 85 | * management system themselve, therefore this function should always return false in |
78 | * this case. It is not our problem to handle this conflict ... | 86 | * this case. It is not our problem to handle this conflict ... |
79 | * @return <i>true</i> if the database was changed and if save without reload will | 87 | * @return <i>true</i> if the database was changed and if save without reload will |
80 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 88 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
81 | * in this situation. | 89 | * in this situation. |
82 | */ | 90 | */ |
83 | virtual bool wasChangedExternally() = 0; | 91 | virtual bool wasChangedExternally() = 0; |
84 | 92 | ||
85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 93 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
86 | 94 | ||
87 | /** | 95 | /** |
88 | * Return all possible settings. | 96 | * Return all possible settings. |
89 | * @return All settings provided by the current backend | 97 | * @return All settings provided by the current backend |
90 | * (i.e.: query_WildCards & query_IgnoreCase) | 98 | * (i.e.: query_WildCards & query_IgnoreCase) |
91 | */ | 99 | */ |
92 | virtual const uint querySettings() = 0; | 100 | virtual const uint querySettings() = 0; |
93 | 101 | ||
94 | /** | 102 | /** |
95 | * Check whether settings are correct. | 103 | * Check whether settings are correct. |
96 | * @return <i>true</i> if the given settings are correct and possible. | 104 | * @return <i>true</i> if the given settings are correct and possible. |
97 | */ | 105 | */ |
98 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 106 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
99 | 107 | ||
100 | /** | 108 | /** |
101 | * FIXME!!! | 109 | * FIXME!!! |
102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | 110 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category |
103 | */ | 111 | */ |
104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 112 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; |
105 | 113 | ||
114 | |||
115 | private: | ||
116 | class Private; | ||
117 | Private *d; | ||
106 | }; | 118 | }; |
107 | #endif | 119 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index 270bef3..b60c5be 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,628 +1,646 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.11 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.10.4.3 2003/07/23 08:54:37 eilers | ||
24 | * Default email was added to the list of all emails, which already contains | ||
25 | * the default email.. | ||
26 | * This closes bug #1045 | ||
27 | * | ||
28 | * Revision 1.10.4.2 2003/07/23 08:44:45 eilers | ||
29 | * Importing of Notes in vcard files wasn't implemented. | ||
30 | * Closes bug #1044 | ||
31 | * | ||
32 | * Revision 1.10.4.1 2003/06/02 13:37:49 eilers | ||
33 | * Fixing memory leak | ||
34 | * | ||
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | 35 | * Revision 1.10 2003/04/13 18:07:10 zecke |
21 | * More API doc | 36 | * More API doc |
22 | * QString -> const QString& | 37 | * QString -> const QString& |
23 | * QString = 0l -> QString::null | 38 | * QString = 0l -> QString::null |
24 | * | 39 | * |
25 | * Revision 1.9 2003/03/21 10:33:09 eilers | 40 | * Revision 1.9 2003/03/21 10:33:09 eilers |
26 | * Merged speed optimized xml backend for contacts to main. | 41 | * Merged speed optimized xml backend for contacts to main. |
27 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 42 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
28 | * all Birthdays/Anniversaries between two dates. This should be used | 43 | * all Birthdays/Anniversaries between two dates. This should be used |
29 | * to show all birthdays in the datebook.. | 44 | * to show all birthdays in the datebook.. |
30 | * This change is sourcecode backward compatible but you have to upgrade | 45 | * This change is sourcecode backward compatible but you have to upgrade |
31 | * the binaries for today-addressbook. | 46 | * the binaries for today-addressbook. |
32 | * | 47 | * |
33 | * Revision 1.8 2003/02/21 16:52:49 zecke | 48 | * Revision 1.8 2003/02/21 16:52:49 zecke |
34 | * -Remove old Todo classes they're deprecated and today I already using the | 49 | * -Remove old Todo classes they're deprecated and today I already using the |
35 | * new API | 50 | * new API |
36 | * -Guard against self assignment in OTodo | 51 | * -Guard against self assignment in OTodo |
37 | * -Add test apps for OPIM | 52 | * -Add test apps for OPIM |
38 | * -Opiefied Event classes | 53 | * -Opiefied Event classes |
39 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 54 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
40 | * -Adjust ORecur and the widget to better timezone behaviour | 55 | * -Adjust ORecur and the widget to better timezone behaviour |
41 | * | 56 | * |
42 | * Revision 1.7 2003/02/16 22:25:46 zecke | 57 | * Revision 1.7 2003/02/16 22:25:46 zecke |
43 | * 0000276 Fix for that bug.. or better temp workaround | 58 | * 0000276 Fix for that bug.. or better temp workaround |
44 | * A Preferred Number is HOME|VOICE | 59 | * A Preferred Number is HOME|VOICE |
45 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | 60 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test |
46 | * triggers both | 61 | * triggers both |
47 | * and the cell phone number overrides the other entries.. | 62 | * and the cell phone number overrides the other entries.. |
48 | * | 63 | * |
49 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 64 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
50 | * number | 65 | * number |
51 | * | 66 | * |
52 | * The right and final fix would be to reorder the if statement to make it | 67 | * The right and final fix would be to reorder the if statement to make it |
53 | * if else based and the less common thing put to the bottom | 68 | * if else based and the less common thing put to the bottom |
54 | * | 69 | * |
55 | * OTodoAccessVcal fix the date for beaming | 70 | * OTodoAccessVcal fix the date for beaming |
56 | * | 71 | * |
57 | * Revision 1.6 2003/01/13 15:49:31 eilers | 72 | * Revision 1.6 2003/01/13 15:49:31 eilers |
58 | * Fixing crash when businesscard.vcf is missing.. | 73 | * Fixing crash when businesscard.vcf is missing.. |
59 | * | 74 | * |
60 | * Revision 1.5 2002/12/07 13:26:22 eilers | 75 | * Revision 1.5 2002/12/07 13:26:22 eilers |
61 | * Fixing bug in storing anniversary.. | 76 | * Fixing bug in storing anniversary.. |
62 | * | 77 | * |
63 | * Revision 1.4 2002/11/13 14:14:51 eilers | 78 | * Revision 1.4 2002/11/13 14:14:51 eilers |
64 | * Added sorted for Contacts.. | 79 | * Added sorted for Contacts.. |
65 | * | 80 | * |
66 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 81 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
67 | * no default arguments in implementation | 82 | * no default arguments in implementation |
68 | * | 83 | * |
69 | * Revision 1.2 2002/11/10 15:41:53 eilers | 84 | * Revision 1.2 2002/11/10 15:41:53 eilers |
70 | * Bugfixes.. | 85 | * Bugfixes.. |
71 | * | 86 | * |
72 | * Revision 1.1 2002/11/09 14:34:52 eilers | 87 | * Revision 1.1 2002/11/09 14:34:52 eilers |
73 | * Added VCard Backend. | 88 | * Added VCard Backend. |
74 | * | 89 | * |
75 | */ | 90 | */ |
76 | #include "ocontactaccessbackend_vcard.h" | 91 | #include "ocontactaccessbackend_vcard.h" |
77 | #include "../../library/backend/vobject_p.h" | 92 | #include "../../library/backend/vobject_p.h" |
78 | #include "../../library/backend/qfiledirect_p.h" | 93 | #include "../../library/backend/qfiledirect_p.h" |
79 | 94 | ||
80 | #include <qpe/timeconversion.h> | 95 | #include <qpe/timeconversion.h> |
81 | 96 | ||
82 | #include <qfile.h> | 97 | #include <qfile.h> |
83 | 98 | ||
84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): | 99 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
85 | m_dirty( false ), | 100 | m_dirty( false ), |
86 | m_file( filename ) | 101 | m_file( filename ) |
87 | { | 102 | { |
88 | load(); | 103 | load(); |
89 | } | 104 | } |
90 | 105 | ||
91 | 106 | ||
92 | bool OContactAccessBackend_VCard::load () | 107 | bool OContactAccessBackend_VCard::load () |
93 | { | 108 | { |
94 | m_map.clear(); | 109 | m_map.clear(); |
95 | m_dirty = false; | 110 | m_dirty = false; |
96 | 111 | ||
97 | VObject* obj = 0l; | 112 | VObject* obj = 0l; |
98 | 113 | ||
99 | if ( QFile::exists(m_file) ){ | 114 | if ( QFile::exists(m_file) ){ |
100 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 115 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
101 | if ( !obj ) | 116 | if ( !obj ) |
102 | return false; | 117 | return false; |
103 | }else{ | 118 | }else{ |
104 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 119 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
105 | return false; | 120 | return false; |
106 | } | 121 | } |
107 | 122 | ||
108 | while ( obj ) { | 123 | while ( obj ) { |
109 | OContact con = parseVObject( obj ); | 124 | OContact con = parseVObject( obj ); |
110 | /* | 125 | /* |
111 | * if uid is 0 assign a new one | 126 | * if uid is 0 assign a new one |
112 | * this at least happens on | 127 | * this at least happens on |
113 | * Nokia6210 | 128 | * Nokia6210 |
114 | */ | 129 | */ |
115 | if ( con.uid() == 0 ){ | 130 | if ( con.uid() == 0 ){ |
116 | con.setUid( 1 ); | 131 | con.setUid( 1 ); |
117 | qWarning("assigned new uid %d",con.uid() ); | 132 | qWarning("assigned new uid %d",con.uid() ); |
118 | } | 133 | } |
119 | 134 | ||
120 | m_map.insert( con.uid(), con ); | 135 | m_map.insert( con.uid(), con ); |
121 | 136 | ||
122 | VObject *t = obj; | 137 | VObject *t = obj; |
123 | obj = nextVObjectInList(obj); | 138 | obj = nextVObjectInList(obj); |
124 | cleanVObject( t ); | 139 | cleanVObject( t ); |
125 | } | 140 | } |
126 | 141 | ||
127 | return true; | 142 | return true; |
128 | 143 | ||
129 | } | 144 | } |
130 | bool OContactAccessBackend_VCard::reload() | 145 | bool OContactAccessBackend_VCard::reload() |
131 | { | 146 | { |
132 | return load(); | 147 | return load(); |
133 | } | 148 | } |
134 | bool OContactAccessBackend_VCard::save() | 149 | bool OContactAccessBackend_VCard::save() |
135 | { | 150 | { |
136 | if (!m_dirty ) | 151 | if (!m_dirty ) |
137 | return true; | 152 | return true; |
138 | 153 | ||
139 | QFileDirect file( m_file ); | 154 | QFileDirect file( m_file ); |
140 | if (!file.open(IO_WriteOnly ) ) | 155 | if (!file.open(IO_WriteOnly ) ) |
141 | return false; | 156 | return false; |
142 | 157 | ||
143 | VObject *obj; | 158 | VObject *obj; |
144 | obj = newVObject( VCCalProp ); | 159 | obj = newVObject( VCCalProp ); |
145 | addPropValue( obj, VCVersionProp, "1.0" ); | 160 | addPropValue( obj, VCVersionProp, "1.0" ); |
146 | 161 | ||
147 | VObject *vo; | 162 | VObject *vo; |
148 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 163 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
149 | vo = createVObject( *it ); | 164 | vo = createVObject( *it ); |
150 | writeVObject( file.directHandle() , vo ); | 165 | writeVObject( file.directHandle() , vo ); |
151 | cleanVObject( vo ); | 166 | cleanVObject( vo ); |
152 | } | 167 | } |
153 | cleanStrTbl(); | 168 | cleanStrTbl(); |
169 | deleteVObject( obj ); | ||
154 | 170 | ||
155 | m_dirty = false; | 171 | m_dirty = false; |
156 | return true; | 172 | return true; |
157 | 173 | ||
158 | 174 | ||
159 | } | 175 | } |
160 | void OContactAccessBackend_VCard::clear () | 176 | void OContactAccessBackend_VCard::clear () |
161 | { | 177 | { |
162 | m_map.clear(); | 178 | m_map.clear(); |
163 | m_dirty = true; // ??? sure ? (se) | 179 | m_dirty = true; // ??? sure ? (se) |
164 | } | 180 | } |
165 | 181 | ||
166 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 182 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
167 | { | 183 | { |
168 | m_map.insert( newcontact.uid(), newcontact ); | 184 | m_map.insert( newcontact.uid(), newcontact ); |
169 | m_dirty = true; | 185 | m_dirty = true; |
170 | return true; | 186 | return true; |
171 | } | 187 | } |
172 | 188 | ||
173 | bool OContactAccessBackend_VCard::remove ( int uid ) | 189 | bool OContactAccessBackend_VCard::remove ( int uid ) |
174 | { | 190 | { |
175 | m_map.remove( uid ); | 191 | m_map.remove( uid ); |
176 | m_dirty = true; | 192 | m_dirty = true; |
177 | return true; | 193 | return true; |
178 | } | 194 | } |
179 | 195 | ||
180 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 196 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
181 | { | 197 | { |
182 | m_map.replace( contact.uid(), contact ); | 198 | m_map.replace( contact.uid(), contact ); |
183 | m_dirty = true; | 199 | m_dirty = true; |
184 | return true; | 200 | return true; |
185 | } | 201 | } |
186 | 202 | ||
187 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 203 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
188 | { | 204 | { |
189 | return m_map[uid]; | 205 | return m_map[uid]; |
190 | } | 206 | } |
191 | 207 | ||
192 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 208 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
193 | { | 209 | { |
194 | QArray<int> ar( m_map.count() ); | 210 | QArray<int> ar( m_map.count() ); |
195 | QMap<int, OContact>::ConstIterator it; | 211 | QMap<int, OContact>::ConstIterator it; |
196 | int i = 0; | 212 | int i = 0; |
197 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 213 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
198 | ar[i] = it.key(); | 214 | ar[i] = it.key(); |
199 | i++; | 215 | i++; |
200 | } | 216 | } |
201 | return ar; | 217 | return ar; |
202 | } | 218 | } |
203 | 219 | ||
204 | // Not implemented | 220 | // Not implemented |
205 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) | 221 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) |
206 | { | 222 | { |
207 | QArray<int> ar(0); | 223 | QArray<int> ar(0); |
208 | return ar; | 224 | return ar; |
209 | } | 225 | } |
210 | 226 | ||
211 | // Not implemented | 227 | // Not implemented |
212 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 228 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
213 | { | 229 | { |
214 | QArray<int> ar(0); | 230 | QArray<int> ar(0); |
215 | return ar; | 231 | return ar; |
216 | } | 232 | } |
217 | 233 | ||
218 | const uint OContactAccessBackend_VCard::querySettings() | 234 | const uint OContactAccessBackend_VCard::querySettings() |
219 | { | 235 | { |
220 | return 0; // No search possible | 236 | return 0; // No search possible |
221 | } | 237 | } |
222 | 238 | ||
223 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 239 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
224 | { | 240 | { |
225 | return false; // No search possible, therefore all settings invalid ;) | 241 | return false; // No search possible, therefore all settings invalid ;) |
226 | } | 242 | } |
227 | 243 | ||
228 | bool OContactAccessBackend_VCard::wasChangedExternally() | 244 | bool OContactAccessBackend_VCard::wasChangedExternally() |
229 | { | 245 | { |
230 | return false; // Don't expect concurrent access | 246 | return false; // Don't expect concurrent access |
231 | } | 247 | } |
232 | 248 | ||
233 | // Not implemented | 249 | // Not implemented |
234 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 250 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) |
235 | { | 251 | { |
236 | QArray<int> ar(0); | 252 | QArray<int> ar(0); |
237 | return ar; | 253 | return ar; |
238 | } | 254 | } |
239 | 255 | ||
240 | // *** Private stuff *** | 256 | // *** Private stuff *** |
241 | 257 | ||
242 | 258 | ||
243 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 259 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
244 | { | 260 | { |
245 | OContact c; | 261 | OContact c; |
246 | 262 | ||
247 | VObjectIterator it; | 263 | VObjectIterator it; |
248 | initPropIterator( &it, obj ); | 264 | initPropIterator( &it, obj ); |
249 | while( moreIteration( &it ) ) { | 265 | while( moreIteration( &it ) ) { |
250 | VObject *o = nextVObject( &it ); | 266 | VObject *o = nextVObject( &it ); |
251 | QCString name = vObjectName( o ); | 267 | QCString name = vObjectName( o ); |
252 | QCString value = vObjectStringZValue( o ); | 268 | QCString value = vObjectStringZValue( o ); |
253 | if ( name == VCNameProp ) { | 269 | if ( name == VCNameProp ) { |
254 | VObjectIterator nit; | 270 | VObjectIterator nit; |
255 | initPropIterator( &nit, o ); | 271 | initPropIterator( &nit, o ); |
256 | while( moreIteration( &nit ) ) { | 272 | while( moreIteration( &nit ) ) { |
257 | VObject *o = nextVObject( &nit ); | 273 | VObject *o = nextVObject( &nit ); |
258 | QCString name = vObjectTypeInfo( o ); | 274 | QCString name = vObjectTypeInfo( o ); |
259 | QString value = vObjectStringZValue( o ); | 275 | QString value = vObjectStringZValue( o ); |
260 | if ( name == VCNamePrefixesProp ) | 276 | if ( name == VCNamePrefixesProp ) |
261 | c.setTitle( value ); | 277 | c.setTitle( value ); |
262 | else if ( name == VCNameSuffixesProp ) | 278 | else if ( name == VCNameSuffixesProp ) |
263 | c.setSuffix( value ); | 279 | c.setSuffix( value ); |
264 | else if ( name == VCFamilyNameProp ) | 280 | else if ( name == VCFamilyNameProp ) |
265 | c.setLastName( value ); | 281 | c.setLastName( value ); |
266 | else if ( name == VCGivenNameProp ) | 282 | else if ( name == VCGivenNameProp ) |
267 | c.setFirstName( value ); | 283 | c.setFirstName( value ); |
268 | else if ( name == VCAdditionalNamesProp ) | 284 | else if ( name == VCAdditionalNamesProp ) |
269 | c.setMiddleName( value ); | 285 | c.setMiddleName( value ); |
270 | } | 286 | } |
271 | } | 287 | } |
272 | else if ( name == VCAdrProp ) { | 288 | else if ( name == VCAdrProp ) { |
273 | bool work = TRUE; // default address is work address | 289 | bool work = TRUE; // default address is work address |
274 | QString street; | 290 | QString street; |
275 | QString city; | 291 | QString city; |
276 | QString region; | 292 | QString region; |
277 | QString postal; | 293 | QString postal; |
278 | QString country; | 294 | QString country; |
279 | 295 | ||
280 | VObjectIterator nit; | 296 | VObjectIterator nit; |
281 | initPropIterator( &nit, o ); | 297 | initPropIterator( &nit, o ); |
282 | while( moreIteration( &nit ) ) { | 298 | while( moreIteration( &nit ) ) { |
283 | VObject *o = nextVObject( &nit ); | 299 | VObject *o = nextVObject( &nit ); |
284 | QCString name = vObjectName( o ); | 300 | QCString name = vObjectName( o ); |
285 | QString value = vObjectStringZValue( o ); | 301 | QString value = vObjectStringZValue( o ); |
286 | if ( name == VCHomeProp ) | 302 | if ( name == VCHomeProp ) |
287 | work = FALSE; | 303 | work = FALSE; |
288 | else if ( name == VCWorkProp ) | 304 | else if ( name == VCWorkProp ) |
289 | work = TRUE; | 305 | work = TRUE; |
290 | else if ( name == VCStreetAddressProp ) | 306 | else if ( name == VCStreetAddressProp ) |
291 | street = value; | 307 | street = value; |
292 | else if ( name == VCCityProp ) | 308 | else if ( name == VCCityProp ) |
293 | city = value; | 309 | city = value; |
294 | else if ( name == VCRegionProp ) | 310 | else if ( name == VCRegionProp ) |
295 | region = value; | 311 | region = value; |
296 | else if ( name == VCPostalCodeProp ) | 312 | else if ( name == VCPostalCodeProp ) |
297 | postal = value; | 313 | postal = value; |
298 | else if ( name == VCCountryNameProp ) | 314 | else if ( name == VCCountryNameProp ) |
299 | country = value; | 315 | country = value; |
300 | } | 316 | } |
301 | if ( work ) { | 317 | if ( work ) { |
302 | c.setBusinessStreet( street ); | 318 | c.setBusinessStreet( street ); |
303 | c.setBusinessCity( city ); | 319 | c.setBusinessCity( city ); |
304 | c.setBusinessCountry( country ); | 320 | c.setBusinessCountry( country ); |
305 | c.setBusinessZip( postal ); | 321 | c.setBusinessZip( postal ); |
306 | c.setBusinessState( region ); | 322 | c.setBusinessState( region ); |
307 | } else { | 323 | } else { |
308 | c.setHomeStreet( street ); | 324 | c.setHomeStreet( street ); |
309 | c.setHomeCity( city ); | 325 | c.setHomeCity( city ); |
310 | c.setHomeCountry( country ); | 326 | c.setHomeCountry( country ); |
311 | c.setHomeZip( postal ); | 327 | c.setHomeZip( postal ); |
312 | c.setHomeState( region ); | 328 | c.setHomeState( region ); |
313 | } | 329 | } |
314 | } | 330 | } |
315 | else if ( name == VCTelephoneProp ) { | 331 | else if ( name == VCTelephoneProp ) { |
316 | enum { | 332 | enum { |
317 | HOME = 0x01, | 333 | HOME = 0x01, |
318 | WORK = 0x02, | 334 | WORK = 0x02, |
319 | VOICE = 0x04, | 335 | VOICE = 0x04, |
320 | CELL = 0x08, | 336 | CELL = 0x08, |
321 | FAX = 0x10, | 337 | FAX = 0x10, |
322 | PAGER = 0x20, | 338 | PAGER = 0x20, |
323 | UNKNOWN = 0x80 | 339 | UNKNOWN = 0x80 |
324 | }; | 340 | }; |
325 | int type = 0; | 341 | int type = 0; |
326 | 342 | ||
327 | VObjectIterator nit; | 343 | VObjectIterator nit; |
328 | initPropIterator( &nit, o ); | 344 | initPropIterator( &nit, o ); |
329 | while( moreIteration( &nit ) ) { | 345 | while( moreIteration( &nit ) ) { |
330 | VObject *o = nextVObject( &nit ); | 346 | VObject *o = nextVObject( &nit ); |
331 | QCString name = vObjectTypeInfo( o ); | 347 | QCString name = vObjectTypeInfo( o ); |
332 | if ( name == VCHomeProp ) | 348 | if ( name == VCHomeProp ) |
333 | type |= HOME; | 349 | type |= HOME; |
334 | else if ( name == VCWorkProp ) | 350 | else if ( name == VCWorkProp ) |
335 | type |= WORK; | 351 | type |= WORK; |
336 | else if ( name == VCVoiceProp ) | 352 | else if ( name == VCVoiceProp ) |
337 | type |= VOICE; | 353 | type |= VOICE; |
338 | else if ( name == VCCellularProp ) | 354 | else if ( name == VCCellularProp ) |
339 | type |= CELL; | 355 | type |= CELL; |
340 | else if ( name == VCFaxProp ) | 356 | else if ( name == VCFaxProp ) |
341 | type |= FAX; | 357 | type |= FAX; |
342 | else if ( name == VCPagerProp ) | 358 | else if ( name == VCPagerProp ) |
343 | type |= PAGER; | 359 | type |= PAGER; |
344 | else if ( name == VCPreferredProp ) | 360 | else if ( name == VCPreferredProp ) |
345 | ; | 361 | ; |
346 | else | 362 | else |
347 | type |= UNKNOWN; | 363 | type |= UNKNOWN; |
348 | } | 364 | } |
349 | if ( (type & UNKNOWN) != UNKNOWN ) { | 365 | if ( (type & UNKNOWN) != UNKNOWN ) { |
350 | if ( ( type & (HOME|WORK) ) == 0 ) // default | 366 | if ( ( type & (HOME|WORK) ) == 0 ) // default |
351 | type |= HOME; | 367 | type |= HOME; |
352 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | 368 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default |
353 | type |= VOICE; | 369 | type |= VOICE; |
354 | 370 | ||
355 | qWarning("value %s %d", value.data(), type ); | 371 | qWarning("value %s %d", value.data(), type ); |
356 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) | 372 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) |
357 | c.setHomePhone( value ); | 373 | c.setHomePhone( value ); |
358 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 374 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
359 | c.setHomeFax( value ); | 375 | c.setHomeFax( value ); |
360 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 376 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
361 | c.setHomeMobile( value ); | 377 | c.setHomeMobile( value ); |
362 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) | 378 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) |
363 | c.setBusinessPhone( value ); | 379 | c.setBusinessPhone( value ); |
364 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | 380 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) |
365 | c.setBusinessFax( value ); | 381 | c.setBusinessFax( value ); |
366 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | 382 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) |
367 | c.setBusinessMobile( value ); | 383 | c.setBusinessMobile( value ); |
368 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 384 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
369 | c.setBusinessPager( value ); | 385 | c.setBusinessPager( value ); |
370 | } | 386 | } |
371 | } | 387 | } |
372 | else if ( name == VCEmailAddressProp ) { | 388 | else if ( name == VCEmailAddressProp ) { |
373 | QString email = vObjectStringZValue( o ); | 389 | QString email = vObjectStringZValue( o ); |
374 | bool valid = TRUE; | 390 | bool valid = TRUE; |
375 | VObjectIterator nit; | 391 | VObjectIterator nit; |
376 | initPropIterator( &nit, o ); | 392 | initPropIterator( &nit, o ); |
377 | while( moreIteration( &nit ) ) { | 393 | while( moreIteration( &nit ) ) { |
378 | VObject *o = nextVObject( &nit ); | 394 | VObject *o = nextVObject( &nit ); |
379 | QCString name = vObjectTypeInfo( o ); | 395 | QCString name = vObjectTypeInfo( o ); |
380 | if ( name != VCInternetProp && name != VCHomeProp && | 396 | if ( name != VCInternetProp && name != VCHomeProp && |
381 | name != VCWorkProp && | 397 | name != VCWorkProp && |
382 | name != VCPreferredProp ) | 398 | name != VCPreferredProp ) |
383 | // ### preffered should map to default email | 399 | // ### preffered should map to default email |
384 | valid = FALSE; | 400 | valid = FALSE; |
385 | } | 401 | } |
386 | if ( valid ) { | 402 | if ( valid ) { |
387 | c.insertEmail( email ); | 403 | c.insertEmail( email ); |
388 | } | 404 | } |
389 | } | 405 | } |
390 | else if ( name == VCURLProp ) { | 406 | else if ( name == VCURLProp ) { |
391 | VObjectIterator nit; | 407 | VObjectIterator nit; |
392 | initPropIterator( &nit, o ); | 408 | initPropIterator( &nit, o ); |
393 | while( moreIteration( &nit ) ) { | 409 | while( moreIteration( &nit ) ) { |
394 | VObject *o = nextVObject( &nit ); | 410 | VObject *o = nextVObject( &nit ); |
395 | QCString name = vObjectTypeInfo( o ); | 411 | QCString name = vObjectTypeInfo( o ); |
396 | if ( name == VCHomeProp ) | 412 | if ( name == VCHomeProp ) |
397 | c.setHomeWebpage( value ); | 413 | c.setHomeWebpage( value ); |
398 | else if ( name == VCWorkProp ) | 414 | else if ( name == VCWorkProp ) |
399 | c.setBusinessWebpage( value ); | 415 | c.setBusinessWebpage( value ); |
400 | } | 416 | } |
401 | } | 417 | } |
402 | else if ( name == VCOrgProp ) { | 418 | else if ( name == VCOrgProp ) { |
403 | VObjectIterator nit; | 419 | VObjectIterator nit; |
404 | initPropIterator( &nit, o ); | 420 | initPropIterator( &nit, o ); |
405 | while( moreIteration( &nit ) ) { | 421 | while( moreIteration( &nit ) ) { |
406 | VObject *o = nextVObject( &nit ); | 422 | VObject *o = nextVObject( &nit ); |
407 | QCString name = vObjectName( o ); | 423 | QCString name = vObjectName( o ); |
408 | QString value = vObjectStringZValue( o ); | 424 | QString value = vObjectStringZValue( o ); |
409 | if ( name == VCOrgNameProp ) | 425 | if ( name == VCOrgNameProp ) |
410 | c.setCompany( value ); | 426 | c.setCompany( value ); |
411 | else if ( name == VCOrgUnitProp ) | 427 | else if ( name == VCOrgUnitProp ) |
412 | c.setDepartment( value ); | 428 | c.setDepartment( value ); |
413 | else if ( name == VCOrgUnit2Prop ) | 429 | else if ( name == VCOrgUnit2Prop ) |
414 | c.setOffice( value ); | 430 | c.setOffice( value ); |
415 | } | 431 | } |
416 | } | 432 | } |
417 | else if ( name == VCTitleProp ) { | 433 | else if ( name == VCTitleProp ) { |
418 | c.setJobTitle( value ); | 434 | c.setJobTitle( value ); |
419 | } | 435 | } |
420 | else if ( name == "X-Qtopia-Profession" ) { | 436 | else if ( name == "X-Qtopia-Profession" ) { |
421 | c.setProfession( value ); | 437 | c.setProfession( value ); |
422 | } | 438 | } |
423 | else if ( name == "X-Qtopia-Manager" ) { | 439 | else if ( name == "X-Qtopia-Manager" ) { |
424 | c.setManager( value ); | 440 | c.setManager( value ); |
425 | } | 441 | } |
426 | else if ( name == "X-Qtopia-Assistant" ) { | 442 | else if ( name == "X-Qtopia-Assistant" ) { |
427 | c.setAssistant( value ); | 443 | c.setAssistant( value ); |
428 | } | 444 | } |
429 | else if ( name == "X-Qtopia-Spouse" ) { | 445 | else if ( name == "X-Qtopia-Spouse" ) { |
430 | c.setSpouse( value ); | 446 | c.setSpouse( value ); |
431 | } | 447 | } |
432 | else if ( name == "X-Qtopia-Gender" ) { | 448 | else if ( name == "X-Qtopia-Gender" ) { |
433 | c.setGender( value ); | 449 | c.setGender( value ); |
434 | } | 450 | } |
435 | else if ( name == "X-Qtopia-Anniversary" ) { | 451 | else if ( name == "X-Qtopia-Anniversary" ) { |
436 | c.setAnniversary( convVCardDateToDate( value ) ); | 452 | c.setAnniversary( convVCardDateToDate( value ) ); |
437 | } | 453 | } |
438 | else if ( name == "X-Qtopia-Nickname" ) { | 454 | else if ( name == "X-Qtopia-Nickname" ) { |
439 | c.setNickname( value ); | 455 | c.setNickname( value ); |
440 | } | 456 | } |
441 | else if ( name == "X-Qtopia-Children" ) { | 457 | else if ( name == "X-Qtopia-Children" ) { |
442 | c.setChildren( value ); | 458 | c.setChildren( value ); |
443 | } | 459 | } |
444 | else if ( name == VCBirthDateProp ) { | 460 | else if ( name == VCBirthDateProp ) { |
445 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 461 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
446 | c.setBirthday( convVCardDateToDate( value ) ); | 462 | c.setBirthday( convVCardDateToDate( value ) ); |
447 | 463 | ||
448 | } | 464 | } |
449 | 465 | else if ( name == VCCommentProp ) { | |
466 | c.setNotes( value ); | ||
467 | } | ||
450 | #if 0 | 468 | #if 0 |
451 | else { | 469 | else { |
452 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 470 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
453 | VObjectIterator nit; | 471 | VObjectIterator nit; |
454 | initPropIterator( &nit, o ); | 472 | initPropIterator( &nit, o ); |
455 | while( moreIteration( &nit ) ) { | 473 | while( moreIteration( &nit ) ) { |
456 | VObject *o = nextVObject( &nit ); | 474 | VObject *o = nextVObject( &nit ); |
457 | QCString name = vObjectName( o ); | 475 | QCString name = vObjectName( o ); |
458 | QString value = vObjectStringZValue( o ); | 476 | QString value = vObjectStringZValue( o ); |
459 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 477 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
460 | } | 478 | } |
461 | } | 479 | } |
462 | #endif | 480 | #endif |
463 | } | 481 | } |
464 | c.setFileAs(); | 482 | c.setFileAs(); |
465 | return c; | 483 | return c; |
466 | } | 484 | } |
467 | 485 | ||
468 | 486 | ||
469 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 487 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
470 | { | 488 | { |
471 | VObject *vcard = newVObject( VCCardProp ); | 489 | VObject *vcard = newVObject( VCCardProp ); |
472 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 490 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
473 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 491 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
474 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 492 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
475 | 493 | ||
476 | // full name | 494 | // full name |
477 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 495 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
478 | 496 | ||
479 | // name properties | 497 | // name properties |
480 | VObject *name = safeAddProp( vcard, VCNameProp ); | 498 | VObject *name = safeAddProp( vcard, VCNameProp ); |
481 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 499 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
482 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 500 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
483 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 501 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
484 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 502 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
485 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 503 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
486 | 504 | ||
487 | // home properties | 505 | // home properties |
488 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 506 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
489 | safeAddProp( home_adr, VCHomeProp ); | 507 | safeAddProp( home_adr, VCHomeProp ); |
490 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 508 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
491 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 509 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |
492 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); | 510 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); |
493 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); | 511 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); |
494 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); | 512 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); |
495 | 513 | ||
496 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); | 514 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); |
497 | safeAddProp( home_phone, VCHomeProp ); | 515 | safeAddProp( home_phone, VCHomeProp ); |
498 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); | 516 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); |
499 | safeAddProp( home_phone, VCHomeProp ); | 517 | safeAddProp( home_phone, VCHomeProp ); |
500 | safeAddProp( home_phone, VCCellularProp ); | 518 | safeAddProp( home_phone, VCCellularProp ); |
501 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); | 519 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); |
502 | safeAddProp( home_phone, VCHomeProp ); | 520 | safeAddProp( home_phone, VCHomeProp ); |
503 | safeAddProp( home_phone, VCFaxProp ); | 521 | safeAddProp( home_phone, VCFaxProp ); |
504 | 522 | ||
505 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); | 523 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); |
506 | safeAddProp( url, VCHomeProp ); | 524 | safeAddProp( url, VCHomeProp ); |
507 | 525 | ||
508 | // work properties | 526 | // work properties |
509 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); | 527 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); |
510 | safeAddProp( work_adr, VCWorkProp ); | 528 | safeAddProp( work_adr, VCWorkProp ); |
511 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); | 529 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); |
512 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); | 530 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); |
513 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | 531 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); |
514 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | 532 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); |
515 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 533 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
516 | 534 | ||
517 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 535 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
518 | safeAddProp( work_phone, VCWorkProp ); | 536 | safeAddProp( work_phone, VCWorkProp ); |
519 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 537 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
520 | safeAddProp( work_phone, VCWorkProp ); | 538 | safeAddProp( work_phone, VCWorkProp ); |
521 | safeAddProp( work_phone, VCCellularProp ); | 539 | safeAddProp( work_phone, VCCellularProp ); |
522 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 540 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
523 | safeAddProp( work_phone, VCWorkProp ); | 541 | safeAddProp( work_phone, VCWorkProp ); |
524 | safeAddProp( work_phone, VCFaxProp ); | 542 | safeAddProp( work_phone, VCFaxProp ); |
525 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 543 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
526 | safeAddProp( work_phone, VCWorkProp ); | 544 | safeAddProp( work_phone, VCWorkProp ); |
527 | safeAddProp( work_phone, VCPagerProp ); | 545 | safeAddProp( work_phone, VCPagerProp ); |
528 | 546 | ||
529 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 547 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
530 | safeAddProp( url, VCWorkProp ); | 548 | safeAddProp( url, VCWorkProp ); |
531 | 549 | ||
532 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 550 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
533 | safeAddProp( title, VCWorkProp ); | 551 | safeAddProp( title, VCWorkProp ); |
534 | 552 | ||
535 | 553 | ||
536 | QStringList emails = c.emailList(); | 554 | QStringList emails = c.emailList(); |
537 | emails.prepend( c.defaultEmail() ); | 555 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 |
538 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 556 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
539 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 557 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
540 | safeAddProp( email, VCInternetProp ); | 558 | safeAddProp( email, VCInternetProp ); |
541 | } | 559 | } |
542 | 560 | ||
543 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 561 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
544 | 562 | ||
545 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 563 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
546 | if ( c.birthday().isValid() ){ | 564 | if ( c.birthday().isValid() ){ |
547 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); | 565 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
548 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); | 566 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
549 | } | 567 | } |
550 | 568 | ||
551 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 569 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
552 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 570 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
553 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 571 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
554 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 572 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
555 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 573 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
556 | } | 574 | } |
557 | 575 | ||
558 | // some values we have to export as custom fields | 576 | // some values we have to export as custom fields |
559 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 577 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
560 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 578 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
561 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 579 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
562 | 580 | ||
563 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 581 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
564 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 582 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
565 | if ( c.anniversary().isValid() ){ | 583 | if ( c.anniversary().isValid() ){ |
566 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | 584 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); |
567 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | 585 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); |
568 | } | 586 | } |
569 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 587 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
570 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 588 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
571 | 589 | ||
572 | return vcard; | 590 | return vcard; |
573 | } | 591 | } |
574 | 592 | ||
575 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | 593 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const |
576 | { | 594 | { |
577 | QString str_rfc2425 = QString("%1-%2-%3") | 595 | QString str_rfc2425 = QString("%1-%2-%3") |
578 | .arg( d.year() ) | 596 | .arg( d.year() ) |
579 | .arg( d.month(), 2 ) | 597 | .arg( d.month(), 2 ) |
580 | .arg( d.day(), 2 ); | 598 | .arg( d.day(), 2 ); |
581 | // Now replace spaces with "0"... | 599 | // Now replace spaces with "0"... |
582 | int pos = 0; | 600 | int pos = 0; |
583 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | 601 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) |
584 | str_rfc2425.replace( pos, 1, "0" ); | 602 | str_rfc2425.replace( pos, 1, "0" ); |
585 | 603 | ||
586 | return str_rfc2425; | 604 | return str_rfc2425; |
587 | } | 605 | } |
588 | 606 | ||
589 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 607 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
590 | { | 608 | { |
591 | int monthPos = datestr.find('-'); | 609 | int monthPos = datestr.find('-'); |
592 | int dayPos = datestr.find('-', monthPos+1 ); | 610 | int dayPos = datestr.find('-', monthPos+1 ); |
593 | int sep_ignore = 1; | 611 | int sep_ignore = 1; |
594 | if ( monthPos == -1 || dayPos == -1 ) { | 612 | if ( monthPos == -1 || dayPos == -1 ) { |
595 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 613 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
596 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 614 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
597 | if ( datestr.length() == 8 ){ | 615 | if ( datestr.length() == 8 ){ |
598 | monthPos = 4; | 616 | monthPos = 4; |
599 | dayPos = 6; | 617 | dayPos = 6; |
600 | sep_ignore = 0; | 618 | sep_ignore = 0; |
601 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 619 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
602 | } else { | 620 | } else { |
603 | return QDate(); | 621 | return QDate(); |
604 | } | 622 | } |
605 | } | 623 | } |
606 | int y = datestr.left( monthPos ).toInt(); | 624 | int y = datestr.left( monthPos ).toInt(); |
607 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 625 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
608 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 626 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
609 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 627 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
610 | QDate date ( y,m,d ); | 628 | QDate date ( y,m,d ); |
611 | return date; | 629 | return date; |
612 | } | 630 | } |
613 | 631 | ||
614 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 632 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
615 | { | 633 | { |
616 | VObject *ret = 0; | 634 | VObject *ret = 0; |
617 | if ( o && !value.isEmpty() ) | 635 | if ( o && !value.isEmpty() ) |
618 | ret = addPropValue( o, prop, value.latin1() ); | 636 | ret = addPropValue( o, prop, value.latin1() ); |
619 | return ret; | 637 | return ret; |
620 | } | 638 | } |
621 | 639 | ||
622 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 640 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
623 | { | 641 | { |
624 | VObject *ret = 0; | 642 | VObject *ret = 0; |
625 | if ( o ) | 643 | if ( o ) |
626 | ret = addProp( o, prop ); | 644 | ret = addProp( o, prop ); |
627 | return ret; | 645 | return ret; |
628 | } | 646 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 097142b..1c21619 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -1,811 +1,814 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
20 | * Revision 1.6 2003/07/07 16:19:47 eilers | 23 | * Revision 1.6 2003/07/07 16:19:47 eilers |
21 | * Fixing serious bug in hasQuerySettings() | 24 | * Fixing serious bug in hasQuerySettings() |
22 | * | 25 | * |
23 | * Revision 1.5 2003/04/13 18:07:10 zecke | 26 | * Revision 1.5 2003/04/13 18:07:10 zecke |
24 | * More API doc | 27 | * More API doc |
25 | * QString -> const QString& | 28 | * QString -> const QString& |
26 | * QString = 0l -> QString::null | 29 | * QString = 0l -> QString::null |
27 | * | 30 | * |
28 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 31 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
29 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 32 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
30 | * | 33 | * |
31 | * Revision 1.3 2003/03/21 12:26:28 eilers | 34 | * Revision 1.3 2003/03/21 12:26:28 eilers |
32 | * Fixing small bug: If we search a birthday from today to today, it returned | 35 | * Fixing small bug: If we search a birthday from today to today, it returned |
33 | * every contact .. | 36 | * every contact .. |
34 | * | 37 | * |
35 | * Revision 1.2 2003/03/21 10:33:09 eilers | 38 | * Revision 1.2 2003/03/21 10:33:09 eilers |
36 | * Merged speed optimized xml backend for contacts to main. | 39 | * Merged speed optimized xml backend for contacts to main. |
37 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 40 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
38 | * all Birthdays/Anniversaries between two dates. This should be used | 41 | * all Birthdays/Anniversaries between two dates. This should be used |
39 | * to show all birthdays in the datebook.. | 42 | * to show all birthdays in the datebook.. |
40 | * This change is sourcecode backward compatible but you have to upgrade | 43 | * This change is sourcecode backward compatible but you have to upgrade |
41 | * the binaries for today-addressbook. | 44 | * the binaries for today-addressbook. |
42 | * | 45 | * |
43 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 46 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
44 | * Speed optimization. Removed the sequential search loops. | 47 | * Speed optimization. Removed the sequential search loops. |
45 | * | 48 | * |
46 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 49 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
47 | * Writing offsets to debug output.. | 50 | * Writing offsets to debug output.. |
48 | * | 51 | * |
49 | * Revision 1.1 2003/02/09 15:05:01 eilers | 52 | * Revision 1.1 2003/02/09 15:05:01 eilers |
50 | * Nothing happened.. Just some cleanup before I will start.. | 53 | * Nothing happened.. Just some cleanup before I will start.. |
51 | * | 54 | * |
52 | * Revision 1.12 2003/01/03 16:58:03 eilers | 55 | * Revision 1.12 2003/01/03 16:58:03 eilers |
53 | * Reenable debug output | 56 | * Reenable debug output |
54 | * | 57 | * |
55 | * Revision 1.11 2003/01/03 12:31:28 eilers | 58 | * Revision 1.11 2003/01/03 12:31:28 eilers |
56 | * Bugfix for calculating data diffs.. | 59 | * Bugfix for calculating data diffs.. |
57 | * | 60 | * |
58 | * Revision 1.10 2003/01/02 14:27:12 eilers | 61 | * Revision 1.10 2003/01/02 14:27:12 eilers |
59 | * Improved query by example: Search by date is possible.. First step | 62 | * Improved query by example: Search by date is possible.. First step |
60 | * for a today plugin for birthdays.. | 63 | * for a today plugin for birthdays.. |
61 | * | 64 | * |
62 | * Revision 1.9 2002/12/08 12:48:57 eilers | 65 | * Revision 1.9 2002/12/08 12:48:57 eilers |
63 | * Moved journal-enum from ocontact into i the xml-backend.. | 66 | * Moved journal-enum from ocontact into i the xml-backend.. |
64 | * | 67 | * |
65 | * Revision 1.8 2002/11/14 17:04:24 eilers | 68 | * Revision 1.8 2002/11/14 17:04:24 eilers |
66 | * Sorting will now work if fullname is identical on some entries | 69 | * Sorting will now work if fullname is identical on some entries |
67 | * | 70 | * |
68 | * Revision 1.7 2002/11/13 15:02:46 eilers | 71 | * Revision 1.7 2002/11/13 15:02:46 eilers |
69 | * Small Bug in sorted fixed | 72 | * Small Bug in sorted fixed |
70 | * | 73 | * |
71 | * Revision 1.6 2002/11/13 14:14:51 eilers | 74 | * Revision 1.6 2002/11/13 14:14:51 eilers |
72 | * Added sorted for Contacts.. | 75 | * Added sorted for Contacts.. |
73 | * | 76 | * |
74 | * Revision 1.5 2002/11/01 15:10:42 eilers | 77 | * Revision 1.5 2002/11/01 15:10:42 eilers |
75 | * Added regExp-search in database for all fields in a contact. | 78 | * Added regExp-search in database for all fields in a contact. |
76 | * | 79 | * |
77 | * Revision 1.4 2002/10/16 10:52:40 eilers | 80 | * Revision 1.4 2002/10/16 10:52:40 eilers |
78 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 81 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
79 | * | 82 | * |
80 | * Revision 1.3 2002/10/14 16:21:54 eilers | 83 | * Revision 1.3 2002/10/14 16:21:54 eilers |
81 | * Some minor interface updates | 84 | * Some minor interface updates |
82 | * | 85 | * |
83 | * Revision 1.2 2002/10/07 17:34:24 eilers | 86 | * Revision 1.2 2002/10/07 17:34:24 eilers |
84 | * added OBackendFactory for advanced backend access | 87 | * added OBackendFactory for advanced backend access |
85 | * | 88 | * |
86 | * Revision 1.1 2002/09/27 17:11:44 eilers | 89 | * Revision 1.1 2002/09/27 17:11:44 eilers |
87 | * Added API for accessing the Contact-Database ! It is compiling, but | 90 | * Added API for accessing the Contact-Database ! It is compiling, but |
88 | * please do not expect that anything is working ! | 91 | * please do not expect that anything is working ! |
89 | * I will debug that stuff in the next time .. | 92 | * I will debug that stuff in the next time .. |
90 | * Please read README_COMPILE for compiling ! | 93 | * Please read README_COMPILE for compiling ! |
91 | * | 94 | * |
92 | * | 95 | * |
93 | */ | 96 | */ |
94 | 97 | ||
95 | #include "ocontactaccessbackend_xml.h" | 98 | #include "ocontactaccessbackend_xml.h" |
96 | 99 | ||
97 | #include <qasciidict.h> | 100 | #include <qasciidict.h> |
98 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
99 | #include <qfile.h> | 102 | #include <qfile.h> |
100 | #include <qfileinfo.h> | 103 | #include <qfileinfo.h> |
101 | #include <qregexp.h> | 104 | #include <qregexp.h> |
102 | #include <qarray.h> | 105 | #include <qarray.h> |
103 | #include <qmap.h> | 106 | #include <qmap.h> |
104 | #include <qdatetime.h> | 107 | #include <qdatetime.h> |
105 | 108 | ||
106 | #include <qpe/global.h> | 109 | #include <qpe/global.h> |
107 | 110 | ||
108 | #include <opie/xmltree.h> | 111 | #include <opie/xmltree.h> |
109 | #include "ocontactaccessbackend.h" | 112 | #include "ocontactaccessbackend.h" |
110 | #include "ocontactaccess.h" | 113 | #include "ocontactaccess.h" |
111 | 114 | ||
112 | #include <stdlib.h> | 115 | #include <stdlib.h> |
113 | #include <errno.h> | 116 | #include <errno.h> |
114 | 117 | ||
115 | using namespace Opie; | 118 | using namespace Opie; |
116 | 119 | ||
117 | 120 | ||
118 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): | 121 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
119 | m_changed( false ) | 122 | m_changed( false ) |
120 | { | 123 | { |
121 | // Just m_contactlist should call delete if an entry | 124 | // Just m_contactlist should call delete if an entry |
122 | // is removed. | 125 | // is removed. |
123 | m_contactList.setAutoDelete( true ); | 126 | m_contactList.setAutoDelete( true ); |
124 | m_uidToContact.setAutoDelete( false ); | 127 | m_uidToContact.setAutoDelete( false ); |
125 | 128 | ||
126 | m_appName = appname; | 129 | m_appName = appname; |
127 | 130 | ||
128 | /* Set journalfile name ... */ | 131 | /* Set journalfile name ... */ |
129 | m_journalName = getenv("HOME"); | 132 | m_journalName = getenv("HOME"); |
130 | m_journalName +="/.abjournal" + appname; | 133 | m_journalName +="/.abjournal" + appname; |
131 | 134 | ||
132 | /* Expecting to access the default filename if nothing else is set */ | 135 | /* Expecting to access the default filename if nothing else is set */ |
133 | if ( filename.isEmpty() ){ | 136 | if ( filename.isEmpty() ){ |
134 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 137 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
135 | } else | 138 | } else |
136 | m_fileName = filename; | 139 | m_fileName = filename; |
137 | 140 | ||
138 | /* Load Database now */ | 141 | /* Load Database now */ |
139 | load (); | 142 | load (); |
140 | } | 143 | } |
141 | 144 | ||
142 | bool OContactAccessBackend_XML::save() | 145 | bool OContactAccessBackend_XML::save() |
143 | { | 146 | { |
144 | 147 | ||
145 | if ( !m_changed ) | 148 | if ( !m_changed ) |
146 | return true; | 149 | return true; |
147 | 150 | ||
148 | QString strNewFile = m_fileName + ".new"; | 151 | QString strNewFile = m_fileName + ".new"; |
149 | QFile f( strNewFile ); | 152 | QFile f( strNewFile ); |
150 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 153 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
151 | return false; | 154 | return false; |
152 | 155 | ||
153 | int total_written; | 156 | int total_written; |
154 | int idx_offset = 0; | 157 | int idx_offset = 0; |
155 | QString out; | 158 | QString out; |
156 | 159 | ||
157 | // Write Header | 160 | // Write Header |
158 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 161 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
159 | " <Groups>\n" | 162 | " <Groups>\n" |
160 | " </Groups>\n" | 163 | " </Groups>\n" |
161 | " <Contacts>\n"; | 164 | " <Contacts>\n"; |
162 | QCString cstr = out.utf8(); | 165 | QCString cstr = out.utf8(); |
163 | f.writeBlock( cstr.data(), cstr.length() ); | 166 | f.writeBlock( cstr.data(), cstr.length() ); |
164 | idx_offset += cstr.length(); | 167 | idx_offset += cstr.length(); |
165 | out = ""; | 168 | out = ""; |
166 | 169 | ||
167 | // Write all contacts | 170 | // Write all contacts |
168 | QListIterator<OContact> it( m_contactList ); | 171 | QListIterator<OContact> it( m_contactList ); |
169 | for ( ; it.current(); ++it ) { | 172 | for ( ; it.current(); ++it ) { |
170 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 173 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
171 | out += "<Contact "; | 174 | out += "<Contact "; |
172 | (*it)->save( out ); | 175 | (*it)->save( out ); |
173 | out += "/>\n"; | 176 | out += "/>\n"; |
174 | cstr = out.utf8(); | 177 | cstr = out.utf8(); |
175 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 178 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
176 | idx_offset += cstr.length(); | 179 | idx_offset += cstr.length(); |
177 | if ( total_written != int(cstr.length()) ) { | 180 | if ( total_written != int(cstr.length()) ) { |
178 | f.close(); | 181 | f.close(); |
179 | QFile::remove( strNewFile ); | 182 | QFile::remove( strNewFile ); |
180 | return false; | 183 | return false; |
181 | } | 184 | } |
182 | out = ""; | 185 | out = ""; |
183 | } | 186 | } |
184 | out += " </Contacts>\n</AddressBook>\n"; | 187 | out += " </Contacts>\n</AddressBook>\n"; |
185 | 188 | ||
186 | // Write Footer | 189 | // Write Footer |
187 | cstr = out.utf8(); | 190 | cstr = out.utf8(); |
188 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 191 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
189 | if ( total_written != int( cstr.length() ) ) { | 192 | if ( total_written != int( cstr.length() ) ) { |
190 | f.close(); | 193 | f.close(); |
191 | QFile::remove( strNewFile ); | 194 | QFile::remove( strNewFile ); |
192 | return false; | 195 | return false; |
193 | } | 196 | } |
194 | f.close(); | 197 | f.close(); |
195 | 198 | ||
196 | // move the file over, I'm just going to use the system call | 199 | // move the file over, I'm just going to use the system call |
197 | // because, I don't feel like using QDir. | 200 | // because, I don't feel like using QDir. |
198 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 201 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
199 | qWarning( "problem renaming file %s to %s, errno: %d", | 202 | qWarning( "problem renaming file %s to %s, errno: %d", |
200 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 203 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
201 | // remove the tmp file... | 204 | // remove the tmp file... |
202 | QFile::remove( strNewFile ); | 205 | QFile::remove( strNewFile ); |
203 | } | 206 | } |
204 | 207 | ||
205 | /* The journalfile should be removed now... */ | 208 | /* The journalfile should be removed now... */ |
206 | removeJournal(); | 209 | removeJournal(); |
207 | 210 | ||
208 | m_changed = false; | 211 | m_changed = false; |
209 | return true; | 212 | return true; |
210 | } | 213 | } |
211 | 214 | ||
212 | bool OContactAccessBackend_XML::load () | 215 | bool OContactAccessBackend_XML::load () |
213 | { | 216 | { |
214 | m_contactList.clear(); | 217 | m_contactList.clear(); |
215 | m_uidToContact.clear(); | 218 | m_uidToContact.clear(); |
216 | 219 | ||
217 | /* Load XML-File and journal if it exists */ | 220 | /* Load XML-File and journal if it exists */ |
218 | if ( !load ( m_fileName, false ) ) | 221 | if ( !load ( m_fileName, false ) ) |
219 | return false; | 222 | return false; |
220 | /* The returncode of the journalfile is ignored due to the | 223 | /* The returncode of the journalfile is ignored due to the |
221 | * fact that it does not exist when this class is instantiated ! | 224 | * fact that it does not exist when this class is instantiated ! |
222 | * But there may such a file exist, if the application crashed. | 225 | * But there may such a file exist, if the application crashed. |
223 | * Therefore we try to load it to get the changes before the # | 226 | * Therefore we try to load it to get the changes before the # |
224 | * crash happened... | 227 | * crash happened... |
225 | */ | 228 | */ |
226 | load (m_journalName, true); | 229 | load (m_journalName, true); |
227 | 230 | ||
228 | return true; | 231 | return true; |
229 | } | 232 | } |
230 | 233 | ||
231 | void OContactAccessBackend_XML::clear () | 234 | void OContactAccessBackend_XML::clear () |
232 | { | 235 | { |
233 | m_contactList.clear(); | 236 | m_contactList.clear(); |
234 | m_uidToContact.clear(); | 237 | m_uidToContact.clear(); |
235 | 238 | ||
236 | m_changed = false; | 239 | m_changed = false; |
237 | } | 240 | } |
238 | 241 | ||
239 | bool OContactAccessBackend_XML::wasChangedExternally() | 242 | bool OContactAccessBackend_XML::wasChangedExternally() |
240 | { | 243 | { |
241 | QFileInfo fi( m_fileName ); | 244 | QFileInfo fi( m_fileName ); |
242 | 245 | ||
243 | QDateTime lastmod = fi.lastModified (); | 246 | QDateTime lastmod = fi.lastModified (); |
244 | 247 | ||
245 | return (lastmod != m_readtime); | 248 | return (lastmod != m_readtime); |
246 | } | 249 | } |
247 | 250 | ||
248 | QArray<int> OContactAccessBackend_XML::allRecords() const | 251 | QArray<int> OContactAccessBackend_XML::allRecords() const |
249 | { | 252 | { |
250 | QArray<int> uid_list( m_contactList.count() ); | 253 | QArray<int> uid_list( m_contactList.count() ); |
251 | 254 | ||
252 | uint counter = 0; | 255 | uint counter = 0; |
253 | QListIterator<OContact> it( m_contactList ); | 256 | QListIterator<OContact> it( m_contactList ); |
254 | for( ; it.current(); ++it ){ | 257 | for( ; it.current(); ++it ){ |
255 | uid_list[counter++] = (*it)->uid(); | 258 | uid_list[counter++] = (*it)->uid(); |
256 | } | 259 | } |
257 | 260 | ||
258 | return ( uid_list ); | 261 | return ( uid_list ); |
259 | } | 262 | } |
260 | 263 | ||
261 | OContact OContactAccessBackend_XML::find ( int uid ) const | 264 | OContact OContactAccessBackend_XML::find ( int uid ) const |
262 | { | 265 | { |
263 | OContact foundContact; //Create empty contact | 266 | OContact foundContact; //Create empty contact |
264 | 267 | ||
265 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 268 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
266 | 269 | ||
267 | if ( found ){ | 270 | if ( found ){ |
268 | foundContact = *found; | 271 | foundContact = *found; |
269 | } | 272 | } |
270 | 273 | ||
271 | return ( foundContact ); | 274 | return ( foundContact ); |
272 | } | 275 | } |
273 | 276 | ||
274 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 277 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
275 | const QDateTime& d ) | 278 | const QDateTime& d ) |
276 | { | 279 | { |
277 | 280 | ||
278 | QArray<int> m_currentQuery( m_contactList.count() ); | 281 | QArray<int> m_currentQuery( m_contactList.count() ); |
279 | QListIterator<OContact> it( m_contactList ); | 282 | QListIterator<OContact> it( m_contactList ); |
280 | uint arraycounter = 0; | 283 | uint arraycounter = 0; |
281 | 284 | ||
282 | for( ; it.current(); ++it ){ | 285 | for( ; it.current(); ++it ){ |
283 | /* Search all fields and compare them with query object. Store them into list | 286 | /* Search all fields and compare them with query object. Store them into list |
284 | * if all fields matches. | 287 | * if all fields matches. |
285 | */ | 288 | */ |
286 | QDate* queryDate = 0l; | 289 | QDate* queryDate = 0l; |
287 | QDate* checkDate = 0l; | 290 | QDate* checkDate = 0l; |
288 | bool allcorrect = true; | 291 | bool allcorrect = true; |
289 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 292 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
290 | // Birthday and anniversary are special nonstring fields and should | 293 | // Birthday and anniversary are special nonstring fields and should |
291 | // be handled specially | 294 | // be handled specially |
292 | switch ( i ){ | 295 | switch ( i ){ |
293 | case Qtopia::Birthday: | 296 | case Qtopia::Birthday: |
294 | queryDate = new QDate( query.birthday() ); | 297 | queryDate = new QDate( query.birthday() ); |
295 | checkDate = new QDate( (*it)->birthday() ); | 298 | checkDate = new QDate( (*it)->birthday() ); |
296 | case Qtopia::Anniversary: | 299 | case Qtopia::Anniversary: |
297 | if ( queryDate == 0l ){ | 300 | if ( queryDate == 0l ){ |
298 | queryDate = new QDate( query.anniversary() ); | 301 | queryDate = new QDate( query.anniversary() ); |
299 | checkDate = new QDate( (*it)->anniversary() ); | 302 | checkDate = new QDate( (*it)->anniversary() ); |
300 | } | 303 | } |
301 | 304 | ||
302 | if ( queryDate->isValid() ){ | 305 | if ( queryDate->isValid() ){ |
303 | if( checkDate->isValid() ){ | 306 | if( checkDate->isValid() ){ |
304 | if ( settings & OContactAccess::DateYear ){ | 307 | if ( settings & OContactAccess::DateYear ){ |
305 | if ( queryDate->year() != checkDate->year() ) | 308 | if ( queryDate->year() != checkDate->year() ) |
306 | allcorrect = false; | 309 | allcorrect = false; |
307 | } | 310 | } |
308 | if ( settings & OContactAccess::DateMonth ){ | 311 | if ( settings & OContactAccess::DateMonth ){ |
309 | if ( queryDate->month() != checkDate->month() ) | 312 | if ( queryDate->month() != checkDate->month() ) |
310 | allcorrect = false; | 313 | allcorrect = false; |
311 | } | 314 | } |
312 | if ( settings & OContactAccess::DateDay ){ | 315 | if ( settings & OContactAccess::DateDay ){ |
313 | if ( queryDate->day() != checkDate->day() ) | 316 | if ( queryDate->day() != checkDate->day() ) |
314 | allcorrect = false; | 317 | allcorrect = false; |
315 | } | 318 | } |
316 | if ( settings & OContactAccess::DateDiff ) { | 319 | if ( settings & OContactAccess::DateDiff ) { |
317 | QDate current; | 320 | QDate current; |
318 | // If we get an additional date, we | 321 | // If we get an additional date, we |
319 | // will take this date instead of | 322 | // will take this date instead of |
320 | // the current one.. | 323 | // the current one.. |
321 | if ( !d.date().isValid() ) | 324 | if ( !d.date().isValid() ) |
322 | current = QDate::currentDate(); | 325 | current = QDate::currentDate(); |
323 | else | 326 | else |
324 | current = d.date(); | 327 | current = d.date(); |
325 | 328 | ||
326 | // We have to equalize the year, otherwise | 329 | // We have to equalize the year, otherwise |
327 | // the search will fail.. | 330 | // the search will fail.. |
328 | checkDate->setYMD( current.year(), | 331 | checkDate->setYMD( current.year(), |
329 | checkDate->month(), | 332 | checkDate->month(), |
330 | checkDate->day() ); | 333 | checkDate->day() ); |
331 | if ( *checkDate < current ) | 334 | if ( *checkDate < current ) |
332 | checkDate->setYMD( current.year()+1, | 335 | checkDate->setYMD( current.year()+1, |
333 | checkDate->month(), | 336 | checkDate->month(), |
334 | checkDate->day() ); | 337 | checkDate->day() ); |
335 | 338 | ||
336 | // Check whether the birthday/anniversary date is between | 339 | // Check whether the birthday/anniversary date is between |
337 | // the current/given date and the maximum date | 340 | // the current/given date and the maximum date |
338 | // ( maximum time range ) ! | 341 | // ( maximum time range ) ! |
339 | qWarning("Checking if %s is between %s and %s ! ", | 342 | qWarning("Checking if %s is between %s and %s ! ", |
340 | checkDate->toString().latin1(), | 343 | checkDate->toString().latin1(), |
341 | current.toString().latin1(), | 344 | current.toString().latin1(), |
342 | queryDate->toString().latin1() ); | 345 | queryDate->toString().latin1() ); |
343 | if ( current.daysTo( *queryDate ) >= 0 ){ | 346 | if ( current.daysTo( *queryDate ) >= 0 ){ |
344 | if ( !( ( *checkDate >= current ) && | 347 | if ( !( ( *checkDate >= current ) && |
345 | ( *checkDate <= *queryDate ) ) ){ | 348 | ( *checkDate <= *queryDate ) ) ){ |
346 | allcorrect = false; | 349 | allcorrect = false; |
347 | qWarning (" Nope!.."); | 350 | qWarning (" Nope!.."); |
348 | } | 351 | } |
349 | } | 352 | } |
350 | } | 353 | } |
351 | } else{ | 354 | } else{ |
352 | // checkDate is invalid. Therefore this entry is always rejected | 355 | // checkDate is invalid. Therefore this entry is always rejected |
353 | allcorrect = false; | 356 | allcorrect = false; |
354 | } | 357 | } |
355 | } | 358 | } |
356 | 359 | ||
357 | delete queryDate; | 360 | delete queryDate; |
358 | queryDate = 0l; | 361 | queryDate = 0l; |
359 | delete checkDate; | 362 | delete checkDate; |
360 | checkDate = 0l; | 363 | checkDate = 0l; |
361 | break; | 364 | break; |
362 | default: | 365 | default: |
363 | /* Just compare fields which are not empty in the query object */ | 366 | /* Just compare fields which are not empty in the query object */ |
364 | if ( !query.field(i).isEmpty() ){ | 367 | if ( !query.field(i).isEmpty() ){ |
365 | switch ( settings & ~( OContactAccess::IgnoreCase | 368 | switch ( settings & ~( OContactAccess::IgnoreCase |
366 | | OContactAccess::DateDiff | 369 | | OContactAccess::DateDiff |
367 | | OContactAccess::DateYear | 370 | | OContactAccess::DateYear |
368 | | OContactAccess::DateMonth | 371 | | OContactAccess::DateMonth |
369 | | OContactAccess::DateDay | 372 | | OContactAccess::DateDay |
370 | | OContactAccess::MatchOne | 373 | | OContactAccess::MatchOne |
371 | ) ){ | 374 | ) ){ |
372 | 375 | ||
373 | case OContactAccess::RegExp:{ | 376 | case OContactAccess::RegExp:{ |
374 | QRegExp expr ( query.field(i), | 377 | QRegExp expr ( query.field(i), |
375 | !(settings & OContactAccess::IgnoreCase), | 378 | !(settings & OContactAccess::IgnoreCase), |
376 | false ); | 379 | false ); |
377 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 380 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
378 | allcorrect = false; | 381 | allcorrect = false; |
379 | } | 382 | } |
380 | break; | 383 | break; |
381 | case OContactAccess::WildCards:{ | 384 | case OContactAccess::WildCards:{ |
382 | QRegExp expr ( query.field(i), | 385 | QRegExp expr ( query.field(i), |
383 | !(settings & OContactAccess::IgnoreCase), | 386 | !(settings & OContactAccess::IgnoreCase), |
384 | true ); | 387 | true ); |
385 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 388 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
386 | allcorrect = false; | 389 | allcorrect = false; |
387 | } | 390 | } |
388 | break; | 391 | break; |
389 | case OContactAccess::ExactMatch:{ | 392 | case OContactAccess::ExactMatch:{ |
390 | if (settings & OContactAccess::IgnoreCase){ | 393 | if (settings & OContactAccess::IgnoreCase){ |
391 | if ( query.field(i).upper() != | 394 | if ( query.field(i).upper() != |
392 | (*it)->field(i).upper() ) | 395 | (*it)->field(i).upper() ) |
393 | allcorrect = false; | 396 | allcorrect = false; |
394 | }else{ | 397 | }else{ |
395 | if ( query.field(i) != (*it)->field(i) ) | 398 | if ( query.field(i) != (*it)->field(i) ) |
396 | allcorrect = false; | 399 | allcorrect = false; |
397 | } | 400 | } |
398 | } | 401 | } |
399 | break; | 402 | break; |
400 | } | 403 | } |
401 | } | 404 | } |
402 | } | 405 | } |
403 | } | 406 | } |
404 | if ( allcorrect ){ | 407 | if ( allcorrect ){ |
405 | m_currentQuery[arraycounter++] = (*it)->uid(); | 408 | m_currentQuery[arraycounter++] = (*it)->uid(); |
406 | } | 409 | } |
407 | } | 410 | } |
408 | 411 | ||
409 | // Shrink to fit.. | 412 | // Shrink to fit.. |
410 | m_currentQuery.resize(arraycounter); | 413 | m_currentQuery.resize(arraycounter); |
411 | 414 | ||
412 | return m_currentQuery; | 415 | return m_currentQuery; |
413 | } | 416 | } |
414 | 417 | ||
415 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 418 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
416 | { | 419 | { |
417 | QArray<int> m_currentQuery( m_contactList.count() ); | 420 | QArray<int> m_currentQuery( m_contactList.count() ); |
418 | QListIterator<OContact> it( m_contactList ); | 421 | QListIterator<OContact> it( m_contactList ); |
419 | uint arraycounter = 0; | 422 | uint arraycounter = 0; |
420 | 423 | ||
421 | for( ; it.current(); ++it ){ | 424 | for( ; it.current(); ++it ){ |
422 | if ( (*it)->match( r ) ){ | 425 | if ( (*it)->match( r ) ){ |
423 | m_currentQuery[arraycounter++] = (*it)->uid(); | 426 | m_currentQuery[arraycounter++] = (*it)->uid(); |
424 | } | 427 | } |
425 | 428 | ||
426 | } | 429 | } |
427 | // Shrink to fit.. | 430 | // Shrink to fit.. |
428 | m_currentQuery.resize(arraycounter); | 431 | m_currentQuery.resize(arraycounter); |
429 | 432 | ||
430 | return m_currentQuery; | 433 | return m_currentQuery; |
431 | } | 434 | } |
432 | 435 | ||
433 | const uint OContactAccessBackend_XML::querySettings() | 436 | const uint OContactAccessBackend_XML::querySettings() |
434 | { | 437 | { |
435 | return ( OContactAccess::WildCards | 438 | return ( OContactAccess::WildCards |
436 | | OContactAccess::IgnoreCase | 439 | | OContactAccess::IgnoreCase |
437 | | OContactAccess::RegExp | 440 | | OContactAccess::RegExp |
438 | | OContactAccess::ExactMatch | 441 | | OContactAccess::ExactMatch |
439 | | OContactAccess::DateDiff | 442 | | OContactAccess::DateDiff |
440 | | OContactAccess::DateYear | 443 | | OContactAccess::DateYear |
441 | | OContactAccess::DateMonth | 444 | | OContactAccess::DateMonth |
442 | | OContactAccess::DateDay | 445 | | OContactAccess::DateDay |
443 | ); | 446 | ); |
444 | } | 447 | } |
445 | 448 | ||
446 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 449 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const |
447 | { | 450 | { |
448 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 451 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
449 | * may be added with any of the other settings. IgnoreCase should never used alone. | 452 | * may be added with any of the other settings. IgnoreCase should never used alone. |
450 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 453 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
451 | */ | 454 | */ |
452 | 455 | ||
453 | // Step 1: Check whether the given settings are supported by this backend | 456 | // Step 1: Check whether the given settings are supported by this backend |
454 | if ( ( querySettings & ( | 457 | if ( ( querySettings & ( |
455 | OContactAccess::IgnoreCase | 458 | OContactAccess::IgnoreCase |
456 | | OContactAccess::WildCards | 459 | | OContactAccess::WildCards |
457 | | OContactAccess::DateDiff | 460 | | OContactAccess::DateDiff |
458 | | OContactAccess::DateYear | 461 | | OContactAccess::DateYear |
459 | | OContactAccess::DateMonth | 462 | | OContactAccess::DateMonth |
460 | | OContactAccess::DateDay | 463 | | OContactAccess::DateDay |
461 | | OContactAccess::RegExp | 464 | | OContactAccess::RegExp |
462 | | OContactAccess::ExactMatch | 465 | | OContactAccess::ExactMatch |
463 | ) ) != querySettings ) | 466 | ) ) != querySettings ) |
464 | return false; | 467 | return false; |
465 | 468 | ||
466 | // Step 2: Check whether the given combinations are ok.. | 469 | // Step 2: Check whether the given combinations are ok.. |
467 | 470 | ||
468 | // IngoreCase alone is invalid | 471 | // IngoreCase alone is invalid |
469 | if ( querySettings == OContactAccess::IgnoreCase ) | 472 | if ( querySettings == OContactAccess::IgnoreCase ) |
470 | return false; | 473 | return false; |
471 | 474 | ||
472 | // WildCards, RegExp and ExactMatch should never used at the same time | 475 | // WildCards, RegExp and ExactMatch should never used at the same time |
473 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 476 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
474 | | OContactAccess::DateDiff | 477 | | OContactAccess::DateDiff |
475 | | OContactAccess::DateYear | 478 | | OContactAccess::DateYear |
476 | | OContactAccess::DateMonth | 479 | | OContactAccess::DateMonth |
477 | | OContactAccess::DateDay | 480 | | OContactAccess::DateDay |
478 | ) | 481 | ) |
479 | ){ | 482 | ){ |
480 | case OContactAccess::RegExp: | 483 | case OContactAccess::RegExp: |
481 | return ( true ); | 484 | return ( true ); |
482 | case OContactAccess::WildCards: | 485 | case OContactAccess::WildCards: |
483 | return ( true ); | 486 | return ( true ); |
484 | case OContactAccess::ExactMatch: | 487 | case OContactAccess::ExactMatch: |
485 | return ( true ); | 488 | return ( true ); |
486 | case 0: // one of the upper removed bits were set.. | 489 | case 0: // one of the upper removed bits were set.. |
487 | return ( true ); | 490 | return ( true ); |
488 | default: | 491 | default: |
489 | return ( false ); | 492 | return ( false ); |
490 | } | 493 | } |
491 | } | 494 | } |
492 | 495 | ||
493 | // Currently only asc implemented.. | 496 | // Currently only asc implemented.. |
494 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 497 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
495 | { | 498 | { |
496 | QMap<QString, int> nameToUid; | 499 | QMap<QString, int> nameToUid; |
497 | QStringList names; | 500 | QStringList names; |
498 | QArray<int> m_currentQuery( m_contactList.count() ); | 501 | QArray<int> m_currentQuery( m_contactList.count() ); |
499 | 502 | ||
500 | // First fill map and StringList with all Names | 503 | // First fill map and StringList with all Names |
501 | // Afterwards sort namelist and use map to fill array to return.. | 504 | // Afterwards sort namelist and use map to fill array to return.. |
502 | QListIterator<OContact> it( m_contactList ); | 505 | QListIterator<OContact> it( m_contactList ); |
503 | for( ; it.current(); ++it ){ | 506 | for( ; it.current(); ++it ){ |
504 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); | 507 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); |
505 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); | 508 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); |
506 | } | 509 | } |
507 | names.sort(); | 510 | names.sort(); |
508 | 511 | ||
509 | int i = 0; | 512 | int i = 0; |
510 | if ( asc ){ | 513 | if ( asc ){ |
511 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 514 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
512 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 515 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
513 | }else{ | 516 | }else{ |
514 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | 517 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) |
515 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 518 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
516 | } | 519 | } |
517 | 520 | ||
518 | return m_currentQuery; | 521 | return m_currentQuery; |
519 | 522 | ||
520 | } | 523 | } |
521 | 524 | ||
522 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 525 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) |
523 | { | 526 | { |
524 | //qWarning("odefaultbackend: ACTION::ADD"); | 527 | //qWarning("odefaultbackend: ACTION::ADD"); |
525 | updateJournal (newcontact, ACTION_ADD); | 528 | updateJournal (newcontact, ACTION_ADD); |
526 | addContact_p( newcontact ); | 529 | addContact_p( newcontact ); |
527 | 530 | ||
528 | m_changed = true; | 531 | m_changed = true; |
529 | 532 | ||
530 | return true; | 533 | return true; |
531 | } | 534 | } |
532 | 535 | ||
533 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 536 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
534 | { | 537 | { |
535 | m_changed = true; | 538 | m_changed = true; |
536 | 539 | ||
537 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 540 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
538 | 541 | ||
539 | if ( found ) { | 542 | if ( found ) { |
540 | OContact* newCont = new OContact( contact ); | 543 | OContact* newCont = new OContact( contact ); |
541 | 544 | ||
542 | updateJournal ( *newCont, ACTION_REPLACE); | 545 | updateJournal ( *newCont, ACTION_REPLACE); |
543 | m_contactList.removeRef ( found ); | 546 | m_contactList.removeRef ( found ); |
544 | m_contactList.append ( newCont ); | 547 | m_contactList.append ( newCont ); |
545 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); | 548 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
546 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); | 549 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
547 | 550 | ||
548 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); | 551 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); |
549 | 552 | ||
550 | return true; | 553 | return true; |
551 | } else | 554 | } else |
552 | return false; | 555 | return false; |
553 | } | 556 | } |
554 | 557 | ||
555 | bool OContactAccessBackend_XML::remove ( int uid ) | 558 | bool OContactAccessBackend_XML::remove ( int uid ) |
556 | { | 559 | { |
557 | m_changed = true; | 560 | m_changed = true; |
558 | 561 | ||
559 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 562 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
560 | 563 | ||
561 | if ( found ) { | 564 | if ( found ) { |
562 | updateJournal ( *found, ACTION_REMOVE); | 565 | updateJournal ( *found, ACTION_REMOVE); |
563 | m_contactList.removeRef ( found ); | 566 | m_contactList.removeRef ( found ); |
564 | m_uidToContact.remove( QString().setNum( uid ) ); | 567 | m_uidToContact.remove( QString().setNum( uid ) ); |
565 | 568 | ||
566 | return true; | 569 | return true; |
567 | } else | 570 | } else |
568 | return false; | 571 | return false; |
569 | } | 572 | } |
570 | 573 | ||
571 | bool OContactAccessBackend_XML::reload(){ | 574 | bool OContactAccessBackend_XML::reload(){ |
572 | /* Reload is the same as load in this implementation */ | 575 | /* Reload is the same as load in this implementation */ |
573 | return ( load() ); | 576 | return ( load() ); |
574 | } | 577 | } |
575 | 578 | ||
576 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 579 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) |
577 | { | 580 | { |
578 | OContact* contRef = new OContact( newcontact ); | 581 | OContact* contRef = new OContact( newcontact ); |
579 | 582 | ||
580 | m_contactList.append ( contRef ); | 583 | m_contactList.append ( contRef ); |
581 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 584 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
582 | } | 585 | } |
583 | 586 | ||
584 | /* This function loads the xml-database and the journalfile */ | 587 | /* This function loads the xml-database and the journalfile */ |
585 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 588 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
586 | { | 589 | { |
587 | 590 | ||
588 | /* We use the time of the last read to check if the file was | 591 | /* We use the time of the last read to check if the file was |
589 | * changed externally. | 592 | * changed externally. |
590 | */ | 593 | */ |
591 | if ( !isJournal ){ | 594 | if ( !isJournal ){ |
592 | QFileInfo fi( filename ); | 595 | QFileInfo fi( filename ); |
593 | m_readtime = fi.lastModified (); | 596 | m_readtime = fi.lastModified (); |
594 | } | 597 | } |
595 | 598 | ||
596 | const int JOURNALACTION = Qtopia::Notes + 1; | 599 | const int JOURNALACTION = Qtopia::Notes + 1; |
597 | const int JOURNALROW = JOURNALACTION + 1; | 600 | const int JOURNALROW = JOURNALACTION + 1; |
598 | 601 | ||
599 | bool foundAction = false; | 602 | bool foundAction = false; |
600 | journal_action action = ACTION_ADD; | 603 | journal_action action = ACTION_ADD; |
601 | int journalKey = 0; | 604 | int journalKey = 0; |
602 | QMap<int, QString> contactMap; | 605 | QMap<int, QString> contactMap; |
603 | QMap<QString, QString> customMap; | 606 | QMap<QString, QString> customMap; |
604 | QMap<QString, QString>::Iterator customIt; | 607 | QMap<QString, QString>::Iterator customIt; |
605 | QAsciiDict<int> dict( 47 ); | 608 | QAsciiDict<int> dict( 47 ); |
606 | 609 | ||
607 | dict.setAutoDelete( TRUE ); | 610 | dict.setAutoDelete( TRUE ); |
608 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 611 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
609 | dict.insert( "Title", new int(Qtopia::Title) ); | 612 | dict.insert( "Title", new int(Qtopia::Title) ); |
610 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 613 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
611 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 614 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
612 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 615 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
613 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 616 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
614 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 617 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
615 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 618 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
616 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 619 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
617 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 620 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
618 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 621 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
619 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 622 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
620 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 623 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
621 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 624 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
622 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 625 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
623 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 626 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
624 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 627 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
625 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 628 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
626 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 629 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
627 | dict.insert( "Company", new int(Qtopia::Company) ); | 630 | dict.insert( "Company", new int(Qtopia::Company) ); |
628 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 631 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
629 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 632 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
630 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 633 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
631 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 634 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
632 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 635 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
633 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 636 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
634 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 637 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
635 | dict.insert( "Department", new int(Qtopia::Department) ); | 638 | dict.insert( "Department", new int(Qtopia::Department) ); |
636 | dict.insert( "Office", new int(Qtopia::Office) ); | 639 | dict.insert( "Office", new int(Qtopia::Office) ); |
637 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 640 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
638 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 641 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
639 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 642 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
640 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 643 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
641 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 644 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
642 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 645 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
643 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 646 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
644 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 647 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
645 | dict.insert( "Children", new int(Qtopia::Children) ); | 648 | dict.insert( "Children", new int(Qtopia::Children) ); |
646 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 649 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
647 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 650 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
648 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 651 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
649 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 652 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
650 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 653 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
651 | dict.insert( "action", new int(JOURNALACTION) ); | 654 | dict.insert( "action", new int(JOURNALACTION) ); |
652 | dict.insert( "actionrow", new int(JOURNALROW) ); | 655 | dict.insert( "actionrow", new int(JOURNALROW) ); |
653 | 656 | ||
654 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 657 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
655 | 658 | ||
656 | XMLElement *root = XMLElement::load( filename ); | 659 | XMLElement *root = XMLElement::load( filename ); |
657 | if(root != 0l ){ // start parsing | 660 | if(root != 0l ){ // start parsing |
658 | /* Parse all XML-Elements and put the data into the | 661 | /* Parse all XML-Elements and put the data into the |
659 | * Contact-Class | 662 | * Contact-Class |
660 | */ | 663 | */ |
661 | XMLElement *element = root->firstChild(); | 664 | XMLElement *element = root->firstChild(); |
662 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 665 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
663 | element = element->firstChild(); | 666 | element = element->firstChild(); |
664 | 667 | ||
665 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 668 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
666 | while( element && !isJournal ){ | 669 | while( element && !isJournal ){ |
667 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 670 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
668 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 671 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
669 | // element->tagName().latin1()); | 672 | // element->tagName().latin1()); |
670 | element = element->nextChild(); | 673 | element = element->nextChild(); |
671 | } else { | 674 | } else { |
672 | element = element->firstChild(); | 675 | element = element->firstChild(); |
673 | break; | 676 | break; |
674 | } | 677 | } |
675 | } | 678 | } |
676 | /* Parse all Contacts and ignore unknown tags */ | 679 | /* Parse all Contacts and ignore unknown tags */ |
677 | while( element ){ | 680 | while( element ){ |
678 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 681 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
679 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 682 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
680 | // element->tagName().latin1()); | 683 | // element->tagName().latin1()); |
681 | element = element->nextChild(); | 684 | element = element->nextChild(); |
682 | continue; | 685 | continue; |
683 | } | 686 | } |
684 | /* Found alement with tagname "contact", now parse and store all | 687 | /* Found alement with tagname "contact", now parse and store all |
685 | * attributes contained | 688 | * attributes contained |
686 | */ | 689 | */ |
687 | //qWarning("OContactDefBack::load element tagName() : %s", | 690 | //qWarning("OContactDefBack::load element tagName() : %s", |
688 | // element->tagName().latin1() ); | 691 | // element->tagName().latin1() ); |
689 | QString dummy; | 692 | QString dummy; |
690 | foundAction = false; | 693 | foundAction = false; |
691 | 694 | ||
692 | XMLElement::AttributeMap aMap = element->attributes(); | 695 | XMLElement::AttributeMap aMap = element->attributes(); |
693 | XMLElement::AttributeMap::Iterator it; | 696 | XMLElement::AttributeMap::Iterator it; |
694 | contactMap.clear(); | 697 | contactMap.clear(); |
695 | customMap.clear(); | 698 | customMap.clear(); |
696 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 699 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
697 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 700 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
698 | 701 | ||
699 | int *find = dict[ it.key() ]; | 702 | int *find = dict[ it.key() ]; |
700 | /* Unknown attributes will be stored as "Custom" elements */ | 703 | /* Unknown attributes will be stored as "Custom" elements */ |
701 | if ( !find ) { | 704 | if ( !find ) { |
702 | qWarning("Attribute %s not known.", it.key().latin1()); | 705 | qWarning("Attribute %s not known.", it.key().latin1()); |
703 | //contact.setCustomField(it.key(), it.data()); | 706 | //contact.setCustomField(it.key(), it.data()); |
704 | customMap.insert( it.key(), it.data() ); | 707 | customMap.insert( it.key(), it.data() ); |
705 | continue; | 708 | continue; |
706 | } | 709 | } |
707 | 710 | ||
708 | /* Check if special conversion is needed and add attribute | 711 | /* Check if special conversion is needed and add attribute |
709 | * into Contact class | 712 | * into Contact class |
710 | */ | 713 | */ |
711 | switch( *find ) { | 714 | switch( *find ) { |
712 | /* | 715 | /* |
713 | case Qtopia::AddressUid: | 716 | case Qtopia::AddressUid: |
714 | contact.setUid( it.data().toInt() ); | 717 | contact.setUid( it.data().toInt() ); |
715 | break; | 718 | break; |
716 | case Qtopia::AddressCategory: | 719 | case Qtopia::AddressCategory: |
717 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 720 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
718 | break; | 721 | break; |
719 | */ | 722 | */ |
720 | case JOURNALACTION: | 723 | case JOURNALACTION: |
721 | action = journal_action(it.data().toInt()); | 724 | action = journal_action(it.data().toInt()); |
722 | foundAction = true; | 725 | foundAction = true; |
723 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 726 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
724 | break; | 727 | break; |
725 | case JOURNALROW: | 728 | case JOURNALROW: |
726 | journalKey = it.data().toInt(); | 729 | journalKey = it.data().toInt(); |
727 | break; | 730 | break; |
728 | default: // no conversion needed add them to the map | 731 | default: // no conversion needed add them to the map |
729 | contactMap.insert( *find, it.data() ); | 732 | contactMap.insert( *find, it.data() ); |
730 | break; | 733 | break; |
731 | } | 734 | } |
732 | } | 735 | } |
733 | /* now generate the Contact contact */ | 736 | /* now generate the Contact contact */ |
734 | OContact contact( contactMap ); | 737 | OContact contact( contactMap ); |
735 | 738 | ||
736 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 739 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
737 | contact.setCustomField( customIt.key(), customIt.data() ); | 740 | contact.setCustomField( customIt.key(), customIt.data() ); |
738 | } | 741 | } |
739 | 742 | ||
740 | if (foundAction){ | 743 | if (foundAction){ |
741 | foundAction = false; | 744 | foundAction = false; |
742 | switch ( action ) { | 745 | switch ( action ) { |
743 | case ACTION_ADD: | 746 | case ACTION_ADD: |
744 | addContact_p (contact); | 747 | addContact_p (contact); |
745 | break; | 748 | break; |
746 | case ACTION_REMOVE: | 749 | case ACTION_REMOVE: |
747 | if ( !remove (contact.uid()) ) | 750 | if ( !remove (contact.uid()) ) |
748 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 751 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
749 | contact.uid() ); | 752 | contact.uid() ); |
750 | break; | 753 | break; |
751 | case ACTION_REPLACE: | 754 | case ACTION_REPLACE: |
752 | if ( !replace ( contact ) ) | 755 | if ( !replace ( contact ) ) |
753 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 756 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
754 | contact.uid() ); | 757 | contact.uid() ); |
755 | break; | 758 | break; |
756 | default: | 759 | default: |
757 | qWarning ("Unknown action: ignored !"); | 760 | qWarning ("Unknown action: ignored !"); |
758 | break; | 761 | break; |
759 | } | 762 | } |
760 | }else{ | 763 | }else{ |
761 | /* Add contact to list */ | 764 | /* Add contact to list */ |
762 | addContact_p (contact); | 765 | addContact_p (contact); |
763 | } | 766 | } |
764 | 767 | ||
765 | /* Move to next element */ | 768 | /* Move to next element */ |
766 | element = element->nextChild(); | 769 | element = element->nextChild(); |
767 | } | 770 | } |
768 | }else { | 771 | }else { |
769 | qWarning("ODefBack::could not load"); | 772 | qWarning("ODefBack::could not load"); |
770 | } | 773 | } |
771 | delete root; | 774 | delete root; |
772 | qWarning("returning from loading" ); | 775 | qWarning("returning from loading" ); |
773 | return true; | 776 | return true; |
774 | } | 777 | } |
775 | 778 | ||
776 | 779 | ||
777 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 780 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
778 | journal_action action ) | 781 | journal_action action ) |
779 | { | 782 | { |
780 | QFile f( m_journalName ); | 783 | QFile f( m_journalName ); |
781 | bool created = !f.exists(); | 784 | bool created = !f.exists(); |
782 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 785 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
783 | return; | 786 | return; |
784 | 787 | ||
785 | QString buf; | 788 | QString buf; |
786 | QCString str; | 789 | QCString str; |
787 | 790 | ||
788 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 791 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
789 | // get a XML-File which is readable by our parser. | 792 | // get a XML-File which is readable by our parser. |
790 | // This is just a cheat, but better than rewrite the parser. | 793 | // This is just a cheat, but better than rewrite the parser. |
791 | if ( created ){ | 794 | if ( created ){ |
792 | buf = "<Contacts>"; | 795 | buf = "<Contacts>"; |
793 | QCString cstr = buf.utf8(); | 796 | QCString cstr = buf.utf8(); |
794 | f.writeBlock( cstr.data(), cstr.length() ); | 797 | f.writeBlock( cstr.data(), cstr.length() ); |
795 | } | 798 | } |
796 | 799 | ||
797 | buf = "<Contact "; | 800 | buf = "<Contact "; |
798 | cnt.save( buf ); | 801 | cnt.save( buf ); |
799 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 802 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
800 | buf += "/>\n"; | 803 | buf += "/>\n"; |
801 | QCString cstr = buf.utf8(); | 804 | QCString cstr = buf.utf8(); |
802 | f.writeBlock( cstr.data(), cstr.length() ); | 805 | f.writeBlock( cstr.data(), cstr.length() ); |
803 | } | 806 | } |
804 | 807 | ||
805 | void OContactAccessBackend_XML::removeJournal() | 808 | void OContactAccessBackend_XML::removeJournal() |
806 | { | 809 | { |
807 | QFile f ( m_journalName ); | 810 | QFile f ( m_journalName ); |
808 | if ( f.exists() ) | 811 | if ( f.exists() ) |
809 | f.remove(); | 812 | f.remove(); |
810 | } | 813 | } |
811 | 814 | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index 86ff298..3c02c42 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h | |||
@@ -1,73 +1,77 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include "opimaccessbackend.h" | 6 | #include "opimaccessbackend.h" |
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * This class is the interface to the storage of Events. | 10 | * This class is the interface to the storage of Events. |
11 | * @see OPimAccessBackend | 11 | * @see OPimAccessBackend |
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
15 | public: | 15 | public: |
16 | typedef int UID; | 16 | typedef int UID; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * c'tor without parameter | 19 | * c'tor without parameter |
20 | */ | 20 | */ |
21 | ODateBookAccessBackend(); | 21 | ODateBookAccessBackend(); |
22 | ~ODateBookAccessBackend(); | 22 | ~ODateBookAccessBackend(); |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * This method should return a list of UIDs containing | 25 | * This method should return a list of UIDs containing |
26 | * all events. No filter should be applied | 26 | * all events. No filter should be applied |
27 | * @return list of events | 27 | * @return list of events |
28 | */ | 28 | */ |
29 | virtual QArray<UID> rawEvents()const = 0; | 29 | virtual QArray<UID> rawEvents()const = 0; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * This method should return a list of UIDs containing | 32 | * This method should return a list of UIDs containing |
33 | * all repeating events. No filter should be applied | 33 | * all repeating events. No filter should be applied |
34 | * @return list of repeating events | 34 | * @return list of repeating events |
35 | */ | 35 | */ |
36 | virtual QArray<UID> rawRepeats()const = 0; | 36 | virtual QArray<UID> rawRepeats()const = 0; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * This mthod should return a list of UIDs containing all non | 39 | * This mthod should return a list of UIDs containing all non |
40 | * repeating events. No filter should be applied | 40 | * repeating events. No filter should be applied |
41 | * @return list of nonrepeating events | 41 | * @return list of nonrepeating events |
42 | */ | 42 | */ |
43 | virtual QArray<UID> nonRepeats() const = 0; | 43 | virtual QArray<UID> nonRepeats() const = 0; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * If you do not want to implement the effectiveEvents methods below | 46 | * If you do not want to implement the effectiveEvents methods below |
47 | * you need to supply it with directNonRepeats. | 47 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | 48 | * This method can return empty lists if effectiveEvents is implememted |
49 | */ | 49 | */ |
50 | virtual OEvent::ValueList directNonRepeats() = 0; | 50 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Same as above but return raw repeats! | 53 | * Same as above but return raw repeats! |
54 | */ | 54 | */ |
55 | virtual OEvent::ValueList directRawRepeats() = 0; | 55 | virtual OEvent::ValueList directRawRepeats() = 0; |
56 | 56 | ||
57 | /* is implemented by default but you can reimplement it*/ | 57 | /* is implemented by default but you can reimplement it*/ |
58 | /** | 58 | /** |
59 | * Effective Events are special event occuring during a time frame. This method does calcualte | 59 | * Effective Events are special event occuring during a time frame. This method does calcualte |
60 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method | 60 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method |
61 | * yourself | 61 | * yourself |
62 | */ | 62 | */ |
63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); | 63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * this is an overloaded member function | 66 | * this is an overloaded member function |
67 | * @see effecticeEvents | 67 | * @see effecticeEvents |
68 | */ | 68 | */ |
69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); | 69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); |
70 | 70 | ||
71 | private: | ||
72 | class Private; | ||
73 | Private *d; | ||
74 | |||
71 | }; | 75 | }; |
72 | 76 | ||
73 | #endif | 77 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index ab2eea4..5ea945c 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -1,606 +1,606 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | 6 | ||
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
9 | #include <sys/stat.h> | 9 | #include <sys/stat.h> |
10 | 10 | ||
11 | #include <unistd.h> | 11 | #include <unistd.h> |
12 | 12 | ||
13 | #include <qasciidict.h> | 13 | #include <qasciidict.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | 15 | ||
16 | #include <qtopia/global.h> | 16 | #include <qtopia/global.h> |
17 | #include <qtopia/stringutil.h> | 17 | #include <qtopia/stringutil.h> |
18 | #include <qtopia/timeconversion.h> | 18 | #include <qtopia/timeconversion.h> |
19 | 19 | ||
20 | #include "opimnotifymanager.h" | 20 | #include "opimnotifymanager.h" |
21 | #include "orecur.h" | 21 | #include "orecur.h" |
22 | #include "otimezone.h" | 22 | #include "otimezone.h" |
23 | #include "odatebookaccessbackend_xml.h" | 23 | #include "odatebookaccessbackend_xml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | // FROM TT again | 26 | // FROM TT again |
27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
28 | { | 28 | { |
29 | char needleChar; | 29 | char needleChar; |
30 | char haystackChar; | 30 | char haystackChar; |
31 | if (!needle || !haystack || !hLen || !nLen) | 31 | if (!needle || !haystack || !hLen || !nLen) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | const char* hsearch = haystack; | 34 | const char* hsearch = haystack; |
35 | 35 | ||
36 | if ((needleChar = *needle++) != 0) { | 36 | if ((needleChar = *needle++) != 0) { |
37 | nLen--; //(to make up for needle++) | 37 | nLen--; //(to make up for needle++) |
38 | do { | 38 | do { |
39 | do { | 39 | do { |
40 | if ((haystackChar = *hsearch++) == 0) | 40 | if ((haystackChar = *hsearch++) == 0) |
41 | return (0); | 41 | return (0); |
42 | if (hsearch >= haystack + hLen) | 42 | if (hsearch >= haystack + hLen) |
43 | return (0); | 43 | return (0); |
44 | } while (haystackChar != needleChar); | 44 | } while (haystackChar != needleChar); |
45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
46 | hsearch--; | 46 | hsearch--; |
47 | } | 47 | } |
48 | return ((char *)hsearch); | 48 | return ((char *)hsearch); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | namespace { | 52 | namespace { |
53 | time_t start, end, created, rp_end; | 53 | time_t start, end, created, rp_end; |
54 | ORecur* rec; | 54 | ORecur* rec; |
55 | ORecur* recur() { | 55 | ORecur* recur() { |
56 | if (!rec) | 56 | if (!rec) |
57 | rec = new ORecur; | 57 | rec = new ORecur; |
58 | 58 | ||
59 | return rec; | 59 | return rec; |
60 | } | 60 | } |
61 | int alarmTime; | 61 | int alarmTime; |
62 | int snd; | 62 | int snd; |
63 | enum Attribute{ | 63 | enum Attribute{ |
64 | FDescription = 0, | 64 | FDescription = 0, |
65 | FLocation, | 65 | FLocation, |
66 | FCategories, | 66 | FCategories, |
67 | FUid, | 67 | FUid, |
68 | FType, | 68 | FType, |
69 | FAlarm, | 69 | FAlarm, |
70 | FSound, | 70 | FSound, |
71 | FRType, | 71 | FRType, |
72 | FRWeekdays, | 72 | FRWeekdays, |
73 | FRPosition, | 73 | FRPosition, |
74 | FRFreq, | 74 | FRFreq, |
75 | FRHasEndDate, | 75 | FRHasEndDate, |
76 | FREndDate, | 76 | FREndDate, |
77 | FRStart, | 77 | FRStart, |
78 | FREnd, | 78 | FREnd, |
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, |
81 | FTimeZone, | 81 | FTimeZone, |
82 | FRecParent, | 82 | FRecParent, |
83 | FRecChildren, | 83 | FRecChildren, |
84 | FExceptions | 84 | FExceptions |
85 | }; | 85 | }; |
86 | inline void save( const OEvent& ev, QString& buf ) { | 86 | inline void save( const OEvent& ev, QString& buf ) { |
87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); | 87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); |
88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
89 | if (!ev.location().isEmpty() ) | 89 | if (!ev.location().isEmpty() ) |
90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
91 | 91 | ||
92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
94 | 94 | ||
95 | if (ev.isAllDay() ) | 95 | if (ev.isAllDay() ) |
96 | buf += " type=\"AllDay\""; | 96 | buf += " type=\"AllDay\""; |
97 | 97 | ||
98 | if (ev.hasNotifiers() ) { | 98 | if (ev.hasNotifiers() ) { |
99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
102 | if ( alarm.sound() == OPimAlarm::Loud ) | 102 | if ( alarm.sound() == OPimAlarm::Loud ) |
103 | buf += "loud"; | 103 | buf += "loud"; |
104 | else | 104 | else |
105 | buf += "silent"; | 105 | buf += "silent"; |
106 | buf += "\""; | 106 | buf += "\""; |
107 | } | 107 | } |
108 | if ( ev.hasRecurrence() ) { | 108 | if ( ev.hasRecurrence() ) { |
109 | buf += ev.recurrence().toString(); | 109 | buf += ev.recurrence().toString(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /* | 112 | /* |
113 | * fscking timezones :) well, we'll first convert | 113 | * fscking timezones :) well, we'll first convert |
114 | * the QDateTime to a QDateTime in UTC time | 114 | * the QDateTime to a QDateTime in UTC time |
115 | * and then we'll create a nice time_t | 115 | * and then we'll create a nice time_t |
116 | */ | 116 | */ |
117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
120 | if (!ev.note().isEmpty() ) { | 120 | if (!ev.note().isEmpty() ) { |
121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
122 | } | 122 | } |
123 | 123 | ||
124 | buf += " timezone=\""; | 124 | buf += " timezone=\""; |
125 | if ( ev.timeZone().isEmpty() ) | 125 | if ( ev.timeZone().isEmpty() ) |
126 | buf += "None"; | 126 | buf += "None"; |
127 | else | 127 | else |
128 | buf += ev.timeZone(); | 128 | buf += ev.timeZone(); |
129 | buf += "\""; | 129 | buf += "\""; |
130 | 130 | ||
131 | if (ev.parent() != 0 ) { | 131 | if (ev.parent() != 0 ) { |
132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
133 | } | 133 | } |
134 | 134 | ||
135 | if (ev.children().count() != 0 ) { | 135 | if (ev.children().count() != 0 ) { |
136 | QArray<int> children = ev.children(); | 136 | QArray<int> children = ev.children(); |
137 | buf += " recchildren=\""; | 137 | buf += " recchildren=\""; |
138 | for ( uint i = 0; i < children.count(); i++ ) { | 138 | for ( uint i = 0; i < children.count(); i++ ) { |
139 | if ( i != 0 ) buf += " "; | 139 | if ( i != 0 ) buf += " "; |
140 | buf += QString::number( children[i] ); | 140 | buf += QString::number( children[i] ); |
141 | } | 141 | } |
142 | buf+= "\""; | 142 | buf+= "\""; |
143 | } | 143 | } |
144 | 144 | ||
145 | // skip custom writing | 145 | // skip custom writing |
146 | } | 146 | } |
147 | 147 | ||
148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
149 | QMap<int, OEvent>::ConstIterator it; | 149 | QMap<int, OEvent>::ConstIterator it; |
150 | QString buf; | 150 | QString buf; |
151 | QCString str; | 151 | QCString str; |
152 | int total_written; | 152 | int total_written; |
153 | for ( it = list.begin(); it != list.end(); ++it ) { | 153 | for ( it = list.begin(); it != list.end(); ++it ) { |
154 | buf = "<event"; | 154 | buf = "<event"; |
155 | save( it.data(), buf ); | 155 | save( it.data(), buf ); |
156 | buf += " />\n"; | 156 | buf += " />\n"; |
157 | str = buf.utf8(); | 157 | str = buf.utf8(); |
158 | 158 | ||
159 | total_written = file.writeBlock(str.data(), str.length() ); | 159 | total_written = file.writeBlock(str.data(), str.length() ); |
160 | if ( total_written != int(str.length() ) ) | 160 | if ( total_written != int(str.length() ) ) |
161 | return false; | 161 | return false; |
162 | } | 162 | } |
163 | return true; | 163 | return true; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
168 | const QString& fileName ) | 168 | const QString& fileName ) |
169 | : ODateBookAccessBackend() { | 169 | : ODateBookAccessBackend() { |
170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
171 | m_changed = false; | 171 | m_changed = false; |
172 | } | 172 | } |
173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
174 | } | 174 | } |
175 | bool ODateBookAccessBackend_XML::load() { | 175 | bool ODateBookAccessBackend_XML::load() { |
176 | return loadFile(); | 176 | return loadFile(); |
177 | } | 177 | } |
178 | bool ODateBookAccessBackend_XML::reload() { | 178 | bool ODateBookAccessBackend_XML::reload() { |
179 | clear(); | 179 | clear(); |
180 | return load(); | 180 | return load(); |
181 | } | 181 | } |
182 | bool ODateBookAccessBackend_XML::save() { | 182 | bool ODateBookAccessBackend_XML::save() { |
183 | if (!m_changed) return true; | 183 | if (!m_changed) return true; |
184 | 184 | ||
185 | int total_written; | 185 | int total_written; |
186 | QString strFileNew = m_name + ".new"; | 186 | QString strFileNew = m_name + ".new"; |
187 | 187 | ||
188 | QFile f( strFileNew ); | 188 | QFile f( strFileNew ); |
189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
190 | 190 | ||
191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
193 | buf += "<events>\n"; | 193 | buf += "<events>\n"; |
194 | QCString str = buf.utf8(); | 194 | QCString str = buf.utf8(); |
195 | total_written = f.writeBlock( str.data(), str.length() ); | 195 | total_written = f.writeBlock( str.data(), str.length() ); |
196 | if ( total_written != int(str.length() ) ) { | 196 | if ( total_written != int(str.length() ) ) { |
197 | f.close(); | 197 | f.close(); |
198 | QFile::remove( strFileNew ); | 198 | QFile::remove( strFileNew ); |
199 | return false; | 199 | return false; |
200 | } | 200 | } |
201 | 201 | ||
202 | if (!forAll( m_raw, f ) ) { | 202 | if (!forAll( m_raw, f ) ) { |
203 | f.close(); | 203 | f.close(); |
204 | QFile::remove( strFileNew ); | 204 | QFile::remove( strFileNew ); |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | if (!forAll( m_rep, f ) ) { | 207 | if (!forAll( m_rep, f ) ) { |
208 | f.close(); | 208 | f.close(); |
209 | QFile::remove( strFileNew ); | 209 | QFile::remove( strFileNew ); |
210 | return false; | 210 | return false; |
211 | } | 211 | } |
212 | 212 | ||
213 | buf = "</events>\n</DATEBOOK>\n"; | 213 | buf = "</events>\n</DATEBOOK>\n"; |
214 | str = buf.utf8(); | 214 | str = buf.utf8(); |
215 | total_written = f.writeBlock( str.data(), str.length() ); | 215 | total_written = f.writeBlock( str.data(), str.length() ); |
216 | if ( total_written != int(str.length() ) ) { | 216 | if ( total_written != int(str.length() ) ) { |
217 | f.close(); | 217 | f.close(); |
218 | QFile::remove( strFileNew ); | 218 | QFile::remove( strFileNew ); |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | f.close(); | 221 | f.close(); |
222 | 222 | ||
223 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 223 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
224 | QFile::remove( strFileNew ); | 224 | QFile::remove( strFileNew ); |
225 | return false; | 225 | return false; |
226 | } | 226 | } |
227 | 227 | ||
228 | m_changed = false; | 228 | m_changed = false; |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
233 | uint i = 0; | 233 | uint i = 0; |
234 | QMap<int, OEvent>::ConstIterator it; | 234 | QMap<int, OEvent>::ConstIterator it; |
235 | 235 | ||
236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
237 | ints[i] = it.key(); | 237 | ints[i] = it.key(); |
238 | i++; | 238 | i++; |
239 | } | 239 | } |
240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
241 | ints[i] = it.key(); | 241 | ints[i] = it.key(); |
242 | i++; | 242 | i++; |
243 | } | 243 | } |
244 | 244 | ||
245 | return ints; | 245 | return ints; |
246 | } | 246 | } |
247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { | 247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { |
248 | return QArray<int>(); | 248 | return QArray<int>(); |
249 | } | 249 | } |
250 | void ODateBookAccessBackend_XML::clear() { | 250 | void ODateBookAccessBackend_XML::clear() { |
251 | m_changed = true; | 251 | m_changed = true; |
252 | m_raw.clear(); | 252 | m_raw.clear(); |
253 | m_rep.clear(); | 253 | m_rep.clear(); |
254 | } | 254 | } |
255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
256 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
257 | return m_raw[uid]; | 257 | return m_raw[uid]; |
258 | else | 258 | else |
259 | return m_rep[uid]; | 259 | return m_rep[uid]; |
260 | } | 260 | } |
261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
262 | m_changed = true; | 262 | m_changed = true; |
263 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
264 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
265 | else | 265 | else |
266 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
267 | 267 | ||
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
271 | m_changed = true; | 271 | m_changed = true; |
272 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
273 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
274 | 274 | ||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
279 | return add( ev ); | 279 | return add( ev ); |
280 | } | 280 | } |
281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
282 | return allRecords(); | 282 | return allRecords(); |
283 | } | 283 | } |
284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
285 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
286 | uint i = 0; | 286 | uint i = 0; |
287 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
288 | 288 | ||
289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
290 | ints[i] = it.key(); | 290 | ints[i] = it.key(); |
291 | i++; | 291 | i++; |
292 | } | 292 | } |
293 | 293 | ||
294 | return ints; | 294 | return ints; |
295 | } | 295 | } |
296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
297 | QArray<int> ints( m_raw.count() ); | 297 | QArray<int> ints( m_raw.count() ); |
298 | uint i = 0; | 298 | uint i = 0; |
299 | QMap<int, OEvent>::ConstIterator it; | 299 | QMap<int, OEvent>::ConstIterator it; |
300 | 300 | ||
301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
302 | ints[i] = it.key(); | 302 | ints[i] = it.key(); |
303 | i++; | 303 | i++; |
304 | } | 304 | } |
305 | 305 | ||
306 | return ints; | 306 | return ints; |
307 | } | 307 | } |
308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
309 | OEvent::ValueList list; | 309 | OEvent::ValueList list; |
310 | QMap<int, OEvent>::ConstIterator it; | 310 | QMap<int, OEvent>::ConstIterator it; |
311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
312 | list.append( it.data() ); | 312 | list.append( it.data() ); |
313 | 313 | ||
314 | return list; | 314 | return list; |
315 | } | 315 | } |
316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
317 | OEvent::ValueList list; | 317 | OEvent::ValueList list; |
318 | QMap<int, OEvent>::ConstIterator it; | 318 | QMap<int, OEvent>::ConstIterator it; |
319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
320 | list.append( it.data() ); | 320 | list.append( it.data() ); |
321 | 321 | ||
322 | return list; | 322 | return list; |
323 | } | 323 | } |
324 | bool ODateBookAccessBackend_XML::loadFile() { | 324 | bool ODateBookAccessBackend_XML::loadFile() { |
325 | m_changed = false; | 325 | m_changed = false; |
326 | 326 | ||
327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
328 | if ( fd < 0 ) return false; | 328 | if ( fd < 0 ) return false; |
329 | 329 | ||
330 | struct stat attribute; | 330 | struct stat attribute; |
331 | if ( ::fstat(fd, &attribute ) == -1 ) { | 331 | if ( ::fstat(fd, &attribute ) == -1 ) { |
332 | ::close( fd ); | 332 | ::close( fd ); |
333 | return false; | 333 | return false; |
334 | } | 334 | } |
335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
336 | if ( map_addr == ( (caddr_t)-1) ) { | 336 | if ( map_addr == ( (caddr_t)-1) ) { |
337 | ::close( fd ); | 337 | ::close( fd ); |
338 | return false; | 338 | return false; |
339 | } | 339 | } |
340 | 340 | ||
341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
342 | ::close( fd ); | 342 | ::close( fd ); |
343 | 343 | ||
344 | QAsciiDict<int> dict(FExceptions+1); | 344 | QAsciiDict<int> dict(FExceptions+1); |
345 | dict.setAutoDelete( true ); | 345 | dict.setAutoDelete( true ); |
346 | dict.insert( "description", new int(FDescription) ); | 346 | dict.insert( "description", new int(FDescription) ); |
347 | dict.insert( "location", new int(FLocation) ); | 347 | dict.insert( "location", new int(FLocation) ); |
348 | dict.insert( "categories", new int(FCategories) ); | 348 | dict.insert( "categories", new int(FCategories) ); |
349 | dict.insert( "uid", new int(FUid) ); | 349 | dict.insert( "uid", new int(FUid) ); |
350 | dict.insert( "type", new int(FType) ); | 350 | dict.insert( "type", new int(FType) ); |
351 | dict.insert( "alarm", new int(FAlarm) ); | 351 | dict.insert( "alarm", new int(FAlarm) ); |
352 | dict.insert( "sound", new int(FSound) ); | 352 | dict.insert( "sound", new int(FSound) ); |
353 | dict.insert( "rtype", new int(FRType) ); | 353 | dict.insert( "rtype", new int(FRType) ); |
354 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 354 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
355 | dict.insert( "rposition", new int(FRPosition) ); | 355 | dict.insert( "rposition", new int(FRPosition) ); |
356 | dict.insert( "rfreq", new int(FRFreq) ); | 356 | dict.insert( "rfreq", new int(FRFreq) ); |
357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
358 | dict.insert( "enddt", new int(FREndDate) ); | 358 | dict.insert( "enddt", new int(FREndDate) ); |
359 | dict.insert( "start", new int(FRStart) ); | 359 | dict.insert( "start", new int(FRStart) ); |
360 | dict.insert( "end", new int(FREnd) ); | 360 | dict.insert( "end", new int(FREnd) ); |
361 | dict.insert( "note", new int(FNote) ); | 361 | dict.insert( "note", new int(FNote) ); |
362 | dict.insert( "created", new int(FCreated) ); | 362 | dict.insert( "created", new int(FCreated) ); |
363 | dict.insert( "recparent", new int(FRecParent) ); | 363 | dict.insert( "recparent", new int(FRecParent) ); |
364 | dict.insert( "recchildren", new int(FRecChildren) ); | 364 | dict.insert( "recchildren", new int(FRecChildren) ); |
365 | dict.insert( "exceptions", new int(FExceptions) ); | 365 | dict.insert( "exceptions", new int(FExceptions) ); |
366 | dict.insert( "timezone", new int(FTimeZone) ); | 366 | dict.insert( "timezone", new int(FTimeZone) ); |
367 | 367 | ||
368 | char* dt = (char*)map_addr; | 368 | char* dt = (char*)map_addr; |
369 | int len = attribute.st_size; | 369 | int len = attribute.st_size; |
370 | int i = 0; | 370 | int i = 0; |
371 | char* point; | 371 | char* point; |
372 | const char* collectionString = "<event "; | 372 | const char* collectionString = "<event "; |
373 | int strLen = ::strlen(collectionString); | 373 | int strLen = ::strlen(collectionString); |
374 | int *find; | 374 | int *find; |
375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
376 | i = point -dt; | 376 | i = point -dt; |
377 | i+= strLen; | 377 | i+= strLen; |
378 | 378 | ||
379 | alarmTime = -1; | 379 | alarmTime = -1; |
380 | snd = 0; // silent | 380 | snd = 0; // silent |
381 | 381 | ||
382 | OEvent ev; | 382 | OEvent ev; |
383 | rec = 0; | 383 | rec = 0; |
384 | 384 | ||
385 | while ( TRUE ) { | 385 | while ( TRUE ) { |
386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
387 | ++i; | 387 | ++i; |
388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
389 | break; | 389 | break; |
390 | 390 | ||
391 | 391 | ||
392 | // we have another attribute, read it. | 392 | // we have another attribute, read it. |
393 | int j = i; | 393 | int j = i; |
394 | while ( j < len && dt[j] != '=' ) | 394 | while ( j < len && dt[j] != '=' ) |
395 | ++j; | 395 | ++j; |
396 | QCString attr( dt+i, j-i+1); | 396 | QCString attr( dt+i, j-i+1); |
397 | 397 | ||
398 | i = ++j; // skip = | 398 | i = ++j; // skip = |
399 | 399 | ||
400 | // find the start of quotes | 400 | // find the start of quotes |
401 | while ( i < len && dt[i] != '"' ) | 401 | while ( i < len && dt[i] != '"' ) |
402 | ++i; | 402 | ++i; |
403 | j = ++i; | 403 | j = ++i; |
404 | 404 | ||
405 | bool haveUtf = FALSE; | 405 | bool haveUtf = FALSE; |
406 | bool haveEnt = FALSE; | 406 | bool haveEnt = FALSE; |
407 | while ( j < len && dt[j] != '"' ) { | 407 | while ( j < len && dt[j] != '"' ) { |
408 | if ( ((unsigned char)dt[j]) > 0x7f ) | 408 | if ( ((unsigned char)dt[j]) > 0x7f ) |
409 | haveUtf = TRUE; | 409 | haveUtf = TRUE; |
410 | if ( dt[j] == '&' ) | 410 | if ( dt[j] == '&' ) |
411 | haveEnt = TRUE; | 411 | haveEnt = TRUE; |
412 | ++j; | 412 | ++j; |
413 | } | 413 | } |
414 | if ( i == j ) { | 414 | if ( i == j ) { |
415 | // empty value | 415 | // empty value |
416 | i = j + 1; | 416 | i = j + 1; |
417 | continue; | 417 | continue; |
418 | } | 418 | } |
419 | 419 | ||
420 | QCString value( dt+i, j-i+1 ); | 420 | QCString value( dt+i, j-i+1 ); |
421 | i = j + 1; | 421 | i = j + 1; |
422 | 422 | ||
423 | QString str = (haveUtf ? QString::fromUtf8( value ) | 423 | QString str = (haveUtf ? QString::fromUtf8( value ) |
424 | : QString::fromLatin1( value ) ); | 424 | : QString::fromLatin1( value ) ); |
425 | if ( haveEnt ) | 425 | if ( haveEnt ) |
426 | str = Qtopia::plainString( str ); | 426 | str = Qtopia::plainString( str ); |
427 | 427 | ||
428 | /* | 428 | /* |
429 | * add key + value | 429 | * add key + value |
430 | */ | 430 | */ |
431 | find = dict[attr.data()]; | 431 | find = dict[attr.data()]; |
432 | if (!find) | 432 | if (!find) |
433 | ev.setCustomField( attr, value ); | 433 | ev.setCustomField( attr, str ); |
434 | else { | 434 | else { |
435 | setField( ev, *find, value ); | 435 | setField( ev, *find, str ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | /* time to finalize */ | 438 | /* time to finalize */ |
439 | finalizeRecord( ev ); | 439 | finalizeRecord( ev ); |
440 | delete rec; | 440 | delete rec; |
441 | } | 441 | } |
442 | ::munmap(map_addr, attribute.st_size ); | 442 | ::munmap(map_addr, attribute.st_size ); |
443 | m_changed = false; // changed during add | 443 | m_changed = false; // changed during add |
444 | 444 | ||
445 | return true; | 445 | return true; |
446 | } | 446 | } |
447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
448 | /* AllDay is alway in UTC */ | 448 | /* AllDay is alway in UTC */ |
449 | if ( ev.isAllDay() ) { | 449 | if ( ev.isAllDay() ) { |
450 | OTimeZone utc = OTimeZone::utc(); | 450 | OTimeZone utc = OTimeZone::utc(); |
451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
453 | ev.setTimeZone( "UTC"); // make sure it is really utc | 453 | ev.setTimeZone( "UTC"); // make sure it is really utc |
454 | }else { | 454 | }else { |
455 | /* to current date time */ | 455 | /* to current date time */ |
456 | qWarning(" Start is %d", start ); | 456 | // qWarning(" Start is %d", start ); |
457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
458 | QDateTime date = zone.toDateTime( start ); | 458 | QDateTime date = zone.toDateTime( start ); |
459 | qWarning(" Start is %s", date.toString().latin1() ); | 459 | qWarning(" Start is %s", date.toString().latin1() ); |
460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
461 | 461 | ||
462 | date = zone.toDateTime( end ); | 462 | date = zone.toDateTime( end ); |
463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
464 | } | 464 | } |
465 | if ( rec && rec->doesRecur() ) { | 465 | if ( rec && rec->doesRecur() ) { |
466 | OTimeZone utc = OTimeZone::utc(); | 466 | OTimeZone utc = OTimeZone::utc(); |
467 | ORecur recu( *rec ); // call copy c'tor; | 467 | ORecur recu( *rec ); // call copy c'tor; |
468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
470 | recu.setStart( ev.startDateTime().date() ); | 470 | recu.setStart( ev.startDateTime().date() ); |
471 | ev.setRecurrence( recu ); | 471 | ev.setRecurrence( recu ); |
472 | } | 472 | } |
473 | 473 | ||
474 | if (alarmTime != -1 ) { | 474 | if (alarmTime != -1 ) { |
475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
476 | OPimAlarm al( snd , dt ); | 476 | OPimAlarm al( snd , dt ); |
477 | ev.notifiers().add( al ); | 477 | ev.notifiers().add( al ); |
478 | } | 478 | } |
479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
480 | qWarning("already contains assign uid"); | 480 | qWarning("already contains assign uid"); |
481 | ev.setUid( 1 ); | 481 | ev.setUid( 1 ); |
482 | } | 482 | } |
483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); | 483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); |
484 | if ( ev.hasRecurrence() ) | 484 | if ( ev.hasRecurrence() ) |
485 | m_rep.insert( ev.uid(), ev ); | 485 | m_rep.insert( ev.uid(), ev ); |
486 | else | 486 | else |
487 | m_raw.insert( ev.uid(), ev ); | 487 | m_raw.insert( ev.uid(), ev ); |
488 | 488 | ||
489 | } | 489 | } |
490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
491 | // qWarning(" setting %s", value.latin1() ); | 491 | // qWarning(" setting %s", value.latin1() ); |
492 | switch( id ) { | 492 | switch( id ) { |
493 | case FDescription: | 493 | case FDescription: |
494 | e.setDescription( value ); | 494 | e.setDescription( value ); |
495 | break; | 495 | break; |
496 | case FLocation: | 496 | case FLocation: |
497 | e.setLocation( value ); | 497 | e.setLocation( value ); |
498 | break; | 498 | break; |
499 | case FCategories: | 499 | case FCategories: |
500 | e.setCategories( e.idsFromString( value ) ); | 500 | e.setCategories( e.idsFromString( value ) ); |
501 | break; | 501 | break; |
502 | case FUid: | 502 | case FUid: |
503 | e.setUid( value.toInt() ); | 503 | e.setUid( value.toInt() ); |
504 | break; | 504 | break; |
505 | case FType: | 505 | case FType: |
506 | if ( value == "AllDay" ) { | 506 | if ( value == "AllDay" ) { |
507 | e.setAllDay( true ); | 507 | e.setAllDay( true ); |
508 | e.setTimeZone( "UTC" ); | 508 | e.setTimeZone( "UTC" ); |
509 | } | 509 | } |
510 | break; | 510 | break; |
511 | case FAlarm: | 511 | case FAlarm: |
512 | alarmTime = value.toInt(); | 512 | alarmTime = value.toInt(); |
513 | break; | 513 | break; |
514 | case FSound: | 514 | case FSound: |
515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
516 | break; | 516 | break; |
517 | // recurrence stuff | 517 | // recurrence stuff |
518 | case FRType: | 518 | case FRType: |
519 | if ( value == "Daily" ) | 519 | if ( value == "Daily" ) |
520 | recur()->setType( ORecur::Daily ); | 520 | recur()->setType( ORecur::Daily ); |
521 | else if ( value == "Weekly" ) | 521 | else if ( value == "Weekly" ) |
522 | recur()->setType( ORecur::Weekly); | 522 | recur()->setType( ORecur::Weekly); |
523 | else if ( value == "MonthlyDay" ) | 523 | else if ( value == "MonthlyDay" ) |
524 | recur()->setType( ORecur::MonthlyDay ); | 524 | recur()->setType( ORecur::MonthlyDay ); |
525 | else if ( value == "MonthlyDate" ) | 525 | else if ( value == "MonthlyDate" ) |
526 | recur()->setType( ORecur::MonthlyDate ); | 526 | recur()->setType( ORecur::MonthlyDate ); |
527 | else if ( value == "Yearly" ) | 527 | else if ( value == "Yearly" ) |
528 | recur()->setType( ORecur::Yearly ); | 528 | recur()->setType( ORecur::Yearly ); |
529 | else | 529 | else |
530 | recur()->setType( ORecur::NoRepeat ); | 530 | recur()->setType( ORecur::NoRepeat ); |
531 | break; | 531 | break; |
532 | case FRWeekdays: | 532 | case FRWeekdays: |
533 | recur()->setDays( value.toInt() ); | 533 | recur()->setDays( value.toInt() ); |
534 | break; | 534 | break; |
535 | case FRPosition: | 535 | case FRPosition: |
536 | recur()->setPosition( value.toInt() ); | 536 | recur()->setPosition( value.toInt() ); |
537 | break; | 537 | break; |
538 | case FRFreq: | 538 | case FRFreq: |
539 | recur()->setFrequency( value.toInt() ); | 539 | recur()->setFrequency( value.toInt() ); |
540 | break; | 540 | break; |
541 | case FRHasEndDate: | 541 | case FRHasEndDate: |
542 | recur()->setHasEndDate( value.toInt() ); | 542 | recur()->setHasEndDate( value.toInt() ); |
543 | break; | 543 | break; |
544 | case FREndDate: { | 544 | case FREndDate: { |
545 | rp_end = (time_t) value.toLong(); | 545 | rp_end = (time_t) value.toLong(); |
546 | break; | 546 | break; |
547 | } | 547 | } |
548 | case FRStart: { | 548 | case FRStart: { |
549 | start = (time_t) value.toLong(); | 549 | start = (time_t) value.toLong(); |
550 | break; | 550 | break; |
551 | } | 551 | } |
552 | case FREnd: { | 552 | case FREnd: { |
553 | end = ( (time_t) value.toLong() ); | 553 | end = ( (time_t) value.toLong() ); |
554 | break; | 554 | break; |
555 | } | 555 | } |
556 | case FNote: | 556 | case FNote: |
557 | e.setNote( value ); | 557 | e.setNote( value ); |
558 | break; | 558 | break; |
559 | case FCreated: | 559 | case FCreated: |
560 | created = value.toInt(); | 560 | created = value.toInt(); |
561 | break; | 561 | break; |
562 | case FRecParent: | 562 | case FRecParent: |
563 | e.setParent( value.toInt() ); | 563 | e.setParent( value.toInt() ); |
564 | break; | 564 | break; |
565 | case FRecChildren:{ | 565 | case FRecChildren:{ |
566 | QStringList list = QStringList::split(' ', value ); | 566 | QStringList list = QStringList::split(' ', value ); |
567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
568 | e.addChild( (*it).toInt() ); | 568 | e.addChild( (*it).toInt() ); |
569 | } | 569 | } |
570 | } | 570 | } |
571 | break; | 571 | break; |
572 | case FExceptions:{ | 572 | case FExceptions:{ |
573 | QStringList list = QStringList::split(' ', value ); | 573 | QStringList list = QStringList::split(' ', value ); |
574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
576 | qWarning("adding exception %s", date.toString().latin1() ); | 576 | qWarning("adding exception %s", date.toString().latin1() ); |
577 | recur()->exceptions().append( date ); | 577 | recur()->exceptions().append( date ); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | break; | 580 | break; |
581 | case FTimeZone: | 581 | case FTimeZone: |
582 | if ( value != "None" ) | 582 | if ( value != "None" ) |
583 | e.setTimeZone( value ); | 583 | e.setTimeZone( value ); |
584 | break; | 584 | break; |
585 | default: | 585 | default: |
586 | break; | 586 | break; |
587 | } | 587 | } |
588 | } | 588 | } |
589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
590 | { | 590 | { |
591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); | 591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); |
592 | uint arraycounter = 0; | 592 | uint arraycounter = 0; |
593 | QMap<int, OEvent>::ConstIterator it; | 593 | QMap<int, OEvent>::ConstIterator it; |
594 | 594 | ||
595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) | 595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) |
596 | if ( it.data().match( r ) ) | 596 | if ( it.data().match( r ) ) |
597 | m_currentQuery[arraycounter++] = it.data().uid(); | 597 | m_currentQuery[arraycounter++] = it.data().uid(); |
598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) | 598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) |
599 | if ( it.data().match( r ) ) | 599 | if ( it.data().match( r ) ) |
600 | m_currentQuery[arraycounter++] = it.data().uid(); | 600 | m_currentQuery[arraycounter++] = it.data().uid(); |
601 | 601 | ||
602 | // Shrink to fit.. | 602 | // Shrink to fit.. |
603 | m_currentQuery.resize(arraycounter); | 603 | m_currentQuery.resize(arraycounter); |
604 | 604 | ||
605 | return m_currentQuery; | 605 | return m_currentQuery; |
606 | } | 606 | } |
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index f4bbe35..c3d91f7 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h | |||
@@ -1,159 +1,159 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_BACKEND | 1 | #ifndef OPIE_PIM_ACCESS_BACKEND |
2 | #define OPIE_PIM_ACCESS_BACKEND | 2 | #define OPIE_PIM_ACCESS_BACKEND |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/otemplatebase.h> | 6 | #include <opie/otemplatebase.h> |
7 | #include <opie/opimrecord.h> | 7 | #include <opie/opimrecord.h> |
8 | 8 | ||
9 | 9 | ||
10 | class OPimAccessBackendPrivate; | ||
10 | /** | 11 | /** |
11 | * OPimAccessBackend is the base class | 12 | * OPimAccessBackend is the base class |
12 | * for all private backends | 13 | * for all private backends |
13 | * it operates on OPimRecord as the base class | 14 | * it operates on OPimRecord as the base class |
14 | * and it's responsible for fast manipulating | 15 | * and it's responsible for fast manipulating |
15 | * the resource the implementation takes care | 16 | * the resource the implementation takes care |
16 | * of | 17 | * of |
17 | */ | 18 | */ |
18 | template <class T = OPimRecord> | 19 | template <class T = OPimRecord> |
19 | class OPimAccessBackend { | 20 | class OPimAccessBackend { |
20 | public: | 21 | public: |
21 | typedef OTemplateBase<T> Frontend; | 22 | typedef OTemplateBase<T> Frontend; |
22 | 23 | ||
23 | /** The access hint from the frontend */ | 24 | /** The access hint from the frontend */ |
24 | OPimAccessBackend(int access = 0); | 25 | OPimAccessBackend(int access = 0); |
25 | virtual ~OPimAccessBackend(); | 26 | virtual ~OPimAccessBackend(); |
26 | 27 | ||
27 | /** | 28 | /** |
28 | * load the resource | 29 | * load the resource |
29 | */ | 30 | */ |
30 | virtual bool load() = 0; | 31 | virtual bool load() = 0; |
31 | 32 | ||
32 | /** | 33 | /** |
33 | * reload the resource | 34 | * reload the resource |
34 | */ | 35 | */ |
35 | virtual bool reload() = 0; | 36 | virtual bool reload() = 0; |
36 | 37 | ||
37 | /** | 38 | /** |
38 | * save the resource and | 39 | * save the resource and |
39 | * all it's changes | 40 | * all it's changes |
40 | */ | 41 | */ |
41 | virtual bool save() = 0; | 42 | virtual bool save() = 0; |
42 | 43 | ||
43 | /** | 44 | /** |
44 | * return an array of | 45 | * return an array of |
45 | * all available uids | 46 | * all available uids |
46 | */ | 47 | */ |
47 | virtual QArray<int> allRecords()const = 0; | 48 | virtual QArray<int> allRecords()const = 0; |
48 | 49 | ||
49 | /** | 50 | /** |
50 | * return a List of records | 51 | * return a List of records |
51 | * that match the regex | 52 | * that match the regex |
52 | */ | 53 | */ |
53 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; | 54 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * queryByExample for T with the given Settings | 57 | * queryByExample for T with the given Settings |
57 | * | 58 | * |
58 | */ | 59 | */ |
59 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; | 60 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * find the OPimRecord with uid @param uid | 63 | * find the OPimRecord with uid @param uid |
63 | * returns T and T.isEmpty() if nothing was found | 64 | * returns T and T.isEmpty() if nothing was found |
64 | */ | 65 | */ |
65 | virtual T find(int uid )const = 0; | 66 | virtual T find(int uid )const = 0; |
66 | 67 | ||
67 | virtual T find(int uid, const QArray<int>& items, | 68 | virtual T find(int uid, const QArray<int>& items, |
68 | uint current, typename Frontend::CacheDirection )const ; | 69 | uint current, typename Frontend::CacheDirection )const ; |
69 | /** | 70 | /** |
70 | * clear the back end | 71 | * clear the back end |
71 | */ | 72 | */ |
72 | virtual void clear() = 0; | 73 | virtual void clear() = 0; |
73 | 74 | ||
74 | /** | 75 | /** |
75 | * add T | 76 | * add T |
76 | */ | 77 | */ |
77 | virtual bool add( const T& t ) = 0; | 78 | virtual bool add( const T& t ) = 0; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * remove | 81 | * remove |
81 | */ | 82 | */ |
82 | virtual bool remove( int uid ) = 0; | 83 | virtual bool remove( int uid ) = 0; |
83 | 84 | ||
84 | /** | 85 | /** |
85 | * replace a record with T.uid() | 86 | * replace a record with T.uid() |
86 | */ | 87 | */ |
87 | virtual bool replace( const T& t ) = 0; | 88 | virtual bool replace( const T& t ) = 0; |
88 | 89 | ||
89 | /* | 90 | /* |
90 | * setTheFrontEnd!!! | 91 | * setTheFrontEnd!!! |
91 | */ | 92 | */ |
92 | void setFrontend( Frontend* front ); | 93 | void setFrontend( Frontend* front ); |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * set the read ahead count | 96 | * set the read ahead count |
96 | */ | 97 | */ |
97 | void setReadAhead( uint count ); | 98 | void setReadAhead( uint count ); |
98 | protected: | 99 | protected: |
99 | int access()const; | 100 | int access()const; |
100 | void cache( const T& t )const; | 101 | void cache( const T& t )const; |
101 | 102 | ||
102 | /** | 103 | /** |
103 | * use a prime number here! | 104 | * use a prime number here! |
104 | */ | 105 | */ |
105 | void setSaneCacheSize( int ); | 106 | void setSaneCacheSize( int ); |
106 | 107 | ||
107 | uint readAhead()const; | 108 | uint readAhead()const; |
108 | 109 | ||
109 | private: | 110 | private: |
110 | class Private; | 111 | OPimAccessBackendPrivate *d; |
111 | Private* d; | ||
112 | Frontend* m_front; | 112 | Frontend* m_front; |
113 | uint m_read; | 113 | uint m_read; |
114 | int m_acc; | 114 | int m_acc; |
115 | 115 | ||
116 | }; | 116 | }; |
117 | 117 | ||
118 | template <class T> | 118 | template <class T> |
119 | OPimAccessBackend<T>::OPimAccessBackend(int acc) | 119 | OPimAccessBackend<T>::OPimAccessBackend(int acc) |
120 | : m_acc( acc ) | 120 | : m_acc( acc ) |
121 | { | 121 | { |
122 | m_front = 0l; | 122 | m_front = 0l; |
123 | } | 123 | } |
124 | template <class T> | 124 | template <class T> |
125 | OPimAccessBackend<T>::~OPimAccessBackend() { | 125 | OPimAccessBackend<T>::~OPimAccessBackend() { |
126 | 126 | ||
127 | } | 127 | } |
128 | template <class T> | 128 | template <class T> |
129 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 129 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
130 | m_front = fr; | 130 | m_front = fr; |
131 | } | 131 | } |
132 | template <class T> | 132 | template <class T> |
133 | void OPimAccessBackend<T>::cache( const T& t )const { | 133 | void OPimAccessBackend<T>::cache( const T& t )const { |
134 | if (m_front ) | 134 | if (m_front ) |
135 | m_front->cache( t ); | 135 | m_front->cache( t ); |
136 | } | 136 | } |
137 | template <class T> | 137 | template <class T> |
138 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 138 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
139 | if (m_front ) | 139 | if (m_front ) |
140 | m_front->setSaneCacheSize( size ); | 140 | m_front->setSaneCacheSize( size ); |
141 | } | 141 | } |
142 | template <class T> | 142 | template <class T> |
143 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 143 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
144 | uint, typename Frontend::CacheDirection )const { | 144 | uint, typename Frontend::CacheDirection )const { |
145 | return find( uid ); | 145 | return find( uid ); |
146 | } | 146 | } |
147 | template <class T> | 147 | template <class T> |
148 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | 148 | void OPimAccessBackend<T>::setReadAhead( uint count ) { |
149 | m_read = count; | 149 | m_read = count; |
150 | } | 150 | } |
151 | template <class T> | 151 | template <class T> |
152 | uint OPimAccessBackend<T>::readAhead()const { | 152 | uint OPimAccessBackend<T>::readAhead()const { |
153 | return m_read; | 153 | return m_read; |
154 | } | 154 | } |
155 | template <class T> | 155 | template <class T> |
156 | int OPimAccessBackend<T>::access()const { | 156 | int OPimAccessBackend<T>::access()const { |
157 | return m_acc; | 157 | return m_acc; |
158 | } | 158 | } |
159 | #endif | 159 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h index 05e8ca9..6be95bc 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.h +++ b/libopie2/opiepim/backend/otodoaccessbackend.h | |||
@@ -1,24 +1,28 @@ | |||
1 | #ifndef OPIE_TODO_ACCESS_BACKEND_H | 1 | #ifndef OPIE_TODO_ACCESS_BACKEND_H |
2 | #define OPIE_TODO_ACCESS_BACKEND_H | 2 | #define OPIE_TODO_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qbitarray.h> | 4 | #include <qbitarray.h> |
5 | 5 | ||
6 | #include "otodo.h" | 6 | #include "otodo.h" |
7 | #include "opimaccessbackend.h" | 7 | #include "opimaccessbackend.h" |
8 | 8 | ||
9 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { | 9 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { |
10 | public: | 10 | public: |
11 | OTodoAccessBackend(); | 11 | OTodoAccessBackend(); |
12 | ~OTodoAccessBackend(); | 12 | ~OTodoAccessBackend(); |
13 | virtual QArray<int> effectiveToDos( const QDate& start, | 13 | virtual QArray<int> effectiveToDos( const QDate& start, |
14 | const QDate& end, | 14 | const QDate& end, |
15 | bool includeNoDates ) = 0; | 15 | bool includeNoDates ) = 0; |
16 | virtual QArray<int> overDue() = 0; | 16 | virtual QArray<int> overDue() = 0; |
17 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, | 17 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, |
18 | int cat ) = 0; | 18 | int cat ) = 0; |
19 | virtual void removeAllCompleted() = 0; | 19 | virtual void removeAllCompleted() = 0; |
20 | virtual QBitArray supports()const = 0; | 20 | virtual QBitArray supports()const = 0; |
21 | |||
22 | private: | ||
23 | class Private; | ||
24 | Private *d; | ||
21 | 25 | ||
22 | }; | 26 | }; |
23 | 27 | ||
24 | #endif | 28 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp index 3577e14..6415952 100644 --- a/libopie2/opiepim/backend/otodoaccessvcal.cpp +++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp | |||
@@ -1,225 +1,249 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | 2 | ||
3 | #include <qtopia/private/vobject_p.h> | 3 | #include <qtopia/private/vobject_p.h> |
4 | #include <qtopia/timeconversion.h> | 4 | #include <qtopia/timeconversion.h> |
5 | #include <qtopia/private/qfiledirect_p.h> | 5 | #include <qtopia/private/qfiledirect_p.h> |
6 | 6 | ||
7 | #include "otodoaccessvcal.h" | 7 | #include "otodoaccessvcal.h" |
8 | 8 | ||
9 | namespace { | 9 | namespace { |
10 | static OTodo eventByVObj( VObject *obj ){ | 10 | static OTodo eventByVObj( VObject *obj ){ |
11 | OTodo event; | 11 | OTodo event; |
12 | VObject *ob; | 12 | VObject *ob; |
13 | QCString name; | 13 | QCString name; |
14 | // no uid, attendees, ... and no fun | 14 | // no uid, attendees, ... and no fun |
15 | // description | 15 | // description |
16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | 16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ |
17 | name = vObjectStringZValue( ob ); | 17 | name = vObjectStringZValue( ob ); |
18 | #if 0 | ||
18 | event.setDescription( name ); | 19 | event.setDescription( name ); |
20 | #else | ||
21 | event.setSummary( name ); | ||
22 | #endif | ||
19 | } | 23 | } |
20 | // summary | 24 | // summary |
21 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { | 25 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { |
22 | name = vObjectStringZValue( ob ); | 26 | name = vObjectStringZValue( ob ); |
27 | #if 0 | ||
23 | event.setSummary( name ); | 28 | event.setSummary( name ); |
29 | #else | ||
30 | event.setDescription( name ); | ||
31 | #endif | ||
24 | } | 32 | } |
25 | // completed | 33 | // completed |
26 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | 34 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ |
27 | name = vObjectStringZValue( ob ); | 35 | name = vObjectStringZValue( ob ); |
28 | if( name == "COMPLETED" ){ | 36 | if( name == "COMPLETED" ){ |
29 | event.setCompleted( true ); | 37 | event.setCompleted( true ); |
30 | }else{ | 38 | }else{ |
31 | event.setCompleted( false ); | 39 | event.setCompleted( false ); |
32 | } | 40 | } |
33 | }else | 41 | }else |
34 | event.setCompleted( false ); | 42 | event.setCompleted( false ); |
35 | // priority | 43 | // priority |
36 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | 44 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { |
37 | name = vObjectStringZValue( ob ); | 45 | name = vObjectStringZValue( ob ); |
38 | bool ok; | 46 | bool ok; |
39 | event.setPriority(name.toInt(&ok) ); | 47 | event.setPriority(name.toInt(&ok) ); |
40 | } | 48 | } |
41 | //due date | 49 | //due date |
42 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | 50 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ |
43 | event.setHasDueDate( true ); | 51 | event.setHasDueDate( true ); |
44 | name = vObjectStringZValue( ob ); | 52 | name = vObjectStringZValue( ob ); |
45 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); | 53 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); |
46 | } | 54 | } |
47 | // categories | 55 | // categories |
48 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | 56 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ |
49 | name = vObjectStringZValue( ob ); | 57 | name = vObjectStringZValue( ob ); |
50 | qWarning("Categories:%s", name.data() ); | 58 | qWarning("Categories:%s", name.data() ); |
51 | } | 59 | } |
52 | 60 | ||
53 | event.setUid( 1 ); | 61 | event.setUid( 1 ); |
54 | return event; | 62 | return event; |
55 | }; | 63 | }; |
56 | static VObject *vobjByEvent( const OTodo &event ) { | 64 | static VObject *vobjByEvent( const OTodo &event ) { |
57 | VObject *task = newVObject( VCTodoProp ); | 65 | VObject *task = newVObject( VCTodoProp ); |
58 | if( task == 0 ) | 66 | if( task == 0 ) |
59 | return 0l; | 67 | return 0l; |
60 | 68 | ||
61 | if( event.hasDueDate() ) { | 69 | if( event.hasDueDate() ) { |
62 | QTime time(0, 0, 0); | 70 | QTime time(0, 0, 0); |
63 | QDateTime date(event.dueDate(), time ); | 71 | QDateTime date(event.dueDate(), time ); |
64 | addPropValue( task, VCDueProp, | 72 | addPropValue( task, VCDueProp, |
65 | TimeConversion::toISO8601( date ) ); | 73 | TimeConversion::toISO8601( date ) ); |
66 | } | 74 | } |
67 | 75 | ||
68 | if( event.isCompleted() ) | 76 | if( event.isCompleted() ) |
69 | addPropValue( task, VCStatusProp, "COMPLETED"); | 77 | addPropValue( task, VCStatusProp, "COMPLETED"); |
70 | 78 | ||
71 | QString string = QString::number(event.priority() ); | 79 | QString string = QString::number(event.priority() ); |
72 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | 80 | addPropValue( task, VCPriorityProp, string.local8Bit() ); |
73 | 81 | ||
74 | addPropValue( task, VCCategoriesProp, | 82 | addPropValue( task, VCCategoriesProp, |
75 | event.idsToString( event.categories() ).local8Bit() ); | 83 | event.idsToString( event.categories() ).local8Bit() ); |
76 | 84 | ||
85 | #if 0 | ||
86 | |||
87 | // There seems a misrepresentation between summary in otodoevent | ||
88 | // and summary in vcard. | ||
89 | // The same with description.. | ||
90 | // Description is summary and vice versa.. Argh.. (eilers) | ||
91 | |||
92 | |||
77 | addPropValue( task, VCDescriptionProp, | 93 | addPropValue( task, VCDescriptionProp, |
78 | event.description().local8Bit() ); | 94 | event.description().local8Bit() ); |
79 | 95 | ||
80 | addPropValue( task, VCSummaryProp, | 96 | addPropValue( task, VCSummaryProp, |
81 | event.summary().local8Bit() ); | 97 | event.summary().local8Bit() ); |
98 | |||
99 | #else | ||
100 | addPropValue( task, VCDescriptionProp, | ||
101 | event.summary().local8Bit() ); | ||
102 | |||
103 | addPropValue( task, VCSummaryProp, | ||
104 | event.description().local8Bit() ); | ||
105 | #endif | ||
82 | return task; | 106 | return task; |
83 | }; | 107 | }; |
84 | } | 108 | } |
85 | 109 | ||
86 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) | 110 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) |
87 | : m_dirty(false), m_file( path ) | 111 | : m_dirty(false), m_file( path ) |
88 | { | 112 | { |
89 | } | 113 | } |
90 | OTodoAccessVCal::~OTodoAccessVCal() { | 114 | OTodoAccessVCal::~OTodoAccessVCal() { |
91 | } | 115 | } |
92 | bool OTodoAccessVCal::load() { | 116 | bool OTodoAccessVCal::load() { |
93 | m_map.clear(); | 117 | m_map.clear(); |
94 | m_dirty = false; | 118 | m_dirty = false; |
95 | 119 | ||
96 | VObject* vcal = 0l; | 120 | VObject* vcal = 0l; |
97 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 121 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
98 | if (!vcal ) | 122 | if (!vcal ) |
99 | return false; | 123 | return false; |
100 | 124 | ||
101 | // Iterate over the list | 125 | // Iterate over the list |
102 | VObjectIterator it; | 126 | VObjectIterator it; |
103 | VObject* vobj; | 127 | VObject* vobj; |
104 | 128 | ||
105 | initPropIterator(&it, vcal); | 129 | initPropIterator(&it, vcal); |
106 | 130 | ||
107 | while( moreIteration( &it ) ) { | 131 | while( moreIteration( &it ) ) { |
108 | vobj = ::nextVObject( &it ); | 132 | vobj = ::nextVObject( &it ); |
109 | QCString name = ::vObjectName( vobj ); | 133 | QCString name = ::vObjectName( vobj ); |
110 | if( name == VCTodoProp ){ | 134 | if( name == VCTodoProp ){ |
111 | OTodo to = eventByVObj( vobj ); | 135 | OTodo to = eventByVObj( vobj ); |
112 | m_map.insert( to.uid(), to ); | 136 | m_map.insert( to.uid(), to ); |
113 | } | 137 | } |
114 | } | 138 | } |
115 | 139 | ||
116 | // Should I do a delete vcal? | 140 | // Should I do a delete vcal? |
117 | 141 | ||
118 | return true; | 142 | return true; |
119 | } | 143 | } |
120 | bool OTodoAccessVCal::reload() { | 144 | bool OTodoAccessVCal::reload() { |
121 | return load(); | 145 | return load(); |
122 | } | 146 | } |
123 | bool OTodoAccessVCal::save() { | 147 | bool OTodoAccessVCal::save() { |
124 | if (!m_dirty ) | 148 | if (!m_dirty ) |
125 | return true; | 149 | return true; |
126 | 150 | ||
127 | QFileDirect file( m_file ); | 151 | QFileDirect file( m_file ); |
128 | if (!file.open(IO_WriteOnly ) ) | 152 | if (!file.open(IO_WriteOnly ) ) |
129 | return false; | 153 | return false; |
130 | 154 | ||
131 | VObject *obj; | 155 | VObject *obj; |
132 | obj = newVObject( VCCalProp ); | 156 | obj = newVObject( VCCalProp ); |
133 | addPropValue( obj, VCVersionProp, "1.0" ); | 157 | addPropValue( obj, VCVersionProp, "1.0" ); |
134 | VObject *vo; | 158 | VObject *vo; |
135 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 159 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
136 | vo = vobjByEvent( it.data() ); | 160 | vo = vobjByEvent( it.data() ); |
137 | addVObjectProp(obj, vo ); | 161 | addVObjectProp(obj, vo ); |
138 | } | 162 | } |
139 | writeVObject( file.directHandle(), obj ); | 163 | writeVObject( file.directHandle(), obj ); |
140 | cleanVObject( obj ); | 164 | cleanVObject( obj ); |
141 | cleanStrTbl(); | 165 | cleanStrTbl(); |
142 | 166 | ||
143 | m_dirty = false; | 167 | m_dirty = false; |
144 | return true; | 168 | return true; |
145 | } | 169 | } |
146 | void OTodoAccessVCal::clear() { | 170 | void OTodoAccessVCal::clear() { |
147 | m_map.clear(); | 171 | m_map.clear(); |
148 | m_dirty = true; | 172 | m_dirty = true; |
149 | } | 173 | } |
150 | bool OTodoAccessVCal::add( const OTodo& to ) { | 174 | bool OTodoAccessVCal::add( const OTodo& to ) { |
151 | m_map.insert( to.uid(), to ); | 175 | m_map.insert( to.uid(), to ); |
152 | m_dirty = true; | 176 | m_dirty = true; |
153 | return true; | 177 | return true; |
154 | } | 178 | } |
155 | bool OTodoAccessVCal::remove( int uid ) { | 179 | bool OTodoAccessVCal::remove( int uid ) { |
156 | m_map.remove( uid ); | 180 | m_map.remove( uid ); |
157 | m_dirty = true; | 181 | m_dirty = true; |
158 | return true; | 182 | return true; |
159 | } | 183 | } |
160 | void OTodoAccessVCal::removeAllCompleted() { | 184 | void OTodoAccessVCal::removeAllCompleted() { |
161 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { | 185 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { |
162 | if ( (*it).isCompleted() ) | 186 | if ( (*it).isCompleted() ) |
163 | m_map.remove( it ); | 187 | m_map.remove( it ); |
164 | } | 188 | } |
165 | } | 189 | } |
166 | bool OTodoAccessVCal::replace( const OTodo& to ) { | 190 | bool OTodoAccessVCal::replace( const OTodo& to ) { |
167 | m_map.replace( to.uid(), to ); | 191 | m_map.replace( to.uid(), to ); |
168 | m_dirty = true; | 192 | m_dirty = true; |
169 | return true; | 193 | return true; |
170 | } | 194 | } |
171 | OTodo OTodoAccessVCal::find(int uid )const { | 195 | OTodo OTodoAccessVCal::find(int uid )const { |
172 | return m_map[uid]; | 196 | return m_map[uid]; |
173 | } | 197 | } |
174 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { | 198 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { |
175 | QArray<int> ar(0); | 199 | QArray<int> ar(0); |
176 | return ar; | 200 | return ar; |
177 | } | 201 | } |
178 | QArray<int> OTodoAccessVCal::allRecords()const { | 202 | QArray<int> OTodoAccessVCal::allRecords()const { |
179 | QArray<int> ar( m_map.count() ); | 203 | QArray<int> ar( m_map.count() ); |
180 | QMap<int, OTodo>::ConstIterator it; | 204 | QMap<int, OTodo>::ConstIterator it; |
181 | int i = 0; | 205 | int i = 0; |
182 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 206 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
183 | ar[i] = it.key(); | 207 | ar[i] = it.key(); |
184 | i++; | 208 | i++; |
185 | } | 209 | } |
186 | return ar; | 210 | return ar; |
187 | } | 211 | } |
188 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp &r)const { | 212 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { |
189 | QArray<int> ar(0); | 213 | QArray<int> ar(0); |
190 | return ar; | 214 | return ar; |
191 | } | 215 | } |
192 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { | 216 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { |
193 | QArray<int> ar(0); | 217 | QArray<int> ar(0); |
194 | return ar; | 218 | return ar; |
195 | } | 219 | } |
196 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , | 220 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , |
197 | const QDate& , | 221 | const QDate& , |
198 | bool ) { | 222 | bool ) { |
199 | QArray<int> ar(0); | 223 | QArray<int> ar(0); |
200 | return ar; | 224 | return ar; |
201 | } | 225 | } |
202 | QArray<int> OTodoAccessVCal::overDue() { | 226 | QArray<int> OTodoAccessVCal::overDue() { |
203 | QArray<int> ar(0); | 227 | QArray<int> ar(0); |
204 | return ar; | 228 | return ar; |
205 | } | 229 | } |
206 | QBitArray OTodoAccessVCal::supports()const { | 230 | QBitArray OTodoAccessVCal::supports()const { |
207 | static QBitArray ar = sup(); | 231 | static QBitArray ar = sup(); |
208 | 232 | ||
209 | return ar; | 233 | return ar; |
210 | } | 234 | } |
211 | QBitArray OTodoAccessVCal::sup() { | 235 | QBitArray OTodoAccessVCal::sup() { |
212 | QBitArray ar ( OTodo::CompletedDate +1 ); | 236 | QBitArray ar ( OTodo::CompletedDate +1 ); |
213 | ar.fill( true ); | 237 | ar.fill( true ); |
214 | 238 | ||
215 | ar[OTodo::CrossReference] = false; | 239 | ar[OTodo::CrossReference] = false; |
216 | ar[OTodo::State ] = false; | 240 | ar[OTodo::State ] = false; |
217 | ar[OTodo::Reminders] = false; | 241 | ar[OTodo::Reminders] = false; |
218 | ar[OTodo::Notifiers] = false; | 242 | ar[OTodo::Notifiers] = false; |
219 | ar[OTodo::Maintainer] = false; | 243 | ar[OTodo::Maintainer] = false; |
220 | ar[OTodo::Progress] = false; | 244 | ar[OTodo::Progress] = false; |
221 | ar[OTodo::Alarms ] = false; | 245 | ar[OTodo::Alarms ] = false; |
222 | ar[OTodo::Recurrence] = false; | 246 | ar[OTodo::Recurrence] = false; |
223 | 247 | ||
224 | return ar; | 248 | return ar; |
225 | } | 249 | } |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 3d15354..f688735 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,874 +1,876 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <sys/mman.h> | 4 | #include <sys/mman.h> |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
7 | 7 | ||
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qvector.h> | 12 | #include <qvector.h> |
13 | 13 | ||
14 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
15 | #include <qpe/stringutil.h> | 15 | #include <qpe/stringutil.h> |
16 | #include <qpe/timeconversion.h> | 16 | #include <qpe/timeconversion.h> |
17 | 17 | ||
18 | #include "oconversion.h" | 18 | #include "oconversion.h" |
19 | #include "opimstate.h" | 19 | #include "opimstate.h" |
20 | #include "otimezone.h" | 20 | #include "otimezone.h" |
21 | #include "opimnotifymanager.h" | 21 | #include "opimnotifymanager.h" |
22 | #include "orecur.h" | 22 | #include "orecur.h" |
23 | #include "otodoaccessxml.h" | 23 | #include "otodoaccessxml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | time_t rp_end; | 26 | time_t rp_end; |
27 | ORecur* rec; | 27 | ORecur* rec; |
28 | ORecur *recur() { | 28 | ORecur *recur() { |
29 | if (!rec ) rec = new ORecur; | 29 | if (!rec ) rec = new ORecur; |
30 | return rec; | 30 | return rec; |
31 | } | 31 | } |
32 | int snd; | 32 | int snd; |
33 | enum MoreAttributes { | 33 | enum MoreAttributes { |
34 | FRType = OTodo::CompletedDate + 2, | 34 | FRType = OTodo::CompletedDate + 2, |
35 | FRWeekdays, | 35 | FRWeekdays, |
36 | FRPosition, | 36 | FRPosition, |
37 | FRFreq, | 37 | FRFreq, |
38 | FRHasEndDate, | 38 | FRHasEndDate, |
39 | FREndDate, | 39 | FREndDate, |
40 | FRStart, | 40 | FRStart, |
41 | FREnd | 41 | FREnd |
42 | }; | 42 | }; |
43 | // FROM TT again | 43 | // FROM TT again |
44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
45 | { | 45 | { |
46 | char needleChar; | 46 | char needleChar; |
47 | char haystackChar; | 47 | char haystackChar; |
48 | if (!needle || !haystack || !hLen || !nLen) | 48 | if (!needle || !haystack || !hLen || !nLen) |
49 | return 0; | 49 | return 0; |
50 | 50 | ||
51 | const char* hsearch = haystack; | 51 | const char* hsearch = haystack; |
52 | 52 | ||
53 | if ((needleChar = *needle++) != 0) { | 53 | if ((needleChar = *needle++) != 0) { |
54 | nLen--; //(to make up for needle++) | 54 | nLen--; //(to make up for needle++) |
55 | do { | 55 | do { |
56 | do { | 56 | do { |
57 | if ((haystackChar = *hsearch++) == 0) | 57 | if ((haystackChar = *hsearch++) == 0) |
58 | return (0); | 58 | return (0); |
59 | if (hsearch >= haystack + hLen) | 59 | if (hsearch >= haystack + hLen) |
60 | return (0); | 60 | return (0); |
61 | } while (haystackChar != needleChar); | 61 | } while (haystackChar != needleChar); |
62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
63 | hsearch--; | 63 | hsearch--; |
64 | } | 64 | } |
65 | return ((char *)hsearch); | 65 | return ((char *)hsearch); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
71 | const QString& fileName ) | 71 | const QString& fileName ) |
72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
73 | { | 73 | { |
74 | if (!fileName.isEmpty() ) | 74 | if (!fileName.isEmpty() ) |
75 | m_file = fileName; | 75 | m_file = fileName; |
76 | else | 76 | else |
77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
78 | } | 78 | } |
79 | OTodoAccessXML::~OTodoAccessXML() { | 79 | OTodoAccessXML::~OTodoAccessXML() { |
80 | 80 | ||
81 | } | 81 | } |
82 | bool OTodoAccessXML::load() { | 82 | bool OTodoAccessXML::load() { |
83 | rec = 0; | 83 | rec = 0; |
84 | m_opened = true; | 84 | m_opened = true; |
85 | m_changed = false; | 85 | m_changed = false; |
86 | /* initialize dict */ | 86 | /* initialize dict */ |
87 | /* | 87 | /* |
88 | * UPDATE dict if you change anything!!! | 88 | * UPDATE dict if you change anything!!! |
89 | */ | 89 | */ |
90 | QAsciiDict<int> dict(21); | 90 | QAsciiDict<int> dict(26); |
91 | dict.setAutoDelete( TRUE ); | 91 | dict.setAutoDelete( TRUE ); |
92 | dict.insert("Categories" , new int(OTodo::Category) ); | 92 | dict.insert("Categories" , new int(OTodo::Category) ); |
93 | dict.insert("Uid" , new int(OTodo::Uid) ); | 93 | dict.insert("Uid" , new int(OTodo::Uid) ); |
94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
95 | dict.insert("Completed" , new int(OTodo::Completed) ); | 95 | dict.insert("Completed" , new int(OTodo::Completed) ); |
96 | dict.insert("Description" , new int(OTodo::Description) ); | 96 | dict.insert("Description" , new int(OTodo::Description) ); |
97 | dict.insert("Summary" , new int(OTodo::Summary) ); | 97 | dict.insert("Summary" , new int(OTodo::Summary) ); |
98 | dict.insert("Priority" , new int(OTodo::Priority) ); | 98 | dict.insert("Priority" , new int(OTodo::Priority) ); |
99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
102 | dict.insert("Progress" , new int(OTodo::Progress) ); | 102 | dict.insert("Progress" , new int(OTodo::Progress) ); |
103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); | 103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); |
104 | dict.insert("StartDate", new int(OTodo::StartDate) ); | 104 | dict.insert("StartDate", new int(OTodo::StartDate) ); |
105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
106 | dict.insert("State", new int(OTodo::State) ); | 106 | dict.insert("State", new int(OTodo::State) ); |
107 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 107 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
108 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 108 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
111 | dict.insert("rtype", new int(FRType) ); | 111 | dict.insert("rtype", new int(FRType) ); |
112 | dict.insert("rweekdays", new int(FRWeekdays) ); | 112 | dict.insert("rweekdays", new int(FRWeekdays) ); |
113 | dict.insert("rposition", new int(FRPosition) ); | 113 | dict.insert("rposition", new int(FRPosition) ); |
114 | dict.insert("rfreq", new int(FRFreq) ); | 114 | dict.insert("rfreq", new int(FRFreq) ); |
115 | dict.insert("start", new int(FRStart) ); | 115 | dict.insert("start", new int(FRStart) ); |
116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
117 | dict.insert("enddt", new int(FREndDate) ); | 117 | dict.insert("enddt", new int(FREndDate) ); |
118 | 118 | ||
119 | // here the custom XML parser from TT it's GPL | 119 | // here the custom XML parser from TT it's GPL |
120 | // but we want to push OpiePIM... to TT..... | 120 | // but we want to push OpiePIM... to TT..... |
121 | // mmap part from zecke :) | 121 | // mmap part from zecke :) |
122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); | 122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
123 | struct stat attribut; | 123 | struct stat attribut; |
124 | if ( fd < 0 ) return false; | 124 | if ( fd < 0 ) return false; |
125 | 125 | ||
126 | if ( fstat(fd, &attribut ) == -1 ) { | 126 | if ( fstat(fd, &attribut ) == -1 ) { |
127 | ::close( fd ); | 127 | ::close( fd ); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
131 | if ( map_addr == ( (caddr_t)-1) ) { | 131 | if ( map_addr == ( (caddr_t)-1) ) { |
132 | ::close(fd ); | 132 | ::close(fd ); |
133 | return false; | 133 | return false; |
134 | } | 134 | } |
135 | /* advise the kernel who we want to read it */ | 135 | /* advise the kernel who we want to read it */ |
136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | 136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); |
137 | /* we do not the file any more */ | 137 | /* we do not the file any more */ |
138 | ::close( fd ); | 138 | ::close( fd ); |
139 | 139 | ||
140 | char* dt = (char*)map_addr; | 140 | char* dt = (char*)map_addr; |
141 | int len = attribut.st_size; | 141 | int len = attribut.st_size; |
142 | int i = 0; | 142 | int i = 0; |
143 | char *point; | 143 | char *point; |
144 | const char* collectionString = "<Task "; | 144 | const char* collectionString = "<Task "; |
145 | int strLen = strlen(collectionString); | 145 | int strLen = strlen(collectionString); |
146 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { | 146 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { |
147 | i = point -dt; | 147 | i = point -dt; |
148 | i+= strLen; | 148 | i+= strLen; |
149 | qWarning("Found a start at %d %d", i, (point-dt) ); | 149 | qWarning("Found a start at %d %d", i, (point-dt) ); |
150 | 150 | ||
151 | OTodo ev; | 151 | OTodo ev; |
152 | m_year = m_month = m_day = 0; | 152 | m_year = m_month = m_day = 0; |
153 | 153 | ||
154 | while ( TRUE ) { | 154 | while ( TRUE ) { |
155 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 155 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
156 | ++i; | 156 | ++i; |
157 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 157 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
158 | break; | 158 | break; |
159 | 159 | ||
160 | // we have another attribute, read it. | 160 | // we have another attribute, read it. |
161 | int j = i; | 161 | int j = i; |
162 | while ( j < len && dt[j] != '=' ) | 162 | while ( j < len && dt[j] != '=' ) |
163 | ++j; | 163 | ++j; |
164 | QCString attr( dt+i, j-i+1); | 164 | QCString attr( dt+i, j-i+1); |
165 | 165 | ||
166 | i = ++j; // skip = | 166 | i = ++j; // skip = |
167 | 167 | ||
168 | // find the start of quotes | 168 | // find the start of quotes |
169 | while ( i < len && dt[i] != '"' ) | 169 | while ( i < len && dt[i] != '"' ) |
170 | ++i; | 170 | ++i; |
171 | j = ++i; | 171 | j = ++i; |
172 | 172 | ||
173 | bool haveUtf = FALSE; | 173 | bool haveUtf = FALSE; |
174 | bool haveEnt = FALSE; | 174 | bool haveEnt = FALSE; |
175 | while ( j < len && dt[j] != '"' ) { | 175 | while ( j < len && dt[j] != '"' ) { |
176 | if ( ((unsigned char)dt[j]) > 0x7f ) | 176 | if ( ((unsigned char)dt[j]) > 0x7f ) |
177 | haveUtf = TRUE; | 177 | haveUtf = TRUE; |
178 | if ( dt[j] == '&' ) | 178 | if ( dt[j] == '&' ) |
179 | haveEnt = TRUE; | 179 | haveEnt = TRUE; |
180 | ++j; | 180 | ++j; |
181 | } | 181 | } |
182 | if ( i == j ) { | 182 | if ( i == j ) { |
183 | // empty value | 183 | // empty value |
184 | i = j + 1; | 184 | i = j + 1; |
185 | continue; | 185 | continue; |
186 | } | 186 | } |
187 | 187 | ||
188 | QCString value( dt+i, j-i+1 ); | 188 | QCString value( dt+i, j-i+1 ); |
189 | i = j + 1; | 189 | i = j + 1; |
190 | 190 | ||
191 | QString str = (haveUtf ? QString::fromUtf8( value ) | 191 | QString str = (haveUtf ? QString::fromUtf8( value ) |
192 | : QString::fromLatin1( value ) ); | 192 | : QString::fromLatin1( value ) ); |
193 | if ( haveEnt ) | 193 | if ( haveEnt ) |
194 | str = Qtopia::plainString( str ); | 194 | str = Qtopia::plainString( str ); |
195 | 195 | ||
196 | /* | 196 | /* |
197 | * add key + value | 197 | * add key + value |
198 | */ | 198 | */ |
199 | todo( &dict, ev, attr, str ); | 199 | todo( &dict, ev, attr, str ); |
200 | 200 | ||
201 | } | 201 | } |
202 | /* | 202 | /* |
203 | * now add it | 203 | * now add it |
204 | */ | 204 | */ |
205 | qWarning("End at %d", i ); | 205 | qWarning("End at %d", i ); |
206 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 206 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
207 | ev.setUid( 1 ); | 207 | ev.setUid( 1 ); |
208 | m_changed = true; | 208 | m_changed = true; |
209 | } | 209 | } |
210 | if ( ev.hasDueDate() ) { | 210 | if ( ev.hasDueDate() ) { |
211 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 211 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
212 | } | 212 | } |
213 | if ( rec && rec->doesRecur() ) { | 213 | if ( rec && rec->doesRecur() ) { |
214 | OTimeZone utc = OTimeZone::utc(); | 214 | OTimeZone utc = OTimeZone::utc(); |
215 | ORecur recu( *rec ); // call copy c'tor | 215 | ORecur recu( *rec ); // call copy c'tor |
216 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); | 216 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); |
217 | recu.setStart( ev.dueDate() ); | 217 | recu.setStart( ev.dueDate() ); |
218 | ev.setRecurrence( recu ); | 218 | ev.setRecurrence( recu ); |
219 | } | 219 | } |
220 | m_events.insert(ev.uid(), ev ); | 220 | m_events.insert(ev.uid(), ev ); |
221 | m_year = m_month = m_day = -1; | 221 | m_year = m_month = m_day = -1; |
222 | delete rec; | 222 | delete rec; |
223 | rec = 0; | 223 | rec = 0; |
224 | } | 224 | } |
225 | 225 | ||
226 | munmap(map_addr, attribut.st_size ); | 226 | munmap(map_addr, attribut.st_size ); |
227 | 227 | ||
228 | qWarning("counts %d records loaded!", m_events.count() ); | 228 | qWarning("counts %d records loaded!", m_events.count() ); |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | bool OTodoAccessXML::reload() { | 231 | bool OTodoAccessXML::reload() { |
232 | m_events.clear(); | 232 | m_events.clear(); |
233 | return load(); | 233 | return load(); |
234 | } | 234 | } |
235 | bool OTodoAccessXML::save() { | 235 | bool OTodoAccessXML::save() { |
236 | // qWarning("saving"); | 236 | // qWarning("saving"); |
237 | if (!m_opened || !m_changed ) { | 237 | if (!m_opened || !m_changed ) { |
238 | // qWarning("not saving"); | 238 | // qWarning("not saving"); |
239 | return true; | 239 | return true; |
240 | } | 240 | } |
241 | QString strNewFile = m_file + ".new"; | 241 | QString strNewFile = m_file + ".new"; |
242 | QFile f( strNewFile ); | 242 | QFile f( strNewFile ); |
243 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 243 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
244 | return false; | 244 | return false; |
245 | 245 | ||
246 | int written; | 246 | int written; |
247 | QString out; | 247 | QString out; |
248 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 248 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
249 | 249 | ||
250 | // for all todos | 250 | // for all todos |
251 | QMap<int, OTodo>::Iterator it; | 251 | QMap<int, OTodo>::Iterator it; |
252 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 252 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
253 | out+= "<Task " + toString( (*it) ) + " />\n"; | 253 | out+= "<Task " + toString( (*it) ) + " />\n"; |
254 | QCString cstr = out.utf8(); | 254 | QCString cstr = out.utf8(); |
255 | written = f.writeBlock( cstr.data(), cstr.length() ); | 255 | written = f.writeBlock( cstr.data(), cstr.length() ); |
256 | 256 | ||
257 | /* less written then we wanted */ | 257 | /* less written then we wanted */ |
258 | if ( written != (int)cstr.length() ) { | 258 | if ( written != (int)cstr.length() ) { |
259 | f.close(); | 259 | f.close(); |
260 | QFile::remove( strNewFile ); | 260 | QFile::remove( strNewFile ); |
261 | return false; | 261 | return false; |
262 | } | 262 | } |
263 | out = QString::null; | 263 | out = QString::null; |
264 | } | 264 | } |
265 | 265 | ||
266 | out += "</Tasks>"; | 266 | out += "</Tasks>"; |
267 | QCString cstr = out.utf8(); | 267 | QCString cstr = out.utf8(); |
268 | written = f.writeBlock( cstr.data(), cstr.length() ); | 268 | written = f.writeBlock( cstr.data(), cstr.length() ); |
269 | 269 | ||
270 | if ( written != (int)cstr.length() ) { | 270 | if ( written != (int)cstr.length() ) { |
271 | f.close(); | 271 | f.close(); |
272 | QFile::remove( strNewFile ); | 272 | QFile::remove( strNewFile ); |
273 | return false; | 273 | return false; |
274 | } | 274 | } |
275 | /* flush before renaming */ | 275 | /* flush before renaming */ |
276 | f.close(); | 276 | f.close(); |
277 | 277 | ||
278 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 278 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
279 | // qWarning("error renaming"); | 279 | // qWarning("error renaming"); |
280 | QFile::remove( strNewFile ); | 280 | QFile::remove( strNewFile ); |
281 | } | 281 | } |
282 | 282 | ||
283 | m_changed = false; | 283 | m_changed = false; |
284 | return true; | 284 | return true; |
285 | } | 285 | } |
286 | QArray<int> OTodoAccessXML::allRecords()const { | 286 | QArray<int> OTodoAccessXML::allRecords()const { |
287 | QArray<int> ids( m_events.count() ); | 287 | QArray<int> ids( m_events.count() ); |
288 | QMap<int, OTodo>::ConstIterator it; | 288 | QMap<int, OTodo>::ConstIterator it; |
289 | int i = 0; | 289 | int i = 0; |
290 | 290 | ||
291 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 291 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
292 | ids[i] = it.key(); | 292 | ids[i] = it.key(); |
293 | i++; | 293 | i++; |
294 | } | 294 | } |
295 | return ids; | 295 | return ids; |
296 | } | 296 | } |
297 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { | 297 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { |
298 | QArray<int> ids(0); | 298 | QArray<int> ids(0); |
299 | return ids; | 299 | return ids; |
300 | } | 300 | } |
301 | OTodo OTodoAccessXML::find( int uid )const { | 301 | OTodo OTodoAccessXML::find( int uid )const { |
302 | OTodo todo; | 302 | OTodo todo; |
303 | todo.setUid( 0 ); // isEmpty() | 303 | todo.setUid( 0 ); // isEmpty() |
304 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); | 304 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); |
305 | if ( it != m_events.end() ) | 305 | if ( it != m_events.end() ) |
306 | todo = it.data(); | 306 | todo = it.data(); |
307 | 307 | ||
308 | return todo; | 308 | return todo; |
309 | } | 309 | } |
310 | void OTodoAccessXML::clear() { | 310 | void OTodoAccessXML::clear() { |
311 | if (m_opened ) | 311 | if (m_opened ) |
312 | m_changed = true; | 312 | m_changed = true; |
313 | 313 | ||
314 | m_events.clear(); | 314 | m_events.clear(); |
315 | } | 315 | } |
316 | bool OTodoAccessXML::add( const OTodo& todo ) { | 316 | bool OTodoAccessXML::add( const OTodo& todo ) { |
317 | // qWarning("add"); | 317 | // qWarning("add"); |
318 | m_changed = true; | 318 | m_changed = true; |
319 | m_events.insert( todo.uid(), todo ); | 319 | m_events.insert( todo.uid(), todo ); |
320 | 320 | ||
321 | return true; | 321 | return true; |
322 | } | 322 | } |
323 | bool OTodoAccessXML::remove( int uid ) { | 323 | bool OTodoAccessXML::remove( int uid ) { |
324 | m_changed = true; | 324 | m_changed = true; |
325 | m_events.remove( uid ); | 325 | m_events.remove( uid ); |
326 | 326 | ||
327 | return true; | 327 | return true; |
328 | } | 328 | } |
329 | bool OTodoAccessXML::replace( const OTodo& todo) { | 329 | bool OTodoAccessXML::replace( const OTodo& todo) { |
330 | m_changed = true; | 330 | m_changed = true; |
331 | m_events.replace( todo.uid(), todo ); | 331 | m_events.replace( todo.uid(), todo ); |
332 | 332 | ||
333 | return true; | 333 | return true; |
334 | } | 334 | } |
335 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, | 335 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, |
336 | const QDate& end, | 336 | const QDate& end, |
337 | bool includeNoDates ) { | 337 | bool includeNoDates ) { |
338 | QArray<int> ids( m_events.count() ); | 338 | QArray<int> ids( m_events.count() ); |
339 | QMap<int, OTodo>::Iterator it; | 339 | QMap<int, OTodo>::Iterator it; |
340 | 340 | ||
341 | int i = 0; | 341 | int i = 0; |
342 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 342 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
343 | if ( !it.data().hasDueDate() ) { | 343 | if ( !it.data().hasDueDate() ) { |
344 | if ( includeNoDates ) { | 344 | if ( includeNoDates ) { |
345 | ids[i] = it.key(); | 345 | ids[i] = it.key(); |
346 | i++; | 346 | i++; |
347 | } | 347 | } |
348 | }else if ( it.data().dueDate() >= start && | 348 | }else if ( it.data().dueDate() >= start && |
349 | it.data().dueDate() <= end ) { | 349 | it.data().dueDate() <= end ) { |
350 | ids[i] = it.key(); | 350 | ids[i] = it.key(); |
351 | i++; | 351 | i++; |
352 | } | 352 | } |
353 | } | 353 | } |
354 | ids.resize( i ); | 354 | ids.resize( i ); |
355 | return ids; | 355 | return ids; |
356 | } | 356 | } |
357 | QArray<int> OTodoAccessXML::overDue() { | 357 | QArray<int> OTodoAccessXML::overDue() { |
358 | QArray<int> ids( m_events.count() ); | 358 | QArray<int> ids( m_events.count() ); |
359 | int i = 0; | 359 | int i = 0; |
360 | 360 | ||
361 | QMap<int, OTodo>::Iterator it; | 361 | QMap<int, OTodo>::Iterator it; |
362 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 362 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
363 | if ( it.data().isOverdue() ) { | 363 | if ( it.data().isOverdue() ) { |
364 | ids[i] = it.key(); | 364 | ids[i] = it.key(); |
365 | i++; | 365 | i++; |
366 | } | 366 | } |
367 | } | 367 | } |
368 | ids.resize( i ); | 368 | ids.resize( i ); |
369 | return ids; | 369 | return ids; |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | /* private */ | 373 | /* private */ |
374 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | 374 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, |
375 | const QCString& attr, const QString& val) { | 375 | const QCString& attr, const QString& val) { |
376 | // qWarning("parse to do from XMLElement" ); | 376 | // qWarning("parse to do from XMLElement" ); |
377 | 377 | ||
378 | int *find=0; | 378 | int *find=0; |
379 | 379 | ||
380 | find = (*dict)[ attr.data() ]; | 380 | find = (*dict)[ attr.data() ]; |
381 | if (!find ) { | 381 | if (!find ) { |
382 | // qWarning("Unknown option" + it.key() ); | 382 | // qWarning("Unknown option" + it.key() ); |
383 | ev.setCustomField( attr, val ); | 383 | ev.setCustomField( attr, val ); |
384 | return; | 384 | return; |
385 | } | 385 | } |
386 | 386 | ||
387 | switch( *find ) { | 387 | switch( *find ) { |
388 | case OTodo::Uid: | 388 | case OTodo::Uid: |
389 | ev.setUid( val.toInt() ); | 389 | ev.setUid( val.toInt() ); |
390 | break; | 390 | break; |
391 | case OTodo::Category: | 391 | case OTodo::Category: |
392 | ev.setCategories( ev.idsFromString( val ) ); | 392 | ev.setCategories( ev.idsFromString( val ) ); |
393 | break; | 393 | break; |
394 | case OTodo::HasDate: | 394 | case OTodo::HasDate: |
395 | ev.setHasDueDate( val.toInt() ); | 395 | ev.setHasDueDate( val.toInt() ); |
396 | break; | 396 | break; |
397 | case OTodo::Completed: | 397 | case OTodo::Completed: |
398 | ev.setCompleted( val.toInt() ); | 398 | ev.setCompleted( val.toInt() ); |
399 | break; | 399 | break; |
400 | case OTodo::Description: | 400 | case OTodo::Description: |
401 | ev.setDescription( val ); | 401 | ev.setDescription( val ); |
402 | break; | 402 | break; |
403 | case OTodo::Summary: | 403 | case OTodo::Summary: |
404 | ev.setSummary( val ); | 404 | ev.setSummary( val ); |
405 | break; | 405 | break; |
406 | case OTodo::Priority: | 406 | case OTodo::Priority: |
407 | ev.setPriority( val.toInt() ); | 407 | ev.setPriority( val.toInt() ); |
408 | break; | 408 | break; |
409 | case OTodo::DateDay: | 409 | case OTodo::DateDay: |
410 | m_day = val.toInt(); | 410 | m_day = val.toInt(); |
411 | break; | 411 | break; |
412 | case OTodo::DateMonth: | 412 | case OTodo::DateMonth: |
413 | m_month = val.toInt(); | 413 | m_month = val.toInt(); |
414 | break; | 414 | break; |
415 | case OTodo::DateYear: | 415 | case OTodo::DateYear: |
416 | m_year = val.toInt(); | 416 | m_year = val.toInt(); |
417 | break; | 417 | break; |
418 | case OTodo::Progress: | 418 | case OTodo::Progress: |
419 | ev.setProgress( val.toInt() ); | 419 | ev.setProgress( val.toInt() ); |
420 | break; | 420 | break; |
421 | case OTodo::CompletedDate: | 421 | case OTodo::CompletedDate: |
422 | ev.setCompletedDate( OConversion::dateFromString( val ) ); | 422 | ev.setCompletedDate( OConversion::dateFromString( val ) ); |
423 | break; | 423 | break; |
424 | case OTodo::StartDate: | 424 | case OTodo::StartDate: |
425 | ev.setStartDate( OConversion::dateFromString( val ) ); | 425 | ev.setStartDate( OConversion::dateFromString( val ) ); |
426 | break; | 426 | break; |
427 | case OTodo::State: | 427 | case OTodo::State: |
428 | ev.setState( val.toInt() ); | 428 | ev.setState( val.toInt() ); |
429 | break; | 429 | break; |
430 | case OTodo::Alarms:{ | 430 | case OTodo::Alarms:{ |
431 | OPimNotifyManager &manager = ev.notifiers(); | 431 | OPimNotifyManager &manager = ev.notifiers(); |
432 | QStringList als = QStringList::split(";", val ); | 432 | QStringList als = QStringList::split(";", val ); |
433 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | 433 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { |
434 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 434 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty |
435 | qWarning("alarm: %s", alarm.join("___").latin1() ); | 435 | qWarning("alarm: %s", alarm.join("___").latin1() ); |
436 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); | 436 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); |
437 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); | 437 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); |
438 | manager.add( al ); | 438 | manager.add( al ); |
439 | } | 439 | } |
440 | } | 440 | } |
441 | break; | 441 | break; |
442 | case OTodo::Reminders:{ | 442 | case OTodo::Reminders:{ |
443 | OPimNotifyManager &manager = ev.notifiers(); | 443 | OPimNotifyManager &manager = ev.notifiers(); |
444 | QStringList rems = QStringList::split(";", val ); | 444 | QStringList rems = QStringList::split(";", val ); |
445 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | 445 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { |
446 | OPimReminder rem( (*it).toInt() ); | 446 | OPimReminder rem( (*it).toInt() ); |
447 | manager.add( rem ); | 447 | manager.add( rem ); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | break; | 450 | break; |
451 | case OTodo::CrossReference: | 451 | case OTodo::CrossReference: |
452 | { | 452 | { |
453 | /* | 453 | /* |
454 | * A cross refernce looks like | 454 | * A cross refernce looks like |
455 | * appname,id;appname,id | 455 | * appname,id;appname,id |
456 | * we need to split it up | 456 | * we need to split it up |
457 | */ | 457 | */ |
458 | QStringList refs = QStringList::split(';', val ); | 458 | QStringList refs = QStringList::split(';', val ); |
459 | QStringList::Iterator strIt; | 459 | QStringList::Iterator strIt; |
460 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 460 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
461 | int pos = (*strIt).find(','); | 461 | int pos = (*strIt).find(','); |
462 | if ( pos > -1 ) | 462 | if ( pos > -1 ) |
463 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 463 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
464 | 464 | ||
465 | } | 465 | } |
466 | break; | 466 | break; |
467 | } | 467 | } |
468 | /* Recurrence stuff below + post processing later */ | 468 | /* Recurrence stuff below + post processing later */ |
469 | case FRType: | 469 | case FRType: |
470 | if ( val == "Daily" ) | 470 | if ( val == "Daily" ) |
471 | recur()->setType( ORecur::Daily ); | 471 | recur()->setType( ORecur::Daily ); |
472 | else if ( val == "Weekly" ) | 472 | else if ( val == "Weekly" ) |
473 | recur()->setType( ORecur::Weekly); | 473 | recur()->setType( ORecur::Weekly); |
474 | else if ( val == "MonthlyDay" ) | 474 | else if ( val == "MonthlyDay" ) |
475 | recur()->setType( ORecur::MonthlyDay ); | 475 | recur()->setType( ORecur::MonthlyDay ); |
476 | else if ( val == "MonthlyDate" ) | 476 | else if ( val == "MonthlyDate" ) |
477 | recur()->setType( ORecur::MonthlyDate ); | 477 | recur()->setType( ORecur::MonthlyDate ); |
478 | else if ( val == "Yearly" ) | 478 | else if ( val == "Yearly" ) |
479 | recur()->setType( ORecur::Yearly ); | 479 | recur()->setType( ORecur::Yearly ); |
480 | else | 480 | else |
481 | recur()->setType( ORecur::NoRepeat ); | 481 | recur()->setType( ORecur::NoRepeat ); |
482 | break; | 482 | break; |
483 | case FRWeekdays: | 483 | case FRWeekdays: |
484 | recur()->setDays( val.toInt() ); | 484 | recur()->setDays( val.toInt() ); |
485 | break; | 485 | break; |
486 | case FRPosition: | 486 | case FRPosition: |
487 | recur()->setPosition( val.toInt() ); | 487 | recur()->setPosition( val.toInt() ); |
488 | break; | 488 | break; |
489 | case FRFreq: | 489 | case FRFreq: |
490 | recur()->setFrequency( val.toInt() ); | 490 | recur()->setFrequency( val.toInt() ); |
491 | break; | 491 | break; |
492 | case FRHasEndDate: | 492 | case FRHasEndDate: |
493 | recur()->setHasEndDate( val.toInt() ); | 493 | recur()->setHasEndDate( val.toInt() ); |
494 | break; | 494 | break; |
495 | case FREndDate: { | 495 | case FREndDate: { |
496 | rp_end = (time_t) val.toLong(); | 496 | rp_end = (time_t) val.toLong(); |
497 | break; | 497 | break; |
498 | } | 498 | } |
499 | default: | 499 | default: |
500 | ev.setCustomField( attr, val ); | 500 | ev.setCustomField( attr, val ); |
501 | break; | 501 | break; |
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
505 | // from PalmtopRecord... GPL ### FIXME | 505 | // from PalmtopRecord... GPL ### FIXME |
506 | namespace { | 506 | namespace { |
507 | QString customToXml(const QMap<QString, QString>& customMap ) | 507 | QString customToXml(const QMap<QString, QString>& customMap ) |
508 | { | 508 | { |
509 | //qWarning(QString("writing custom %1").arg(customMap.count())); | 509 | //qWarning(QString("writing custom %1").arg(customMap.count())); |
510 | QString buf(" "); | 510 | QString buf(" "); |
511 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); | 511 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); |
512 | cit != customMap.end(); ++cit) { | 512 | cit != customMap.end(); ++cit) { |
513 | // qWarning(".ITEM."); | 513 | // qWarning(".ITEM."); |
514 | buf += cit.key(); | 514 | buf += cit.key(); |
515 | buf += "=\""; | 515 | buf += "=\""; |
516 | buf += Qtopia::escapeString(cit.data()); | 516 | buf += Qtopia::escapeString(cit.data()); |
517 | buf += "\" "; | 517 | buf += "\" "; |
518 | } | 518 | } |
519 | return buf; | 519 | return buf; |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | } | 523 | } |
524 | 524 | ||
525 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 525 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
526 | QString str; | 526 | QString str; |
527 | 527 | ||
528 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 528 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
529 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 529 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
530 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 530 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
531 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 531 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
532 | 532 | ||
533 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 533 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
534 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 534 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
535 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 535 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
536 | 536 | ||
537 | if ( ev.hasDueDate() ) { | 537 | if ( ev.hasDueDate() ) { |
538 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 538 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
539 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 539 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
540 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 540 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
541 | } | 541 | } |
542 | // qWarning( "Uid %d", ev.uid() ); | 542 | // qWarning( "Uid %d", ev.uid() ); |
543 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 543 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
544 | 544 | ||
545 | // append the extra options | 545 | // append the extra options |
546 | /* FIXME Qtopia::Record this is currently not | 546 | /* FIXME Qtopia::Record this is currently not |
547 | * possible you can set custom fields | 547 | * possible you can set custom fields |
548 | * but don' iterate over the list | 548 | * but don' iterate over the list |
549 | * I may do #define private protected | 549 | * I may do #define private protected |
550 | * for this case - cough --zecke | 550 | * for this case - cough --zecke |
551 | */ | 551 | */ |
552 | /* | 552 | /* |
553 | QMap<QString, QString> extras = ev.extras(); | 553 | QMap<QString, QString> extras = ev.extras(); |
554 | QMap<QString, QString>::Iterator extIt; | 554 | QMap<QString, QString>::Iterator extIt; |
555 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 555 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
556 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 556 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
557 | */ | 557 | */ |
558 | // cross refernce | 558 | // cross refernce |
559 | if ( ev.hasRecurrence() ) { | 559 | if ( ev.hasRecurrence() ) { |
560 | str += ev.recurrence().toString(); | 560 | str += ev.recurrence().toString(); |
561 | } | 561 | } |
562 | if ( ev.hasStartDate() ) | 562 | if ( ev.hasStartDate() ) |
563 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; | 563 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; |
564 | if ( ev.hasCompletedDate() ) | 564 | if ( ev.hasCompletedDate() ) |
565 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; | 565 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; |
566 | if ( ev.hasState() ) | 566 | if ( ev.hasState() ) |
567 | str += "State=\""+QString::number( ev.state().state() )+"\" "; | 567 | str += "State=\""+QString::number( ev.state().state() )+"\" "; |
568 | 568 | ||
569 | /* | 569 | /* |
570 | * save reminders and notifiers! | 570 | * save reminders and notifiers! |
571 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... | 571 | * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... |
572 | */ | 572 | */ |
573 | if ( ev.hasNotifiers() ) { | 573 | if ( ev.hasNotifiers() ) { |
574 | OPimNotifyManager manager = ev.notifiers(); | 574 | OPimNotifyManager manager = ev.notifiers(); |
575 | OPimNotifyManager::Alarms alarms = manager.alarms(); | 575 | OPimNotifyManager::Alarms alarms = manager.alarms(); |
576 | if (!alarms.isEmpty() ) { | 576 | if (!alarms.isEmpty() ) { |
577 | QStringList als; | 577 | QStringList als; |
578 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 578 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
579 | for ( ; it != alarms.end(); ++it ) { | 579 | for ( ; it != alarms.end(); ++it ) { |
580 | /* only if time is valid */ | 580 | /* only if time is valid */ |
581 | if ( (*it).dateTime().isValid() ) { | 581 | if ( (*it).dateTime().isValid() ) { |
582 | als << OConversion::dateTimeToString( (*it).dateTime() ) | 582 | als << OConversion::dateTimeToString( (*it).dateTime() ) |
583 | + ":" + QString::number( (*it).duration() ) | 583 | + ":" + QString::number( (*it).duration() ) |
584 | + ":" + QString::number( (*it).sound() ) | 584 | + ":" + QString::number( (*it).sound() ) |
585 | + ":"; | 585 | + ":"; |
586 | } | 586 | } |
587 | } | 587 | } |
588 | // now write the list | 588 | // now write the list |
589 | qWarning("als: %s", als.join("____________").latin1() ); | 589 | qWarning("als: %s", als.join("____________").latin1() ); |
590 | str += "Alarms=\""+als.join(";") +"\" "; | 590 | str += "Alarms=\""+als.join(";") +"\" "; |
591 | } | 591 | } |
592 | 592 | ||
593 | /* | 593 | /* |
594 | * now the same for reminders but more easy. We just save the uid of the OEvent. | 594 | * now the same for reminders but more easy. We just save the uid of the OEvent. |
595 | */ | 595 | */ |
596 | OPimNotifyManager::Reminders reminders = manager.reminders(); | 596 | OPimNotifyManager::Reminders reminders = manager.reminders(); |
597 | if (!reminders.isEmpty() ) { | 597 | if (!reminders.isEmpty() ) { |
598 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 598 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
599 | QStringList records; | 599 | QStringList records; |
600 | for ( ; it != reminders.end(); ++it ) { | 600 | for ( ; it != reminders.end(); ++it ) { |
601 | records << QString::number( (*it).recordUid() ); | 601 | records << QString::number( (*it).recordUid() ); |
602 | } | 602 | } |
603 | str += "Reminders=\""+ records.join(";") +"\" "; | 603 | str += "Reminders=\""+ records.join(";") +"\" "; |
604 | } | 604 | } |
605 | } | 605 | } |
606 | str += customToXml( ev.toExtraMap() ); | 606 | str += customToXml( ev.toExtraMap() ); |
607 | 607 | ||
608 | 608 | ||
609 | return str; | 609 | return str; |
610 | } | 610 | } |
611 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 611 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
612 | return Qtopia::Record::idsToString( ints ); | 612 | return Qtopia::Record::idsToString( ints ); |
613 | } | 613 | } |
614 | 614 | ||
615 | /* internal class for sorting | 615 | /* internal class for sorting |
616 | * | 616 | * |
617 | * Inspired by todoxmlio.cpp from TT | 617 | * Inspired by todoxmlio.cpp from TT |
618 | */ | 618 | */ |
619 | 619 | ||
620 | struct OTodoXMLContainer { | 620 | struct OTodoXMLContainer { |
621 | OTodo todo; | 621 | OTodo todo; |
622 | }; | 622 | }; |
623 | 623 | ||
624 | namespace { | 624 | namespace { |
625 | inline QString string( const OTodo& todo) { | 625 | inline QString string( const OTodo& todo) { |
626 | return todo.summary().isEmpty() ? | 626 | return todo.summary().isEmpty() ? |
627 | todo.description().left(20 ) : | 627 | todo.description().left(20 ) : |
628 | todo.summary(); | 628 | todo.summary(); |
629 | } | 629 | } |
630 | inline int completed( const OTodo& todo1, const OTodo& todo2) { | 630 | inline int completed( const OTodo& todo1, const OTodo& todo2) { |
631 | int ret = 0; | 631 | int ret = 0; |
632 | if ( todo1.isCompleted() ) ret++; | 632 | if ( todo1.isCompleted() ) ret++; |
633 | if ( todo2.isCompleted() ) ret--; | 633 | if ( todo2.isCompleted() ) ret--; |
634 | return ret; | 634 | return ret; |
635 | } | 635 | } |
636 | inline int priority( const OTodo& t1, const OTodo& t2) { | 636 | inline int priority( const OTodo& t1, const OTodo& t2) { |
637 | return ( t1.priority() - t2.priority() ); | 637 | return ( t1.priority() - t2.priority() ); |
638 | } | 638 | } |
639 | inline int description( const OTodo& t1, const OTodo& t2) { | 639 | inline int description( const OTodo& t1, const OTodo& t2) { |
640 | return QString::compare( string(t1), string(t2) ); | 640 | return QString::compare( string(t1), string(t2) ); |
641 | } | 641 | } |
642 | inline int deadline( const OTodo& t1, const OTodo& t2) { | 642 | inline int deadline( const OTodo& t1, const OTodo& t2) { |
643 | int ret = 0; | 643 | int ret = 0; |
644 | if ( t1.hasDueDate() && | 644 | if ( t1.hasDueDate() && |
645 | t2.hasDueDate() ) | 645 | t2.hasDueDate() ) |
646 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 646 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
647 | else if ( t1.hasDueDate() ) | 647 | else if ( t1.hasDueDate() ) |
648 | ret = -1; | 648 | ret = -1; |
649 | else if ( t2.hasDueDate() ) | 649 | else if ( t2.hasDueDate() ) |
650 | ret = 1; | 650 | ret = 1; |
651 | else | 651 | else |
652 | ret = 0; | 652 | ret = 0; |
653 | 653 | ||
654 | return ret; | 654 | return ret; |
655 | } | 655 | } |
656 | 656 | ||
657 | }; | 657 | }; |
658 | 658 | ||
659 | /* | 659 | /* |
660 | * Returns: | 660 | * Returns: |
661 | * 0 if item1 == item2 | 661 | * 0 if item1 == item2 |
662 | * | 662 | * |
663 | * non-zero if item1 != item2 | 663 | * non-zero if item1 != item2 |
664 | * | 664 | * |
665 | * This function returns int rather than bool so that reimplementations | 665 | * This function returns int rather than bool so that reimplementations |
666 | * can return one of three values and use it to sort by: | 666 | * can return one of three values and use it to sort by: |
667 | * | 667 | * |
668 | * 0 if item1 == item2 | 668 | * 0 if item1 == item2 |
669 | * | 669 | * |
670 | * > 0 (positive integer) if item1 > item2 | 670 | * > 0 (positive integer) if item1 > item2 |
671 | * | 671 | * |
672 | * < 0 (negative integer) if item1 < item2 | 672 | * < 0 (negative integer) if item1 < item2 |
673 | * | 673 | * |
674 | */ | 674 | */ |
675 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | 675 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { |
676 | public: | 676 | public: |
677 | OTodoXMLVector(int size, bool asc, int sort) | 677 | OTodoXMLVector(int size, bool asc, int sort) |
678 | : QVector<OTodoXMLContainer>( size ) | 678 | : QVector<OTodoXMLContainer>( size ) |
679 | { | 679 | { |
680 | setAutoDelete( true ); | 680 | setAutoDelete( true ); |
681 | m_asc = asc; | 681 | m_asc = asc; |
682 | m_sort = sort; | 682 | m_sort = sort; |
683 | } | 683 | } |
684 | /* return the summary/description */ | 684 | /* return the summary/description */ |
685 | QString string( const OTodo& todo) { | 685 | QString string( const OTodo& todo) { |
686 | return todo.summary().isEmpty() ? | 686 | return todo.summary().isEmpty() ? |
687 | todo.description().left(20 ) : | 687 | todo.description().left(20 ) : |
688 | todo.summary(); | 688 | todo.summary(); |
689 | } | 689 | } |
690 | /** | 690 | /** |
691 | * we take the sortorder( switch on it ) | 691 | * we take the sortorder( switch on it ) |
692 | * | 692 | * |
693 | */ | 693 | */ |
694 | int compareItems( Item d1, Item d2 ) { | 694 | int compareItems( Item d1, Item d2 ) { |
695 | bool seComp, sePrio, seDesc, seDeadline; | 695 | bool seComp, sePrio, seDesc, seDeadline; |
696 | seComp = sePrio = seDeadline = seDesc = false; | 696 | seComp = sePrio = seDeadline = seDesc = false; |
697 | int ret =0; | 697 | int ret =0; |
698 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | 698 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; |
699 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | 699 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; |
700 | 700 | ||
701 | /* same item */ | 701 | /* same item */ |
702 | if ( con1->todo.uid() == con2->todo.uid() ) | 702 | if ( con1->todo.uid() == con2->todo.uid() ) |
703 | return 0; | 703 | return 0; |
704 | 704 | ||
705 | switch ( m_sort ) { | 705 | switch ( m_sort ) { |
706 | /* completed */ | 706 | /* completed */ |
707 | case 0: { | 707 | case 0: { |
708 | ret = completed( con1->todo, con2->todo ); | 708 | ret = completed( con1->todo, con2->todo ); |
709 | seComp = TRUE; | 709 | seComp = TRUE; |
710 | break; | 710 | break; |
711 | } | 711 | } |
712 | /* priority */ | 712 | /* priority */ |
713 | case 1: { | 713 | case 1: { |
714 | ret = priority( con1->todo, con2->todo ); | 714 | ret = priority( con1->todo, con2->todo ); |
715 | sePrio = TRUE; | 715 | sePrio = TRUE; |
716 | break; | 716 | break; |
717 | } | 717 | } |
718 | /* description */ | 718 | /* description */ |
719 | case 2: { | 719 | case 2: { |
720 | ret = description( con1->todo, con2->todo ); | 720 | ret = description( con1->todo, con2->todo ); |
721 | seDesc = TRUE; | 721 | seDesc = TRUE; |
722 | break; | 722 | break; |
723 | } | 723 | } |
724 | /* deadline */ | 724 | /* deadline */ |
725 | case 3: { | 725 | case 3: { |
726 | ret = deadline( con1->todo, con2->todo ); | 726 | ret = deadline( con1->todo, con2->todo ); |
727 | seDeadline = TRUE; | 727 | seDeadline = TRUE; |
728 | break; | 728 | break; |
729 | } | 729 | } |
730 | default: | 730 | default: |
731 | ret = 0; | 731 | ret = 0; |
732 | break; | 732 | break; |
733 | }; | 733 | }; |
734 | /* | 734 | /* |
735 | * FIXME do better sorting if the first sort criteria | 735 | * FIXME do better sorting if the first sort criteria |
736 | * ret equals 0 start with complete and so on... | 736 | * ret equals 0 start with complete and so on... |
737 | */ | 737 | */ |
738 | 738 | ||
739 | /* twist it we're not ascending*/ | 739 | /* twist it we're not ascending*/ |
740 | if (!m_asc) | 740 | if (!m_asc) |
741 | ret = ret * -1; | 741 | ret = ret * -1; |
742 | 742 | ||
743 | if ( ret ) | 743 | if ( ret ) |
744 | return ret; | 744 | return ret; |
745 | 745 | ||
746 | // default did not gave difference let's try it other way around | 746 | // default did not gave difference let's try it other way around |
747 | /* | 747 | /* |
748 | * General try if already checked if not test | 748 | * General try if already checked if not test |
749 | * and return | 749 | * and return |
750 | * 1.Completed | 750 | * 1.Completed |
751 | * 2.Priority | 751 | * 2.Priority |
752 | * 3.Description | 752 | * 3.Description |
753 | * 4.DueDate | 753 | * 4.DueDate |
754 | */ | 754 | */ |
755 | if (!seComp ) { | 755 | if (!seComp ) { |
756 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { | 756 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { |
757 | if (!m_asc ) ret *= -1; | 757 | if (!m_asc ) ret *= -1; |
758 | return ret; | 758 | return ret; |
759 | } | 759 | } |
760 | } | 760 | } |
761 | if (!sePrio ) { | 761 | if (!sePrio ) { |
762 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { | 762 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { |
763 | if (!m_asc ) ret *= -1; | 763 | if (!m_asc ) ret *= -1; |
764 | return ret; | 764 | return ret; |
765 | } | 765 | } |
766 | } | 766 | } |
767 | if (!seDesc ) { | 767 | if (!seDesc ) { |
768 | if ( (ret = description(con1->todo, con2->todo ) ) ) { | 768 | if ( (ret = description(con1->todo, con2->todo ) ) ) { |
769 | if (!m_asc) ret *= -1; | 769 | if (!m_asc) ret *= -1; |
770 | return ret; | 770 | return ret; |
771 | } | 771 | } |
772 | } | 772 | } |
773 | if (!seDeadline) { | 773 | if (!seDeadline) { |
774 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { | 774 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { |
775 | if (!m_asc) ret *= -1; | 775 | if (!m_asc) ret *= -1; |
776 | return ret; | 776 | return ret; |
777 | } | 777 | } |
778 | } | 778 | } |
779 | 779 | ||
780 | return 0; | 780 | return 0; |
781 | } | 781 | } |
782 | private: | 782 | private: |
783 | bool m_asc; | 783 | bool m_asc; |
784 | int m_sort; | 784 | int m_sort; |
785 | 785 | ||
786 | }; | 786 | }; |
787 | 787 | ||
788 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | 788 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, |
789 | int sortFilter, int cat ) { | 789 | int sortFilter, int cat ) { |
790 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | 790 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); |
791 | QMap<int, OTodo>::Iterator it; | 791 | QMap<int, OTodo>::Iterator it; |
792 | int item = 0; | 792 | int item = 0; |
793 | 793 | ||
794 | bool bCat = sortFilter & 1 ? true : false; | 794 | bool bCat = sortFilter & 1 ? true : false; |
795 | bool bOnly = sortFilter & 2 ? true : false; | 795 | bool bOnly = sortFilter & 2 ? true : false; |
796 | bool comp = sortFilter & 4 ? true : false; | 796 | bool comp = sortFilter & 4 ? true : false; |
797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
798 | 798 | ||
799 | /* show category */ | 799 | /* show category */ |
800 | /* -1 == unfiled */ | 800 | /* -1 == unfiled */ |
801 | if ( bCat && cat == -1 ) { | 801 | if ( bCat && cat == -1 ) { |
802 | if(!(*it).categories().isEmpty() ) | 802 | if(!(*it).categories().isEmpty() ) |
803 | continue; | 803 | continue; |
804 | }else if ( bCat && cat != 0) | 804 | }else if ( bCat && cat != 0) |
805 | if (!(*it).categories().contains( cat ) ) { | 805 | if (!(*it).categories().contains( cat ) ) { |
806 | continue; | 806 | continue; |
807 | } | 807 | } |
808 | /* isOverdue but we should not show overdue - why?*/ | 808 | /* isOverdue but we should not show overdue - why?*/ |
809 | /* if ( (*it).isOverdue() && !bOnly ) { | 809 | /* if ( (*it).isOverdue() && !bOnly ) { |
810 | qWarning("item is overdue but !bOnly"); | 810 | qWarning("item is overdue but !bOnly"); |
811 | continue; | 811 | continue; |
812 | } | 812 | } |
813 | */ | 813 | */ |
814 | if ( !(*it).isOverdue() && bOnly ) { | 814 | if ( !(*it).isOverdue() && bOnly ) { |
815 | continue; | 815 | continue; |
816 | } | 816 | } |
817 | 817 | ||
818 | if ((*it).isCompleted() && comp ) { | 818 | if ((*it).isCompleted() && comp ) { |
819 | continue; | 819 | continue; |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | OTodoXMLContainer* con = new OTodoXMLContainer(); | 823 | OTodoXMLContainer* con = new OTodoXMLContainer(); |
824 | con->todo = (*it); | 824 | con->todo = (*it); |
825 | vector.insert(item, con ); | 825 | vector.insert(item, con ); |
826 | item++; | 826 | item++; |
827 | } | 827 | } |
828 | vector.resize( item ); | 828 | vector.resize( item ); |
829 | /* sort it now */ | 829 | /* sort it now */ |
830 | vector.sort(); | 830 | vector.sort(); |
831 | /* now get the uids */ | 831 | /* now get the uids */ |
832 | QArray<int> array( vector.count() ); | 832 | QArray<int> array( vector.count() ); |
833 | for (uint i= 0; i < vector.count(); i++ ) { | 833 | for (uint i= 0; i < vector.count(); i++ ) { |
834 | array[i] = ( vector.at(i) )->todo.uid(); | 834 | array[i] = ( vector.at(i) )->todo.uid(); |
835 | } | 835 | } |
836 | return array; | 836 | return array; |
837 | }; | 837 | }; |
838 | void OTodoAccessXML::removeAllCompleted() { | 838 | void OTodoAccessXML::removeAllCompleted() { |
839 | QMap<int, OTodo> events = m_events; | ||
839 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 840 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
840 | if ( (*it).isCompleted() ) | 841 | if ( (*it).isCompleted() ) |
841 | m_events.remove( it ); | 842 | events.remove( it.key() ); |
842 | } | 843 | } |
844 | m_events = events; | ||
843 | } | 845 | } |
844 | QBitArray OTodoAccessXML::supports()const { | 846 | QBitArray OTodoAccessXML::supports()const { |
845 | static QBitArray ar = sup(); | 847 | static QBitArray ar = sup(); |
846 | return ar; | 848 | return ar; |
847 | } | 849 | } |
848 | QBitArray OTodoAccessXML::sup() { | 850 | QBitArray OTodoAccessXML::sup() { |
849 | QBitArray ar( OTodo::CompletedDate +1 ); | 851 | QBitArray ar( OTodo::CompletedDate +1 ); |
850 | ar.fill( true ); | 852 | ar.fill( true ); |
851 | ar[OTodo::CrossReference] = false; | 853 | ar[OTodo::CrossReference] = false; |
852 | ar[OTodo::State ] = false; | 854 | ar[OTodo::State ] = false; |
853 | ar[OTodo::Reminders] = false; | 855 | ar[OTodo::Reminders] = false; |
854 | ar[OTodo::Notifiers] = false; | 856 | ar[OTodo::Notifiers] = false; |
855 | ar[OTodo::Maintainer] = false; | 857 | ar[OTodo::Maintainer] = false; |
856 | 858 | ||
857 | return ar; | 859 | return ar; |
858 | } | 860 | } |
859 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const | 861 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const |
860 | { | 862 | { |
861 | QArray<int> m_currentQuery( m_events.count() ); | 863 | QArray<int> m_currentQuery( m_events.count() ); |
862 | uint arraycounter = 0; | 864 | uint arraycounter = 0; |
863 | 865 | ||
864 | QMap<int, OTodo>::ConstIterator it; | 866 | QMap<int, OTodo>::ConstIterator it; |
865 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 867 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
866 | if ( it.data().match( r ) ) | 868 | if ( it.data().match( r ) ) |
867 | m_currentQuery[arraycounter++] = it.data().uid(); | 869 | m_currentQuery[arraycounter++] = it.data().uid(); |
868 | 870 | ||
869 | } | 871 | } |
870 | // Shrink to fit.. | 872 | // Shrink to fit.. |
871 | m_currentQuery.resize(arraycounter); | 873 | m_currentQuery.resize(arraycounter); |
872 | 874 | ||
873 | return m_currentQuery; | 875 | return m_currentQuery; |
874 | } | 876 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index e90db32..9b0a719 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,170 +1,181 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | * Class to manage the Contacts. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.9 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.8.2.1 2003/06/30 14:34:19 eilers | ||
24 | * Patches from Zecke: | ||
25 | * Fixing and cleaning up extraMap handling | ||
26 | * Adding d_ptr for binary compatibility in the future | ||
27 | * | ||
20 | * Revision 1.8 2003/05/08 13:55:09 tille | 28 | * Revision 1.8 2003/05/08 13:55:09 tille |
21 | * search stuff | 29 | * search stuff |
22 | * and match, toRichText & toShortText in oevent | 30 | * and match, toRichText & toShortText in oevent |
23 | * | 31 | * |
24 | * Revision 1.7 2003/04/13 18:07:10 zecke | 32 | * Revision 1.7 2003/04/13 18:07:10 zecke |
25 | * More API doc | 33 | * More API doc |
26 | * QString -> const QString& | 34 | * QString -> const QString& |
27 | * QString = 0l -> QString::null | 35 | * QString = 0l -> QString::null |
28 | * | 36 | * |
29 | * Revision 1.6 2003/01/02 14:27:12 eilers | 37 | * Revision 1.6 2003/01/02 14:27:12 eilers |
30 | * Improved query by example: Search by date is possible.. First step | 38 | * Improved query by example: Search by date is possible.. First step |
31 | * for a today plugin for birthdays.. | 39 | * for a today plugin for birthdays.. |
32 | * | 40 | * |
33 | * Revision 1.5 2002/11/13 14:14:51 eilers | 41 | * Revision 1.5 2002/11/13 14:14:51 eilers |
34 | * Added sorted for Contacts.. | 42 | * Added sorted for Contacts.. |
35 | * | 43 | * |
36 | * Revision 1.4 2002/11/01 15:10:42 eilers | 44 | * Revision 1.4 2002/11/01 15:10:42 eilers |
37 | * Added regExp-search in database for all fields in a contact. | 45 | * Added regExp-search in database for all fields in a contact. |
38 | * | 46 | * |
39 | * Revision 1.3 2002/10/16 10:52:40 eilers | 47 | * Revision 1.3 2002/10/16 10:52:40 eilers |
40 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 48 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
41 | * | 49 | * |
42 | * Revision 1.2 2002/10/14 16:21:54 eilers | 50 | * Revision 1.2 2002/10/14 16:21:54 eilers |
43 | * Some minor interface updates | 51 | * Some minor interface updates |
44 | * | 52 | * |
45 | * Revision 1.1 2002/09/27 17:11:44 eilers | 53 | * Revision 1.1 2002/09/27 17:11:44 eilers |
46 | * Added API for accessing the Contact-Database ! It is compiling, but | 54 | * Added API for accessing the Contact-Database ! It is compiling, but |
47 | * please do not expect that anything is working ! | 55 | * please do not expect that anything is working ! |
48 | * I will debug that stuff in the next time .. | 56 | * I will debug that stuff in the next time .. |
49 | * Please read README_COMPILE for compiling ! | 57 | * Please read README_COMPILE for compiling ! |
50 | * | 58 | * |
51 | * ===================================================================== | 59 | * ===================================================================== |
52 | */ | 60 | */ |
53 | #ifndef _OCONTACTACCESS_H | 61 | #ifndef _OCONTACTACCESS_H |
54 | #define _OCONTACTACCESS_H | 62 | #define _OCONTACTACCESS_H |
55 | 63 | ||
56 | #include <qobject.h> | 64 | #include <qobject.h> |
57 | 65 | ||
58 | #include <qpe/qcopenvelope_qws.h> | 66 | #include <qpe/qcopenvelope_qws.h> |
59 | 67 | ||
60 | #include <qvaluelist.h> | 68 | #include <qvaluelist.h> |
61 | #include <qfileinfo.h> | 69 | #include <qfileinfo.h> |
62 | 70 | ||
63 | #include "ocontact.h" | 71 | #include "ocontact.h" |
64 | #include "ocontactaccessbackend.h" | 72 | #include "ocontactaccessbackend.h" |
65 | #include "opimaccesstemplate.h" | 73 | #include "opimaccesstemplate.h" |
66 | 74 | ||
67 | /** | 75 | /** |
68 | * Class to access the contacts database. | 76 | * Class to access the contacts database. |
69 | * This is just a frontend for the real database handling which is | 77 | * This is just a frontend for the real database handling which is |
70 | * done by the backend. | 78 | * done by the backend. |
71 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | 79 | * This class is used to access the Contacts on a system. This class as any OPIE PIM |
72 | * class is backend independent. | 80 | * class is backend independent. |
73 | 81 | ||
74 | * @see OPimAccessTemplate | 82 | * @see OPimAccessTemplate |
75 | */ | 83 | */ |
76 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 84 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
77 | { | 85 | { |
78 | Q_OBJECT | 86 | Q_OBJECT |
79 | 87 | ||
80 | public: | 88 | public: |
81 | /** | 89 | /** |
82 | * Create Database with contacts (addressbook). | 90 | * Create Database with contacts (addressbook). |
83 | * @param appname Name of application which wants access to the database | 91 | * @param appname Name of application which wants access to the database |
84 | * (i.e. "todolist") | 92 | * (i.e. "todolist") |
85 | * @param filename The name of the database file. If not set, the default one | 93 | * @param filename The name of the database file. If not set, the default one |
86 | * is used. | 94 | * is used. |
87 | * @param backend Pointer to an alternative Backend. If not set, we will use | 95 | * @param backend Pointer to an alternative Backend. If not set, we will use |
88 | * the default backend. | 96 | * the default backend. |
89 | * @param handlesync If <b>true</b> the database stores the current state | 97 | * @param handlesync If <b>true</b> the database stores the current state |
90 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 98 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
91 | * which are used before and after synchronisation. If the application wants | 99 | * which are used before and after synchronisation. If the application wants |
92 | * to react itself, it should be disabled by setting it to <b>false</b> | 100 | * to react itself, it should be disabled by setting it to <b>false</b> |
93 | * @see OContactAccessBackend | 101 | * @see OContactAccessBackend |
94 | */ | 102 | */ |
95 | OContactAccess (const QString appname, const QString filename = 0l, | 103 | OContactAccess (const QString appname, const QString filename = 0l, |
96 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 104 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
97 | ~OContactAccess (); | 105 | ~OContactAccess (); |
98 | 106 | ||
99 | /** Constants for query. | 107 | /** Constants for query. |
100 | * Use this constants to set the query parameters. | 108 | * Use this constants to set the query parameters. |
101 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 109 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
102 | * @see queryByExample() | 110 | * @see queryByExample() |
103 | */ | 111 | */ |
104 | enum QuerySettings { | 112 | enum QuerySettings { |
105 | WildCards = 0x0001, | 113 | WildCards = 0x0001, |
106 | IgnoreCase = 0x0002, | 114 | IgnoreCase = 0x0002, |
107 | RegExp = 0x0004, | 115 | RegExp = 0x0004, |
108 | ExactMatch = 0x0008, | 116 | ExactMatch = 0x0008, |
109 | MatchOne = 0x0010, // Only one Entry must match | 117 | MatchOne = 0x0010, // Only one Entry must match |
110 | DateDiff = 0x0020, // Find all entries from today until given date | 118 | DateDiff = 0x0020, // Find all entries from today until given date |
111 | DateYear = 0x0040, // The year matches | 119 | DateYear = 0x0040, // The year matches |
112 | DateMonth = 0x0080, // The month matches | 120 | DateMonth = 0x0080, // The month matches |
113 | DateDay = 0x0100, // The day matches | 121 | DateDay = 0x0100, // The day matches |
114 | }; | 122 | }; |
115 | 123 | ||
116 | 124 | ||
117 | /** Return all Contacts in a sorted manner. | 125 | /** Return all Contacts in a sorted manner. |
118 | * @param ascending true: Sorted in acending order. | 126 | * @param ascending true: Sorted in acending order. |
119 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 127 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
120 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 128 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
121 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 129 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
122 | */ | 130 | */ |
123 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 131 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
124 | 132 | ||
125 | /** Return all possible settings. | 133 | /** Return all possible settings. |
126 | * @return All settings provided by the current backend | 134 | * @return All settings provided by the current backend |
127 | * (i.e.: query_WildCards & query_IgnoreCase) | 135 | * (i.e.: query_WildCards & query_IgnoreCase) |
128 | */ | 136 | */ |
129 | const uint querySettings(); | 137 | const uint querySettings(); |
130 | 138 | ||
131 | /** Check whether settings are correct. | 139 | /** Check whether settings are correct. |
132 | * @return <i>true</i> if the given settings are correct and possible. | 140 | * @return <i>true</i> if the given settings are correct and possible. |
133 | */ | 141 | */ |
134 | bool hasQuerySettings ( int querySettings ) const; | 142 | bool hasQuerySettings ( int querySettings ) const; |
135 | 143 | ||
136 | /** | 144 | /** |
137 | * if the resource was changed externally. | 145 | * if the resource was changed externally. |
138 | * You should use the signal instead of polling possible changes ! | 146 | * You should use the signal instead of polling possible changes ! |
139 | */ | 147 | */ |
140 | bool wasChangedExternally()const; | 148 | bool wasChangedExternally()const; |
141 | 149 | ||
142 | 150 | ||
143 | /** Save contacts database. | 151 | /** Save contacts database. |
144 | * Save is more a "commit". After calling this function, all changes are public available. | 152 | * Save is more a "commit". After calling this function, all changes are public available. |
145 | * @return true if successful | 153 | * @return true if successful |
146 | */ | 154 | */ |
147 | bool save(); | 155 | bool save(); |
148 | 156 | ||
149 | signals: | 157 | signals: |
150 | /* Signal is emitted if the database was changed. Therefore | 158 | /* Signal is emitted if the database was changed. Therefore |
151 | * we may need to reload to stay consistent. | 159 | * we may need to reload to stay consistent. |
152 | * @param which Pointer to the database who created this event. This pointer | 160 | * @param which Pointer to the database who created this event. This pointer |
153 | * is useful if an application has to handle multiple databases at the same time. | 161 | * is useful if an application has to handle multiple databases at the same time. |
154 | * @see reload() | 162 | * @see reload() |
155 | */ | 163 | */ |
156 | void signalChanged ( const OContactAccess *which ); | 164 | void signalChanged ( const OContactAccess *which ); |
157 | 165 | ||
158 | 166 | ||
159 | private: | 167 | private: |
160 | // class OContactAccessPrivate; | 168 | // class OContactAccessPrivate; |
161 | // OContactAccessPrivate* d; | 169 | // OContactAccessPrivate* d; |
162 | OContactAccessBackend *m_backEnd; | 170 | OContactAccessBackend *m_backEnd; |
163 | bool m_loading:1; | 171 | bool m_loading:1; |
164 | 172 | ||
165 | private slots: | 173 | private slots: |
166 | void copMessage( const QCString &msg, const QByteArray &data ); | 174 | void copMessage( const QCString &msg, const QByteArray &data ); |
167 | 175 | ||
176 | private: | ||
177 | class Private; | ||
178 | Private *d; | ||
168 | 179 | ||
169 | }; | 180 | }; |
170 | #endif | 181 | #endif |
diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/oconversion.h index 13367e1..4c0a497 100644 --- a/libopie2/opiepim/core/oconversion.h +++ b/libopie2/opiepim/core/oconversion.h | |||
@@ -1,43 +1,48 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | **********************************************************************/ | 17 | **********************************************************************/ |
18 | 18 | ||
19 | #ifndef __oconversion_h__ | 19 | #ifndef __oconversion_h__ |
20 | #define __oconversion_h__ | 20 | #define __oconversion_h__ |
21 | 21 | ||
22 | /* #include <time.h> */ | 22 | /* #include <time.h> */ |
23 | /* #include <sys/types.h> */ | 23 | /* #include <sys/types.h> */ |
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | 25 | ||
26 | /* FIXME namespace? -zecke */ | 26 | /* FIXME namespace? -zecke */ |
27 | class OConversion | 27 | class OConversion |
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | static QString dateToString( const QDate &d ); | 30 | static QString dateToString( const QDate &d ); |
31 | static QDate dateFromString( const QString &datestr ); | 31 | static QDate dateFromString( const QString &datestr ); |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * simple function to store DateTime as string and read from string | 34 | * simple function to store DateTime as string and read from string |
35 | * no timezone changing is done | 35 | * no timezone changing is done |
36 | * DDMMYYYYHHMMSS is the simple format | 36 | * DDMMYYYYHHMMSS is the simple format |
37 | */ | 37 | */ |
38 | static QString dateTimeToString( const QDateTime& ); | 38 | static QString dateTimeToString( const QDateTime& ); |
39 | static QDateTime dateTimeFromString( const QString& ); | 39 | static QDateTime dateTimeFromString( const QString& ); |
40 | |||
41 | private: | ||
42 | class Private; | ||
43 | Private* d; | ||
44 | |||
40 | }; | 45 | }; |
41 | 46 | ||
42 | #endif // __oconversion_h__ | 47 | #endif // __oconversion_h__ |
43 | 48 | ||
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 8ff205c..ecbeb68 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,298 +1,302 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "opimcache.h" | 10 | #include "opimcache.h" |
11 | #include "otemplatebase.h" | 11 | #include "otemplatebase.h" |
12 | 12 | ||
13 | class OPimAccessTemplatePrivate; | ||
13 | /** | 14 | /** |
14 | * Thats the frontend to our OPIE PIM | 15 | * Thats the frontend to our OPIE PIM |
15 | * Library. Either you want to use it's | 16 | * Library. Either you want to use it's |
16 | * interface or you want to implement | 17 | * interface or you want to implement |
17 | * your own Access lib | 18 | * your own Access lib |
18 | * Just create a OPimRecord and inherit from | 19 | * Just create a OPimRecord and inherit from |
19 | * the plugins | 20 | * the plugins |
20 | */ | 21 | */ |
21 | 22 | ||
22 | template <class T = OPimRecord > | 23 | template <class T = OPimRecord > |
23 | class OPimAccessTemplate : public OTemplateBase<T> { | 24 | class OPimAccessTemplate : public OTemplateBase<T> { |
24 | public: | 25 | public: |
25 | enum Access { | 26 | enum Access { |
26 | Random = 0, | 27 | Random = 0, |
27 | SortedAccess | 28 | SortedAccess |
28 | }; | 29 | }; |
29 | typedef ORecordList<T> List; | 30 | typedef ORecordList<T> List; |
30 | typedef OPimAccessBackend<T> BackEnd; | 31 | typedef OPimAccessBackend<T> BackEnd; |
31 | typedef OPimCache<T> Cache; | 32 | typedef OPimCache<T> Cache; |
32 | 33 | ||
33 | /** | 34 | /** |
34 | * c'tor BackEnd | 35 | * c'tor BackEnd |
35 | * enum Access a small hint on how to handle the backend | 36 | * enum Access a small hint on how to handle the backend |
36 | */ | 37 | */ |
37 | OPimAccessTemplate( BackEnd* end); | 38 | OPimAccessTemplate( BackEnd* end); |
38 | 39 | ||
39 | virtual ~OPimAccessTemplate(); | 40 | virtual ~OPimAccessTemplate(); |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * load from the backend | 43 | * load from the backend |
43 | */ | 44 | */ |
44 | bool load(); | 45 | bool load(); |
45 | 46 | ||
46 | /** Reload database. | 47 | /** Reload database. |
47 | * You should execute this function if the external database | 48 | * You should execute this function if the external database |
48 | * was changed. | 49 | * was changed. |
49 | * This function will load the external database and afterwards | 50 | * This function will load the external database and afterwards |
50 | * rejoin the local changes. Therefore the local database will be set consistent. | 51 | * rejoin the local changes. Therefore the local database will be set consistent. |
51 | */ | 52 | */ |
52 | virtual bool reload(); | 53 | virtual bool reload(); |
53 | 54 | ||
54 | /** Save contacts database. | 55 | /** Save contacts database. |
55 | * Save is more a "commit". After calling this function, all changes are public available. | 56 | * Save is more a "commit". After calling this function, all changes are public available. |
56 | * @return true if successful | 57 | * @return true if successful |
57 | */ | 58 | */ |
58 | bool save(); | 59 | bool save(); |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * if the resource was changed externally | 62 | * if the resource was changed externally |
62 | * You should use the signal handling instead of polling possible changes ! | 63 | * You should use the signal handling instead of polling possible changes ! |
63 | * zecke: Do you implement a signal for otodoaccess ? | 64 | * zecke: Do you implement a signal for otodoaccess ? |
64 | */ | 65 | */ |
65 | bool wasChangedExternally()const; | 66 | bool wasChangedExternally()const; |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * return a List of records | 69 | * return a List of records |
69 | * you can iterate over them | 70 | * you can iterate over them |
70 | */ | 71 | */ |
71 | virtual List allRecords()const; | 72 | virtual List allRecords()const; |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * return a List of records | 75 | * return a List of records |
75 | * that match the regex | 76 | * that match the regex |
76 | */ | 77 | */ |
77 | virtual List matchRegexp( const QRegExp &r ) const; | 78 | virtual List matchRegexp( const QRegExp &r ) const; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * queryByExample. | 81 | * queryByExample. |
81 | * @see otodoaccess, ocontactaccess | 82 | * @see otodoaccess, ocontactaccess |
82 | */ | 83 | */ |
83 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); | 84 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * find the OPimRecord uid | 87 | * find the OPimRecord uid |
87 | */ | 88 | */ |
88 | virtual T find( int uid )const; | 89 | virtual T find( int uid )const; |
89 | 90 | ||
90 | /** | 91 | /** |
91 | * read ahead cache find method ;) | 92 | * read ahead cache find method ;) |
92 | */ | 93 | */ |
93 | virtual T find( int uid, const QArray<int>&, | 94 | virtual T find( int uid, const QArray<int>&, |
94 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 95 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
95 | 96 | ||
96 | /* invalidate cache here */ | 97 | /* invalidate cache here */ |
97 | /** | 98 | /** |
98 | * clears the backend and invalidates the backend | 99 | * clears the backend and invalidates the backend |
99 | */ | 100 | */ |
100 | void clear() ; | 101 | void clear() ; |
101 | 102 | ||
102 | /** | 103 | /** |
103 | * add T to the backend | 104 | * add T to the backend |
104 | * @param t The item to add. | 105 | * @param t The item to add. |
105 | * @return <i>true</i> if added successfully. | 106 | * @return <i>true</i> if added successfully. |
106 | */ | 107 | */ |
107 | virtual bool add( const T& t ) ; | 108 | virtual bool add( const T& t ) ; |
108 | bool add( const OPimRecord& ); | 109 | bool add( const OPimRecord& ); |
109 | 110 | ||
110 | /* only the uid matters */ | 111 | /* only the uid matters */ |
111 | /** | 112 | /** |
112 | * remove T from the backend | 113 | * remove T from the backend |
113 | * @param t The item to remove | 114 | * @param t The item to remove |
114 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
115 | */ | 116 | */ |
116 | virtual bool remove( const T& t ); | 117 | virtual bool remove( const T& t ); |
117 | 118 | ||
118 | /** | 119 | /** |
119 | * remove the OPimRecord with uid | 120 | * remove the OPimRecord with uid |
120 | * @param uid The ID of the item to remove | 121 | * @param uid The ID of the item to remove |
121 | * @return <i>true</i> if successful. | 122 | * @return <i>true</i> if successful. |
122 | */ | 123 | */ |
123 | bool remove( int uid ); | 124 | bool remove( int uid ); |
124 | bool remove( const OPimRecord& ); | 125 | bool remove( const OPimRecord& ); |
125 | 126 | ||
126 | /** | 127 | /** |
127 | * replace T from backend | 128 | * replace T from backend |
128 | * @param t The item to replace | 129 | * @param t The item to replace |
129 | * @return <i>true</i> if successful. | 130 | * @return <i>true</i> if successful. |
130 | */ | 131 | */ |
131 | virtual bool replace( const T& t) ; | 132 | virtual bool replace( const T& t) ; |
132 | 133 | ||
133 | void setReadAhead( uint count ); | 134 | void setReadAhead( uint count ); |
134 | /** | 135 | /** |
135 | * @internal | 136 | * @internal |
136 | */ | 137 | */ |
137 | void cache( const T& )const; | 138 | void cache( const T& )const; |
138 | void setSaneCacheSize( int ); | 139 | void setSaneCacheSize( int ); |
139 | 140 | ||
140 | QArray<int> records()const; | 141 | QArray<int> records()const; |
141 | protected: | 142 | protected: |
142 | /** | 143 | /** |
143 | * invalidate the cache | 144 | * invalidate the cache |
144 | */ | 145 | */ |
145 | void invalidateCache(); | 146 | void invalidateCache(); |
146 | 147 | ||
147 | void setBackEnd( BackEnd* end ); | 148 | void setBackEnd( BackEnd* end ); |
148 | /** | 149 | /** |
149 | * returns the backend | 150 | * returns the backend |
150 | */ | 151 | */ |
151 | BackEnd* backEnd(); | 152 | BackEnd* backEnd(); |
152 | BackEnd* m_backEnd; | 153 | BackEnd* m_backEnd; |
153 | Cache m_cache; | 154 | Cache m_cache; |
154 | 155 | ||
156 | private: | ||
157 | OPimAccessTemplatePrivate *d; | ||
158 | |||
155 | }; | 159 | }; |
156 | 160 | ||
157 | template <class T> | 161 | template <class T> |
158 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 162 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
159 | : OTemplateBase<T>(), m_backEnd( end ) | 163 | : OTemplateBase<T>(), m_backEnd( end ) |
160 | { | 164 | { |
161 | if (end ) | 165 | if (end ) |
162 | end->setFrontend( this ); | 166 | end->setFrontend( this ); |
163 | } | 167 | } |
164 | template <class T> | 168 | template <class T> |
165 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 169 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
166 | qWarning("~OPimAccessTemplate<T>"); | 170 | qWarning("~OPimAccessTemplate<T>"); |
167 | delete m_backEnd; | 171 | delete m_backEnd; |
168 | } | 172 | } |
169 | template <class T> | 173 | template <class T> |
170 | bool OPimAccessTemplate<T>::load() { | 174 | bool OPimAccessTemplate<T>::load() { |
171 | invalidateCache(); | 175 | invalidateCache(); |
172 | return m_backEnd->load(); | 176 | return m_backEnd->load(); |
173 | } | 177 | } |
174 | template <class T> | 178 | template <class T> |
175 | bool OPimAccessTemplate<T>::reload() { | 179 | bool OPimAccessTemplate<T>::reload() { |
176 | invalidateCache(); // zecke: I think this should be added (se) | 180 | invalidateCache(); // zecke: I think this should be added (se) |
177 | return m_backEnd->reload(); | 181 | return m_backEnd->reload(); |
178 | } | 182 | } |
179 | template <class T> | 183 | template <class T> |
180 | bool OPimAccessTemplate<T>::save() { | 184 | bool OPimAccessTemplate<T>::save() { |
181 | return m_backEnd->save(); | 185 | return m_backEnd->save(); |
182 | } | 186 | } |
183 | template <class T> | 187 | template <class T> |
184 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 188 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
185 | QArray<int> ints = m_backEnd->allRecords(); | 189 | QArray<int> ints = m_backEnd->allRecords(); |
186 | List lis(ints, this ); | 190 | List lis(ints, this ); |
187 | return lis; | 191 | return lis; |
188 | } | 192 | } |
189 | template <class T> | 193 | template <class T> |
190 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 194 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
191 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 195 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
192 | List lis(ints, this ); | 196 | List lis(ints, this ); |
193 | return lis; | 197 | return lis; |
194 | } | 198 | } |
195 | template <class T> | 199 | template <class T> |
196 | QArray<int> OPimAccessTemplate<T>::records()const { | 200 | QArray<int> OPimAccessTemplate<T>::records()const { |
197 | return m_backEnd->allRecords(); | 201 | return m_backEnd->allRecords(); |
198 | } | 202 | } |
199 | template <class T> | 203 | template <class T> |
200 | typename OPimAccessTemplate<T>::List | 204 | typename OPimAccessTemplate<T>::List |
201 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 205 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { |
202 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | 206 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); |
203 | 207 | ||
204 | List lis(ints, this ); | 208 | List lis(ints, this ); |
205 | return lis; | 209 | return lis; |
206 | } | 210 | } |
207 | template <class T> | 211 | template <class T> |
208 | T OPimAccessTemplate<T>::find( int uid ) const{ | 212 | T OPimAccessTemplate<T>::find( int uid ) const{ |
209 | T t = m_backEnd->find( uid ); | 213 | T t = m_backEnd->find( uid ); |
210 | cache( t ); | 214 | cache( t ); |
211 | return t; | 215 | return t; |
212 | } | 216 | } |
213 | template <class T> | 217 | template <class T> |
214 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 218 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
215 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 219 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
216 | /* | 220 | /* |
217 | * better do T.isEmpty() | 221 | * better do T.isEmpty() |
218 | * after a find this way we would | 222 | * after a find this way we would |
219 | * avoid two finds in QCache... | 223 | * avoid two finds in QCache... |
220 | */ | 224 | */ |
221 | // qWarning("find it now %d", uid ); | 225 | // qWarning("find it now %d", uid ); |
222 | if (m_cache.contains( uid ) ) { | 226 | if (m_cache.contains( uid ) ) { |
223 | return m_cache.find( uid ); | 227 | return m_cache.find( uid ); |
224 | } | 228 | } |
225 | 229 | ||
226 | T t = m_backEnd->find( uid, ar, current, dir ); | 230 | T t = m_backEnd->find( uid, ar, current, dir ); |
227 | cache( t ); | 231 | cache( t ); |
228 | return t; | 232 | return t; |
229 | } | 233 | } |
230 | template <class T> | 234 | template <class T> |
231 | void OPimAccessTemplate<T>::clear() { | 235 | void OPimAccessTemplate<T>::clear() { |
232 | invalidateCache(); | 236 | invalidateCache(); |
233 | m_backEnd->clear(); | 237 | m_backEnd->clear(); |
234 | } | 238 | } |
235 | template <class T> | 239 | template <class T> |
236 | bool OPimAccessTemplate<T>::add( const T& t ) { | 240 | bool OPimAccessTemplate<T>::add( const T& t ) { |
237 | cache( t ); | 241 | cache( t ); |
238 | return m_backEnd->add( t ); | 242 | return m_backEnd->add( t ); |
239 | } | 243 | } |
240 | template <class T> | 244 | template <class T> |
241 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 245 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
242 | /* same type */ | 246 | /* same type */ |
243 | if ( rec.rtti() == T::rtti() ) { | 247 | if ( rec.rtti() == T::rtti() ) { |
244 | const T &t = static_cast<const T&>(rec); | 248 | const T &t = static_cast<const T&>(rec); |
245 | return add(t); | 249 | return add(t); |
246 | } | 250 | } |
247 | return false; | 251 | return false; |
248 | } | 252 | } |
249 | template <class T> | 253 | template <class T> |
250 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 254 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
251 | return remove( t.uid() ); | 255 | return remove( t.uid() ); |
252 | } | 256 | } |
253 | template <class T> | 257 | template <class T> |
254 | bool OPimAccessTemplate<T>::remove( int uid ) { | 258 | bool OPimAccessTemplate<T>::remove( int uid ) { |
255 | m_cache.remove( uid ); | 259 | m_cache.remove( uid ); |
256 | return m_backEnd->remove( uid ); | 260 | return m_backEnd->remove( uid ); |
257 | } | 261 | } |
258 | template <class T> | 262 | template <class T> |
259 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 263 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
260 | return remove( rec.uid() ); | 264 | return remove( rec.uid() ); |
261 | } | 265 | } |
262 | template <class T> | 266 | template <class T> |
263 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 267 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
264 | m_cache.replace( t ); | 268 | m_cache.replace( t ); |
265 | return m_backEnd->replace( t ); | 269 | return m_backEnd->replace( t ); |
266 | } | 270 | } |
267 | template <class T> | 271 | template <class T> |
268 | void OPimAccessTemplate<T>::invalidateCache() { | 272 | void OPimAccessTemplate<T>::invalidateCache() { |
269 | m_cache.invalidate(); | 273 | m_cache.invalidate(); |
270 | } | 274 | } |
271 | template <class T> | 275 | template <class T> |
272 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 276 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
273 | return m_backEnd; | 277 | return m_backEnd; |
274 | } | 278 | } |
275 | template <class T> | 279 | template <class T> |
276 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 280 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
277 | return false; | 281 | return false; |
278 | } | 282 | } |
279 | template <class T> | 283 | template <class T> |
280 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 284 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
281 | m_backEnd = end; | 285 | m_backEnd = end; |
282 | if (m_backEnd ) | 286 | if (m_backEnd ) |
283 | m_backEnd->setFrontend( this ); | 287 | m_backEnd->setFrontend( this ); |
284 | } | 288 | } |
285 | template <class T> | 289 | template <class T> |
286 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 290 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
287 | /* hacky we need to work around the const*/ | 291 | /* hacky we need to work around the const*/ |
288 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 292 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
289 | } | 293 | } |
290 | template <class T> | 294 | template <class T> |
291 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 295 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
292 | m_cache.setSize( size ); | 296 | m_cache.setSize( size ); |
293 | } | 297 | } |
294 | template <class T> | 298 | template <class T> |
295 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | 299 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { |
296 | m_backEnd->setReadAhead( count ); | 300 | m_backEnd->setReadAhead( count ); |
297 | } | 301 | } |
298 | #endif | 302 | #endif |
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index 73414e5..7f7cff5 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h | |||
@@ -1,125 +1,131 @@ | |||
1 | #ifndef OPIE_PIM_CACHE_H | 1 | #ifndef OPIE_PIM_CACHE_H |
2 | #define OPIE_PIM_CACHE_H | 2 | #define OPIE_PIM_CACHE_H |
3 | 3 | ||
4 | #include <qintcache.h> | 4 | #include <qintcache.h> |
5 | 5 | ||
6 | #include "opimrecord.h" | 6 | #include "opimrecord.h" |
7 | 7 | ||
8 | class OPimCacheItemPrivate; | ||
9 | |||
8 | template <class T = OPimRecord> | 10 | template <class T = OPimRecord> |
9 | class OPimCacheItem { | 11 | class OPimCacheItem { |
10 | public: | 12 | public: |
11 | OPimCacheItem( const T& t = T() ); | 13 | OPimCacheItem( const T& t = T() ); |
12 | OPimCacheItem( const OPimCacheItem& ); | 14 | OPimCacheItem( const OPimCacheItem& ); |
13 | ~OPimCacheItem(); | 15 | ~OPimCacheItem(); |
14 | 16 | ||
15 | OPimCacheItem &operator=( const OPimCacheItem& ); | 17 | OPimCacheItem &operator=( const OPimCacheItem& ); |
16 | 18 | ||
17 | T record()const; | 19 | T record()const; |
18 | void setRecord( const T& ); | 20 | void setRecord( const T& ); |
19 | private: | 21 | private: |
20 | T m_t; | 22 | T m_t; |
23 | OPimCacheItemPrivate *d; | ||
21 | }; | 24 | }; |
22 | 25 | ||
26 | |||
27 | class OPimCachePrivate; | ||
23 | /** | 28 | /** |
24 | * OPimCache for caching the items | 29 | * OPimCache for caching the items |
25 | * We support adding, removing | 30 | * We support adding, removing |
26 | * and finding | 31 | * and finding |
27 | */ | 32 | */ |
28 | template <class T = OPimRecord> | 33 | template <class T = OPimRecord> |
29 | class OPimCache { | 34 | class OPimCache { |
30 | public: | 35 | public: |
31 | typedef OPimCacheItem<T> Item; | 36 | typedef OPimCacheItem<T> Item; |
32 | OPimCache(); | 37 | OPimCache(); |
33 | OPimCache( const OPimCache& ); | 38 | OPimCache( const OPimCache& ); |
34 | ~OPimCache(); | 39 | ~OPimCache(); |
35 | 40 | ||
36 | OPimCache &operator=( const OPimCache& ); | 41 | OPimCache &operator=( const OPimCache& ); |
37 | 42 | ||
38 | bool contains(int uid)const; | 43 | bool contains(int uid)const; |
39 | void invalidate(); | 44 | void invalidate(); |
40 | void setSize( int size ); | 45 | void setSize( int size ); |
41 | 46 | ||
42 | T find(int uid )const; | 47 | T find(int uid )const; |
43 | void add( const T& ); | 48 | void add( const T& ); |
44 | void remove( int uid ); | 49 | void remove( int uid ); |
45 | void replace( const T& ); | 50 | void replace( const T& ); |
46 | 51 | ||
47 | private: | 52 | private: |
48 | QIntCache<Item> m_cache; | 53 | QIntCache<Item> m_cache; |
54 | OPimCachePrivate* d; | ||
49 | }; | 55 | }; |
50 | 56 | ||
51 | // Implementation | 57 | // Implementation |
52 | template <class T> | 58 | template <class T> |
53 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 59 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
54 | : m_t(t) { | 60 | : m_t(t) { |
55 | } | 61 | } |
56 | template <class T> | 62 | template <class T> |
57 | OPimCacheItem<T>::~OPimCacheItem() { | 63 | OPimCacheItem<T>::~OPimCacheItem() { |
58 | 64 | ||
59 | } | 65 | } |
60 | template <class T> | 66 | template <class T> |
61 | T OPimCacheItem<T>::record()const { | 67 | T OPimCacheItem<T>::record()const { |
62 | return m_t; | 68 | return m_t; |
63 | } | 69 | } |
64 | template <class T> | 70 | template <class T> |
65 | void OPimCacheItem<T>::setRecord( const T& t ) { | 71 | void OPimCacheItem<T>::setRecord( const T& t ) { |
66 | m_t = t; | 72 | m_t = t; |
67 | } | 73 | } |
68 | // Cache | 74 | // Cache |
69 | template <class T> | 75 | template <class T> |
70 | OPimCache<T>::OPimCache() | 76 | OPimCache<T>::OPimCache() |
71 | : m_cache(100, 53 ) | 77 | : m_cache(100, 53 ) |
72 | { | 78 | { |
73 | m_cache.setAutoDelete( TRUE ); | 79 | m_cache.setAutoDelete( TRUE ); |
74 | } | 80 | } |
75 | template <class T> | 81 | template <class T> |
76 | OPimCache<T>::~OPimCache() { | 82 | OPimCache<T>::~OPimCache() { |
77 | 83 | ||
78 | } | 84 | } |
79 | template <class T> | 85 | template <class T> |
80 | bool OPimCache<T>::contains(int uid )const { | 86 | bool OPimCache<T>::contains(int uid )const { |
81 | Item* it = m_cache.find( uid, FALSE ); | 87 | Item* it = m_cache.find( uid, FALSE ); |
82 | if (!it) | 88 | if (!it) |
83 | return false; | 89 | return false; |
84 | return true; | 90 | return true; |
85 | } | 91 | } |
86 | template <class T> | 92 | template <class T> |
87 | void OPimCache<T>::invalidate() { | 93 | void OPimCache<T>::invalidate() { |
88 | m_cache.clear(); | 94 | m_cache.clear(); |
89 | } | 95 | } |
90 | template <class T> | 96 | template <class T> |
91 | void OPimCache<T>::setSize( int size ) { | 97 | void OPimCache<T>::setSize( int size ) { |
92 | m_cache.setMaxCost( size ); | 98 | m_cache.setMaxCost( size ); |
93 | } | 99 | } |
94 | template <class T> | 100 | template <class T> |
95 | T OPimCache<T>::find(int uid )const { | 101 | T OPimCache<T>::find(int uid )const { |
96 | Item *it = m_cache.find( uid ); | 102 | Item *it = m_cache.find( uid ); |
97 | if (it) | 103 | if (it) |
98 | return it->record(); | 104 | return it->record(); |
99 | return T(); | 105 | return T(); |
100 | } | 106 | } |
101 | template <class T> | 107 | template <class T> |
102 | void OPimCache<T>::add( const T& t ) { | 108 | void OPimCache<T>::add( const T& t ) { |
103 | Item* it = 0l; | 109 | Item* it = 0l; |
104 | it = m_cache.find(t.uid(), FALSE ); | 110 | it = m_cache.find(t.uid(), FALSE ); |
105 | 111 | ||
106 | if (it ) | 112 | if (it ) |
107 | it->setRecord( t ); | 113 | it->setRecord( t ); |
108 | 114 | ||
109 | it = new Item( t ); | 115 | it = new Item( t ); |
110 | if (!m_cache.insert( t.uid(), it ) ) | 116 | if (!m_cache.insert( t.uid(), it ) ) |
111 | delete it; | 117 | delete it; |
112 | } | 118 | } |
113 | template <class T> | 119 | template <class T> |
114 | void OPimCache<T>::remove( int uid ) { | 120 | void OPimCache<T>::remove( int uid ) { |
115 | m_cache.remove( uid ); | 121 | m_cache.remove( uid ); |
116 | } | 122 | } |
117 | template <class T> | 123 | template <class T> |
118 | void OPimCache<T>::replace( const T& t) { | 124 | void OPimCache<T>::replace( const T& t) { |
119 | Item *it = m_cache.find( t.uid() ); | 125 | Item *it = m_cache.find( t.uid() ); |
120 | if ( it ) { | 126 | if ( it ) { |
121 | it->setRecord( t ); | 127 | it->setRecord( t ); |
122 | } | 128 | } |
123 | } | 129 | } |
124 | 130 | ||
125 | #endif | 131 | #endif |
diff --git a/libopie2/opiepim/core/opimxrefmanager.h b/libopie2/opiepim/core/opimxrefmanager.h index 39e5eef..c485e98 100644 --- a/libopie2/opiepim/core/opimxrefmanager.h +++ b/libopie2/opiepim/core/opimxrefmanager.h | |||
@@ -1,41 +1,43 @@ | |||
1 | #ifndef OPIM_XREF_MANAGER_H | 1 | #ifndef OPIM_XREF_MANAGER_H |
2 | #define OPIM_XREF_MANAGER_H | 2 | #define OPIM_XREF_MANAGER_H |
3 | 3 | ||
4 | #include <qstringlist.h> | 4 | #include <qstringlist.h> |
5 | 5 | ||
6 | #include <opie/opimxref.h> | 6 | #include <opie/opimxref.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * This is a simple manager for | 9 | * This is a simple manager for |
10 | * OPimXRefs. | 10 | * OPimXRefs. |
11 | * It allows addition, removing, replacing | 11 | * It allows addition, removing, replacing |
12 | * clearing and 'querying' the XRef... | 12 | * clearing and 'querying' the XRef... |
13 | */ | 13 | */ |
14 | class OPimXRefManager { | 14 | class OPimXRefManager { |
15 | public: | 15 | public: |
16 | OPimXRefManager(); | 16 | OPimXRefManager(); |
17 | OPimXRefManager( const OPimXRefManager& ); | 17 | OPimXRefManager( const OPimXRefManager& ); |
18 | ~OPimXRefManager(); | 18 | ~OPimXRefManager(); |
19 | 19 | ||
20 | OPimXRefManager& operator=( const OPimXRefManager& ); | 20 | OPimXRefManager& operator=( const OPimXRefManager& ); |
21 | bool operator==( const OPimXRefManager& ); | 21 | bool operator==( const OPimXRefManager& ); |
22 | 22 | ||
23 | void add( const OPimXRef& ); | 23 | void add( const OPimXRef& ); |
24 | void remove( const OPimXRef& ); | 24 | void remove( const OPimXRef& ); |
25 | void replace( const OPimXRef& ); | 25 | void replace( const OPimXRef& ); |
26 | 26 | ||
27 | void clear(); | 27 | void clear(); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * apps participating | 30 | * apps participating |
31 | */ | 31 | */ |
32 | QStringList apps()const; | 32 | QStringList apps()const; |
33 | OPimXRef::ValueList list()const; | 33 | OPimXRef::ValueList list()const; |
34 | OPimXRef::ValueList list( const QString& service )const; | 34 | OPimXRef::ValueList list( const QString& service )const; |
35 | OPimXRef::ValueList list( int uid )const; | 35 | OPimXRef::ValueList list( int uid )const; |
36 | 36 | ||
37 | private: | 37 | private: |
38 | OPimXRef::ValueList m_list; | 38 | OPimXRef::ValueList m_list; |
39 | class Private; | ||
40 | Private *d; | ||
39 | }; | 41 | }; |
40 | 42 | ||
41 | #endif | 43 | #endif |
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h index 29fb6ec..cadac74 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/otemplatebase.h | |||
@@ -1,91 +1,98 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 1 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 2 | #define OPIE_TEMPLATE_BASE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | 7 | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Templates do not have a base class, This is why | 10 | * Templates do not have a base class, This is why |
11 | * we've this class | 11 | * we've this class |
12 | * this is here to give us the possibility | 12 | * this is here to give us the possibility |
13 | * to have a common base class | 13 | * to have a common base class |
14 | * You may not want to use that interface internaly | 14 | * You may not want to use that interface internaly |
15 | * POOR mans interface | 15 | * POOR mans interface |
16 | */ | 16 | */ |
17 | class OPimBasePrivate; | ||
17 | struct OPimBase { | 18 | struct OPimBase { |
18 | /** | 19 | /** |
19 | * return the rtti | 20 | * return the rtti |
20 | */ | 21 | */ |
21 | virtual int rtti()= 0; | 22 | virtual int rtti()= 0; |
22 | virtual OPimRecord* record()const = 0; | 23 | virtual OPimRecord* record()const = 0; |
23 | virtual OPimRecord* record(int uid)const = 0; | 24 | virtual OPimRecord* record(int uid)const = 0; |
24 | virtual bool add( const OPimRecord& ) = 0; | 25 | virtual bool add( const OPimRecord& ) = 0; |
25 | virtual bool remove( int uid ) = 0; | 26 | virtual bool remove( int uid ) = 0; |
26 | virtual bool remove( const OPimRecord& ) = 0; | 27 | virtual bool remove( const OPimRecord& ) = 0; |
27 | virtual void clear() = 0; | 28 | virtual void clear() = 0; |
28 | virtual bool load() = 0; | 29 | virtual bool load() = 0; |
29 | virtual bool save() = 0; | 30 | virtual bool save() = 0; |
30 | virtual QArray<int> records()const = 0; | 31 | virtual QArray<int> records()const = 0; |
31 | /* | 32 | /* |
32 | * ADD editing here? | 33 | * ADD editing here? |
33 | * -zecke | 34 | * -zecke |
34 | */ | 35 | */ |
36 | private: | ||
37 | OPimBasePrivate* d; | ||
35 | 38 | ||
36 | }; | 39 | }; |
37 | /** | 40 | /** |
38 | * internal template base | 41 | * internal template base |
39 | * T needs to implement the copy c'tor!!! | 42 | * T needs to implement the copy c'tor!!! |
40 | */ | 43 | */ |
44 | class OTemplateBasePrivate; | ||
41 | template <class T = OPimRecord> | 45 | template <class T = OPimRecord> |
42 | class OTemplateBase : public OPimBase { | 46 | class OTemplateBase : public OPimBase { |
43 | public: | 47 | public: |
44 | enum CacheDirection { Forward=0, Reverse }; | 48 | enum CacheDirection { Forward=0, Reverse }; |
45 | OTemplateBase() { | 49 | OTemplateBase() { |
46 | }; | 50 | }; |
47 | virtual ~OTemplateBase() { | 51 | virtual ~OTemplateBase() { |
48 | } | 52 | } |
49 | virtual T find( int uid )const = 0; | 53 | virtual T find( int uid )const = 0; |
50 | 54 | ||
51 | /** | 55 | /** |
52 | * read ahead find | 56 | * read ahead find |
53 | */ | 57 | */ |
54 | virtual T find( int uid, const QArray<int>& items, | 58 | virtual T find( int uid, const QArray<int>& items, |
55 | uint current, CacheDirection dir = Forward )const = 0; | 59 | uint current, CacheDirection dir = Forward )const = 0; |
56 | virtual void cache( const T& )const = 0; | 60 | virtual void cache( const T& )const = 0; |
57 | virtual void setSaneCacheSize( int ) = 0; | 61 | virtual void setSaneCacheSize( int ) = 0; |
58 | 62 | ||
59 | /* reimplement of OPimBase */ | 63 | /* reimplement of OPimBase */ |
60 | int rtti(); | 64 | int rtti(); |
61 | OPimRecord* record()const; | 65 | OPimRecord* record()const; |
62 | OPimRecord* record(int uid )const; | 66 | OPimRecord* record(int uid )const; |
63 | static T* rec(); | 67 | static T* rec(); |
68 | |||
69 | private: | ||
70 | OTemplateBasePrivate *d; | ||
64 | }; | 71 | }; |
65 | 72 | ||
66 | /* | 73 | /* |
67 | * implementation | 74 | * implementation |
68 | */ | 75 | */ |
69 | template <class T> | 76 | template <class T> |
70 | int | 77 | int |
71 | OTemplateBase<T>::rtti() { | 78 | OTemplateBase<T>::rtti() { |
72 | return T::rtti(); | 79 | return T::rtti(); |
73 | } | 80 | } |
74 | template <class T> | 81 | template <class T> |
75 | OPimRecord* OTemplateBase<T>::record()const { | 82 | OPimRecord* OTemplateBase<T>::record()const { |
76 | T* t = new T; | 83 | T* t = new T; |
77 | return t; | 84 | return t; |
78 | } | 85 | } |
79 | template <class T> | 86 | template <class T> |
80 | OPimRecord* OTemplateBase<T>::record(int uid )const { | 87 | OPimRecord* OTemplateBase<T>::record(int uid )const { |
81 | T t2 = find(uid ); | 88 | T t2 = find(uid ); |
82 | T* t1 = new T(t2); | 89 | T* t1 = new T(t2); |
83 | 90 | ||
84 | return t1; | 91 | return t1; |
85 | }; | 92 | }; |
86 | template <class T> | 93 | template <class T> |
87 | T* OTemplateBase<T>::rec() { | 94 | T* OTemplateBase<T>::rec() { |
88 | return new T; | 95 | return new T; |
89 | } | 96 | } |
90 | 97 | ||
91 | #endif | 98 | #endif |
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index be4ce0a..3473baa 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -1,1138 +1,1211 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #define QTOPIA_INTERNAL_CONTACT_MRE | 20 | #define QTOPIA_INTERNAL_CONTACT_MRE |
21 | 21 | ||
22 | #include "ocontact.h" | 22 | #include "ocontact.h" |
23 | #include "opimresolver.h" | 23 | #include "opimresolver.h" |
24 | #include "oconversion.h" | ||
24 | 25 | ||
25 | #include <qpe/stringutil.h> | 26 | #include <qpe/stringutil.h> |
26 | #include "oconversion.h" | ||
27 | #include <qpe/timestring.h> | 27 | #include <qpe/timestring.h> |
28 | #include <qpe/config.h> | ||
28 | 29 | ||
29 | #include <qobject.h> | 30 | #include <qobject.h> |
30 | #include <qregexp.h> | 31 | #include <qregexp.h> |
31 | #include <qstylesheet.h> | 32 | #include <qstylesheet.h> |
32 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
33 | #include <qmap.h> | 34 | #include <qmap.h> |
34 | 35 | ||
35 | #include <stdio.h> | 36 | #include <stdio.h> |
36 | 37 | ||
37 | /*! | 38 | /*! |
38 | \class Contact contact.h | 39 | \class Contact contact.h |
39 | \brief The Contact class holds the data of an address book entry. | 40 | \brief The Contact class holds the data of an address book entry. |
40 | 41 | ||
41 | This data includes information the name of the person, contact | 42 | This data includes information the name of the person, contact |
42 | information, and business information such as deparment and job title. | 43 | information, and business information such as deparment and job title. |
43 | 44 | ||
44 | \ingroup qtopiaemb | 45 | \ingroup qtopiaemb |
45 | \ingroup qtopiadesktop | 46 | \ingroup qtopiadesktop |
46 | */ | 47 | */ |
47 | 48 | ||
48 | 49 | ||
49 | /*! | 50 | /*! |
50 | Creates a new, empty contact. | 51 | Creates a new, empty contact. |
51 | */ | 52 | */ |
52 | OContact::OContact() | 53 | OContact::OContact() |
53 | : OPimRecord(), mMap(), d( 0 ) | 54 | : OPimRecord(), mMap(), d( 0 ) |
54 | { | 55 | { |
55 | } | 56 | } |
56 | 57 | ||
57 | /*! | 58 | /*! |
58 | \internal | 59 | \internal |
59 | Creates a new contact. The properties of the contact are | 60 | Creates a new contact. The properties of the contact are |
60 | set from \a fromMap. | 61 | set from \a fromMap. |
61 | */ | 62 | */ |
62 | OContact::OContact( const QMap<int, QString> &fromMap ) : | 63 | OContact::OContact( const QMap<int, QString> &fromMap ) : |
63 | OPimRecord(), mMap( fromMap ), d( 0 ) | 64 | OPimRecord(), mMap( fromMap ), d( 0 ) |
64 | { | 65 | { |
65 | QString cats = mMap[ Qtopia::AddressCategory ]; | 66 | QString cats = mMap[ Qtopia::AddressCategory ]; |
66 | if ( !cats.isEmpty() ) | 67 | if ( !cats.isEmpty() ) |
67 | setCategories( idsFromString( cats ) ); | 68 | setCategories( idsFromString( cats ) ); |
68 | 69 | ||
69 | QString uidStr = find( Qtopia::AddressUid ); | 70 | QString uidStr = find( Qtopia::AddressUid ); |
70 | 71 | ||
71 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ | 72 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ |
72 | qWarning( "Invalid UID found. Generate new one.." ); | 73 | qWarning( "Invalid UID found. Generate new one.." ); |
73 | setUid( uidGen().generate() ); | 74 | setUid( uidGen().generate() ); |
74 | }else | 75 | }else |
75 | setUid( uidStr.toInt() ); | 76 | setUid( uidStr.toInt() ); |
76 | 77 | ||
77 | // if ( !uidStr.isEmpty() ) | 78 | // if ( !uidStr.isEmpty() ) |
78 | // setUid( uidStr.toInt() ); | 79 | // setUid( uidStr.toInt() ); |
79 | } | 80 | } |
80 | 81 | ||
81 | /*! | 82 | /*! |
82 | Destroys a contact. | 83 | Destroys a contact. |
83 | */ | 84 | */ |
84 | OContact::~OContact() | 85 | OContact::~OContact() |
85 | { | 86 | { |
86 | } | 87 | } |
87 | 88 | ||
88 | /*! \fn void OContact::setTitle( const QString &str ) | 89 | /*! \fn void OContact::setTitle( const QString &str ) |
89 | Sets the title of the contact to \a str. | 90 | Sets the title of the contact to \a str. |
90 | */ | 91 | */ |
91 | 92 | ||
92 | /*! \fn void OContact::setFirstName( const QString &str ) | 93 | /*! \fn void OContact::setFirstName( const QString &str ) |
93 | Sets the first name of the contact to \a str. | 94 | Sets the first name of the contact to \a str. |
94 | */ | 95 | */ |
95 | 96 | ||
96 | /*! \fn void OContact::setMiddleName( const QString &str ) | 97 | /*! \fn void OContact::setMiddleName( const QString &str ) |
97 | Sets the middle name of the contact to \a str. | 98 | Sets the middle name of the contact to \a str. |
98 | */ | 99 | */ |
99 | 100 | ||
100 | /*! \fn void OContact::setLastName( const QString &str ) | 101 | /*! \fn void OContact::setLastName( const QString &str ) |
101 | Sets the last name of the contact to \a str. | 102 | Sets the last name of the contact to \a str. |
102 | */ | 103 | */ |
103 | 104 | ||
104 | /*! \fn void OContact::setSuffix( const QString &str ) | 105 | /*! \fn void OContact::setSuffix( const QString &str ) |
105 | Sets the suffix of the contact to \a str. | 106 | Sets the suffix of the contact to \a str. |
106 | */ | 107 | */ |
107 | 108 | ||
108 | /*! \fn void OContact::setFileAs( const QString &str ) | 109 | /*! \fn void OContact::setFileAs( const QString &str ) |
109 | Sets the contact to filed as \a str. | 110 | Sets the contact to filed as \a str. |
110 | */ | 111 | */ |
111 | 112 | ||
112 | /*! \fn void OContact::setDefaultEmail( const QString &str ) | 113 | /*! \fn void OContact::setDefaultEmail( const QString &str ) |
113 | Sets the default email of the contact to \a str. | 114 | Sets the default email of the contact to \a str. |
114 | */ | 115 | */ |
115 | 116 | ||
116 | /*! \fn void OContact::setHomeStreet( const QString &str ) | 117 | /*! \fn void OContact::setHomeStreet( const QString &str ) |
117 | Sets the home street address of the contact to \a str. | 118 | Sets the home street address of the contact to \a str. |
118 | */ | 119 | */ |
119 | 120 | ||
120 | /*! \fn void OContact::setHomeCity( const QString &str ) | 121 | /*! \fn void OContact::setHomeCity( const QString &str ) |
121 | Sets the home city of the contact to \a str. | 122 | Sets the home city of the contact to \a str. |
122 | */ | 123 | */ |
123 | 124 | ||
124 | /*! \fn void OContact::setHomeState( const QString &str ) | 125 | /*! \fn void OContact::setHomeState( const QString &str ) |
125 | Sets the home state of the contact to \a str. | 126 | Sets the home state of the contact to \a str. |
126 | */ | 127 | */ |
127 | 128 | ||
128 | /*! \fn void OContact::setHomeZip( const QString &str ) | 129 | /*! \fn void OContact::setHomeZip( const QString &str ) |
129 | Sets the home zip code of the contact to \a str. | 130 | Sets the home zip code of the contact to \a str. |
130 | */ | 131 | */ |
131 | 132 | ||
132 | /*! \fn void OContact::setHomeCountry( const QString &str ) | 133 | /*! \fn void OContact::setHomeCountry( const QString &str ) |
133 | Sets the home country of the contact to \a str. | 134 | Sets the home country of the contact to \a str. |
134 | */ | 135 | */ |
135 | 136 | ||
136 | /*! \fn void OContact::setHomePhone( const QString &str ) | 137 | /*! \fn void OContact::setHomePhone( const QString &str ) |
137 | Sets the home phone number of the contact to \a str. | 138 | Sets the home phone number of the contact to \a str. |
138 | */ | 139 | */ |
139 | 140 | ||
140 | /*! \fn void OContact::setHomeFax( const QString &str ) | 141 | /*! \fn void OContact::setHomeFax( const QString &str ) |
141 | Sets the home fax number of the contact to \a str. | 142 | Sets the home fax number of the contact to \a str. |
142 | */ | 143 | */ |
143 | 144 | ||
144 | /*! \fn void OContact::setHomeMobile( const QString &str ) | 145 | /*! \fn void OContact::setHomeMobile( const QString &str ) |
145 | Sets the home mobile phone number of the contact to \a str. | 146 | Sets the home mobile phone number of the contact to \a str. |
146 | */ | 147 | */ |
147 | 148 | ||
148 | /*! \fn void OContact::setHomeWebpage( const QString &str ) | 149 | /*! \fn void OContact::setHomeWebpage( const QString &str ) |
149 | Sets the home webpage of the contact to \a str. | 150 | Sets the home webpage of the contact to \a str. |
150 | */ | 151 | */ |
151 | 152 | ||
152 | /*! \fn void OContact::setCompany( const QString &str ) | 153 | /*! \fn void OContact::setCompany( const QString &str ) |
153 | Sets the company for contact to \a str. | 154 | Sets the company for contact to \a str. |
154 | */ | 155 | */ |
155 | 156 | ||
156 | /*! \fn void OContact::setJobTitle( const QString &str ) | 157 | /*! \fn void OContact::setJobTitle( const QString &str ) |
157 | Sets the job title of the contact to \a str. | 158 | Sets the job title of the contact to \a str. |
158 | */ | 159 | */ |
159 | 160 | ||
160 | /*! \fn void OContact::setDepartment( const QString &str ) | 161 | /*! \fn void OContact::setDepartment( const QString &str ) |
161 | Sets the department for contact to \a str. | 162 | Sets the department for contact to \a str. |
162 | */ | 163 | */ |
163 | 164 | ||
164 | /*! \fn void OContact::setOffice( const QString &str ) | 165 | /*! \fn void OContact::setOffice( const QString &str ) |
165 | Sets the office for contact to \a str. | 166 | Sets the office for contact to \a str. |
166 | */ | 167 | */ |
167 | 168 | ||
168 | /*! \fn void OContact::setBusinessStreet( const QString &str ) | 169 | /*! \fn void OContact::setBusinessStreet( const QString &str ) |
169 | Sets the business street address of the contact to \a str. | 170 | Sets the business street address of the contact to \a str. |
170 | */ | 171 | */ |
171 | 172 | ||
172 | /*! \fn void OContact::setBusinessCity( const QString &str ) | 173 | /*! \fn void OContact::setBusinessCity( const QString &str ) |
173 | Sets the business city of the contact to \a str. | 174 | Sets the business city of the contact to \a str. |
174 | */ | 175 | */ |
175 | 176 | ||
176 | /*! \fn void OContact::setBusinessState( const QString &str ) | 177 | /*! \fn void OContact::setBusinessState( const QString &str ) |
177 | Sets the business state of the contact to \a str. | 178 | Sets the business state of the contact to \a str. |
178 | */ | 179 | */ |
179 | 180 | ||
180 | /*! \fn void OContact::setBusinessZip( const QString &str ) | 181 | /*! \fn void OContact::setBusinessZip( const QString &str ) |
181 | Sets the business zip code of the contact to \a str. | 182 | Sets the business zip code of the contact to \a str. |
182 | */ | 183 | */ |
183 | 184 | ||
184 | /*! \fn void OContact::setBusinessCountry( const QString &str ) | 185 | /*! \fn void OContact::setBusinessCountry( const QString &str ) |
185 | Sets the business country of the contact to \a str. | 186 | Sets the business country of the contact to \a str. |
186 | */ | 187 | */ |
187 | 188 | ||
188 | /*! \fn void OContact::setBusinessPhone( const QString &str ) | 189 | /*! \fn void OContact::setBusinessPhone( const QString &str ) |
189 | Sets the business phone number of the contact to \a str. | 190 | Sets the business phone number of the contact to \a str. |
190 | */ | 191 | */ |
191 | 192 | ||
192 | /*! \fn void OContact::setBusinessFax( const QString &str ) | 193 | /*! \fn void OContact::setBusinessFax( const QString &str ) |
193 | Sets the business fax number of the contact to \a str. | 194 | Sets the business fax number of the contact to \a str. |
194 | */ | 195 | */ |
195 | 196 | ||
196 | /*! \fn void OContact::setBusinessMobile( const QString &str ) | 197 | /*! \fn void OContact::setBusinessMobile( const QString &str ) |
197 | Sets the business mobile phone number of the contact to \a str. | 198 | Sets the business mobile phone number of the contact to \a str. |
198 | */ | 199 | */ |
199 | 200 | ||
200 | /*! \fn void OContact::setBusinessPager( const QString &str ) | 201 | /*! \fn void OContact::setBusinessPager( const QString &str ) |
201 | Sets the business pager number of the contact to \a str. | 202 | Sets the business pager number of the contact to \a str. |
202 | */ | 203 | */ |
203 | 204 | ||
204 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) | 205 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) |
205 | Sets the business webpage of the contact to \a str. | 206 | Sets the business webpage of the contact to \a str. |
206 | */ | 207 | */ |
207 | 208 | ||
208 | /*! \fn void OContact::setProfession( const QString &str ) | 209 | /*! \fn void OContact::setProfession( const QString &str ) |
209 | Sets the profession of the contact to \a str. | 210 | Sets the profession of the contact to \a str. |
210 | */ | 211 | */ |
211 | 212 | ||
212 | /*! \fn void OContact::setAssistant( const QString &str ) | 213 | /*! \fn void OContact::setAssistant( const QString &str ) |
213 | Sets the assistant of the contact to \a str. | 214 | Sets the assistant of the contact to \a str. |
214 | */ | 215 | */ |
215 | 216 | ||
216 | /*! \fn void OContact::setManager( const QString &str ) | 217 | /*! \fn void OContact::setManager( const QString &str ) |
217 | Sets the manager of the contact to \a str. | 218 | Sets the manager of the contact to \a str. |
218 | */ | 219 | */ |
219 | 220 | ||
220 | /*! \fn void OContact::setSpouse( const QString &str ) | 221 | /*! \fn void OContact::setSpouse( const QString &str ) |
221 | Sets the spouse of the contact to \a str. | 222 | Sets the spouse of the contact to \a str. |
222 | */ | 223 | */ |
223 | 224 | ||
224 | /*! \fn void OContact::setGender( const QString &str ) | 225 | /*! \fn void OContact::setGender( const QString &str ) |
225 | Sets the gender of the contact to \a str. | 226 | Sets the gender of the contact to \a str. |
226 | */ | 227 | */ |
227 | 228 | ||
228 | /*! \fn void OContact::setNickname( const QString &str ) | 229 | /*! \fn void OContact::setNickname( const QString &str ) |
229 | Sets the nickname of the contact to \a str. | 230 | Sets the nickname of the contact to \a str. |
230 | */ | 231 | */ |
231 | 232 | ||
232 | /*! \fn void OContact::setNotes( const QString &str ) | 233 | /*! \fn void OContact::setNotes( const QString &str ) |
233 | Sets the notes about the contact to \a str. | 234 | Sets the notes about the contact to \a str. |
234 | */ | 235 | */ |
235 | 236 | ||
236 | /*! \fn QString OContact::title() const | 237 | /*! \fn QString OContact::title() const |
237 | Returns the title of the contact. | 238 | Returns the title of the contact. |
238 | */ | 239 | */ |
239 | 240 | ||
240 | /*! \fn QString OContact::firstName() const | 241 | /*! \fn QString OContact::firstName() const |
241 | Returns the first name of the contact. | 242 | Returns the first name of the contact. |
242 | */ | 243 | */ |
243 | 244 | ||
244 | /*! \fn QString OContact::middleName() const | 245 | /*! \fn QString OContact::middleName() const |
245 | Returns the middle name of the contact. | 246 | Returns the middle name of the contact. |
246 | */ | 247 | */ |
247 | 248 | ||
248 | /*! \fn QString OContact::lastName() const | 249 | /*! \fn QString OContact::lastName() const |
249 | Returns the last name of the contact. | 250 | Returns the last name of the contact. |
250 | */ | 251 | */ |
251 | 252 | ||
252 | /*! \fn QString OContact::suffix() const | 253 | /*! \fn QString OContact::suffix() const |
253 | Returns the suffix of the contact. | 254 | Returns the suffix of the contact. |
254 | */ | 255 | */ |
255 | 256 | ||
256 | /*! \fn QString OContact::fileAs() const | 257 | /*! \fn QString OContact::fileAs() const |
257 | Returns the string the contact is filed as. | 258 | Returns the string the contact is filed as. |
258 | */ | 259 | */ |
259 | 260 | ||
260 | /*! \fn QString OContact::defaultEmail() const | 261 | /*! \fn QString OContact::defaultEmail() const |
261 | Returns the default email address of the contact. | 262 | Returns the default email address of the contact. |
262 | */ | 263 | */ |
263 | 264 | ||
264 | /*! \fn QString OContact::emails() const | 265 | /*! \fn QString OContact::emails() const |
265 | Returns the list of email address for a contact separated by ';'s in a single | 266 | Returns the list of email address for a contact separated by ';'s in a single |
266 | string. | 267 | string. |
267 | */ | 268 | */ |
268 | 269 | ||
269 | /*! \fn QString OContact::homeStreet() const | 270 | /*! \fn QString OContact::homeStreet() const |
270 | Returns the home street address of the contact. | 271 | Returns the home street address of the contact. |
271 | */ | 272 | */ |
272 | 273 | ||
273 | /*! \fn QString OContact::homeCity() const | 274 | /*! \fn QString OContact::homeCity() const |
274 | Returns the home city of the contact. | 275 | Returns the home city of the contact. |
275 | */ | 276 | */ |
276 | 277 | ||
277 | /*! \fn QString OContact::homeState() const | 278 | /*! \fn QString OContact::homeState() const |
278 | Returns the home state of the contact. | 279 | Returns the home state of the contact. |
279 | */ | 280 | */ |
280 | 281 | ||
281 | /*! \fn QString OContact::homeZip() const | 282 | /*! \fn QString OContact::homeZip() const |
282 | Returns the home zip of the contact. | 283 | Returns the home zip of the contact. |
283 | */ | 284 | */ |
284 | 285 | ||
285 | /*! \fn QString OContact::homeCountry() const | 286 | /*! \fn QString OContact::homeCountry() const |
286 | Returns the home country of the contact. | 287 | Returns the home country of the contact. |
287 | */ | 288 | */ |
288 | 289 | ||
289 | /*! \fn QString OContact::homePhone() const | 290 | /*! \fn QString OContact::homePhone() const |
290 | Returns the home phone number of the contact. | 291 | Returns the home phone number of the contact. |
291 | */ | 292 | */ |
292 | 293 | ||
293 | /*! \fn QString OContact::homeFax() const | 294 | /*! \fn QString OContact::homeFax() const |
294 | Returns the home fax number of the contact. | 295 | Returns the home fax number of the contact. |
295 | */ | 296 | */ |
296 | 297 | ||
297 | /*! \fn QString OContact::homeMobile() const | 298 | /*! \fn QString OContact::homeMobile() const |
298 | Returns the home mobile number of the contact. | 299 | Returns the home mobile number of the contact. |
299 | */ | 300 | */ |
300 | 301 | ||
301 | /*! \fn QString OContact::homeWebpage() const | 302 | /*! \fn QString OContact::homeWebpage() const |
302 | Returns the home webpage of the contact. | 303 | Returns the home webpage of the contact. |
303 | */ | 304 | */ |
304 | 305 | ||
305 | /*! \fn QString OContact::company() const | 306 | /*! \fn QString OContact::company() const |
306 | Returns the company for the contact. | 307 | Returns the company for the contact. |
307 | */ | 308 | */ |
308 | 309 | ||
309 | /*! \fn QString OContact::department() const | 310 | /*! \fn QString OContact::department() const |
310 | Returns the department for the contact. | 311 | Returns the department for the contact. |
311 | */ | 312 | */ |
312 | 313 | ||
313 | /*! \fn QString OContact::office() const | 314 | /*! \fn QString OContact::office() const |
314 | Returns the office for the contact. | 315 | Returns the office for the contact. |
315 | */ | 316 | */ |
316 | 317 | ||
317 | /*! \fn QString OContact::jobTitle() const | 318 | /*! \fn QString OContact::jobTitle() const |
318 | Returns the job title of the contact. | 319 | Returns the job title of the contact. |
319 | */ | 320 | */ |
320 | 321 | ||
321 | /*! \fn QString OContact::profession() const | 322 | /*! \fn QString OContact::profession() const |
322 | Returns the profession of the contact. | 323 | Returns the profession of the contact. |
323 | */ | 324 | */ |
324 | 325 | ||
325 | /*! \fn QString OContact::assistant() const | 326 | /*! \fn QString OContact::assistant() const |
326 | Returns the assistant of the contact. | 327 | Returns the assistant of the contact. |
327 | */ | 328 | */ |
328 | 329 | ||
329 | /*! \fn QString OContact::manager() const | 330 | /*! \fn QString OContact::manager() const |
330 | Returns the manager of the contact. | 331 | Returns the manager of the contact. |
331 | */ | 332 | */ |
332 | 333 | ||
333 | /*! \fn QString OContact::businessStreet() const | 334 | /*! \fn QString OContact::businessStreet() const |
334 | Returns the business street address of the contact. | 335 | Returns the business street address of the contact. |
335 | */ | 336 | */ |
336 | 337 | ||
337 | /*! \fn QString OContact::businessCity() const | 338 | /*! \fn QString OContact::businessCity() const |
338 | Returns the business city of the contact. | 339 | Returns the business city of the contact. |
339 | */ | 340 | */ |
340 | 341 | ||
341 | /*! \fn QString OContact::businessState() const | 342 | /*! \fn QString OContact::businessState() const |
342 | Returns the business state of the contact. | 343 | Returns the business state of the contact. |
343 | */ | 344 | */ |
344 | 345 | ||
345 | /*! \fn QString OContact::businessZip() const | 346 | /*! \fn QString OContact::businessZip() const |
346 | Returns the business zip of the contact. | 347 | Returns the business zip of the contact. |
347 | */ | 348 | */ |
348 | 349 | ||
349 | /*! \fn QString OContact::businessCountry() const | 350 | /*! \fn QString OContact::businessCountry() const |
350 | Returns the business country of the contact. | 351 | Returns the business country of the contact. |
351 | */ | 352 | */ |
352 | 353 | ||
353 | /*! \fn QString OContact::businessPhone() const | 354 | /*! \fn QString OContact::businessPhone() const |
354 | Returns the business phone number of the contact. | 355 | Returns the business phone number of the contact. |
355 | */ | 356 | */ |
356 | 357 | ||
357 | /*! \fn QString OContact::businessFax() const | 358 | /*! \fn QString OContact::businessFax() const |
358 | Returns the business fax number of the contact. | 359 | Returns the business fax number of the contact. |
359 | */ | 360 | */ |
360 | 361 | ||
361 | /*! \fn QString OContact::businessMobile() const | 362 | /*! \fn QString OContact::businessMobile() const |
362 | Returns the business mobile number of the contact. | 363 | Returns the business mobile number of the contact. |
363 | */ | 364 | */ |
364 | 365 | ||
365 | /*! \fn QString OContact::businessPager() const | 366 | /*! \fn QString OContact::businessPager() const |
366 | Returns the business pager number of the contact. | 367 | Returns the business pager number of the contact. |
367 | */ | 368 | */ |
368 | 369 | ||
369 | /*! \fn QString OContact::businessWebpage() const | 370 | /*! \fn QString OContact::businessWebpage() const |
370 | Returns the business webpage of the contact. | 371 | Returns the business webpage of the contact. |
371 | */ | 372 | */ |
372 | 373 | ||
373 | /*! \fn QString OContact::spouse() const | 374 | /*! \fn QString OContact::spouse() const |
374 | Returns the spouse of the contact. | 375 | Returns the spouse of the contact. |
375 | */ | 376 | */ |
376 | 377 | ||
377 | /*! \fn QString OContact::gender() const | 378 | /*! \fn QString OContact::gender() const |
378 | Returns the gender of the contact. | 379 | Returns the gender of the contact. |
379 | */ | 380 | */ |
380 | 381 | ||
381 | /*! \fn QString OContact::nickname() const | 382 | /*! \fn QString OContact::nickname() const |
382 | Returns the nickname of the contact. | 383 | Returns the nickname of the contact. |
383 | */ | 384 | */ |
384 | 385 | ||
385 | /*! \fn QString OContact::children() const | 386 | /*! \fn QString OContact::children() const |
386 | Returns the children of the contact. | 387 | Returns the children of the contact. |
387 | */ | 388 | */ |
388 | 389 | ||
389 | /*! \fn QString OContact::notes() const | 390 | /*! \fn QString OContact::notes() const |
390 | Returns the notes relating to the the contact. | 391 | Returns the notes relating to the the contact. |
391 | */ | 392 | */ |
392 | 393 | ||
393 | /*! \fn QString OContact::groups() const | 394 | /*! \fn QString OContact::groups() const |
394 | \internal | 395 | \internal |
395 | Returns the groups for the contact. | 396 | Returns the groups for the contact. |
396 | */ | 397 | */ |
397 | 398 | ||
398 | /*! \fn QStringList OContact::groupList() const | 399 | /*! \fn QStringList OContact::groupList() const |
399 | \internal | 400 | \internal |
400 | */ | 401 | */ |
401 | 402 | ||
402 | /*! \fn QString OContact::field(int) const | 403 | /*! \fn QString OContact::field(int) const |
403 | \internal | 404 | \internal |
404 | */ | 405 | */ |
405 | 406 | ||
406 | /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) | 407 | /*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) |
407 | \internal | 408 | \internal |
408 | */ | 409 | */ |
409 | 410 | ||
410 | /*! \fn void OContact::setUid( int id ) | 411 | /*! \fn void OContact::setUid( int id ) |
411 | \internal | 412 | \internal |
412 | Sets the uid for this record to \a id. | 413 | Sets the uid for this record to \a id. |
413 | */ | 414 | */ |
414 | 415 | ||
415 | /*! \enum OContact::journal_action | 416 | /*! \enum OContact::journal_action |
416 | \internal | 417 | \internal |
417 | */ | 418 | */ |
418 | 419 | ||
419 | /*! | 420 | /*! |
420 | \internal | 421 | \internal |
421 | */ | 422 | */ |
422 | QMap<int, QString> OContact::toMap() const | 423 | QMap<int, QString> OContact::toMap() const |
423 | { | 424 | { |
424 | QMap<int, QString> map = mMap; | 425 | QMap<int, QString> map = mMap; |
425 | QString cats = idsToString( categories() ); | 426 | QString cats = idsToString( categories() ); |
426 | if ( !cats.isEmpty() ) | 427 | if ( !cats.isEmpty() ) |
427 | map.insert( Qtopia::AddressCategory, cats ); | 428 | map.insert( Qtopia::AddressCategory, cats ); |
428 | return map; | 429 | return map; |
429 | } | 430 | } |
430 | 431 | ||
431 | /*! | 432 | /*! |
432 | Returns a rich text formatted QString representing the contents the contact. | 433 | Returns a rich text formatted QString representing the contents the contact. |
433 | */ | 434 | */ |
434 | QString OContact::toRichText() const | 435 | QString OContact::toRichText() const |
435 | { | 436 | { |
436 | QString text; | 437 | QString text; |
437 | QString value, comp, state; | 438 | QString value, comp, state; |
438 | QString str; | 439 | QString str; |
439 | bool marker = false; | 440 | bool marker = false; |
440 | 441 | ||
442 | Config cfg("qpe"); | ||
443 | cfg.setGroup("Appearance"); | ||
444 | int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); | ||
445 | |||
441 | // name, jobtitle and company | 446 | // name, jobtitle and company |
442 | if ( !(value = fullName()).isEmpty() ) | 447 | if ( !(value = fullName()).isEmpty() ) |
443 | text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>"; | 448 | text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString(value) + "</h3></b>"; |
444 | 449 | ||
445 | if ( !(value = jobTitle()).isEmpty() ) | 450 | if ( !(value = jobTitle()).isEmpty() ) |
446 | text += Qtopia::escapeString(value) + "<br>"; | 451 | text += Qtopia::escapeString(value); |
447 | 452 | ||
448 | comp = company(); | 453 | comp = company(); |
449 | if ( !(value = department()).isEmpty() ) { | 454 | if ( !(value = department()).isEmpty() ) { |
450 | text += Qtopia::escapeString(value); | 455 | text += Qtopia::escapeString(value); |
451 | if ( comp ) | 456 | if ( comp ) |
452 | text += ", "; | 457 | text += ", "; |
453 | else | 458 | else |
454 | text += "<br>"; | 459 | text += "<br>"; |
455 | } | 460 | } |
456 | if ( !comp.isEmpty() ) | 461 | if ( !comp.isEmpty() ) |
457 | text += Qtopia::escapeString(comp) + "<br>"; | 462 | text += Qtopia::escapeString(comp); |
458 | 463 | ||
459 | text += "<hr><br>"; | 464 | text += "<br><hr>"; |
460 | 465 | ||
461 | // defailt email | 466 | // defailt email |
462 | QString defEmail = defaultEmail(); | 467 | QString defEmail = defaultEmail(); |
463 | if ( !defEmail.isEmpty() ) | 468 | if ( !defEmail.isEmpty() ){ |
464 | text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>" | 469 | text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>" |
465 | + Qtopia::escapeString(defEmail) + "<br>"; | 470 | + Qtopia::escapeString(defEmail); |
466 | 471 | marker = true; | |
467 | text += "<br>"; | 472 | } |
468 | 473 | ||
469 | // business address | 474 | // business address |
470 | if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || | 475 | if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || |
471 | !businessZip().isEmpty() || !businessCountry().isEmpty() ) { | 476 | !businessZip().isEmpty() || !businessCountry().isEmpty() ) { |
472 | text += QObject::tr( "<b>Work Address:</b>" ); | 477 | text += QObject::tr( "<br><br><b>Work Address:</b>" ); |
473 | text += "<br>"; | ||
474 | marker = true; | 478 | marker = true; |
475 | } | 479 | } |
476 | 480 | ||
477 | if ( !(value = businessStreet()).isEmpty() ) | 481 | if ( !(value = businessStreet()).isEmpty() ){ |
478 | text += Qtopia::escapeString(value) + "<br>"; | 482 | text += "<br>" + Qtopia::escapeString(value); |
479 | state = businessState(); | 483 | marker = true; |
480 | if ( !(value = businessZip()).isEmpty() ) | 484 | } |
481 | text += Qtopia::escapeString(value) + " "; | 485 | |
482 | if ( !(value = businessCity()).isEmpty() ) { | 486 | switch( addressformat ){ |
483 | text += Qtopia::escapeString(value); | 487 | case Zip_City_State:{ // Zip_Code City, State |
484 | if ( state ) | 488 | state = businessState(); |
485 | text += ", " + Qtopia::escapeString(state); | 489 | if ( !(value = businessZip()).isEmpty() ){ |
486 | text += "<br>"; | 490 | text += "<br>" + Qtopia::escapeString(value) + " "; |
487 | } else if ( !state.isEmpty() ) | 491 | marker = true; |
488 | text += Qtopia::escapeString(state) + "<br>"; | 492 | |
493 | } else | ||
494 | text += "<br>"; | ||
495 | |||
496 | if ( !(value = businessCity()).isEmpty() ) { | ||
497 | marker = true; | ||
498 | text += Qtopia::escapeString(value); | ||
499 | if ( state ) | ||
500 | text += ", " + Qtopia::escapeString(state); | ||
501 | } else if ( !state.isEmpty() ){ | ||
502 | text += "<br>" + Qtopia::escapeString(state); | ||
503 | marker = true; | ||
504 | } | ||
505 | break; | ||
506 | } | ||
507 | case City_State_Zip:{ // City, State Zip_Code | ||
508 | state = businessState(); | ||
509 | if ( !(value = businessCity()).isEmpty() ) { | ||
510 | marker = true; | ||
511 | text += "<br>" + Qtopia::escapeString(value); | ||
512 | if ( state ) | ||
513 | text += ", " + Qtopia::escapeString(state); | ||
514 | } else if ( !state.isEmpty() ){ | ||
515 | text += "<br>" + Qtopia::escapeString(state); | ||
516 | marker = true; | ||
517 | } | ||
518 | if ( !(value = businessZip()).isEmpty() ){ | ||
519 | text += " " + Qtopia::escapeString(value); | ||
520 | marker = true; | ||
521 | } | ||
522 | break; | ||
523 | } | ||
524 | } | ||
489 | 525 | ||
490 | if ( !(value = businessCountry()).isEmpty() ) | 526 | if ( !(value = businessCountry()).isEmpty() ){ |
491 | text += Qtopia::escapeString(value) + "<br>"; | 527 | text += "<br>" + Qtopia::escapeString(value); |
528 | marker = true; | ||
529 | } | ||
492 | 530 | ||
493 | // rest of Business data | 531 | // rest of Business data |
494 | str = office(); | 532 | str = office(); |
495 | if ( !str.isEmpty() ){ | 533 | if ( !str.isEmpty() ){ |
496 | text += "<b>" + QObject::tr("Office: ") + "</b>" | 534 | text += "<br><b>" + QObject::tr("Office: ") + "</b>" |
497 | + Qtopia::escapeString(str) + "<br>"; | 535 | + Qtopia::escapeString(str); |
498 | marker = true; | 536 | marker = true; |
499 | } | 537 | } |
500 | str = businessWebpage(); | 538 | str = businessWebpage(); |
501 | if ( !str.isEmpty() ){ | 539 | if ( !str.isEmpty() ){ |
502 | text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>" | 540 | text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>" |
503 | + Qtopia::escapeString(str) + "<br>"; | 541 | + Qtopia::escapeString(str); |
504 | marker = true; | 542 | marker = true; |
505 | } | 543 | } |
506 | str = businessPhone(); | 544 | str = businessPhone(); |
507 | if ( !str.isEmpty() ){ | 545 | if ( !str.isEmpty() ){ |
508 | text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>" | 546 | text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>" |
509 | + Qtopia::escapeString(str) + "<br>"; | 547 | + Qtopia::escapeString(str); |
510 | marker = true; | 548 | marker = true; |
511 | } | 549 | } |
512 | str = businessFax(); | 550 | str = businessFax(); |
513 | if ( !str.isEmpty() ){ | 551 | if ( !str.isEmpty() ){ |
514 | text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>" | 552 | text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>" |
515 | + Qtopia::escapeString(str) + "<br>"; | 553 | + Qtopia::escapeString(str); |
516 | marker = true; | 554 | marker = true; |
517 | } | 555 | } |
518 | str = businessMobile(); | 556 | str = businessMobile(); |
519 | if ( !str.isEmpty() ){ | 557 | if ( !str.isEmpty() ){ |
520 | text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>" | 558 | text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>" |
521 | + Qtopia::escapeString(str) + "<br>"; | 559 | + Qtopia::escapeString(str); |
522 | marker = true; | 560 | marker = true; |
523 | } | 561 | } |
524 | str = businessPager(); | 562 | str = businessPager(); |
525 | if ( !str.isEmpty() ){ | 563 | if ( !str.isEmpty() ){ |
526 | text += "<b>" + QObject::tr("Business Pager: ") + "</b>" | 564 | text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>" |
527 | + Qtopia::escapeString(str) + "<br>"; | 565 | + Qtopia::escapeString(str); |
528 | marker = true; | 566 | marker = true; |
529 | } | 567 | } |
530 | 568 | ||
531 | text += "<br>"; | 569 | text += "<br>"; |
532 | 570 | ||
533 | // home address | 571 | // home address |
534 | if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || | 572 | if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || |
535 | !homeZip().isEmpty() || !homeCountry().isEmpty() ) { | 573 | !homeZip().isEmpty() || !homeCountry().isEmpty() ) { |
536 | text += QObject::tr( "<b>Home Address:</b>" ); | 574 | text += QObject::tr( "<br><br><b>Home Address:</b>" ); |
537 | text += "<br>"; | 575 | marker = true; |
538 | } | 576 | } |
539 | 577 | ||
540 | if ( !(value = homeStreet()).isEmpty() ) | 578 | if ( !(value = homeStreet()).isEmpty() ){ |
541 | text += Qtopia::escapeString(value) + "<br>"; | 579 | text += "<br>" + Qtopia::escapeString(value); |
542 | state = homeState(); | 580 | marker = true; |
543 | if ( !(value = homeZip()).isEmpty() ) | 581 | } |
544 | text += Qtopia::escapeString(value) + " "; | 582 | |
545 | if ( !(value = homeCity()).isEmpty() ) { | 583 | switch( addressformat ){ |
546 | text += Qtopia::escapeString(value); | 584 | case Zip_City_State:{ // Zip_Code City, State |
547 | if ( !state.isEmpty() ) | 585 | state = homeState(); |
548 | text += ", " + Qtopia::escapeString(state); | 586 | if ( !(value = homeZip()).isEmpty() ){ |
549 | text += "<br>"; | 587 | text += "<br>" + Qtopia::escapeString(value) + " "; |
550 | } else if (!state.isEmpty()) | 588 | marker = true; |
551 | text += Qtopia::escapeString(state) + "<br>"; | 589 | } else |
552 | if ( !(value = homeCountry()).isEmpty() ) | 590 | text += "<br>"; |
553 | text += Qtopia::escapeString(value) + "<br>"; | 591 | |
592 | if ( !(value = homeCity()).isEmpty() ) { | ||
593 | marker = true; | ||
594 | text += Qtopia::escapeString(value); | ||
595 | if ( !state.isEmpty() ) | ||
596 | text += ", " + Qtopia::escapeString(state); | ||
597 | } else if (!state.isEmpty()) { | ||
598 | text += "<br>" + Qtopia::escapeString(state); | ||
599 | marker = true; | ||
600 | } | ||
601 | break; | ||
602 | } | ||
603 | case City_State_Zip:{ // City, State Zip_Code | ||
604 | state = homeState(); | ||
605 | if ( !(value = homeCity()).isEmpty() ) { | ||
606 | marker = true; | ||
607 | text += "<br>" + Qtopia::escapeString(value); | ||
608 | if ( state ) | ||
609 | text += ", " + Qtopia::escapeString(state); | ||
610 | } else if ( !state.isEmpty() ){ | ||
611 | text += "<br>" + Qtopia::escapeString(state); | ||
612 | marker = true; | ||
613 | } | ||
614 | if ( !(value = homeZip()).isEmpty() ){ | ||
615 | text += " " + Qtopia::escapeString(value); | ||
616 | marker = true; | ||
617 | } | ||
618 | break; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | if ( !(value = homeCountry()).isEmpty() ){ | ||
623 | text += "<br>" + Qtopia::escapeString(value); | ||
624 | marker = true; | ||
625 | } | ||
554 | 626 | ||
555 | // rest of Home data | 627 | // rest of Home data |
556 | str = homeWebpage(); | 628 | str = homeWebpage(); |
557 | if ( !str.isEmpty() ){ | 629 | if ( !str.isEmpty() ){ |
558 | text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>" | 630 | text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>" |
559 | + Qtopia::escapeString(str) + "<br>"; | 631 | + Qtopia::escapeString(str); |
560 | marker = true; | 632 | marker = true; |
561 | } | 633 | } |
562 | str = homePhone(); | 634 | str = homePhone(); |
563 | if ( !str.isEmpty() ){ | 635 | if ( !str.isEmpty() ){ |
564 | text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>" | 636 | text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>" |
565 | + Qtopia::escapeString(str) + "<br>"; | 637 | + Qtopia::escapeString(str); |
566 | marker = true; | 638 | marker = true; |
567 | } | 639 | } |
568 | str = homeFax(); | 640 | str = homeFax(); |
569 | if ( !str.isEmpty() ){ | 641 | if ( !str.isEmpty() ){ |
570 | text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>" | 642 | text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>" |
571 | + Qtopia::escapeString(str) + "<br>"; | 643 | + Qtopia::escapeString(str); |
572 | marker = true; | 644 | marker = true; |
573 | } | 645 | } |
574 | str = homeMobile(); | 646 | str = homeMobile(); |
575 | if ( !str.isEmpty() ){ | 647 | if ( !str.isEmpty() ){ |
576 | text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>" | 648 | text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>" |
577 | + Qtopia::escapeString(str) + "<br>"; | 649 | + Qtopia::escapeString(str); |
578 | marker = true; | 650 | marker = true; |
579 | } | 651 | } |
580 | 652 | ||
581 | if ( marker ) | 653 | if ( marker ) |
582 | text += "<br><hr><br>"; | 654 | text += "<br><hr>"; |
583 | // the others... | 655 | |
656 | // the rest... | ||
584 | str = emails(); | 657 | str = emails(); |
585 | if ( !str.isEmpty() && ( str != defEmail ) ) | 658 | if ( !str.isEmpty() && ( str != defEmail ) ) |
586 | text += "<b>" + QObject::tr("All Emails: ") + "</b>" | 659 | text += "<br><b>" + QObject::tr("All Emails: ") + "</b>" |
587 | + Qtopia::escapeString(str) + "<br>"; | 660 | + Qtopia::escapeString(str); |
588 | str = profession(); | 661 | str = profession(); |
589 | if ( !str.isEmpty() ) | 662 | if ( !str.isEmpty() ) |
590 | text += "<b>" + QObject::tr("Profession: ") + "</b>" | 663 | text += "<br><b>" + QObject::tr("Profession: ") + "</b>" |
591 | + Qtopia::escapeString(str) + "<br>"; | 664 | + Qtopia::escapeString(str); |
592 | str = assistant(); | 665 | str = assistant(); |
593 | if ( !str.isEmpty() ) | 666 | if ( !str.isEmpty() ) |
594 | text += "<b>" + QObject::tr("Assistant: ") + "</b>" | 667 | text += "<br><b>" + QObject::tr("Assistant: ") + "</b>" |
595 | + Qtopia::escapeString(str) + "<br>"; | 668 | + Qtopia::escapeString(str); |
596 | str = manager(); | 669 | str = manager(); |
597 | if ( !str.isEmpty() ) | 670 | if ( !str.isEmpty() ) |
598 | text += "<b>" + QObject::tr("Manager: ") + "</b>" | 671 | text += "<br><b>" + QObject::tr("Manager: ") + "</b>" |
599 | + Qtopia::escapeString(str) + "<br>"; | 672 | + Qtopia::escapeString(str); |
600 | str = gender(); | 673 | str = gender(); |
601 | if ( !str.isEmpty() && str.toInt() != 0 ) { | 674 | if ( !str.isEmpty() && str.toInt() != 0 ) { |
602 | if ( str.toInt() == 1 ) | 675 | text += "<br>"; |
603 | str = QObject::tr( "Male" ); | 676 | if ( str.toInt() == 1 ) |
604 | else if ( str.toInt() == 2 ) | 677 | str = QObject::tr( "Male" ); |
605 | str = QObject::tr( "Female" ); | 678 | else if ( str.toInt() == 2 ) |
606 | text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; | 679 | str = QObject::tr( "Female" ); |
680 | text += "<b>" + QObject::tr("Gender: ") + "</b>" + str; | ||
607 | } | 681 | } |
608 | str = spouse(); | 682 | str = spouse(); |
609 | if ( !str.isEmpty() ) | 683 | if ( !str.isEmpty() ) |
610 | text += "<b>" + QObject::tr("Spouse: ") + "</b>" | 684 | text += "<br><b>" + QObject::tr("Spouse: ") + "</b>" |
611 | + Qtopia::escapeString(str) + "<br>"; | 685 | + Qtopia::escapeString(str); |
612 | if ( birthday().isValid() ){ | 686 | if ( birthday().isValid() ){ |
613 | str = TimeString::numberDateString( birthday() ); | 687 | str = TimeString::numberDateString( birthday() ); |
614 | text += "<b>" + QObject::tr("Birthday: ") + "</b>" | 688 | text += "<br><b>" + QObject::tr("Birthday: ") + "</b>" |
615 | + Qtopia::escapeString(str) + "<br>"; | 689 | + Qtopia::escapeString(str); |
616 | } | 690 | } |
617 | if ( anniversary().isValid() ){ | 691 | if ( anniversary().isValid() ){ |
618 | str = TimeString::numberDateString( anniversary() ); | 692 | str = TimeString::numberDateString( anniversary() ); |
619 | text += "<b>" + QObject::tr("Anniversary: ") + "</b>" | 693 | text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>" |
620 | + Qtopia::escapeString(str) + "<br>"; | 694 | + Qtopia::escapeString(str); |
621 | } | 695 | } |
622 | str = children(); | 696 | str = children(); |
623 | if ( !str.isEmpty() ) | 697 | if ( !str.isEmpty() ) |
624 | text += "<b>" + QObject::tr("Children: ") + "</b>" | 698 | text += "<br><b>" + QObject::tr("Children: ") + "</b>" |
625 | + Qtopia::escapeString(str) + "<br>"; | 699 | + Qtopia::escapeString(str); |
626 | 700 | ||
627 | str = nickname(); | 701 | str = nickname(); |
628 | if ( !str.isEmpty() ) | 702 | if ( !str.isEmpty() ) |
629 | text += "<b>" + QObject::tr("Nickname: ") + "</b>" | 703 | text += "<br><b>" + QObject::tr("Nickname: ") + "</b>" |
630 | + Qtopia::escapeString(str) + "<br>"; | 704 | + Qtopia::escapeString(str); |
631 | 705 | ||
632 | // categories | 706 | // categories |
633 | if ( categoryNames("Contacts").count() ){ | 707 | if ( categoryNames("Contacts").count() ){ |
634 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 708 | text += "<br><b>" + QObject::tr( "Category:") + "</b> "; |
635 | text += categoryNames("Contacts").join(", "); | 709 | text += categoryNames("Contacts").join(", "); |
636 | text += "<br>"; | ||
637 | } | 710 | } |
638 | 711 | ||
639 | // notes last | 712 | // notes last |
640 | if ( !(value = notes()).isEmpty() ) { | 713 | if ( !(value = notes()).isEmpty() ) { |
641 | text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; | 714 | text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; |
642 | QRegExp reg("\n"); | 715 | QRegExp reg("\n"); |
643 | 716 | ||
644 | //QString tmp = Qtopia::escapeString(value); | 717 | //QString tmp = Qtopia::escapeString(value); |
645 | QString tmp = QStyleSheet::convertFromPlainText(value); | 718 | QString tmp = QStyleSheet::convertFromPlainText(value); |
646 | //tmp.replace( reg, "<br>" ); | 719 | //tmp.replace( reg, "<br>" ); |
647 | text += "<br>" + tmp + "<br>"; | 720 | text += "<br>" + tmp + "<br>"; |
648 | } | 721 | } |
649 | return text; | 722 | return text; |
650 | } | 723 | } |
651 | 724 | ||
652 | /*! | 725 | /*! |
653 | \internal | 726 | \internal |
654 | */ | 727 | */ |
655 | void OContact::insert( int key, const QString &v ) | 728 | void OContact::insert( int key, const QString &v ) |
656 | { | 729 | { |
657 | QString value = v.stripWhiteSpace(); | 730 | QString value = v.stripWhiteSpace(); |
658 | if ( value.isEmpty() ) | 731 | if ( value.isEmpty() ) |
659 | mMap.remove( key ); | 732 | mMap.remove( key ); |
660 | else | 733 | else |
661 | mMap.insert( key, value ); | 734 | mMap.insert( key, value ); |
662 | } | 735 | } |
663 | 736 | ||
664 | /*! | 737 | /*! |
665 | \internal | 738 | \internal |
666 | */ | 739 | */ |
667 | void OContact::replace( int key, const QString & v ) | 740 | void OContact::replace( int key, const QString & v ) |
668 | { | 741 | { |
669 | QString value = v.stripWhiteSpace(); | 742 | QString value = v.stripWhiteSpace(); |
670 | if ( value.isEmpty() ) | 743 | if ( value.isEmpty() ) |
671 | mMap.remove( key ); | 744 | mMap.remove( key ); |
672 | else | 745 | else |
673 | mMap.replace( key, value ); | 746 | mMap.replace( key, value ); |
674 | } | 747 | } |
675 | 748 | ||
676 | /*! | 749 | /*! |
677 | \internal | 750 | \internal |
678 | */ | 751 | */ |
679 | QString OContact::find( int key ) const | 752 | QString OContact::find( int key ) const |
680 | { | 753 | { |
681 | return mMap[key]; | 754 | return mMap[key]; |
682 | } | 755 | } |
683 | 756 | ||
684 | /*! | 757 | /*! |
685 | \internal | 758 | \internal |
686 | */ | 759 | */ |
687 | QString OContact::displayAddress( const QString &street, | 760 | QString OContact::displayAddress( const QString &street, |
688 | const QString &city, | 761 | const QString &city, |
689 | const QString &state, | 762 | const QString &state, |
690 | const QString &zip, | 763 | const QString &zip, |
691 | const QString &country ) const | 764 | const QString &country ) const |
692 | { | 765 | { |
693 | QString s = street; | 766 | QString s = street; |
694 | if ( !street.isEmpty() ) | 767 | if ( !street.isEmpty() ) |
695 | s+= "\n"; | 768 | s+= "\n"; |
696 | s += city; | 769 | s += city; |
697 | if ( !city.isEmpty() && !state.isEmpty() ) | 770 | if ( !city.isEmpty() && !state.isEmpty() ) |
698 | s += ", "; | 771 | s += ", "; |
699 | s += state; | 772 | s += state; |
700 | if ( !state.isEmpty() && !zip.isEmpty() ) | 773 | if ( !state.isEmpty() && !zip.isEmpty() ) |
701 | s += " "; | 774 | s += " "; |
702 | s += zip; | 775 | s += zip; |
703 | if ( !country.isEmpty() && !s.isEmpty() ) | 776 | if ( !country.isEmpty() && !s.isEmpty() ) |
704 | s += "\n"; | 777 | s += "\n"; |
705 | s += country; | 778 | s += country; |
706 | return s; | 779 | return s; |
707 | } | 780 | } |
708 | 781 | ||
709 | /*! | 782 | /*! |
710 | \internal | 783 | \internal |
711 | */ | 784 | */ |
712 | QString OContact::displayBusinessAddress() const | 785 | QString OContact::displayBusinessAddress() const |
713 | { | 786 | { |
714 | return displayAddress( businessStreet(), businessCity(), | 787 | return displayAddress( businessStreet(), businessCity(), |
715 | businessState(), businessZip(), | 788 | businessState(), businessZip(), |
716 | businessCountry() ); | 789 | businessCountry() ); |
717 | } | 790 | } |
718 | 791 | ||
719 | /*! | 792 | /*! |
720 | \internal | 793 | \internal |
721 | */ | 794 | */ |
722 | QString OContact::displayHomeAddress() const | 795 | QString OContact::displayHomeAddress() const |
723 | { | 796 | { |
724 | return displayAddress( homeStreet(), homeCity(), | 797 | return displayAddress( homeStreet(), homeCity(), |
725 | homeState(), homeZip(), | 798 | homeState(), homeZip(), |
726 | homeCountry() ); | 799 | homeCountry() ); |
727 | } | 800 | } |
728 | 801 | ||
729 | /*! | 802 | /*! |
730 | Returns the full name of the contact | 803 | Returns the full name of the contact |
731 | */ | 804 | */ |
732 | QString OContact::fullName() const | 805 | QString OContact::fullName() const |
733 | { | 806 | { |
734 | QString title = find( Qtopia::Title ); | 807 | QString title = find( Qtopia::Title ); |
735 | QString firstName = find( Qtopia::FirstName ); | 808 | QString firstName = find( Qtopia::FirstName ); |
736 | QString middleName = find( Qtopia::MiddleName ); | 809 | QString middleName = find( Qtopia::MiddleName ); |
737 | QString lastName = find( Qtopia::LastName ); | 810 | QString lastName = find( Qtopia::LastName ); |
738 | QString suffix = find( Qtopia::Suffix ); | 811 | QString suffix = find( Qtopia::Suffix ); |
739 | 812 | ||
740 | QString name = title; | 813 | QString name = title; |
741 | if ( !firstName.isEmpty() ) { | 814 | if ( !firstName.isEmpty() ) { |
742 | if ( !name.isEmpty() ) | 815 | if ( !name.isEmpty() ) |
743 | name += " "; | 816 | name += " "; |
744 | name += firstName; | 817 | name += firstName; |
745 | } | 818 | } |
746 | if ( !middleName.isEmpty() ) { | 819 | if ( !middleName.isEmpty() ) { |
747 | if ( !name.isEmpty() ) | 820 | if ( !name.isEmpty() ) |
748 | name += " "; | 821 | name += " "; |
749 | name += middleName; | 822 | name += middleName; |
750 | } | 823 | } |
751 | if ( !lastName.isEmpty() ) { | 824 | if ( !lastName.isEmpty() ) { |
752 | if ( !name.isEmpty() ) | 825 | if ( !name.isEmpty() ) |
753 | name += " "; | 826 | name += " "; |
754 | name += lastName; | 827 | name += lastName; |
755 | } | 828 | } |
756 | if ( !suffix.isEmpty() ) { | 829 | if ( !suffix.isEmpty() ) { |
757 | if ( !name.isEmpty() ) | 830 | if ( !name.isEmpty() ) |
758 | name += " "; | 831 | name += " "; |
759 | name += suffix; | 832 | name += suffix; |
760 | } | 833 | } |
761 | return name.simplifyWhiteSpace(); | 834 | return name.simplifyWhiteSpace(); |
762 | } | 835 | } |
763 | 836 | ||
764 | /*! | 837 | /*! |
765 | Returns a list of the names of the children of the contact. | 838 | Returns a list of the names of the children of the contact. |
766 | */ | 839 | */ |
767 | QStringList OContact::childrenList() const | 840 | QStringList OContact::childrenList() const |
768 | { | 841 | { |
769 | return QStringList::split( " ", find( Qtopia::Children ) ); | 842 | return QStringList::split( " ", find( Qtopia::Children ) ); |
770 | } | 843 | } |
771 | 844 | ||
772 | /*! \fn void OContact::insertEmail( const QString &email ) | 845 | /*! \fn void OContact::insertEmail( const QString &email ) |
773 | 846 | ||
774 | Insert \a email into the email list. Ensures \a email can only be added | 847 | Insert \a email into the email list. Ensures \a email can only be added |
775 | once. If there is no default email address set, it sets it to the \a email. | 848 | once. If there is no default email address set, it sets it to the \a email. |
776 | */ | 849 | */ |
777 | 850 | ||
778 | /*! \fn void OContact::removeEmail( const QString &email ) | 851 | /*! \fn void OContact::removeEmail( const QString &email ) |
779 | 852 | ||
780 | Removes the \a email from the email list. If the default email was \a email, | 853 | Removes the \a email from the email list. If the default email was \a email, |
781 | then the default email address is assigned to the first email in the | 854 | then the default email address is assigned to the first email in the |
782 | email list | 855 | email list |
783 | */ | 856 | */ |
784 | 857 | ||
785 | /*! \fn void OContact::clearEmails() | 858 | /*! \fn void OContact::clearEmails() |
786 | 859 | ||
787 | Clears the email list. | 860 | Clears the email list. |
788 | */ | 861 | */ |
789 | 862 | ||
790 | /*! \fn void OContact::insertEmails( const QStringList &emailList ) | 863 | /*! \fn void OContact::insertEmails( const QStringList &emailList ) |
791 | 864 | ||
792 | Appends the \a emailList to the exiting email list | 865 | Appends the \a emailList to the exiting email list |
793 | */ | 866 | */ |
794 | 867 | ||
795 | /*! | 868 | /*! |
796 | Returns a list of email addresses belonging to the contact, including | 869 | Returns a list of email addresses belonging to the contact, including |
797 | the default email address. | 870 | the default email address. |
798 | */ | 871 | */ |
799 | QStringList OContact::emailList() const | 872 | QStringList OContact::emailList() const |
800 | { | 873 | { |
801 | QString emailStr = emails(); | 874 | QString emailStr = emails(); |
802 | 875 | ||
803 | QStringList r; | 876 | QStringList r; |
804 | if ( !emailStr.isEmpty() ) { | 877 | if ( !emailStr.isEmpty() ) { |
805 | qDebug(" emailstr "); | 878 | qDebug(" emailstr "); |
806 | QStringList l = QStringList::split( emailSeparator(), emailStr ); | 879 | QStringList l = QStringList::split( emailSeparator(), emailStr ); |
807 | for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) | 880 | for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) |
808 | r += (*it).simplifyWhiteSpace(); | 881 | r += (*it).simplifyWhiteSpace(); |
809 | } | 882 | } |
810 | 883 | ||
811 | return r; | 884 | return r; |
812 | } | 885 | } |
813 | 886 | ||
814 | /*! | 887 | /*! |
815 | \overload | 888 | \overload |
816 | 889 | ||
817 | Generates the string for the contact to be filed as from the first, | 890 | Generates the string for the contact to be filed as from the first, |
818 | middle and last name of the contact. | 891 | middle and last name of the contact. |
819 | */ | 892 | */ |
820 | void OContact::setFileAs() | 893 | void OContact::setFileAs() |
821 | { | 894 | { |
822 | QString lastName, firstName, middleName, fileas; | 895 | QString lastName, firstName, middleName, fileas; |
823 | 896 | ||
824 | lastName = find( Qtopia::LastName ); | 897 | lastName = find( Qtopia::LastName ); |
825 | firstName = find( Qtopia::FirstName ); | 898 | firstName = find( Qtopia::FirstName ); |
826 | middleName = find( Qtopia::MiddleName ); | 899 | middleName = find( Qtopia::MiddleName ); |
827 | if ( !lastName.isEmpty() && !firstName.isEmpty() | 900 | if ( !lastName.isEmpty() && !firstName.isEmpty() |
828 | && !middleName.isEmpty() ) | 901 | && !middleName.isEmpty() ) |
829 | fileas = lastName + ", " + firstName + " " + middleName; | 902 | fileas = lastName + ", " + firstName + " " + middleName; |
830 | else if ( !lastName.isEmpty() && !firstName.isEmpty() ) | 903 | else if ( !lastName.isEmpty() && !firstName.isEmpty() ) |
831 | fileas = lastName + ", " + firstName; | 904 | fileas = lastName + ", " + firstName; |
832 | else if ( !lastName.isEmpty() || !firstName.isEmpty() || | 905 | else if ( !lastName.isEmpty() || !firstName.isEmpty() || |
833 | !middleName.isEmpty() ) | 906 | !middleName.isEmpty() ) |
834 | fileas = firstName + ( firstName.isEmpty() ? "" : " " ) | 907 | fileas = firstName + ( firstName.isEmpty() ? "" : " " ) |
835 | + middleName + ( middleName.isEmpty() ? "" : " " ) | 908 | + middleName + ( middleName.isEmpty() ? "" : " " ) |
836 | + lastName; | 909 | + lastName; |
837 | 910 | ||
838 | replace( Qtopia::FileAs, fileas ); | 911 | replace( Qtopia::FileAs, fileas ); |
839 | } | 912 | } |
840 | 913 | ||
841 | /*! | 914 | /*! |
842 | \internal | 915 | \internal |
843 | Appends the contact information to \a buf. | 916 | Appends the contact information to \a buf. |
844 | */ | 917 | */ |
845 | void OContact::save( QString &buf ) const | 918 | void OContact::save( QString &buf ) const |
846 | { | 919 | { |
847 | static const QStringList SLFIELDS = fields(); | 920 | static const QStringList SLFIELDS = fields(); |
848 | // I'm expecting "<Contact " in front of this... | 921 | // I'm expecting "<Contact " in front of this... |
849 | for ( QMap<int, QString>::ConstIterator it = mMap.begin(); | 922 | for ( QMap<int, QString>::ConstIterator it = mMap.begin(); |
850 | it != mMap.end(); ++it ) { | 923 | it != mMap.end(); ++it ) { |
851 | const QString &value = it.data(); | 924 | const QString &value = it.data(); |
852 | int key = it.key(); | 925 | int key = it.key(); |
853 | if ( !value.isEmpty() ) { | 926 | if ( !value.isEmpty() ) { |
854 | if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) | 927 | if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) |
855 | continue; | 928 | continue; |
856 | 929 | ||
857 | key -= Qtopia::AddressCategory+1; | 930 | key -= Qtopia::AddressCategory+1; |
858 | buf += SLFIELDS[key]; | 931 | buf += SLFIELDS[key]; |
859 | buf += "=\"" + Qtopia::escapeString(value) + "\" "; | 932 | buf += "=\"" + Qtopia::escapeString(value) + "\" "; |
860 | } | 933 | } |
861 | } | 934 | } |
862 | buf += customToXml(); | 935 | buf += customToXml(); |
863 | if ( categories().count() > 0 ) | 936 | if ( categories().count() > 0 ) |
864 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; | 937 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; |
865 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; | 938 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; |
866 | // You need to close this yourself | 939 | // You need to close this yourself |
867 | } | 940 | } |
868 | 941 | ||
869 | 942 | ||
870 | /*! | 943 | /*! |
871 | \internal | 944 | \internal |
872 | Returns the list of fields belonging to a contact | 945 | Returns the list of fields belonging to a contact |
873 | Never change order of this list ! It has to be regarding | 946 | Never change order of this list ! It has to be regarding |
874 | enum AddressBookFields !! | 947 | enum AddressBookFields !! |
875 | */ | 948 | */ |
876 | QStringList OContact::fields() | 949 | QStringList OContact::fields() |
877 | { | 950 | { |
878 | QStringList list; | 951 | QStringList list; |
879 | 952 | ||
880 | list.append( "Title" ); // Not Used! | 953 | list.append( "Title" ); // Not Used! |
881 | list.append( "FirstName" ); | 954 | list.append( "FirstName" ); |
882 | list.append( "MiddleName" ); | 955 | list.append( "MiddleName" ); |
883 | list.append( "LastName" ); | 956 | list.append( "LastName" ); |
884 | list.append( "Suffix" ); | 957 | list.append( "Suffix" ); |
885 | list.append( "FileAs" ); | 958 | list.append( "FileAs" ); |
886 | 959 | ||
887 | list.append( "JobTitle" ); | 960 | list.append( "JobTitle" ); |
888 | list.append( "Department" ); | 961 | list.append( "Department" ); |
889 | list.append( "Company" ); | 962 | list.append( "Company" ); |
890 | list.append( "BusinessPhone" ); | 963 | list.append( "BusinessPhone" ); |
891 | list.append( "BusinessFax" ); | 964 | list.append( "BusinessFax" ); |
892 | list.append( "BusinessMobile" ); | 965 | list.append( "BusinessMobile" ); |
893 | 966 | ||
894 | list.append( "DefaultEmail" ); | 967 | list.append( "DefaultEmail" ); |
895 | list.append( "Emails" ); | 968 | list.append( "Emails" ); |
896 | 969 | ||
897 | list.append( "HomePhone" ); | 970 | list.append( "HomePhone" ); |
898 | list.append( "HomeFax" ); | 971 | list.append( "HomeFax" ); |
899 | list.append( "HomeMobile" ); | 972 | list.append( "HomeMobile" ); |
900 | 973 | ||
901 | list.append( "BusinessStreet" ); | 974 | list.append( "BusinessStreet" ); |
902 | list.append( "BusinessCity" ); | 975 | list.append( "BusinessCity" ); |
903 | list.append( "BusinessState" ); | 976 | list.append( "BusinessState" ); |
904 | list.append( "BusinessZip" ); | 977 | list.append( "BusinessZip" ); |
905 | list.append( "BusinessCountry" ); | 978 | list.append( "BusinessCountry" ); |
906 | list.append( "BusinessPager" ); | 979 | list.append( "BusinessPager" ); |
907 | list.append( "BusinessWebPage" ); | 980 | list.append( "BusinessWebPage" ); |
908 | 981 | ||
909 | list.append( "Office" ); | 982 | list.append( "Office" ); |
910 | list.append( "Profession" ); | 983 | list.append( "Profession" ); |
911 | list.append( "Assistant" ); | 984 | list.append( "Assistant" ); |
912 | list.append( "Manager" ); | 985 | list.append( "Manager" ); |
913 | 986 | ||
914 | list.append( "HomeStreet" ); | 987 | list.append( "HomeStreet" ); |
915 | list.append( "HomeCity" ); | 988 | list.append( "HomeCity" ); |
916 | list.append( "HomeState" ); | 989 | list.append( "HomeState" ); |
917 | list.append( "HomeZip" ); | 990 | list.append( "HomeZip" ); |
918 | list.append( "HomeCountry" ); | 991 | list.append( "HomeCountry" ); |
919 | list.append( "HomeWebPage" ); | 992 | list.append( "HomeWebPage" ); |
920 | 993 | ||
921 | list.append( "Spouse" ); | 994 | list.append( "Spouse" ); |
922 | list.append( "Gender" ); | 995 | list.append( "Gender" ); |
923 | list.append( "Birthday" ); | 996 | list.append( "Birthday" ); |
924 | list.append( "Anniversary" ); | 997 | list.append( "Anniversary" ); |
925 | list.append( "Nickname" ); | 998 | list.append( "Nickname" ); |
926 | list.append( "Children" ); | 999 | list.append( "Children" ); |
927 | 1000 | ||
928 | list.append( "Notes" ); | 1001 | list.append( "Notes" ); |
929 | list.append( "Groups" ); | 1002 | list.append( "Groups" ); |
930 | 1003 | ||
931 | return list; | 1004 | return list; |
932 | } | 1005 | } |
933 | 1006 | ||
934 | 1007 | ||
935 | /*! | 1008 | /*! |
936 | Sets the list of email address for contact to those contained in \a str. | 1009 | Sets the list of email address for contact to those contained in \a str. |
937 | Email address should be separated by ';'s. | 1010 | Email address should be separated by ';'s. |
938 | */ | 1011 | */ |
939 | void OContact::setEmails( const QString &str ) | 1012 | void OContact::setEmails( const QString &str ) |
940 | { | 1013 | { |
941 | replace( Qtopia::Emails, str ); | 1014 | replace( Qtopia::Emails, str ); |
942 | if ( str.isEmpty() ) | 1015 | if ( str.isEmpty() ) |
943 | setDefaultEmail( QString::null ); | 1016 | setDefaultEmail( QString::null ); |
944 | } | 1017 | } |
945 | 1018 | ||
946 | /*! | 1019 | /*! |
947 | Sets the list of children for the contact to those contained in \a str. | 1020 | Sets the list of children for the contact to those contained in \a str. |
948 | */ | 1021 | */ |
949 | void OContact::setChildren( const QString &str ) | 1022 | void OContact::setChildren( const QString &str ) |
950 | { | 1023 | { |
951 | replace( Qtopia::Children, str ); | 1024 | replace( Qtopia::Children, str ); |
952 | } | 1025 | } |
953 | 1026 | ||
954 | /*! | 1027 | /*! |
955 | \overload | 1028 | \overload |
956 | Returns TRUE if the contact matches the regular expression \a regexp. | 1029 | Returns TRUE if the contact matches the regular expression \a regexp. |
957 | Otherwise returns FALSE. | 1030 | Otherwise returns FALSE. |
958 | */ | 1031 | */ |
959 | bool OContact::match( const QRegExp &r ) const | 1032 | bool OContact::match( const QRegExp &r ) const |
960 | { | 1033 | { |
961 | setLastHitField( -1 ); | 1034 | setLastHitField( -1 ); |
962 | bool match; | 1035 | bool match; |
963 | match = false; | 1036 | match = false; |
964 | QMap<int, QString>::ConstIterator it; | 1037 | QMap<int, QString>::ConstIterator it; |
965 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 1038 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
966 | if ( (*it).find( r ) > -1 ) { | 1039 | if ( (*it).find( r ) > -1 ) { |
967 | setLastHitField( it.key() ); | 1040 | setLastHitField( it.key() ); |
968 | match = true; | 1041 | match = true; |
969 | break; | 1042 | break; |
970 | } | 1043 | } |
971 | } | 1044 | } |
972 | return match; | 1045 | return match; |
973 | } | 1046 | } |
974 | 1047 | ||
975 | 1048 | ||
976 | QString OContact::toShortText() const | 1049 | QString OContact::toShortText() const |
977 | { | 1050 | { |
978 | return ( fullName() ); | 1051 | return ( fullName() ); |
979 | } | 1052 | } |
980 | QString OContact::type() const | 1053 | QString OContact::type() const |
981 | { | 1054 | { |
982 | return QString::fromLatin1( "OContact" ); | 1055 | return QString::fromLatin1( "OContact" ); |
983 | } | 1056 | } |
984 | 1057 | ||
985 | 1058 | ||
986 | 1059 | ||
987 | class QString OContact::recordField( int pos ) const | 1060 | class QString OContact::recordField( int pos ) const |
988 | { | 1061 | { |
989 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1062 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
990 | return SLFIELDS[pos]; | 1063 | return SLFIELDS[pos]; |
991 | } | 1064 | } |
992 | 1065 | ||
993 | // In future releases, we should store birthday and anniversary | 1066 | // In future releases, we should store birthday and anniversary |
994 | // internally as QDate instead of QString ! | 1067 | // internally as QDate instead of QString ! |
995 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1068 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
996 | 1069 | ||
997 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1070 | /*! \fn void OContact::setBirthday( const QDate& date ) |
998 | Sets the birthday for the contact to \a date. If date is null | 1071 | Sets the birthday for the contact to \a date. If date is null |
999 | the current stored date will be removed. | 1072 | the current stored date will be removed. |
1000 | */ | 1073 | */ |
1001 | void OContact::setBirthday( const QDate &v ) | 1074 | void OContact::setBirthday( const QDate &v ) |
1002 | { | 1075 | { |
1003 | if ( v.isNull() ){ | 1076 | if ( v.isNull() ){ |
1004 | qWarning( "Remove Birthday"); | 1077 | qWarning( "Remove Birthday"); |
1005 | replace( Qtopia::Birthday, QString::null ); | 1078 | replace( Qtopia::Birthday, QString::null ); |
1006 | return; | 1079 | return; |
1007 | } | 1080 | } |
1008 | 1081 | ||
1009 | if ( v.isValid() ) | 1082 | if ( v.isValid() ) |
1010 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); | 1083 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); |
1011 | 1084 | ||
1012 | } | 1085 | } |
1013 | 1086 | ||
1014 | 1087 | ||
1015 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1088 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1016 | Sets the anniversary of the contact to \a date. If date is | 1089 | Sets the anniversary of the contact to \a date. If date is |
1017 | null, the current stored date will be removed. | 1090 | null, the current stored date will be removed. |
1018 | */ | 1091 | */ |
1019 | void OContact::setAnniversary( const QDate &v ) | 1092 | void OContact::setAnniversary( const QDate &v ) |
1020 | { | 1093 | { |
1021 | if ( v.isNull() ){ | 1094 | if ( v.isNull() ){ |
1022 | qWarning( "Remove Anniversary"); | 1095 | qWarning( "Remove Anniversary"); |
1023 | replace( Qtopia::Anniversary, QString::null ); | 1096 | replace( Qtopia::Anniversary, QString::null ); |
1024 | return; | 1097 | return; |
1025 | } | 1098 | } |
1026 | 1099 | ||
1027 | if ( v.isValid() ) | 1100 | if ( v.isValid() ) |
1028 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); | 1101 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); |
1029 | } | 1102 | } |
1030 | 1103 | ||
1031 | /*! \fn QDate OContact::birthday() const | 1104 | /*! \fn QDate OContact::birthday() const |
1032 | Returns the birthday of the contact. | 1105 | Returns the birthday of the contact. |
1033 | */ | 1106 | */ |
1034 | QDate OContact::birthday() const | 1107 | QDate OContact::birthday() const |
1035 | { | 1108 | { |
1036 | QString str = find( Qtopia::Birthday ); | 1109 | QString str = find( Qtopia::Birthday ); |
1037 | qWarning ("Birthday %s", str.latin1() ); | 1110 | qWarning ("Birthday %s", str.latin1() ); |
1038 | if ( !str.isEmpty() ) | 1111 | if ( !str.isEmpty() ) |
1039 | return OConversion::dateFromString ( str ); | 1112 | return OConversion::dateFromString ( str ); |
1040 | else | 1113 | else |
1041 | return QDate(); | 1114 | return QDate(); |
1042 | } | 1115 | } |
1043 | 1116 | ||
1044 | 1117 | ||
1045 | /*! \fn QDate OContact::anniversary() const | 1118 | /*! \fn QDate OContact::anniversary() const |
1046 | Returns the anniversary of the contact. | 1119 | Returns the anniversary of the contact. |
1047 | */ | 1120 | */ |
1048 | QDate OContact::anniversary() const | 1121 | QDate OContact::anniversary() const |
1049 | { | 1122 | { |
1050 | QDate empty; | 1123 | QDate empty; |
1051 | QString str = find( Qtopia::Anniversary ); | 1124 | QString str = find( Qtopia::Anniversary ); |
1052 | qWarning ("Anniversary %s", str.latin1() ); | 1125 | qWarning ("Anniversary %s", str.latin1() ); |
1053 | if ( !str.isEmpty() ) | 1126 | if ( !str.isEmpty() ) |
1054 | return OConversion::dateFromString ( str ); | 1127 | return OConversion::dateFromString ( str ); |
1055 | else | 1128 | else |
1056 | return empty; | 1129 | return empty; |
1057 | } | 1130 | } |
1058 | 1131 | ||
1059 | 1132 | ||
1060 | void OContact::insertEmail( const QString &v ) | 1133 | void OContact::insertEmail( const QString &v ) |
1061 | { | 1134 | { |
1062 | //qDebug("insertEmail %s", v.latin1()); | 1135 | //qDebug("insertEmail %s", v.latin1()); |
1063 | QString e = v.simplifyWhiteSpace(); | 1136 | QString e = v.simplifyWhiteSpace(); |
1064 | QString def = defaultEmail(); | 1137 | QString def = defaultEmail(); |
1065 | 1138 | ||
1066 | // if no default, set it as the default email and don't insert | 1139 | // if no default, set it as the default email and don't insert |
1067 | if ( def.isEmpty() ) { | 1140 | if ( def.isEmpty() ) { |
1068 | setDefaultEmail( e ); // will insert into the list for us | 1141 | setDefaultEmail( e ); // will insert into the list for us |
1069 | return; | 1142 | return; |
1070 | } | 1143 | } |
1071 | 1144 | ||
1072 | // otherwise, insert assuming doesn't already exist | 1145 | // otherwise, insert assuming doesn't already exist |
1073 | QString emailsStr = find( Qtopia::Emails ); | 1146 | QString emailsStr = find( Qtopia::Emails ); |
1074 | if ( emailsStr.contains( e )) | 1147 | if ( emailsStr.contains( e )) |
1075 | return; | 1148 | return; |
1076 | if ( !emailsStr.isEmpty() ) | 1149 | if ( !emailsStr.isEmpty() ) |
1077 | emailsStr += emailSeparator(); | 1150 | emailsStr += emailSeparator(); |
1078 | emailsStr += e; | 1151 | emailsStr += e; |
1079 | replace( Qtopia::Emails, emailsStr ); | 1152 | replace( Qtopia::Emails, emailsStr ); |
1080 | } | 1153 | } |
1081 | 1154 | ||
1082 | void OContact::removeEmail( const QString &v ) | 1155 | void OContact::removeEmail( const QString &v ) |
1083 | { | 1156 | { |
1084 | QString e = v.simplifyWhiteSpace(); | 1157 | QString e = v.simplifyWhiteSpace(); |
1085 | QString def = defaultEmail(); | 1158 | QString def = defaultEmail(); |
1086 | QString emailsStr = find( Qtopia::Emails ); | 1159 | QString emailsStr = find( Qtopia::Emails ); |
1087 | QStringList emails = emailList(); | 1160 | QStringList emails = emailList(); |
1088 | 1161 | ||
1089 | // otherwise, must first contain it | 1162 | // otherwise, must first contain it |
1090 | if ( !emailsStr.contains( e ) ) | 1163 | if ( !emailsStr.contains( e ) ) |
1091 | return; | 1164 | return; |
1092 | 1165 | ||
1093 | // remove it | 1166 | // remove it |
1094 | //qDebug(" removing email from list %s", e.latin1()); | 1167 | //qDebug(" removing email from list %s", e.latin1()); |
1095 | emails.remove( e ); | 1168 | emails.remove( e ); |
1096 | // reset the string | 1169 | // reset the string |
1097 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1170 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1098 | replace( Qtopia::Emails, emailsStr ); | 1171 | replace( Qtopia::Emails, emailsStr ); |
1099 | 1172 | ||
1100 | // if default, then replace the default email with the first one | 1173 | // if default, then replace the default email with the first one |
1101 | if ( def == e ) { | 1174 | if ( def == e ) { |
1102 | //qDebug("removeEmail is default; setting new default"); | 1175 | //qDebug("removeEmail is default; setting new default"); |
1103 | if ( !emails.count() ) | 1176 | if ( !emails.count() ) |
1104 | clearEmails(); | 1177 | clearEmails(); |
1105 | else // setDefaultEmail will remove e from the list | 1178 | else // setDefaultEmail will remove e from the list |
1106 | setDefaultEmail( emails.first() ); | 1179 | setDefaultEmail( emails.first() ); |
1107 | } | 1180 | } |
1108 | } | 1181 | } |
1109 | void OContact::clearEmails() | 1182 | void OContact::clearEmails() |
1110 | { | 1183 | { |
1111 | mMap.remove( Qtopia::DefaultEmail ); | 1184 | mMap.remove( Qtopia::DefaultEmail ); |
1112 | mMap.remove( Qtopia::Emails ); | 1185 | mMap.remove( Qtopia::Emails ); |
1113 | } | 1186 | } |
1114 | void OContact::setDefaultEmail( const QString &v ) | 1187 | void OContact::setDefaultEmail( const QString &v ) |
1115 | { | 1188 | { |
1116 | QString e = v.simplifyWhiteSpace(); | 1189 | QString e = v.simplifyWhiteSpace(); |
1117 | 1190 | ||
1118 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); | 1191 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); |
1119 | replace( Qtopia::DefaultEmail, e ); | 1192 | replace( Qtopia::DefaultEmail, e ); |
1120 | 1193 | ||
1121 | if ( !e.isEmpty() ) | 1194 | if ( !e.isEmpty() ) |
1122 | insertEmail( e ); | 1195 | insertEmail( e ); |
1123 | 1196 | ||
1124 | } | 1197 | } |
1125 | 1198 | ||
1126 | void OContact::insertEmails( const QStringList &v ) | 1199 | void OContact::insertEmails( const QStringList &v ) |
1127 | { | 1200 | { |
1128 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | 1201 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) |
1129 | insertEmail( *it ); | 1202 | insertEmail( *it ); |
1130 | } | 1203 | } |
1131 | int OContact::rtti() { | 1204 | int OContact::rtti() { |
1132 | return OPimResolver::AddressBook; | 1205 | return OPimResolver::AddressBook; |
1133 | } | 1206 | } |
1134 | void OContact::setUid( int i ) | 1207 | void OContact::setUid( int i ) |
1135 | { | 1208 | { |
1136 | OPimRecord::setUid(i); | 1209 | OPimRecord::setUid(i); |
1137 | replace( Qtopia::AddressUid , QString::number(i)); | 1210 | replace( Qtopia::AddressUid , QString::number(i)); |
1138 | } | 1211 | } |
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index dd2de17..9a1a8dc 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h | |||
@@ -1,240 +1,245 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 14 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 16 | ** not clear to you. |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #ifndef __OCONTACT_H__ | 20 | #ifndef __OCONTACT_H__ |
21 | #define __OCONTACT_H__ | 21 | #define __OCONTACT_H__ |
22 | 22 | ||
23 | #include <opie/opimrecord.h> | 23 | #include <opie/opimrecord.h> |
24 | #include <qpe/recordfields.h> | 24 | #include <qpe/recordfields.h> |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | 28 | ||
29 | #if defined(QPC_TEMPLATEDLL) | 29 | #if defined(QPC_TEMPLATEDLL) |
30 | // MOC_SKIP_BEGIN | 30 | // MOC_SKIP_BEGIN |
31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
32 | // MOC_SKIP_END | 32 | // MOC_SKIP_END |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | class ContactPrivate; | 35 | class OContactPrivate; |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * OContact class represents a specialised PIM Record for contacts. | 38 | * OContact class represents a specialised PIM Record for contacts. |
39 | * It does store all kind of persopn related information. | 39 | * It does store all kind of persopn related information. |
40 | * | 40 | * |
41 | * @short Contact Container | 41 | * @short Contact Container |
42 | * @author TT, Stefan Eiler, Holger Freyther | 42 | * @author TT, Stefan Eiler, Holger Freyther |
43 | */ | 43 | */ |
44 | class QPC_EXPORT OContact : public OPimRecord | 44 | class QPC_EXPORT OContact : public OPimRecord |
45 | { | 45 | { |
46 | friend class DataSet; | 46 | friend class DataSet; |
47 | public: | 47 | public: |
48 | OContact(); | 48 | OContact(); |
49 | OContact( const QMap<int, QString> &fromMap ); | 49 | OContact( const QMap<int, QString> &fromMap ); |
50 | virtual ~OContact(); | 50 | virtual ~OContact(); |
51 | 51 | ||
52 | enum DateFormat{ | ||
53 | Zip_City_State = 0, | ||
54 | City_State_Zip | ||
55 | }; | ||
56 | |||
52 | /* | 57 | /* |
53 | * do we need to inline them | 58 | * do we need to inline them |
54 | * if yes do we need to inline them this way? | 59 | * if yes do we need to inline them this way? |
55 | * -zecke | 60 | * -zecke |
56 | */ | 61 | */ |
57 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 62 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
58 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 63 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
59 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 64 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
60 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 65 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
61 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 66 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
62 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 67 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
63 | void setFileAs(); | 68 | void setFileAs(); |
64 | 69 | ||
65 | // default email address | 70 | // default email address |
66 | void setDefaultEmail( const QString &v ); | 71 | void setDefaultEmail( const QString &v ); |
67 | // inserts email to list and ensure's doesn't already exist | 72 | // inserts email to list and ensure's doesn't already exist |
68 | void insertEmail( const QString &v ); | 73 | void insertEmail( const QString &v ); |
69 | void removeEmail( const QString &v ); | 74 | void removeEmail( const QString &v ); |
70 | void clearEmails(); | 75 | void clearEmails(); |
71 | void insertEmails( const QStringList &v ); | 76 | void insertEmails( const QStringList &v ); |
72 | 77 | ||
73 | // home | 78 | // home |
74 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 79 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
75 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 80 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
76 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 81 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
77 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 82 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
78 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 83 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
79 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 84 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
80 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 85 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
81 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 86 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
82 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 87 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
83 | 88 | ||
84 | // business | 89 | // business |
85 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 90 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
86 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 91 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
87 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 92 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
88 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 93 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
89 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 94 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
90 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 95 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
91 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 96 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
92 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 97 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
93 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 98 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
94 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 99 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
95 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 100 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
96 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } | 101 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } |
97 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } | 102 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } |
98 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } | 103 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } |
99 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } | 104 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } |
100 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } | 105 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } |
101 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } | 106 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } |
102 | 107 | ||
103 | // personal | 108 | // personal |
104 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } | 109 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } |
105 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } | 110 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } |
106 | void setBirthday( const QDate &v ); | 111 | void setBirthday( const QDate &v ); |
107 | void setAnniversary( const QDate &v ); | 112 | void setAnniversary( const QDate &v ); |
108 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } | 113 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } |
109 | void setChildren( const QString &v ); | 114 | void setChildren( const QString &v ); |
110 | 115 | ||
111 | // other | 116 | // other |
112 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 117 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
113 | 118 | ||
114 | virtual bool match( const QRegExp ®exp ) const; | 119 | virtual bool match( const QRegExp ®exp ) const; |
115 | 120 | ||
116 | // // custom | 121 | // // custom |
117 | // void setCustomField( const QString &key, const QString &v ) | 122 | // void setCustomField( const QString &key, const QString &v ) |
118 | // { replace(Custom- + key, v ); } | 123 | // { replace(Custom- + key, v ); } |
119 | 124 | ||
120 | // name | 125 | // name |
121 | QString fullName() const; | 126 | QString fullName() const; |
122 | QString title() const { return find( Qtopia::Title ); } | 127 | QString title() const { return find( Qtopia::Title ); } |
123 | QString firstName() const { return find( Qtopia::FirstName ); } | 128 | QString firstName() const { return find( Qtopia::FirstName ); } |
124 | QString middleName() const { return find( Qtopia::MiddleName ); } | 129 | QString middleName() const { return find( Qtopia::MiddleName ); } |
125 | QString lastName() const { return find( Qtopia::LastName ); } | 130 | QString lastName() const { return find( Qtopia::LastName ); } |
126 | QString suffix() const { return find( Qtopia::Suffix ); } | 131 | QString suffix() const { return find( Qtopia::Suffix ); } |
127 | QString fileAs() const { return find( Qtopia::FileAs ); } | 132 | QString fileAs() const { return find( Qtopia::FileAs ); } |
128 | 133 | ||
129 | 134 | ||
130 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 135 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
131 | QStringList emailList() const; | 136 | QStringList emailList() const; |
132 | 137 | ||
133 | // home | 138 | // home |
134 | /* | 139 | /* |
135 | * OPimAddress address(enum Location)const; | 140 | * OPimAddress address(enum Location)const; |
136 | * would be some how nicer... | 141 | * would be some how nicer... |
137 | * -zecke | 142 | * -zecke |
138 | */ | 143 | */ |
139 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 144 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
140 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 145 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
141 | QString homeState() const { return find( Qtopia::HomeState ); } | 146 | QString homeState() const { return find( Qtopia::HomeState ); } |
142 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 147 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
143 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 148 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
144 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 149 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
145 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 150 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
146 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 151 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
147 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 152 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
148 | /** Multi line string containing all non-empty address info in the form | 153 | /** Multi line string containing all non-empty address info in the form |
149 | * Street | 154 | * Street |
150 | * City, State Zip | 155 | * City, State Zip |
151 | * Country | 156 | * Country |
152 | */ | 157 | */ |
153 | QString displayHomeAddress() const; | 158 | QString displayHomeAddress() const; |
154 | 159 | ||
155 | // business | 160 | // business |
156 | QString company() const { return find( Qtopia::Company ); } | 161 | QString company() const { return find( Qtopia::Company ); } |
157 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 162 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
158 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 163 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
159 | QString businessState() const { return find( Qtopia::BusinessState ); } | 164 | QString businessState() const { return find( Qtopia::BusinessState ); } |
160 | QString businessZip() const { return find( Qtopia::BusinessZip ); } | 165 | QString businessZip() const { return find( Qtopia::BusinessZip ); } |
161 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } | 166 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } |
162 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } | 167 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } |
163 | QString jobTitle() const { return find( Qtopia::JobTitle ); } | 168 | QString jobTitle() const { return find( Qtopia::JobTitle ); } |
164 | QString department() const { return find( Qtopia::Department ); } | 169 | QString department() const { return find( Qtopia::Department ); } |
165 | QString office() const { return find( Qtopia::Office ); } | 170 | QString office() const { return find( Qtopia::Office ); } |
166 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } | 171 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } |
167 | QString businessFax() const { return find( Qtopia::BusinessFax ); } | 172 | QString businessFax() const { return find( Qtopia::BusinessFax ); } |
168 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } | 173 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } |
169 | QString businessPager() const { return find( Qtopia::BusinessPager ); } | 174 | QString businessPager() const { return find( Qtopia::BusinessPager ); } |
170 | QString profession() const { return find( Qtopia::Profession ); } | 175 | QString profession() const { return find( Qtopia::Profession ); } |
171 | QString assistant() const { return find( Qtopia::Assistant ); } | 176 | QString assistant() const { return find( Qtopia::Assistant ); } |
172 | QString manager() const { return find( Qtopia::Manager ); } | 177 | QString manager() const { return find( Qtopia::Manager ); } |
173 | /** Multi line string containing all non-empty address info in the form | 178 | /** Multi line string containing all non-empty address info in the form |
174 | * Street | 179 | * Street |
175 | * City, State Zip | 180 | * City, State Zip |
176 | * Country | 181 | * Country |
177 | */ | 182 | */ |
178 | QString displayBusinessAddress() const; | 183 | QString displayBusinessAddress() const; |
179 | 184 | ||
180 | //personal | 185 | //personal |
181 | QString spouse() const { return find( Qtopia::Spouse ); } | 186 | QString spouse() const { return find( Qtopia::Spouse ); } |
182 | QString gender() const { return find( Qtopia::Gender ); } | 187 | QString gender() const { return find( Qtopia::Gender ); } |
183 | QDate birthday() const; | 188 | QDate birthday() const; |
184 | QDate anniversary() const; | 189 | QDate anniversary() const; |
185 | QString nickname() const { return find( Qtopia::Nickname ); } | 190 | QString nickname() const { return find( Qtopia::Nickname ); } |
186 | QString children() const { return find( Qtopia::Children ); } | 191 | QString children() const { return find( Qtopia::Children ); } |
187 | QStringList childrenList() const; | 192 | QStringList childrenList() const; |
188 | 193 | ||
189 | // other | 194 | // other |
190 | QString notes() const { return find( Qtopia::Notes ); } | 195 | QString notes() const { return find( Qtopia::Notes ); } |
191 | QString groups() const { return find( Qtopia::Groups ); } | 196 | QString groups() const { return find( Qtopia::Groups ); } |
192 | QStringList groupList() const; | 197 | QStringList groupList() const; |
193 | 198 | ||
194 | // // custom | 199 | // // custom |
195 | // const QString &customField( const QString &key ) | 200 | // const QString &customField( const QString &key ) |
196 | // { return find( Custom- + key ); } | 201 | // { return find( Custom- + key ); } |
197 | 202 | ||
198 | 203 | ||
199 | QString toRichText() const; | 204 | QString toRichText() const; |
200 | QMap<int, QString> toMap() const; | 205 | QMap<int, QString> toMap() const; |
201 | QString field( int key ) const { return find( key ); } | 206 | QString field( int key ) const { return find( key ); } |
202 | 207 | ||
203 | 208 | ||
204 | void setUid( int i ); | 209 | void setUid( int i ); |
205 | 210 | ||
206 | QString toShortText()const; | 211 | QString toShortText()const; |
207 | QString OContact::type()const; | 212 | QString OContact::type()const; |
208 | QMap<QString,QString> OContact::toExtraMap() const; | 213 | QMap<QString,QString> OContact::toExtraMap() const; |
209 | class QString OContact::recordField(int) const; | 214 | class QString OContact::recordField(int) const; |
210 | 215 | ||
211 | // Why private ? (eilers,se) | 216 | // Why private ? (eilers,se) |
212 | QString emailSeparator() const { return " "; } | 217 | QString emailSeparator() const { return " "; } |
213 | // the emails should be seperated by a comma | 218 | // the emails should be seperated by a comma |
214 | void setEmails( const QString &v ); | 219 | void setEmails( const QString &v ); |
215 | QString emails() const { return find( Qtopia::Emails ); } | 220 | QString emails() const { return find( Qtopia::Emails ); } |
216 | static int rtti(); | 221 | static int rtti(); |
217 | 222 | ||
218 | private: | 223 | private: |
219 | // The XML-Backend needs some access to the private functions | 224 | // The XML-Backend needs some access to the private functions |
220 | friend class OContactAccessBackend_XML; | 225 | friend class OContactAccessBackend_XML; |
221 | 226 | ||
222 | void insert( int key, const QString &value ); | 227 | void insert( int key, const QString &value ); |
223 | void replace( int key, const QString &value ); | 228 | void replace( int key, const QString &value ); |
224 | QString find( int key ) const; | 229 | QString find( int key ) const; |
225 | static QStringList fields(); | 230 | static QStringList fields(); |
226 | 231 | ||
227 | void save( QString &buf ) const; | 232 | void save( QString &buf ) const; |
228 | 233 | ||
229 | QString displayAddress( const QString &street, | 234 | QString displayAddress( const QString &street, |
230 | const QString &city, | 235 | const QString &city, |
231 | const QString &state, | 236 | const QString &state, |
232 | const QString &zip, | 237 | const QString &zip, |
233 | const QString &country ) const; | 238 | const QString &country ) const; |
234 | 239 | ||
235 | QMap<int, QString> mMap; | 240 | QMap<int, QString> mMap; |
236 | ContactPrivate *d; | 241 | OContactPrivate *d; |
237 | }; | 242 | }; |
238 | 243 | ||
239 | 244 | ||
240 | #endif | 245 | #endif |
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index edcd729..5211f57 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,300 +1,306 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | class ORecordListIteratorPrivate; | ||
10 | /** | 11 | /** |
11 | * Our List Iterator | 12 | * Our List Iterator |
12 | * it behaves like STL or Qt | 13 | * it behaves like STL or Qt |
13 | * | 14 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 15 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 16 | * doSomeCoolStuff( (*it) ); |
16 | */ | 17 | */ |
17 | template <class T> class ORecordList; | 18 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 19 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 20 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 21 | friend class ORecordList<T>; |
21 | public: | 22 | public: |
22 | typedef OTemplateBase<T> Base; | 23 | typedef OTemplateBase<T> Base; |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * The c'tor used internally from | 26 | * The c'tor used internally from |
26 | * ORecordList | 27 | * ORecordList |
27 | */ | 28 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 29 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 30 | ||
30 | /** | 31 | /** |
31 | * The standard c'tor | 32 | * The standard c'tor |
32 | */ | 33 | */ |
33 | ORecordListIterator(); | 34 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 35 | ~ORecordListIterator(); |
35 | 36 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 37 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 38 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * a * operator ;) | 41 | * a * operator ;) |
41 | * use it like this T = (*it); | 42 | * use it like this T = (*it); |
42 | */ | 43 | */ |
43 | T operator*(); | 44 | T operator*(); |
44 | ORecordListIterator &operator++(); | 45 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 46 | ORecordListIterator &operator--(); |
46 | 47 | ||
47 | bool operator==( const ORecordListIterator& it ); | 48 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 49 | bool operator!=( const ORecordListIterator& it ); |
49 | 50 | ||
50 | /** | 51 | /** |
51 | * the current item | 52 | * the current item |
52 | */ | 53 | */ |
53 | uint current()const; | 54 | uint current()const; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * the number of items | 57 | * the number of items |
57 | */ | 58 | */ |
58 | uint count()const; | 59 | uint count()const; |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * sets the current item | 62 | * sets the current item |
62 | */ | 63 | */ |
63 | void setCurrent( uint cur ); | 64 | void setCurrent( uint cur ); |
64 | 65 | ||
65 | private: | 66 | private: |
66 | QArray<int> m_uids; | 67 | QArray<int> m_uids; |
67 | uint m_current; | 68 | uint m_current; |
68 | const Base* m_temp; | 69 | const Base* m_temp; |
69 | bool m_end : 1; | 70 | bool m_end : 1; |
70 | T m_record; | 71 | T m_record; |
71 | bool m_direction :1; | 72 | bool m_direction :1; |
72 | 73 | ||
73 | /* d pointer for future versions */ | 74 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 75 | ORecordListIteratorPrivate *d; |
75 | IteratorPrivate *d; | ||
76 | }; | 76 | }; |
77 | |||
78 | class ORecordListPrivate; | ||
77 | /** | 79 | /** |
78 | * The recordlist used as a return type | 80 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 81 | * from OPimAccessTemplate |
80 | */ | 82 | */ |
81 | template <class T = OPimRecord > | 83 | template <class T = OPimRecord > |
82 | class ORecordList { | 84 | class ORecordList { |
83 | public: | 85 | public: |
84 | typedef OTemplateBase<T> Base; | 86 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 87 | typedef ORecordListIterator<T> Iterator; |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * c'tor | 90 | * c'tor |
89 | */ | 91 | */ |
90 | ORecordList () { | 92 | ORecordList () { |
91 | } | 93 | } |
92 | ORecordList( const QArray<int>& ids, | 94 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 95 | const Base* ); |
94 | ~ORecordList(); | 96 | ~ORecordList(); |
95 | 97 | ||
96 | /** | 98 | /** |
97 | * the first iterator | 99 | * the first iterator |
98 | */ | 100 | */ |
99 | Iterator begin(); | 101 | Iterator begin(); |
100 | 102 | ||
101 | /** | 103 | /** |
102 | * the end | 104 | * the end |
103 | */ | 105 | */ |
104 | Iterator end(); | 106 | Iterator end(); |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * the number of items in the list | 109 | * the number of items in the list |
108 | */ | 110 | */ |
109 | uint count()const; | 111 | uint count()const; |
110 | 112 | ||
111 | T operator[]( uint i ); | 113 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | 114 | int uidAt(uint i ); |
113 | 115 | ||
114 | /** | 116 | /** |
115 | * Remove the contact with given uid | 117 | * Remove the contact with given uid |
116 | */ | 118 | */ |
117 | bool remove( int uid ); | 119 | bool remove( int uid ); |
118 | 120 | ||
119 | /* | 121 | /* |
120 | ConstIterator begin()const; | 122 | ConstIterator begin()const; |
121 | ConstIterator end()const; | 123 | ConstIterator end()const; |
122 | */ | 124 | */ |
123 | private: | 125 | private: |
124 | QArray<int> m_ids; | 126 | QArray<int> m_ids; |
125 | const Base* m_acc; | 127 | const Base* m_acc; |
128 | ORecordListPrivate *d; | ||
126 | }; | 129 | }; |
127 | 130 | ||
128 | /* ok now implement it */ | 131 | /* ok now implement it */ |
129 | template <class T> | 132 | template <class T> |
130 | ORecordListIterator<T>::ORecordListIterator() { | 133 | ORecordListIterator<T>::ORecordListIterator() { |
131 | m_current = 0; | 134 | m_current = 0; |
132 | m_temp = 0l; | 135 | m_temp = 0l; |
133 | m_end = true; | 136 | m_end = true; |
134 | m_record = T(); | 137 | m_record = T(); |
135 | /* forward */ | 138 | /* forward */ |
136 | m_direction = TRUE; | 139 | m_direction = TRUE; |
137 | } | 140 | } |
138 | template <class T> | 141 | template <class T> |
139 | ORecordListIterator<T>::~ORecordListIterator() { | 142 | ORecordListIterator<T>::~ORecordListIterator() { |
140 | /* nothing to delete */ | 143 | /* nothing to delete */ |
141 | } | 144 | } |
142 | 145 | ||
143 | template <class T> | 146 | template <class T> |
144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 147 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
145 | // qWarning("ORecordListIterator copy c'tor"); | 148 | // qWarning("ORecordListIterator copy c'tor"); |
146 | m_uids = it.m_uids; | 149 | m_uids = it.m_uids; |
147 | m_current = it.m_current; | 150 | m_current = it.m_current; |
148 | m_temp = it.m_temp; | 151 | m_temp = it.m_temp; |
149 | m_end = it.m_end; | 152 | m_end = it.m_end; |
150 | m_record = it.m_record; | 153 | m_record = it.m_record; |
151 | m_direction = it.m_direction; | 154 | m_direction = it.m_direction; |
152 | } | 155 | } |
153 | 156 | ||
154 | template <class T> | 157 | template <class T> |
155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 158 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
156 | m_uids = it.m_uids; | 159 | m_uids = it.m_uids; |
157 | m_current = it.m_current; | 160 | m_current = it.m_current; |
158 | m_temp = it.m_temp; | 161 | m_temp = it.m_temp; |
159 | m_end = it.m_end; | 162 | m_end = it.m_end; |
160 | m_record = it.m_record; | 163 | m_record = it.m_record; |
161 | 164 | ||
162 | return *this; | 165 | return *this; |
163 | } | 166 | } |
164 | 167 | ||
165 | template <class T> | 168 | template <class T> |
166 | T ORecordListIterator<T>::operator*() { | 169 | T ORecordListIterator<T>::operator*() { |
167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 170 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
168 | if (!m_end ) | 171 | if (!m_end ) |
169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 172 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
170 | m_direction ? Base::Forward : | 173 | m_direction ? Base::Forward : |
171 | Base::Reverse ); | 174 | Base::Reverse ); |
172 | else | 175 | else |
173 | m_record = T(); | 176 | m_record = T(); |
174 | 177 | ||
175 | return m_record; | 178 | return m_record; |
176 | } | 179 | } |
177 | 180 | ||
178 | template <class T> | 181 | template <class T> |
179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 182 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
180 | m_direction = true; | 183 | m_direction = true; |
181 | if (m_current < m_uids.count() ) { | 184 | if (m_current < m_uids.count() ) { |
182 | m_end = false; | 185 | m_end = false; |
183 | ++m_current; | 186 | ++m_current; |
184 | }else | 187 | }else |
185 | m_end = true; | 188 | m_end = true; |
186 | 189 | ||
187 | return *this; | 190 | return *this; |
188 | } | 191 | } |
189 | template <class T> | 192 | template <class T> |
190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 193 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
191 | m_direction = false; | 194 | m_direction = false; |
192 | if ( m_current > 0 ) { | 195 | if ( m_current > 0 ) { |
193 | --m_current; | 196 | --m_current; |
194 | m_end = false; | 197 | m_end = false; |
195 | } else | 198 | } else |
196 | m_end = true; | 199 | m_end = true; |
197 | 200 | ||
198 | return *this; | 201 | return *this; |
199 | } | 202 | } |
200 | 203 | ||
201 | template <class T> | 204 | template <class T> |
202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 205 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
203 | 206 | ||
204 | /* if both are at we're the same.... */ | 207 | /* if both are at we're the same.... */ |
205 | if ( m_end == it.m_end ) return true; | 208 | if ( m_end == it.m_end ) return true; |
206 | 209 | ||
207 | if ( m_uids != it.m_uids ) return false; | 210 | if ( m_uids != it.m_uids ) return false; |
208 | if ( m_current != it.m_current ) return false; | 211 | if ( m_current != it.m_current ) return false; |
209 | if ( m_temp != it.m_temp ) return false; | 212 | if ( m_temp != it.m_temp ) return false; |
210 | 213 | ||
211 | return true; | 214 | return true; |
212 | } | 215 | } |
213 | template <class T> | 216 | template <class T> |
214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 217 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
215 | return !(*this == it ); | 218 | return !(*this == it ); |
216 | } | 219 | } |
217 | template <class T> | 220 | template <class T> |
218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 221 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
219 | const Base* t ) | 222 | const Base* t ) |
220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 223 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
221 | m_direction( false ) | 224 | m_direction( false ) |
222 | { | 225 | { |
226 | /* if the list is empty we're already at the end of the list */ | ||
227 | if (uids.count() == 0 ) | ||
228 | m_end = true; | ||
223 | } | 229 | } |
224 | template <class T> | 230 | template <class T> |
225 | uint ORecordListIterator<T>::current()const { | 231 | uint ORecordListIterator<T>::current()const { |
226 | return m_current; | 232 | return m_current; |
227 | } | 233 | } |
228 | template <class T> | 234 | template <class T> |
229 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 235 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
230 | if( cur < m_uids.count() ) { | 236 | if( cur < m_uids.count() ) { |
231 | m_end = false; | 237 | m_end = false; |
232 | m_current= cur; | 238 | m_current= cur; |
233 | } | 239 | } |
234 | } | 240 | } |
235 | template <class T> | 241 | template <class T> |
236 | uint ORecordListIterator<T>::count()const { | 242 | uint ORecordListIterator<T>::count()const { |
237 | return m_uids.count(); | 243 | return m_uids.count(); |
238 | } | 244 | } |
239 | template <class T> | 245 | template <class T> |
240 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 246 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
241 | const Base* acc ) | 247 | const Base* acc ) |
242 | : m_ids( ids ), m_acc( acc ) | 248 | : m_ids( ids ), m_acc( acc ) |
243 | { | 249 | { |
244 | } | 250 | } |
245 | template <class T> | 251 | template <class T> |
246 | ORecordList<T>::~ORecordList() { | 252 | ORecordList<T>::~ORecordList() { |
247 | /* nothing to do here */ | 253 | /* nothing to do here */ |
248 | } | 254 | } |
249 | template <class T> | 255 | template <class T> |
250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 256 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { |
251 | Iterator it( m_ids, m_acc ); | 257 | Iterator it( m_ids, m_acc ); |
252 | return it; | 258 | return it; |
253 | } | 259 | } |
254 | template <class T> | 260 | template <class T> |
255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 261 | typename ORecordList<T>::Iterator ORecordList<T>::end() { |
256 | Iterator it( m_ids, m_acc ); | 262 | Iterator it( m_ids, m_acc ); |
257 | it.m_end = true; | 263 | it.m_end = true; |
258 | it.m_current = m_ids.count(); | 264 | it.m_current = m_ids.count(); |
259 | 265 | ||
260 | return it; | 266 | return it; |
261 | } | 267 | } |
262 | template <class T> | 268 | template <class T> |
263 | uint ORecordList<T>::count()const { | 269 | uint ORecordList<T>::count()const { |
264 | return m_ids.count(); | 270 | return m_ids.count(); |
265 | } | 271 | } |
266 | template <class T> | 272 | template <class T> |
267 | T ORecordList<T>::operator[]( uint i ) { | 273 | T ORecordList<T>::operator[]( uint i ) { |
268 | if ( i >= m_ids.count() ) | 274 | if ( i >= m_ids.count() ) |
269 | return T(); | 275 | return T(); |
270 | /* forward */ | 276 | /* forward */ |
271 | return m_acc->find( m_ids[i], m_ids, i ); | 277 | return m_acc->find( m_ids[i], m_ids, i ); |
272 | } | 278 | } |
273 | template <class T> | 279 | template <class T> |
274 | int ORecordList<T>::uidAt( uint i ) { | 280 | int ORecordList<T>::uidAt( uint i ) { |
275 | return m_ids[i]; | 281 | return m_ids[i]; |
276 | } | 282 | } |
277 | 283 | ||
278 | template <class T> | 284 | template <class T> |
279 | bool ORecordList<T>::remove( int uid ) { | 285 | bool ORecordList<T>::remove( int uid ) { |
280 | QArray<int> copy( m_ids.count() ); | 286 | QArray<int> copy( m_ids.count() ); |
281 | int counter = 0; | 287 | int counter = 0; |
282 | bool ret_val = false; | 288 | bool ret_val = false; |
283 | 289 | ||
284 | for (uint i = 0; i < m_ids.count(); i++){ | 290 | for (uint i = 0; i < m_ids.count(); i++){ |
285 | if ( m_ids[i] != uid ){ | 291 | if ( m_ids[i] != uid ){ |
286 | copy[counter++] = m_ids[i]; | 292 | copy[counter++] = m_ids[i]; |
287 | 293 | ||
288 | }else | 294 | }else |
289 | ret_val = true; | 295 | ret_val = true; |
290 | } | 296 | } |
291 | 297 | ||
292 | copy.resize( counter ); | 298 | copy.resize( counter ); |
293 | m_ids = copy; | 299 | m_ids = copy; |
294 | 300 | ||
295 | 301 | ||
296 | return ret_val; | 302 | return ret_val; |
297 | } | 303 | } |
298 | 304 | ||
299 | 305 | ||
300 | #endif | 306 | #endif |
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index 38b93f7..5a18c37 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -1,516 +1,520 @@ | |||
1 | 1 | ||
2 | #include <qobject.h> | 2 | #include <qobject.h> |
3 | #include <qshared.h> | 3 | #include <qshared.h> |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
7 | #include <qpe/palmtopuidgen.h> | 7 | #include <qpe/palmtopuidgen.h> |
8 | #include <qpe/stringutil.h> | 8 | #include <qpe/stringutil.h> |
9 | #include <qpe/palmtoprecord.h> | 9 | #include <qpe/palmtoprecord.h> |
10 | #include <qpe/stringutil.h> | 10 | #include <qpe/stringutil.h> |
11 | #include <qpe/categories.h> | 11 | #include <qpe/categories.h> |
12 | #include <qpe/categoryselect.h> | 12 | #include <qpe/categoryselect.h> |
13 | 13 | ||
14 | 14 | ||
15 | #include "opimstate.h" | 15 | #include "opimstate.h" |
16 | #include "orecur.h" | 16 | #include "orecur.h" |
17 | #include "opimmaintainer.h" | 17 | #include "opimmaintainer.h" |
18 | #include "opimnotifymanager.h" | 18 | #include "opimnotifymanager.h" |
19 | #include "opimresolver.h" | 19 | #include "opimresolver.h" |
20 | 20 | ||
21 | #include "otodo.h" | 21 | #include "otodo.h" |
22 | 22 | ||
23 | 23 | ||
24 | struct OTodo::OTodoData : public QShared { | 24 | struct OTodo::OTodoData : public QShared { |
25 | OTodoData() : QShared() { | 25 | OTodoData() : QShared() { |
26 | recur = 0; | 26 | recur = 0; |
27 | state = 0; | 27 | state = 0; |
28 | maintainer = 0; | 28 | maintainer = 0; |
29 | notifiers = 0; | 29 | notifiers = 0; |
30 | }; | 30 | }; |
31 | ~OTodoData() { | ||
32 | delete recur; | ||
33 | delete maintainer; | ||
34 | delete notifiers; | ||
35 | } | ||
31 | 36 | ||
32 | QDate date; | 37 | QDate date; |
33 | bool isCompleted:1; | 38 | bool isCompleted:1; |
34 | bool hasDate:1; | 39 | bool hasDate:1; |
35 | int priority; | 40 | int priority; |
36 | QString desc; | 41 | QString desc; |
37 | QString sum; | 42 | QString sum; |
38 | QMap<QString, QString> extra; | 43 | QMap<QString, QString> extra; |
39 | ushort prog; | 44 | ushort prog; |
40 | OPimState *state; | 45 | OPimState *state; |
41 | ORecur *recur; | 46 | ORecur *recur; |
42 | OPimMaintainer *maintainer; | 47 | OPimMaintainer *maintainer; |
43 | QDate start; | 48 | QDate start; |
44 | QDate completed; | 49 | QDate completed; |
45 | OPimNotifyManager *notifiers; | 50 | OPimNotifyManager *notifiers; |
46 | }; | 51 | }; |
47 | 52 | ||
48 | OTodo::OTodo(const OTodo &event ) | 53 | OTodo::OTodo(const OTodo &event ) |
49 | : OPimRecord( event ), data( event.data ) | 54 | : OPimRecord( event ), data( event.data ) |
50 | { | 55 | { |
51 | data->ref(); | 56 | data->ref(); |
52 | // qWarning("ref up"); | 57 | // qWarning("ref up"); |
53 | } | 58 | } |
54 | OTodo::~OTodo() { | 59 | OTodo::~OTodo() { |
55 | 60 | ||
56 | // qWarning("~OTodo " ); | 61 | // qWarning("~OTodo " ); |
57 | if ( data->deref() ) { | 62 | if ( data->deref() ) { |
58 | // qWarning("OTodo::dereffing"); | 63 | // qWarning("OTodo::dereffing"); |
59 | delete data; | 64 | delete data; |
60 | data = 0l; | 65 | data = 0l; |
61 | } | 66 | } |
62 | } | 67 | } |
63 | OTodo::OTodo(bool completed, int priority, | 68 | OTodo::OTodo(bool completed, int priority, |
64 | const QArray<int> &category, | 69 | const QArray<int> &category, |
65 | const QString& summary, | 70 | const QString& summary, |
66 | const QString &description, | 71 | const QString &description, |
67 | ushort progress, | 72 | ushort progress, |
68 | bool hasDate, QDate date, int uid ) | 73 | bool hasDate, QDate date, int uid ) |
69 | : OPimRecord( uid ) | 74 | : OPimRecord( uid ) |
70 | { | 75 | { |
71 | // qWarning("OTodoData " + summary); | 76 | // qWarning("OTodoData " + summary); |
72 | setCategories( category ); | 77 | setCategories( category ); |
73 | 78 | ||
74 | data = new OTodoData; | 79 | data = new OTodoData; |
75 | 80 | ||
76 | data->date = date; | 81 | data->date = date; |
77 | data->isCompleted = completed; | 82 | data->isCompleted = completed; |
78 | data->hasDate = hasDate; | 83 | data->hasDate = hasDate; |
79 | data->priority = priority; | 84 | data->priority = priority; |
80 | data->sum = summary; | 85 | data->sum = summary; |
81 | data->prog = progress; | 86 | data->prog = progress; |
82 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 87 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
83 | } | 88 | } |
84 | OTodo::OTodo(bool completed, int priority, | 89 | OTodo::OTodo(bool completed, int priority, |
85 | const QStringList &category, | 90 | const QStringList &category, |
86 | const QString& summary, | 91 | const QString& summary, |
87 | const QString &description, | 92 | const QString &description, |
88 | ushort progress, | 93 | ushort progress, |
89 | bool hasDate, QDate date, int uid ) | 94 | bool hasDate, QDate date, int uid ) |
90 | : OPimRecord( uid ) | 95 | : OPimRecord( uid ) |
91 | { | 96 | { |
92 | // qWarning("OTodoData" + summary); | 97 | // qWarning("OTodoData" + summary); |
93 | setCategories( idsFromString( category.join(";") ) ); | 98 | setCategories( idsFromString( category.join(";") ) ); |
94 | 99 | ||
95 | data = new OTodoData; | 100 | data = new OTodoData; |
96 | 101 | ||
97 | data->date = date; | 102 | data->date = date; |
98 | data->isCompleted = completed; | 103 | data->isCompleted = completed; |
99 | data->hasDate = hasDate; | 104 | data->hasDate = hasDate; |
100 | data->priority = priority; | 105 | data->priority = priority; |
101 | data->sum = summary; | 106 | data->sum = summary; |
102 | data->prog = progress; | 107 | data->prog = progress; |
103 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 108 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
104 | } | 109 | } |
105 | bool OTodo::match( const QRegExp ®Exp )const | 110 | bool OTodo::match( const QRegExp ®Exp )const |
106 | { | 111 | { |
107 | if( QString::number( data->priority ).find( regExp ) != -1 ){ | 112 | if( QString::number( data->priority ).find( regExp ) != -1 ){ |
108 | setLastHitField( Priority ); | 113 | setLastHitField( Priority ); |
109 | return true; | 114 | return true; |
110 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ | 115 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ |
111 | setLastHitField( HasDate ); | 116 | setLastHitField( HasDate ); |
112 | return true; | 117 | return true; |
113 | }else if(data->desc.find( regExp ) != -1 ){ | 118 | }else if(data->desc.find( regExp ) != -1 ){ |
114 | setLastHitField( Description ); | 119 | setLastHitField( Description ); |
115 | return true; | 120 | return true; |
116 | }else if(data->sum.find( regExp ) != -1 ) { | 121 | }else if(data->sum.find( regExp ) != -1 ) { |
117 | setLastHitField( Summary ); | 122 | setLastHitField( Summary ); |
118 | return true; | 123 | return true; |
119 | } | 124 | } |
120 | return false; | 125 | return false; |
121 | } | 126 | } |
122 | bool OTodo::isCompleted() const | 127 | bool OTodo::isCompleted() const |
123 | { | 128 | { |
124 | return data->isCompleted; | 129 | return data->isCompleted; |
125 | } | 130 | } |
126 | bool OTodo::hasDueDate() const | 131 | bool OTodo::hasDueDate() const |
127 | { | 132 | { |
128 | return data->hasDate; | 133 | return data->hasDate; |
129 | } | 134 | } |
130 | bool OTodo::hasStartDate()const { | 135 | bool OTodo::hasStartDate()const { |
131 | return data->start.isValid(); | 136 | return data->start.isValid(); |
132 | } | 137 | } |
133 | bool OTodo::hasCompletedDate()const { | 138 | bool OTodo::hasCompletedDate()const { |
134 | return data->completed.isValid(); | 139 | return data->completed.isValid(); |
135 | } | 140 | } |
136 | int OTodo::priority()const | 141 | int OTodo::priority()const |
137 | { | 142 | { |
138 | return data->priority; | 143 | return data->priority; |
139 | } | 144 | } |
140 | QString OTodo::summary() const | 145 | QString OTodo::summary() const |
141 | { | 146 | { |
142 | return data->sum; | 147 | return data->sum; |
143 | } | 148 | } |
144 | ushort OTodo::progress() const | 149 | ushort OTodo::progress() const |
145 | { | 150 | { |
146 | return data->prog; | 151 | return data->prog; |
147 | } | 152 | } |
148 | QDate OTodo::dueDate()const | 153 | QDate OTodo::dueDate()const |
149 | { | 154 | { |
150 | return data->date; | 155 | return data->date; |
151 | } | 156 | } |
152 | QDate OTodo::startDate()const { | 157 | QDate OTodo::startDate()const { |
153 | return data->start; | 158 | return data->start; |
154 | } | 159 | } |
155 | QDate OTodo::completedDate()const { | 160 | QDate OTodo::completedDate()const { |
156 | return data->completed; | 161 | return data->completed; |
157 | } | 162 | } |
158 | QString OTodo::description()const | 163 | QString OTodo::description()const |
159 | { | 164 | { |
160 | return data->desc; | 165 | return data->desc; |
161 | } | 166 | } |
162 | bool OTodo::hasState() const{ | 167 | bool OTodo::hasState() const{ |
163 | if (!data->state ) return false; | 168 | if (!data->state ) return false; |
164 | return ( data->state->state() != OPimState::Undefined ); | 169 | return ( data->state->state() != OPimState::Undefined ); |
165 | } | 170 | } |
166 | OPimState OTodo::state()const { | 171 | OPimState OTodo::state()const { |
167 | if (!data->state ) { | 172 | if (!data->state ) { |
168 | OPimState state; | 173 | OPimState state; |
169 | return state; | 174 | return state; |
170 | } | 175 | } |
171 | 176 | ||
172 | return (*data->state); | 177 | return (*data->state); |
173 | } | 178 | } |
174 | bool OTodo::hasRecurrence()const { | 179 | bool OTodo::hasRecurrence()const { |
175 | if (!data->recur) return false; | 180 | if (!data->recur) return false; |
176 | return data->recur->doesRecur(); | 181 | return data->recur->doesRecur(); |
177 | } | 182 | } |
178 | ORecur OTodo::recurrence()const { | 183 | ORecur OTodo::recurrence()const { |
179 | if (!data->recur) return ORecur(); | 184 | if (!data->recur) return ORecur(); |
180 | 185 | ||
181 | return (*data->recur); | 186 | return (*data->recur); |
182 | } | 187 | } |
183 | bool OTodo::hasMaintainer()const { | 188 | bool OTodo::hasMaintainer()const { |
184 | if (!data->maintainer) return false; | 189 | if (!data->maintainer) return false; |
185 | 190 | ||
186 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); | 191 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); |
187 | } | 192 | } |
188 | OPimMaintainer OTodo::maintainer()const { | 193 | OPimMaintainer OTodo::maintainer()const { |
189 | if (!data->maintainer) return OPimMaintainer(); | 194 | if (!data->maintainer) return OPimMaintainer(); |
190 | 195 | ||
191 | return (*data->maintainer); | 196 | return (*data->maintainer); |
192 | } | 197 | } |
193 | void OTodo::setCompleted( bool completed ) | 198 | void OTodo::setCompleted( bool completed ) |
194 | { | 199 | { |
195 | changeOrModify(); | 200 | changeOrModify(); |
196 | data->isCompleted = completed; | 201 | data->isCompleted = completed; |
197 | } | 202 | } |
198 | void OTodo::setHasDueDate( bool hasDate ) | 203 | void OTodo::setHasDueDate( bool hasDate ) |
199 | { | 204 | { |
200 | changeOrModify(); | 205 | changeOrModify(); |
201 | data->hasDate = hasDate; | 206 | data->hasDate = hasDate; |
202 | } | 207 | } |
203 | void OTodo::setDescription(const QString &desc ) | 208 | void OTodo::setDescription(const QString &desc ) |
204 | { | 209 | { |
205 | // qWarning( "desc " + desc ); | 210 | // qWarning( "desc " + desc ); |
206 | changeOrModify(); | 211 | changeOrModify(); |
207 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); | 212 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); |
208 | } | 213 | } |
209 | void OTodo::setSummary( const QString& sum ) | 214 | void OTodo::setSummary( const QString& sum ) |
210 | { | 215 | { |
211 | changeOrModify(); | 216 | changeOrModify(); |
212 | data->sum = sum; | 217 | data->sum = sum; |
213 | } | 218 | } |
214 | void OTodo::setPriority(int prio ) | 219 | void OTodo::setPriority(int prio ) |
215 | { | 220 | { |
216 | changeOrModify(); | 221 | changeOrModify(); |
217 | data->priority = prio; | 222 | data->priority = prio; |
218 | } | 223 | } |
219 | void OTodo::setDueDate( const QDate& date ) | 224 | void OTodo::setDueDate( const QDate& date ) |
220 | { | 225 | { |
221 | changeOrModify(); | 226 | changeOrModify(); |
222 | data->date = date; | 227 | data->date = date; |
223 | } | 228 | } |
224 | void OTodo::setStartDate( const QDate& date ) { | 229 | void OTodo::setStartDate( const QDate& date ) { |
225 | changeOrModify(); | 230 | changeOrModify(); |
226 | data->start = date; | 231 | data->start = date; |
227 | } | 232 | } |
228 | void OTodo::setCompletedDate( const QDate& date ) { | 233 | void OTodo::setCompletedDate( const QDate& date ) { |
229 | changeOrModify(); | 234 | changeOrModify(); |
230 | data->completed = date; | 235 | data->completed = date; |
231 | } | 236 | } |
232 | void OTodo::setState( const OPimState& state ) { | 237 | void OTodo::setState( const OPimState& state ) { |
233 | changeOrModify(); | 238 | changeOrModify(); |
234 | if (data->state ) | 239 | if (data->state ) |
235 | (*data->state) = state; | 240 | (*data->state) = state; |
236 | else | 241 | else |
237 | data->state = new OPimState( state ); | 242 | data->state = new OPimState( state ); |
238 | } | 243 | } |
239 | void OTodo::setRecurrence( const ORecur& rec) { | 244 | void OTodo::setRecurrence( const ORecur& rec) { |
240 | changeOrModify(); | 245 | changeOrModify(); |
241 | if (data->recur ) | 246 | if (data->recur ) |
242 | (*data->recur) = rec; | 247 | (*data->recur) = rec; |
243 | else | 248 | else |
244 | data->recur = new ORecur( rec ); | 249 | data->recur = new ORecur( rec ); |
245 | } | 250 | } |
246 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { | 251 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { |
247 | changeOrModify(); | 252 | changeOrModify(); |
248 | 253 | ||
249 | if (data->maintainer ) | 254 | if (data->maintainer ) |
250 | (*data->maintainer) = pim; | 255 | (*data->maintainer) = pim; |
251 | else | 256 | else |
252 | data->maintainer = new OPimMaintainer( pim ); | 257 | data->maintainer = new OPimMaintainer( pim ); |
253 | } | 258 | } |
254 | bool OTodo::isOverdue( ) | 259 | bool OTodo::isOverdue( ) |
255 | { | 260 | { |
256 | if( data->hasDate && !data->isCompleted) | 261 | if( data->hasDate && !data->isCompleted) |
257 | return QDate::currentDate() > data->date; | 262 | return QDate::currentDate() > data->date; |
258 | return false; | 263 | return false; |
259 | } | 264 | } |
260 | void OTodo::setProgress(ushort progress ) | 265 | void OTodo::setProgress(ushort progress ) |
261 | { | 266 | { |
262 | changeOrModify(); | 267 | changeOrModify(); |
263 | data->prog = progress; | 268 | data->prog = progress; |
264 | } | 269 | } |
265 | QString OTodo::toShortText() const { | 270 | QString OTodo::toShortText() const { |
266 | return summary(); | 271 | return summary(); |
267 | } | 272 | } |
268 | /*! | 273 | /*! |
269 | Returns a richt text string | 274 | Returns a richt text string |
270 | */ | 275 | */ |
271 | QString OTodo::toRichText() const | 276 | QString OTodo::toRichText() const |
272 | { | 277 | { |
273 | QString text; | 278 | QString text; |
274 | QStringList catlist; | 279 | QStringList catlist; |
275 | 280 | ||
276 | // summary | 281 | // summary |
277 | text += "<b><h3><img src=\"todo/TodoList\">"; | 282 | text += "<b><h3><img src=\"todo/TodoList\"> "; |
278 | if ( !summary().isEmpty() ) { | 283 | if ( !summary().isEmpty() ) { |
279 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); | 284 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); |
280 | } | 285 | } |
281 | text += "</h3></b><br><hr><br>"; | 286 | text += "</h3></b><br><hr><br>"; |
282 | 287 | ||
283 | // description | 288 | // description |
284 | if( !description().isEmpty() ){ | 289 | if( !description().isEmpty() ){ |
285 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 290 | text += "<b>" + QObject::tr( "Notes:" ) + "</b><br>"; |
286 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; | 291 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
287 | } | 292 | } |
288 | 293 | ||
289 | // priority | 294 | // priority |
290 | int priorityval = priority(); | 295 | int priorityval = priority(); |
291 | text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + | 296 | text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + |
292 | QString::number( priorityval ) + "\">"; | 297 | QString::number( priorityval ) + "\"> "; |
293 | // text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" + | 298 | |
294 | // QString::number( priority() ) + "\"><br>"; | ||
295 | switch ( priorityval ) | 299 | switch ( priorityval ) |
296 | { | 300 | { |
297 | case 1 : text += QObject::tr( "Very high" ); | 301 | case 1 : text += QObject::tr( "Very high" ); |
298 | break; | 302 | break; |
299 | case 2 : text += QObject::tr( "High" ); | 303 | case 2 : text += QObject::tr( "High" ); |
300 | break; | 304 | break; |
301 | case 3 : text += QObject::tr( "Normal" ); | 305 | case 3 : text += QObject::tr( "Normal" ); |
302 | break; | 306 | break; |
303 | case 4 : text += QObject::tr( "Low" ); | 307 | case 4 : text += QObject::tr( "Low" ); |
304 | break; | 308 | break; |
305 | case 5 : text += QObject::tr( "Very low" ); | 309 | case 5 : text += QObject::tr( "Very low" ); |
306 | break; | 310 | break; |
307 | }; | 311 | }; |
308 | text += "<br>"; | 312 | text += "<br>"; |
309 | 313 | ||
310 | // progress | 314 | // progress |
311 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 315 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
312 | + QString::number( progress() ) + " %<br>"; | 316 | + QString::number( progress() ) + " %<br>"; |
313 | 317 | ||
314 | // due date | 318 | // due date |
315 | if (hasDueDate() ){ | 319 | if (hasDueDate() ){ |
316 | QDate dd = dueDate(); | 320 | QDate dd = dueDate(); |
317 | int off = QDate::currentDate().daysTo( dd ); | 321 | int off = QDate::currentDate().daysTo( dd ); |
318 | 322 | ||
319 | text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; | 323 | text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; |
320 | if ( off < 0 ) | 324 | if ( off < 0 ) |
321 | text += "#FF0000"; | 325 | text += "#FF0000"; |
322 | else if ( off == 0 ) | 326 | else if ( off == 0 ) |
323 | text += "#FFFF00"; | 327 | text += "#FFFF00"; |
324 | else if ( off > 0 ) | 328 | else if ( off > 0 ) |
325 | text += "#00FF00"; | 329 | text += "#00FF00"; |
326 | 330 | ||
327 | text += "\">" + dd.toString() + "</font><br>"; | 331 | text += "\">" + dd.toString() + "</font><br>"; |
328 | } | 332 | } |
329 | 333 | ||
330 | // categories | 334 | // categories |
331 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 335 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
332 | text += categoryNames( "Todo List" ).join(", "); | 336 | text += categoryNames( "Todo List" ).join(", "); |
333 | text += "<br>"; | 337 | text += "<br>"; |
334 | 338 | ||
335 | return text; | 339 | return text; |
336 | } | 340 | } |
337 | bool OTodo::hasNotifiers()const { | 341 | bool OTodo::hasNotifiers()const { |
338 | if (!data->notifiers) return false; | 342 | if (!data->notifiers) return false; |
339 | return !data->notifiers->isEmpty(); | 343 | return !data->notifiers->isEmpty(); |
340 | } | 344 | } |
341 | OPimNotifyManager& OTodo::notifiers() { | 345 | OPimNotifyManager& OTodo::notifiers() { |
342 | if (!data->notifiers ) | 346 | if (!data->notifiers ) |
343 | data->notifiers = new OPimNotifyManager; | 347 | data->notifiers = new OPimNotifyManager; |
344 | return (*data->notifiers); | 348 | return (*data->notifiers); |
345 | } | 349 | } |
346 | const OPimNotifyManager& OTodo::notifiers()const{ | 350 | const OPimNotifyManager& OTodo::notifiers()const{ |
347 | if (!data->notifiers ) | 351 | if (!data->notifiers ) |
348 | data->notifiers = new OPimNotifyManager; | 352 | data->notifiers = new OPimNotifyManager; |
349 | 353 | ||
350 | return (*data->notifiers); | 354 | return (*data->notifiers); |
351 | } | 355 | } |
352 | 356 | ||
353 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 357 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
354 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 358 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
355 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 359 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
356 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 360 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
357 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 361 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
358 | return priority() < toDoEvent.priority(); | 362 | return priority() < toDoEvent.priority(); |
359 | }else{ | 363 | }else{ |
360 | return dueDate() < toDoEvent.dueDate(); | 364 | return dueDate() < toDoEvent.dueDate(); |
361 | } | 365 | } |
362 | } | 366 | } |
363 | return false; | 367 | return false; |
364 | } | 368 | } |
365 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 369 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
366 | { | 370 | { |
367 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 371 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
368 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 372 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
369 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 373 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
370 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 374 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
371 | return priority() <= toDoEvent.priority(); | 375 | return priority() <= toDoEvent.priority(); |
372 | }else{ | 376 | }else{ |
373 | return dueDate() <= toDoEvent.dueDate(); | 377 | return dueDate() <= toDoEvent.dueDate(); |
374 | } | 378 | } |
375 | } | 379 | } |
376 | return true; | 380 | return true; |
377 | } | 381 | } |
378 | bool OTodo::operator>(const OTodo &toDoEvent )const | 382 | bool OTodo::operator>(const OTodo &toDoEvent )const |
379 | { | 383 | { |
380 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 384 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
381 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 385 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
382 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 386 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
383 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 387 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
384 | return priority() > toDoEvent.priority(); | 388 | return priority() > toDoEvent.priority(); |
385 | }else{ | 389 | }else{ |
386 | return dueDate() > toDoEvent.dueDate(); | 390 | return dueDate() > toDoEvent.dueDate(); |
387 | } | 391 | } |
388 | } | 392 | } |
389 | return false; | 393 | return false; |
390 | } | 394 | } |
391 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 395 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
392 | { | 396 | { |
393 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 397 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
394 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 398 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
395 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 399 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
396 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 400 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
397 | return priority() > toDoEvent.priority(); | 401 | return priority() > toDoEvent.priority(); |
398 | }else{ | 402 | }else{ |
399 | return dueDate() > toDoEvent.dueDate(); | 403 | return dueDate() > toDoEvent.dueDate(); |
400 | } | 404 | } |
401 | } | 405 | } |
402 | return true; | 406 | return true; |
403 | } | 407 | } |
404 | bool OTodo::operator==(const OTodo &toDoEvent )const | 408 | bool OTodo::operator==(const OTodo &toDoEvent )const |
405 | { | 409 | { |
406 | if ( data->priority != toDoEvent.data->priority ) return false; | 410 | if ( data->priority != toDoEvent.data->priority ) return false; |
407 | if ( data->priority != toDoEvent.data->prog ) return false; | 411 | if ( data->priority != toDoEvent.data->prog ) return false; |
408 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 412 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
409 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 413 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
410 | if ( data->date != toDoEvent.data->date ) return false; | 414 | if ( data->date != toDoEvent.data->date ) return false; |
411 | if ( data->sum != toDoEvent.data->sum ) return false; | 415 | if ( data->sum != toDoEvent.data->sum ) return false; |
412 | if ( data->desc != toDoEvent.data->desc ) return false; | 416 | if ( data->desc != toDoEvent.data->desc ) return false; |
413 | if ( data->maintainer != toDoEvent.data->maintainer ) | 417 | if ( data->maintainer != toDoEvent.data->maintainer ) |
414 | return false; | 418 | return false; |
415 | 419 | ||
416 | return OPimRecord::operator==( toDoEvent ); | 420 | return OPimRecord::operator==( toDoEvent ); |
417 | } | 421 | } |
418 | void OTodo::deref() { | 422 | void OTodo::deref() { |
419 | 423 | ||
420 | // qWarning("deref in ToDoEvent"); | 424 | // qWarning("deref in ToDoEvent"); |
421 | if ( data->deref() ) { | 425 | if ( data->deref() ) { |
422 | // qWarning("deleting"); | 426 | // qWarning("deleting"); |
423 | delete data; | 427 | delete data; |
424 | data= 0; | 428 | data= 0; |
425 | } | 429 | } |
426 | } | 430 | } |
427 | OTodo &OTodo::operator=(const OTodo &item ) | 431 | OTodo &OTodo::operator=(const OTodo &item ) |
428 | { | 432 | { |
429 | if ( this == &item ) return *this; | 433 | if ( this == &item ) return *this; |
430 | 434 | ||
431 | OPimRecord::operator=( item ); | 435 | OPimRecord::operator=( item ); |
432 | //qWarning("operator= ref "); | 436 | //qWarning("operator= ref "); |
433 | item.data->ref(); | 437 | item.data->ref(); |
434 | deref(); | 438 | deref(); |
435 | data = item.data; | 439 | data = item.data; |
436 | 440 | ||
437 | return *this; | 441 | return *this; |
438 | } | 442 | } |
439 | 443 | ||
440 | QMap<int, QString> OTodo::toMap() const { | 444 | QMap<int, QString> OTodo::toMap() const { |
441 | QMap<int, QString> map; | 445 | QMap<int, QString> map; |
442 | 446 | ||
443 | map.insert( Uid, QString::number( uid() ) ); | 447 | map.insert( Uid, QString::number( uid() ) ); |
444 | map.insert( Category, idsToString( categories() ) ); | 448 | map.insert( Category, idsToString( categories() ) ); |
445 | map.insert( HasDate, QString::number( data->hasDate ) ); | 449 | map.insert( HasDate, QString::number( data->hasDate ) ); |
446 | map.insert( Completed, QString::number( data->isCompleted ) ); | 450 | map.insert( Completed, QString::number( data->isCompleted ) ); |
447 | map.insert( Description, data->desc ); | 451 | map.insert( Description, data->desc ); |
448 | map.insert( Summary, data->sum ); | 452 | map.insert( Summary, data->sum ); |
449 | map.insert( Priority, QString::number( data->priority ) ); | 453 | map.insert( Priority, QString::number( data->priority ) ); |
450 | map.insert( DateDay, QString::number( data->date.day() ) ); | 454 | map.insert( DateDay, QString::number( data->date.day() ) ); |
451 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 455 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
452 | map.insert( DateYear, QString::number( data->date.year() ) ); | 456 | map.insert( DateYear, QString::number( data->date.year() ) ); |
453 | map.insert( Progress, QString::number( data->prog ) ); | 457 | map.insert( Progress, QString::number( data->prog ) ); |
454 | // map.insert( CrossReference, crossToString() ); | 458 | // map.insert( CrossReference, crossToString() ); |
455 | /* FIXME!!! map.insert( State, ); | 459 | /* FIXME!!! map.insert( State, ); |
456 | map.insert( Recurrence, ); | 460 | map.insert( Recurrence, ); |
457 | map.insert( Reminders, ); | 461 | map.insert( Reminders, ); |
458 | map. | 462 | map. |
459 | */ | 463 | */ |
460 | return map; | 464 | return map; |
461 | } | 465 | } |
462 | 466 | ||
463 | /** | 467 | /** |
464 | * change or modify looks at the ref count and either | 468 | * change or modify looks at the ref count and either |
465 | * creates a new QShared Object or it can modify it | 469 | * creates a new QShared Object or it can modify it |
466 | * right in place | 470 | * right in place |
467 | */ | 471 | */ |
468 | void OTodo::changeOrModify() { | 472 | void OTodo::changeOrModify() { |
469 | if ( data->count != 1 ) { | 473 | if ( data->count != 1 ) { |
470 | qWarning("changeOrModify"); | 474 | qWarning("changeOrModify"); |
471 | data->deref(); | 475 | data->deref(); |
472 | OTodoData* d2 = new OTodoData(); | 476 | OTodoData* d2 = new OTodoData(); |
473 | copy(data, d2 ); | 477 | copy(data, d2 ); |
474 | data = d2; | 478 | data = d2; |
475 | } | 479 | } |
476 | } | 480 | } |
477 | // WATCHOUT | 481 | // WATCHOUT |
478 | /* | 482 | /* |
479 | * if you add something to the Data struct | 483 | * if you add something to the Data struct |
480 | * be sure to copy it here | 484 | * be sure to copy it here |
481 | */ | 485 | */ |
482 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 486 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
483 | dest->date = src->date; | 487 | dest->date = src->date; |
484 | dest->isCompleted = src->isCompleted; | 488 | dest->isCompleted = src->isCompleted; |
485 | dest->hasDate = src->hasDate; | 489 | dest->hasDate = src->hasDate; |
486 | dest->priority = src->priority; | 490 | dest->priority = src->priority; |
487 | dest->desc = src->desc; | 491 | dest->desc = src->desc; |
488 | dest->sum = src->sum; | 492 | dest->sum = src->sum; |
489 | dest->extra = src->extra; | 493 | dest->extra = src->extra; |
490 | dest->prog = src->prog; | 494 | dest->prog = src->prog; |
491 | 495 | ||
492 | if (src->state ) | 496 | if (src->state ) |
493 | dest->state = new OPimState( *src->state ); | 497 | dest->state = new OPimState( *src->state ); |
494 | 498 | ||
495 | if (src->recur ) | 499 | if (src->recur ) |
496 | dest->recur = new ORecur( *src->recur ); | 500 | dest->recur = new ORecur( *src->recur ); |
497 | 501 | ||
498 | if (src->maintainer ) | 502 | if (src->maintainer ) |
499 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | 503 | dest->maintainer = new OPimMaintainer( *src->maintainer ) |
500 | ; | 504 | ; |
501 | dest->start = src->start; | 505 | dest->start = src->start; |
502 | dest->completed = src->completed; | 506 | dest->completed = src->completed; |
503 | 507 | ||
504 | if (src->notifiers ) | 508 | if (src->notifiers ) |
505 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | 509 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); |
506 | } | 510 | } |
507 | QString OTodo::type() const { | 511 | QString OTodo::type() const { |
508 | return QString::fromLatin1("OTodo"); | 512 | return QString::fromLatin1("OTodo"); |
509 | } | 513 | } |
510 | QString OTodo::recordField(int /*id*/ )const { | 514 | QString OTodo::recordField(int /*id*/ )const { |
511 | return QString::null; | 515 | return QString::null; |
512 | } | 516 | } |
513 | 517 | ||
514 | int OTodo::rtti(){ | 518 | int OTodo::rtti(){ |
515 | return OPimResolver::TodoList; | 519 | return OPimResolver::TodoList; |
516 | } | 520 | } |
diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h index f9a345a..6df98b9 100644 --- a/libopie2/opiepim/otodo.h +++ b/libopie2/opiepim/otodo.h | |||
@@ -1,294 +1,285 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_TODO_EVENT_H | 2 | #ifndef OPIE_TODO_EVENT_H |
3 | #define OPIE_TODO_EVENT_H | 3 | #define OPIE_TODO_EVENT_H |
4 | 4 | ||
5 | 5 | ||
6 | #include <qarray.h> | 6 | #include <qarray.h> |
7 | #include <qmap.h> | 7 | #include <qmap.h> |
8 | #include <qregexp.h> | 8 | #include <qregexp.h> |
9 | #include <qstringlist.h> | 9 | #include <qstringlist.h> |
10 | #include <qdatetime.h> | 10 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 11 | #include <qvaluelist.h> |
12 | 12 | ||
13 | #include <qpe/recordfields.h> | 13 | #include <qpe/recordfields.h> |
14 | #include <qpe/palmtopuidgen.h> | 14 | #include <qpe/palmtopuidgen.h> |
15 | 15 | ||
16 | #include <opie/opimrecord.h> | 16 | #include <opie/opimrecord.h> |
17 | 17 | ||
18 | 18 | ||
19 | class OPimState; | 19 | class OPimState; |
20 | class ORecur; | 20 | class ORecur; |
21 | class OPimMaintainer; | 21 | class OPimMaintainer; |
22 | class OPimNotifyManager; | 22 | class OPimNotifyManager; |
23 | class OTodo : public OPimRecord { | 23 | class OTodo : public OPimRecord { |
24 | public: | 24 | public: |
25 | typedef QValueList<OTodo> ValueList; | 25 | typedef QValueList<OTodo> ValueList; |
26 | enum RecordFields { | 26 | enum RecordFields { |
27 | Uid = Qtopia::UID_ID, | 27 | Uid = Qtopia::UID_ID, |
28 | Category = Qtopia::CATEGORY_ID, | 28 | Category = Qtopia::CATEGORY_ID, |
29 | HasDate, | 29 | HasDate, |
30 | Completed, | 30 | Completed, |
31 | Description, | 31 | Description, |
32 | Summary, | 32 | Summary, |
33 | Priority, | 33 | Priority, |
34 | DateDay, | 34 | DateDay, |
35 | DateMonth, | 35 | DateMonth, |
36 | DateYear, | 36 | DateYear, |
37 | Progress, | 37 | Progress, |
38 | CrossReference, | 38 | CrossReference, |
39 | State, | 39 | State, |
40 | Recurrence, | 40 | Recurrence, |
41 | Alarms, | 41 | Alarms, |
42 | Reminders, | 42 | Reminders, |
43 | Notifiers, | 43 | Notifiers, |
44 | Maintainer, | 44 | Maintainer, |
45 | StartDate, | 45 | StartDate, |
46 | CompletedDate | 46 | CompletedDate |
47 | }; | 47 | }; |
48 | public: | 48 | public: |
49 | // priorities from Very low to very high | 49 | // priorities from Very low to very high |
50 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; | 50 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; |
51 | 51 | ||
52 | /* Constructs a new ToDoEvent | 52 | /* Constructs a new ToDoEvent |
53 | @param completed Is the TodoEvent completed | 53 | @param completed Is the TodoEvent completed |
54 | @param priority What is the priority of this ToDoEvent | 54 | @param priority What is the priority of this ToDoEvent |
55 | @param category Which category does it belong( uid ) | 55 | @param category Which category does it belong( uid ) |
56 | @param summary A small summary of the todo | 56 | @param summary A small summary of the todo |
57 | @param description What is this ToDoEvent about | 57 | @param description What is this ToDoEvent about |
58 | @param hasDate Does this Event got a deadline | 58 | @param hasDate Does this Event got a deadline |
59 | @param date what is the deadline? | 59 | @param date what is the deadline? |
60 | @param uid what is the UUID of this Event | 60 | @param uid what is the UUID of this Event |
61 | **/ | 61 | **/ |
62 | OTodo( bool completed = false, int priority = Normal, | 62 | OTodo( bool completed = false, int priority = Normal, |
63 | const QStringList &category = QStringList(), | 63 | const QStringList &category = QStringList(), |
64 | const QString &summary = QString::null , | 64 | const QString &summary = QString::null , |
65 | const QString &description = QString::null, | 65 | const QString &description = QString::null, |
66 | ushort progress = 0, | 66 | ushort progress = 0, |
67 | bool hasDate = false, QDate date = QDate::currentDate(), | 67 | bool hasDate = false, QDate date = QDate::currentDate(), |
68 | int uid = 0 /*empty*/ ); | 68 | int uid = 0 /*empty*/ ); |
69 | 69 | ||
70 | OTodo( bool completed, int priority, | 70 | OTodo( bool completed, int priority, |
71 | const QArray<int>& category, | 71 | const QArray<int>& category, |
72 | const QString& summary = QString::null, | 72 | const QString& summary = QString::null, |
73 | const QString& description = QString::null, | 73 | const QString& description = QString::null, |
74 | ushort progress = 0, | 74 | ushort progress = 0, |
75 | bool hasDate = false, QDate date = QDate::currentDate(), | 75 | bool hasDate = false, QDate date = QDate::currentDate(), |
76 | int uid = 0 /* empty */ ); | 76 | int uid = 0 /* empty */ ); |
77 | 77 | ||
78 | /** Copy c'tor | 78 | /** Copy c'tor |
79 | * | 79 | * |
80 | */ | 80 | */ |
81 | OTodo(const OTodo & ); | 81 | OTodo(const OTodo & ); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | *destructor | 84 | *destructor |
85 | */ | 85 | */ |
86 | ~OTodo(); | 86 | ~OTodo(); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Is this event completed? | 89 | * Is this event completed? |
90 | */ | 90 | */ |
91 | bool isCompleted() const; | 91 | bool isCompleted() const; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Does this Event have a deadline | 94 | * Does this Event have a deadline |
95 | */ | 95 | */ |
96 | bool hasDueDate() const; | 96 | bool hasDueDate() const; |
97 | bool hasStartDate()const; | 97 | bool hasStartDate()const; |
98 | bool hasCompletedDate()const; | 98 | bool hasCompletedDate()const; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Does this Event has an alarm time ? | ||
102 | */ | ||
103 | bool hasAlarmDateTime() const; | ||
104 | |||
105 | /** | ||
106 | * What is the priority? | 101 | * What is the priority? |
107 | */ | 102 | */ |
108 | int priority()const ; | 103 | int priority()const ; |
109 | 104 | ||
110 | /** | 105 | /** |
111 | * progress as ushort 0, 20, 40, 60, 80 or 100% | 106 | * progress as ushort 0, 20, 40, 60, 80 or 100% |
112 | */ | 107 | */ |
113 | ushort progress() const; | 108 | ushort progress() const; |
114 | 109 | ||
115 | /** | 110 | /** |
116 | * The due Date | 111 | * The due Date |
117 | */ | 112 | */ |
118 | QDate dueDate()const; | 113 | QDate dueDate()const; |
119 | 114 | ||
120 | /** | 115 | /** |
121 | * When did it start? | 116 | * When did it start? |
122 | */ | 117 | */ |
123 | QDate startDate()const; | 118 | QDate startDate()const; |
124 | 119 | ||
125 | /** | 120 | /** |
126 | * When was it completed? | 121 | * When was it completed? |
127 | */ | 122 | */ |
128 | QDate completedDate()const; | 123 | QDate completedDate()const; |
129 | 124 | ||
130 | /** | 125 | /** |
131 | * does it have a state? | 126 | * does it have a state? |
132 | */ | 127 | */ |
133 | bool hasState()const; | 128 | bool hasState()const; |
134 | 129 | ||
135 | /** | 130 | /** |
136 | * What is the state of this OTodo? | 131 | * What is the state of this OTodo? |
137 | */ | 132 | */ |
138 | OPimState state()const; | 133 | OPimState state()const; |
139 | 134 | ||
140 | /** | 135 | /** |
141 | * has recurrence? | 136 | * has recurrence? |
142 | */ | 137 | */ |
143 | bool hasRecurrence()const; | 138 | bool hasRecurrence()const; |
144 | 139 | ||
145 | /** | 140 | /** |
146 | * the recurrance of this | 141 | * the recurrance of this |
147 | */ | 142 | */ |
148 | ORecur recurrence()const; | 143 | ORecur recurrence()const; |
149 | 144 | ||
150 | /** | 145 | /** |
151 | * does this OTodo have a maintainer? | 146 | * does this OTodo have a maintainer? |
152 | */ | 147 | */ |
153 | bool hasMaintainer()const; | 148 | bool hasMaintainer()const; |
154 | 149 | ||
155 | /** | 150 | /** |
156 | * the Maintainer of this OTodo | 151 | * the Maintainer of this OTodo |
157 | */ | 152 | */ |
158 | OPimMaintainer maintainer()const; | 153 | OPimMaintainer maintainer()const; |
159 | 154 | ||
160 | /** | 155 | /** |
161 | * The description of the todo | 156 | * The description of the todo |
162 | */ | 157 | */ |
163 | QString description()const; | 158 | QString description()const; |
164 | 159 | ||
165 | /** | 160 | /** |
166 | * A small summary of the todo | 161 | * A small summary of the todo |
167 | */ | 162 | */ |
168 | QString summary() const; | 163 | QString summary() const; |
169 | 164 | ||
170 | /** | 165 | /** |
171 | * @reimplemented | 166 | * @reimplemented |
172 | * Return this todoevent in a RichText formatted QString | 167 | * Return this todoevent in a RichText formatted QString |
173 | */ | 168 | */ |
174 | QString toRichText() const; | 169 | QString toRichText() const; |
175 | 170 | ||
176 | bool hasNotifiers()const; | 171 | bool hasNotifiers()const; |
177 | /* | 172 | /* |
178 | * FIXME check if the sharing is still fine!! -zecke | 173 | * FIXME check if the sharing is still fine!! -zecke |
179 | * ### CHECK If API is fine | 174 | * ### CHECK If API is fine |
180 | */ | 175 | */ |
181 | /** | 176 | /** |
182 | * return a reference to our notifiers... | 177 | * return a reference to our notifiers... |
183 | */ | 178 | */ |
184 | OPimNotifyManager ¬ifiers(); | 179 | OPimNotifyManager ¬ifiers(); |
185 | 180 | ||
186 | /** | 181 | /** |
187 | * | 182 | * |
188 | */ | 183 | */ |
189 | const OPimNotifyManager ¬ifiers()const; | 184 | const OPimNotifyManager ¬ifiers()const; |
190 | 185 | ||
191 | /** | 186 | /** |
192 | * reimplementations | 187 | * reimplementations |
193 | */ | 188 | */ |
194 | QString type()const; | 189 | QString type()const; |
195 | QString toShortText()const; | 190 | QString toShortText()const; |
196 | QString recordField(int id )const; | 191 | QString recordField(int id )const; |
197 | 192 | ||
198 | /** | 193 | /** |
199 | * toMap puts all data into the map. int relates | 194 | * toMap puts all data into the map. int relates |
200 | * to ToDoEvent RecordFields enum | 195 | * to ToDoEvent RecordFields enum |
201 | */ | 196 | */ |
202 | QMap<int, QString> toMap()const; | 197 | QMap<int, QString> toMap()const; |
203 | 198 | ||
204 | /** | 199 | /** |
205 | * Set if this Todo is completed | 200 | * Set if this Todo is completed |
206 | */ | 201 | */ |
207 | void setCompleted(bool completed ); | 202 | void setCompleted(bool completed ); |
208 | 203 | ||
209 | /** | 204 | /** |
210 | * set if this todo got an end data | 205 | * set if this todo got an end data |
211 | */ | 206 | */ |
212 | void setHasDueDate( bool hasDate ); | 207 | void setHasDueDate( bool hasDate ); |
213 | // FIXME we do not have these for start, completed | 208 | // FIXME we do not have these for start, completed |
214 | // cause we'll use the isNull() of QDate for figuring | 209 | // cause we'll use the isNull() of QDate for figuring |
215 | // out if it's has a date... | 210 | // out if it's has a date... |
216 | // decide what to do here? -zecke | 211 | // decide what to do here? -zecke |
217 | 212 | ||
218 | /** | 213 | /** |
219 | * Set the priority of the Todo | 214 | * Set the priority of the Todo |
220 | */ | 215 | */ |
221 | void setPriority(int priority ); | 216 | void setPriority(int priority ); |
222 | 217 | ||
223 | /** | 218 | /** |
224 | * Set the progress. | 219 | * Set the progress. |
225 | */ | 220 | */ |
226 | void setProgress( ushort progress ); | 221 | void setProgress( ushort progress ); |
227 | 222 | ||
228 | /** | 223 | /** |
229 | * set the end date | 224 | * set the end date |
230 | */ | 225 | */ |
231 | void setDueDate( const QDate& date ); | 226 | void setDueDate( const QDate& date ); |
232 | 227 | ||
233 | /** | 228 | /** |
234 | * set the start date | 229 | * set the start date |
235 | */ | 230 | */ |
236 | void setStartDate( const QDate& date ); | 231 | void setStartDate( const QDate& date ); |
237 | 232 | ||
238 | /** | 233 | /** |
239 | * set the completed date | 234 | * set the completed date |
240 | */ | 235 | */ |
241 | void setCompletedDate( const QDate& date ); | 236 | void setCompletedDate( const QDate& date ); |
242 | 237 | ||
243 | void setRecurrence( const ORecur& ); | 238 | void setRecurrence( const ORecur& ); |
244 | /** | ||
245 | * set the alarm time | ||
246 | */ | ||
247 | void setAlarmDateTime ( const QDateTime& alarm ); | ||
248 | 239 | ||
249 | void setDescription(const QString& ); | 240 | void setDescription(const QString& ); |
250 | void setSummary(const QString& ); | 241 | void setSummary(const QString& ); |
251 | 242 | ||
252 | /** | 243 | /** |
253 | * set the state of a Todo | 244 | * set the state of a Todo |
254 | * @param state State what the todo should take | 245 | * @param state State what the todo should take |
255 | */ | 246 | */ |
256 | void setState( const OPimState& state); | 247 | void setState( const OPimState& state); |
257 | 248 | ||
258 | /** | 249 | /** |
259 | * set the Maintainer Mode | 250 | * set the Maintainer Mode |
260 | */ | 251 | */ |
261 | void setMaintainer( const OPimMaintainer& ); | 252 | void setMaintainer( const OPimMaintainer& ); |
262 | 253 | ||
263 | bool isOverdue(); | 254 | bool isOverdue(); |
264 | 255 | ||
265 | 256 | ||
266 | virtual bool match( const QRegExp &r )const; | 257 | virtual bool match( const QRegExp &r )const; |
267 | 258 | ||
268 | bool operator<(const OTodo &toDoEvent )const; | 259 | bool operator<(const OTodo &toDoEvent )const; |
269 | bool operator<=(const OTodo &toDoEvent )const; | 260 | bool operator<=(const OTodo &toDoEvent )const; |
270 | bool operator!=(const OTodo &toDoEvent )const; | 261 | bool operator!=(const OTodo &toDoEvent )const; |
271 | bool operator>(const OTodo &toDoEvent )const; | 262 | bool operator>(const OTodo &toDoEvent )const; |
272 | bool operator>=(const OTodo &toDoEvent)const; | 263 | bool operator>=(const OTodo &toDoEvent)const; |
273 | bool operator==(const OTodo &toDoEvent )const; | 264 | bool operator==(const OTodo &toDoEvent )const; |
274 | OTodo &operator=(const OTodo &toDoEvent ); | 265 | OTodo &operator=(const OTodo &toDoEvent ); |
275 | 266 | ||
276 | static int rtti(); | 267 | static int rtti(); |
277 | 268 | ||
278 | private: | 269 | private: |
279 | class OTodoPrivate; | 270 | class OTodoPrivate; |
280 | struct OTodoData; | 271 | struct OTodoData; |
281 | 272 | ||
282 | void deref(); | 273 | void deref(); |
283 | inline void changeOrModify(); | 274 | inline void changeOrModify(); |
284 | void copy( OTodoData* src, OTodoData* dest ); | 275 | void copy( OTodoData* src, OTodoData* dest ); |
285 | OTodoPrivate *d; | 276 | OTodoPrivate *d; |
286 | OTodoData *data; | 277 | OTodoData *data; |
287 | 278 | ||
288 | }; | 279 | }; |
289 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { | 280 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { |
290 | return !(*this == toDoEvent); | 281 | return !(*this == toDoEvent); |
291 | } | 282 | } |
292 | 283 | ||
293 | 284 | ||
294 | #endif | 285 | #endif |
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp index 4044bc1..2739e26 100644 --- a/libopie2/opiepim/ui/opimmainwindow.cpp +++ b/libopie2/opiepim/ui/opimmainwindow.cpp | |||
@@ -1,138 +1,150 @@ | |||
1 | #include <qapplication.h> | 1 | #include <qapplication.h> |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | #include <qcopchannel_qws.h> | 3 | #include <qcopchannel_qws.h> |
4 | 4 | ||
5 | #include <qpe/sound.h> | 5 | #include <qpe/sound.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | #include <qpe/qpeapplication.h> | ||
7 | 8 | ||
8 | #include "opimresolver.h" | 9 | #include "opimresolver.h" |
9 | #include "opimmainwindow.h" | 10 | #include "opimmainwindow.h" |
10 | 11 | ||
11 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 12 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, |
12 | const char* name, WFlags flag ) | 13 | const char* name, WFlags flag ) |
13 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { | 14 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { |
14 | 15 | ||
15 | /* | 16 | /* |
16 | * let's generate our QCopChannel | 17 | * let's generate our QCopChannel |
17 | */ | 18 | */ |
18 | m_str = QString("QPE/"+m_service).local8Bit(); | 19 | m_str = QString("QPE/"+m_service).local8Bit(); |
19 | m_channel= new QCopChannel(m_str, this ); | 20 | m_channel= new QCopChannel(m_str, this ); |
20 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | 21 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), |
21 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 22 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
22 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), | 23 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), |
23 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 24 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
24 | 25 | ||
25 | /* connect flush and reload */ | 26 | /* connect flush and reload */ |
26 | connect(qApp, SIGNAL(flush() ), | 27 | connect(qApp, SIGNAL(flush() ), |
27 | this, SLOT(flush() ) ); | 28 | this, SLOT(flush() ) ); |
28 | connect(qApp, SIGNAL(reload() ), | 29 | connect(qApp, SIGNAL(reload() ), |
29 | this, SLOT(reload() ) ); | 30 | this, SLOT(reload() ) ); |
30 | } | 31 | } |
31 | OPimMainWindow::~OPimMainWindow() { | 32 | OPimMainWindow::~OPimMainWindow() { |
32 | delete m_channel; | 33 | delete m_channel; |
33 | } | 34 | } |
34 | QCopChannel* OPimMainWindow::channel() { | 35 | QCopChannel* OPimMainWindow::channel() { |
35 | return m_channel; | 36 | return m_channel; |
36 | } | 37 | } |
37 | void OPimMainWindow::doSetDocument( const QString& ) { | 38 | void OPimMainWindow::doSetDocument( const QString& ) { |
38 | 39 | ||
39 | } | 40 | } |
40 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 41 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
42 | bool needShow = false; | ||
41 | /* | 43 | /* |
42 | * create demands to create | 44 | * create demands to create |
43 | * a new record... | 45 | * a new record... |
44 | */ | 46 | */ |
45 | QDataStream stream(array, IO_ReadOnly); | 47 | QDataStream stream(array, IO_ReadOnly); |
46 | if ( cmd == "create()" ) { | 48 | if ( cmd == "create()" ) { |
49 | raise(); | ||
47 | int uid = create(); | 50 | int uid = create(); |
48 | QCopEnvelope e(m_str, "created(int)" ); | 51 | QCopEnvelope e(m_str, "created(int)" ); |
49 | e << uid; | 52 | e << uid; |
53 | needShow = true; | ||
50 | }else if ( cmd == "remove(int)" ) { | 54 | }else if ( cmd == "remove(int)" ) { |
51 | int uid; | 55 | int uid; |
52 | stream >> uid; | 56 | stream >> uid; |
53 | bool rem = remove( uid ); | 57 | bool rem = remove( uid ); |
54 | QCopEnvelope e(m_str, "removed(bool)" ); | 58 | QCopEnvelope e(m_str, "removed(bool)" ); |
55 | e << rem; | 59 | e << rem; |
60 | needShow = true; | ||
56 | }else if ( cmd == "beam(int)" ) { | 61 | }else if ( cmd == "beam(int)" ) { |
57 | int uid; | 62 | int uid; |
58 | stream >> uid; | 63 | stream >> uid; |
59 | beam( uid); | 64 | beam( uid); |
60 | }else if ( cmd == "show(int)" ) { | 65 | }else if ( cmd == "show(int)" ) { |
66 | raise(); | ||
61 | int uid; | 67 | int uid; |
62 | stream >> uid; | 68 | stream >> uid; |
63 | show( uid ); | 69 | show( uid ); |
70 | needShow = true; | ||
64 | }else if ( cmd == "edit(int)" ) { | 71 | }else if ( cmd == "edit(int)" ) { |
72 | raise(); | ||
65 | int uid; | 73 | int uid; |
66 | stream >> uid; | 74 | stream >> uid; |
67 | edit( uid ); | 75 | edit( uid ); |
68 | }else if ( cmd == "add(int,QByteArray)" ) { | 76 | }else if ( cmd == "add(int,QByteArray)" ) { |
69 | int rtti; | 77 | int rtti; |
70 | QByteArray array; | 78 | QByteArray array; |
71 | stream >> rtti; | 79 | stream >> rtti; |
72 | stream >> array; | 80 | stream >> array; |
73 | m_fallBack = record(rtti, array ); | 81 | m_fallBack = record(rtti, array ); |
74 | if (!m_fallBack) return; | 82 | if (!m_fallBack) return; |
75 | add( *m_fallBack ); | 83 | add( *m_fallBack ); |
76 | delete m_fallBack; | 84 | delete m_fallBack; |
77 | }else if ( cmd == "alarm(QDateTime,int)" ) { | 85 | }else if ( cmd == "alarm(QDateTime,int)" ) { |
86 | raise(); | ||
78 | QDateTime dt; int uid; | 87 | QDateTime dt; int uid; |
79 | stream >> dt; | 88 | stream >> dt; |
80 | stream >> uid; | 89 | stream >> uid; |
81 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); | 90 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); |
82 | QDateTime current = QDateTime::currentDateTime(); | 91 | QDateTime current = QDateTime::currentDateTime(); |
83 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) | 92 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) |
84 | return; | 93 | return; |
85 | doAlarm( dt, uid ); | 94 | doAlarm( dt, uid ); |
86 | 95 | needShow = true; | |
87 | } | 96 | } |
97 | |||
98 | if (needShow ) | ||
99 | QPEApplication::setKeepRunning(); | ||
88 | } | 100 | } |
89 | /* implement the url scripting here */ | 101 | /* implement the url scripting here */ |
90 | void OPimMainWindow::setDocument( const QString& str) { | 102 | void OPimMainWindow::setDocument( const QString& str) { |
91 | doSetDocument( str ); | 103 | doSetDocument( str ); |
92 | } | 104 | } |
93 | /* | 105 | /* |
94 | * we now try to get the array demarshalled | 106 | * we now try to get the array demarshalled |
95 | * check if the rtti matches this one | 107 | * check if the rtti matches this one |
96 | */ | 108 | */ |
97 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | 109 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { |
98 | if ( service() != rtti ) | 110 | if ( service() != rtti ) |
99 | return 0l; | 111 | return 0l; |
100 | 112 | ||
101 | OPimRecord* record = OPimResolver::self()->record( rtti ); | 113 | OPimRecord* record = OPimResolver::self()->record( rtti ); |
102 | QDataStream str(array, IO_ReadOnly ); | 114 | QDataStream str(array, IO_ReadOnly ); |
103 | if ( !record || !record->loadFromStream(str) ) { | 115 | if ( !record || !record->loadFromStream(str) ) { |
104 | delete record; | 116 | delete record; |
105 | record = 0l; | 117 | record = 0l; |
106 | } | 118 | } |
107 | 119 | ||
108 | return record; | 120 | return record; |
109 | } | 121 | } |
110 | /* | 122 | /* |
111 | * get the rtti for the service | 123 | * get the rtti for the service |
112 | */ | 124 | */ |
113 | int OPimMainWindow::service() { | 125 | int OPimMainWindow::service() { |
114 | if ( m_rtti == -1 ) | 126 | if ( m_rtti == -1 ) |
115 | m_rtti = OPimResolver::self()->serviceId( m_service ); | 127 | m_rtti = OPimResolver::self()->serviceId( m_service ); |
116 | 128 | ||
117 | return m_rtti; | 129 | return m_rtti; |
118 | } | 130 | } |
119 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { | 131 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { |
120 | 132 | ||
121 | } | 133 | } |
122 | void OPimMainWindow::startAlarm(int count ) { | 134 | void OPimMainWindow::startAlarm(int count ) { |
123 | m_alarmCount = count; | 135 | m_alarmCount = count; |
124 | m_playedCount = 0; | 136 | m_playedCount = 0; |
125 | Sound::soundAlarm(); | 137 | Sound::soundAlarm(); |
126 | m_timerId = startTimer( 5000 ); | 138 | m_timerId = startTimer( 5000 ); |
127 | } | 139 | } |
128 | void OPimMainWindow::killAlarm() { | 140 | void OPimMainWindow::killAlarm() { |
129 | killTimer( m_timerId ); | 141 | killTimer( m_timerId ); |
130 | } | 142 | } |
131 | void OPimMainWindow::timerEvent( QTimerEvent* e) { | 143 | void OPimMainWindow::timerEvent( QTimerEvent* e) { |
132 | if ( m_playedCount <m_alarmCount ) { | 144 | if ( m_playedCount <m_alarmCount ) { |
133 | m_playedCount++; | 145 | m_playedCount++; |
134 | Sound::soundAlarm(); | 146 | Sound::soundAlarm(); |
135 | }else { | 147 | }else { |
136 | killTimer( e->timerId() ); | 148 | killTimer( e->timerId() ); |
137 | } | 149 | } |
138 | } | 150 | } |