author | eilers <eilers> | 2002-11-19 08:09:25 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-11-19 08:09:25 (UTC) |
commit | 30b3c39b9fc3d6e4da21c7f7406d66b7ebf02d1a (patch) (unidiff) | |
tree | d917a8d887b0a23605002692b958891cffa08c20 | |
parent | 8500e91c7d1faca6ad301244534b13885d5799a8 (diff) | |
download | opie-30b3c39b9fc3d6e4da21c7f7406d66b7ebf02d1a.zip opie-30b3c39b9fc3d6e4da21c7f7406d66b7ebf02d1a.tar.gz opie-30b3c39b9fc3d6e4da21c7f7406d66b7ebf02d1a.tar.bz2 |
Minor bugfix
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index b8127e9..e333b17 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -1,712 +1,714 @@ | |||
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 | { | 127 | { |
128 | qWarning("C'tor start"); | 128 | qWarning("C'tor start"); |
129 | 129 | ||
130 | setSelectionMode( NoSelection ); | 130 | setSelectionMode( NoSelection ); |
131 | init(); | 131 | init(); |
132 | setSorting( TRUE ); | 132 | setSorting( TRUE ); |
133 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 133 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
134 | this, SLOT(itemClicked(int,int)) ); | 134 | this, SLOT(itemClicked(int,int)) ); |
135 | 135 | ||
136 | contactList.clear(); | 136 | contactList.clear(); |
137 | qWarning("C'tor end"); | 137 | qWarning("C'tor end"); |
138 | } | 138 | } |
139 | 139 | ||
140 | AbTable::~AbTable() | 140 | AbTable::~AbTable() |
141 | { | 141 | { |
142 | } | 142 | } |
143 | 143 | ||
144 | void AbTable::init() | 144 | void AbTable::init() |
145 | { | 145 | { |
146 | // :SX showChar = '\0'; | 146 | // :SX showChar = '\0'; |
147 | setNumRows( 0 ); | 147 | setNumRows( 0 ); |
148 | setNumCols( 2 ); | 148 | setNumCols( 2 ); |
149 | 149 | ||
150 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); | 150 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); |
151 | horizontalHeader()->setLabel( 1, tr( "Contact" )); | 151 | horizontalHeader()->setLabel( 1, tr( "Contact" )); |
152 | setLeftMargin( 0 ); | 152 | setLeftMargin( 0 ); |
153 | verticalHeader()->hide(); | 153 | verticalHeader()->hide(); |
154 | columnVisible = true; | 154 | columnVisible = true; |
155 | } | 155 | } |
156 | 156 | ||
157 | void AbTable::setContacts( const OContactAccess::List& viewList ) | 157 | void AbTable::setContacts( const OContactAccess::List& viewList ) |
158 | { | 158 | { |
159 | qWarning("AbTable::setContacts()"); | 159 | qWarning("AbTable::setContacts()"); |
160 | 160 | ||
161 | clear(); | 161 | clear(); |
162 | m_viewList = viewList; | 162 | m_viewList = viewList; |
163 | 163 | ||
164 | setSorting( false ); | 164 | setSorting( false ); |
165 | setUpdatesEnabled( FALSE ); | 165 | setUpdatesEnabled( FALSE ); |
166 | 166 | ||
167 | OContactAccess::List::Iterator it; | 167 | OContactAccess::List::Iterator it; |
168 | setNumRows( m_viewList.count() ); | 168 | setNumRows( m_viewList.count() ); |
169 | int row = 0; | 169 | int row = 0; |
170 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) | 170 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) |
171 | insertIntoTable( *it, row++ ); | 171 | insertIntoTable( *it, row++ ); |
172 | 172 | ||
173 | setUpdatesEnabled( TRUE ); | 173 | setUpdatesEnabled( TRUE ); |
174 | 174 | ||
175 | setSorting( true ); | 175 | setSorting( true ); |
176 | 176 | ||
177 | resort(); | 177 | resort(); |
178 | 178 | ||
179 | updateVisible(); | 179 | updateVisible(); |
180 | 180 | ||
181 | } | 181 | } |
182 | 182 | ||
183 | bool AbTable::selectContact( int UID ) | 183 | bool AbTable::selectContact( int UID ) |
184 | { | 184 | { |
185 | qWarning( "AbTable::selectContact( %d )", UID ); | 185 | qWarning( "AbTable::selectContact( %d )", UID ); |
186 | int rows = numRows(); | 186 | int rows = numRows(); |
187 | AbTableItem *abi; | 187 | AbTableItem *abi; |
188 | OContact* foundContact = 0l; | 188 | OContact* foundContact = 0l; |
189 | bool found = false; | 189 | bool found = false; |
190 | 190 | ||
191 | for ( int r = 0; r < rows; ++r ) { | 191 | for ( int r = 0; r < rows; ++r ) { |
192 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 192 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
193 | foundContact = &contactList[abi]; | 193 | foundContact = &contactList[abi]; |
194 | if ( foundContact -> uid() == UID ){ | 194 | if ( foundContact -> uid() == UID ){ |
195 | ensureCellVisible( r, 0 ); | 195 | ensureCellVisible( r, 0 ); |
196 | setCurrentCell( r, 0 ); | 196 | setCurrentCell( r, 0 ); |
197 | found = true; | 197 | found = true; |
198 | break; | 198 | break; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | if ( !found ){ | 202 | if ( !found ){ |
203 | ensureCellVisible( 0,0 ); | 203 | ensureCellVisible( 0,0 ); |
204 | setCurrentCell( 0, 0 ); | 204 | setCurrentCell( 0, 0 ); |
205 | } | 205 | } |
206 | 206 | ||
207 | return true; | 207 | return true; |
208 | } | 208 | } |
209 | 209 | ||
210 | void AbTable::insertIntoTable( const OContact& cnt, int row ) | 210 | void AbTable::insertIntoTable( const OContact& cnt, int row ) |
211 | { | 211 | { |
212 | // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); | 212 | // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); |
213 | QString strName, | 213 | QString strName, |
214 | strContact; | 214 | strContact; |
215 | 215 | ||
216 | strName = findContactName( cnt ); | 216 | strName = findContactName( cnt ); |
217 | strContact = findContactContact( cnt, row ); | 217 | strContact = findContactContact( cnt, row ); |
218 | 218 | ||
219 | AbTableItem *ati; | 219 | AbTableItem *ati; |
220 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 220 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
221 | contactList.insert( ati, cnt ); | 221 | contactList.insert( ati, cnt ); |
222 | setItem( row, 0, ati ); | 222 | setItem( row, 0, ati ); |
223 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | 223 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); |
224 | setItem( row, 1, ati ); | 224 | setItem( row, 1, ati ); |
225 | 225 | ||
226 | //### cannot do this; table only has two columns at this point | 226 | //### cannot do this; table only has two columns at this point |
227 | // setItem( row, 2, new AbPickItem( this ) ); | 227 | // setItem( row, 2, new AbPickItem( this ) ); |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | 232 | ||
233 | void AbTable::columnClicked( int col ) | 233 | void AbTable::columnClicked( int col ) |
234 | { | 234 | { |
235 | if ( !sorting() ) | 235 | if ( !sorting() ) |
236 | return; | 236 | return; |
237 | 237 | ||
238 | if ( lastSortCol == -1 ) | 238 | if ( lastSortCol == -1 ) |
239 | lastSortCol = col; | 239 | lastSortCol = col; |
240 | 240 | ||
241 | if ( col == lastSortCol ) { | 241 | if ( col == lastSortCol ) { |
242 | asc = !asc; | 242 | asc = !asc; |
243 | } else { | 243 | } else { |
244 | lastSortCol = col; | 244 | lastSortCol = col; |
245 | asc = TRUE; | 245 | asc = TRUE; |
246 | } | 246 | } |
247 | //QMessageBox::information( this, "resort", "columnClicked" ); | 247 | //QMessageBox::information( this, "resort", "columnClicked" ); |
248 | resort(); | 248 | resort(); |
249 | } | 249 | } |
250 | 250 | ||
251 | void AbTable::resort() | 251 | void AbTable::resort() |
252 | { | 252 | { |
253 | qWarning( "void AbTable::resort()" ); | 253 | qWarning( "void AbTable::resort()" ); |
254 | if ( sorting() ) { | 254 | if ( sorting() ) { |
255 | if ( lastSortCol == -1 ) | 255 | if ( lastSortCol == -1 ) |
256 | lastSortCol = 0; | 256 | lastSortCol = 0; |
257 | sortColumn( lastSortCol, asc, TRUE ); | 257 | sortColumn( lastSortCol, asc, TRUE ); |
258 | //QMessageBox::information( this, "resort", "resort" ); | 258 | //QMessageBox::information( this, "resort", "resort" ); |
259 | updateVisible(); | 259 | updateVisible(); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | OContact AbTable::currentEntry() | 263 | OContact AbTable::currentEntry() |
264 | { | 264 | { |
265 | qWarning( "OContact AbTable::currentEntry()" ); | 265 | qWarning( "OContact AbTable::currentEntry()" ); |
266 | OContact cnt; | 266 | OContact cnt; |
267 | AbTableItem *abItem; | 267 | AbTableItem *abItem; |
268 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 268 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
269 | if ( abItem ) { | 269 | if ( abItem ) { |
270 | cnt = contactList[abItem]; | 270 | cnt = contactList[abItem]; |
271 | //cnt = contactList[currentRow()]; | 271 | //cnt = contactList[currentRow()]; |
272 | } | 272 | } |
273 | return cnt; | 273 | return cnt; |
274 | } | 274 | } |
275 | 275 | ||
276 | int AbTable::currentEntry_UID() | 276 | int AbTable::currentEntry_UID() |
277 | { | 277 | { |
278 | return ( currentEntry().uid() ); | 278 | return ( currentEntry().uid() ); |
279 | } | 279 | } |
280 | 280 | ||
281 | void AbTable::clear() | 281 | void AbTable::clear() |
282 | { | 282 | { |
283 | qWarning( "void AbTable::clear()" ); | 283 | qWarning( "void AbTable::clear()" ); |
284 | contactList.clear(); | 284 | contactList.clear(); |
285 | for ( int r = 0; r < numRows(); ++r ) { | 285 | for ( int r = 0; r < numRows(); ++r ) { |
286 | for ( int c = 0; c < numCols(); ++c ) { | 286 | for ( int c = 0; c < numCols(); ++c ) { |
287 | if ( cellWidget( r, c ) ) | 287 | if ( cellWidget( r, c ) ) |
288 | clearCellWidget( r, c ); | 288 | clearCellWidget( r, c ); |
289 | clearCell( r, c ); | 289 | clearCell( r, c ); |
290 | } | 290 | } |
291 | } | 291 | } |
292 | setNumRows( 0 ); | 292 | setNumRows( 0 ); |
293 | } | 293 | } |
294 | 294 | ||
295 | // Refresh updates column 2 if the contactsettings changed | 295 | // Refresh updates column 2 if the contactsettings changed |
296 | void AbTable::refresh() | 296 | void AbTable::refresh() |
297 | { | 297 | { |
298 | qWarning( "void AbTable::refresh()" ); | 298 | qWarning( "void AbTable::refresh()" ); |
299 | int rows = numRows(); | 299 | int rows = numRows(); |
300 | QString value; | 300 | QString value; |
301 | AbTableItem *abi; | 301 | AbTableItem *abi; |
302 | 302 | ||
303 | for ( int r = 0; r < rows; ++r ) { | 303 | for ( int r = 0; r < rows; ++r ) { |
304 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 304 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
305 | value = findContactContact( contactList[abi], r ); | 305 | value = findContactContact( contactList[abi], r ); |
306 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 306 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
307 | } | 307 | } |
308 | resort(); | 308 | resort(); |
309 | } | 309 | } |
310 | 310 | ||
311 | void AbTable::keyPressEvent( QKeyEvent *e ) | 311 | void AbTable::keyPressEvent( QKeyEvent *e ) |
312 | { | 312 | { |
313 | char key = toupper( e->ascii() ); | 313 | char key = toupper( e->ascii() ); |
314 | 314 | ||
315 | if ( key >= 'A' && key <= 'Z' ) | 315 | if ( key >= 'A' && key <= 'Z' ) |
316 | moveTo( key ); | 316 | moveTo( key ); |
317 | 317 | ||
318 | qWarning("Received key .."); | 318 | qWarning("Received key .."); |
319 | switch( e->key() ) { | 319 | switch( e->key() ) { |
320 | case Qt::Key_Space: | 320 | case Qt::Key_Space: |
321 | case Qt::Key_Return: | 321 | case Qt::Key_Return: |
322 | case Qt::Key_Enter: | 322 | case Qt::Key_Enter: |
323 | emit signalSwitch(); | 323 | emit signalSwitch(); |
324 | break; | 324 | break; |
325 | // case Qt::Key_Up: | 325 | // case Qt::Key_Up: |
326 | // qWarning("a"); | 326 | // qWarning("a"); |
327 | // emit signalKeyUp(); | 327 | // emit signalKeyUp(); |
328 | // break; | 328 | // break; |
329 | // case Qt::Key_Down: | 329 | // case Qt::Key_Down: |
330 | // qWarning("b"); | 330 | // qWarning("b"); |
331 | // emit signalKeyDown(); | 331 | // emit signalKeyDown(); |
332 | // break; | 332 | // break; |
333 | default: | 333 | default: |
334 | QTable::keyPressEvent( e ); | 334 | QTable::keyPressEvent( e ); |
335 | } | 335 | } |
336 | 336 | ||
337 | } | 337 | } |
338 | 338 | ||
339 | void AbTable::moveTo( char c ) | 339 | void AbTable::moveTo( char c ) |
340 | { | 340 | { |
341 | qWarning( "void AbTable::moveTo( char c )" ); | 341 | qWarning( "void AbTable::moveTo( char c )" ); |
342 | 342 | ||
343 | int rows = numRows(); | 343 | int rows = numRows(); |
344 | QString value; | 344 | QString value; |
345 | AbTableItem *abi; | 345 | AbTableItem *abi; |
346 | int r; | 346 | int r; |
347 | if ( asc ) { | 347 | if ( asc ) { |
348 | r = 0; | 348 | r = 0; |
349 | while ( r < rows-1) { | 349 | while ( r < rows-1) { |
350 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 350 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
351 | QChar first = abi->key()[0]; | 351 | QChar first = abi->key()[0]; |
352 | //### is there a bug in QChar to char comparison??? | 352 | //### is there a bug in QChar to char comparison??? |
353 | if ( first.row() || first.cell() >= c ) | 353 | if ( first.row() || first.cell() >= c ) |
354 | break; | 354 | break; |
355 | r++; | 355 | r++; |
356 | } | 356 | } |
357 | } else { | 357 | } else { |
358 | //### should probably disable reverse sorting instead | 358 | //### should probably disable reverse sorting instead |
359 | r = rows - 1; | 359 | r = rows - 1; |
360 | while ( r > 0 ) { | 360 | while ( r > 0 ) { |
361 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 361 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
362 | QChar first = abi->key()[0]; | 362 | QChar first = abi->key()[0]; |
363 | //### is there a bug in QChar to char comparison??? | 363 | //### is there a bug in QChar to char comparison??? |
364 | if ( first.row() || first.cell() >= c ) | 364 | if ( first.row() || first.cell() >= c ) |
365 | break; | 365 | break; |
366 | r--; | 366 | r--; |
367 | } | 367 | } |
368 | } | 368 | } |
369 | setCurrentCell( r, currentColumn() ); | 369 | setCurrentCell( r, currentColumn() ); |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | QString AbTable::findContactName( const OContact &entry ) | 373 | QString AbTable::findContactName( const OContact &entry ) |
374 | { | 374 | { |
375 | // We use the fileAs, then company, defaultEmail | 375 | // We use the fileAs, then company, defaultEmail |
376 | QString str; | 376 | QString str; |
377 | str = entry.fileAs(); | 377 | str = entry.fileAs(); |
378 | if ( str.isEmpty() ) { | 378 | if ( str.isEmpty() ) { |
379 | str = entry.company(); | 379 | str = entry.company(); |
380 | if ( str.isEmpty() ) { | 380 | if ( str.isEmpty() ) { |
381 | str = entry.defaultEmail(); | 381 | str = entry.defaultEmail(); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | return str; | 384 | return str; |
385 | } | 385 | } |
386 | 386 | ||
387 | 387 | ||
388 | 388 | ||
389 | void AbTable::resizeRows() { | 389 | void AbTable::resizeRows() { |
390 | /* | 390 | /* |
391 | if (numRows()) { | 391 | if (numRows()) { |
392 | for (int i = 0; i < numRows(); i++) { | 392 | for (int i = 0; i < numRows(); i++) { |
393 | setRowHeight( i, size ); | 393 | setRowHeight( i, size ); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | updateVisible(); | 396 | updateVisible(); |
397 | */ | 397 | */ |
398 | } | 398 | } |
399 | 399 | ||
400 | 400 | ||
401 | void AbTable::realignTable() | 401 | void AbTable::realignTable() |
402 | { | 402 | { |
403 | qWarning( "void AbTable::realignTable()" ); | 403 | qWarning( "void AbTable::realignTable()" ); |
404 | 404 | ||
405 | setPaintingEnabled( FALSE ); | 405 | setPaintingEnabled( FALSE ); |
406 | 406 | ||
407 | resizeRows(); | 407 | resizeRows(); |
408 | fitColumns(); | 408 | fitColumns(); |
409 | 409 | ||
410 | setPaintingEnabled( TRUE ); | 410 | setPaintingEnabled( TRUE ); |
411 | 411 | ||
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | #if QT_VERSION <= 230 | 417 | #if QT_VERSION <= 230 |
418 | #ifndef SINGLE_APP | 418 | #ifndef SINGLE_APP |
419 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | 419 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) |
420 | { | 420 | { |
421 | // Region of the rect we should draw | 421 | // Region of the rect we should draw |
422 | QRegion reg( QRect( cx, cy, cw, ch ) ); | 422 | QRegion reg( QRect( cx, cy, cw, ch ) ); |
423 | // Subtract the table from it | 423 | // Subtract the table from it |
424 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); | 424 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); |
425 | // And draw the rectangles (transformed as needed) | 425 | // And draw the rectangles (transformed as needed) |
426 | QArray<QRect> r = reg.rects(); | 426 | QArray<QRect> r = reg.rects(); |
427 | for (unsigned int i=0; i<r.count(); i++) | 427 | for (unsigned int i=0; i<r.count(); i++) |
428 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); | 428 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); |
429 | } | 429 | } |
430 | #endif | 430 | #endif |
431 | #endif | 431 | #endif |
432 | 432 | ||
433 | 433 | ||
434 | // int AbTable::rowHeight( int ) const | 434 | // int AbTable::rowHeight( int ) const |
435 | // { | 435 | // { |
436 | // return 18; | 436 | // return 18; |
437 | // } | 437 | // } |
438 | 438 | ||
439 | // int AbTable::rowPos( int row ) const | 439 | // int AbTable::rowPos( int row ) const |
440 | // { | 440 | // { |
441 | // return 18*row; | 441 | // return 18*row; |
442 | // } | 442 | // } |
443 | 443 | ||
444 | // int AbTable::rowAt( int pos ) const | 444 | // int AbTable::rowAt( int pos ) const |
445 | // { | 445 | // { |
446 | // return QMIN( pos/18, numRows()-1 ); | 446 | // return QMIN( pos/18, numRows()-1 ); |
447 | // } | 447 | // } |
448 | 448 | ||
449 | 449 | ||
450 | 450 | ||
451 | void AbTable::fitColumns() | 451 | void AbTable::fitColumns() |
452 | { | 452 | { |
453 | qWarning( "void AbTable::fitColumns()" ); | 453 | qWarning( "void AbTable::fitColumns()" ); |
454 | int contentsWidth = visibleWidth() / 2; // :SX Why too low | 454 | int contentsWidth = visibleWidth() / 2; // :SX Why too low |
455 | // Fix to better value | 455 | // Fix to better value |
456 | // contentsWidth = 130; | 456 | // contentsWidth = 130; |
457 | 457 | ||
458 | if ( columnVisible == false ){ | 458 | if ( columnVisible == false ){ |
459 | showColumn(0); | 459 | showColumn(0); |
460 | columnVisible = true; | 460 | columnVisible = true; |
461 | } | 461 | } |
462 | 462 | ||
463 | qWarning("Width: %d", contentsWidth); | 463 | qWarning("Width: %d", contentsWidth); |
464 | 464 | ||
465 | setColumnWidth( 0, contentsWidth ); | 465 | setColumnWidth( 0, contentsWidth ); |
466 | adjustColumn(1); | 466 | adjustColumn(1); |
467 | if ( columnWidth(1) < contentsWidth ) | 467 | if ( columnWidth(1) < contentsWidth ) |
468 | setColumnWidth( 1, contentsWidth ); | 468 | setColumnWidth( 1, contentsWidth ); |
469 | } | 469 | } |
470 | 470 | ||
471 | void AbTable::show() | 471 | void AbTable::show() |
472 | { | 472 | { |
473 | qWarning( "void AbTable::show()" ); | 473 | qWarning( "void AbTable::show()" ); |
474 | realignTable(); | 474 | realignTable(); |
475 | QTable::show(); | 475 | QTable::show(); |
476 | } | 476 | } |
477 | 477 | ||
478 | void AbTable::setChoiceNames( const QStringList& list) | 478 | void AbTable::setChoiceNames( const QStringList& list) |
479 | { | 479 | { |
480 | choicenames = list; | 480 | choicenames = list; |
481 | if ( choicenames.isEmpty() ) { | 481 | if ( choicenames.isEmpty() ) { |
482 | // hide pick column | 482 | // hide pick column |
483 | setNumCols( 2 ); | 483 | setNumCols( 2 ); |
484 | } else { | 484 | } else { |
485 | // show pick column | 485 | // show pick column |
486 | setNumCols( 3 ); | 486 | setNumCols( 3 ); |
487 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); | 487 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); |
488 | horizontalHeader()->setLabel( 2, tr( "Pick" )); | 488 | horizontalHeader()->setLabel( 2, tr( "Pick" )); |
489 | } | 489 | } |
490 | fitColumns(); | 490 | fitColumns(); |
491 | } | 491 | } |
492 | 492 | ||
493 | void AbTable::itemClicked(int,int col) | 493 | void AbTable::itemClicked(int,int col) |
494 | { | 494 | { |
495 | qWarning( "AbTable::itemClicked(int, col:%d)", col); | 495 | qWarning( "AbTable::itemClicked(int, col:%d)", col); |
496 | if ( col == 2 ) { | 496 | if ( col == 2 ) { |
497 | return; | 497 | return; |
498 | } else { | 498 | } else { |
499 | qWarning ("Emitting signalSwitch()"); | 499 | qWarning ("Emitting signalSwitch()"); |
500 | emit signalSwitch(); | 500 | emit signalSwitch(); |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | QStringList AbTable::choiceNames() const | 504 | QStringList AbTable::choiceNames() const |
505 | { | 505 | { |
506 | return choicenames; | 506 | return choicenames; |
507 | } | 507 | } |
508 | 508 | ||
509 | void AbTable::setChoiceSelection( const QValueList<int>& list ) | 509 | void AbTable::setChoiceSelection( const QValueList<int>& list ) |
510 | { | 510 | { |
511 | intFields = list; | 511 | intFields = list; |
512 | } | 512 | } |
513 | 513 | ||
514 | QStringList AbTable::choiceSelection(int /*index*/) const | 514 | QStringList AbTable::choiceSelection(int /*index*/) const |
515 | { | 515 | { |
516 | QStringList r; | 516 | QStringList r; |
517 | /* ###### | 517 | /* ###### |
518 | 518 | ||
519 | QString selname = choicenames.at(index); | 519 | QString selname = choicenames.at(index); |
520 | for (each row) { | 520 | for (each row) { |
521 | OContact *c = contactForRow(row); | 521 | OContact *c = contactForRow(row); |
522 | if ( text(row,2) == selname ) { | 522 | if ( text(row,2) == selname ) { |
523 | r.append(c->email); | 523 | r.append(c->email); |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | */ | 527 | */ |
528 | return r; | 528 | return r; |
529 | } | 529 | } |
530 | 530 | ||
531 | 531 | ||
532 | 532 | ||
533 | 533 | ||
534 | void AbTable::updateVisible() | 534 | void AbTable::updateVisible() |
535 | { | 535 | { |
536 | int visible, | 536 | int visible, |
537 | totalRows, | 537 | totalRows, |
538 | row, | 538 | row, |
539 | selectedRow = 0; | 539 | selectedRow = 0; |
540 | 540 | ||
541 | visible = 0; | 541 | visible = 0; |
542 | 542 | ||
543 | realignTable(); | 543 | realignTable(); |
544 | 544 | ||
545 | setPaintingEnabled( FALSE ); | 545 | setPaintingEnabled( FALSE ); |
546 | 546 | ||
547 | totalRows = numRows(); | 547 | totalRows = numRows(); |
548 | for ( row = 0; row < totalRows; row++ ) { | 548 | for ( row = 0; row < totalRows; row++ ) { |
549 | if ( rowHeight(row) == 0 ) { | 549 | if ( rowHeight(row) == 0 ) { |
550 | showRow( row ); | 550 | showRow( row ); |
551 | adjustRow( row ); | 551 | adjustRow( row ); |
552 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) | 552 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) |
553 | selectedRow = row; | 553 | selectedRow = row; |
554 | } | 554 | } |
555 | visible++; | 555 | visible++; |
556 | } | 556 | } |
557 | 557 | ||
558 | if ( selectedRow ) | 558 | if ( selectedRow ) |
559 | setCurrentCell( selectedRow, 0 ); | 559 | setCurrentCell( selectedRow, 0 ); |
560 | 560 | ||
561 | if ( !visible ) | 561 | if ( !visible ) |
562 | setCurrentCell( -1, 0 ); | 562 | setCurrentCell( -1, 0 ); |
563 | 563 | ||
564 | setPaintingEnabled( TRUE ); | 564 | setPaintingEnabled( TRUE ); |
565 | 565 | ||
566 | 566 | ||
567 | } | 567 | } |
568 | 568 | ||
569 | 569 | ||
570 | void AbTable::setPaintingEnabled( bool e ) | 570 | void AbTable::setPaintingEnabled( bool e ) |
571 | { | 571 | { |
572 | if ( e != enablePainting ) { | 572 | if ( e != enablePainting ) { |
573 | if ( !enablePainting ) { | 573 | if ( !enablePainting ) { |
574 | enablePainting = true; | 574 | enablePainting = true; |
575 | rowHeightChanged( 0 ); | 575 | rowHeightChanged( 0 ); |
576 | viewport()->update(); | 576 | viewport()->update(); |
577 | } else { | 577 | } else { |
578 | enablePainting = false; | 578 | enablePainting = false; |
579 | } | 579 | } |
580 | } | 580 | } |
581 | } | 581 | } |
582 | 582 | ||
583 | void AbTable::rowHeightChanged( int row ) | 583 | void AbTable::rowHeightChanged( int row ) |
584 | { | 584 | { |
585 | if ( enablePainting ) | 585 | if ( enablePainting ) |
586 | QTable::rowHeightChanged( row ); | 586 | QTable::rowHeightChanged( row ); |
587 | } | 587 | } |
588 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) | 588 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) |
589 | { | 589 | { |
590 | QString value; | 590 | QString value; |
591 | value = ""; | 591 | value = ""; |
592 | for ( QValueList<int>::ConstIterator it = intFields.begin(); | 592 | for ( QValueList<int>::ConstIterator it = intFields.begin(); |
593 | it != intFields.end(); ++it ) { | 593 | it != intFields.end(); ++it ) { |
594 | switch ( *it ) { | 594 | switch ( *it ) { |
595 | default: | 595 | default: |
596 | break; | 596 | break; |
597 | case Qtopia::Title: | 597 | case Qtopia::Title: |
598 | value = entry.title(); | 598 | value = entry.title(); |
599 | break; | 599 | break; |
600 | case Qtopia::Suffix: | 600 | case Qtopia::Suffix: |
601 | value = entry.suffix(); | 601 | value = entry.suffix(); |
602 | break; | 602 | break; |
603 | case Qtopia::FileAs: | 603 | case Qtopia::FileAs: |
604 | value = entry.fileAs(); | 604 | value = entry.fileAs(); |
605 | break; | 605 | break; |
606 | case Qtopia::DefaultEmail: | 606 | case Qtopia::DefaultEmail: |
607 | value = entry.defaultEmail(); | 607 | value = entry.defaultEmail(); |
608 | case Qtopia::Emails: | 608 | case Qtopia::Emails: |
609 | value = entry.emails(); | 609 | value = entry.emails(); |
610 | break; | 610 | break; |
611 | case Qtopia::HomeStreet: | 611 | case Qtopia::HomeStreet: |
612 | value = entry.homeStreet(); | 612 | value = entry.homeStreet(); |
613 | break; | 613 | break; |
614 | case Qtopia::HomeCity: | 614 | case Qtopia::HomeCity: |
615 | value = entry.homeCity(); | 615 | value = entry.homeCity(); |
616 | break; | 616 | break; |
617 | case Qtopia::HomeState: | 617 | case Qtopia::HomeState: |
618 | value = entry.homeState(); | 618 | value = entry.homeState(); |
619 | break; | 619 | break; |
620 | case Qtopia::HomeZip: | 620 | case Qtopia::HomeZip: |
621 | value = entry.homeZip(); | 621 | value = entry.homeZip(); |
622 | break; | 622 | break; |
623 | case Qtopia::HomeCountry: | 623 | case Qtopia::HomeCountry: |
624 | value = entry.homeCountry(); | 624 | value = entry.homeCountry(); |
625 | break; | 625 | break; |
626 | case Qtopia::HomePhone: | 626 | case Qtopia::HomePhone: |
627 | value = entry.homePhone(); | 627 | value = entry.homePhone(); |
628 | break; | 628 | break; |
629 | case Qtopia::HomeFax: | 629 | case Qtopia::HomeFax: |
630 | value = entry.homeFax(); | 630 | value = entry.homeFax(); |
631 | break; | 631 | break; |
632 | case Qtopia::HomeMobile: | 632 | case Qtopia::HomeMobile: |
633 | value = entry.homeMobile(); | 633 | value = entry.homeMobile(); |
634 | break; | 634 | break; |
635 | case Qtopia::HomeWebPage: | 635 | case Qtopia::HomeWebPage: |
636 | value = entry.homeWebpage(); | 636 | value = entry.homeWebpage(); |
637 | break; | 637 | break; |
638 | case Qtopia::Company: | 638 | case Qtopia::Company: |
639 | value = entry.company(); | 639 | value = entry.company(); |
640 | break; | 640 | break; |
641 | case Qtopia::BusinessCity: | 641 | case Qtopia::BusinessCity: |
642 | value = entry.businessCity(); | 642 | value = entry.businessCity(); |
643 | break; | 643 | break; |
644 | case Qtopia::BusinessStreet: | 644 | case Qtopia::BusinessStreet: |
645 | value = entry.businessStreet(); | 645 | value = entry.businessStreet(); |
646 | break; | 646 | break; |
647 | case Qtopia::BusinessZip: | 647 | case Qtopia::BusinessZip: |
648 | value = entry.businessZip(); | 648 | value = entry.businessZip(); |
649 | break; | 649 | break; |
650 | case Qtopia::BusinessCountry: | 650 | case Qtopia::BusinessCountry: |
651 | value = entry.businessCountry(); | 651 | value = entry.businessCountry(); |
652 | break; | 652 | break; |
653 | case Qtopia::BusinessWebPage: | 653 | case Qtopia::BusinessWebPage: |
654 | value = entry.businessWebpage(); | 654 | value = entry.businessWebpage(); |
655 | break; | 655 | break; |
656 | case Qtopia::JobTitle: | 656 | case Qtopia::JobTitle: |
657 | value = entry.jobTitle(); | 657 | value = entry.jobTitle(); |
658 | break; | 658 | break; |
659 | case Qtopia::Department: | 659 | case Qtopia::Department: |
660 | value = entry.department(); | 660 | value = entry.department(); |
661 | break; | 661 | break; |
662 | case Qtopia::Office: | 662 | case Qtopia::Office: |
663 | value = entry.office(); | 663 | value = entry.office(); |
664 | break; | 664 | break; |
665 | case Qtopia::BusinessPhone: | 665 | case Qtopia::BusinessPhone: |
666 | value = entry.businessPhone(); | 666 | value = entry.businessPhone(); |
667 | break; | 667 | break; |
668 | case Qtopia::BusinessFax: | 668 | case Qtopia::BusinessFax: |
669 | value = entry.businessFax(); | 669 | value = entry.businessFax(); |
670 | break; | 670 | break; |
671 | case Qtopia::BusinessMobile: | 671 | case Qtopia::BusinessMobile: |
672 | value = entry.businessMobile(); | 672 | value = entry.businessMobile(); |
673 | break; | 673 | break; |
674 | case Qtopia::BusinessPager: | 674 | case Qtopia::BusinessPager: |
675 | value = entry.businessPager(); | 675 | value = entry.businessPager(); |
676 | break; | 676 | break; |
677 | case Qtopia::Profession: | 677 | case Qtopia::Profession: |
678 | value = entry.profession(); | 678 | value = entry.profession(); |
679 | break; | 679 | break; |
680 | case Qtopia::Assistant: | 680 | case Qtopia::Assistant: |
681 | value = entry.assistant(); | 681 | value = entry.assistant(); |
682 | break; | 682 | break; |
683 | case Qtopia::Manager: | 683 | case Qtopia::Manager: |
684 | value = entry.manager(); | 684 | value = entry.manager(); |
685 | break; | 685 | break; |
686 | case Qtopia::Spouse: | 686 | case Qtopia::Spouse: |
687 | value = entry.spouse(); | 687 | value = entry.spouse(); |
688 | break; | 688 | break; |
689 | case Qtopia::Gender: | 689 | case Qtopia::Gender: |
690 | value = entry.gender(); | 690 | value = entry.gender(); |
691 | break; | 691 | break; |
692 | case Qtopia::Birthday: | 692 | case Qtopia::Birthday: |
693 | value = TimeString::numberDateString( entry.birthday() ); | 693 | if ( ! entry.birthday().isNull() ) |
694 | value = TimeString::numberDateString( entry.birthday() ); | ||
694 | break; | 695 | break; |
695 | case Qtopia::Anniversary: | 696 | case Qtopia::Anniversary: |
696 | value = TimeString::numberDateString( entry.anniversary() ); | 697 | if ( ! entry.anniversary().isNull() ) |
698 | value = TimeString::numberDateString( entry.anniversary() ); | ||
697 | break; | 699 | break; |
698 | case Qtopia::Nickname: | 700 | case Qtopia::Nickname: |
699 | value = entry.nickname(); | 701 | value = entry.nickname(); |
700 | break; | 702 | break; |
701 | case Qtopia::Children: | 703 | case Qtopia::Children: |
702 | value = entry.children(); | 704 | value = entry.children(); |
703 | break; | 705 | break; |
704 | case Qtopia::Notes: | 706 | case Qtopia::Notes: |
705 | value = entry.notes(); | 707 | value = entry.notes(); |
706 | break; | 708 | break; |
707 | } | 709 | } |
708 | if ( !value.isEmpty() ) | 710 | if ( !value.isEmpty() ) |
709 | break; | 711 | break; |
710 | } | 712 | } |
711 | return value; | 713 | return value; |
712 | } | 714 | } |