author | eilers <eilers> | 2002-11-27 15:21:06 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-11-27 15:21:06 (UTC) |
commit | 4b20972da142bbdea42c682025ab5303c35a5a92 (patch) (unidiff) | |
tree | 934acaec747a495188a7d3c1e125ecc0776b68c6 | |
parent | 4d7272423782dc2f9f7dbde36b848f55eb323c79 (diff) | |
download | opie-4b20972da142bbdea42c682025ab5303c35a5a92.zip opie-4b20972da142bbdea42c682025ab5303c35a5a92.tar.gz opie-4b20972da142bbdea42c682025ab5303c35a5a92.tar.bz2 |
Extremely improved table update
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 55 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 3 | ||||
-rw-r--r-- | core/pim/addressbook/abview.cpp | 72 | ||||
-rw-r--r-- | core/pim/addressbook/abview.h | 3 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 46 |
5 files changed, 109 insertions, 70 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index e333b17..00335ae 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -1,714 +1,747 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of Qt Palmtop Environment. | 5 | ** This file is part of Qt Palmtop Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
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 | #include <qpe/timestring.h> | 27 | #include <qpe/timestring.h> |
28 | 28 | ||
29 | #include <opie/orecordlist.h> | 29 | #include <opie/orecordlist.h> |
30 | 30 | ||
31 | #include <qasciidict.h> | 31 | #include <qasciidict.h> |
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | 36 | ||
37 | #include "abtable.h" | 37 | #include "abtable.h" |
38 | 38 | ||
39 | #include <errno.h> | 39 | #include <errno.h> |
40 | #include <fcntl.h> | 40 | #include <fcntl.h> |
41 | #include <unistd.h> | 41 | #include <unistd.h> |
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | 43 | ||
44 | #include <ctype.h> //toupper() for key hack | 44 | #include <ctype.h> //toupper() for key hack |
45 | 45 | ||
46 | /*! | 46 | /*! |
47 | \class AbTableItem abtable.h | 47 | \class AbTableItem abtable.h |
48 | 48 | ||
49 | \brief QTableItem based class for showing a field of an entry | 49 | \brief QTableItem based class for showing a field of an entry |
50 | */ | 50 | */ |
51 | 51 | ||
52 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, | 52 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, |
53 | const QString &secondSortKey) | 53 | const QString &secondSortKey) |
54 | : QTableItem( t, et, s ) | 54 | : QTableItem( t, et, s ) |
55 | { | 55 | { |
56 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); | 56 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); |
57 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); | 57 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); |
58 | } | 58 | } |
59 | 59 | ||
60 | int AbTableItem::alignment() const | 60 | int AbTableItem::alignment() const |
61 | { | 61 | { |
62 | return AlignLeft|AlignVCenter; | 62 | return AlignLeft|AlignVCenter; |
63 | } | 63 | } |
64 | 64 | ||
65 | QString AbTableItem::key() const | 65 | QString AbTableItem::key() const |
66 | { | 66 | { |
67 | return sortKey; | 67 | return sortKey; |
68 | } | 68 | } |
69 | 69 | ||
70 | // A way to reset the item, without out doing a delete or a new... | 70 | // A way to reset the item, without out doing a delete or a new... |
71 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) | 71 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) |
72 | { | 72 | { |
73 | setText( txt ); | 73 | setText( txt ); |
74 | sortKey = Qtopia::buildSortKey( txt, secondKey ); | 74 | sortKey = Qtopia::buildSortKey( txt, secondKey ); |
75 | 75 | ||
76 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); | 76 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); |
77 | } | 77 | } |
78 | 78 | ||
79 | /*! | 79 | /*! |
80 | \class AbPickItem abtable.h | 80 | \class AbPickItem abtable.h |
81 | 81 | ||
82 | \brief QTableItem based class for showing slection of an entry | 82 | \brief QTableItem based class for showing slection of an entry |
83 | */ | 83 | */ |
84 | 84 | ||
85 | AbPickItem::AbPickItem( QTable *t ) : | 85 | AbPickItem::AbPickItem( QTable *t ) : |
86 | QTableItem(t, WhenCurrent, "?") | 86 | QTableItem(t, WhenCurrent, "?") |
87 | { | 87 | { |
88 | } | 88 | } |
89 | 89 | ||
90 | QWidget *AbPickItem::createEditor() const | 90 | QWidget *AbPickItem::createEditor() const |
91 | { | 91 | { |
92 | QComboBox* combo = new QComboBox( table()->viewport() ); | 92 | QComboBox* combo = new QComboBox( table()->viewport() ); |
93 | ( (AbPickItem*)this )->cb = combo; | 93 | ( (AbPickItem*)this )->cb = combo; |
94 | AbTable* t = static_cast<AbTable*>(table()); | 94 | AbTable* t = static_cast<AbTable*>(table()); |
95 | QStringList c = t->choiceNames(); | 95 | QStringList c = t->choiceNames(); |
96 | int cur = 0; | 96 | int cur = 0; |
97 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { | 97 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { |
98 | if ( *it == text() ) | 98 | if ( *it == text() ) |
99 | cur = combo->count(); | 99 | cur = combo->count(); |
100 | combo->insertItem(*it); | 100 | combo->insertItem(*it); |
101 | } | 101 | } |
102 | combo->setCurrentItem(cur); | 102 | combo->setCurrentItem(cur); |
103 | return combo; | 103 | return combo; |
104 | } | 104 | } |
105 | 105 | ||
106 | void AbPickItem::setContentFromEditor( QWidget *w ) | 106 | void AbPickItem::setContentFromEditor( QWidget *w ) |
107 | { | 107 | { |
108 | if ( w->inherits("QComboBox") ) | 108 | if ( w->inherits("QComboBox") ) |
109 | setText( ( (QComboBox*)w )->currentText() ); | 109 | setText( ( (QComboBox*)w )->currentText() ); |
110 | else | 110 | else |
111 | QTableItem::setContentFromEditor( w ); | 111 | QTableItem::setContentFromEditor( w ); |
112 | } | 112 | } |
113 | 113 | ||
114 | /*! | 114 | /*! |
115 | \class AbTable abtable.h | 115 | \class AbTable abtable.h |
116 | 116 | ||
117 | \brief QTable based class for showing a list of entries | 117 | \brief QTable based class for showing a list of entries |
118 | */ | 118 | */ |
119 | 119 | ||
120 | AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) | 120 | AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) |
121 | : QTable( parent, name ), | 121 | : QTable( parent, name ), |
122 | lastSortCol( -1 ), | 122 | lastSortCol( -1 ), |
123 | asc( TRUE ), | 123 | asc( TRUE ), |
124 | intFields( order ), | 124 | intFields( order ), |
125 | enablePainting( true ), | 125 | enablePainting( true ), |
126 | columnVisible( true ) | 126 | columnVisible( true ), |
127 | countNested( 0 ) | ||
127 | { | 128 | { |
128 | qWarning("C'tor start"); | 129 | qWarning("C'tor start"); |
129 | 130 | ||
130 | setSelectionMode( NoSelection ); | 131 | setSelectionMode( NoSelection ); |
131 | init(); | 132 | init(); |
132 | setSorting( TRUE ); | 133 | setSorting( TRUE ); |
133 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 134 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
134 | this, SLOT(itemClicked(int,int)) ); | 135 | this, SLOT(itemClicked(int,int)) ); |
135 | 136 | ||
136 | contactList.clear(); | 137 | contactList.clear(); |
137 | qWarning("C'tor end"); | 138 | qWarning("C'tor end"); |
138 | } | 139 | } |
139 | 140 | ||
140 | AbTable::~AbTable() | 141 | AbTable::~AbTable() |
141 | { | 142 | { |
142 | } | 143 | } |
143 | 144 | ||
144 | void AbTable::init() | 145 | void AbTable::init() |
145 | { | 146 | { |
146 | // :SX showChar = '\0'; | 147 | // :SX showChar = '\0'; |
147 | setNumRows( 0 ); | 148 | setNumRows( 0 ); |
148 | setNumCols( 2 ); | 149 | setNumCols( 2 ); |
149 | 150 | ||
150 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); | 151 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); |
151 | horizontalHeader()->setLabel( 1, tr( "Contact" )); | 152 | horizontalHeader()->setLabel( 1, tr( "Contact" )); |
152 | setLeftMargin( 0 ); | 153 | setLeftMargin( 0 ); |
153 | verticalHeader()->hide(); | 154 | verticalHeader()->hide(); |
154 | columnVisible = true; | 155 | columnVisible = true; |
155 | } | 156 | } |
156 | 157 | ||
157 | void AbTable::setContacts( const OContactAccess::List& viewList ) | 158 | void AbTable::setContacts( const OContactAccess::List& viewList ) |
158 | { | 159 | { |
159 | qWarning("AbTable::setContacts()"); | 160 | qWarning("AbTable::setContacts()"); |
160 | 161 | ||
161 | clear(); | 162 | clear(); |
162 | m_viewList = viewList; | 163 | m_viewList = viewList; |
163 | 164 | ||
164 | setSorting( false ); | 165 | setSorting( false ); |
165 | setUpdatesEnabled( FALSE ); | 166 | setPaintingEnabled( FALSE ); |
166 | 167 | ||
167 | OContactAccess::List::Iterator it; | 168 | OContactAccess::List::Iterator it; |
168 | setNumRows( m_viewList.count() ); | 169 | setNumRows( m_viewList.count() ); |
169 | int row = 0; | 170 | int row = 0; |
170 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) | 171 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) |
171 | insertIntoTable( *it, row++ ); | 172 | insertIntoTable( *it, row++ ); |
172 | 173 | ||
173 | setUpdatesEnabled( TRUE ); | ||
174 | |||
175 | setSorting( true ); | 174 | setSorting( true ); |
176 | 175 | ||
177 | resort(); | 176 | resort(); |
178 | 177 | ||
179 | updateVisible(); | 178 | updateVisible(); |
180 | 179 | ||
180 | setPaintingEnabled( TRUE ); | ||
181 | |||
181 | } | 182 | } |
182 | 183 | ||
183 | bool AbTable::selectContact( int UID ) | 184 | bool AbTable::selectContact( int UID ) |
184 | { | 185 | { |
185 | qWarning( "AbTable::selectContact( %d )", UID ); | 186 | qWarning( "AbTable::selectContact( %d )", UID ); |
186 | int rows = numRows(); | 187 | int rows = numRows(); |
187 | AbTableItem *abi; | 188 | AbTableItem *abi; |
188 | OContact* foundContact = 0l; | 189 | OContact* foundContact = 0l; |
189 | bool found = false; | 190 | bool found = false; |
190 | 191 | ||
192 | setPaintingEnabled( FALSE ); | ||
191 | for ( int r = 0; r < rows; ++r ) { | 193 | for ( int r = 0; r < rows; ++r ) { |
192 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 194 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
193 | foundContact = &contactList[abi]; | 195 | foundContact = &contactList[abi]; |
194 | if ( foundContact -> uid() == UID ){ | 196 | if ( foundContact -> uid() == UID ){ |
195 | ensureCellVisible( r, 0 ); | 197 | ensureCellVisible( r, 0 ); |
196 | setCurrentCell( r, 0 ); | 198 | setCurrentCell( r, 0 ); |
197 | found = true; | 199 | found = true; |
198 | break; | 200 | break; |
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
202 | if ( !found ){ | 204 | if ( !found ){ |
203 | ensureCellVisible( 0,0 ); | 205 | ensureCellVisible( 0,0 ); |
204 | setCurrentCell( 0, 0 ); | 206 | setCurrentCell( 0, 0 ); |
205 | } | 207 | } |
206 | 208 | ||
209 | setPaintingEnabled( TRUE ); | ||
210 | |||
207 | return true; | 211 | return true; |
208 | } | 212 | } |
209 | 213 | ||
210 | void AbTable::insertIntoTable( const OContact& cnt, int row ) | 214 | void AbTable::insertIntoTable( const OContact& cnt, int row ) |
211 | { | 215 | { |
212 | // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); | 216 | qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); |
213 | QString strName, | 217 | QString strName, |
214 | strContact; | 218 | strContact; |
215 | 219 | ||
216 | strName = findContactName( cnt ); | 220 | strName = findContactName( cnt ); |
217 | strContact = findContactContact( cnt, row ); | 221 | strContact = findContactContact( cnt, row ); |
218 | 222 | ||
219 | AbTableItem *ati; | 223 | AbTableItem *ati; |
220 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 224 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
221 | contactList.insert( ati, cnt ); | 225 | contactList.insert( ati, cnt ); |
222 | setItem( row, 0, ati ); | 226 | setItem( row, 0, ati ); |
223 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | 227 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); |
224 | setItem( row, 1, ati ); | 228 | setItem( row, 1, ati ); |
225 | 229 | ||
226 | //### cannot do this; table only has two columns at this point | 230 | //### cannot do this; table only has two columns at this point |
227 | // setItem( row, 2, new AbPickItem( this ) ); | 231 | // setItem( row, 2, new AbPickItem( this ) ); |
228 | 232 | ||
229 | } | 233 | } |
230 | 234 | ||
231 | 235 | ||
232 | 236 | ||
233 | void AbTable::columnClicked( int col ) | 237 | void AbTable::columnClicked( int col ) |
234 | { | 238 | { |
235 | if ( !sorting() ) | 239 | if ( !sorting() ) |
236 | return; | 240 | return; |
237 | 241 | ||
238 | if ( lastSortCol == -1 ) | 242 | if ( lastSortCol == -1 ) |
239 | lastSortCol = col; | 243 | lastSortCol = col; |
240 | 244 | ||
241 | if ( col == lastSortCol ) { | 245 | if ( col == lastSortCol ) { |
242 | asc = !asc; | 246 | asc = !asc; |
243 | } else { | 247 | } else { |
244 | lastSortCol = col; | 248 | lastSortCol = col; |
245 | asc = TRUE; | 249 | asc = TRUE; |
246 | } | 250 | } |
247 | //QMessageBox::information( this, "resort", "columnClicked" ); | 251 | //QMessageBox::information( this, "resort", "columnClicked" ); |
248 | resort(); | 252 | resort(); |
249 | } | 253 | } |
250 | 254 | ||
251 | void AbTable::resort() | 255 | void AbTable::resort() |
252 | { | 256 | { |
253 | qWarning( "void AbTable::resort()" ); | 257 | qWarning( "void AbTable::resort()" ); |
258 | setPaintingEnabled( FALSE ); | ||
254 | if ( sorting() ) { | 259 | if ( sorting() ) { |
255 | if ( lastSortCol == -1 ) | 260 | if ( lastSortCol == -1 ) |
256 | lastSortCol = 0; | 261 | lastSortCol = 0; |
257 | sortColumn( lastSortCol, asc, TRUE ); | 262 | sortColumn( lastSortCol, asc, TRUE ); |
258 | //QMessageBox::information( this, "resort", "resort" ); | 263 | //QMessageBox::information( this, "resort", "resort" ); |
259 | updateVisible(); | 264 | updateVisible(); |
260 | } | 265 | } |
266 | setPaintingEnabled( TRUE ); | ||
261 | } | 267 | } |
262 | 268 | ||
263 | OContact AbTable::currentEntry() | 269 | OContact AbTable::currentEntry() |
264 | { | 270 | { |
265 | qWarning( "OContact AbTable::currentEntry()" ); | 271 | qWarning( "OContact AbTable::currentEntry()" ); |
266 | OContact cnt; | 272 | OContact cnt; |
267 | AbTableItem *abItem; | 273 | AbTableItem *abItem; |
268 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 274 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
269 | if ( abItem ) { | 275 | if ( abItem ) { |
270 | cnt = contactList[abItem]; | 276 | cnt = contactList[abItem]; |
271 | //cnt = contactList[currentRow()]; | 277 | //cnt = contactList[currentRow()]; |
272 | } | 278 | } |
273 | return cnt; | 279 | return cnt; |
274 | } | 280 | } |
275 | 281 | ||
276 | int AbTable::currentEntry_UID() | 282 | int AbTable::currentEntry_UID() |
277 | { | 283 | { |
278 | return ( currentEntry().uid() ); | 284 | return ( currentEntry().uid() ); |
279 | } | 285 | } |
280 | 286 | ||
281 | void AbTable::clear() | 287 | void AbTable::clear() |
282 | { | 288 | { |
283 | qWarning( "void AbTable::clear()" ); | 289 | qWarning( "void AbTable::clear()" ); |
284 | contactList.clear(); | 290 | contactList.clear(); |
291 | |||
292 | setPaintingEnabled( FALSE ); | ||
285 | for ( int r = 0; r < numRows(); ++r ) { | 293 | for ( int r = 0; r < numRows(); ++r ) { |
286 | for ( int c = 0; c < numCols(); ++c ) { | 294 | for ( int c = 0; c < numCols(); ++c ) { |
287 | if ( cellWidget( r, c ) ) | 295 | if ( cellWidget( r, c ) ) |
288 | clearCellWidget( r, c ); | 296 | clearCellWidget( r, c ); |
289 | clearCell( r, c ); | 297 | clearCell( r, c ); |
290 | } | 298 | } |
291 | } | 299 | } |
292 | setNumRows( 0 ); | 300 | setNumRows( 0 ); |
301 | setPaintingEnabled( TRUE ); | ||
293 | } | 302 | } |
294 | 303 | ||
295 | // Refresh updates column 2 if the contactsettings changed | 304 | // Refresh updates column 2 if the contactsettings changed |
296 | void AbTable::refresh() | 305 | void AbTable::refresh() |
297 | { | 306 | { |
298 | qWarning( "void AbTable::refresh()" ); | 307 | qWarning( "void AbTable::refresh()" ); |
299 | int rows = numRows(); | 308 | int rows = numRows(); |
300 | QString value; | 309 | QString value; |
301 | AbTableItem *abi; | 310 | AbTableItem *abi; |
302 | 311 | ||
312 | setPaintingEnabled( FALSE ); | ||
303 | for ( int r = 0; r < rows; ++r ) { | 313 | for ( int r = 0; r < rows; ++r ) { |
304 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 314 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
305 | value = findContactContact( contactList[abi], r ); | 315 | value = findContactContact( contactList[abi], r ); |
306 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 316 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
307 | } | 317 | } |
308 | resort(); | 318 | resort(); |
319 | setPaintingEnabled( TRUE ); | ||
309 | } | 320 | } |
310 | 321 | ||
311 | void AbTable::keyPressEvent( QKeyEvent *e ) | 322 | void AbTable::keyPressEvent( QKeyEvent *e ) |
312 | { | 323 | { |
313 | char key = toupper( e->ascii() ); | 324 | char key = toupper( e->ascii() ); |
314 | 325 | ||
315 | if ( key >= 'A' && key <= 'Z' ) | 326 | if ( key >= 'A' && key <= 'Z' ) |
316 | moveTo( key ); | 327 | moveTo( key ); |
317 | 328 | ||
318 | qWarning("Received key .."); | 329 | qWarning("Received key .."); |
319 | switch( e->key() ) { | 330 | switch( e->key() ) { |
320 | case Qt::Key_Space: | 331 | case Qt::Key_Space: |
321 | case Qt::Key_Return: | 332 | case Qt::Key_Return: |
322 | case Qt::Key_Enter: | 333 | case Qt::Key_Enter: |
323 | emit signalSwitch(); | 334 | emit signalSwitch(); |
324 | break; | 335 | break; |
325 | // case Qt::Key_Up: | 336 | // case Qt::Key_Up: |
326 | // qWarning("a"); | 337 | // qWarning("a"); |
327 | // emit signalKeyUp(); | 338 | // emit signalKeyUp(); |
328 | // break; | 339 | // break; |
329 | // case Qt::Key_Down: | 340 | // case Qt::Key_Down: |
330 | // qWarning("b"); | 341 | // qWarning("b"); |
331 | // emit signalKeyDown(); | 342 | // emit signalKeyDown(); |
332 | // break; | 343 | // break; |
333 | default: | 344 | default: |
334 | QTable::keyPressEvent( e ); | 345 | QTable::keyPressEvent( e ); |
335 | } | 346 | } |
336 | 347 | ||
337 | } | 348 | } |
338 | 349 | ||
339 | void AbTable::moveTo( char c ) | 350 | void AbTable::moveTo( char c ) |
340 | { | 351 | { |
341 | qWarning( "void AbTable::moveTo( char c )" ); | 352 | qWarning( "void AbTable::moveTo( char c )" ); |
342 | 353 | ||
343 | int rows = numRows(); | 354 | int rows = numRows(); |
344 | QString value; | 355 | QString value; |
345 | AbTableItem *abi; | 356 | AbTableItem *abi; |
346 | int r; | 357 | int r; |
347 | if ( asc ) { | 358 | if ( asc ) { |
348 | r = 0; | 359 | r = 0; |
349 | while ( r < rows-1) { | 360 | while ( r < rows-1) { |
350 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 361 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
351 | QChar first = abi->key()[0]; | 362 | QChar first = abi->key()[0]; |
352 | //### is there a bug in QChar to char comparison??? | 363 | //### is there a bug in QChar to char comparison??? |
353 | if ( first.row() || first.cell() >= c ) | 364 | if ( first.row() || first.cell() >= c ) |
354 | break; | 365 | break; |
355 | r++; | 366 | r++; |
356 | } | 367 | } |
357 | } else { | 368 | } else { |
358 | //### should probably disable reverse sorting instead | 369 | //### should probably disable reverse sorting instead |
359 | r = rows - 1; | 370 | r = rows - 1; |
360 | while ( r > 0 ) { | 371 | while ( r > 0 ) { |
361 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 372 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
362 | QChar first = abi->key()[0]; | 373 | QChar first = abi->key()[0]; |
363 | //### is there a bug in QChar to char comparison??? | 374 | //### is there a bug in QChar to char comparison??? |
364 | if ( first.row() || first.cell() >= c ) | 375 | if ( first.row() || first.cell() >= c ) |
365 | break; | 376 | break; |
366 | r--; | 377 | r--; |
367 | } | 378 | } |
368 | } | 379 | } |
369 | setCurrentCell( r, currentColumn() ); | 380 | setCurrentCell( r, currentColumn() ); |
370 | } | 381 | } |
371 | 382 | ||
372 | 383 | ||
373 | QString AbTable::findContactName( const OContact &entry ) | 384 | QString AbTable::findContactName( const OContact &entry ) |
374 | { | 385 | { |
375 | // We use the fileAs, then company, defaultEmail | 386 | // We use the fileAs, then company, defaultEmail |
376 | QString str; | 387 | QString str; |
377 | str = entry.fileAs(); | 388 | str = entry.fileAs(); |
378 | if ( str.isEmpty() ) { | 389 | if ( str.isEmpty() ) { |
379 | str = entry.company(); | 390 | str = entry.company(); |
380 | if ( str.isEmpty() ) { | 391 | if ( str.isEmpty() ) { |
381 | str = entry.defaultEmail(); | 392 | str = entry.defaultEmail(); |
382 | } | 393 | } |
383 | } | 394 | } |
384 | return str; | 395 | return str; |
385 | } | 396 | } |
386 | 397 | ||
387 | 398 | ||
388 | 399 | ||
389 | void AbTable::resizeRows() { | 400 | void AbTable::resizeRows() { |
390 | /* | 401 | /* |
391 | if (numRows()) { | 402 | if (numRows()) { |
392 | for (int i = 0; i < numRows(); i++) { | 403 | for (int i = 0; i < numRows(); i++) { |
393 | setRowHeight( i, size ); | 404 | setRowHeight( i, size ); |
394 | } | 405 | } |
395 | } | 406 | } |
396 | updateVisible(); | 407 | updateVisible(); |
397 | */ | 408 | */ |
398 | } | 409 | } |
399 | 410 | ||
400 | 411 | ||
401 | void AbTable::realignTable() | 412 | void AbTable::realignTable() |
402 | { | 413 | { |
403 | qWarning( "void AbTable::realignTable()" ); | 414 | qWarning( "void AbTable::realignTable()" ); |
404 | 415 | ||
405 | setPaintingEnabled( FALSE ); | 416 | setPaintingEnabled( FALSE ); |
406 | 417 | ||
407 | resizeRows(); | 418 | resizeRows(); |
408 | fitColumns(); | 419 | fitColumns(); |
409 | 420 | ||
410 | setPaintingEnabled( TRUE ); | 421 | setPaintingEnabled( TRUE ); |
411 | 422 | ||
412 | } | 423 | } |
413 | 424 | ||
414 | 425 | ||
415 | 426 | ||
416 | 427 | ||
417 | #if QT_VERSION <= 230 | 428 | #if QT_VERSION <= 230 |
418 | #ifndef SINGLE_APP | 429 | #ifndef SINGLE_APP |
419 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | 430 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) |
420 | { | 431 | { |
421 | // Region of the rect we should draw | 432 | // Region of the rect we should draw |
422 | QRegion reg( QRect( cx, cy, cw, ch ) ); | 433 | QRegion reg( QRect( cx, cy, cw, ch ) ); |
423 | // Subtract the table from it | 434 | // Subtract the table from it |
424 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); | 435 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); |
425 | // And draw the rectangles (transformed as needed) | 436 | // And draw the rectangles (transformed as needed) |
426 | QArray<QRect> r = reg.rects(); | 437 | QArray<QRect> r = reg.rects(); |
427 | for (unsigned int i=0; i<r.count(); i++) | 438 | for (unsigned int i=0; i<r.count(); i++) |
428 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); | 439 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); |
429 | } | 440 | } |
430 | #endif | 441 | #endif |
431 | #endif | 442 | #endif |
432 | 443 | ||
433 | 444 | ||
434 | // int AbTable::rowHeight( int ) const | 445 | // int AbTable::rowHeight( int ) const |
435 | // { | 446 | // { |
436 | // return 18; | 447 | // return 18; |
437 | // } | 448 | // } |
438 | 449 | ||
439 | // int AbTable::rowPos( int row ) const | 450 | // int AbTable::rowPos( int row ) const |
440 | // { | 451 | // { |
441 | // return 18*row; | 452 | // return 18*row; |
442 | // } | 453 | // } |
443 | 454 | ||
444 | // int AbTable::rowAt( int pos ) const | 455 | // int AbTable::rowAt( int pos ) const |
445 | // { | 456 | // { |
446 | // return QMIN( pos/18, numRows()-1 ); | 457 | // return QMIN( pos/18, numRows()-1 ); |
447 | // } | 458 | // } |
448 | 459 | ||
449 | 460 | ||
450 | 461 | ||
451 | void AbTable::fitColumns() | 462 | void AbTable::fitColumns() |
452 | { | 463 | { |
453 | qWarning( "void AbTable::fitColumns()" ); | 464 | qWarning( "void AbTable::fitColumns()" ); |
454 | int contentsWidth = visibleWidth() / 2; // :SX Why too low | 465 | int contentsWidth = visibleWidth() / 2; // :SX Why too low |
455 | // Fix to better value | 466 | // Fix to better value |
456 | // contentsWidth = 130; | 467 | // contentsWidth = 130; |
468 | |||
469 | setPaintingEnabled( FALSE ); | ||
457 | 470 | ||
458 | if ( columnVisible == false ){ | 471 | if ( columnVisible == false ){ |
459 | showColumn(0); | 472 | showColumn(0); |
460 | columnVisible = true; | 473 | columnVisible = true; |
461 | } | 474 | } |
462 | 475 | ||
463 | qWarning("Width: %d", contentsWidth); | 476 | qWarning("Width: %d", contentsWidth); |
464 | 477 | ||
465 | setColumnWidth( 0, contentsWidth ); | 478 | setColumnWidth( 0, contentsWidth ); |
466 | adjustColumn(1); | 479 | adjustColumn(1); |
467 | if ( columnWidth(1) < contentsWidth ) | 480 | if ( columnWidth(1) < contentsWidth ) |
468 | setColumnWidth( 1, contentsWidth ); | 481 | setColumnWidth( 1, contentsWidth ); |
482 | |||
483 | setPaintingEnabled( TRUE ); | ||
469 | } | 484 | } |
470 | 485 | ||
471 | void AbTable::show() | 486 | void AbTable::show() |
472 | { | 487 | { |
473 | qWarning( "void AbTable::show()" ); | 488 | qWarning( "void AbTable::show()" ); |
474 | realignTable(); | 489 | realignTable(); |
475 | QTable::show(); | 490 | QTable::show(); |
476 | } | 491 | } |
477 | 492 | ||
478 | void AbTable::setChoiceNames( const QStringList& list) | 493 | void AbTable::setChoiceNames( const QStringList& list) |
479 | { | 494 | { |
480 | choicenames = list; | 495 | choicenames = list; |
481 | if ( choicenames.isEmpty() ) { | 496 | if ( choicenames.isEmpty() ) { |
482 | // hide pick column | 497 | // hide pick column |
483 | setNumCols( 2 ); | 498 | setNumCols( 2 ); |
484 | } else { | 499 | } else { |
485 | // show pick column | 500 | // show pick column |
486 | setNumCols( 3 ); | 501 | setNumCols( 3 ); |
487 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); | 502 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); |
488 | horizontalHeader()->setLabel( 2, tr( "Pick" )); | 503 | horizontalHeader()->setLabel( 2, tr( "Pick" )); |
489 | } | 504 | } |
490 | fitColumns(); | 505 | fitColumns(); |
491 | } | 506 | } |
492 | 507 | ||
493 | void AbTable::itemClicked(int,int col) | 508 | void AbTable::itemClicked(int,int col) |
494 | { | 509 | { |
495 | qWarning( "AbTable::itemClicked(int, col:%d)", col); | 510 | qWarning( "AbTable::itemClicked(int, col:%d)", col); |
496 | if ( col == 2 ) { | 511 | if ( col == 2 ) { |
497 | return; | 512 | return; |
498 | } else { | 513 | } else { |
499 | qWarning ("Emitting signalSwitch()"); | 514 | qWarning ("Emitting signalSwitch()"); |
500 | emit signalSwitch(); | 515 | emit signalSwitch(); |
501 | } | 516 | } |
502 | } | 517 | } |
503 | 518 | ||
504 | QStringList AbTable::choiceNames() const | 519 | QStringList AbTable::choiceNames() const |
505 | { | 520 | { |
506 | return choicenames; | 521 | return choicenames; |
507 | } | 522 | } |
508 | 523 | ||
509 | void AbTable::setChoiceSelection( const QValueList<int>& list ) | 524 | void AbTable::setChoiceSelection( const QValueList<int>& list ) |
510 | { | 525 | { |
511 | intFields = list; | 526 | intFields = list; |
512 | } | 527 | } |
513 | 528 | ||
514 | QStringList AbTable::choiceSelection(int /*index*/) const | 529 | QStringList AbTable::choiceSelection(int /*index*/) const |
515 | { | 530 | { |
516 | QStringList r; | 531 | QStringList r; |
517 | /* ###### | 532 | /* ###### |
518 | 533 | ||
519 | QString selname = choicenames.at(index); | 534 | QString selname = choicenames.at(index); |
520 | for (each row) { | 535 | for (each row) { |
521 | OContact *c = contactForRow(row); | 536 | OContact *c = contactForRow(row); |
522 | if ( text(row,2) == selname ) { | 537 | if ( text(row,2) == selname ) { |
523 | r.append(c->email); | 538 | r.append(c->email); |
524 | } | 539 | } |
525 | } | 540 | } |
526 | 541 | ||
527 | */ | 542 | */ |
528 | return r; | 543 | return r; |
529 | } | 544 | } |
530 | 545 | ||
531 | 546 | ||
532 | 547 | ||
533 | 548 | ||
534 | void AbTable::updateVisible() | 549 | void AbTable::updateVisible() |
535 | { | 550 | { |
551 | qWarning("void AbTable::updateVisible()"); | ||
552 | |||
536 | int visible, | 553 | int visible, |
537 | totalRows, | 554 | totalRows, |
538 | row, | 555 | row, |
539 | selectedRow = 0; | 556 | selectedRow = 0; |
540 | 557 | ||
541 | visible = 0; | 558 | visible = 0; |
542 | 559 | ||
543 | realignTable(); | ||
544 | |||
545 | setPaintingEnabled( FALSE ); | 560 | setPaintingEnabled( FALSE ); |
546 | 561 | ||
562 | realignTable(); | ||
563 | |||
547 | totalRows = numRows(); | 564 | totalRows = numRows(); |
548 | for ( row = 0; row < totalRows; row++ ) { | 565 | for ( row = 0; row < totalRows; row++ ) { |
549 | if ( rowHeight(row) == 0 ) { | 566 | if ( rowHeight(row) == 0 ) { |
550 | showRow( row ); | 567 | showRow( row ); |
551 | adjustRow( row ); | 568 | adjustRow( row ); |
552 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) | 569 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) |
553 | selectedRow = row; | 570 | selectedRow = row; |
554 | } | 571 | } |
555 | visible++; | 572 | visible++; |
556 | } | 573 | } |
557 | 574 | ||
558 | if ( selectedRow ) | 575 | if ( selectedRow ) |
559 | setCurrentCell( selectedRow, 0 ); | 576 | setCurrentCell( selectedRow, 0 ); |
560 | 577 | ||
561 | if ( !visible ) | 578 | if ( !visible ) |
562 | setCurrentCell( -1, 0 ); | 579 | setCurrentCell( -1, 0 ); |
563 | 580 | ||
564 | setPaintingEnabled( TRUE ); | 581 | setPaintingEnabled( TRUE ); |
565 | 582 | ||
566 | 583 | ||
567 | } | 584 | } |
568 | 585 | ||
569 | 586 | ||
570 | void AbTable::setPaintingEnabled( bool e ) | 587 | void AbTable::setPaintingEnabled( bool e ) |
571 | { | 588 | { |
572 | if ( e != enablePainting ) { | 589 | qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); |
573 | if ( !enablePainting ) { | 590 | |
591 | if ( e ) { | ||
592 | if ( countNested > 0 ) | ||
593 | --countNested; | ||
594 | if ( ! countNested ){ | ||
595 | setUpdatesEnabled( true ); | ||
574 | enablePainting = true; | 596 | enablePainting = true; |
575 | rowHeightChanged( 0 ); | 597 | rowHeightChanged( 0 ); |
576 | viewport()->update(); | 598 | viewport()->update(); |
577 | } else { | ||
578 | enablePainting = false; | ||
579 | } | 599 | } |
600 | } else { | ||
601 | ++countNested; | ||
602 | enablePainting = false; | ||
603 | setUpdatesEnabled( false ); | ||
580 | } | 604 | } |
605 | qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); | ||
581 | } | 606 | } |
582 | 607 | ||
608 | void AbTable::viewportPaintEvent( QPaintEvent* e ) { | ||
609 | qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); | ||
610 | if ( enablePainting ) | ||
611 | QTable::viewportPaintEvent( e ); | ||
612 | } | ||
613 | |||
614 | |||
615 | |||
583 | void AbTable::rowHeightChanged( int row ) | 616 | void AbTable::rowHeightChanged( int row ) |
584 | { | 617 | { |
585 | if ( enablePainting ) | 618 | if ( enablePainting ) |
586 | QTable::rowHeightChanged( row ); | 619 | QTable::rowHeightChanged( row ); |
587 | } | 620 | } |
588 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) | 621 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) |
589 | { | 622 | { |
590 | QString value; | 623 | QString value; |
591 | value = ""; | 624 | value = ""; |
592 | for ( QValueList<int>::ConstIterator it = intFields.begin(); | 625 | for ( QValueList<int>::ConstIterator it = intFields.begin(); |
593 | it != intFields.end(); ++it ) { | 626 | it != intFields.end(); ++it ) { |
594 | switch ( *it ) { | 627 | switch ( *it ) { |
595 | default: | 628 | default: |
596 | break; | 629 | break; |
597 | case Qtopia::Title: | 630 | case Qtopia::Title: |
598 | value = entry.title(); | 631 | value = entry.title(); |
599 | break; | 632 | break; |
600 | case Qtopia::Suffix: | 633 | case Qtopia::Suffix: |
601 | value = entry.suffix(); | 634 | value = entry.suffix(); |
602 | break; | 635 | break; |
603 | case Qtopia::FileAs: | 636 | case Qtopia::FileAs: |
604 | value = entry.fileAs(); | 637 | value = entry.fileAs(); |
605 | break; | 638 | break; |
606 | case Qtopia::DefaultEmail: | 639 | case Qtopia::DefaultEmail: |
607 | value = entry.defaultEmail(); | 640 | value = entry.defaultEmail(); |
608 | case Qtopia::Emails: | 641 | case Qtopia::Emails: |
609 | value = entry.emails(); | 642 | value = entry.emails(); |
610 | break; | 643 | break; |
611 | case Qtopia::HomeStreet: | 644 | case Qtopia::HomeStreet: |
612 | value = entry.homeStreet(); | 645 | value = entry.homeStreet(); |
613 | break; | 646 | break; |
614 | case Qtopia::HomeCity: | 647 | case Qtopia::HomeCity: |
615 | value = entry.homeCity(); | 648 | value = entry.homeCity(); |
616 | break; | 649 | break; |
617 | case Qtopia::HomeState: | 650 | case Qtopia::HomeState: |
618 | value = entry.homeState(); | 651 | value = entry.homeState(); |
619 | break; | 652 | break; |
620 | case Qtopia::HomeZip: | 653 | case Qtopia::HomeZip: |
621 | value = entry.homeZip(); | 654 | value = entry.homeZip(); |
622 | break; | 655 | break; |
623 | case Qtopia::HomeCountry: | 656 | case Qtopia::HomeCountry: |
624 | value = entry.homeCountry(); | 657 | value = entry.homeCountry(); |
625 | break; | 658 | break; |
626 | case Qtopia::HomePhone: | 659 | case Qtopia::HomePhone: |
627 | value = entry.homePhone(); | 660 | value = entry.homePhone(); |
628 | break; | 661 | break; |
629 | case Qtopia::HomeFax: | 662 | case Qtopia::HomeFax: |
630 | value = entry.homeFax(); | 663 | value = entry.homeFax(); |
631 | break; | 664 | break; |
632 | case Qtopia::HomeMobile: | 665 | case Qtopia::HomeMobile: |
633 | value = entry.homeMobile(); | 666 | value = entry.homeMobile(); |
634 | break; | 667 | break; |
635 | case Qtopia::HomeWebPage: | 668 | case Qtopia::HomeWebPage: |
636 | value = entry.homeWebpage(); | 669 | value = entry.homeWebpage(); |
637 | break; | 670 | break; |
638 | case Qtopia::Company: | 671 | case Qtopia::Company: |
639 | value = entry.company(); | 672 | value = entry.company(); |
640 | break; | 673 | break; |
641 | case Qtopia::BusinessCity: | 674 | case Qtopia::BusinessCity: |
642 | value = entry.businessCity(); | 675 | value = entry.businessCity(); |
643 | break; | 676 | break; |
644 | case Qtopia::BusinessStreet: | 677 | case Qtopia::BusinessStreet: |
645 | value = entry.businessStreet(); | 678 | value = entry.businessStreet(); |
646 | break; | 679 | break; |
647 | case Qtopia::BusinessZip: | 680 | case Qtopia::BusinessZip: |
648 | value = entry.businessZip(); | 681 | value = entry.businessZip(); |
649 | break; | 682 | break; |
650 | case Qtopia::BusinessCountry: | 683 | case Qtopia::BusinessCountry: |
651 | value = entry.businessCountry(); | 684 | value = entry.businessCountry(); |
652 | break; | 685 | break; |
653 | case Qtopia::BusinessWebPage: | 686 | case Qtopia::BusinessWebPage: |
654 | value = entry.businessWebpage(); | 687 | value = entry.businessWebpage(); |
655 | break; | 688 | break; |
656 | case Qtopia::JobTitle: | 689 | case Qtopia::JobTitle: |
657 | value = entry.jobTitle(); | 690 | value = entry.jobTitle(); |
658 | break; | 691 | break; |
659 | case Qtopia::Department: | 692 | case Qtopia::Department: |
660 | value = entry.department(); | 693 | value = entry.department(); |
661 | break; | 694 | break; |
662 | case Qtopia::Office: | 695 | case Qtopia::Office: |
663 | value = entry.office(); | 696 | value = entry.office(); |
664 | break; | 697 | break; |
665 | case Qtopia::BusinessPhone: | 698 | case Qtopia::BusinessPhone: |
666 | value = entry.businessPhone(); | 699 | value = entry.businessPhone(); |
667 | break; | 700 | break; |
668 | case Qtopia::BusinessFax: | 701 | case Qtopia::BusinessFax: |
669 | value = entry.businessFax(); | 702 | value = entry.businessFax(); |
670 | break; | 703 | break; |
671 | case Qtopia::BusinessMobile: | 704 | case Qtopia::BusinessMobile: |
672 | value = entry.businessMobile(); | 705 | value = entry.businessMobile(); |
673 | break; | 706 | break; |
674 | case Qtopia::BusinessPager: | 707 | case Qtopia::BusinessPager: |
675 | value = entry.businessPager(); | 708 | value = entry.businessPager(); |
676 | break; | 709 | break; |
677 | case Qtopia::Profession: | 710 | case Qtopia::Profession: |
678 | value = entry.profession(); | 711 | value = entry.profession(); |
679 | break; | 712 | break; |
680 | case Qtopia::Assistant: | 713 | case Qtopia::Assistant: |
681 | value = entry.assistant(); | 714 | value = entry.assistant(); |
682 | break; | 715 | break; |
683 | case Qtopia::Manager: | 716 | case Qtopia::Manager: |
684 | value = entry.manager(); | 717 | value = entry.manager(); |
685 | break; | 718 | break; |
686 | case Qtopia::Spouse: | 719 | case Qtopia::Spouse: |
687 | value = entry.spouse(); | 720 | value = entry.spouse(); |
688 | break; | 721 | break; |
689 | case Qtopia::Gender: | 722 | case Qtopia::Gender: |
690 | value = entry.gender(); | 723 | value = entry.gender(); |
691 | break; | 724 | break; |
692 | case Qtopia::Birthday: | 725 | case Qtopia::Birthday: |
693 | if ( ! entry.birthday().isNull() ) | 726 | if ( ! entry.birthday().isNull() ) |
694 | value = TimeString::numberDateString( entry.birthday() ); | 727 | value = TimeString::numberDateString( entry.birthday() ); |
695 | break; | 728 | break; |
696 | case Qtopia::Anniversary: | 729 | case Qtopia::Anniversary: |
697 | if ( ! entry.anniversary().isNull() ) | 730 | if ( ! entry.anniversary().isNull() ) |
698 | value = TimeString::numberDateString( entry.anniversary() ); | 731 | value = TimeString::numberDateString( entry.anniversary() ); |
699 | break; | 732 | break; |
700 | case Qtopia::Nickname: | 733 | case Qtopia::Nickname: |
701 | value = entry.nickname(); | 734 | value = entry.nickname(); |
702 | break; | 735 | break; |
703 | case Qtopia::Children: | 736 | case Qtopia::Children: |
704 | value = entry.children(); | 737 | value = entry.children(); |
705 | break; | 738 | break; |
706 | case Qtopia::Notes: | 739 | case Qtopia::Notes: |
707 | value = entry.notes(); | 740 | value = entry.notes(); |
708 | break; | 741 | break; |
709 | } | 742 | } |
710 | if ( !value.isEmpty() ) | 743 | if ( !value.isEmpty() ) |
711 | break; | 744 | break; |
712 | } | 745 | } |
713 | return value; | 746 | return value; |
714 | } | 747 | } |
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 83bd5a7..9825665 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h | |||
@@ -1,136 +1,137 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of Qt Palmtop Environment. | 5 | ** This file is part of Qt Palmtop Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef ABTABLE_H | 22 | #ifndef ABTABLE_H |
23 | #define ABTABLE_H | 23 | #define ABTABLE_H |
24 | 24 | ||
25 | #include <qpe/categories.h> | 25 | #include <qpe/categories.h> |
26 | #include <opie/ocontact.h> | 26 | #include <opie/ocontact.h> |
27 | #include <opie/ocontactaccess.h> | 27 | #include <opie/ocontactaccess.h> |
28 | 28 | ||
29 | #include <qmap.h> | 29 | #include <qmap.h> |
30 | #include <qtable.h> | 30 | #include <qtable.h> |
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | 33 | ||
34 | class AbTableItem : public QTableItem | 34 | class AbTableItem : public QTableItem |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | AbTableItem( QTable *t, EditType et, const QString &s, | 37 | AbTableItem( QTable *t, EditType et, const QString &s, |
38 | const QString &secondSortKey); | 38 | const QString &secondSortKey); |
39 | QString entryKey() const; | 39 | QString entryKey() const; |
40 | void setEntryKey( const QString & k ); | 40 | void setEntryKey( const QString & k ); |
41 | virtual int alignment() const; | 41 | virtual int alignment() const; |
42 | virtual QString key() const; | 42 | virtual QString key() const; |
43 | void setItem( const QString &txt, const QString &secondKey ); | 43 | void setItem( const QString &txt, const QString &secondKey ); |
44 | 44 | ||
45 | private: | 45 | private: |
46 | QString sortKey; | 46 | QString sortKey; |
47 | }; | 47 | }; |
48 | 48 | ||
49 | class AbPickItem : public QTableItem | 49 | class AbPickItem : public QTableItem |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | AbPickItem( QTable *t ); | 52 | AbPickItem( QTable *t ); |
53 | 53 | ||
54 | QWidget *createEditor() const; | 54 | QWidget *createEditor() const; |
55 | void setContentFromEditor( QWidget *w ); | 55 | void setContentFromEditor( QWidget *w ); |
56 | 56 | ||
57 | private: | 57 | private: |
58 | QGuardedPtr<QComboBox> cb; | 58 | QGuardedPtr<QComboBox> cb; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | class AbTable : public QTable | 61 | class AbTable : public QTable |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | 64 | ||
65 | public: | 65 | public: |
66 | AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); | 66 | AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); |
67 | ~AbTable(); | 67 | ~AbTable(); |
68 | 68 | ||
69 | // Set the contacts shown in the table | 69 | // Set the contacts shown in the table |
70 | void setContacts( const OContactAccess::List& viewList ); | 70 | void setContacts( const OContactAccess::List& viewList ); |
71 | // Selects a contact of a specific UID | 71 | // Selects a contact of a specific UID |
72 | bool selectContact( int UID ); | 72 | bool selectContact( int UID ); |
73 | 73 | ||
74 | // Get the current selected entry | 74 | // Get the current selected entry |
75 | OContact currentEntry(); | 75 | OContact currentEntry(); |
76 | 76 | ||
77 | // Get the UID of the current selected Entry | 77 | // Get the UID of the current selected Entry |
78 | int currentEntry_UID(); | 78 | int currentEntry_UID(); |
79 | 79 | ||
80 | QString findContactName( const OContact &entry ); | 80 | QString findContactName( const OContact &entry ); |
81 | 81 | ||
82 | void init(); | 82 | void init(); |
83 | void clear(); | 83 | void clear(); |
84 | void refresh(); | 84 | void refresh(); |
85 | 85 | ||
86 | void show(); | 86 | void show(); |
87 | void setPaintingEnabled( bool e ); | 87 | void setPaintingEnabled( bool e ); |
88 | void viewportPaintEvent( QPaintEvent* e); | ||
88 | 89 | ||
89 | // addresspicker mode (What's that ? se) | 90 | // addresspicker mode (What's that ? se) |
90 | void setChoiceNames( const QStringList& list); | 91 | void setChoiceNames( const QStringList& list); |
91 | QStringList choiceNames() const; | 92 | QStringList choiceNames() const; |
92 | void setChoiceSelection( const QValueList<int>& list ); | 93 | void setChoiceSelection( const QValueList<int>& list ); |
93 | QStringList choiceSelection(int index) const; | 94 | QStringList choiceSelection(int index) const; |
94 | 95 | ||
95 | signals: | 96 | signals: |
96 | void signalSwitch(); | 97 | void signalSwitch(); |
97 | void signalEditor(); | 98 | void signalEditor(); |
98 | void signalKeyDown(); | 99 | void signalKeyDown(); |
99 | void signalKeyUp(); | 100 | void signalKeyUp(); |
100 | 101 | ||
101 | protected: | 102 | protected: |
102 | virtual void keyPressEvent( QKeyEvent *e ); | 103 | virtual void keyPressEvent( QKeyEvent *e ); |
103 | 104 | ||
104 | // int rowHeight( int ) const; | 105 | // int rowHeight( int ) const; |
105 | // int rowPos( int row ) const; | 106 | // int rowPos( int row ) const; |
106 | // virtual int rowAt( int pos ) const; | 107 | // virtual int rowAt( int pos ) const; |
107 | 108 | ||
108 | 109 | ||
109 | protected slots: | 110 | protected slots: |
110 | void moveTo( char ); | 111 | void moveTo( char ); |
111 | virtual void columnClicked( int col ); | 112 | virtual void columnClicked( int col ); |
112 | void itemClicked(int,int col); | 113 | void itemClicked(int,int col); |
113 | void rowHeightChanged( int row ); | 114 | void rowHeightChanged( int row ); |
114 | 115 | ||
115 | private: | 116 | private: |
116 | void insertIntoTable( const OContact &cnt, int row ); | 117 | void insertIntoTable( const OContact &cnt, int row ); |
117 | QString findContactContact( const OContact &entry, int row ); | 118 | QString findContactContact( const OContact &entry, int row ); |
118 | void fitColumns(); | 119 | void fitColumns(); |
119 | void resizeRows(); | 120 | void resizeRows(); |
120 | void realignTable(); | 121 | void realignTable(); |
121 | void resort(); | 122 | void resort(); |
122 | void updateVisible(); | 123 | void updateVisible(); |
123 | 124 | ||
124 | int lastSortCol; | 125 | int lastSortCol; |
125 | bool asc; | 126 | bool asc; |
126 | QMap<AbTableItem*, OContact> contactList; | 127 | QMap<AbTableItem*, OContact> contactList; |
127 | QValueList<int> intFields; | 128 | QValueList<int> intFields; |
128 | QStringList choicenames; | 129 | QStringList choicenames; |
129 | bool enablePainting; | 130 | bool enablePainting; |
130 | |||
131 | bool columnVisible; | 131 | bool columnVisible; |
132 | int countNested; | ||
132 | 133 | ||
133 | OContactAccess::List m_viewList; | 134 | OContactAccess::List m_viewList; |
134 | 135 | ||
135 | }; | 136 | }; |
136 | #endif // ABTABLE_H | 137 | #endif // ABTABLE_H |
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 8d22129..3af7663 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp | |||
@@ -1,445 +1,459 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** | ||
15 | **********************************************************************/ | ||
16 | |||
1 | #include "abview.h" | 17 | #include "abview.h" |
2 | 18 | ||
3 | #include <qlayout.h> | 19 | #include <qlayout.h> |
4 | 20 | ||
5 | #include <qpe/global.h> | 21 | #include <qpe/global.h> |
6 | 22 | ||
7 | #include <opie/ocontactaccessbackend_vcard.h> | 23 | #include <opie/ocontactaccessbackend_vcard.h> |
8 | 24 | ||
9 | 25 | ||
10 | // Is defined in LibQPE | 26 | // Is defined in LibQPE |
11 | extern QString categoryFileName(); | 27 | extern QString categoryFileName(); |
12 | 28 | ||
13 | QString addressbookPersonalVCardName() | 29 | QString addressbookPersonalVCardName() |
14 | { | 30 | { |
15 | QString filename = Global::applicationFileName("addressbook", | 31 | QString filename = Global::applicationFileName("addressbook", |
16 | "businesscard.vcf"); | 32 | "businesscard.vcf"); |
17 | return filename; | 33 | return filename; |
18 | } | 34 | } |
19 | 35 | ||
20 | 36 | ||
21 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): | 37 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): |
22 | QWidget(parent), | 38 | QWidget(parent), |
23 | mCat(0), | 39 | mCat(0), |
24 | m_inSearch( false ), | 40 | m_inSearch( false ), |
25 | m_inPersonal( false ), | 41 | m_inPersonal( false ), |
26 | m_curr_category( -1 ), | 42 | m_curr_category( -1 ), |
27 | m_curr_View( TableView ), | 43 | m_curr_View( TableView ), |
28 | m_prev_View( TableView ), | 44 | m_prev_View( TableView ), |
29 | m_curr_Contact ( 0 ), | 45 | m_curr_Contact ( 0 ), |
30 | m_contactdb ( 0l ), | 46 | m_contactdb ( 0l ), |
31 | m_storedDB ( 0l ), | 47 | m_storedDB ( 0l ), |
32 | m_viewStack( 0l ), | 48 | m_viewStack( 0l ), |
33 | m_abTable( 0l ), | 49 | m_abTable( 0l ), |
34 | m_orderedFields( ordered ) | 50 | m_orderedFields( ordered ) |
35 | { | 51 | { |
36 | // Load default database and handle syncing myself.. ! | 52 | // Load default database and handle syncing myself.. ! |
37 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), | 53 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), |
38 | mCat.load( categoryFileName() ); | 54 | mCat.load( categoryFileName() ); |
39 | 55 | ||
40 | // Create Layout and put WidgetStack into it. | 56 | // Create Layout and put WidgetStack into it. |
41 | QVBoxLayout *vb = new QVBoxLayout( this ); | 57 | QVBoxLayout *vb = new QVBoxLayout( this ); |
42 | m_viewStack = new QWidgetStack( this ); | 58 | m_viewStack = new QWidgetStack( this ); |
43 | vb->addWidget( m_viewStack ); | 59 | vb->addWidget( m_viewStack ); |
44 | 60 | ||
45 | // Creat TableView | 61 | // Creat TableView |
46 | QVBox* tableBox = new QVBox( m_viewStack ); | 62 | QVBox* tableBox = new QVBox( m_viewStack ); |
47 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); | 63 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); |
48 | m_abTable->setCurrentCell( 0, 0 ); | 64 | m_abTable->setCurrentCell( 0, 0 ); |
49 | m_abTable->setFocus(); | 65 | m_abTable->setFocus(); |
50 | 66 | ||
51 | // Add TableView to WidgetStack and raise it | 67 | // Add TableView to WidgetStack and raise it |
52 | m_viewStack -> addWidget( tableBox , TableView ); | 68 | m_viewStack -> addWidget( tableBox , TableView ); |
53 | 69 | ||
54 | // Create CardView and add it to WidgetStack | 70 | // Create CardView and add it to WidgetStack |
55 | QVBox* cardBox = new QVBox( m_viewStack ); | 71 | QVBox* cardBox = new QVBox( m_viewStack ); |
56 | m_ablabel = new AbLabel( cardBox, "CardView"); | 72 | m_ablabel = new AbLabel( cardBox, "CardView"); |
57 | m_viewStack -> addWidget( cardBox , CardView ); | 73 | m_viewStack -> addWidget( cardBox , CardView ); |
58 | 74 | ||
59 | // Connect views to me | 75 | // Connect views to me |
60 | connect ( m_abTable, SIGNAL( signalSwitch( void ) ), | 76 | connect ( m_abTable, SIGNAL( signalSwitch( void ) ), |
61 | this, SLOT( slotSwitch( void ) ) ); | 77 | this, SLOT( slotSwitch( void ) ) ); |
62 | connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), | 78 | connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), |
63 | this, SLOT( slotSwitch( void ) ) ); | 79 | this, SLOT( slotSwitch( void ) ) ); |
64 | 80 | ||
65 | load(); | 81 | load(); |
66 | } | 82 | } |
67 | 83 | ||
68 | AbView::~AbView() | 84 | AbView::~AbView() |
69 | { | 85 | { |
70 | m_contactdb -> save(); | 86 | m_contactdb -> save(); |
71 | delete m_contactdb; | 87 | delete m_contactdb; |
72 | 88 | ||
73 | if ( m_storedDB ){ | 89 | if ( m_storedDB ){ |
74 | m_storedDB -> save(); | 90 | m_storedDB -> save(); |
75 | delete m_storedDB; | 91 | delete m_storedDB; |
76 | } | 92 | } |
77 | } | 93 | } |
78 | 94 | ||
79 | 95 | ||
80 | void AbView::setView( Views view ) | 96 | void AbView::setView( Views view ) |
81 | { | 97 | { |
82 | qWarning("AbView::setView( Views view )"); | 98 | qWarning("AbView::setView( Views view )"); |
83 | m_curr_View = view; | 99 | m_curr_View = view; |
84 | load(); | 100 | load(); |
85 | } | 101 | } |
86 | 102 | ||
87 | void AbView::addEntry( const OContact &newContact ) | 103 | void AbView::addEntry( const OContact &newContact ) |
88 | { | 104 | { |
89 | qWarning("abview:AddContact"); | 105 | qWarning("abview:AddContact"); |
90 | m_contactdb->add ( newContact ); | 106 | m_contactdb->add ( newContact ); |
91 | load(); | 107 | load(); |
92 | 108 | ||
93 | } | 109 | } |
94 | void AbView::removeEntry( const int UID ) | 110 | void AbView::removeEntry( const int UID ) |
95 | { | 111 | { |
96 | qWarning("abview:RemoveContact"); | 112 | qWarning("abview:RemoveContact"); |
97 | m_contactdb->remove( UID ); | 113 | m_contactdb->remove( UID ); |
98 | load(); | 114 | load(); |
99 | } | 115 | } |
100 | 116 | ||
101 | void AbView::replaceEntry( const OContact &contact ) | 117 | void AbView::replaceEntry( const OContact &contact ) |
102 | { | 118 | { |
103 | qWarning("abview:ReplaceContact"); | 119 | qWarning("abview:ReplaceContact"); |
104 | m_contactdb->replace( contact ); | 120 | m_contactdb->replace( contact ); |
105 | load(); | 121 | load(); |
106 | 122 | ||
107 | } | 123 | } |
108 | 124 | ||
109 | OContact AbView::currentEntry() | 125 | OContact AbView::currentEntry() |
110 | { | 126 | { |
111 | switch ( (int) m_curr_View ) { | 127 | switch ( (int) m_curr_View ) { |
112 | case TableView: | 128 | case TableView: |
113 | return ( m_abTable -> currentEntry() ); | 129 | return ( m_abTable -> currentEntry() ); |
114 | break; | 130 | break; |
115 | case CardView: | 131 | case CardView: |
116 | return ( m_ablabel -> currentEntry() ); | 132 | return ( m_ablabel -> currentEntry() ); |
117 | break; | 133 | break; |
118 | } | 134 | } |
119 | return OContact(); | 135 | return OContact(); |
120 | } | 136 | } |
121 | 137 | ||
122 | bool AbView::save() | 138 | bool AbView::save() |
123 | { | 139 | { |
124 | qWarning("abView:Save data"); | 140 | qWarning("abView:Save data"); |
125 | 141 | ||
126 | return m_contactdb->save(); | 142 | return m_contactdb->save(); |
127 | } | 143 | } |
128 | 144 | ||
129 | void AbView::load() | 145 | void AbView::load() |
130 | { | 146 | { |
131 | qWarning("abView:Load data"); | 147 | qWarning("abView:Load data"); |
132 | 148 | ||
133 | if ( m_inPersonal ) | 149 | if ( m_inPersonal ) |
134 | m_list = m_contactdb->allRecords(); | 150 | m_list = m_contactdb->allRecords(); |
135 | else | 151 | else |
136 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); | 152 | m_list = m_contactdb->sorted( true, 0, 0, 0 ); |
137 | 153 | ||
138 | clearForCategory(); | 154 | clearForCategory(); |
139 | 155 | ||
140 | // Feed all views with new lists | ||
141 | updateListinViews(); | ||
142 | |||
143 | qWarning ("Number of contacts: %d", m_list.count()); | 156 | qWarning ("Number of contacts: %d", m_list.count()); |
144 | 157 | ||
145 | updateView(); | 158 | updateView(); |
146 | 159 | ||
147 | } | 160 | } |
148 | 161 | ||
149 | void AbView::reload() | 162 | void AbView::reload() |
150 | { | 163 | { |
151 | qWarning( "void AbView::reload()" ); | 164 | qWarning( "void AbView::reload()" ); |
152 | 165 | ||
153 | m_contactdb->reload(); | 166 | m_contactdb->reload(); |
154 | load(); | 167 | load(); |
155 | } | 168 | } |
156 | 169 | ||
157 | void AbView::clear() | 170 | void AbView::clear() |
158 | { | 171 | { |
159 | // :SX | 172 | // :SX |
160 | } | 173 | } |
161 | 174 | ||
162 | void AbView::setShowByCategory( Views view, const QString& cat ) | 175 | void AbView::setShowByCategory( const QString& cat ) |
163 | { | 176 | { |
164 | qWarning("AbView::setShowCategory( Views view, const QString& cat )"); | 177 | qWarning("AbView::setShowCategory( const QString& cat )"); |
165 | |||
166 | // if ( view == PersonalView ){ | ||
167 | // if ( ! m_inPersonal ) | ||
168 | // showPersonal( true ); | ||
169 | |||
170 | // }else{ | ||
171 | // if ( m_inPersonal ) | ||
172 | // showPersonal( false ); | ||
173 | |||
174 | // m_curr_View = view; | ||
175 | // } | ||
176 | 178 | ||
177 | int intCat = 0; | 179 | int intCat = 0; |
178 | 180 | ||
179 | // All (cat == NULL) will be stored as -1 | 181 | // All (cat == NULL) will be stored as -1 |
180 | if ( cat.isNull() ) | 182 | if ( cat.isNull() ) |
181 | intCat = -1; | 183 | intCat = -1; |
182 | else | 184 | else |
183 | intCat = mCat.id("Contacts", cat ); | 185 | intCat = mCat.id("Contacts", cat ); |
184 | 186 | ||
185 | // If we just change the view, we don't have to reload any data.. | 187 | // Just do anything if we really change the category |
186 | // This speeds up a lot of things ! | 188 | if ( intCat != m_curr_category ){ |
187 | if ( intCat == m_curr_category ){ | ||
188 | qWarning ("Just change the View (Category is: %d)", m_curr_category); | ||
189 | m_prev_View = m_curr_View; | ||
190 | m_curr_View = view; | ||
191 | |||
192 | updateView(); | ||
193 | }else{ | ||
194 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | 189 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); |
195 | 190 | ||
196 | m_curr_View = view; | ||
197 | m_curr_category = intCat; | 191 | m_curr_category = intCat; |
198 | emit signalClearLetterPicker(); | 192 | emit signalClearLetterPicker(); |
199 | 193 | ||
200 | load(); | 194 | load(); |
201 | } | 195 | } |
202 | 196 | ||
203 | } | 197 | } |
198 | |||
199 | void AbView::setShowToView( Views view ) | ||
200 | { | ||
201 | qWarning("void AbView::setShowToView( View %d )", view); | ||
202 | |||
203 | qWarning ("Change the View (Category is: %d)", m_curr_category); | ||
204 | |||
205 | if ( m_curr_View != view ){ | ||
206 | m_prev_View = m_curr_View; | ||
207 | m_curr_View = view; | ||
208 | |||
209 | updateView(); | ||
210 | } | ||
211 | |||
212 | } | ||
213 | |||
204 | void AbView::setShowByLetter( char c ) | 214 | void AbView::setShowByLetter( char c ) |
205 | { | 215 | { |
206 | qWarning("void AbView::setShowByLetter( %c )", c ); | 216 | qWarning("void AbView::setShowByLetter( %c )", c ); |
207 | OContact query; | 217 | OContact query; |
208 | if ( c == 0 ){ | 218 | if ( c == 0 ){ |
209 | load(); | 219 | load(); |
210 | return; | 220 | return; |
211 | }else{ | 221 | }else{ |
212 | query.setLastName( QString("%1*").arg(c) ); | 222 | query.setLastName( QString("%1*").arg(c) ); |
213 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); | 223 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards ); |
214 | clearForCategory(); | 224 | clearForCategory(); |
215 | m_curr_Contact = 0; | 225 | m_curr_Contact = 0; |
216 | } | 226 | } |
217 | updateView(); | 227 | updateView(); |
218 | } | 228 | } |
219 | 229 | ||
220 | void AbView::setListOrder( const QValueList<int>& ordered ) | 230 | void AbView::setListOrder( const QValueList<int>& ordered ) |
221 | { | 231 | { |
222 | m_orderedFields = ordered; | 232 | m_orderedFields = ordered; |
223 | updateView(); | 233 | updateView(); |
224 | } | 234 | } |
225 | 235 | ||
226 | 236 | ||
227 | QString AbView::showCategory() const | 237 | QString AbView::showCategory() const |
228 | { | 238 | { |
229 | return mCat.label( "Contacts", m_curr_category ); | 239 | return mCat.label( "Contacts", m_curr_category ); |
230 | } | 240 | } |
231 | 241 | ||
232 | void AbView::showPersonal( bool personal ) | 242 | void AbView::showPersonal( bool personal ) |
233 | { | 243 | { |
234 | qWarning ("void AbView::showPersonal( %d )", personal); | 244 | qWarning ("void AbView::showPersonal( %d )", personal); |
235 | 245 | ||
236 | if ( personal ){ | 246 | if ( personal ){ |
237 | 247 | ||
238 | if ( m_inPersonal ) | 248 | if ( m_inPersonal ) |
239 | return; | 249 | return; |
240 | 250 | ||
241 | // Now switch to vCard Backend and load data. | 251 | // Now switch to vCard Backend and load data. |
242 | // The current default backend will be stored | 252 | // The current default backend will be stored |
243 | // to avoid unneeded load/stores. | 253 | // to avoid unneeded load/stores. |
244 | m_storedDB = m_contactdb; | 254 | m_storedDB = m_contactdb; |
245 | 255 | ||
246 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 256 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
247 | addressbookPersonalVCardName() ); | 257 | addressbookPersonalVCardName() ); |
248 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 258 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
249 | 259 | ||
250 | m_inPersonal = true; | 260 | m_inPersonal = true; |
251 | m_curr_View = CardView; | 261 | m_curr_View = CardView; |
252 | 262 | ||
253 | }else{ | 263 | }else{ |
254 | 264 | ||
255 | if ( !m_inPersonal ) | 265 | if ( !m_inPersonal ) |
256 | return; | 266 | return; |
257 | 267 | ||
258 | // Remove vCard Backend and restore default | 268 | // Remove vCard Backend and restore default |
259 | m_contactdb->save(); | 269 | m_contactdb->save(); |
260 | delete m_contactdb; | 270 | delete m_contactdb; |
261 | 271 | ||
262 | m_contactdb = m_storedDB; | 272 | m_contactdb = m_storedDB; |
263 | m_storedDB = 0l; | 273 | m_storedDB = 0l; |
264 | 274 | ||
265 | m_curr_View = TableView; | 275 | m_curr_View = TableView; |
266 | m_inPersonal = false; | 276 | m_inPersonal = false; |
267 | 277 | ||
268 | } | 278 | } |
269 | load(); | 279 | load(); |
270 | } | 280 | } |
271 | 281 | ||
272 | QStringList AbView::categories() | 282 | QStringList AbView::categories() |
273 | { | 283 | { |
274 | mCat.load( categoryFileName() ); | 284 | mCat.load( categoryFileName() ); |
275 | QStringList categoryList = mCat.labels( "Contacts" ); | 285 | QStringList categoryList = mCat.labels( "Contacts" ); |
276 | return categoryList; | 286 | return categoryList; |
277 | } | 287 | } |
278 | 288 | ||
279 | // BEGIN: Slots | 289 | // BEGIN: Slots |
280 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | 290 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, |
281 | bool , QString cat = QString::null ) | 291 | bool , QString cat = QString::null ) |
282 | { | 292 | { |
283 | qWarning( "void AbView::slotDoFind" ); | 293 | qWarning( "void AbView::slotDoFind" ); |
284 | 294 | ||
285 | // We reloading the data: Deselect Letterpicker | 295 | // We reloading the data: Deselect Letterpicker |
286 | emit signalClearLetterPicker(); | 296 | emit signalClearLetterPicker(); |
287 | 297 | ||
288 | // Use the current Category if nothing else selected | 298 | // Use the current Category if nothing else selected |
289 | int category = 0; | 299 | int category = 0; |
290 | 300 | ||
291 | if ( cat.isEmpty() ) | 301 | if ( cat.isEmpty() ) |
292 | category = m_curr_category; | 302 | category = m_curr_category; |
293 | else{ | 303 | else{ |
294 | category = mCat.id("Contacts", cat ); | 304 | category = mCat.id("Contacts", cat ); |
295 | } | 305 | } |
296 | 306 | ||
297 | qWarning ("Find in Category %d", category); | 307 | qWarning ("Find in Category %d", category); |
298 | 308 | ||
299 | QRegExp r( str ); | 309 | QRegExp r( str ); |
300 | r.setCaseSensitive( caseSensitive ); | 310 | r.setCaseSensitive( caseSensitive ); |
301 | r.setWildcard( !useRegExp ); | 311 | r.setWildcard( !useRegExp ); |
302 | 312 | ||
303 | // Get all matching entries out of the database | 313 | // Get all matching entries out of the database |
304 | m_list = m_contactdb->matchRegexp( r ); | 314 | m_list = m_contactdb->matchRegexp( r ); |
305 | 315 | ||
306 | qWarning( "found: %d", m_list.count() ); | 316 | qWarning( "found: %d", m_list.count() ); |
307 | if ( m_list.count() == 0 ){ | 317 | if ( m_list.count() == 0 ){ |
308 | emit signalNotFound(); | 318 | emit signalNotFound(); |
309 | return; | 319 | return; |
310 | } | 320 | } |
311 | 321 | ||
312 | // Now remove all contacts with wrong category (if any selected) | 322 | // Now remove all contacts with wrong category (if any selected) |
313 | // This algorithm is a litte bit ineffective, but | 323 | // This algorithm is a litte bit ineffective, but |
314 | // we will not have a lot of matching entries.. | 324 | // we will not have a lot of matching entries.. |
315 | clearForCategory(); | 325 | clearForCategory(); |
316 | 326 | ||
317 | // Now show all found entries | 327 | // Now show all found entries |
318 | updateView(); | 328 | updateView(); |
319 | } | 329 | } |
320 | 330 | ||
321 | void AbView::offSearch() | 331 | void AbView::offSearch() |
322 | { | 332 | { |
323 | m_inSearch = false; | 333 | m_inSearch = false; |
324 | 334 | ||
325 | load(); | 335 | load(); |
326 | } | 336 | } |
327 | 337 | ||
328 | void AbView::slotSwitch(){ | 338 | void AbView::slotSwitch(){ |
329 | qWarning("AbView::slotSwitch()"); | 339 | qWarning("AbView::slotSwitch()"); |
330 | 340 | ||
331 | m_prev_View = m_curr_View; | 341 | m_prev_View = m_curr_View; |
332 | switch ( (int) m_curr_View ){ | 342 | switch ( (int) m_curr_View ){ |
333 | case TableView: | 343 | case TableView: |
334 | qWarning("Switching to CardView"); | 344 | qWarning("Switching to CardView"); |
335 | m_curr_View = CardView; | 345 | m_curr_View = CardView; |
336 | break; | 346 | break; |
337 | case CardView: | 347 | case CardView: |
338 | qWarning("Switching to TableView"); | 348 | qWarning("Switching to TableView"); |
339 | m_curr_View = TableView; | 349 | m_curr_View = TableView; |
340 | break; | 350 | break; |
341 | } | 351 | } |
342 | updateView(); | 352 | updateView(); |
343 | 353 | ||
344 | } | 354 | } |
345 | 355 | ||
346 | // END: Slots | 356 | // END: Slots |
347 | 357 | ||
348 | void AbView::clearForCategory() | 358 | void AbView::clearForCategory() |
349 | { | 359 | { |
350 | OContactAccess::List::Iterator it; | 360 | OContactAccess::List::Iterator it; |
351 | // Now remove all contacts with wrong category if any category selected | 361 | // Now remove all contacts with wrong category if any category selected |
352 | 362 | ||
353 | OContactAccess::List allList = m_list; | 363 | OContactAccess::List allList = m_list; |
354 | if ( m_curr_category != -1 ){ | 364 | if ( m_curr_category != -1 ){ |
355 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 365 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
356 | if ( !contactCompare( *it, m_curr_category ) ){ | 366 | if ( !contactCompare( *it, m_curr_category ) ){ |
357 | qWarning("Removing %d", (*it).uid()); | 367 | qWarning("Removing %d", (*it).uid()); |
358 | m_list.remove( (*it).uid() ); | 368 | m_list.remove( (*it).uid() ); |
359 | } | 369 | } |
360 | } | 370 | } |
361 | } | 371 | } |
362 | 372 | ||
363 | } | 373 | } |
364 | 374 | ||
365 | bool AbView::contactCompare( const OContact &cnt, int category ) | 375 | bool AbView::contactCompare( const OContact &cnt, int category ) |
366 | { | 376 | { |
367 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); | 377 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); |
368 | 378 | ||
369 | bool returnMe; | 379 | bool returnMe; |
370 | QArray<int> cats; | 380 | QArray<int> cats; |
371 | cats = cnt.categories(); | 381 | cats = cnt.categories(); |
372 | 382 | ||
373 | qWarning ("Number of categories: %d", cats.count() ); | 383 | qWarning ("Number of categories: %d", cats.count() ); |
374 | 384 | ||
375 | returnMe = false; | 385 | returnMe = false; |
376 | if ( cats.count() == 0 && category == 0 ) | 386 | if ( cats.count() == 0 && category == 0 ) |
377 | // Contacts with no category will just shown on "All" and "Unfiled" | 387 | // Contacts with no category will just shown on "All" and "Unfiled" |
378 | returnMe = true; | 388 | returnMe = true; |
379 | else { | 389 | else { |
380 | int i; | 390 | int i; |
381 | for ( i = 0; i < int(cats.count()); i++ ) { | 391 | for ( i = 0; i < int(cats.count()); i++ ) { |
382 | qWarning("Comparing %d with %d",cats[i],category ); | 392 | qWarning("Comparing %d with %d",cats[i],category ); |
383 | if ( cats[i] == category ) { | 393 | if ( cats[i] == category ) { |
384 | returnMe = true; | 394 | returnMe = true; |
385 | break; | 395 | break; |
386 | } | 396 | } |
387 | } | 397 | } |
388 | } | 398 | } |
389 | qWarning ("Return: %d", returnMe); | 399 | qWarning ("Return: %d", returnMe); |
390 | return returnMe; | 400 | return returnMe; |
391 | } | 401 | } |
392 | 402 | ||
393 | // In Some rare cases we have to update all lists.. | 403 | // In Some rare cases we have to update all lists.. |
394 | void AbView::updateListinViews() | 404 | void AbView::updateListinViews() |
395 | { | 405 | { |
396 | m_abTable -> setContacts( m_list ); | 406 | m_abTable -> setContacts( m_list ); |
397 | m_ablabel -> setContacts( m_list ); | 407 | m_ablabel -> setContacts( m_list ); |
398 | } | 408 | } |
399 | 409 | ||
400 | void AbView::updateView() | 410 | void AbView::updateView() |
401 | { | 411 | { |
402 | qWarning("AbView::updateView()"); | 412 | qWarning("AbView::updateView()"); |
403 | 413 | ||
414 | // Feed all views with new lists | ||
415 | updateListinViews(); | ||
416 | |||
404 | if ( m_viewStack -> visibleWidget() ){ | 417 | if ( m_viewStack -> visibleWidget() ){ |
405 | m_viewStack -> visibleWidget() -> clearFocus(); | 418 | m_viewStack -> visibleWidget() -> clearFocus(); |
406 | } | 419 | } |
407 | 420 | ||
408 | // If we switching the view, we have to store some information | 421 | // If we switching the view, we have to store some information |
409 | if ( m_list.count() ){ | 422 | if ( m_list.count() ){ |
410 | switch ( (int) m_prev_View ) { | 423 | switch ( (int) m_prev_View ) { |
411 | case TableView: | 424 | case TableView: |
412 | m_curr_Contact = m_abTable -> currentEntry_UID(); | 425 | m_curr_Contact = m_abTable -> currentEntry_UID(); |
413 | break; | 426 | break; |
414 | case CardView: | 427 | case CardView: |
415 | m_curr_Contact = m_ablabel -> currentEntry_UID(); | 428 | m_curr_Contact = m_ablabel -> currentEntry_UID(); |
416 | break; | 429 | break; |
417 | } | 430 | } |
418 | emit signalViewSwitched ( (int) m_curr_View ); | ||
419 | }else | 431 | }else |
420 | m_curr_Contact = 0; | 432 | m_curr_Contact = 0; |
421 | 433 | ||
434 | // Inform the world that the view is changed | ||
435 | if ( m_curr_View != m_prev_View ) | ||
436 | emit signalViewSwitched ( (int) m_curr_View ); | ||
437 | |||
422 | m_prev_View = m_curr_View; | 438 | m_prev_View = m_curr_View; |
423 | 439 | ||
424 | // Switch to new View | 440 | // Switch to new View |
425 | switch ( (int) m_curr_View ) { | 441 | switch ( (int) m_curr_View ) { |
426 | case TableView: | 442 | case TableView: |
427 | m_abTable -> setChoiceSelection( m_orderedFields ); | 443 | m_abTable -> setChoiceSelection( m_orderedFields ); |
428 | m_abTable -> setContacts( m_list ); | ||
429 | if ( m_curr_Contact != 0 ) | 444 | if ( m_curr_Contact != 0 ) |
430 | m_abTable -> selectContact ( m_curr_Contact ); | 445 | m_abTable -> selectContact ( m_curr_Contact ); |
431 | m_abTable -> setFocus(); | 446 | m_abTable -> setFocus(); |
432 | break; | 447 | break; |
433 | case CardView: | 448 | case CardView: |
434 | m_ablabel -> setContacts( m_list ); | ||
435 | if ( m_curr_Contact != 0 ) | 449 | if ( m_curr_Contact != 0 ) |
436 | m_ablabel -> selectContact( m_curr_Contact ); | 450 | m_ablabel -> selectContact( m_curr_Contact ); |
437 | m_ablabel -> setFocus(); | 451 | m_ablabel -> setFocus(); |
438 | break; | 452 | break; |
439 | } | 453 | } |
440 | 454 | ||
441 | // Raise the current View | 455 | // Raise the current View |
442 | m_viewStack -> raiseWidget( m_curr_View ); | 456 | m_viewStack -> raiseWidget( m_curr_View ); |
443 | } | 457 | } |
444 | 458 | ||
445 | 459 | ||
diff --git a/core/pim/addressbook/abview.h b/core/pim/addressbook/abview.h index 201b521..2c10cfa 100644 --- a/core/pim/addressbook/abview.h +++ b/core/pim/addressbook/abview.h | |||
@@ -1,86 +1,87 @@ | |||
1 | #ifndef _ABVIEW_H_ | 1 | #ifndef _ABVIEW_H_ |
2 | #define _ABVIEW_H_ | 2 | #define _ABVIEW_H_ |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qwidgetstack.h> | 5 | #include <qwidgetstack.h> |
6 | 6 | ||
7 | #include <qpe/categories.h> | 7 | #include <qpe/categories.h> |
8 | #include <opie/ocontact.h> | 8 | #include <opie/ocontact.h> |
9 | #include <opie/ocontactaccess.h> | 9 | #include <opie/ocontactaccess.h> |
10 | 10 | ||
11 | #include "contacteditor.h" | 11 | #include "contacteditor.h" |
12 | #include "abtable.h" | 12 | #include "abtable.h" |
13 | #include "ablabel.h" | 13 | #include "ablabel.h" |
14 | 14 | ||
15 | class AbView: public QWidget | 15 | class AbView: public QWidget |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | 18 | ||
19 | public: | 19 | public: |
20 | enum Views{ TableView=0, CardView, PersonalView }; | 20 | enum Views{ TableView=0, CardView, PersonalView }; |
21 | 21 | ||
22 | AbView( QWidget* parent, const QValueList<int>& ordered ); | 22 | AbView( QWidget* parent, const QValueList<int>& ordered ); |
23 | ~AbView(); | 23 | ~AbView(); |
24 | 24 | ||
25 | bool save(); | 25 | bool save(); |
26 | void load(); | 26 | void load(); |
27 | void reload(); | 27 | void reload(); |
28 | void clear(); | 28 | void clear(); |
29 | 29 | ||
30 | void setView( Views view ); | 30 | void setView( Views view ); |
31 | void showPersonal( bool personal ); | 31 | void showPersonal( bool personal ); |
32 | void setShowByCategory( Views view, const QString& cat ); | 32 | void setShowByCategory( const QString& cat ); |
33 | void setShowToView( Views view ); | ||
33 | void setShowByLetter( char c ); | 34 | void setShowByLetter( char c ); |
34 | void setListOrder( const QValueList<int>& ordered ); | 35 | void setListOrder( const QValueList<int>& ordered ); |
35 | 36 | ||
36 | // Add Entry and put to current | 37 | // Add Entry and put to current |
37 | void addEntry( const OContact &newContact ); | 38 | void addEntry( const OContact &newContact ); |
38 | void removeEntry( const int UID ); | 39 | void removeEntry( const int UID ); |
39 | void replaceEntry( const OContact &contact ); | 40 | void replaceEntry( const OContact &contact ); |
40 | OContact currentEntry(); | 41 | OContact currentEntry(); |
41 | 42 | ||
42 | void inSearch() { m_inSearch = true; } | 43 | void inSearch() { m_inSearch = true; } |
43 | void offSearch(); | 44 | void offSearch(); |
44 | 45 | ||
45 | QString showCategory() const; | 46 | QString showCategory() const; |
46 | QStringList categories(); | 47 | QStringList categories(); |
47 | 48 | ||
48 | signals: | 49 | signals: |
49 | void signalNotFound(); | 50 | void signalNotFound(); |
50 | void signalClearLetterPicker(); | 51 | void signalClearLetterPicker(); |
51 | void signalViewSwitched ( int ); | 52 | void signalViewSwitched ( int ); |
52 | 53 | ||
53 | public slots: | 54 | public slots: |
54 | void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | 55 | void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, |
55 | bool backwards, QString category = QString::null ); | 56 | bool backwards, QString category = QString::null ); |
56 | void slotSwitch(); | 57 | void slotSwitch(); |
57 | 58 | ||
58 | private: | 59 | private: |
59 | void updateListinViews(); | 60 | void updateListinViews(); |
60 | void updateView(); | 61 | void updateView(); |
61 | void clearForCategory(); | 62 | void clearForCategory(); |
62 | bool contactCompare( const OContact &cnt, int category ); | 63 | bool contactCompare( const OContact &cnt, int category ); |
63 | void parseName( const QString& name, QString *first, QString *middle, | 64 | void parseName( const QString& name, QString *first, QString *middle, |
64 | QString * last ); | 65 | QString * last ); |
65 | 66 | ||
66 | Categories mCat; | 67 | Categories mCat; |
67 | bool m_inSearch; | 68 | bool m_inSearch; |
68 | bool m_inPersonal; | 69 | bool m_inPersonal; |
69 | int m_curr_category; | 70 | int m_curr_category; |
70 | Views m_curr_View; | 71 | Views m_curr_View; |
71 | Views m_prev_View; | 72 | Views m_prev_View; |
72 | int m_curr_Contact; | 73 | int m_curr_Contact; |
73 | 74 | ||
74 | OContactAccess* m_contactdb; | 75 | OContactAccess* m_contactdb; |
75 | OContactAccess* m_storedDB; | 76 | OContactAccess* m_storedDB; |
76 | OContactAccess::List m_list; | 77 | OContactAccess::List m_list; |
77 | 78 | ||
78 | QWidgetStack* m_viewStack; | 79 | QWidgetStack* m_viewStack; |
79 | AbTable* m_abTable; | 80 | AbTable* m_abTable; |
80 | AbLabel* m_ablabel; | 81 | AbLabel* m_ablabel; |
81 | 82 | ||
82 | QValueList<int> m_orderedFields; | 83 | QValueList<int> m_orderedFields; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | 86 | ||
86 | #endif | 87 | #endif |
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 3b2e4b8..5d588da 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -440,521 +440,511 @@ void AddressbookWindow::slotFindClose() | |||
440 | 440 | ||
441 | 441 | ||
442 | void AddressbookWindow::slotFind() | 442 | void AddressbookWindow::slotFind() |
443 | { | 443 | { |
444 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); | 444 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); |
445 | 445 | ||
446 | searchEdit->clearFocus(); | 446 | searchEdit->clearFocus(); |
447 | // m_abView->setFocus(); | 447 | // m_abView->setFocus(); |
448 | 448 | ||
449 | } | 449 | } |
450 | 450 | ||
451 | void AddressbookWindow::slotViewBack() | 451 | void AddressbookWindow::slotViewBack() |
452 | { | 452 | { |
453 | // :SX showList(); | 453 | // :SX showList(); |
454 | } | 454 | } |
455 | 455 | ||
456 | void AddressbookWindow::slotViewEdit() | 456 | void AddressbookWindow::slotViewEdit() |
457 | { | 457 | { |
458 | if(!syncing) { | 458 | if(!syncing) { |
459 | if (actionPersonal->isOn()) { | 459 | if (actionPersonal->isOn()) { |
460 | editPersonal(); | 460 | editPersonal(); |
461 | } else { | 461 | } else { |
462 | editEntry( EditEntry ); | 462 | editEntry( EditEntry ); |
463 | } | 463 | } |
464 | } else { | 464 | } else { |
465 | QMessageBox::warning( this, tr("Contacts"), | 465 | QMessageBox::warning( this, tr("Contacts"), |
466 | tr("Can not edit data, currently syncing") ); | 466 | tr("Can not edit data, currently syncing") ); |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | 471 | ||
472 | void AddressbookWindow::writeMail() | 472 | void AddressbookWindow::writeMail() |
473 | { | 473 | { |
474 | OContact c = m_abView -> currentEntry(); | 474 | OContact c = m_abView -> currentEntry(); |
475 | QString name = c.fileAs(); | 475 | QString name = c.fileAs(); |
476 | QString email = c.defaultEmail(); | 476 | QString email = c.defaultEmail(); |
477 | 477 | ||
478 | // I prefer the OPIE-Environment variable before the | 478 | // I prefer the OPIE-Environment variable before the |
479 | // QPE-one.. | 479 | // QPE-one.. |
480 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); | 480 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); |
481 | if ( basepath.isEmpty() ) | 481 | if ( basepath.isEmpty() ) |
482 | basepath = QString::fromLatin1( getenv("QPEDIR") ); | 482 | basepath = QString::fromLatin1( getenv("QPEDIR") ); |
483 | 483 | ||
484 | // Try to access the preferred. If not possible, try to | 484 | // Try to access the preferred. If not possible, try to |
485 | // switch to the other one.. | 485 | // switch to the other one.. |
486 | if ( m_config.useQtMail() ){ | 486 | if ( m_config.useQtMail() ){ |
487 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); | 487 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); |
488 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ | 488 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ |
489 | qWarning ("QCop"); | 489 | qWarning ("QCop"); |
490 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 490 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
491 | e << name << email; | 491 | e << name << email; |
492 | return; | 492 | return; |
493 | } else | 493 | } else |
494 | m_config.setUseOpieMail( true ); | 494 | m_config.setUseOpieMail( true ); |
495 | } | 495 | } |
496 | if ( m_config.useOpieMail() ){ | 496 | if ( m_config.useOpieMail() ){ |
497 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); | 497 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); |
498 | if ( QFile::exists( basepath + "/bin/mail" ) ){ | 498 | if ( QFile::exists( basepath + "/bin/mail" ) ){ |
499 | qWarning ("QCop"); | 499 | qWarning ("QCop"); |
500 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); | 500 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); |
501 | e << name << email; | 501 | e << name << email; |
502 | return; | 502 | return; |
503 | } else | 503 | } else |
504 | m_config.setUseQtMail( true ); | 504 | m_config.setUseQtMail( true ); |
505 | } | 505 | } |
506 | 506 | ||
507 | } | 507 | } |
508 | 508 | ||
509 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 509 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
510 | 510 | ||
511 | void AddressbookWindow::slotBeam() | 511 | void AddressbookWindow::slotBeam() |
512 | { | 512 | { |
513 | QString filename; | 513 | QString filename; |
514 | OContact c; | 514 | OContact c; |
515 | if ( actionPersonal->isOn() ) { | 515 | if ( actionPersonal->isOn() ) { |
516 | filename = addressbookPersonalVCardName(); | 516 | filename = addressbookPersonalVCardName(); |
517 | if (!QFile::exists(filename)) | 517 | if (!QFile::exists(filename)) |
518 | return; // can't beam a non-existent file | 518 | return; // can't beam a non-existent file |
519 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 519 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
520 | filename ); | 520 | filename ); |
521 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 521 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
522 | OContactAccess::List allList = access->allRecords(); | 522 | OContactAccess::List allList = access->allRecords(); |
523 | OContactAccess::List::Iterator it = allList.begin(); // Just take first | 523 | OContactAccess::List::Iterator it = allList.begin(); // Just take first |
524 | c = *it; | 524 | c = *it; |
525 | 525 | ||
526 | delete access; | 526 | delete access; |
527 | } else { | 527 | } else { |
528 | unlink( beamfile ); // delete if exists | 528 | unlink( beamfile ); // delete if exists |
529 | mkdir("/tmp/obex/", 0755); | 529 | mkdir("/tmp/obex/", 0755); |
530 | c = m_abView -> currentEntry(); | 530 | c = m_abView -> currentEntry(); |
531 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 531 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
532 | beamfile ); | 532 | beamfile ); |
533 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 533 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
534 | access->add( c ); | 534 | access->add( c ); |
535 | access->save(); | 535 | access->save(); |
536 | delete access; | 536 | delete access; |
537 | 537 | ||
538 | filename = beamfile; | 538 | filename = beamfile; |
539 | } | 539 | } |
540 | 540 | ||
541 | 541 | ||
542 | Ir *ir = new Ir( this ); | 542 | Ir *ir = new Ir( this ); |
543 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 543 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
544 | QString description = c.fullName(); | 544 | QString description = c.fullName(); |
545 | ir->send( filename, description, "text/x-vCard" ); | 545 | ir->send( filename, description, "text/x-vCard" ); |
546 | } | 546 | } |
547 | 547 | ||
548 | void AddressbookWindow::beamDone( Ir *ir ) | 548 | void AddressbookWindow::beamDone( Ir *ir ) |
549 | { | 549 | { |
550 | delete ir; | 550 | delete ir; |
551 | unlink( beamfile ); | 551 | unlink( beamfile ); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | static void parseName( const QString& name, QString *first, QString *middle, | 555 | static void parseName( const QString& name, QString *first, QString *middle, |
556 | QString * last ) | 556 | QString * last ) |
557 | { | 557 | { |
558 | 558 | ||
559 | int comma = name.find ( "," ); | 559 | int comma = name.find ( "," ); |
560 | QString rest; | 560 | QString rest; |
561 | if ( comma > 0 ) { | 561 | if ( comma > 0 ) { |
562 | *last = name.left( comma ); | 562 | *last = name.left( comma ); |
563 | comma++; | 563 | comma++; |
564 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 564 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
565 | comma++; | 565 | comma++; |
566 | rest = name.mid( comma ); | 566 | rest = name.mid( comma ); |
567 | } else { | 567 | } else { |
568 | int space = name.findRev( ' ' ); | 568 | int space = name.findRev( ' ' ); |
569 | *last = name.mid( space+1 ); | 569 | *last = name.mid( space+1 ); |
570 | rest = name.left( space ); | 570 | rest = name.left( space ); |
571 | } | 571 | } |
572 | int space = rest.find( ' ' ); | 572 | int space = rest.find( ' ' ); |
573 | if ( space <= 0 ) { | 573 | if ( space <= 0 ) { |
574 | *first = rest; | 574 | *first = rest; |
575 | } else { | 575 | } else { |
576 | *first = rest.left( space ); | 576 | *first = rest.left( space ); |
577 | *middle = rest.mid( space+1 ); | 577 | *middle = rest.mid( space+1 ); |
578 | } | 578 | } |
579 | 579 | ||
580 | } | 580 | } |
581 | 581 | ||
582 | 582 | ||
583 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 583 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
584 | { | 584 | { |
585 | if (msg == "editPersonal()") { | 585 | if (msg == "editPersonal()") { |
586 | editPersonal(); | 586 | editPersonal(); |
587 | } else if (msg == "editPersonalAndClose()") { | 587 | } else if (msg == "editPersonalAndClose()") { |
588 | editPersonal(); | 588 | editPersonal(); |
589 | close(); | 589 | close(); |
590 | } else if ( msg == "addContact(QString,QString)" ) { | 590 | } else if ( msg == "addContact(QString,QString)" ) { |
591 | QDataStream stream(data,IO_ReadOnly); | 591 | QDataStream stream(data,IO_ReadOnly); |
592 | QString name, email; | 592 | QString name, email; |
593 | stream >> name >> email; | 593 | stream >> name >> email; |
594 | 594 | ||
595 | OContact cnt; | 595 | OContact cnt; |
596 | QString fn, mn, ln; | 596 | QString fn, mn, ln; |
597 | parseName( name, &fn, &mn, &ln ); | 597 | parseName( name, &fn, &mn, &ln ); |
598 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); | 598 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); |
599 | cnt.setFirstName( fn ); | 599 | cnt.setFirstName( fn ); |
600 | cnt.setMiddleName( mn ); | 600 | cnt.setMiddleName( mn ); |
601 | cnt.setLastName( ln ); | 601 | cnt.setLastName( ln ); |
602 | cnt.insertEmails( email ); | 602 | cnt.insertEmails( email ); |
603 | cnt.setDefaultEmail( email ); | 603 | cnt.setDefaultEmail( email ); |
604 | cnt.setFileAs(); | 604 | cnt.setFileAs(); |
605 | 605 | ||
606 | m_abView -> addEntry( cnt ); | 606 | m_abView -> addEntry( cnt ); |
607 | 607 | ||
608 | // :SXm_abView()->init( cnt ); | 608 | // :SXm_abView()->init( cnt ); |
609 | editEntry( EditEntry ); | 609 | editEntry( EditEntry ); |
610 | 610 | ||
611 | 611 | ||
612 | 612 | ||
613 | } | 613 | } |
614 | #if 0 | 614 | #if 0 |
615 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { | 615 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { |
616 | QDataStream stream(data,IO_ReadOnly); | 616 | QDataStream stream(data,IO_ReadOnly); |
617 | QCString ch,m; | 617 | QCString ch,m; |
618 | QStringList types; | 618 | QStringList types; |
619 | stream >> ch >> m >> types; | 619 | stream >> ch >> m >> types; |
620 | AddressPicker picker(abList,this,0,TRUE); | 620 | AddressPicker picker(abList,this,0,TRUE); |
621 | picker.showMaximized(); | 621 | picker.showMaximized(); |
622 | picker.setChoiceNames(types); | 622 | picker.setChoiceNames(types); |
623 | int i=0; | 623 | int i=0; |
624 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 624 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
625 | QStringList sel; | 625 | QStringList sel; |
626 | stream >> sel; | 626 | stream >> sel; |
627 | picker.setSelection(i++,sel); | 627 | picker.setSelection(i++,sel); |
628 | } | 628 | } |
629 | picker.showMaximized(); | 629 | picker.showMaximized(); |
630 | picker.exec(); | 630 | picker.exec(); |
631 | 631 | ||
632 | // ###### note: contacts may have been added - save here! | 632 | // ###### note: contacts may have been added - save here! |
633 | 633 | ||
634 | setCentralWidget(abList); | 634 | setCentralWidget(abList); |
635 | QCopEnvelope e(ch,m); | 635 | QCopEnvelope e(ch,m); |
636 | i=0; | 636 | i=0; |
637 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 637 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
638 | QStringList sel = picker.selection(i++); | 638 | QStringList sel = picker.selection(i++); |
639 | e << sel; | 639 | e << sel; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | #endif | 642 | #endif |
643 | 643 | ||
644 | } | 644 | } |
645 | 645 | ||
646 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 646 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
647 | { | 647 | { |
648 | OContact entry; | 648 | OContact entry; |
649 | if ( !abEditor ) { | 649 | if ( !abEditor ) { |
650 | abEditor = new ContactEditor( entry, this, "editor" ); | 650 | abEditor = new ContactEditor( entry, this, "editor" ); |
651 | } | 651 | } |
652 | if ( entryMode == EditEntry ) | 652 | if ( entryMode == EditEntry ) |
653 | abEditor->setEntry( m_abView -> currentEntry() ); | 653 | abEditor->setEntry( m_abView -> currentEntry() ); |
654 | else if ( entryMode == NewEntry ) | 654 | else if ( entryMode == NewEntry ) |
655 | abEditor->setEntry( entry ); | 655 | abEditor->setEntry( entry ); |
656 | // other things may chane the caption. | 656 | // other things may chane the caption. |
657 | abEditor->setCaption( tr("Edit Address") ); | 657 | abEditor->setCaption( tr("Edit Address") ); |
658 | 658 | ||
659 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 659 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
660 | abEditor->showMaximized(); | 660 | abEditor->showMaximized(); |
661 | #endif | 661 | #endif |
662 | // fix the foxus... | 662 | // fix the foxus... |
663 | abEditor->setNameFocus(); | 663 | abEditor->setNameFocus(); |
664 | if ( abEditor->exec() ) { | 664 | if ( abEditor->exec() ) { |
665 | setFocus(); | 665 | setFocus(); |
666 | if ( entryMode == NewEntry ) { | 666 | if ( entryMode == NewEntry ) { |
667 | OContact insertEntry = abEditor->entry(); | 667 | OContact insertEntry = abEditor->entry(); |
668 | insertEntry.assignUid(); | 668 | insertEntry.assignUid(); |
669 | m_abView -> addEntry( insertEntry ); | 669 | m_abView -> addEntry( insertEntry ); |
670 | } else { | 670 | } else { |
671 | OContact replEntry = abEditor->entry(); | 671 | OContact replEntry = abEditor->entry(); |
672 | 672 | ||
673 | if ( !replEntry.isValidUid() ) | 673 | if ( !replEntry.isValidUid() ) |
674 | replEntry.assignUid(); | 674 | replEntry.assignUid(); |
675 | 675 | ||
676 | m_abView -> replaceEntry( replEntry ); | 676 | m_abView -> replaceEntry( replEntry ); |
677 | } | 677 | } |
678 | } | 678 | } |
679 | // populateCategories(); | 679 | // populateCategories(); |
680 | 680 | ||
681 | } | 681 | } |
682 | 682 | ||
683 | void AddressbookWindow::editPersonal() | 683 | void AddressbookWindow::editPersonal() |
684 | { | 684 | { |
685 | OContact entry; | 685 | OContact entry; |
686 | if ( !abEditor ) { | 686 | if ( !abEditor ) { |
687 | abEditor = new ContactEditor( entry, this, "editor" ); | 687 | abEditor = new ContactEditor( entry, this, "editor" ); |
688 | } | 688 | } |
689 | 689 | ||
690 | abEditor->setCaption(tr("Edit My Personal Details")); | 690 | abEditor->setCaption(tr("Edit My Personal Details")); |
691 | abEditor->setPersonalView( true ); | 691 | abEditor->setPersonalView( true ); |
692 | editEntry( EditEntry ); | 692 | editEntry( EditEntry ); |
693 | abEditor->setPersonalView( false ); | 693 | abEditor->setPersonalView( false ); |
694 | 694 | ||
695 | } | 695 | } |
696 | 696 | ||
697 | 697 | ||
698 | void AddressbookWindow::slotPersonalView() | 698 | void AddressbookWindow::slotPersonalView() |
699 | { | 699 | { |
700 | if (!actionPersonal->isOn()) { | 700 | if (!actionPersonal->isOn()) { |
701 | // we just turned it off | 701 | // we just turned it off |
702 | setCaption( tr("Contacts") ); | 702 | setCaption( tr("Contacts") ); |
703 | actionNew->setEnabled(TRUE); | 703 | actionNew->setEnabled(TRUE); |
704 | actionTrash->setEnabled(TRUE); | 704 | actionTrash->setEnabled(TRUE); |
705 | actionFind->setEnabled(TRUE); | 705 | actionFind->setEnabled(TRUE); |
706 | actionMail->setEnabled(TRUE); | 706 | actionMail->setEnabled(TRUE); |
707 | // slotUpdateToolbar(); | 707 | // slotUpdateToolbar(); |
708 | 708 | ||
709 | m_abView->showPersonal( false ); | 709 | m_abView->showPersonal( false ); |
710 | 710 | ||
711 | return; | 711 | return; |
712 | } | 712 | } |
713 | 713 | ||
714 | // XXX need to disable some QActions. | 714 | // XXX need to disable some QActions. |
715 | actionNew->setEnabled(FALSE); | 715 | actionNew->setEnabled(FALSE); |
716 | actionTrash->setEnabled(FALSE); | 716 | actionTrash->setEnabled(FALSE); |
717 | actionFind->setEnabled(FALSE); | 717 | actionFind->setEnabled(FALSE); |
718 | actionMail->setEnabled(FALSE); | 718 | actionMail->setEnabled(FALSE); |
719 | 719 | ||
720 | setCaption( tr("Contacts - My Personal Details") ); | 720 | setCaption( tr("Contacts - My Personal Details") ); |
721 | 721 | ||
722 | m_abView->showPersonal( true ); | 722 | m_abView->showPersonal( true ); |
723 | 723 | ||
724 | } | 724 | } |
725 | 725 | ||
726 | 726 | ||
727 | void AddressbookWindow::listIsEmpty( bool empty ) | 727 | void AddressbookWindow::listIsEmpty( bool empty ) |
728 | { | 728 | { |
729 | if ( !empty ) { | 729 | if ( !empty ) { |
730 | deleteButton->setEnabled( TRUE ); | 730 | deleteButton->setEnabled( TRUE ); |
731 | } | 731 | } |
732 | } | 732 | } |
733 | 733 | ||
734 | void AddressbookWindow::reload() | 734 | void AddressbookWindow::reload() |
735 | { | 735 | { |
736 | syncing = FALSE; | 736 | syncing = FALSE; |
737 | m_abView->clear(); | 737 | m_abView->clear(); |
738 | m_abView->reload(); | 738 | m_abView->reload(); |
739 | } | 739 | } |
740 | 740 | ||
741 | void AddressbookWindow::flush() | 741 | void AddressbookWindow::flush() |
742 | { | 742 | { |
743 | syncing = TRUE; | 743 | syncing = TRUE; |
744 | m_abView->save(); | 744 | m_abView->save(); |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
748 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 748 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
749 | { | 749 | { |
750 | 750 | ||
751 | if(syncing) { | 751 | if(syncing) { |
752 | /* shouldn't we save, I hear you say? well its already been set | 752 | /* shouldn't we save, I hear you say? well its already been set |
753 | so that an edit can not occur during a sync, and we flushed | 753 | so that an edit can not occur during a sync, and we flushed |
754 | at the start of the sync, so there is no need to save | 754 | at the start of the sync, so there is no need to save |
755 | Saving however itself would cause problems. */ | 755 | Saving however itself would cause problems. */ |
756 | e->accept(); | 756 | e->accept(); |
757 | return; | 757 | return; |
758 | } | 758 | } |
759 | //################## shouldn't always save | 759 | //################## shouldn't always save |
760 | // True, but the database handles this automatically ! (se) | 760 | // True, but the database handles this automatically ! (se) |
761 | if ( save() ) | 761 | if ( save() ) |
762 | e->accept(); | 762 | e->accept(); |
763 | else | 763 | else |
764 | e->ignore(); | 764 | e->ignore(); |
765 | } | 765 | } |
766 | 766 | ||
767 | /* | 767 | /* |
768 | Returns TRUE if it is OK to exit | 768 | Returns TRUE if it is OK to exit |
769 | */ | 769 | */ |
770 | 770 | ||
771 | bool AddressbookWindow::save() | 771 | bool AddressbookWindow::save() |
772 | { | 772 | { |
773 | if ( !m_abView->save() ) { | 773 | if ( !m_abView->save() ) { |
774 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 774 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
775 | tr("Unable to save information.\n" | 775 | tr("Unable to save information.\n" |
776 | "Free up some space\n" | 776 | "Free up some space\n" |
777 | "and try again.\n" | 777 | "and try again.\n" |
778 | "\nQuit anyway?"), | 778 | "\nQuit anyway?"), |
779 | QMessageBox::Yes|QMessageBox::Escape, | 779 | QMessageBox::Yes|QMessageBox::Escape, |
780 | QMessageBox::No|QMessageBox::Default ) | 780 | QMessageBox::No|QMessageBox::Default ) |
781 | != QMessageBox::No ) | 781 | != QMessageBox::No ) |
782 | return TRUE; | 782 | return TRUE; |
783 | else | 783 | else |
784 | return FALSE; | 784 | return FALSE; |
785 | } | 785 | } |
786 | return TRUE; | 786 | return TRUE; |
787 | } | 787 | } |
788 | 788 | ||
789 | #ifdef __DEBUG_RELEASE | 789 | #ifdef __DEBUG_RELEASE |
790 | void AddressbookWindow::slotSave() | 790 | void AddressbookWindow::slotSave() |
791 | { | 791 | { |
792 | save(); | 792 | save(); |
793 | } | 793 | } |
794 | #endif | 794 | #endif |
795 | 795 | ||
796 | 796 | ||
797 | void AddressbookWindow::slotNotFound() | 797 | void AddressbookWindow::slotNotFound() |
798 | { | 798 | { |
799 | qWarning("Got notfound signal !"); | 799 | qWarning("Got notfound signal !"); |
800 | QMessageBox::information( this, tr( "Not Found" ), | 800 | QMessageBox::information( this, tr( "Not Found" ), |
801 | tr( "Unable to find a contact for this \n search pattern!" ) ); | 801 | tr( "Unable to find a contact for this \n search pattern!" ) ); |
802 | 802 | ||
803 | 803 | ||
804 | } | 804 | } |
805 | void AddressbookWindow::slotWrapAround() | 805 | void AddressbookWindow::slotWrapAround() |
806 | { | 806 | { |
807 | qWarning("Got wrap signal !"); | 807 | qWarning("Got wrap signal !"); |
808 | // if ( doNotifyWrapAround ) | 808 | // if ( doNotifyWrapAround ) |
809 | // QMessageBox::information( this, tr( "End of list" ), | 809 | // QMessageBox::information( this, tr( "End of list" ), |
810 | // tr( "End of list. Wrap around now...!" ) + "\n" ); | 810 | // tr( "End of list. Wrap around now...!" ) + "\n" ); |
811 | 811 | ||
812 | } | 812 | } |
813 | 813 | ||
814 | void AddressbookWindow::slotSetCategory( int c ) | 814 | void AddressbookWindow::slotSetCategory( int c ) |
815 | { | 815 | { |
816 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); | 816 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); |
817 | 817 | ||
818 | QString cat, book; | 818 | QString cat, book; |
819 | AbView::Views view = AbView::TableView; | 819 | AbView::Views view = AbView::TableView; |
820 | 820 | ||
821 | if ( c <= 0 ) | 821 | if ( c <= 0 ) |
822 | return; | 822 | return; |
823 | 823 | ||
824 | // Checkmark Book Menu Item Selected | 824 | // Switch view |
825 | if ( c < 3 ) | 825 | if ( c < 3 ) |
826 | for ( unsigned int i = 1; i < 3; i++ ) | 826 | for ( unsigned int i = 1; i < 3; i++ ){ |
827 | catMenu->setItemChecked( i, c == (int)i ); | 827 | if ( catMenu ) |
828 | // Checkmark Category Menu Item Selected | 828 | catMenu->setItemChecked( i, c == (int)i ); |
829 | } | ||
829 | else | 830 | else |
831 | // Checkmark Category Menu Item Selected | ||
830 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) | 832 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) |
831 | catMenu->setItemChecked( i, c == (int)i ); | 833 | catMenu->setItemChecked( i, c == (int)i ); |
832 | 834 | ||
835 | // Now switch to the selected category | ||
833 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { | 836 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { |
834 | if (catMenu->isItemChecked( i )) { | 837 | if (catMenu->isItemChecked( i )) { |
835 | if ( i == 1 ){ // default List view | 838 | if ( i == 1 ){ // default List view |
836 | book = QString::null; | 839 | book = QString::null; |
837 | view = AbView::TableView; | 840 | view = AbView::TableView; |
838 | }else if ( i == 2 ){ | 841 | }else if ( i == 2 ){ |
839 | book = tr( "Cards" ); | 842 | book = tr( "Cards" ); |
840 | view = AbView::CardView; | 843 | view = AbView::CardView; |
841 | // }else if ( i == 3 ){ | 844 | // }else if ( i == 3 ){ |
842 | // book = tr( "Personal" ); | 845 | // book = tr( "Personal" ); |
843 | // view = AbView:: PersonalView; | 846 | // view = AbView:: PersonalView; |
844 | }else if ( i == 3 ){ // default All Categories | 847 | }else if ( i == 3 ){ // default All Categories |
845 | cat = QString::null; | 848 | cat = QString::null; |
846 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled | 849 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled |
847 | cat = "Unfiled"; | 850 | cat = "Unfiled"; |
848 | qWarning ("Unfiled selected!!!"); | 851 | qWarning ("Unfiled selected!!!"); |
849 | }else{ | 852 | }else{ |
850 | cat = m_abView->categories()[i - 4]; | 853 | cat = m_abView->categories()[i - 4]; |
851 | } | 854 | } |
852 | } | 855 | } |
853 | } | 856 | } |
854 | 857 | ||
858 | // Switch to the selected View | ||
855 | slotViewSwitched( view ); | 859 | slotViewSwitched( view ); |
856 | 860 | ||
857 | m_abView -> setShowByCategory( view, cat ); | 861 | // Tell the view about the selected category |
862 | m_abView -> setShowByCategory( cat ); | ||
858 | 863 | ||
859 | if ( book.isEmpty() ) | 864 | if ( book.isEmpty() ) |
860 | book = "List"; | 865 | book = "List"; |
861 | if ( cat.isEmpty() ) | 866 | if ( cat.isEmpty() ) |
862 | cat = "All"; | 867 | cat = "All"; |
863 | 868 | ||
864 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); | 869 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); |
865 | } | 870 | } |
866 | 871 | ||
867 | void AddressbookWindow::slotViewSwitched( int view ) | 872 | void AddressbookWindow::slotViewSwitched( int view ) |
868 | { | 873 | { |
869 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); | 874 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); |
870 | int menu = 0; | 875 | int menu = 0; |
876 | |||
877 | // Switch to selected view | ||
871 | switch ( view ){ | 878 | switch ( view ){ |
872 | case AbView::TableView: | 879 | case AbView::TableView: |
873 | menu = 1; | 880 | menu = 1; |
874 | m_tableViewButton->setOn(true); | 881 | m_tableViewButton->setOn(true); |
875 | m_cardViewButton->setOn(false); | 882 | m_cardViewButton->setOn(false); |
876 | break; | 883 | break; |
877 | case AbView::CardView: | 884 | case AbView::CardView: |
878 | menu = 2; | 885 | menu = 2; |
879 | m_tableViewButton->setOn(false); | 886 | m_tableViewButton->setOn(false); |
880 | m_cardViewButton->setOn(true); | 887 | m_cardViewButton->setOn(true); |
881 | break; | 888 | break; |
882 | // case AbView::PersonalView: | ||
883 | // menu = 3; | ||
884 | // break; | ||
885 | // case AbView::CompanyBook: | ||
886 | // menu = 3; | ||
887 | // break; | ||
888 | // case AbView::EmailBook: | ||
889 | // menu = 4; | ||
890 | // break; | ||
891 | } | 889 | } |
892 | for ( unsigned int i = 1; i < 3; i++ ){ | 890 | for ( unsigned int i = 1; i < 3; i++ ){ |
893 | if ( catMenu ) | 891 | if ( catMenu ) |
894 | catMenu->setItemChecked( i, menu == (int)i ); | 892 | catMenu->setItemChecked( i, menu == (int)i ); |
895 | } | 893 | } |
894 | |||
895 | // Tell the view about the selected view | ||
896 | m_abView -> setShowToView ( (AbView::Views) view ); | ||
897 | |||
896 | } | 898 | } |
897 | 899 | ||
898 | 900 | ||
899 | void AddressbookWindow::slotListView() | 901 | void AddressbookWindow::slotListView() |
900 | { | 902 | { |
901 | emit slotSetCategory( AbView::TableView +1 ); | 903 | slotViewSwitched( AbView::TableView ); |
902 | } | 904 | } |
903 | 905 | ||
904 | void AddressbookWindow::slotCardView() | 906 | void AddressbookWindow::slotCardView() |
905 | { | 907 | { |
906 | emit slotSetCategory( AbView::CardView +1 ); | 908 | slotViewSwitched( AbView::CardView ); |
907 | } | 909 | } |
908 | 910 | ||
909 | void AddressbookWindow::slotSetLetter( char c ) { | 911 | void AddressbookWindow::slotSetLetter( char c ) { |
910 | 912 | ||
911 | m_abView->setShowByLetter( c ); | 913 | m_abView->setShowByLetter( c ); |
912 | 914 | ||
913 | } | 915 | } |
914 | 916 | ||
915 | 917 | ||
916 | void AddressbookWindow::populateCategories() | 918 | void AddressbookWindow::populateCategories() |
917 | { | 919 | { |
918 | catMenu->clear(); | 920 | catMenu->clear(); |
919 | 921 | ||
920 | int id, rememberId; | 922 | int id, rememberId; |
921 | id = 1; | 923 | id = 1; |
922 | rememberId = 0; | 924 | rememberId = 0; |
923 | 925 | ||
924 | catMenu->insertItem( Resource::loadPixmap( "datebook/weeklst" ), tr( "List" ), id++ ); | 926 | catMenu->insertItem( Resource::loadPixmap( "datebook/weeklst" ), tr( "List" ), id++ ); |
925 | catMenu->insertItem( Resource::loadPixmap( "day" ), tr( "Cards" ), id++ ); | 927 | catMenu->insertItem( Resource::loadPixmap( "day" ), tr( "Cards" ), id++ ); |
926 | // catMenu->insertItem( tr( "Personal" ), id++ ); | 928 | // catMenu->insertItem( tr( "Personal" ), id++ ); |
927 | catMenu->insertSeparator(); | 929 | catMenu->insertSeparator(); |
928 | 930 | ||
929 | catMenu->insertItem( tr( "All" ), id++ ); | 931 | catMenu->insertItem( tr( "All" ), id++ ); |
930 | QStringList categories = m_abView->categories(); | 932 | QStringList categories = m_abView->categories(); |
931 | categories.append( tr( "Unfiled" ) ); | 933 | categories.append( tr( "Unfiled" ) ); |
932 | for ( QStringList::Iterator it = categories.begin(); | 934 | for ( QStringList::Iterator it = categories.begin(); |
933 | it != categories.end(); ++it ) { | 935 | it != categories.end(); ++it ) { |
934 | catMenu->insertItem( *it, id ); | 936 | catMenu->insertItem( *it, id ); |
935 | if ( *it == m_abView -> showCategory() ) | 937 | if ( *it == m_abView -> showCategory() ) |
936 | rememberId = id; | 938 | rememberId = id; |
937 | ++id; | 939 | ++id; |
938 | } | 940 | } |
939 | 941 | ||
940 | // :SX | ||
941 | // if ( abList->showBook().isEmpty() ) { | ||
942 | // catMenu->setItemChecked( 1, true ); | ||
943 | // } else if ( abList->showBook() == "Phone" ) { | ||
944 | // catMenu->setItemChecked( 2, true ); | ||
945 | // } else if ( abList->showBook() == "Company" ) { | ||
946 | // catMenu->setItemChecked( 3, true ); | ||
947 | // } else if ( abList->showBook() == "Email" ) { | ||
948 | // catMenu->setItemChecked( 4, true ); | ||
949 | // } else if ( abList->showBook() == "Cards" ) { | ||
950 | // catMenu->setItemChecked( 5, true ); | ||
951 | // } | ||
952 | 942 | ||
953 | if ( m_abView -> showCategory().isEmpty() ) { | 943 | if ( m_abView -> showCategory().isEmpty() ) { |
954 | slotSetCategory( 3 ); | 944 | slotSetCategory( 3 ); |
955 | } | 945 | } |
956 | else { | 946 | else { |
957 | slotSetCategory( rememberId ); | 947 | slotSetCategory( rememberId ); |
958 | } | 948 | } |
959 | } | 949 | } |
960 | 950 | ||