author | tux_mike <tux_mike> | 2002-04-17 20:46:18 (UTC) |
---|---|---|
committer | tux_mike <tux_mike> | 2002-04-17 20:46:18 (UTC) |
commit | 7b19e1d98d5acf01102ac057ec077fc036c034c6 (patch) (unidiff) | |
tree | a5ec8752ba8cbf9c5c037f1ec3552be544cc8b3f | |
parent | 106073977316103f057930daf45f3a083114d48d (diff) | |
download | opie-7b19e1d98d5acf01102ac057ec077fc036c034c6.zip opie-7b19e1d98d5acf01102ac057ec077fc036c034c6.tar.gz opie-7b19e1d98d5acf01102ac057ec077fc036c034c6.tar.bz2 |
Added a Letter Picker
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 86 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 27 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.h | 1 | ||||
-rw-r--r-- | core/pim/addressbook/picker.cpp | 7 |
4 files changed, 98 insertions, 23 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 759cb48..124ff6c 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -1,1124 +1,1200 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_CONTACT_MRE | 21 | #define QTOPIA_INTERNAL_CONTACT_MRE |
22 | 22 | ||
23 | #include <qpe/categoryselect.h> | 23 | #include <qpe/categoryselect.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | #include <qpe/stringutil.h> | 25 | #include <qpe/stringutil.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | 27 | ||
28 | #include <qasciidict.h> | 28 | #include <qasciidict.h> |
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | 31 | ||
32 | #include "abtable.h" | 32 | #include "abtable.h" |
33 | 33 | ||
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | #include <fcntl.h> | 35 | #include <fcntl.h> |
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | 38 | ||
39 | #include <ctype.h> //toupper() for key hack | 39 | #include <ctype.h> //toupper() for key hack |
40 | 40 | ||
41 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); | 41 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); |
42 | 42 | ||
43 | //### qtmail/addresslist.cpp hardcodes this filename as well | 43 | //### qtmail/addresslist.cpp hardcodes this filename as well |
44 | static QString journalFileName() | 44 | static QString journalFileName() |
45 | { | 45 | { |
46 | QString str = getenv("HOME"); | 46 | QString str = getenv("HOME"); |
47 | str +="/.abjournal"; | 47 | str +="/.abjournal"; |
48 | return str; | 48 | return str; |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | 52 | ||
53 | /*! | 53 | /*! |
54 | \class AbTableItem abtable.h | 54 | \class AbTableItem abtable.h |
55 | 55 | ||
56 | \brief QTableItem based class for showing a field of an entry | 56 | \brief QTableItem based class for showing a field of an entry |
57 | */ | 57 | */ |
58 | 58 | ||
59 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, | 59 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, |
60 | const QString &secondSortKey) | 60 | const QString &secondSortKey) |
61 | : QTableItem( t, et, s ) | 61 | : QTableItem( t, et, s ) |
62 | { | 62 | { |
63 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); | 63 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); |
64 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); | 64 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); |
65 | } | 65 | } |
66 | 66 | ||
67 | int AbTableItem::alignment() const | 67 | int AbTableItem::alignment() const |
68 | { | 68 | { |
69 | return AlignLeft|AlignVCenter; | 69 | return AlignLeft|AlignVCenter; |
70 | } | 70 | } |
71 | 71 | ||
72 | QString AbTableItem::key() const | 72 | QString AbTableItem::key() const |
73 | { | 73 | { |
74 | return sortKey; | 74 | return sortKey; |
75 | } | 75 | } |
76 | 76 | ||
77 | // A way to reset the item, without out doing a delete or a new... | 77 | // A way to reset the item, without out doing a delete or a new... |
78 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) | 78 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) |
79 | { | 79 | { |
80 | setText( txt ); | 80 | setText( txt ); |
81 | sortKey = Qtopia::buildSortKey( txt, secondKey ); | 81 | sortKey = Qtopia::buildSortKey( txt, secondKey ); |
82 | 82 | ||
83 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); | 83 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); |
84 | } | 84 | } |
85 | 85 | ||
86 | /*! | 86 | /*! |
87 | \class AbPickItem abtable.h | 87 | \class AbPickItem abtable.h |
88 | 88 | ||
89 | \brief QTableItem based class for showing slection of an entry | 89 | \brief QTableItem based class for showing slection of an entry |
90 | */ | 90 | */ |
91 | 91 | ||
92 | AbPickItem::AbPickItem( QTable *t ) : | 92 | AbPickItem::AbPickItem( QTable *t ) : |
93 | QTableItem(t, WhenCurrent, "?") | 93 | QTableItem(t, WhenCurrent, "?") |
94 | { | 94 | { |
95 | } | 95 | } |
96 | 96 | ||
97 | QWidget *AbPickItem::createEditor() const | 97 | QWidget *AbPickItem::createEditor() const |
98 | { | 98 | { |
99 | QComboBox* combo = new QComboBox( table()->viewport() ); | 99 | QComboBox* combo = new QComboBox( table()->viewport() ); |
100 | ( (AbPickItem*)this )->cb = combo; | 100 | ( (AbPickItem*)this )->cb = combo; |
101 | AbTable* t = static_cast<AbTable*>(table()); | 101 | AbTable* t = static_cast<AbTable*>(table()); |
102 | QStringList c = t->choiceNames(); | 102 | QStringList c = t->choiceNames(); |
103 | int cur = 0; | 103 | int cur = 0; |
104 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { | 104 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { |
105 | if ( *it == text() ) | 105 | if ( *it == text() ) |
106 | cur = combo->count(); | 106 | cur = combo->count(); |
107 | combo->insertItem(*it); | 107 | combo->insertItem(*it); |
108 | } | 108 | } |
109 | combo->setCurrentItem(cur); | 109 | combo->setCurrentItem(cur); |
110 | return combo; | 110 | return combo; |
111 | } | 111 | } |
112 | 112 | ||
113 | void AbPickItem::setContentFromEditor( QWidget *w ) | 113 | void AbPickItem::setContentFromEditor( QWidget *w ) |
114 | { | 114 | { |
115 | if ( w->inherits("QComboBox") ) | 115 | if ( w->inherits("QComboBox") ) |
116 | setText( ( (QComboBox*)w )->currentText() ); | 116 | setText( ( (QComboBox*)w )->currentText() ); |
117 | else | 117 | else |
118 | QTableItem::setContentFromEditor( w ); | 118 | QTableItem::setContentFromEditor( w ); |
119 | } | 119 | } |
120 | 120 | ||
121 | /*! | 121 | /*! |
122 | \class AbTable abtable.h | 122 | \class AbTable abtable.h |
123 | 123 | ||
124 | \brief QTable based class for showing a list of entries | 124 | \brief QTable based class for showing a list of entries |
125 | */ | 125 | */ |
126 | 126 | ||
127 | AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) | 127 | AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) |
128 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR | 128 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR |
129 | // : QTable( 0, 0, parent, name, TRUE ), | 129 | // : QTable( 0, 0, parent, name, TRUE ), |
130 | // #else | 130 | // #else |
131 | : QTable( parent, name ), | 131 | : QTable( parent, name ), |
132 | // #endif | 132 | // #endif |
133 | lastSortCol( -1 ), | 133 | lastSortCol( -1 ), |
134 | asc( TRUE ), | 134 | asc( TRUE ), |
135 | intFields( order ), | 135 | intFields( order ), |
136 | currFindRow( -2 ), | 136 | currFindRow( -2 ), |
137 | mCat( 0 ) | 137 | mCat( 0 ) |
138 | { | 138 | { |
139 | mCat.load( categoryFileName() ); | 139 | mCat.load( categoryFileName() ); |
140 | setSelectionMode( NoSelection ); | 140 | setSelectionMode( NoSelection ); |
141 | init(); | 141 | init(); |
142 | setSorting( TRUE ); | 142 | setSorting( TRUE ); |
143 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 143 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
144 | this, SLOT(itemClicked(int,int)) ); | 144 | this, SLOT(itemClicked(int,int)) ); |
145 | } | 145 | } |
146 | 146 | ||
147 | AbTable::~AbTable() | 147 | AbTable::~AbTable() |
148 | { | 148 | { |
149 | } | 149 | } |
150 | 150 | ||
151 | void AbTable::init() | 151 | void AbTable::init() |
152 | { | 152 | { |
153 | showChar = '\0'; | 153 | showChar = '\0'; |
154 | setNumRows( 0 ); | 154 | setNumRows( 0 ); |
155 | setNumCols( 2 ); | 155 | setNumCols( 2 ); |
156 | 156 | ||
157 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); | 157 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); |
158 | horizontalHeader()->setLabel( 1, tr( "Contact" )); | 158 | horizontalHeader()->setLabel( 1, tr( "Contact" )); |
159 | setLeftMargin( 0 ); | 159 | setLeftMargin( 0 ); |
160 | verticalHeader()->hide(); | 160 | verticalHeader()->hide(); |
161 | } | 161 | } |
162 | 162 | ||
163 | void AbTable::columnClicked( int col ) | 163 | void AbTable::columnClicked( int col ) |
164 | { | 164 | { |
165 | if ( !sorting() ) | 165 | if ( !sorting() ) |
166 | return; | 166 | return; |
167 | 167 | ||
168 | if ( lastSortCol == -1 ) | 168 | if ( lastSortCol == -1 ) |
169 | lastSortCol = col; | 169 | lastSortCol = col; |
170 | 170 | ||
171 | if ( col == lastSortCol ) { | 171 | if ( col == lastSortCol ) { |
172 | asc = !asc; | 172 | asc = !asc; |
173 | } else { | 173 | } else { |
174 | lastSortCol = col; | 174 | lastSortCol = col; |
175 | asc = TRUE; | 175 | asc = TRUE; |
176 | } | 176 | } |
177 | resort(); | 177 | resort(); |
178 | } | 178 | } |
179 | 179 | ||
180 | void AbTable::resort() | 180 | void AbTable::resort() |
181 | { | 181 | { |
182 | if ( sorting() ) { | 182 | if ( sorting() ) { |
183 | if ( lastSortCol == -1 ) | 183 | if ( lastSortCol == -1 ) |
184 | lastSortCol = 0; | 184 | lastSortCol = 0; |
185 | sortColumn( lastSortCol, asc, TRUE ); | 185 | sortColumn( lastSortCol, asc, TRUE ); |
186 | updateVisible(); | 186 | updateVisible(); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | Contact AbTable::currentEntry() | 190 | Contact AbTable::currentEntry() |
191 | { | 191 | { |
192 | Contact cnt; | 192 | Contact cnt; |
193 | AbTableItem *abItem; | 193 | AbTableItem *abItem; |
194 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 194 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
195 | if ( abItem ) { | 195 | if ( abItem ) { |
196 | cnt = contactList[abItem]; | 196 | cnt = contactList[abItem]; |
197 | } | 197 | } |
198 | return cnt; | 198 | return cnt; |
199 | } | 199 | } |
200 | 200 | ||
201 | void AbTable::replaceCurrentEntry( const Contact &newContact ) | 201 | void AbTable::replaceCurrentEntry( const Contact &newContact ) |
202 | { | 202 | { |
203 | int row = currentRow(); | 203 | int row = currentRow(); |
204 | updateJournal( newContact, Contact::ACTION_REPLACE, row ); | 204 | updateJournal( newContact, Contact::ACTION_REPLACE, row ); |
205 | updateVisible(); | 205 | updateVisible(); |
206 | 206 | ||
207 | journalFreeReplace( newContact, row ); | 207 | journalFreeReplace( newContact, row ); |
208 | } | 208 | } |
209 | 209 | ||
210 | void AbTable::deleteCurrentEntry() | 210 | void AbTable::deleteCurrentEntry() |
211 | { | 211 | { |
212 | int row = currentRow(); | 212 | int row = currentRow(); |
213 | AbTableItem *abItem; | 213 | AbTableItem *abItem; |
214 | abItem = static_cast<AbTableItem*>(item( row, 0 )); | 214 | abItem = static_cast<AbTableItem*>(item( row, 0 )); |
215 | Contact oldContact; | 215 | Contact oldContact; |
216 | oldContact = contactList[abItem]; | 216 | oldContact = contactList[abItem]; |
217 | updateJournal( oldContact, Contact::ACTION_REMOVE, row ); | 217 | updateJournal( oldContact, Contact::ACTION_REMOVE, row ); |
218 | 218 | ||
219 | // a little wasteful, but it ensure's there is only one place | 219 | // a little wasteful, but it ensure's there is only one place |
220 | // where we delete. | 220 | // where we delete. |
221 | journalFreeRemove( row ); | 221 | journalFreeRemove( row ); |
222 | updateVisible(); | 222 | updateVisible(); |
223 | 223 | ||
224 | if ( numRows() == 0 ) | 224 | if ( numRows() == 0 ) |
225 | emit empty( TRUE ); | 225 | emit empty( TRUE ); |
226 | } | 226 | } |
227 | 227 | ||
228 | void AbTable::clear() | 228 | void AbTable::clear() |
229 | { | 229 | { |
230 | contactList.clear(); | 230 | contactList.clear(); |
231 | for ( int r = 0; r < numRows(); ++r ) { | 231 | for ( int r = 0; r < numRows(); ++r ) { |
232 | for ( int c = 0; c < numCols(); ++c ) { | 232 | for ( int c = 0; c < numCols(); ++c ) { |
233 | if ( cellWidget( r, c ) ) | 233 | if ( cellWidget( r, c ) ) |
234 | clearCellWidget( r, c ); | 234 | clearCellWidget( r, c ); |
235 | clearCell( r, c ); | 235 | clearCell( r, c ); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | setNumRows( 0 ); | 238 | setNumRows( 0 ); |
239 | } | 239 | } |
240 | 240 | ||
241 | void AbTable::refresh() | 241 | void AbTable::refresh() |
242 | { | 242 | { |
243 | int rows = numRows(); | 243 | int rows = numRows(); |
244 | QString value; | 244 | QString value; |
245 | AbTableItem *abi; | 245 | AbTableItem *abi; |
246 | for ( int r = 0; r < rows; ++r ) { | 246 | for ( int r = 0; r < rows; ++r ) { |
247 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 247 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
248 | value = findContactContact( contactList[abi] ); | 248 | value = findContactContact( contactList[abi] ); |
249 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 249 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
250 | } | 250 | } |
251 | resort(); | 251 | resort(); |
252 | } | 252 | } |
253 | 253 | ||
254 | void AbTable::keyPressEvent( QKeyEvent *e ) | 254 | void AbTable::keyPressEvent( QKeyEvent *e ) |
255 | { | 255 | { |
256 | char key = toupper( e->ascii() ); | 256 | char key = toupper( e->ascii() ); |
257 | 257 | ||
258 | if ( key >= 'A' && key <= 'Z' ) | 258 | if ( key >= 'A' && key <= 'Z' ) |
259 | moveTo( key ); | 259 | moveTo( key ); |
260 | 260 | ||
261 | switch( e->key() ) { | 261 | switch( e->key() ) { |
262 | case Qt::Key_Space: | 262 | case Qt::Key_Space: |
263 | case Qt::Key_Return: | 263 | case Qt::Key_Return: |
264 | case Qt::Key_Enter: | 264 | case Qt::Key_Enter: |
265 | emit details(); | 265 | emit details(); |
266 | break; | 266 | break; |
267 | default: | 267 | default: |
268 | QTable::keyPressEvent( e ); | 268 | QTable::keyPressEvent( e ); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | void AbTable::moveTo( char c ) | 272 | void AbTable::moveTo( char c ) |
273 | { | 273 | { |
274 | 274 | ||
275 | int rows = numRows(); | 275 | int rows = numRows(); |
276 | QString value; | 276 | QString value; |
277 | AbTableItem *abi; | 277 | AbTableItem *abi; |
278 | int r; | 278 | int r; |
279 | if ( asc ) { | 279 | if ( asc ) { |
280 | r = 0; | 280 | r = 0; |
281 | while ( r < rows-1) { | 281 | while ( r < rows-1) { |
282 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 282 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
283 | QChar first = abi->key()[0]; | 283 | QChar first = abi->key()[0]; |
284 | //### is there a bug in QChar to char comparison??? | 284 | //### is there a bug in QChar to char comparison??? |
285 | if ( first.row() || first.cell() >= c ) | 285 | if ( first.row() || first.cell() >= c ) |
286 | break; | 286 | break; |
287 | r++; | 287 | r++; |
288 | } | 288 | } |
289 | } else { | 289 | } else { |
290 | //### should probably disable reverse sorting instead | 290 | //### should probably disable reverse sorting instead |
291 | r = rows - 1; | 291 | r = rows - 1; |
292 | while ( r > 0 ) { | 292 | while ( r > 0 ) { |
293 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 293 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
294 | QChar first = abi->key()[0]; | 294 | QChar first = abi->key()[0]; |
295 | //### is there a bug in QChar to char comparison??? | 295 | //### is there a bug in QChar to char comparison??? |
296 | if ( first.row() || first.cell() >= c ) | 296 | if ( first.row() || first.cell() >= c ) |
297 | break; | 297 | break; |
298 | r--; | 298 | r--; |
299 | } | 299 | } |
300 | } | 300 | } |
301 | setCurrentCell( r, currentColumn() ); | 301 | setCurrentCell( r, currentColumn() ); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | QString AbTable::findContactName( const Contact &entry ) | 305 | QString AbTable::findContactName( const Contact &entry ) |
306 | { | 306 | { |
307 | // We use the fileAs, then company, defaultEmail | 307 | // We use the fileAs, then company, defaultEmail |
308 | QString str; | 308 | QString str; |
309 | str = entry.fileAs(); | 309 | str = entry.fileAs(); |
310 | if ( str.isEmpty() ) { | 310 | if ( str.isEmpty() ) { |
311 | str = entry.company(); | 311 | str = entry.company(); |
312 | if ( str.isEmpty() ) { | 312 | if ( str.isEmpty() ) { |
313 | str = entry.defaultEmail(); | 313 | str = entry.defaultEmail(); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | return str; | 316 | return str; |
317 | } | 317 | } |
318 | 318 | ||
319 | QString AbTable::findContactContact( const Contact &entry ) | 319 | QString AbTable::findContactContact( const Contact &entry ) |
320 | { | 320 | { |
321 | QString value; | 321 | QString value; |
322 | value = ""; | 322 | value = ""; |
323 | for ( QValueList<int>::ConstIterator it = intFields->begin(); | 323 | for ( QValueList<int>::ConstIterator it = intFields->begin(); |
324 | it != intFields->end(); ++it ) { | 324 | it != intFields->end(); ++it ) { |
325 | switch ( *it ) { | 325 | switch ( *it ) { |
326 | default: | 326 | default: |
327 | break; | 327 | break; |
328 | case Qtopia::Title: | 328 | case Qtopia::Title: |
329 | value = entry.title(); | 329 | value = entry.title(); |
330 | break; | 330 | break; |
331 | case Qtopia::Suffix: | 331 | case Qtopia::Suffix: |
332 | value = entry.suffix(); | 332 | value = entry.suffix(); |
333 | break; | 333 | break; |
334 | case Qtopia::FileAs: | 334 | case Qtopia::FileAs: |
335 | value = entry.fileAs(); | 335 | value = entry.fileAs(); |
336 | break; | 336 | break; |
337 | case Qtopia::DefaultEmail: | 337 | case Qtopia::DefaultEmail: |
338 | value = entry.defaultEmail(); | 338 | value = entry.defaultEmail(); |
339 | case Qtopia::Emails: | 339 | case Qtopia::Emails: |
340 | value = entry.emails(); | 340 | value = entry.emails(); |
341 | break; | 341 | break; |
342 | case Qtopia::HomeStreet: | 342 | case Qtopia::HomeStreet: |
343 | value = entry.homeStreet(); | 343 | value = entry.homeStreet(); |
344 | break; | 344 | break; |
345 | case Qtopia::HomeCity: | 345 | case Qtopia::HomeCity: |
346 | value = entry.homeCity(); | 346 | value = entry.homeCity(); |
347 | break; | 347 | break; |
348 | case Qtopia::HomeState: | 348 | case Qtopia::HomeState: |
349 | value = entry.homeState(); | 349 | value = entry.homeState(); |
350 | break; | 350 | break; |
351 | case Qtopia::HomeZip: | 351 | case Qtopia::HomeZip: |
352 | value = entry.homeZip(); | 352 | value = entry.homeZip(); |
353 | break; | 353 | break; |
354 | case Qtopia::HomeCountry: | 354 | case Qtopia::HomeCountry: |
355 | value = entry.homeCountry(); | 355 | value = entry.homeCountry(); |
356 | break; | 356 | break; |
357 | case Qtopia::HomePhone: | 357 | case Qtopia::HomePhone: |
358 | value = entry.homePhone(); | 358 | value = entry.homePhone(); |
359 | break; | 359 | break; |
360 | case Qtopia::HomeFax: | 360 | case Qtopia::HomeFax: |
361 | value = entry.homeFax(); | 361 | value = entry.homeFax(); |
362 | break; | 362 | break; |
363 | case Qtopia::HomeMobile: | 363 | case Qtopia::HomeMobile: |
364 | value = entry.homeMobile(); | 364 | value = entry.homeMobile(); |
365 | break; | 365 | break; |
366 | case Qtopia::HomeWebPage: | 366 | case Qtopia::HomeWebPage: |
367 | value = entry.homeWebpage(); | 367 | value = entry.homeWebpage(); |
368 | break; | 368 | break; |
369 | case Qtopia::Company: | 369 | case Qtopia::Company: |
370 | value = entry.company(); | 370 | value = entry.company(); |
371 | break; | 371 | break; |
372 | case Qtopia::BusinessCity: | 372 | case Qtopia::BusinessCity: |
373 | value = entry.businessCity(); | 373 | value = entry.businessCity(); |
374 | break; | 374 | break; |
375 | case Qtopia::BusinessStreet: | 375 | case Qtopia::BusinessStreet: |
376 | value = entry.businessStreet(); | 376 | value = entry.businessStreet(); |
377 | break; | 377 | break; |
378 | case Qtopia::BusinessZip: | 378 | case Qtopia::BusinessZip: |
379 | value = entry.businessZip(); | 379 | value = entry.businessZip(); |
380 | break; | 380 | break; |
381 | case Qtopia::BusinessCountry: | 381 | case Qtopia::BusinessCountry: |
382 | value = entry.businessCountry(); | 382 | value = entry.businessCountry(); |
383 | break; | 383 | break; |
384 | case Qtopia::BusinessWebPage: | 384 | case Qtopia::BusinessWebPage: |
385 | value = entry.businessWebpage(); | 385 | value = entry.businessWebpage(); |
386 | break; | 386 | break; |
387 | case Qtopia::JobTitle: | 387 | case Qtopia::JobTitle: |
388 | value = entry.jobTitle(); | 388 | value = entry.jobTitle(); |
389 | break; | 389 | break; |
390 | case Qtopia::Department: | 390 | case Qtopia::Department: |
391 | value = entry.department(); | 391 | value = entry.department(); |
392 | break; | 392 | break; |
393 | case Qtopia::Office: | 393 | case Qtopia::Office: |
394 | value = entry.office(); | 394 | value = entry.office(); |
395 | break; | 395 | break; |
396 | case Qtopia::BusinessPhone: | 396 | case Qtopia::BusinessPhone: |
397 | value = entry.businessPhone(); | 397 | value = entry.businessPhone(); |
398 | break; | 398 | break; |
399 | case Qtopia::BusinessFax: | 399 | case Qtopia::BusinessFax: |
400 | value = entry.businessFax(); | 400 | value = entry.businessFax(); |
401 | break; | 401 | break; |
402 | case Qtopia::BusinessMobile: | 402 | case Qtopia::BusinessMobile: |
403 | value = entry.businessMobile(); | 403 | value = entry.businessMobile(); |
404 | break; | 404 | break; |
405 | case Qtopia::BusinessPager: | 405 | case Qtopia::BusinessPager: |
406 | value = entry.businessPager(); | 406 | value = entry.businessPager(); |
407 | break; | 407 | break; |
408 | case Qtopia::Profession: | 408 | case Qtopia::Profession: |
409 | value = entry.profession(); | 409 | value = entry.profession(); |
410 | break; | 410 | break; |
411 | case Qtopia::Assistant: | 411 | case Qtopia::Assistant: |
412 | value = entry.assistant(); | 412 | value = entry.assistant(); |
413 | break; | 413 | break; |
414 | case Qtopia::Manager: | 414 | case Qtopia::Manager: |
415 | value = entry.manager(); | 415 | value = entry.manager(); |
416 | break; | 416 | break; |
417 | case Qtopia::Spouse: | 417 | case Qtopia::Spouse: |
418 | value = entry.spouse(); | 418 | value = entry.spouse(); |
419 | break; | 419 | break; |
420 | case Qtopia::Gender: | 420 | case Qtopia::Gender: |
421 | value = entry.gender(); | 421 | value = entry.gender(); |
422 | break; | 422 | break; |
423 | case Qtopia::Birthday: | 423 | case Qtopia::Birthday: |
424 | value = entry.birthday(); | 424 | value = entry.birthday(); |
425 | break; | 425 | break; |
426 | case Qtopia::Anniversary: | 426 | case Qtopia::Anniversary: |
427 | value = entry.anniversary(); | 427 | value = entry.anniversary(); |
428 | break; | 428 | break; |
429 | case Qtopia::Nickname: | 429 | case Qtopia::Nickname: |
430 | value = entry.nickname(); | 430 | value = entry.nickname(); |
431 | break; | 431 | break; |
432 | case Qtopia::Children: | 432 | case Qtopia::Children: |
433 | value = entry.children(); | 433 | value = entry.children(); |
434 | break; | 434 | break; |
435 | case Qtopia::Notes: | 435 | case Qtopia::Notes: |
436 | value = entry.notes(); | 436 | value = entry.notes(); |
437 | break; | 437 | break; |
438 | } | 438 | } |
439 | if ( !value.isEmpty() ) | 439 | if ( !value.isEmpty() ) |
440 | break; | 440 | break; |
441 | } | 441 | } |
442 | return value; | 442 | return value; |
443 | } | 443 | } |
444 | 444 | ||
445 | void AbTable::addEntry( const Contact &newCnt ) | 445 | void AbTable::addEntry( const Contact &newCnt ) |
446 | { | 446 | { |
447 | int row = numRows(); | 447 | int row = numRows(); |
448 | setNumRows( row + 1 ); | 448 | setNumRows( row + 1 ); |
449 | updateJournal( newCnt, Contact::ACTION_ADD ); | 449 | updateJournal( newCnt, Contact::ACTION_ADD ); |
450 | insertIntoTable( newCnt, row ); | 450 | insertIntoTable( newCnt, row ); |
451 | setCurrentCell( row, 0 ); | 451 | setCurrentCell( row, 0 ); |
452 | updateVisible(); | 452 | updateVisible(); |
453 | } | 453 | } |
454 | 454 | ||
455 | void AbTable::resizeRows( int size ) { | 455 | void AbTable::resizeRows( int size ) { |
456 | /* | 456 | /* |
457 | if (numRows()) { | 457 | if (numRows()) { |
458 | for (int i = 0; i < numRows(); i++) { | 458 | for (int i = 0; i < numRows(); i++) { |
459 | setRowHeight( i, size ); | 459 | setRowHeight( i, size ); |
460 | } | 460 | } |
461 | }*/ | 461 | }*/ |
462 | updateVisible(); | 462 | updateVisible(); |
463 | } | 463 | } |
464 | 464 | ||
465 | void AbTable::updateJournal( const Contact &cnt, | 465 | void AbTable::updateJournal( const Contact &cnt, |
466 | Contact::journal_action action, int row ) | 466 | Contact::journal_action action, int row ) |
467 | { | 467 | { |
468 | QFile f( journalFileName() ); | 468 | QFile f( journalFileName() ); |
469 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 469 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
470 | return; | 470 | return; |
471 | QString buf; | 471 | QString buf; |
472 | QCString str; | 472 | QCString str; |
473 | buf = "<Contact "; | 473 | buf = "<Contact "; |
474 | cnt.save( buf ); | 474 | cnt.save( buf ); |
475 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 475 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
476 | if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) | 476 | if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) |
477 | buf += " actionrow=\"" + QString::number(row) + "\" "; | 477 | buf += " actionrow=\"" + QString::number(row) + "\" "; |
478 | buf += "/>\n"; | 478 | buf += "/>\n"; |
479 | QCString cstr = buf.utf8(); | 479 | QCString cstr = buf.utf8(); |
480 | f.writeBlock( cstr.data(), cstr.length() ); | 480 | f.writeBlock( cstr.data(), cstr.length() ); |
481 | QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); | 481 | QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); |
482 | } | 482 | } |
483 | 483 | ||
484 | bool AbTable::save( const QString &fn ) | 484 | bool AbTable::save( const QString &fn ) |
485 | { | 485 | { |
486 | // QTime t; | 486 | // QTime t; |
487 | // t.start(); | 487 | // t.start(); |
488 | 488 | ||
489 | QString strNewFile = fn + ".new"; | 489 | QString strNewFile = fn + ".new"; |
490 | QFile f( strNewFile ); | 490 | QFile f( strNewFile ); |
491 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 491 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
492 | return false; | 492 | return false; |
493 | 493 | ||
494 | int total_written; | 494 | int total_written; |
495 | QString out; | 495 | QString out; |
496 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 496 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
497 | " <Groups>\n" | 497 | " <Groups>\n" |
498 | " </Groups>\n" | 498 | " </Groups>\n" |
499 | " <Contacts>\n"; | 499 | " <Contacts>\n"; |
500 | QMapIterator<AbTableItem*, Contact> it; | 500 | QMapIterator<AbTableItem*, Contact> it; |
501 | for ( it = contactList.begin(); it != contactList.end(); ++it ) { | 501 | for ( it = contactList.begin(); it != contactList.end(); ++it ) { |
502 | out += "<Contact "; | 502 | out += "<Contact "; |
503 | it.data().save( out ); | 503 | it.data().save( out ); |
504 | out += "/>\n"; | 504 | out += "/>\n"; |
505 | QCString cstr = out.utf8(); | 505 | QCString cstr = out.utf8(); |
506 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 506 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
507 | if ( total_written != int(cstr.length()) ) { | 507 | if ( total_written != int(cstr.length()) ) { |
508 | f.close(); | 508 | f.close(); |
509 | QFile::remove( strNewFile ); | 509 | QFile::remove( strNewFile ); |
510 | return false; | 510 | return false; |
511 | } | 511 | } |
512 | out = ""; | 512 | out = ""; |
513 | } | 513 | } |
514 | out += " </Contacts>\n</AddressBook>\n"; | 514 | out += " </Contacts>\n</AddressBook>\n"; |
515 | 515 | ||
516 | QCString cstr = out.utf8(); | 516 | QCString cstr = out.utf8(); |
517 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 517 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
518 | if ( total_written != int(cstr.length()) ) { | 518 | if ( total_written != int(cstr.length()) ) { |
519 | f.close(); | 519 | f.close(); |
520 | QFile::remove( strNewFile ); | 520 | QFile::remove( strNewFile ); |
521 | return false; | 521 | return false; |
522 | } | 522 | } |
523 | f.close(); | 523 | f.close(); |
524 | 524 | ||
525 | // qDebug("saving: %d", t.elapsed() ); | 525 | // qDebug("saving: %d", t.elapsed() ); |
526 | 526 | ||
527 | // move the file over, I'm just going to use the system call | 527 | // move the file over, I'm just going to use the system call |
528 | // because, I don't feel like using QDir. | 528 | // because, I don't feel like using QDir. |
529 | if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { | 529 | if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { |
530 | qWarning( "problem renaming file %s to %s, errno: %d", | 530 | qWarning( "problem renaming file %s to %s, errno: %d", |
531 | strNewFile.latin1(), fn.latin1(), errno ); | 531 | strNewFile.latin1(), fn.latin1(), errno ); |
532 | // remove the tmp file... | 532 | // remove the tmp file... |
533 | QFile::remove( strNewFile ); | 533 | QFile::remove( strNewFile ); |
534 | } | 534 | } |
535 | // remove the journal... | 535 | // remove the journal... |
536 | QFile::remove( journalFileName() ); | 536 | QFile::remove( journalFileName() ); |
537 | return true; | 537 | return true; |
538 | } | 538 | } |
539 | 539 | ||
540 | void AbTable::load( const QString &fn ) | 540 | void AbTable::load( const QString &fn ) |
541 | { | 541 | { |
542 | setSorting( false ); | 542 | setSorting( false ); |
543 | loadFile( fn, false ); | 543 | loadFile( fn, false ); |
544 | // merge in the journal | 544 | // merge in the journal |
545 | if ( QFile::exists( journalFileName() ) ) { | 545 | if ( QFile::exists( journalFileName() ) ) { |
546 | loadFile( journalFileName(), true ); | 546 | loadFile( journalFileName(), true ); |
547 | save( fn ); | 547 | save( fn ); |
548 | } | 548 | } |
549 | setSorting( true ); | 549 | setSorting( true ); |
550 | resort(); | 550 | resort(); |
551 | } | 551 | } |
552 | 552 | ||
553 | void AbTable::loadFile( const QString &strFile, bool journalFile ) | 553 | void AbTable::loadFile( const QString &strFile, bool journalFile ) |
554 | { | 554 | { |
555 | // QTime t; | 555 | // QTime t; |
556 | // t.start(); | 556 | // t.start(); |
557 | QFile f( strFile ); | 557 | QFile f( strFile ); |
558 | if ( !f.open(IO_ReadOnly) ) | 558 | if ( !f.open(IO_ReadOnly) ) |
559 | return; | 559 | return; |
560 | QList<Contact> list; | 560 | QList<Contact> list; |
561 | list.setAutoDelete( TRUE ); | 561 | list.setAutoDelete( TRUE ); |
562 | QByteArray ba = f.readAll(); | 562 | QByteArray ba = f.readAll(); |
563 | f.close(); | 563 | f.close(); |
564 | char *uc = ba.data();//(QChar *)data.unicode(); | 564 | char *uc = ba.data();//(QChar *)data.unicode(); |
565 | int len = ba.size();//data.length(); | 565 | int len = ba.size();//data.length(); |
566 | bool foundAction = false; | 566 | bool foundAction = false; |
567 | Contact::journal_action action; | 567 | Contact::journal_action action; |
568 | bool foundKey = false; | 568 | bool foundKey = false; |
569 | int journalKey = 0; | 569 | int journalKey = 0; |
570 | 570 | ||
571 | const int JOURNALACTION = Qtopia::Notes + 1; | 571 | const int JOURNALACTION = Qtopia::Notes + 1; |
572 | const int JOURNALROW = JOURNALACTION + 1; | 572 | const int JOURNALROW = JOURNALACTION + 1; |
573 | 573 | ||
574 | // ********************************** | 574 | // ********************************** |
575 | // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! | 575 | // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! |
576 | // ********************************** | 576 | // ********************************** |
577 | QAsciiDict<int> dict( 47 ); | 577 | QAsciiDict<int> dict( 47 ); |
578 | dict.setAutoDelete( TRUE ); | 578 | dict.setAutoDelete( TRUE ); |
579 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 579 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
580 | dict.insert( "Title", new int(Qtopia::Title) ); | 580 | dict.insert( "Title", new int(Qtopia::Title) ); |
581 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 581 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
582 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 582 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
583 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 583 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
584 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 584 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
585 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 585 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
586 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 586 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
587 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 587 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
588 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 588 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
589 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 589 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
590 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 590 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
591 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 591 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
592 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 592 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
593 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 593 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
594 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 594 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
595 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 595 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
596 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 596 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
597 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 597 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
598 | dict.insert( "Company", new int(Qtopia::Company) ); | 598 | dict.insert( "Company", new int(Qtopia::Company) ); |
599 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 599 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
600 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 600 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
601 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 601 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
602 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 602 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
603 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 603 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
604 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 604 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
605 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 605 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
606 | dict.insert( "Department", new int(Qtopia::Department) ); | 606 | dict.insert( "Department", new int(Qtopia::Department) ); |
607 | dict.insert( "Office", new int(Qtopia::Office) ); | 607 | dict.insert( "Office", new int(Qtopia::Office) ); |
608 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 608 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
609 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 609 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
610 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 610 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
611 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 611 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
612 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 612 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
613 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 613 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
614 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 614 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
615 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 615 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
616 | dict.insert( "Children", new int(Qtopia::Children) ); | 616 | dict.insert( "Children", new int(Qtopia::Children) ); |
617 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 617 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
618 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 618 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
619 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 619 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
620 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 620 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
621 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 621 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
622 | dict.insert( "action", new int(JOURNALACTION) ); | 622 | dict.insert( "action", new int(JOURNALACTION) ); |
623 | dict.insert( "actionrow", new int(JOURNALROW) ); | 623 | dict.insert( "actionrow", new int(JOURNALROW) ); |
624 | 624 | ||
625 | int i = 0; | 625 | int i = 0; |
626 | int num = 0; | 626 | int num = 0; |
627 | char *point; | 627 | char *point; |
628 | while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { | 628 | while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { |
629 | i = point - uc; | 629 | i = point - uc; |
630 | // if we are reading the standard file, we just need to | 630 | // if we are reading the standard file, we just need to |
631 | // insert info, so just say we'll do an insert... | 631 | // insert info, so just say we'll do an insert... |
632 | action = Contact::ACTION_ADD; | 632 | action = Contact::ACTION_ADD; |
633 | // new Contact | 633 | // new Contact |
634 | Contact *cnt = new Contact; | 634 | Contact *cnt = new Contact; |
635 | i += 9; | 635 | i += 9; |
636 | while ( 1 ) { | 636 | while ( 1 ) { |
637 | while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) | 637 | while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) |
638 | i++; | 638 | i++; |
639 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) | 639 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) |
640 | break; | 640 | break; |
641 | // we have another attribute read it. | 641 | // we have another attribute read it. |
642 | int j = i; | 642 | int j = i; |
643 | while ( j < len && uc[j] != '=' ) | 643 | while ( j < len && uc[j] != '=' ) |
644 | j++; | 644 | j++; |
645 | char *attr = uc+i; | 645 | char *attr = uc+i; |
646 | uc[j] = '\0'; | 646 | uc[j] = '\0'; |
647 | //qDebug("attr=%s", attr.latin1() ); | 647 | //qDebug("attr=%s", attr.latin1() ); |
648 | i = ++j; // skip = | 648 | i = ++j; // skip = |
649 | while ( i < len && uc[i] != '"' ) | 649 | while ( i < len && uc[i] != '"' ) |
650 | i++; | 650 | i++; |
651 | j = ++i; | 651 | j = ++i; |
652 | bool haveEnt = FALSE; | 652 | bool haveEnt = FALSE; |
653 | bool haveUtf = FALSE; | 653 | bool haveUtf = FALSE; |
654 | while ( j < len && uc[j] != '"' ) { | 654 | while ( j < len && uc[j] != '"' ) { |
655 | if ( uc[j] == '&' ) | 655 | if ( uc[j] == '&' ) |
656 | haveEnt = TRUE; | 656 | haveEnt = TRUE; |
657 | if ( ((unsigned char)uc[j]) > 0x7f ) | 657 | if ( ((unsigned char)uc[j]) > 0x7f ) |
658 | haveUtf = TRUE; | 658 | haveUtf = TRUE; |
659 | j++; | 659 | j++; |
660 | } | 660 | } |
661 | 661 | ||
662 | if ( j == i ) { | 662 | if ( j == i ) { |
663 | // empty value | 663 | // empty value |
664 | i = j + 1; | 664 | i = j + 1; |
665 | continue; | 665 | continue; |
666 | } | 666 | } |
667 | 667 | ||
668 | QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) | 668 | QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) |
669 | : QString::fromLatin1( uc+i, j-i ); | 669 | : QString::fromLatin1( uc+i, j-i ); |
670 | if ( haveEnt ) | 670 | if ( haveEnt ) |
671 | value = Qtopia::plainString( value ); | 671 | value = Qtopia::plainString( value ); |
672 | i = j + 1; | 672 | i = j + 1; |
673 | 673 | ||
674 | int *find = dict[ attr ]; | 674 | int *find = dict[ attr ]; |
675 | if ( !find ) { | 675 | if ( !find ) { |
676 | cnt->setCustomField(attr, value); | 676 | cnt->setCustomField(attr, value); |
677 | continue; | 677 | continue; |
678 | } | 678 | } |
679 | #if 1 | 679 | #if 1 |
680 | switch( *find ) { | 680 | switch( *find ) { |
681 | case Qtopia::AddressUid: | 681 | case Qtopia::AddressUid: |
682 | cnt->setUid( value.toInt() ); | 682 | cnt->setUid( value.toInt() ); |
683 | break; | 683 | break; |
684 | case Qtopia::AddressCategory: | 684 | case Qtopia::AddressCategory: |
685 | cnt->setCategories( Qtopia::Record::idsFromString( value )); | 685 | cnt->setCategories( Qtopia::Record::idsFromString( value )); |
686 | break; | 686 | break; |
687 | case JOURNALACTION: | 687 | case JOURNALACTION: |
688 | action = Contact::journal_action(value.toInt()); | 688 | action = Contact::journal_action(value.toInt()); |
689 | break; | 689 | break; |
690 | case JOURNALROW: | 690 | case JOURNALROW: |
691 | journalKey = value.toInt(); | 691 | journalKey = value.toInt(); |
692 | break; | 692 | break; |
693 | 693 | ||
694 | default: | 694 | default: |
695 | cnt->insert( *find, value ); | 695 | cnt->insert( *find, value ); |
696 | break; | 696 | break; |
697 | } | 697 | } |
698 | #endif | 698 | #endif |
699 | } | 699 | } |
700 | 700 | ||
701 | // sadly we can't delay adding of items from the journal to get | 701 | // sadly we can't delay adding of items from the journal to get |
702 | // the proper effect, but then, the journal should _never_ be | 702 | // the proper effect, but then, the journal should _never_ be |
703 | // that huge, and recovering from a crash is not necessarily | 703 | // that huge, and recovering from a crash is not necessarily |
704 | // a *fast* thing. | 704 | // a *fast* thing. |
705 | switch ( action ) { | 705 | switch ( action ) { |
706 | case Contact::ACTION_ADD: | 706 | case Contact::ACTION_ADD: |
707 | if ( journalFile ) { | 707 | if ( journalFile ) { |
708 | int myrows = numRows(); | 708 | int myrows = numRows(); |
709 | setNumRows( myrows + 1 ); | 709 | setNumRows( myrows + 1 ); |
710 | insertIntoTable( *cnt, myrows ); | 710 | insertIntoTable( *cnt, myrows ); |
711 | delete cnt; | 711 | delete cnt; |
712 | } | 712 | } |
713 | else | 713 | else |
714 | list.append( cnt ); | 714 | list.append( cnt ); |
715 | break; | 715 | break; |
716 | case Contact::ACTION_REMOVE: | 716 | case Contact::ACTION_REMOVE: |
717 | // yup, we don't use the entry to remove the object... | 717 | // yup, we don't use the entry to remove the object... |
718 | journalFreeRemove( journalKey ); | 718 | journalFreeRemove( journalKey ); |
719 | delete cnt; | 719 | delete cnt; |
720 | break; | 720 | break; |
721 | case Contact::ACTION_REPLACE: | 721 | case Contact::ACTION_REPLACE: |
722 | journalFreeReplace( *cnt, journalKey ); | 722 | journalFreeReplace( *cnt, journalKey ); |
723 | delete cnt; | 723 | delete cnt; |
724 | break; | 724 | break; |
725 | default: | 725 | default: |
726 | break; | 726 | break; |
727 | } | 727 | } |
728 | num++; | 728 | num++; |
729 | foundAction = false; | 729 | foundAction = false; |
730 | foundKey = false; | 730 | foundKey = false; |
731 | // if ( num % 100 == 0 ) { | 731 | // if ( num % 100 == 0 ) { |
732 | // qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); | 732 | // qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); |
733 | // } | 733 | // } |
734 | } | 734 | } |
735 | if ( list.count() > 0 ) { | 735 | if ( list.count() > 0 ) { |
736 | internalAddEntries( list ); | 736 | internalAddEntries( list ); |
737 | } | 737 | } |
738 | // qDebug("done loading %d, t=%d", num, t.elapsed() ); | 738 | // qDebug("done loading %d, t=%d", num, t.elapsed() ); |
739 | 739 | ||
740 | } | 740 | } |
741 | 741 | ||
742 | void AbTable::realignTable( int row ) | 742 | void AbTable::realignTable( int row ) |
743 | { | 743 | { |
744 | QTableItem *ti1, | 744 | QTableItem *ti1, |
745 | *ti2; | 745 | *ti2; |
746 | int totalRows = numRows(); | 746 | int totalRows = numRows(); |
747 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | 747 | for ( int curr = row; curr < totalRows - 1; curr++ ) { |
748 | // the same info from the todo list still applies, but I | 748 | // the same info from the todo list still applies, but I |
749 | // don't think it is _too_ bad. | 749 | // don't think it is _too_ bad. |
750 | ti1 = item( curr + 1, 0 ); | 750 | ti1 = item( curr + 1, 0 ); |
751 | ti2 = item( curr + 1, 1 ); | 751 | ti2 = item( curr + 1, 1 ); |
752 | takeItem( ti1 ); | 752 | takeItem( ti1 ); |
753 | takeItem( ti2 ); | 753 | takeItem( ti2 ); |
754 | setItem( curr, 0, ti1 ); | 754 | setItem( curr, 0, ti1 ); |
755 | setItem( curr, 1, ti2 ); | 755 | setItem( curr, 1, ti2 ); |
756 | } | 756 | } |
757 | setNumRows( totalRows - 1 ); | 757 | setNumRows( totalRows - 1 ); |
758 | resort(); | 758 | resort(); |
759 | } | 759 | } |
760 | 760 | ||
761 | void AbTable::insertIntoTable( const Contact &cnt, int row ) | 761 | void AbTable::insertIntoTable( const Contact &cnt, int row ) |
762 | { | 762 | { |
763 | QString strName, | 763 | QString strName, |
764 | strContact; | 764 | strContact; |
765 | 765 | ||
766 | strName = findContactName( cnt ); | 766 | strName = findContactName( cnt ); |
767 | strContact = findContactContact( cnt ); | 767 | strContact = findContactContact( cnt ); |
768 | 768 | ||
769 | AbTableItem *ati; | 769 | AbTableItem *ati; |
770 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 770 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
771 | contactList.insert( ati, cnt ); | 771 | contactList.insert( ati, cnt ); |
772 | setItem( row, 0, ati ); | 772 | setItem( row, 0, ati ); |
773 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | 773 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); |
774 | setItem( row, 1, ati ); | 774 | setItem( row, 1, ati ); |
775 | 775 | ||
776 | //### cannot do this; table only has two columns at this point | 776 | //### cannot do this; table only has two columns at this point |
777 | // setItem( row, 2, new AbPickItem( this ) ); | 777 | // setItem( row, 2, new AbPickItem( this ) ); |
778 | 778 | ||
779 | // resort at some point? | 779 | // resort at some point? |
780 | } | 780 | } |
781 | 781 | ||
782 | void AbTable::internalAddEntries( QList<Contact> &list ) | 782 | void AbTable::internalAddEntries( QList<Contact> &list ) |
783 | { | 783 | { |
784 | setUpdatesEnabled( FALSE ); | 784 | setUpdatesEnabled( FALSE ); |
785 | setNumRows( list.count() ); | 785 | setNumRows( list.count() ); |
786 | int row = 0; | 786 | int row = 0; |
787 | Contact *it; | 787 | Contact *it; |
788 | for ( it = list.first(); it; it = list.next() ) | 788 | for ( it = list.first(); it; it = list.next() ) |
789 | insertIntoTable( *it, row++ ); | 789 | insertIntoTable( *it, row++ ); |
790 | resort(); | 790 | resort(); |
791 | setUpdatesEnabled( TRUE ); | 791 | setUpdatesEnabled( TRUE ); |
792 | } | 792 | } |
793 | 793 | ||
794 | 794 | ||
795 | void AbTable::journalFreeReplace( const Contact &cnt, int row ) | 795 | void AbTable::journalFreeReplace( const Contact &cnt, int row ) |
796 | { | 796 | { |
797 | QString strName, | 797 | QString strName, |
798 | strContact; | 798 | strContact; |
799 | AbTableItem *ati; | 799 | AbTableItem *ati; |
800 | 800 | ||
801 | strName = findContactName( cnt ); | 801 | strName = findContactName( cnt ); |
802 | strContact = findContactContact( cnt ); | 802 | strContact = findContactContact( cnt ); |
803 | ati = static_cast<AbTableItem*>(item(row, 0)); | 803 | ati = static_cast<AbTableItem*>(item(row, 0)); |
804 | contactList.remove( ati ); | 804 | contactList.remove( ati ); |
805 | ati->setItem( strName, strContact ); | 805 | ati->setItem( strName, strContact ); |
806 | contactList.insert( ati, cnt ); | 806 | contactList.insert( ati, cnt ); |
807 | 807 | ||
808 | ati = static_cast<AbTableItem*>(item(row, 1)); | 808 | ati = static_cast<AbTableItem*>(item(row, 1)); |
809 | ati->setItem( strContact, strName ); | 809 | ati->setItem( strContact, strName ); |
810 | } | 810 | } |
811 | 811 | ||
812 | void AbTable::journalFreeRemove( int row ) | 812 | void AbTable::journalFreeRemove( int row ) |
813 | { | 813 | { |
814 | AbTableItem *ati; | 814 | AbTableItem *ati; |
815 | ati = static_cast<AbTableItem*>(item(row, 0)); | 815 | ati = static_cast<AbTableItem*>(item(row, 0)); |
816 | if ( !ati ) | 816 | if ( !ati ) |
817 | return; | 817 | return; |
818 | contactList.remove( ati ); | 818 | contactList.remove( ati ); |
819 | realignTable( row ); | 819 | realignTable( row ); |
820 | } | 820 | } |
821 | 821 | ||
822 | #if QT_VERSION <= 230 | 822 | #if QT_VERSION <= 230 |
823 | #ifndef SINGLE_APP | 823 | #ifndef SINGLE_APP |
824 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | 824 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) |
825 | { | 825 | { |
826 | // Region of the rect we should draw | 826 | // Region of the rect we should draw |
827 | QRegion reg( QRect( cx, cy, cw, ch ) ); | 827 | QRegion reg( QRect( cx, cy, cw, ch ) ); |
828 | // Subtract the table from it | 828 | // Subtract the table from it |
829 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); | 829 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); |
830 | // And draw the rectangles (transformed as needed) | 830 | // And draw the rectangles (transformed as needed) |
831 | QArray<QRect> r = reg.rects(); | 831 | QArray<QRect> r = reg.rects(); |
832 | for (unsigned int i=0; i<r.count(); i++) | 832 | for (unsigned int i=0; i<r.count(); i++) |
833 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); | 833 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); |
834 | } | 834 | } |
835 | #endif | 835 | #endif |
836 | #endif | 836 | #endif |
837 | 837 | ||
838 | 838 | ||
839 | // int AbTable::rowHeight( int ) const | 839 | // int AbTable::rowHeight( int ) const |
840 | // { | 840 | // { |
841 | // return 18; | 841 | // return 18; |
842 | // } | 842 | // } |
843 | 843 | ||
844 | // int AbTable::rowPos( int row ) const | 844 | // int AbTable::rowPos( int row ) const |
845 | // { | 845 | // { |
846 | // return 18*row; | 846 | // return 18*row; |
847 | // } | 847 | // } |
848 | 848 | ||
849 | // int AbTable::rowAt( int pos ) const | 849 | // int AbTable::rowAt( int pos ) const |
850 | // { | 850 | // { |
851 | // return QMIN( pos/18, numRows()-1 ); | 851 | // return QMIN( pos/18, numRows()-1 ); |
852 | // } | 852 | // } |
853 | 853 | ||
854 | void AbTable::slotDoFind( const QString &findString, bool caseSensitive, | 854 | void AbTable::slotDoFind( const QString &findString, bool caseSensitive, |
855 | bool backwards, int category ) | 855 | bool backwards, int category ) |
856 | { | 856 | { |
857 | if ( currFindRow < -1 ) | 857 | if ( currFindRow < -1 ) |
858 | currFindRow = currentRow() - 1; | 858 | currFindRow = currentRow() - 1; |
859 | clearSelection( TRUE ); | 859 | clearSelection( TRUE ); |
860 | int rows, | 860 | int rows, |
861 | row; | 861 | row; |
862 | AbTableItem *ati; | 862 | AbTableItem *ati; |
863 | QRegExp r( findString ); | 863 | QRegExp r( findString ); |
864 | r.setCaseSensitive( caseSensitive ); | 864 | r.setCaseSensitive( caseSensitive ); |
865 | rows = numRows(); | 865 | rows = numRows(); |
866 | static bool wrapAround = true; | 866 | static bool wrapAround = true; |
867 | 867 | ||
868 | if ( !backwards ) { | 868 | if ( !backwards ) { |
869 | for ( row = currFindRow + 1; row < rows; row++ ) { | 869 | for ( row = currFindRow + 1; row < rows; row++ ) { |
870 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 870 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
871 | if ( contactCompare( contactList[ati], r, category ) ) | 871 | if ( contactCompare( contactList[ati], r, category ) ) |
872 | break; | 872 | break; |
873 | 873 | ||
874 | } | 874 | } |
875 | } else { | 875 | } else { |
876 | for ( row = currFindRow - 1; row > -1; row-- ) { | 876 | for ( row = currFindRow - 1; row > -1; row-- ) { |
877 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 877 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
878 | if ( contactCompare( contactList[ati], r, category ) ) | 878 | if ( contactCompare( contactList[ati], r, category ) ) |
879 | break; | 879 | break; |
880 | } | 880 | } |
881 | } | 881 | } |
882 | if ( row >= rows || row < 0 ) { | 882 | if ( row >= rows || row < 0 ) { |
883 | if ( row < 0 ) | 883 | if ( row < 0 ) |
884 | currFindRow = rows; | 884 | currFindRow = rows; |
885 | else | 885 | else |
886 | currFindRow = -1; | 886 | currFindRow = -1; |
887 | 887 | ||
888 | if ( wrapAround ) | 888 | if ( wrapAround ) |
889 | emit signalWrapAround(); | 889 | emit signalWrapAround(); |
890 | else | 890 | else |
891 | emit signalNotFound(); | 891 | emit signalNotFound(); |
892 | 892 | ||
893 | wrapAround = !wrapAround; | 893 | wrapAround = !wrapAround; |
894 | } else { | 894 | } else { |
895 | currFindRow = row; | 895 | currFindRow = row; |
896 | QTableSelection foundSelection; | 896 | QTableSelection foundSelection; |
897 | foundSelection.init( currFindRow, 0 ); | 897 | foundSelection.init( currFindRow, 0 ); |
898 | foundSelection.expandTo( currFindRow, numCols() - 1 ); | 898 | foundSelection.expandTo( currFindRow, numCols() - 1 ); |
899 | addSelection( foundSelection ); | 899 | addSelection( foundSelection ); |
900 | setCurrentCell( currFindRow, numCols() - 1 ); | 900 | setCurrentCell( currFindRow, numCols() - 1 ); |
901 | wrapAround = true; | 901 | wrapAround = true; |
902 | } | 902 | } |
903 | } | 903 | } |
904 | 904 | ||
905 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) | 905 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) |
906 | { | 906 | { |
907 | bool returnMe; | 907 | bool returnMe; |
908 | QArray<int> cats; | 908 | QArray<int> cats; |
909 | cats = cnt.categories(); | 909 | cats = cnt.categories(); |
910 | 910 | ||
911 | returnMe = false; | 911 | returnMe = false; |
912 | if ( (category == -1 && cats.count() == 0) || category == -2 ) | 912 | if ( (category == -1 && cats.count() == 0) || category == -2 ) |
913 | returnMe = cnt.match( r ); | 913 | returnMe = cnt.match( r ); |
914 | else { | 914 | else { |
915 | int i; | 915 | int i; |
916 | for ( i = 0; i < int(cats.count()); i++ ) { | 916 | for ( i = 0; i < int(cats.count()); i++ ) { |
917 | if ( cats[i] == category ) { | 917 | if ( cats[i] == category ) { |
918 | returnMe = cnt.match( r ); | 918 | returnMe = cnt.match( r ); |
919 | break; | 919 | break; |
920 | } | 920 | } |
921 | } | 921 | } |
922 | } | 922 | } |
923 | return returnMe; | 923 | return returnMe; |
924 | } | 924 | } |
925 | 925 | ||
926 | void AbTable::fitColumns() | 926 | void AbTable::fitColumns() |
927 | { | 927 | { |
928 | int contentsWidth = visibleWidth(); | 928 | int contentsWidth = visibleWidth(); |
929 | int n = numCols(); | 929 | int n = numCols(); |
930 | int pw = n == 3 ? columnWidth(2) : 0; | 930 | int pw = n == 3 ? columnWidth(2) : 0; |
931 | setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); | 931 | setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); |
932 | setColumnWidth( 1, contentsWidth / 2 - pw ); | 932 | setColumnWidth( 1, contentsWidth / 2 - pw ); |
933 | } | 933 | } |
934 | 934 | ||
935 | void AbTable::show() | 935 | void AbTable::show() |
936 | { | 936 | { |
937 | fitColumns(); | 937 | fitColumns(); |
938 | QTable::show(); | 938 | QTable::show(); |
939 | } | 939 | } |
940 | 940 | ||
941 | void AbTable::setChoiceNames( const QStringList& list) | 941 | void AbTable::setChoiceNames( const QStringList& list) |
942 | { | 942 | { |
943 | choicenames = list; | 943 | choicenames = list; |
944 | if ( choicenames.isEmpty() ) { | 944 | if ( choicenames.isEmpty() ) { |
945 | // hide pick column | 945 | // hide pick column |
946 | setNumCols( 2 ); | 946 | setNumCols( 2 ); |
947 | } else { | 947 | } else { |
948 | // show pick column | 948 | // show pick column |
949 | setNumCols( 3 ); | 949 | setNumCols( 3 ); |
950 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); | 950 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); |
951 | horizontalHeader()->setLabel( 2, tr( "Pick" )); | 951 | horizontalHeader()->setLabel( 2, tr( "Pick" )); |
952 | } | 952 | } |
953 | fitColumns(); | 953 | fitColumns(); |
954 | } | 954 | } |
955 | 955 | ||
956 | void AbTable::itemClicked(int,int col) | 956 | void AbTable::itemClicked(int,int col) |
957 | { | 957 | { |
958 | if ( col == 2 ) { | 958 | if ( col == 2 ) { |
959 | return; | 959 | return; |
960 | } else { | 960 | } else { |
961 | emit details(); | 961 | emit details(); |
962 | } | 962 | } |
963 | } | 963 | } |
964 | 964 | ||
965 | QStringList AbTable::choiceNames() const | 965 | QStringList AbTable::choiceNames() const |
966 | { | 966 | { |
967 | return choicenames; | 967 | return choicenames; |
968 | } | 968 | } |
969 | 969 | ||
970 | void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) | 970 | void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) |
971 | { | 971 | { |
972 | /* ###### | 972 | /* ###### |
973 | 973 | ||
974 | QString selname = choicenames.at(index); | 974 | QString selname = choicenames.at(index); |
975 | for (each row) { | 975 | for (each row) { |
976 | Contact *c = contactForRow(row); | 976 | Contact *c = contactForRow(row); |
977 | if ( list.contains(c->email) ) { | 977 | if ( list.contains(c->email) ) { |
978 | list.remove(c->email); | 978 | list.remove(c->email); |
979 | setText(row, 2, selname); | 979 | setText(row, 2, selname); |
980 | } | 980 | } |
981 | } | 981 | } |
982 | for (remaining list items) { | 982 | for (remaining list items) { |
983 | Contact *c = new contact(item); | 983 | Contact *c = new contact(item); |
984 | setText(newrow, 2, selname); | 984 | setText(newrow, 2, selname); |
985 | } | 985 | } |
986 | 986 | ||
987 | */ | 987 | */ |
988 | } | 988 | } |
989 | 989 | ||
990 | QStringList AbTable::choiceSelection(int /*index*/) const | 990 | QStringList AbTable::choiceSelection(int /*index*/) const |
991 | { | 991 | { |
992 | QStringList r; | 992 | QStringList r; |
993 | /* ###### | 993 | /* ###### |
994 | 994 | ||
995 | QString selname = choicenames.at(index); | 995 | QString selname = choicenames.at(index); |
996 | for (each row) { | 996 | for (each row) { |
997 | Contact *c = contactForRow(row); | 997 | Contact *c = contactForRow(row); |
998 | if ( text(row,2) == selname ) { | 998 | if ( text(row,2) == selname ) { |
999 | r.append(c->email); | 999 | r.append(c->email); |
1000 | } | 1000 | } |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | */ | 1003 | */ |
1004 | return r; | 1004 | return r; |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | void AbTable::setShowCategory( const QString &c ) | 1007 | void AbTable::setShowCategory( const QString &c ) |
1008 | { | 1008 | { |
1009 | showCat = c; | 1009 | showCat = c; |
1010 | updateVisible(); | 1010 | updateVisible(); |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | void AbTable::setShowByLetter( char c ) | 1013 | void AbTable::setShowByLetter( char c ) |
1014 | { | 1014 | { |
1015 | showChar = tolower(c); | 1015 | showChar = tolower(c); |
1016 | qDebug( "AbTable::setShowByLetter %c", showChar); | ||
1017 | updateVisible(); | 1016 | updateVisible(); |
1018 | } | 1017 | } |
1019 | 1018 | ||
1020 | QString AbTable::showCategory() const | 1019 | QString AbTable::showCategory() const |
1021 | { | 1020 | { |
1022 | return showCat; | 1021 | return showCat; |
1023 | } | 1022 | } |
1024 | 1023 | ||
1025 | 1024 | ||
1026 | QStringList AbTable::categories() | 1025 | QStringList AbTable::categories() |
1027 | { | 1026 | { |
1028 | mCat.load( categoryFileName() ); | 1027 | mCat.load( categoryFileName() ); |
1029 | QStringList categoryList = mCat.labels( "Contacts" ); | 1028 | QStringList categoryList = mCat.labels( "Contacts" ); |
1030 | return categoryList; | 1029 | return categoryList; |
1031 | } | 1030 | } |
1032 | 1031 | ||
1033 | void AbTable::updateVisible() | 1032 | void AbTable::updateVisible() |
1034 | { | 1033 | { |
1035 | int visible, | 1034 | int visible, |
1036 | totalRows, | 1035 | totalRows, |
1037 | id, | 1036 | id, |
1038 | totalCats, | 1037 | totalCats, |
1039 | it, | 1038 | it, |
1040 | row; | 1039 | row; |
1041 | bool hide; | 1040 | bool hide; |
1042 | AbTableItem *ati; | 1041 | AbTableItem *ati; |
1043 | Contact *cnt; | 1042 | Contact *cnt; |
1044 | QString fileAsName; | 1043 | QString fileAsName; |
1045 | QString tmpStr; | 1044 | QString tmpStr; |
1046 | visible = 0; | 1045 | visible = 0; |
1047 | 1046 | ||
1048 | setPaintingEnabled( FALSE ); | 1047 | setPaintingEnabled( FALSE ); |
1049 | 1048 | ||
1050 | totalRows = numRows(); | 1049 | totalRows = numRows(); |
1051 | id = mCat.id( "Contacts", showCat ); | 1050 | id = mCat.id( "Contacts", showCat ); |
1052 | QArray<int> cats; | 1051 | QArray<int> cats; |
1053 | for ( row = 0; row < totalRows; row++ ) { | 1052 | for ( row = 0; row < totalRows; row++ ) { |
1054 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 1053 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
1055 | cnt = &contactList[ati]; | 1054 | cnt = &contactList[ati]; |
1056 | cats = cnt->categories(); | 1055 | cats = cnt->categories(); |
1057 | fileAsName = cnt->fileAs(); | 1056 | fileAsName = cnt->fileAs(); |
1058 | hide = false; | 1057 | hide = false; |
1059 | if ( !showCat.isEmpty() ) { | 1058 | if ( !showCat.isEmpty() ) { |
1060 | if ( showCat == tr( "Unfiled" ) ) { | 1059 | if ( showCat == tr( "Unfiled" ) ) { |
1061 | if ( cats.count() > 0 ) | 1060 | if ( cats.count() > 0 ) |
1062 | hide = true; | 1061 | hide = true; |
1063 | } else { | 1062 | } else { |
1064 | // do some comparing | 1063 | // do some comparing |
1065 | if ( !hide ) { | 1064 | if ( !hide ) { |
1066 | hide = true; | 1065 | hide = true; |
1067 | totalCats = int(cats.count()); | 1066 | totalCats = int(cats.count()); |
1068 | for ( it = 0; it < totalCats; it++ ) { | 1067 | for ( it = 0; it < totalCats; it++ ) { |
1069 | if ( cats[it] == id ) { | 1068 | if ( cats[it] == id ) { |
1070 | hide = false; | 1069 | hide = false; |
1071 | break; | 1070 | break; |
1072 | } | 1071 | } |
1073 | } | 1072 | } |
1074 | } | 1073 | } |
1075 | } | 1074 | } |
1076 | } | 1075 | } |
1077 | if ( showChar != '\0' ) { | 1076 | if ( showChar != '\0' ) { |
1078 | tmpStr = fileAsName.left(1); | 1077 | tmpStr = fileAsName.left(1); |
1079 | tmpStr = tmpStr.lower(); | 1078 | tmpStr = tmpStr.lower(); |
1080 | qDebug( "updateVisible "); | 1079 | if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) { |
1081 | qDebug( tmpStr ); | ||
1082 | qDebug( "updateVisible2 %c", showChar ); | ||
1083 | if ( tmpStr != QString(QChar(showChar)) ) { | ||
1084 | hide = true; | 1080 | hide = true; |
1085 | } | 1081 | } |
1082 | if ( showChar == '#' ) { | ||
1083 | if (tmpStr == "a") | ||
1084 | hide = true; | ||
1085 | |||
1086 | if (tmpStr == "b") | ||
1087 | hide = true; | ||
1088 | |||
1089 | if (tmpStr == "c") | ||
1090 | hide = true; | ||
1091 | |||
1092 | if (tmpStr == "d") | ||
1093 | hide = true; | ||
1094 | |||
1095 | if (tmpStr == "e") | ||
1096 | hide = true; | ||
1097 | |||
1098 | if (tmpStr == "f") | ||
1099 | hide = true; | ||
1100 | |||
1101 | if (tmpStr == "g") | ||
1102 | hide = true; | ||
1103 | |||
1104 | if (tmpStr == "h") | ||
1105 | hide = true; | ||
1106 | |||
1107 | if (tmpStr == "i") | ||
1108 | hide = true; | ||
1109 | |||
1110 | if (tmpStr == "j") | ||
1111 | hide = true; | ||
1112 | |||
1113 | if (tmpStr == "k") | ||
1114 | hide = true; | ||
1115 | |||
1116 | if (tmpStr == "l") | ||
1117 | hide = true; | ||
1118 | |||
1119 | if (tmpStr == "m") | ||
1120 | hide = true; | ||
1121 | |||
1122 | if (tmpStr == "n") | ||
1123 | hide = true; | ||
1124 | |||
1125 | if (tmpStr == "o") | ||
1126 | hide = true; | ||
1127 | |||
1128 | if (tmpStr == "p") | ||
1129 | hide = true; | ||
1130 | |||
1131 | if (tmpStr == "q") | ||
1132 | hide = true; | ||
1133 | |||
1134 | if (tmpStr == "r") | ||
1135 | hide = true; | ||
1136 | |||
1137 | if (tmpStr == "s") | ||
1138 | hide = true; | ||
1139 | |||
1140 | if (tmpStr == "t") | ||
1141 | hide = true; | ||
1142 | |||
1143 | if (tmpStr == "u") | ||
1144 | hide = true; | ||
1145 | |||
1146 | if (tmpStr == "v") | ||
1147 | hide = true; | ||
1148 | |||
1149 | if (tmpStr == "w") | ||
1150 | hide = true; | ||
1151 | |||
1152 | if (tmpStr == "x") | ||
1153 | hide = true; | ||
1154 | |||
1155 | if (tmpStr == "y") | ||
1156 | hide = true; | ||
1157 | |||
1158 | if (tmpStr == "z") | ||
1159 | hide = true; | ||
1160 | } | ||
1161 | |||
1086 | } | 1162 | } |
1087 | if ( hide ) { | 1163 | if ( hide ) { |
1088 | if ( currentRow() == row ) | 1164 | if ( currentRow() == row ) |
1089 | setCurrentCell( -1, 0 ); | 1165 | setCurrentCell( -1, 0 ); |
1090 | if ( rowHeight(row) > 0 ) | 1166 | if ( rowHeight(row) > 0 ) |
1091 | hideRow( row ); | 1167 | hideRow( row ); |
1092 | } else { | 1168 | } else { |
1093 | if ( rowHeight(row) == 0 ) { | 1169 | if ( rowHeight(row) == 0 ) { |
1094 | showRow( row ); | 1170 | showRow( row ); |
1095 | adjustRow( row ); | 1171 | adjustRow( row ); |
1096 | } | 1172 | } |
1097 | visible++; | 1173 | visible++; |
1098 | } | 1174 | } |
1099 | } | 1175 | } |
1100 | if ( !visible ) | 1176 | if ( !visible ) |
1101 | setCurrentCell( -1, 0 ); | 1177 | setCurrentCell( -1, 0 ); |
1102 | 1178 | ||
1103 | setPaintingEnabled( TRUE ); | 1179 | setPaintingEnabled( TRUE ); |
1104 | } | 1180 | } |
1105 | 1181 | ||
1106 | 1182 | ||
1107 | void AbTable::setPaintingEnabled( bool e ) | 1183 | void AbTable::setPaintingEnabled( bool e ) |
1108 | { | 1184 | { |
1109 | if ( e != enablePainting ) { | 1185 | if ( e != enablePainting ) { |
1110 | if ( !enablePainting ) { | 1186 | if ( !enablePainting ) { |
1111 | enablePainting = true; | 1187 | enablePainting = true; |
1112 | rowHeightChanged( 0 ); | 1188 | rowHeightChanged( 0 ); |
1113 | viewport()->update(); | 1189 | viewport()->update(); |
1114 | } else { | 1190 | } else { |
1115 | enablePainting = false; | 1191 | enablePainting = false; |
1116 | } | 1192 | } |
1117 | } | 1193 | } |
1118 | } | 1194 | } |
1119 | 1195 | ||
1120 | void AbTable::rowHeightChanged( int row ) | 1196 | void AbTable::rowHeightChanged( int row ) |
1121 | { | 1197 | { |
1122 | if ( enablePainting ) | 1198 | if ( enablePainting ) |
1123 | QTable::rowHeightChanged( row ); | 1199 | QTable::rowHeightChanged( row ); |
1124 | } | 1200 | } |
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index e502cf6..beb953a 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -1,920 +1,923 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_FD | 21 | #define QTOPIA_INTERNAL_FD |
22 | 22 | ||
23 | #include "contacteditor.h" | 23 | #include "contacteditor.h" |
24 | #include "ablabel.h" | 24 | #include "ablabel.h" |
25 | #include "abtable.h" | 25 | #include "abtable.h" |
26 | #include "addresssettings.h" | 26 | #include "addresssettings.h" |
27 | #include "addressbook.h" | 27 | #include "addressbook.h" |
28 | 28 | ||
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
31 | #include <qpe/contact.h> | 31 | #include <qpe/contact.h> |
32 | 32 | ||
33 | #ifndef MAKE_FOR_SHARP_ROM | 33 | #ifndef MAKE_FOR_SHARP_ROM |
34 | #include <qpe/finddialog.h> | 34 | #include <qpe/finddialog.h> |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
38 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
39 | #include <qpe/ir.h> | 39 | #include <qpe/ir.h> |
40 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
41 | #include <qpe/qcopenvelope_qws.h> | 41 | #include <qpe/qcopenvelope_qws.h> |
42 | 42 | ||
43 | #include <qaction.h> | 43 | #include <qaction.h> |
44 | #include <qdialog.h> | 44 | #include <qdialog.h> |
45 | #include <qdir.h> | 45 | #include <qdir.h> |
46 | #include <qfile.h> | 46 | #include <qfile.h> |
47 | #include <qimage.h> | 47 | #include <qimage.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qpe/qpemenubar.h> | 49 | #include <qpe/qpemenubar.h> |
50 | #include <qmessagebox.h> | 50 | #include <qmessagebox.h> |
51 | #include <qpixmap.h> | 51 | #include <qpixmap.h> |
52 | #include <qpopupmenu.h> | 52 | #include <qpopupmenu.h> |
53 | #include <qpe/qpetoolbar.h> | 53 | #include <qpe/qpetoolbar.h> |
54 | #include <qstringlist.h> | 54 | #include <qstringlist.h> |
55 | #include <qtoolbutton.h> | 55 | #include <qtoolbutton.h> |
56 | #include <qwhatsthis.h> | 56 | #include <qwhatsthis.h> |
57 | 57 | ||
58 | #include <stdlib.h> | 58 | #include <stdlib.h> |
59 | #include <sys/stat.h> | 59 | #include <sys/stat.h> |
60 | #include <sys/types.h> | 60 | #include <sys/types.h> |
61 | #include <fcntl.h> | 61 | #include <fcntl.h> |
62 | #include <unistd.h> | 62 | #include <unistd.h> |
63 | 63 | ||
64 | #include <qdatetime.h> | 64 | #include <qdatetime.h> |
65 | 65 | ||
66 | #include "picker.h" | 66 | #include "picker.h" |
67 | static QString addressbookOldXMLFilename() | 67 | static QString addressbookOldXMLFilename() |
68 | { | 68 | { |
69 | QString filename = QPEApplication::documentDir() + "addressbook.xml"; | 69 | QString filename = QPEApplication::documentDir() + "addressbook.xml"; |
70 | return filename; | 70 | return filename; |
71 | } | 71 | } |
72 | 72 | ||
73 | static QString addressbookXMLFilename() | 73 | static QString addressbookXMLFilename() |
74 | { | 74 | { |
75 | QString filename = Global::applicationFileName("addressbook", | 75 | QString filename = Global::applicationFileName("addressbook", |
76 | "addressbook.xml"); | 76 | "addressbook.xml"); |
77 | return filename; | 77 | return filename; |
78 | } | 78 | } |
79 | 79 | ||
80 | static QString addressbookPersonalVCardName() | 80 | static QString addressbookPersonalVCardName() |
81 | { | 81 | { |
82 | QString filename = Global::applicationFileName("addressbook", | 82 | QString filename = Global::applicationFileName("addressbook", |
83 | "businesscard.vcf"); | 83 | "businesscard.vcf"); |
84 | return filename; | 84 | return filename; |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, | 88 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, |
89 | WFlags f ) | 89 | WFlags f ) |
90 | : QMainWindow( parent, name, f ), | 90 | : QMainWindow( parent, name, f ), |
91 | abEditor(0), | 91 | abEditor(0), |
92 | bAbEditFirstTime(TRUE), | 92 | bAbEditFirstTime(TRUE), |
93 | syncing(FALSE) | 93 | syncing(FALSE) |
94 | { | 94 | { |
95 | initFields(); | 95 | initFields(); |
96 | 96 | ||
97 | setCaption( tr("Contacts") ); | 97 | setCaption( tr("Contacts") ); |
98 | setIcon( Resource::loadPixmap( "AddressBook" ) ); | 98 | setIcon( Resource::loadPixmap( "AddressBook" ) ); |
99 | 99 | ||
100 | setToolBarsMovable( FALSE ); | 100 | setToolBarsMovable( FALSE ); |
101 | 101 | ||
102 | QBoxLayout *vb = new QVBoxLayout( this, 0, 0 ); | ||
103 | // Create Toolbars | 102 | // Create Toolbars |
104 | 103 | ||
105 | QPEToolBar *bar = new QPEToolBar( this ); | 104 | QPEToolBar *bar = new QPEToolBar( this ); |
106 | bar->setHorizontalStretchable( TRUE ); | 105 | bar->setHorizontalStretchable( TRUE ); |
107 | 106 | ||
108 | QPEMenuBar *mbList = new QPEMenuBar( bar ); | 107 | QPEMenuBar *mbList = new QPEMenuBar( bar ); |
109 | mbList->setMargin( 0 ); | 108 | mbList->setMargin( 0 ); |
110 | 109 | ||
111 | QPopupMenu *edit = new QPopupMenu( this ); | 110 | QPopupMenu *edit = new QPopupMenu( this ); |
112 | mbList->insertItem( tr( "Contact" ), edit ); | 111 | mbList->insertItem( tr( "Contact" ), edit ); |
113 | 112 | ||
114 | listTools = new QPEToolBar( this, "list operations" ); | 113 | listTools = new QPEToolBar( this, "list operations" ); |
115 | 114 | ||
116 | 115 | ||
117 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, | 116 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, |
118 | 0, this, 0 ); | 117 | 0, this, 0 ); |
119 | actionNew = a; | 118 | actionNew = a; |
120 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); | 119 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); |
121 | a->addTo( edit ); | 120 | a->addTo( edit ); |
122 | a->addTo( listTools ); | 121 | a->addTo( listTools ); |
123 | 122 | ||
124 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 123 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
125 | 0, this, 0 ); | 124 | 0, this, 0 ); |
126 | actionEdit = a; | 125 | actionEdit = a; |
127 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); | 126 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); |
128 | a->addTo( edit ); | 127 | a->addTo( edit ); |
129 | a->addTo( listTools ); | 128 | a->addTo( listTools ); |
130 | 129 | ||
131 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 130 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
132 | 0, this, 0 ); | 131 | 0, this, 0 ); |
133 | actionTrash = a; | 132 | actionTrash = a; |
134 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); | 133 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); |
135 | a->addTo( edit ); | 134 | a->addTo( edit ); |
136 | a->addTo( listTools ); | 135 | a->addTo( listTools ); |
137 | 136 | ||
138 | #ifndef MAKE_FOR_SHARP_ROM | 137 | #ifndef MAKE_FOR_SHARP_ROM |
139 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), | 138 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), |
140 | QString::null, 0, this, 0 ); | 139 | QString::null, 0, this, 0 ); |
141 | actionFind = a; | 140 | actionFind = a; |
142 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 141 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
143 | a->addTo( edit ); | 142 | a->addTo( edit ); |
144 | a->addTo( listTools ); | 143 | a->addTo( listTools ); |
145 | #endif | 144 | #endif |
146 | 145 | ||
147 | 146 | ||
148 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), | 147 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), |
149 | QString::null, 0, this, 0 ); | 148 | QString::null, 0, this, 0 ); |
150 | //a->setEnabled( FALSE ); we got support for it now :) zecke | 149 | //a->setEnabled( FALSE ); we got support for it now :) zecke |
151 | actionMail = a; | 150 | actionMail = a; |
152 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); | 151 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); |
153 | a->addTo( edit ); | 152 | a->addTo( edit ); |
154 | a->addTo( listTools ); | 153 | a->addTo( listTools ); |
155 | 154 | ||
156 | 155 | ||
157 | 156 | ||
158 | if ( Ir::supported() ) { | 157 | if ( Ir::supported() ) { |
159 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, | 158 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, |
160 | 0, this, 0 ); | 159 | 0, this, 0 ); |
161 | actionBeam = a; | 160 | actionBeam = a; |
162 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 161 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
163 | a->addTo( edit ); | 162 | a->addTo( edit ); |
164 | a->addTo( listTools ); | 163 | a->addTo( listTools ); |
165 | } | 164 | } |
166 | 165 | ||
167 | edit->insertSeparator(); | 166 | edit->insertSeparator(); |
168 | 167 | ||
169 | a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); | 168 | a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); |
170 | actionPersonal = a; | 169 | actionPersonal = a; |
171 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); | 170 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); |
172 | a->addTo( edit ); | 171 | a->addTo( edit ); |
173 | 172 | ||
174 | 173 | ||
175 | a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); | 174 | a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); |
176 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 175 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
177 | a->addTo( edit ); | 176 | a->addTo( edit ); |
178 | 177 | ||
179 | // Create Views | 178 | // Create Views |
180 | 179 | ||
181 | // This is safe to call without checking to see if it exists... | 180 | // This is safe to call without checking to see if it exists... |
182 | // not to mention it also does the necessary stuff for the | 181 | // not to mention it also does the necessary stuff for the |
183 | // journaling... | 182 | // journaling... |
184 | QString str = addressbookXMLFilename(); | 183 | QString str = addressbookXMLFilename(); |
185 | if ( str.isNull() ) { | 184 | if ( str.isNull() ) { |
186 | QMessageBox::warning( this, tr("Out of Space"), | 185 | QMessageBox::warning( this, tr("Out of Space"), |
187 | tr("There is not enough space to create\n" | 186 | tr("There is not enough space to create\n" |
188 | "neccessary startup files.\n" | 187 | "neccessary startup files.\n" |
189 | "\nFree up some space before\nentering data!") | 188 | "\nFree up some space before\nentering data!") |
190 | ); | 189 | ); |
191 | } | 190 | } |
192 | 191 | ||
193 | abList = new AbTable( &orderedFields, this, "table" ); | 192 | listContainer = new QWidget( this ); |
194 | vb->insertWidget(0,abList); | 193 | |
194 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); | ||
195 | |||
196 | abList = new AbTable( &orderedFields, listContainer, "table" ); | ||
197 | vb->addWidget(abList); | ||
195 | abList->setHScrollBarMode( QScrollView::AlwaysOff ); | 198 | abList->setHScrollBarMode( QScrollView::AlwaysOff ); |
196 | connect( abList, SIGNAL( empty( bool ) ), | 199 | connect( abList, SIGNAL( empty( bool ) ), |
197 | this, SLOT( listIsEmpty( bool ) ) ); | 200 | this, SLOT( listIsEmpty( bool ) ) ); |
198 | connect( abList, SIGNAL( details() ), | 201 | connect( abList, SIGNAL( details() ), |
199 | this, SLOT( slotListView() ) ); | 202 | this, SLOT( slotListView() ) ); |
200 | connect( abList, SIGNAL(currentChanged(int,int)), | 203 | connect( abList, SIGNAL(currentChanged(int,int)), |
201 | this, SLOT(slotUpdateToolbar()) ); | 204 | this, SLOT(slotUpdateToolbar()) ); |
202 | 205 | ||
203 | mView = 0; | 206 | mView = 0; |
204 | 207 | ||
205 | abList->load( addressbookXMLFilename() ); | 208 | abList->load( addressbookXMLFilename() ); |
206 | if ( QFile::exists(addressbookOldXMLFilename()) ) { | 209 | if ( QFile::exists(addressbookOldXMLFilename()) ) { |
207 | abList->load( addressbookOldXMLFilename() ); | 210 | abList->load( addressbookOldXMLFilename() ); |
208 | QFile::remove(addressbookOldXMLFilename()); | 211 | QFile::remove(addressbookOldXMLFilename()); |
209 | } | 212 | } |
210 | 213 | ||
211 | pLabel = new LetterPicker( abList ); | 214 | pLabel = new LetterPicker( listContainer ); |
212 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); | 215 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); |
213 | vb->insertWidget(1,pLabel); | 216 | vb->addWidget(pLabel); |
214 | catMenu = new QPopupMenu( this ); | 217 | catMenu = new QPopupMenu( this ); |
215 | catMenu->setCheckable( TRUE ); | 218 | catMenu->setCheckable( TRUE ); |
216 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); | 219 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); |
217 | populateCategories(); | 220 | populateCategories(); |
218 | 221 | ||
219 | mbList->insertItem( tr("View"), catMenu ); | 222 | mbList->insertItem( tr("View"), catMenu ); |
220 | setCentralWidget( abList ); | 223 | setCentralWidget( listContainer ); |
221 | 224 | ||
222 | fontMenu = new QPopupMenu(this); | 225 | fontMenu = new QPopupMenu(this); |
223 | fontMenu->setCheckable( true ); | 226 | fontMenu->setCheckable( true ); |
224 | connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); | 227 | connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); |
225 | 228 | ||
226 | fontMenu->insertItem(tr( "Small" ), 0); | 229 | fontMenu->insertItem(tr( "Small" ), 0); |
227 | fontMenu->insertItem(tr( "Normal" ), 1); | 230 | fontMenu->insertItem(tr( "Normal" ), 1); |
228 | fontMenu->insertItem(tr( "Large" ), 2); | 231 | fontMenu->insertItem(tr( "Large" ), 2); |
229 | 232 | ||
230 | defaultFont = new QFont( abList->font() ); | 233 | defaultFont = new QFont( abList->font() ); |
231 | 234 | ||
232 | slotSetFont(startFontSize); | 235 | slotSetFont(startFontSize); |
233 | 236 | ||
234 | mbList->insertItem( tr("Font"), fontMenu); | 237 | mbList->insertItem( tr("Font"), fontMenu); |
235 | setCentralWidget(abList); | 238 | setCentralWidget(listContainer); |
236 | 239 | ||
237 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); | 240 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); |
238 | } | 241 | } |
239 | void AddressbookWindow::slotSetFont( int size ) { | 242 | void AddressbookWindow::slotSetFont( int size ) { |
240 | 243 | ||
241 | if (size > 2 || size < 0) | 244 | if (size > 2 || size < 0) |
242 | size = 1; | 245 | size = 1; |
243 | 246 | ||
244 | startFontSize = size; | 247 | startFontSize = size; |
245 | 248 | ||
246 | QFont *currentFont; | 249 | QFont *currentFont; |
247 | 250 | ||
248 | switch (size) { | 251 | switch (size) { |
249 | case 0: | 252 | case 0: |
250 | fontMenu->setItemChecked(0, true); | 253 | fontMenu->setItemChecked(0, true); |
251 | fontMenu->setItemChecked(1, false); | 254 | fontMenu->setItemChecked(1, false); |
252 | fontMenu->setItemChecked(2, false); | 255 | fontMenu->setItemChecked(2, false); |
253 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 256 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
254 | currentFont = new QFont (abList->font()); | 257 | currentFont = new QFont (abList->font()); |
255 | abList->resizeRows(currentFont->pixelSize() + 7); | 258 | abList->resizeRows(currentFont->pixelSize() + 7); |
256 | break; | 259 | break; |
257 | case 1: | 260 | case 1: |
258 | fontMenu->setItemChecked(0, false); | 261 | fontMenu->setItemChecked(0, false); |
259 | fontMenu->setItemChecked(1, true); | 262 | fontMenu->setItemChecked(1, true); |
260 | fontMenu->setItemChecked(2, false); | 263 | fontMenu->setItemChecked(2, false); |
261 | abList->setFont( *defaultFont ); | 264 | abList->setFont( *defaultFont ); |
262 | currentFont = new QFont (abList->font()); | 265 | currentFont = new QFont (abList->font()); |
263 | abList->resizeRows(currentFont->pixelSize() + 7); | 266 | abList->resizeRows(currentFont->pixelSize() + 7); |
264 | break; | 267 | break; |
265 | case 2: | 268 | case 2: |
266 | fontMenu->setItemChecked(0, false); | 269 | fontMenu->setItemChecked(0, false); |
267 | fontMenu->setItemChecked(1, false); | 270 | fontMenu->setItemChecked(1, false); |
268 | fontMenu->setItemChecked(2, true); | 271 | fontMenu->setItemChecked(2, true); |
269 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); | 272 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); |
270 | currentFont = new QFont (abList->font()); | 273 | currentFont = new QFont (abList->font()); |
271 | abList->resizeRows(currentFont->pixelSize() + 7); | 274 | abList->resizeRows(currentFont->pixelSize() + 7); |
272 | break; | 275 | break; |
273 | } | 276 | } |
274 | } | 277 | } |
275 | 278 | ||
276 | 279 | ||
277 | void AddressbookWindow::setDocument( const QString &filename ) | 280 | void AddressbookWindow::setDocument( const QString &filename ) |
278 | { | 281 | { |
279 | if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; | 282 | if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; |
280 | 283 | ||
281 | QValueList<Contact> cl = Contact::readVCard( filename ); | 284 | QValueList<Contact> cl = Contact::readVCard( filename ); |
282 | for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { | 285 | for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { |
283 | // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") | 286 | // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") |
284 | // .arg( (*it).fullName() ); | 287 | // .arg( (*it).fullName() ); |
285 | // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == | 288 | // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == |
286 | // QMessageBox::Ok ) { | 289 | // QMessageBox::Ok ) { |
287 | abList->addEntry( *it ); | 290 | abList->addEntry( *it ); |
288 | // } | 291 | // } |
289 | } | 292 | } |
290 | 293 | ||
291 | } | 294 | } |
292 | 295 | ||
293 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 296 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
294 | { | 297 | { |
295 | QMainWindow::resizeEvent( e ); | 298 | QMainWindow::resizeEvent( e ); |
296 | 299 | ||
297 | if ( centralWidget() == abList ) | 300 | if ( centralWidget() == listContainer ) |
298 | showList(); | 301 | showList(); |
299 | else if ( centralWidget() == mView ) | 302 | else if ( centralWidget() == mView ) |
300 | showView(); | 303 | showView(); |
301 | } | 304 | } |
302 | 305 | ||
303 | AddressbookWindow::~AddressbookWindow() | 306 | AddressbookWindow::~AddressbookWindow() |
304 | { | 307 | { |
305 | Config cfg("AddressBook"); | 308 | Config cfg("AddressBook"); |
306 | cfg.setGroup("Font"); | 309 | cfg.setGroup("Font"); |
307 | cfg.writeEntry("fontSize", startFontSize); | 310 | cfg.writeEntry("fontSize", startFontSize); |
308 | } | 311 | } |
309 | 312 | ||
310 | void AddressbookWindow::slotUpdateToolbar() | 313 | void AddressbookWindow::slotUpdateToolbar() |
311 | { | 314 | { |
312 | Contact ce = abList->currentEntry(); | 315 | Contact ce = abList->currentEntry(); |
313 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); | 316 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); |
314 | } | 317 | } |
315 | 318 | ||
316 | void AddressbookWindow::showList() | 319 | void AddressbookWindow::showList() |
317 | { | 320 | { |
318 | if ( mView ) mView->hide(); | 321 | if ( mView ) mView->hide(); |
319 | setCentralWidget( abList ); | 322 | setCentralWidget( listContainer ); |
320 | abList->show(); | 323 | listContainer->show(); |
321 | // update our focues... (or use a stack widget!); | 324 | // update our focues... (or use a stack widget!); |
322 | abList->setFocus(); | 325 | abList->setFocus(); |
323 | } | 326 | } |
324 | 327 | ||
325 | void AddressbookWindow::showView() | 328 | void AddressbookWindow::showView() |
326 | { | 329 | { |
327 | if ( abList->numRows() > 0 ) { | 330 | if ( abList->numRows() > 0 ) { |
328 | abList->hide(); | 331 | listContainer->hide(); |
329 | setCentralWidget( abView() ); | 332 | setCentralWidget( abView() ); |
330 | mView->show(); | 333 | mView->show(); |
331 | mView->setFocus(); | 334 | mView->setFocus(); |
332 | } | 335 | } |
333 | } | 336 | } |
334 | 337 | ||
335 | void AddressbookWindow::slotListNew() | 338 | void AddressbookWindow::slotListNew() |
336 | { | 339 | { |
337 | Contact cnt; | 340 | Contact cnt; |
338 | if( !syncing ) { | 341 | if( !syncing ) { |
339 | if ( abEditor ) | 342 | if ( abEditor ) |
340 | abEditor->setEntry( cnt ); | 343 | abEditor->setEntry( cnt ); |
341 | abView()->init( cnt ); | 344 | abView()->init( cnt ); |
342 | editEntry( NewEntry ); | 345 | editEntry( NewEntry ); |
343 | } else { | 346 | } else { |
344 | QMessageBox::warning(this, tr("Contacts"), | 347 | QMessageBox::warning(this, tr("Contacts"), |
345 | tr("Can not edit data, currently syncing")); | 348 | tr("Can not edit data, currently syncing")); |
346 | } | 349 | } |
347 | } | 350 | } |
348 | 351 | ||
349 | void AddressbookWindow::slotListView() | 352 | void AddressbookWindow::slotListView() |
350 | { | 353 | { |
351 | abView()->init( abList->currentEntry() ); | 354 | abView()->init( abList->currentEntry() ); |
352 | mView->sync(); | 355 | mView->sync(); |
353 | showView(); | 356 | showView(); |
354 | } | 357 | } |
355 | 358 | ||
356 | void AddressbookWindow::slotListDelete() | 359 | void AddressbookWindow::slotListDelete() |
357 | { | 360 | { |
358 | if(!syncing) { | 361 | if(!syncing) { |
359 | Contact tmpEntry = abList->currentEntry(); | 362 | Contact tmpEntry = abList->currentEntry(); |
360 | 363 | ||
361 | // get a name, do the best we can... | 364 | // get a name, do the best we can... |
362 | QString strName = tmpEntry.fullName(); | 365 | QString strName = tmpEntry.fullName(); |
363 | if ( strName.isEmpty() ) { | 366 | if ( strName.isEmpty() ) { |
364 | strName = tmpEntry.company(); | 367 | strName = tmpEntry.company(); |
365 | if ( strName.isEmpty() ) | 368 | if ( strName.isEmpty() ) |
366 | strName = "No Name"; | 369 | strName = "No Name"; |
367 | } | 370 | } |
368 | 371 | ||
369 | 372 | ||
370 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 373 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
371 | strName ) ) { | 374 | strName ) ) { |
372 | abList->deleteCurrentEntry(); | 375 | abList->deleteCurrentEntry(); |
373 | showList(); | 376 | showList(); |
374 | } | 377 | } |
375 | } else { | 378 | } else { |
376 | QMessageBox::warning( this, tr("Contacts"), | 379 | QMessageBox::warning( this, tr("Contacts"), |
377 | tr("Can not edit data, currently syncing") ); | 380 | tr("Can not edit data, currently syncing") ); |
378 | } | 381 | } |
379 | } | 382 | } |
380 | 383 | ||
381 | void AddressbookWindow::slotViewBack() | 384 | void AddressbookWindow::slotViewBack() |
382 | { | 385 | { |
383 | showList(); | 386 | showList(); |
384 | } | 387 | } |
385 | 388 | ||
386 | void AddressbookWindow::slotViewEdit() | 389 | void AddressbookWindow::slotViewEdit() |
387 | { | 390 | { |
388 | if(!syncing) { | 391 | if(!syncing) { |
389 | if (actionPersonal->isOn()) { | 392 | if (actionPersonal->isOn()) { |
390 | editPersonal(); | 393 | editPersonal(); |
391 | } else { | 394 | } else { |
392 | if ( !bAbEditFirstTime ) | 395 | if ( !bAbEditFirstTime ) |
393 | abEditor->setEntry( abList->currentEntry() ); | 396 | abEditor->setEntry( abList->currentEntry() ); |
394 | editEntry( EditEntry ); | 397 | editEntry( EditEntry ); |
395 | } | 398 | } |
396 | } else { | 399 | } else { |
397 | QMessageBox::warning( this, tr("Contacts"), | 400 | QMessageBox::warning( this, tr("Contacts"), |
398 | tr("Can not edit data, currently syncing") ); | 401 | tr("Can not edit data, currently syncing") ); |
399 | } | 402 | } |
400 | } | 403 | } |
401 | 404 | ||
402 | 405 | ||
403 | 406 | ||
404 | void AddressbookWindow::writeMail() | 407 | void AddressbookWindow::writeMail() |
405 | { | 408 | { |
406 | Contact c = abList->currentEntry(); | 409 | Contact c = abList->currentEntry(); |
407 | QString name = c.fileAs(); | 410 | QString name = c.fileAs(); |
408 | QString email = c.defaultEmail(); | 411 | QString email = c.defaultEmail(); |
409 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 412 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
410 | e << name << email; | 413 | e << name << email; |
411 | } | 414 | } |
412 | 415 | ||
413 | 416 | ||
414 | 417 | ||
415 | 418 | ||
416 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 419 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
417 | 420 | ||
418 | void AddressbookWindow::slotBeam() | 421 | void AddressbookWindow::slotBeam() |
419 | { | 422 | { |
420 | QString filename; | 423 | QString filename; |
421 | Contact c; | 424 | Contact c; |
422 | if ( actionPersonal->isOn() ) { | 425 | if ( actionPersonal->isOn() ) { |
423 | filename = addressbookPersonalVCardName(); | 426 | filename = addressbookPersonalVCardName(); |
424 | if (!QFile::exists(filename)) | 427 | if (!QFile::exists(filename)) |
425 | return; // can't beam a non-existent file | 428 | return; // can't beam a non-existent file |
426 | c = Contact::readVCard( filename )[0]; | 429 | c = Contact::readVCard( filename )[0]; |
427 | } else { | 430 | } else { |
428 | unlink( beamfile ); // delete if exists | 431 | unlink( beamfile ); // delete if exists |
429 | c = abList->currentEntry(); | 432 | c = abList->currentEntry(); |
430 | mkdir("/tmp/obex/", 0755); | 433 | mkdir("/tmp/obex/", 0755); |
431 | Contact::writeVCard( beamfile, c ); | 434 | Contact::writeVCard( beamfile, c ); |
432 | filename = beamfile; | 435 | filename = beamfile; |
433 | } | 436 | } |
434 | Ir *ir = new Ir( this ); | 437 | Ir *ir = new Ir( this ); |
435 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 438 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
436 | QString description = c.fullName(); | 439 | QString description = c.fullName(); |
437 | ir->send( filename, description, "text/x-vCard" ); | 440 | ir->send( filename, description, "text/x-vCard" ); |
438 | } | 441 | } |
439 | 442 | ||
440 | void AddressbookWindow::beamDone( Ir *ir ) | 443 | void AddressbookWindow::beamDone( Ir *ir ) |
441 | { | 444 | { |
442 | delete ir; | 445 | delete ir; |
443 | unlink( beamfile ); | 446 | unlink( beamfile ); |
444 | } | 447 | } |
445 | 448 | ||
446 | 449 | ||
447 | static void parseName( const QString& name, QString *first, QString *middle, | 450 | static void parseName( const QString& name, QString *first, QString *middle, |
448 | QString * last ) | 451 | QString * last ) |
449 | { | 452 | { |
450 | 453 | ||
451 | int comma = name.find ( "," ); | 454 | int comma = name.find ( "," ); |
452 | QString rest; | 455 | QString rest; |
453 | if ( comma > 0 ) { | 456 | if ( comma > 0 ) { |
454 | *last = name.left( comma ); | 457 | *last = name.left( comma ); |
455 | comma++; | 458 | comma++; |
456 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 459 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
457 | comma++; | 460 | comma++; |
458 | rest = name.mid( comma ); | 461 | rest = name.mid( comma ); |
459 | } else { | 462 | } else { |
460 | int space = name.findRev( ' ' ); | 463 | int space = name.findRev( ' ' ); |
461 | *last = name.mid( space+1 ); | 464 | *last = name.mid( space+1 ); |
462 | rest = name.left( space ); | 465 | rest = name.left( space ); |
463 | } | 466 | } |
464 | int space = rest.find( ' ' ); | 467 | int space = rest.find( ' ' ); |
465 | if ( space <= 0 ) { | 468 | if ( space <= 0 ) { |
466 | *first = rest; | 469 | *first = rest; |
467 | } else { | 470 | } else { |
468 | *first = rest.left( space ); | 471 | *first = rest.left( space ); |
469 | *middle = rest.mid( space+1 ); | 472 | *middle = rest.mid( space+1 ); |
470 | } | 473 | } |
471 | 474 | ||
472 | } | 475 | } |
473 | 476 | ||
474 | 477 | ||
475 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 478 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
476 | { | 479 | { |
477 | if (msg == "editPersonal()") { | 480 | if (msg == "editPersonal()") { |
478 | editPersonal(); | 481 | editPersonal(); |
479 | } else if (msg == "editPersonalAndClose()") { | 482 | } else if (msg == "editPersonalAndClose()") { |
480 | editPersonal(); | 483 | editPersonal(); |
481 | close(); | 484 | close(); |
482 | } else if ( msg == "addContact(QString,QString)" ) { | 485 | } else if ( msg == "addContact(QString,QString)" ) { |
483 | QDataStream stream(data,IO_ReadOnly); | 486 | QDataStream stream(data,IO_ReadOnly); |
484 | QString name, email; | 487 | QString name, email; |
485 | stream >> name >> email; | 488 | stream >> name >> email; |
486 | 489 | ||
487 | Contact cnt; | 490 | Contact cnt; |
488 | QString fn, mn, ln; | 491 | QString fn, mn, ln; |
489 | parseName( name, &fn, &mn, &ln ); | 492 | parseName( name, &fn, &mn, &ln ); |
490 | //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); | 493 | //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); |
491 | cnt.setFirstName( fn ); | 494 | cnt.setFirstName( fn ); |
492 | cnt.setMiddleName( mn ); | 495 | cnt.setMiddleName( mn ); |
493 | cnt.setLastName( ln ); | 496 | cnt.setLastName( ln ); |
494 | cnt.setEmails( email ); | 497 | cnt.setEmails( email ); |
495 | cnt.setDefaultEmail( email ); | 498 | cnt.setDefaultEmail( email ); |
496 | cnt.setFileAs(); | 499 | cnt.setFileAs(); |
497 | 500 | ||
498 | if ( bAbEditFirstTime ) { | 501 | if ( bAbEditFirstTime ) { |
499 | abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, | 502 | abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, |
500 | this, "editor" ); | 503 | this, "editor" ); |
501 | bAbEditFirstTime = FALSE; | 504 | bAbEditFirstTime = FALSE; |
502 | } else { | 505 | } else { |
503 | abEditor->setEntry( cnt ); | 506 | abEditor->setEntry( cnt ); |
504 | } | 507 | } |
505 | abView()->init( cnt ); | 508 | abView()->init( cnt ); |
506 | editEntry( NewEntry ); | 509 | editEntry( NewEntry ); |
507 | 510 | ||
508 | 511 | ||
509 | 512 | ||
510 | } | 513 | } |
511 | #if 0 | 514 | #if 0 |
512 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { | 515 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { |
513 | QDataStream stream(data,IO_ReadOnly); | 516 | QDataStream stream(data,IO_ReadOnly); |
514 | QCString ch,m; | 517 | QCString ch,m; |
515 | QStringList types; | 518 | QStringList types; |
516 | stream >> ch >> m >> types; | 519 | stream >> ch >> m >> types; |
517 | AddressPicker picker(abList,this,0,TRUE); | 520 | AddressPicker picker(abList,this,0,TRUE); |
518 | picker.showMaximized(); | 521 | picker.showMaximized(); |
519 | picker.setChoiceNames(types); | 522 | picker.setChoiceNames(types); |
520 | int i=0; | 523 | int i=0; |
521 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 524 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
522 | QStringList sel; | 525 | QStringList sel; |
523 | stream >> sel; | 526 | stream >> sel; |
524 | picker.setSelection(i++,sel); | 527 | picker.setSelection(i++,sel); |
525 | } | 528 | } |
526 | picker.showMaximized(); | 529 | picker.showMaximized(); |
527 | picker.exec(); | 530 | picker.exec(); |
528 | 531 | ||
529 | // ###### note: contacts may have been added - save here! | 532 | // ###### note: contacts may have been added - save here! |
530 | 533 | ||
531 | setCentralWidget(abList); | 534 | setCentralWidget(abList); |
532 | QCopEnvelope e(ch,m); | 535 | QCopEnvelope e(ch,m); |
533 | i=0; | 536 | i=0; |
534 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 537 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
535 | QStringList sel = picker.selection(i++); | 538 | QStringList sel = picker.selection(i++); |
536 | e << sel; | 539 | e << sel; |
537 | } | 540 | } |
538 | } | 541 | } |
539 | #endif | 542 | #endif |
540 | 543 | ||
541 | } | 544 | } |
542 | 545 | ||
543 | void AddressbookWindow::editPersonal() | 546 | void AddressbookWindow::editPersonal() |
544 | { | 547 | { |
545 | QString filename = addressbookPersonalVCardName(); | 548 | QString filename = addressbookPersonalVCardName(); |
546 | Contact me; | 549 | Contact me; |
547 | if (QFile::exists(filename)) | 550 | if (QFile::exists(filename)) |
548 | me = Contact::readVCard( filename )[0]; | 551 | me = Contact::readVCard( filename )[0]; |
549 | if (bAbEditFirstTime) { | 552 | if (bAbEditFirstTime) { |
550 | abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, | 553 | abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, |
551 | this, "editor" ); | 554 | this, "editor" ); |
552 | // don't create a new editor every time | 555 | // don't create a new editor every time |
553 | bAbEditFirstTime = FALSE; | 556 | bAbEditFirstTime = FALSE; |
554 | } else | 557 | } else |
555 | abEditor->setEntry( me ); | 558 | abEditor->setEntry( me ); |
556 | 559 | ||
557 | abEditor->setCaption(tr("Edit My Personal Details")); | 560 | abEditor->setCaption(tr("Edit My Personal Details")); |
558 | abEditor->showMaximized(); | 561 | abEditor->showMaximized(); |
559 | 562 | ||
560 | // fix the foxus... | 563 | // fix the foxus... |
561 | abEditor->setNameFocus(); | 564 | abEditor->setNameFocus(); |
562 | if ( abEditor->exec() ) { | 565 | if ( abEditor->exec() ) { |
563 | setFocus(); | 566 | setFocus(); |
564 | Contact new_personal = abEditor->entry(); | 567 | Contact new_personal = abEditor->entry(); |
565 | QString fname = addressbookPersonalVCardName(); | 568 | QString fname = addressbookPersonalVCardName(); |
566 | Contact::writeVCard( fname, new_personal ); | 569 | Contact::writeVCard( fname, new_personal ); |
567 | abView()->init(new_personal); | 570 | abView()->init(new_personal); |
568 | abView()->sync(); | 571 | abView()->sync(); |
569 | } | 572 | } |
570 | abEditor->setCaption( tr("Edit Address") ); | 573 | abEditor->setCaption( tr("Edit Address") ); |
571 | } | 574 | } |
572 | 575 | ||
573 | void AddressbookWindow::slotPersonalView() | 576 | void AddressbookWindow::slotPersonalView() |
574 | { | 577 | { |
575 | if (!actionPersonal->isOn()) { | 578 | if (!actionPersonal->isOn()) { |
576 | // we just turned it off | 579 | // we just turned it off |
577 | setCaption( tr("Contacts") ); | 580 | setCaption( tr("Contacts") ); |
578 | actionNew->setEnabled(TRUE); | 581 | actionNew->setEnabled(TRUE); |
579 | actionTrash->setEnabled(TRUE); | 582 | actionTrash->setEnabled(TRUE); |
580 | #ifndef MAKE_FOR_SHARP_ROM | 583 | #ifndef MAKE_FOR_SHARP_ROM |
581 | actionFind->setEnabled(TRUE); | 584 | actionFind->setEnabled(TRUE); |
582 | #endif | 585 | #endif |
583 | slotUpdateToolbar(); // maybe some of the above could be moved there | 586 | slotUpdateToolbar(); // maybe some of the above could be moved there |
584 | showList(); | 587 | showList(); |
585 | return; | 588 | return; |
586 | } | 589 | } |
587 | 590 | ||
588 | // XXX need to disable some QActions. | 591 | // XXX need to disable some QActions. |
589 | actionNew->setEnabled(FALSE); | 592 | actionNew->setEnabled(FALSE); |
590 | actionTrash->setEnabled(FALSE); | 593 | actionTrash->setEnabled(FALSE); |
591 | #ifndef MAKE_FOR_SHARP_ROM | 594 | #ifndef MAKE_FOR_SHARP_ROM |
592 | actionFind->setEnabled(FALSE); | 595 | actionFind->setEnabled(FALSE); |
593 | #endif | 596 | #endif |
594 | actionMail->setEnabled(FALSE); | 597 | actionMail->setEnabled(FALSE); |
595 | 598 | ||
596 | setCaption( tr("Contacts - My Personal Details") ); | 599 | setCaption( tr("Contacts - My Personal Details") ); |
597 | QString filename = addressbookPersonalVCardName(); | 600 | QString filename = addressbookPersonalVCardName(); |
598 | Contact me; | 601 | Contact me; |
599 | if (QFile::exists(filename)) | 602 | if (QFile::exists(filename)) |
600 | me = Contact::readVCard( filename )[0]; | 603 | me = Contact::readVCard( filename )[0]; |
601 | 604 | ||
602 | abView()->init( me ); | 605 | abView()->init( me ); |
603 | abView()->sync(); | 606 | abView()->sync(); |
604 | abList->hide(); | 607 | listContainer->hide(); |
605 | setCentralWidget( abView() ); | 608 | setCentralWidget( abView() ); |
606 | mView->show(); | 609 | mView->show(); |
607 | mView->setFocus(); | 610 | mView->setFocus(); |
608 | } | 611 | } |
609 | 612 | ||
610 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 613 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
611 | { | 614 | { |
612 | Contact entry; | 615 | Contact entry; |
613 | if ( bAbEditFirstTime ) { | 616 | if ( bAbEditFirstTime ) { |
614 | abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, | 617 | abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, |
615 | this, "editor" ); | 618 | this, "editor" ); |
616 | bAbEditFirstTime = FALSE; | 619 | bAbEditFirstTime = FALSE; |
617 | if ( entryMode == EditEntry ) | 620 | if ( entryMode == EditEntry ) |
618 | abEditor->setEntry( abList->currentEntry() ); | 621 | abEditor->setEntry( abList->currentEntry() ); |
619 | } | 622 | } |
620 | // other things may chane the caption. | 623 | // other things may chane the caption. |
621 | abEditor->setCaption( tr("Edit Address") ); | 624 | abEditor->setCaption( tr("Edit Address") ); |
622 | 625 | ||
623 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 626 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
624 | abEditor->showMaximized(); | 627 | abEditor->showMaximized(); |
625 | #endif | 628 | #endif |
626 | // fix the foxus... | 629 | // fix the foxus... |
627 | abEditor->setNameFocus(); | 630 | abEditor->setNameFocus(); |
628 | if ( abEditor->exec() ) { | 631 | if ( abEditor->exec() ) { |
629 | setFocus(); | 632 | setFocus(); |
630 | if ( entryMode == NewEntry ) { | 633 | if ( entryMode == NewEntry ) { |
631 | Contact insertEntry = abEditor->entry(); | 634 | Contact insertEntry = abEditor->entry(); |
632 | insertEntry.assignUid(); | 635 | insertEntry.assignUid(); |
633 | abList->addEntry( insertEntry ); | 636 | abList->addEntry( insertEntry ); |
634 | } else { | 637 | } else { |
635 | Contact replaceEntry = abEditor->entry(); | 638 | Contact replaceEntry = abEditor->entry(); |
636 | if ( !replaceEntry.isValidUid() ) | 639 | if ( !replaceEntry.isValidUid() ) |
637 | replaceEntry.assignUid(); | 640 | replaceEntry.assignUid(); |
638 | abList->replaceCurrentEntry( replaceEntry ); | 641 | abList->replaceCurrentEntry( replaceEntry ); |
639 | } | 642 | } |
640 | } | 643 | } |
641 | populateCategories(); | 644 | populateCategories(); |
642 | showList(); | 645 | showList(); |
643 | } | 646 | } |
644 | 647 | ||
645 | void AddressbookWindow::listIsEmpty( bool empty ) | 648 | void AddressbookWindow::listIsEmpty( bool empty ) |
646 | { | 649 | { |
647 | if ( !empty ) { | 650 | if ( !empty ) { |
648 | deleteButton->setEnabled( TRUE ); | 651 | deleteButton->setEnabled( TRUE ); |
649 | } | 652 | } |
650 | } | 653 | } |
651 | 654 | ||
652 | void AddressbookWindow::reload() | 655 | void AddressbookWindow::reload() |
653 | { | 656 | { |
654 | syncing = FALSE; | 657 | syncing = FALSE; |
655 | abList->clear(); | 658 | abList->clear(); |
656 | abList->load( addressbookXMLFilename() ); | 659 | abList->load( addressbookXMLFilename() ); |
657 | } | 660 | } |
658 | 661 | ||
659 | void AddressbookWindow::flush() | 662 | void AddressbookWindow::flush() |
660 | { | 663 | { |
661 | syncing = TRUE; | 664 | syncing = TRUE; |
662 | abList->save( addressbookXMLFilename() ); | 665 | abList->save( addressbookXMLFilename() ); |
663 | } | 666 | } |
664 | 667 | ||
665 | 668 | ||
666 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 669 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
667 | { | 670 | { |
668 | if ( centralWidget() == mView ) { | 671 | if ( centralWidget() == mView ) { |
669 | if (actionPersonal->isOn()) { | 672 | if (actionPersonal->isOn()) { |
670 | // pretend we clicked it off | 673 | // pretend we clicked it off |
671 | actionPersonal->setOn(FALSE); | 674 | actionPersonal->setOn(FALSE); |
672 | slotPersonalView(); | 675 | slotPersonalView(); |
673 | } else { | 676 | } else { |
674 | showList(); | 677 | showList(); |
675 | } | 678 | } |
676 | e->ignore(); | 679 | e->ignore(); |
677 | return; | 680 | return; |
678 | } | 681 | } |
679 | 682 | ||
680 | if(syncing) { | 683 | if(syncing) { |
681 | /* shouldn't we save, I hear you say? well its already been set | 684 | /* shouldn't we save, I hear you say? well its already been set |
682 | so that an edit can not occur during a sync, and we flushed | 685 | so that an edit can not occur during a sync, and we flushed |
683 | at the start of the sync, so there is no need to save | 686 | at the start of the sync, so there is no need to save |
684 | Saving however itself would cause problems. */ | 687 | Saving however itself would cause problems. */ |
685 | e->accept(); | 688 | e->accept(); |
686 | return; | 689 | return; |
687 | } | 690 | } |
688 | //################## shouldn't always save | 691 | //################## shouldn't always save |
689 | if ( save() ) | 692 | if ( save() ) |
690 | e->accept(); | 693 | e->accept(); |
691 | else | 694 | else |
692 | e->ignore(); | 695 | e->ignore(); |
693 | } | 696 | } |
694 | 697 | ||
695 | /* | 698 | /* |
696 | Returns TRUE if it is OK to exit | 699 | Returns TRUE if it is OK to exit |
697 | */ | 700 | */ |
698 | 701 | ||
699 | bool AddressbookWindow::save() | 702 | bool AddressbookWindow::save() |
700 | { | 703 | { |
701 | QString str = addressbookXMLFilename(); | 704 | QString str = addressbookXMLFilename(); |
702 | if ( str.isNull() ) { | 705 | if ( str.isNull() ) { |
703 | if ( QMessageBox::critical( 0, tr("Out of space"), | 706 | if ( QMessageBox::critical( 0, tr("Out of space"), |
704 | tr("Unable to save information.\n" | 707 | tr("Unable to save information.\n" |
705 | "Free up some space\n" | 708 | "Free up some space\n" |
706 | "and try again.\n" | 709 | "and try again.\n" |
707 | "\nQuit anyway?"), | 710 | "\nQuit anyway?"), |
708 | QMessageBox::Yes|QMessageBox::Escape, | 711 | QMessageBox::Yes|QMessageBox::Escape, |
709 | QMessageBox::No|QMessageBox::Default ) | 712 | QMessageBox::No|QMessageBox::Default ) |
710 | != QMessageBox::No ) | 713 | != QMessageBox::No ) |
711 | return TRUE; | 714 | return TRUE; |
712 | else | 715 | else |
713 | return FALSE; | 716 | return FALSE; |
714 | } else { | 717 | } else { |
715 | if ( !abList->save( str ) ) { | 718 | if ( !abList->save( str ) ) { |
716 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 719 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
717 | tr("Unable to save information.\n" | 720 | tr("Unable to save information.\n" |
718 | "Free up some space\n" | 721 | "Free up some space\n" |
719 | "and try again.\n" | 722 | "and try again.\n" |
720 | "\nQuit anyway?"), | 723 | "\nQuit anyway?"), |
721 | QMessageBox::Yes|QMessageBox::Escape, | 724 | QMessageBox::Yes|QMessageBox::Escape, |
722 | QMessageBox::No|QMessageBox::Default ) | 725 | QMessageBox::No|QMessageBox::Default ) |
723 | != QMessageBox::No ) | 726 | != QMessageBox::No ) |
724 | return TRUE; | 727 | return TRUE; |
725 | else | 728 | else |
726 | return FALSE; | 729 | return FALSE; |
727 | } | 730 | } |
728 | } | 731 | } |
729 | return TRUE; | 732 | return TRUE; |
730 | } | 733 | } |
731 | 734 | ||
732 | void AddressbookWindow::slotSettings() | 735 | void AddressbookWindow::slotSettings() |
733 | { | 736 | { |
734 | AddressSettings frmSettings( this ); | 737 | AddressSettings frmSettings( this ); |
735 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 738 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
736 | frmSettings.showMaximized(); | 739 | frmSettings.showMaximized(); |
737 | #endif | 740 | #endif |
738 | 741 | ||
739 | if ( frmSettings.exec() ) { | 742 | if ( frmSettings.exec() ) { |
740 | allFields.clear(); | 743 | allFields.clear(); |
741 | orderedFields.clear(); | 744 | orderedFields.clear(); |
742 | slOrderedFields.clear(); | 745 | slOrderedFields.clear(); |
743 | initFields(); | 746 | initFields(); |
744 | if ( abEditor ) | 747 | if ( abEditor ) |
745 | abEditor->loadFields(); | 748 | abEditor->loadFields(); |
746 | abList->refresh(); | 749 | abList->refresh(); |
747 | } | 750 | } |
748 | } | 751 | } |
749 | 752 | ||
750 | 753 | ||
751 | void AddressbookWindow::initFields() | 754 | void AddressbookWindow::initFields() |
752 | { | 755 | { |
753 | // we really don't need the things from the configuration, anymore | 756 | // we really don't need the things from the configuration, anymore |
754 | // only thing that is important are the important categories. So, | 757 | // only thing that is important are the important categories. So, |
755 | // Call the contact functions that correspond to these old functions... | 758 | // Call the contact functions that correspond to these old functions... |
756 | 759 | ||
757 | QStringList xmlFields = Contact::fields(); | 760 | QStringList xmlFields = Contact::fields(); |
758 | QStringList visibleFields = Contact::trfields(); | 761 | QStringList visibleFields = Contact::trfields(); |
759 | xmlFields.remove( "Title" ); | 762 | xmlFields.remove( "Title" ); |
760 | visibleFields.remove( tr("Name Title") ); | 763 | visibleFields.remove( tr("Name Title") ); |
761 | visibleFields.remove( tr("Notes") ); | 764 | visibleFields.remove( tr("Notes") ); |
762 | 765 | ||
763 | int i, | 766 | int i, |
764 | version; | 767 | version; |
765 | Config cfg( "AddressBook" ); | 768 | Config cfg( "AddressBook" ); |
766 | QString zn; | 769 | QString zn; |
767 | 770 | ||
768 | // ### Write a function to keep this from happening again... | 771 | // ### Write a function to keep this from happening again... |
769 | QStringList::ConstIterator it; | 772 | QStringList::ConstIterator it; |
770 | for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { | 773 | for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { |
771 | allFields.append( i + 3 ); | 774 | allFields.append( i + 3 ); |
772 | } | 775 | } |
773 | 776 | ||
774 | cfg.setGroup( "Version" ); | 777 | cfg.setGroup( "Version" ); |
775 | version = cfg.readNumEntry( "version" ); | 778 | version = cfg.readNumEntry( "version" ); |
776 | i = 0; | 779 | i = 0; |
777 | startFontSize = 1; | 780 | startFontSize = 1; |
778 | 781 | ||
779 | if ( version >= ADDRESSVERSION ) { | 782 | if ( version >= ADDRESSVERSION ) { |
780 | 783 | ||
781 | cfg.setGroup( "ImportantCategory" ); | 784 | cfg.setGroup( "ImportantCategory" ); |
782 | 785 | ||
783 | zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); | 786 | zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); |
784 | while ( !zn.isNull() ) { | 787 | while ( !zn.isNull() ) { |
785 | if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) { | 788 | if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) { |
786 | slOrderedFields.clear(); | 789 | slOrderedFields.clear(); |
787 | break; | 790 | break; |
788 | } | 791 | } |
789 | slOrderedFields.append( zn ); | 792 | slOrderedFields.append( zn ); |
790 | zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); | 793 | zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); |
791 | } | 794 | } |
792 | cfg.setGroup( "Font" ); | 795 | cfg.setGroup( "Font" ); |
793 | startFontSize = cfg.readNumEntry( "fontSize", 1 ); | 796 | startFontSize = cfg.readNumEntry( "fontSize", 1 ); |
794 | 797 | ||
795 | 798 | ||
796 | } else { | 799 | } else { |
797 | QString str; | 800 | QString str; |
798 | str = getenv("HOME"); | 801 | str = getenv("HOME"); |
799 | str += "/Settings/AddressBook.conf"; | 802 | str += "/Settings/AddressBook.conf"; |
800 | QFile::remove( str ); | 803 | QFile::remove( str ); |
801 | } | 804 | } |
802 | if ( slOrderedFields.count() > 0 ) { | 805 | if ( slOrderedFields.count() > 0 ) { |
803 | for( QStringList::ConstIterator it = slOrderedFields.begin(); | 806 | for( QStringList::ConstIterator it = slOrderedFields.begin(); |
804 | it != slOrderedFields.end(); ++it ) { | 807 | it != slOrderedFields.end(); ++it ) { |
805 | QValueList<int>::ConstIterator itVl; | 808 | QValueList<int>::ConstIterator itVl; |
806 | QStringList::ConstIterator itVis; | 809 | QStringList::ConstIterator itVis; |
807 | itVl = allFields.begin(); | 810 | itVl = allFields.begin(); |
808 | for ( itVis = visibleFields.begin(); | 811 | for ( itVis = visibleFields.begin(); |
809 | itVis != visibleFields.end() && itVl != allFields.end(); | 812 | itVis != visibleFields.end() && itVl != allFields.end(); |
810 | ++itVis, ++itVl ) { | 813 | ++itVis, ++itVl ) { |
811 | if ( *it == *itVis && itVl != allFields.end() ) { | 814 | if ( *it == *itVis && itVl != allFields.end() ) { |
812 | orderedFields.append( *itVl ); | 815 | orderedFields.append( *itVl ); |
813 | } | 816 | } |
814 | } | 817 | } |
815 | } | 818 | } |
816 | } else { | 819 | } else { |
817 | QValueList<int>::ConstIterator it; | 820 | QValueList<int>::ConstIterator it; |
818 | for ( it = allFields.begin(); it != allFields.end(); ++it ) | 821 | for ( it = allFields.begin(); it != allFields.end(); ++it ) |
819 | orderedFields.append( *it ); | 822 | orderedFields.append( *it ); |
820 | 823 | ||
821 | slOrderedFields = visibleFields; | 824 | slOrderedFields = visibleFields; |
822 | orderedFields.remove( Qtopia::AddressUid ); | 825 | orderedFields.remove( Qtopia::AddressUid ); |
823 | orderedFields.remove( Qtopia::Title ); | 826 | orderedFields.remove( Qtopia::Title ); |
824 | orderedFields.remove( Qtopia::Groups ); | 827 | orderedFields.remove( Qtopia::Groups ); |
825 | orderedFields.remove( Qtopia::AddressCategory ); | 828 | orderedFields.remove( Qtopia::AddressCategory ); |
826 | orderedFields.remove( Qtopia::FirstName ); | 829 | orderedFields.remove( Qtopia::FirstName ); |
827 | orderedFields.remove( Qtopia::LastName ); | 830 | orderedFields.remove( Qtopia::LastName ); |
828 | orderedFields.remove( Qtopia::DefaultEmail ); | 831 | orderedFields.remove( Qtopia::DefaultEmail ); |
829 | orderedFields.remove( Qtopia::FileAs ); | 832 | orderedFields.remove( Qtopia::FileAs ); |
830 | orderedFields.remove( Qtopia::Notes ); | 833 | orderedFields.remove( Qtopia::Notes ); |
831 | orderedFields.remove( Qtopia::Gender ); | 834 | orderedFields.remove( Qtopia::Gender ); |
832 | slOrderedFields.remove( tr("Name Title") ); | 835 | slOrderedFields.remove( tr("Name Title") ); |
833 | slOrderedFields.remove( tr("First Name") ); | 836 | slOrderedFields.remove( tr("First Name") ); |
834 | slOrderedFields.remove( tr("Last Name") ); | 837 | slOrderedFields.remove( tr("Last Name") ); |
835 | slOrderedFields.remove( tr("File As") ); | 838 | slOrderedFields.remove( tr("File As") ); |
836 | slOrderedFields.remove( tr("Default Email") ); | 839 | slOrderedFields.remove( tr("Default Email") ); |
837 | slOrderedFields.remove( tr("Notes") ); | 840 | slOrderedFields.remove( tr("Notes") ); |
838 | slOrderedFields.remove( tr("Gender") ); | 841 | slOrderedFields.remove( tr("Gender") ); |
839 | 842 | ||
840 | } | 843 | } |
841 | } | 844 | } |
842 | 845 | ||
843 | 846 | ||
844 | AbLabel *AddressbookWindow::abView() | 847 | AbLabel *AddressbookWindow::abView() |
845 | { | 848 | { |
846 | if ( !mView ) { | 849 | if ( !mView ) { |
847 | mView = new AbLabel( this, "viewer" ); | 850 | mView = new AbLabel( this, "viewer" ); |
848 | mView->init( Contact() ); | 851 | mView->init( Contact() ); |
849 | connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); | 852 | connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); |
850 | } | 853 | } |
851 | return mView; | 854 | return mView; |
852 | } | 855 | } |
853 | 856 | ||
854 | void AddressbookWindow::slotFind() | 857 | void AddressbookWindow::slotFind() |
855 | { | 858 | { |
856 | #ifndef MAKE_FOR_SHARP_ROM | 859 | #ifndef MAKE_FOR_SHARP_ROM |
857 | if ( centralWidget() == abView() ) | 860 | if ( centralWidget() == abView() ) |
858 | showList(); | 861 | showList(); |
859 | 862 | ||
860 | FindDialog frmFind( "Contacts", this ); | 863 | FindDialog frmFind( "Contacts", this ); |
861 | QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); | 864 | QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); |
862 | QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); | 865 | QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); |
863 | QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); | 866 | QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); |
864 | 867 | ||
865 | frmFind.exec(); | 868 | frmFind.exec(); |
866 | 869 | ||
867 | if ( abList->numSelections() ) | 870 | if ( abList->numSelections() ) |
868 | abList->clearSelection(); | 871 | abList->clearSelection(); |
869 | 872 | ||
870 | abList->clearFindRow(); | 873 | abList->clearFindRow(); |
871 | #endif | 874 | #endif |
872 | } | 875 | } |
873 | 876 | ||
874 | void AddressbookWindow::slotSetCategory( int c ) | 877 | void AddressbookWindow::slotSetCategory( int c ) |
875 | { | 878 | { |
876 | if ( c <= 0 ) | 879 | if ( c <= 0 ) |
877 | return; | 880 | return; |
878 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) | 881 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) |
879 | catMenu->setItemChecked( i, c == (int)i ); | 882 | catMenu->setItemChecked( i, c == (int)i ); |
880 | if ( c == 1 ) { | 883 | if ( c == 1 ) { |
881 | abList->setShowCategory( QString::null ); | 884 | abList->setShowCategory( QString::null ); |
882 | setCaption( tr("Contacts") + " - " + tr ( "All" ) ); | 885 | setCaption( tr("Contacts") + " - " + tr ( "All" ) ); |
883 | } else if ( c == (int)catMenu->count() ) { | 886 | } else if ( c == (int)catMenu->count() ) { |
884 | abList->setShowCategory( tr( "Unfiled" ) ); | 887 | abList->setShowCategory( tr( "Unfiled" ) ); |
885 | setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); | 888 | setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); |
886 | } else { | 889 | } else { |
887 | QString cat = abList->categories()[c - 2]; | 890 | QString cat = abList->categories()[c - 2]; |
888 | abList->setShowCategory( cat ); | 891 | abList->setShowCategory( cat ); |
889 | setCaption( tr("Contacts") + " - " + cat ); | 892 | setCaption( tr("Contacts") + " - " + cat ); |
890 | } | 893 | } |
891 | } | 894 | } |
892 | 895 | ||
893 | void AddressbookWindow::slotSetLetter( char c ) { | 896 | void AddressbookWindow::slotSetLetter( char c ) { |
894 | 897 | ||
895 | abList->setShowByLetter( c ); | 898 | abList->setShowByLetter( c ); |
896 | 899 | ||
897 | } | 900 | } |
898 | 901 | ||
899 | void AddressbookWindow::populateCategories() | 902 | void AddressbookWindow::populateCategories() |
900 | { | 903 | { |
901 | catMenu->clear(); | 904 | catMenu->clear(); |
902 | 905 | ||
903 | int id, | 906 | int id, |
904 | rememberId; | 907 | rememberId; |
905 | id = 1; | 908 | id = 1; |
906 | catMenu->insertItem( tr( "All" ), id++ ); | 909 | catMenu->insertItem( tr( "All" ), id++ ); |
907 | QStringList categories = abList->categories(); | 910 | QStringList categories = abList->categories(); |
908 | categories.append( tr( "Unfiled" ) ); | 911 | categories.append( tr( "Unfiled" ) ); |
909 | for ( QStringList::Iterator it = categories.begin(); | 912 | for ( QStringList::Iterator it = categories.begin(); |
910 | it != categories.end(); ++it ) { | 913 | it != categories.end(); ++it ) { |
911 | catMenu->insertItem( *it, id ); | 914 | catMenu->insertItem( *it, id ); |
912 | if ( *it == abList->showCategory() ) | 915 | if ( *it == abList->showCategory() ) |
913 | rememberId = id; | 916 | rememberId = id; |
914 | ++id; | 917 | ++id; |
915 | } | 918 | } |
916 | if ( abList->showCategory().isEmpty() ) | 919 | if ( abList->showCategory().isEmpty() ) |
917 | slotSetCategory( 1 ); | 920 | slotSetCategory( 1 ); |
918 | else | 921 | else |
919 | slotSetCategory( rememberId ); | 922 | slotSetCategory( rememberId ); |
920 | } | 923 | } |
diff --git a/core/pim/addressbook/addressbook.h b/core/pim/addressbook/addressbook.h index 31c4660..8e8c883 100644 --- a/core/pim/addressbook/addressbook.h +++ b/core/pim/addressbook/addressbook.h | |||
@@ -1,104 +1,105 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef Addressbook_H | 20 | #ifndef Addressbook_H |
21 | #define Addressbook_H | 21 | #define Addressbook_H |
22 | 22 | ||
23 | #include <qmainwindow.h> | 23 | #include <qmainwindow.h> |
24 | 24 | ||
25 | class ContactEditor; | 25 | class ContactEditor; |
26 | class AbLabel; | 26 | class AbLabel; |
27 | class AbTable; | 27 | class AbTable; |
28 | class QPEToolBar; | 28 | class QPEToolBar; |
29 | class QPopupMenu; | 29 | class QPopupMenu; |
30 | class QToolButton; | 30 | class QToolButton; |
31 | class QDialog; | 31 | class QDialog; |
32 | class Ir; | 32 | class Ir; |
33 | class QAction; | 33 | class QAction; |
34 | class LetterPicker; | 34 | class LetterPicker; |
35 | 35 | ||
36 | class AddressbookWindow: public QMainWindow | 36 | class AddressbookWindow: public QMainWindow |
37 | { | 37 | { |
38 | Q_OBJECT | 38 | Q_OBJECT |
39 | public: | 39 | public: |
40 | AddressbookWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 40 | AddressbookWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
41 | ~AddressbookWindow(); | 41 | ~AddressbookWindow(); |
42 | 42 | ||
43 | protected: | 43 | protected: |
44 | void resizeEvent( QResizeEvent * e ); | 44 | void resizeEvent( QResizeEvent * e ); |
45 | void showList(); | 45 | void showList(); |
46 | void showView(); | 46 | void showView(); |
47 | enum EntryMode { NewEntry=0, EditEntry }; | 47 | enum EntryMode { NewEntry=0, EditEntry }; |
48 | void editPersonal(); | 48 | void editPersonal(); |
49 | void editEntry( EntryMode ); | 49 | void editEntry( EntryMode ); |
50 | void closeEvent( QCloseEvent *e ); | 50 | void closeEvent( QCloseEvent *e ); |
51 | bool save(); | 51 | bool save(); |
52 | 52 | ||
53 | public slots: | 53 | public slots: |
54 | void flush(); | 54 | void flush(); |
55 | void reload(); | 55 | void reload(); |
56 | void appMessage(const QCString &, const QByteArray &); | 56 | void appMessage(const QCString &, const QByteArray &); |
57 | void setDocument( const QString & ); | 57 | void setDocument( const QString & ); |
58 | 58 | ||
59 | private slots: | 59 | private slots: |
60 | void slotListNew(); | 60 | void slotListNew(); |
61 | void slotListView(); | 61 | void slotListView(); |
62 | void slotListDelete(); | 62 | void slotListDelete(); |
63 | void slotViewBack(); | 63 | void slotViewBack(); |
64 | void slotViewEdit(); | 64 | void slotViewEdit(); |
65 | void slotPersonalView(); | 65 | void slotPersonalView(); |
66 | void listIsEmpty( bool ); | 66 | void listIsEmpty( bool ); |
67 | void slotSettings(); | 67 | void slotSettings(); |
68 | void writeMail(); | 68 | void writeMail(); |
69 | void slotBeam(); | 69 | void slotBeam(); |
70 | void beamDone( Ir * ); | 70 | void beamDone( Ir * ); |
71 | void slotFind(); | 71 | void slotFind(); |
72 | void slotSetCategory( int ); | 72 | void slotSetCategory( int ); |
73 | void slotSetLetter( char ); | 73 | void slotSetLetter( char ); |
74 | void slotUpdateToolbar(); | 74 | void slotUpdateToolbar(); |
75 | void slotSetFont(int); | 75 | void slotSetFont(int); |
76 | private: | 76 | private: |
77 | void initFields();// inititialize our fields... | 77 | void initFields();// inititialize our fields... |
78 | AbLabel *abView(); | 78 | AbLabel *abView(); |
79 | void populateCategories(); | 79 | void populateCategories(); |
80 | 80 | ||
81 | QPopupMenu *catMenu, *fontMenu; | 81 | QPopupMenu *catMenu, *fontMenu; |
82 | QPEToolBar *listTools; | 82 | QPEToolBar *listTools; |
83 | QToolButton *deleteButton; | 83 | QToolButton *deleteButton; |
84 | QValueList<int> allFields, | 84 | QValueList<int> allFields, |
85 | orderedFields; | 85 | orderedFields; |
86 | QStringList slOrderedFields; | 86 | QStringList slOrderedFields; |
87 | enum Panes { paneList=0, paneView, paneEdit }; | 87 | enum Panes { paneList=0, paneView, paneEdit }; |
88 | ContactEditor *abEditor; | 88 | ContactEditor *abEditor; |
89 | AbLabel *mView; | 89 | AbLabel *mView; |
90 | LetterPicker *pLabel; | 90 | LetterPicker *pLabel; |
91 | AbTable *abList; | 91 | AbTable *abList; |
92 | QWidget *listContainer; | ||
92 | 93 | ||
93 | QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, | 94 | QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, |
94 | *actionPersonal, *actionMail; | 95 | *actionPersonal, *actionMail; |
95 | 96 | ||
96 | bool bAbEditFirstTime; | 97 | bool bAbEditFirstTime; |
97 | int viewMargin; | 98 | int viewMargin; |
98 | 99 | ||
99 | bool syncing; | 100 | bool syncing; |
100 | QFont *defaultFont; | 101 | QFont *defaultFont; |
101 | int startFontSize; | 102 | int startFontSize; |
102 | }; | 103 | }; |
103 | 104 | ||
104 | #endif | 105 | #endif |
diff --git a/core/pim/addressbook/picker.cpp b/core/pim/addressbook/picker.cpp index 06dcc7d..a165451 100644 --- a/core/pim/addressbook/picker.cpp +++ b/core/pim/addressbook/picker.cpp | |||
@@ -1,234 +1,229 @@ | |||
1 | #include "picker.h" | 1 | #include "picker.h" |
2 | 2 | ||
3 | #include <qfont.h> | 3 | #include <qfont.h> |
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qtimer.h> | 5 | #include <qtimer.h> |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | 7 | ||
8 | char PickerLabel::lastLetter = '\0'; | 8 | char PickerLabel::lastLetter = '\0'; |
9 | 9 | ||
10 | PickerLabel::PickerLabel( QWidget *parent, const char *name ) | 10 | PickerLabel::PickerLabel( QWidget *parent, const char *name ) |
11 | : QLabel ( parent, name ) | 11 | : QLabel ( parent, name ) |
12 | { | 12 | { |
13 | currentLetter = 0; | 13 | currentLetter = 0; |
14 | //lastLetter = 0; | 14 | //lastLetter = 0; |
15 | 15 | ||
16 | letter1 = '\0'; | 16 | letter1 = '\0'; |
17 | letter2 = '\0'; | 17 | letter2 = '\0'; |
18 | letter3 = '\0'; | 18 | letter3 = '\0'; |
19 | 19 | ||
20 | setFont( QFont( "smallsmooth", 9 ) ); | 20 | setFont( QFont( "smallsmooth", 9 ) ); |
21 | setTextFormat( Qt::RichText ); | 21 | setTextFormat( Qt::RichText ); |
22 | 22 | ||
23 | } | 23 | } |
24 | 24 | ||
25 | PickerLabel::~PickerLabel() | 25 | PickerLabel::~PickerLabel() |
26 | { | 26 | { |
27 | 27 | ||
28 | } | 28 | } |
29 | 29 | ||
30 | void PickerLabel::setLetters( char ch1, char ch2, char ch3 ) | 30 | void PickerLabel::setLetters( char ch1, char ch2, char ch3 ) |
31 | { | 31 | { |
32 | QString tmpStr; | 32 | QString tmpStr; |
33 | 33 | ||
34 | if (ch1 != '\0') | 34 | if (ch1 != '\0') |
35 | letter1 = ch1; | 35 | letter1 = ch1; |
36 | else | 36 | else |
37 | letter1 = ' '; | 37 | letter1 = ' '; |
38 | 38 | ||
39 | if (ch2 != '\0') | 39 | if (ch2 != '\0') |
40 | letter2 = ch2; | 40 | letter2 = ch2; |
41 | else | 41 | else |
42 | letter2 = ' '; | 42 | letter2 = ' '; |
43 | 43 | ||
44 | if (ch3 != '\0') | 44 | if (ch3 != '\0') |
45 | letter3 = ch3; | 45 | letter3 = ch3; |
46 | else | 46 | else |
47 | letter3 = ' '; | 47 | letter3 = ' '; |
48 | 48 | ||
49 | tmpStr = "<qt>"; | 49 | tmpStr = "<qt>"; |
50 | tmpStr += letter1; | 50 | tmpStr += letter1; |
51 | tmpStr += letter2; | 51 | tmpStr += letter2; |
52 | tmpStr += letter3; | 52 | tmpStr += letter3; |
53 | tmpStr += "</qt>"; | 53 | tmpStr += "</qt>"; |
54 | 54 | ||
55 | setText(tmpStr); | 55 | setText(tmpStr); |
56 | 56 | ||
57 | currentLetter = 0; | 57 | currentLetter = 0; |
58 | 58 | ||
59 | } | 59 | } |
60 | 60 | ||
61 | void PickerLabel::clearLetter() | 61 | void PickerLabel::clearLetter() |
62 | { | 62 | { |
63 | 63 | ||
64 | QString tmpStr; | 64 | QString tmpStr; |
65 | 65 | ||
66 | tmpStr = "<qt>"; | 66 | tmpStr = "<qt>"; |
67 | tmpStr += letter1; | 67 | tmpStr += letter1; |
68 | tmpStr += letter2; | 68 | tmpStr += letter2; |
69 | tmpStr += letter3; | 69 | tmpStr += letter3; |
70 | tmpStr += "</qt>"; | 70 | tmpStr += "</qt>"; |
71 | 71 | ||
72 | setText(tmpStr); | 72 | setText(tmpStr); |
73 | 73 | ||
74 | currentLetter = 0; | 74 | currentLetter = 0; |
75 | 75 | ||
76 | } | 76 | } |
77 | 77 | ||
78 | void PickerLabel::mouseReleaseEvent( QMouseEvent *e ) | 78 | void PickerLabel::mouseReleaseEvent( QMouseEvent *e ) |
79 | { | 79 | { |
80 | QString tmpStr; | 80 | QString tmpStr; |
81 | 81 | ||
82 | if (lastLetter != letter1 && lastLetter != letter2 && lastLetter != letter3) | 82 | if (lastLetter != letter1 && lastLetter != letter2 && lastLetter != letter3 && lastLetter != '\0') |
83 | QTimer::singleShot( 0, this, SLOT(emitClearSignal()) ); | 83 | QTimer::singleShot( 0, this, SLOT(emitClearSignal()) ); |
84 | 84 | ||
85 | qDebug( "a" ); | ||
86 | switch (currentLetter) { | 85 | switch (currentLetter) { |
87 | case 0: | 86 | case 0: |
88 | tmpStr = "<qt><font color=\"#7F0000\">"; | 87 | tmpStr = "<qt><font color=\"#7F0000\">"; |
89 | tmpStr += letter1; | 88 | tmpStr += letter1; |
90 | tmpStr += "</font>"; | 89 | tmpStr += "</font>"; |
91 | tmpStr += letter2; | 90 | tmpStr += letter2; |
92 | tmpStr += letter3; | 91 | tmpStr += letter3; |
93 | tmpStr += "</qt>"; | 92 | tmpStr += "</qt>"; |
94 | 93 | ||
95 | setText(tmpStr); | 94 | setText(tmpStr); |
96 | 95 | ||
97 | currentLetter++; | 96 | currentLetter++; |
98 | lastLetter = letter1; | 97 | lastLetter = letter1; |
99 | emit selectedLetter( letter1 ); | 98 | emit selectedLetter( letter1 ); |
100 | qDebug( "PickerLabel::mouseReleaseEvent %c", letter1 ); | ||
101 | break; | 99 | break; |
102 | 100 | ||
103 | case 1: | 101 | case 1: |
104 | tmpStr = "<qt>"; | 102 | tmpStr = "<qt>"; |
105 | tmpStr += letter1; | 103 | tmpStr += letter1; |
106 | tmpStr += "<font color=\"#7F0000\">"; | 104 | tmpStr += "<font color=\"#7F0000\">"; |
107 | tmpStr += letter2; | 105 | tmpStr += letter2; |
108 | tmpStr += "</font>"; | 106 | tmpStr += "</font>"; |
109 | tmpStr += letter3; | 107 | tmpStr += letter3; |
110 | tmpStr += "</qt>"; | 108 | tmpStr += "</qt>"; |
111 | 109 | ||
112 | setText(tmpStr); | 110 | setText(tmpStr); |
113 | 111 | ||
114 | currentLetter++; | 112 | currentLetter++; |
115 | lastLetter = letter2; | 113 | lastLetter = letter2; |
116 | emit selectedLetter( letter2 ); | 114 | emit selectedLetter( letter2 ); |
117 | qDebug( "PickerLabel::mouseReleaseEvent %c", letter2 ); | ||
118 | break; | 115 | break; |
119 | 116 | ||
120 | case 2: | 117 | case 2: |
121 | tmpStr = "<qt>"; | 118 | tmpStr = "<qt>"; |
122 | tmpStr += letter1; | 119 | tmpStr += letter1; |
123 | tmpStr += letter2; | 120 | tmpStr += letter2; |
124 | tmpStr += "<font color=\"#7F0000\">"; | 121 | tmpStr += "<font color=\"#7F0000\">"; |
125 | tmpStr += letter3; | 122 | tmpStr += letter3; |
126 | tmpStr += "</font></qt>"; | 123 | tmpStr += "</font></qt>"; |
127 | 124 | ||
128 | setText(tmpStr); | 125 | setText(tmpStr); |
129 | 126 | ||
130 | currentLetter++; | 127 | currentLetter++; |
131 | lastLetter = letter3; | 128 | lastLetter = letter3; |
132 | emit selectedLetter( letter3 ); | 129 | emit selectedLetter( letter3 ); |
133 | qDebug( "PickerLabel::mouseReleaseEvent %c", letter3 ); | ||
134 | break; | 130 | break; |
135 | 131 | ||
136 | default: | 132 | default: |
137 | clearLetter(); | 133 | clearLetter(); |
138 | lastLetter = '\0'; | 134 | lastLetter = '\0'; |
139 | emit selectedLetter( '\0' ); | 135 | emit selectedLetter( '\0' ); |
140 | 136 | ||
141 | 137 | ||
142 | } | 138 | } |
143 | } | 139 | } |
144 | 140 | ||
145 | void PickerLabel::emitClearSignal() { | 141 | void PickerLabel::emitClearSignal() { |
146 | emit clearAll(); | 142 | emit clearAll(); |
147 | } | 143 | } |
148 | 144 | ||
149 | LetterPicker::LetterPicker( QWidget *parent, const char *name ) | 145 | LetterPicker::LetterPicker( QWidget *parent, const char *name ) |
150 | : QFrame( parent, name ) | 146 | : QFrame( parent, name ) |
151 | { | 147 | { |
152 | QHBoxLayout *l = new QHBoxLayout(this); | 148 | QHBoxLayout *l = new QHBoxLayout(this); |
153 | 149 | ||
154 | lblABC = new PickerLabel( this ); | 150 | lblABC = new PickerLabel( this ); |
155 | l->addWidget( lblABC ); | 151 | l->addWidget( lblABC ); |
156 | 152 | ||
157 | lblDEF = new PickerLabel( this ); | 153 | lblDEF = new PickerLabel( this ); |
158 | l->addWidget( lblDEF ); | 154 | l->addWidget( lblDEF ); |
159 | 155 | ||
160 | lblGHI = new PickerLabel( this ); | 156 | lblGHI = new PickerLabel( this ); |
161 | l->addWidget( lblGHI ); | 157 | l->addWidget( lblGHI ); |
162 | 158 | ||
163 | lblJKL = new PickerLabel( this ); | 159 | lblJKL = new PickerLabel( this ); |
164 | l->addWidget( lblJKL ); | 160 | l->addWidget( lblJKL ); |
165 | 161 | ||
166 | lblMNO = new PickerLabel( this ); | 162 | lblMNO = new PickerLabel( this ); |
167 | l->addWidget( lblMNO ); | 163 | l->addWidget( lblMNO ); |
168 | 164 | ||
169 | lblPQR = new PickerLabel( this ); | 165 | lblPQR = new PickerLabel( this ); |
170 | l->addWidget( lblPQR ); | 166 | l->addWidget( lblPQR ); |
171 | 167 | ||
172 | lblSTU = new PickerLabel( this ); | 168 | lblSTU = new PickerLabel( this ); |
173 | l->addWidget( lblSTU ); | 169 | l->addWidget( lblSTU ); |
174 | 170 | ||
175 | lblVWX = new PickerLabel( this ); | 171 | lblVWX = new PickerLabel( this ); |
176 | l->addWidget( lblVWX ); | 172 | l->addWidget( lblVWX ); |
177 | 173 | ||
178 | lblYZ = new PickerLabel( this ); | 174 | lblYZ = new PickerLabel( this ); |
179 | l->addWidget( lblYZ ); | 175 | l->addWidget( lblYZ ); |
180 | 176 | ||
181 | lblABC->setLetters( 'A', 'B', 'C' ); | 177 | lblABC->setLetters( 'A', 'B', 'C' ); |
182 | lblDEF->setLetters( 'D', 'E', 'F' ); | 178 | lblDEF->setLetters( 'D', 'E', 'F' ); |
183 | lblGHI->setLetters( 'G', 'H', 'I' ); | 179 | lblGHI->setLetters( 'G', 'H', 'I' ); |
184 | lblJKL->setLetters( 'J', 'K', 'L' ); | 180 | lblJKL->setLetters( 'J', 'K', 'L' ); |
185 | lblMNO->setLetters( 'M', 'N', 'O' ); | 181 | lblMNO->setLetters( 'M', 'N', 'O' ); |
186 | lblPQR->setLetters( 'P', 'Q', 'R' ); | 182 | lblPQR->setLetters( 'P', 'Q', 'R' ); |
187 | lblSTU->setLetters( 'S', 'T', 'U' ); | 183 | lblSTU->setLetters( 'S', 'T', 'U' ); |
188 | lblVWX->setLetters( 'V', 'W', 'X' ); | 184 | lblVWX->setLetters( 'V', 'W', 'X' ); |
189 | lblYZ->setLetters( 'Y', 'Z', '#' ); | 185 | lblYZ->setLetters( 'Y', 'Z', '#' ); |
190 | 186 | ||
191 | connect(lblABC, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 187 | connect(lblABC, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
192 | connect(lblDEF, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 188 | connect(lblDEF, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
193 | connect(lblGHI, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 189 | connect(lblGHI, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
194 | connect(lblJKL, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 190 | connect(lblJKL, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
195 | connect(lblMNO, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 191 | connect(lblMNO, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
196 | connect(lblPQR, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 192 | connect(lblPQR, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
197 | connect(lblSTU, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 193 | connect(lblSTU, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
198 | connect(lblVWX, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 194 | connect(lblVWX, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
199 | connect(lblYZ, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); | 195 | connect(lblYZ, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); |
200 | connect(lblABC, SIGNAL(clearAll()), this, SLOT(clear())); | 196 | connect(lblABC, SIGNAL(clearAll()), this, SLOT(clear())); |
201 | connect(lblDEF, SIGNAL(clearAll()), this, SLOT(clear())); | 197 | connect(lblDEF, SIGNAL(clearAll()), this, SLOT(clear())); |
202 | connect(lblGHI, SIGNAL(clearAll()), this, SLOT(clear())); | 198 | connect(lblGHI, SIGNAL(clearAll()), this, SLOT(clear())); |
203 | connect(lblJKL, SIGNAL(clearAll()), this, SLOT(clear())); | 199 | connect(lblJKL, SIGNAL(clearAll()), this, SLOT(clear())); |
204 | connect(lblMNO, SIGNAL(clearAll()), this, SLOT(clear())); | 200 | connect(lblMNO, SIGNAL(clearAll()), this, SLOT(clear())); |
205 | connect(lblPQR, SIGNAL(clearAll()), this, SLOT(clear())); | 201 | connect(lblPQR, SIGNAL(clearAll()), this, SLOT(clear())); |
206 | connect(lblSTU, SIGNAL(clearAll()), this, SLOT(clear())); | 202 | connect(lblSTU, SIGNAL(clearAll()), this, SLOT(clear())); |
207 | connect(lblVWX, SIGNAL(clearAll()), this, SLOT(clear())); | 203 | connect(lblVWX, SIGNAL(clearAll()), this, SLOT(clear())); |
208 | connect(lblYZ, SIGNAL(clearAll()), this, SLOT(clear())); | 204 | connect(lblYZ, SIGNAL(clearAll()), this, SLOT(clear())); |
209 | 205 | ||
210 | } | 206 | } |
211 | 207 | ||
212 | LetterPicker::~LetterPicker() | 208 | LetterPicker::~LetterPicker() |
213 | { | 209 | { |
214 | } | 210 | } |
215 | 211 | ||
216 | void LetterPicker::clear() | 212 | void LetterPicker::clear() |
217 | { | 213 | { |
218 | lblABC->clearLetter(); | 214 | lblABC->clearLetter(); |
219 | lblDEF->clearLetter(); | 215 | lblDEF->clearLetter(); |
220 | lblGHI->clearLetter(); | 216 | lblGHI->clearLetter(); |
221 | lblJKL->clearLetter(); | 217 | lblJKL->clearLetter(); |
222 | lblMNO->clearLetter(); | 218 | lblMNO->clearLetter(); |
223 | lblPQR->clearLetter(); | 219 | lblPQR->clearLetter(); |
224 | lblSTU->clearLetter(); | 220 | lblSTU->clearLetter(); |
225 | lblVWX->clearLetter(); | 221 | lblVWX->clearLetter(); |
226 | lblYZ->clearLetter(); | 222 | lblYZ->clearLetter(); |
227 | } | 223 | } |
228 | 224 | ||
229 | void LetterPicker::newLetter( char letter ) | 225 | void LetterPicker::newLetter( char letter ) |
230 | { | 226 | { |
231 | qDebug( "LetterPicker::newLetter %c", letter ); | ||
232 | emit letterClicked( letter ); | 227 | emit letterClicked( letter ); |
233 | 228 | ||
234 | } | 229 | } |