summaryrefslogtreecommitdiff
path: root/core
Unidiff
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/contacteditor.cpp1397
-rw-r--r--core/pim/addressbook/contacteditor.h158
2 files changed, 1555 insertions, 0 deletions
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp
new file mode 100644
index 0000000..0c90510
--- a/dev/null
+++ b/core/pim/addressbook/contacteditor.cpp
@@ -0,0 +1,1397 @@
1
2#include "contacteditor.h"
3#include "addresspicker.h"
4
5#include <qpe/categoryselect.h>
6#include <qpe/qpeapplication.h>
7#include <qpe/qpedialog.h>
8
9#include <qcombobox.h>
10#include <qlabel.h>
11#include <qtabwidget.h>
12#include <qlayout.h>
13#include <qlineedit.h>
14#include <qmultilineedit.h>
15#include <qscrollview.h>
16#include <qtoolbutton.h>
17#include <qpushbutton.h>
18#include <qmainwindow.h>
19#include <qvaluelist.h>
20
21static inline bool containsAlphaNum( const QString &str );
22static inline bool constainsWhiteSpace( const QString &str );
23
24// helper functions, convert our comma delimited list to proper
25// file format...
26void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
27 QString &strAll );
28
29// helper convert from file format to comma delimited...
30void parseEmailTo( const QString &strDefaultEmail,
31 const QString &strOtherEmail, QString &strBack );
32
33 ContactEditor::ContactEditor(const Contact &entry,
34 const QValueList<int> *newOrderedValues,
35 QStringList *slNewOrdered,
36 QWidget *parent = 0,
37 const char *name = 0,
38 WFlags fl = 0 )
39 : QDialog( parent, name, TRUE, fl ),
40 orderedValues( newOrderedValues ),
41 slOrdered( slNewOrdered )
42{
43
44 init();
45 initMap();
46 setEntry( entry );
47 qDebug("finish");
48}
49
50ContactEditor::~ContactEditor() {
51}
52
53void ContactEditor::init() {
54
55 useFullName = TRUE;
56
57 int i = 0;
58
59 slHomeAddress = new QStringList;
60 slBusinessAddress = new QStringList;
61 slChooserNames = new QStringList;
62 slChooserValues = new QStringList;
63
64 slDynamicEntries = new QStringList;
65
66 //*slDynamicEntries = *slOrdered;
67
68 for (i = 0; i <= 6; i++) {
69 slHomeAddress->append( "" );
70 slBusinessAddress->append( "" );
71 }
72
73 {
74 hasGender = FALSE;
75 hasTitle = FALSE;
76 hasCompany = FALSE;
77 hasNotes = FALSE;
78 hasStreet = FALSE;
79 hasStreet2 = FALSE;
80 hasPOBox = FALSE;
81 hasCity = FALSE;
82 hasState = FALSE;
83 hasZip = FALSE;
84 hasCountry = FALSE;
85
86 QStringList::ConstIterator it = slOrdered->begin();
87 for ( i = 0; it != slOrdered->end(); i++, ++it ) {
88
89 if ( (*it).right( 3 ) == tr( "Fax" ) ) {
90 slChooserNames->append( *it );
91 slChooserValues->append( tr( "" ) );
92 //slDynamicEntries->remove( it );
93 continue;
94 }
95
96 if ( (*it).right( 5 ) == tr( "Phone" ) ) {
97 slChooserNames->append( *it );
98 slChooserValues->append( "" );
99 //slDynamicEntries->remove( it );
100 continue;
101 }
102
103 if ( (*it).right( 2 ) == tr( "IM" ) ) {
104 slChooserNames->append( *it );
105 slChooserValues->append( "" );
106 //slDynamicEntries->remove( it );
107 continue;
108 }
109
110 if ( (*it).right( 6 ) == tr( "Mobile" ) ) {
111 slChooserNames->append( *it );
112 slChooserValues->append( "" );
113 //slDynamicEntries->remove( it );
114 continue;
115 }
116
117 if ( (*it).right( 4 ) == tr( "Page" ) ) {
118 slChooserNames->append( *it );
119 slChooserValues->append( "" );
120 //slDynamicEntries->remove( it );
121 continue;
122 }
123
124 if ( (*it).right( 5 ) == tr( "Pager" ) ) {
125 slChooserNames->append( *it );
126 slChooserValues->append( "" );
127 //slDynamicEntries->remove( it );
128 continue;
129 }
130
131 if ( *it == tr( "Default Email" ) ) {
132 slChooserNames->append( *it );
133 slChooserValues->append( "" );
134 //slDynamicEntries->remove( it );
135 continue;
136 }
137
138 if ( *it == tr( "Emails" ) ) {
139 slChooserNames->append( *it );
140 slChooserValues->append( "" );
141 //slDynamicEntries->remove( it );
142 continue;
143 }
144
145 if ( *it == tr( "Name Title" ) ) {
146 //slDynamicEntries->remove( it );
147 continue;
148 }
149
150 if ( *it == tr( "First Name" ) ) {
151 //slDynamicEntries->remove( it );
152 continue;
153 }
154
155 if ( *it == tr( "Middle Name" ) ) {
156 //slDynamicEntries->remove( it );
157 continue;
158 }
159
160 if ( *it == tr( "Last Name" ) ) {
161 //slDynamicEntries->remove( it );
162 continue;
163 }
164
165 if ( *it == tr( "Suffix" ) ) {
166 //slDynamicEntries->remove( it );
167 continue;
168 }
169
170 if ( *it == tr( "File As" ) ) {
171 //slDynamicEntries->remove( it );
172 continue;
173 }
174
175 if ( *it == tr( "Gender" ) ) {
176 hasGender = TRUE;
177 //slDynamicEntries->remove( it );
178 continue;
179 }
180
181 if ( *it == tr( "Job Title" ) ) {
182 hasTitle = TRUE;
183 //slDynamicEntries->remove( it );
184 continue;
185 }
186
187 if ( *it == tr( "Company" ) ) {
188 hasCompany = TRUE;
189 //slDynamicEntries->remove( it );
190 continue;
191 }
192
193 if ( *it == tr( "Notes" ) ) {
194 hasNotes = TRUE;
195 //slDynamicEntries->remove( it );
196 continue;
197 }
198
199 if ( *it == tr( "Groups" ) ) {
200 //slDynamicEntries->remove( it );
201 continue;
202 }
203
204 if ( (*it).right( 6 ) == tr( "Street" ) ) {
205 hasStreet = TRUE;
206 //slDynamicEntries->remove( it );
207 continue;
208 }
209
210 if ( (*it).right( 8 ) == tr( "Street 2" ) ) {
211 hasStreet2 = TRUE;
212 //slDynamicEntries->remove( it );
213 continue;
214 }
215
216 if ( (*it).right( 8 ) == tr( "P.O. Box" ) ) {
217 hasPOBox = TRUE;
218 //slDynamicEntries->remove( it );
219 continue;
220 }
221
222 if ( (*it).right( 4 ) == tr( "City" ) ) {
223 hasCity = TRUE;
224 //slDynamicEntries->remove( it );
225 continue;
226 }
227
228 if ( (*it).right( 5 ) == tr( "State" ) ) {
229 hasState = TRUE;
230 //slDynamicEntries->remove( it );
231 continue;
232 }
233
234 if ( (*it).right( 3 ) == tr( "Zip" ) ) {
235 hasZip = TRUE;
236 //slDynamicEntries->remove( it );
237 continue;
238 }
239
240 if ( (*it).right( 7 ) == tr( "Country" ) ) {
241 hasCountry = TRUE;
242 //slDynamicEntries->remove( it );
243 continue;
244 }
245
246 slDynamicEntries->append( *it );
247 }
248 }
249
250 QVBoxLayout *vb = new QVBoxLayout( this );
251
252 tabMain = new QTabWidget( this );
253 vb->addWidget( tabMain );
254
255 QWidget *tabViewport = new QWidget ( tabMain );
256
257 vb = new QVBoxLayout( tabViewport );
258
259 svGeneral = new QScrollView( tabViewport );
260 vb->addWidget( svGeneral, 0, 0 );
261 svGeneral->setResizePolicy( QScrollView::AutoOneFit );
262 svGeneral->setFrameStyle( QFrame::NoFrame );
263
264 QWidget *container = new QWidget( svGeneral->viewport() );
265 svGeneral->addChild( container );
266
267 QGridLayout *gl = new QGridLayout( container );
268 gl->setResizeMode( QLayout::FreeResize );
269
270 btnFullName = new QPushButton( tr( "Full Name..." ), container );
271 gl->addWidget( btnFullName, 0, 0 );
272 txtFullName = new QLineEdit( container );
273 gl->addWidget( txtFullName, 0, 1 );
274
275 QLabel *l = new QLabel( tr( "Job Title" ), container );
276 gl->addWidget( l, 1, 0 );
277 txtJobTitle = new QLineEdit( container );
278 gl->addWidget( txtJobTitle, 1, 1 );
279
280 l = new QLabel( tr( "Organization" ), container );
281 gl->addWidget( l, 2, 0 );
282 txtOrganization = new QLineEdit( container );
283 gl->addWidget( txtOrganization, 2, 1 );
284
285 cmbChooserField1 = new QComboBox( FALSE, container );
286 cmbChooserField1->setMaximumWidth( 100 );
287 gl->addWidget( cmbChooserField1, 3, 0 );
288 txtChooserField1 = new QLineEdit( container );
289 gl->addWidget( txtChooserField1, 3, 1 );
290
291 cmbChooserField2 = new QComboBox( FALSE, container );
292 cmbChooserField2->setMaximumWidth( 100 );
293 gl->addWidget( cmbChooserField2, 4, 0 );
294 txtChooserField2 = new QLineEdit( container );
295 gl->addWidget( txtChooserField2, 4, 1 );
296
297 cmbChooserField3 = new QComboBox( FALSE, container );
298 cmbChooserField3->setMaximumWidth( 100 );
299 gl->addWidget( cmbChooserField3, 5, 0 );
300 txtChooserField3 = new QLineEdit( container );
301 gl->addWidget( txtChooserField3, 5, 1 );
302
303 l = new QLabel( tr( "File As" ), container );
304 gl->addWidget( l, 6, 0 );
305 cmbFileAs = new QComboBox( TRUE, container );
306 gl->addWidget( cmbFileAs, 6, 1 );
307
308 l = new QLabel( tr( "Category" ), container );
309 gl->addWidget( l, 7, 0 );
310 cmbCat = new CategorySelect( container );
311 gl->addWidget( cmbCat, 7, 1 );
312
313 btnNote = new QPushButton( tr( "Notes..." ), container );
314 gl->addWidget( btnNote, 8, 1 );
315
316 tabMain->insertTab( tabViewport, tr( "General" ) );
317
318 tabViewport = new QWidget ( tabMain );
319
320 vb = new QVBoxLayout( tabViewport );
321
322 svAddress = new QScrollView( tabViewport );
323 vb->addWidget( svAddress, 0, 0 );
324 svAddress->setResizePolicy( QScrollView::AutoOneFit );
325 svAddress->setFrameStyle( QFrame::NoFrame );
326
327 container = new QWidget( svAddress->viewport() );
328 svAddress->addChild( container );
329
330 gl = new QGridLayout( container, 5, 3, 0, 1 );
331
332 cmbAddress = new QComboBox( FALSE, container );
333 cmbAddress->insertItem( tr( "Business" ) );
334 cmbAddress->insertItem( tr( "Home" ) );
335 gl->addMultiCellWidget( cmbAddress, 0, 0, 0, 1 );
336
337 l = new QLabel( tr( "Address" ), container );
338 gl->addWidget( l, 1, 0 );
339 txtAddress = new QLineEdit( container );
340 gl->addMultiCellWidget( txtAddress, 1, 1, 1, 2 );
341/*
342 l = new QLabel( tr( "Address 2" ), container );
343 gl->addWidget( l, 2, 0 );
344 txtAddress2 = new QLineEdit( container );
345 gl->addMultiCellWidget( txtAddress2, 2, 2, 1, 2 );
346
347 l = new QLabel( tr( "P.O. Box" ), container );
348 gl->addWidget( l, 3, 0 );
349 txtPOBox = new QLineEdit( container );
350 gl->addMultiCellWidget( txtPOBox, 3, 3, 1, 2 );
351*/
352 l = new QLabel( tr( "City" ), container );
353 gl->addWidget( l, 2, 0 );
354 txtCity = new QLineEdit( container );
355 gl->addMultiCellWidget( txtCity, 2, 2, 1, 2 );
356
357 l = new QLabel( tr( "State" ), container );
358 gl->addWidget( l, 3, 0 );
359 txtState = new QLineEdit( container );
360 gl->addMultiCellWidget( txtState, 3, 3, 1, 2 );
361
362 l = new QLabel( tr( "Zip Code" ), container );
363 gl->addWidget( l, 4, 0 );
364 txtZip = new QLineEdit( container );
365 gl->addMultiCellWidget( txtZip, 4, 4, 1, 2 );
366
367 l = new QLabel( tr( "Country" ), container );
368 gl->addWidget( l, 5, 0 );
369 cmbCountry = new QComboBox( TRUE, container );
370 cmbCountry->insertItem( tr( "" ) );
371 cmbCountry->insertItem( tr( "United States" ) );
372 cmbCountry->insertItem( tr( "United Kingdom" ) );
373 cmbCountry->insertItem( tr( "Japan" ) );
374 cmbCountry->insertItem( tr( "France" ) );
375 cmbCountry->insertItem( tr( "Germany" ) );
376 cmbCountry->insertItem( tr( "Norway" ) );
377 cmbCountry->insertItem( tr( "Canada" ) );
378
379 gl->addMultiCellWidget( cmbCountry, 5, 5, 1, 2 );
380
381 tabMain->insertTab( tabViewport, tr( "Address" ) );
382
383 tabViewport = new QWidget ( tabMain );
384
385 vb = new QVBoxLayout( tabViewport );
386
387 svDetails = new QScrollView( tabViewport );
388 vb->addWidget( svDetails, 0, 0 );
389 svDetails->setResizePolicy( QScrollView::AutoOneFit );
390 svDetails->setFrameStyle( QFrame::NoFrame );
391
392 container = new QWidget( svDetails->viewport() );
393 svDetails->addChild( container );
394
395 gl = new QGridLayout( container, 1, 2, 0, 1 );
396
397 QStringList::ConstIterator it = slDynamicEntries->begin();
398 for (i = 0; it != slDynamicEntries->end(); i++, ++it) {
399 l = new QLabel( *it, container );
400 listName.append( l );
401 gl->addWidget( l, i, 0 );
402 QLineEdit *e = new QLineEdit( container );
403 listValue.append( e );
404 gl->addWidget( e, i, 1);
405 }
406
407 l = new QLabel( tr("Gender"), container );
408 gl->addWidget( l, slDynamicEntries->count(), 0 );
409 cmbGender = new QComboBox( container );
410 cmbGender->insertItem( "", 0 );
411 cmbGender->insertItem( tr("Male"), 1);
412 cmbGender->insertItem( tr("Female"), 2);
413 gl->addWidget( cmbGender, slDynamicEntries->count(), 1 );
414
415 tabMain->insertTab( tabViewport, tr( "Details" ) );
416
417 dlgNote = new QDialog( this, "Note Dialog", TRUE );
418 dlgNote->setCaption( tr("Enter Note") );
419 QVBoxLayout *vbNote = new QVBoxLayout( dlgNote );
420 txtNote = new QMultiLineEdit( dlgNote );
421 vbNote->addWidget( txtNote );
422 connect( btnNote, SIGNAL(clicked()), this, SLOT(slotNote()) );
423
424 dlgName = new QDialog( this, "Name Dialog", TRUE );
425 dlgName->setCaption( tr("Edit Name") );
426 gl = new QGridLayout( dlgName, 4, 2, 0, 1 );
427
428 l = new QLabel( tr("First Name"), dlgName );
429 gl->addWidget( l, 0, 0 );
430 txtFirstName = new QLineEdit( dlgName );
431 gl->addWidget( txtFirstName, 0, 1 );
432
433 l = new QLabel( tr("Middle Name"), dlgName );
434 gl->addWidget( l, 1, 0 );
435 txtMiddleName = new QLineEdit( dlgName );
436 gl->addWidget( txtMiddleName, 1, 1 );
437
438 l = new QLabel( tr("Last Name"), dlgName );
439 gl->addWidget( l, 2, 0 );
440 txtLastName = new QLineEdit( dlgName );
441 gl->addWidget( txtLastName, 2, 1 );
442
443 l = new QLabel( tr("Suffix"), dlgName );
444 gl->addWidget( l, 3, 0 );
445 txtSuffix = new QLineEdit( dlgName );
446 gl->addWidget( txtSuffix, 3, 1 );
447
448 cmbChooserField1->insertStringList( *slChooserNames );
449 cmbChooserField2->insertStringList( *slChooserNames );
450 cmbChooserField3->insertStringList( *slChooserNames );
451
452 cmbChooserField1->setCurrentItem( 1 );
453 cmbChooserField2->setCurrentItem( 2 );
454 cmbChooserField3->setCurrentItem( 3 );
455
456 connect( btnFullName, SIGNAL(clicked()), this, SLOT(slotName()) );
457
458 connect( txtFullName, SIGNAL(textChanged(const QString &)), this, SLOT(slotFullNameChange(const QString &)) );
459
460 connect( txtChooserField1, SIGNAL(textChanged(const QString &)), this, SLOT(slotChooser1Change(const QString &)) );
461 connect( txtChooserField2, SIGNAL(textChanged(const QString &)), this, SLOT(slotChooser2Change(const QString &)) );
462 connect( txtChooserField3, SIGNAL(textChanged(const QString &)), this, SLOT(slotChooser3Change(const QString &)) );
463 connect( txtAddress, SIGNAL(textChanged(const QString &)), this, SLOT(slotAddressChange(const QString &)) );
464 //connect( txtAddress2, SIGNAL(textChanged(const QString &)), this, SLOT(slotAddress2Change(const QString &)) );
465 //connect( txtPOBox, SIGNAL(textChanged(const QString &)), this, SLOT(slotPOBoxChange(const QString &)) );
466 connect( txtCity, SIGNAL(textChanged(const QString &)), this, SLOT(slotCityChange(const QString &)) );
467 connect( txtState, SIGNAL(textChanged(const QString &)), this, SLOT(slotStateChange(const QString &)) );
468 connect( txtZip, SIGNAL(textChanged(const QString &)), this, SLOT(slotZipChange(const QString &)) );
469 connect( cmbCountry, SIGNAL(textChanged(const QString &)), this, SLOT(slotCountryChange(const QString &)) );
470 connect( cmbCountry, SIGNAL(activated(const QString &)), this, SLOT(slotCountryChange(const QString &)) );
471 connect( cmbChooserField1, SIGNAL(activated(int)), this, SLOT(slotCmbChooser1Change(int)) );
472 connect( cmbChooserField2, SIGNAL(activated(int)), this, SLOT(slotCmbChooser2Change(int)) );
473 connect( cmbChooserField3, SIGNAL(activated(int)), this, SLOT(slotCmbChooser3Change(int)) );
474 connect( cmbAddress, SIGNAL(activated(int)), this, SLOT(slotAddressTypeChange(int)) );
475 new QPEDialogListener(this);
476}
477
478void ContactEditor::initMap()
479{
480 /*
481 // since the fields and the XML fields exist, create a map
482 // between them...
483 Config cfg1( "AddressBook" );
484 Config cfg2( "AddressBook" );
485 QString strCfg1,
486 strCfg2;
487 int i;
488
489 // This stuff better exist...
490 cfg1.setGroup( "AddressFields" );
491o cfg2.setGroup( "XMLFields" );
492 i = 0;
493 strCfg1 = cfg1.readEntry( "Field" + QString::number(i), QString::null );
494 strCfg2 = cfg2.readEntry( "XMLField" + QString::number(i++),
495 QString::null );
496 while ( !strCfg1.isNull() && !strCfg2.isNull() ) {
497 mapField.insert( strCfg1, strCfg2 );
498 strCfg1 = cfg1.readEntry( "Field" + QString::number(i),
499 QString::null );
500 strCfg2 = cfg2.readEntry( "XMLField" + QString::number(i++),
501 QString::null );
502 }
503 */
504}
505
506void ContactEditor::slotChooser1Change( const QString &textChanged ) {
507
508 int index = cmbChooserField1->currentItem();
509
510 (*slChooserValues)[index] = textChanged;
511
512}
513
514void ContactEditor::slotChooser2Change( const QString &textChanged ) {
515
516 int index = cmbChooserField2->currentItem();
517
518 (*slChooserValues)[index] = textChanged;
519
520}
521
522void ContactEditor::slotChooser3Change( const QString &textChanged ) {
523
524 int index = cmbChooserField3->currentItem();
525
526 (*slChooserValues)[index] = textChanged;
527
528}
529
530void ContactEditor::slotAddressChange( const QString &textChanged ) {
531
532 qDebug((*slBusinessAddress)[0]);
533 qDebug((*slHomeAddress)[0]);
534 qDebug(textChanged);
535 if ( cmbAddress->currentItem() == 0 ) {
536 (*slBusinessAddress)[0] = textChanged;
537 } else {
538 (*slHomeAddress)[0] = textChanged;
539 }
540}
541
542void ContactEditor::slotAddress2Change( const QString &textChanged ) {
543
544 qDebug((*slBusinessAddress)[1]);
545 qDebug((*slHomeAddress)[1]);
546 qDebug(textChanged);
547
548 if ( cmbAddress->currentItem() == 0 ) {
549 (*slBusinessAddress)[1] = textChanged;
550 } else {
551 (*slHomeAddress)[1] = textChanged;
552 }
553}
554
555void ContactEditor::slotPOBoxChange( const QString &textChanged ) {
556
557 qDebug((*slBusinessAddress)[2]);
558 qDebug((*slHomeAddress)[2]);
559 qDebug(textChanged);
560 if ( cmbAddress->currentItem() == 0 ) {
561 (*slBusinessAddress)[2] = textChanged;
562 } else {
563 (*slHomeAddress)[2] = textChanged;
564 }
565}
566
567void ContactEditor::slotCityChange( const QString &textChanged ) {
568
569 qDebug((*slBusinessAddress)[3]);
570 qDebug((*slHomeAddress)[3]);
571 qDebug(textChanged);
572 if ( cmbAddress->currentItem() == 0 ) {
573 (*slBusinessAddress)[3] = textChanged;
574 } else {
575 (*slHomeAddress)[3] = textChanged;
576 }
577}
578
579void ContactEditor::slotStateChange( const QString &textChanged ) {
580
581
582 qDebug((*slBusinessAddress)[4]);
583 qDebug((*slHomeAddress)[4]);
584 qDebug(textChanged);
585 if ( cmbAddress->currentItem() == 0 ) {
586 (*slBusinessAddress)[4] = textChanged;
587 } else {
588 (*slHomeAddress)[4] = textChanged;
589 }
590}
591
592void ContactEditor::slotZipChange( const QString &textChanged ) {
593
594 qDebug((*slBusinessAddress)[5]);
595 qDebug((*slHomeAddress)[5]);
596 qDebug(textChanged);
597 if ( cmbAddress->currentItem() == 0 ) {
598 (*slBusinessAddress)[5] = textChanged;
599 } else {
600 (*slHomeAddress)[5] = textChanged;
601 }
602}
603
604void ContactEditor::slotCountryChange( const QString &textChanged ) {
605
606 qDebug((*slBusinessAddress)[6]);
607 qDebug((*slHomeAddress)[6]);
608 qDebug(textChanged);
609 if ( cmbAddress->currentItem() == 0 ) {
610 (*slBusinessAddress)[6] = textChanged;
611 } else {
612 (*slHomeAddress)[6] = textChanged;
613 }
614}
615
616void ContactEditor::slotCmbChooser1Change( int index ) {
617
618 txtChooserField1->setText( (*slChooserValues)[index] );
619
620}
621
622void ContactEditor::slotCmbChooser2Change( int index ) {
623
624 txtChooserField2->setText( (*slChooserValues)[index] );
625
626}
627
628void ContactEditor::slotCmbChooser3Change( int index ) {
629
630 txtChooserField3->setText( (*slChooserValues)[index] );
631
632}
633
634void ContactEditor::slotAddressTypeChange( int index ) {
635
636 qDebug((*slBusinessAddress)[0]);
637 qDebug((*slBusinessAddress)[1]);
638 qDebug((*slBusinessAddress)[2]);
639qDebug((*slBusinessAddress)[3]);
640qDebug((*slBusinessAddress)[4]);
641qDebug((*slBusinessAddress)[5]);
642qDebug((*slBusinessAddress)[6]);
643
644
645
646 if ( index == 0 ) {
647
648 txtAddress->setText( (*slBusinessAddress)[0] );
649 //txtAddress2->setText( (*slBusinessAddress)[1] );
650 //txtPOBox->setText( (*slBusinessAddress)[2] );
651 txtCity->setText( (*slBusinessAddress)[3] );
652 txtState->setText( (*slBusinessAddress)[4] );
653 txtZip->setText( (*slBusinessAddress)[5] );
654 QLineEdit *txtTmp = cmbCountry->lineEdit();
655 txtTmp->setText( (*slBusinessAddress)[6] );
656
657 } else {
658
659 txtAddress->setText( (*slHomeAddress)[0] );
660 //txtAddress2->setText( (*slHomeAddress)[1] );
661 //txtPOBox->setText( (*slHomeAddress)[2] );
662 txtCity->setText( (*slHomeAddress)[3] );
663 txtState->setText( (*slHomeAddress)[4] );
664 txtZip->setText( (*slHomeAddress)[5] );
665 QLineEdit *txtTmp = cmbCountry->lineEdit();
666 txtTmp->setText( (*slHomeAddress)[6] );
667
668 }
669
670}
671
672void ContactEditor::slotFullNameChange( const QString &textChanged ) {
673
674 int index = cmbFileAs->currentItem();
675
676 cmbFileAs->clear();
677
678 cmbFileAs->insertItem( parseName( textChanged, 0 ) );
679 cmbFileAs->insertItem( parseName( textChanged, 1 ) );
680 cmbFileAs->insertItem( parseName( textChanged, 2 ) );
681 cmbFileAs->insertItem( parseName( textChanged, 3 ) );
682
683 cmbFileAs->setCurrentItem( index );
684
685 useFullName = TRUE;
686
687 }
688
689void ContactEditor::loadFields() {
690
691 QStringList::ConstIterator it;
692 QListIterator<QLabel> lit( listName );
693 for ( it = slDynamicEntries->begin(); *lit; ++lit, ++it) {
694 (*lit)->setText( *it );
695 }
696}
697
698void ContactEditor::accept() {
699
700 if ( isEmpty() ) {
701 cleanupFields();
702 reject();
703 } else {
704 saveEntry();
705 cleanupFields();
706 QDialog::accept();
707 }
708
709}
710
711void ContactEditor::slotNote() {
712
713 dlgNote->showMaximized();
714 if ( !dlgNote->exec() ) {
715 txtNote->setText( ent.notes() );
716 }
717}
718
719void ContactEditor::slotName() {
720
721 if (useFullName = TRUE) {
722 txtFirstName->setText( parseName(txtFullName->text(), NAME_F) );
723 txtMiddleName->setText( parseName(txtFullName->text(), NAME_M) );
724 txtLastName->setText( parseName(txtFullName->text(), NAME_L) );
725 txtSuffix->setText( parseName(txtFullName->text(), NAME_S) );
726 }
727
728 dlgName->showMaximized();
729 if ( dlgName->exec() ) {
730 txtFullName->setText( txtFirstName->text() + " " + txtMiddleName->text() + " " + txtLastName->text() + " " + txtSuffix->text() );
731 slotFullNameChange( txtFullName->text() );
732 useFullName = FALSE;
733 }
734
735}
736
737void ContactEditor::setNameFocus() {
738
739 txtFullName->setFocus();
740
741}
742
743bool ContactEditor::isEmpty() {
744 // Test and see if the record should be saved.
745 // More strict than the original qtopia, needs name or fileas to save
746
747 QString t = txtFullName->text();
748 if ( !t.isEmpty() && containsAlphaNum( t ) )
749 return false;
750
751 t = cmbFileAs->currentText();
752 if ( !t.isEmpty() && containsAlphaNum( t ) )
753 return false;
754
755 return true;
756
757}
758
759QString ContactEditor::parseName( const QString fullName, int type ) {
760
761 QString simplifiedName( fullName.simplifyWhiteSpace() );
762 QString strFirstName;
763 QString strMiddleName;
764 QString strLastName;
765 QString strSuffix;
766 QString strTitle;
767 int commapos;
768 int spCount;
769 int spPos;
770 int spPos2;
771
772
773 commapos = simplifiedName.find( ',', 0, TRUE);
774 spCount = simplifiedName.contains( ' ', TRUE );
775
776 if ( commapos == -1 ) {
777
778 switch (spCount) {
779 case 0:
780 return simplifiedName;
781
782 case 1:
783 spPos = simplifiedName.find( ' ', 0, TRUE );
784 strFirstName = simplifiedName.left( spPos );
785 strLastName = simplifiedName.mid( spPos + 1 );
786 break;
787
788 case 2:
789 spPos = simplifiedName.find( ' ', 0, TRUE );
790 strFirstName = simplifiedName.left( spPos );
791 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
792 strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
793 strLastName = simplifiedName.mid( spPos2 + 1 );
794 break;
795
796 case 3:
797 spPos = simplifiedName.find( ' ', 0, TRUE );
798 strFirstName = simplifiedName.left( spPos );
799 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
800 strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
801 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
802 strLastName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
803 strSuffix = simplifiedName.mid( spPos + 1 );
804 break;
805
806 case 4:
807 spPos = simplifiedName.find( ' ', 0, TRUE );
808 strTitle = simplifiedName.left( spPos );
809 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
810 strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
811 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
812 strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
813 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
814 strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
815 strSuffix = simplifiedName.mid( spPos2 + 1 );
816 break;
817
818 default:
819 spPos = simplifiedName.find( ' ', 0, TRUE );
820 strTitle = simplifiedName.left( spPos );
821 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
822 strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
823 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
824 strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
825 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
826 strLastName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
827 strSuffix = simplifiedName.mid( spPos2 + 1 );
828 break;
829 }
830 } else {
831 simplifiedName.replace( commapos, 1, " " );
832 simplifiedName = simplifiedName.simplifyWhiteSpace();
833
834 switch (spCount) {
835 case 0:
836 return simplifiedName;
837
838 case 1:
839 spPos = simplifiedName.find( ' ', 0, TRUE );
840 strLastName = simplifiedName.left( spPos );
841 strFirstName = simplifiedName.mid( spPos + 1 );
842 break;
843
844 case 2:
845 spPos = simplifiedName.find( ' ', 0, TRUE );
846 strLastName = simplifiedName.left( spPos );
847 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
848 strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
849 strMiddleName = simplifiedName.mid( spPos2 + 1 );
850 break;
851
852 case 3:
853 spPos = simplifiedName.find( ' ', 0, TRUE );
854 strLastName = simplifiedName.left( spPos );
855 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
856 strFirstName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
857 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
858 strMiddleName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
859 strSuffix = simplifiedName.mid( spPos + 1 );
860 break;
861
862 case 4:
863 spPos = simplifiedName.find( ' ', 0, TRUE );
864 strLastName = simplifiedName.left( spPos );
865 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
866 strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
867 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
868 strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
869 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
870 strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
871 strSuffix = simplifiedName.mid( spPos2 + 1 );
872 break;
873
874 default:
875 spPos = simplifiedName.find( ' ', 0, TRUE );
876 strLastName = simplifiedName.left( spPos );
877 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
878 strTitle = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
879 spPos = simplifiedName.find( ' ', spPos2 + 1, TRUE );
880 strFirstName = simplifiedName.mid( spPos2 + 1, (spPos - 1) - spPos );
881 spPos2 = simplifiedName.find( ' ', spPos + 1, TRUE );
882 strMiddleName = simplifiedName.mid( spPos + 1, (spPos2 - 1) - spPos );
883 strSuffix = simplifiedName.mid( spPos2 + 1 );
884 break;
885 }
886 }
887
888 switch (type) {
889 case NAME_FL:
890 return strFirstName + " " + strLastName;
891
892 case NAME_LF:
893 return strLastName + ", " + strFirstName;
894
895 case NAME_LFM:
896 return strLastName + ", " + strFirstName + " " + strMiddleName;
897
898 case NAME_FMLS:
899 return strFirstName + " " + strMiddleName + " " + strLastName + " " + strSuffix;
900
901 case NAME_F:
902 return strFirstName;
903
904 case NAME_M:
905 return strMiddleName;
906
907 case NAME_L:
908 return strLastName;
909
910 case NAME_S:
911 return strSuffix;
912
913 }
914}
915
916void ContactEditor::cleanupFields() {
917
918 QStringList::Iterator it = slChooserValues->begin();
919 for ( int i = 0; it != slChooserValues->end(); i++, ++it ) {
920 (*it) = "";
921 }
922
923 for ( int i = 0; i < 7; i++ ) {
924 (*slHomeAddress)[i] = "";
925 (*slBusinessAddress)[i] = "";
926 }
927
928 QStringList::ConstIterator cit;
929 QListIterator<QLineEdit> itLE( listValue );
930 for ( cit = slDynamicEntries->begin(); cit != slDynamicEntries->end(); ++cit, ++itLE) {
931 (*itLE)->setText( "" );
932 }
933
934 txtFirstName->setText("");
935 txtMiddleName->setText("");
936 txtLastName->setText("");
937 txtSuffix->setText("");
938 txtNote->setText("");
939 txtFullName->setText("");
940 txtJobTitle->setText("");
941 txtOrganization->setText("");
942 txtChooserField1->setText("");
943 txtChooserField2->setText("");
944 txtChooserField3->setText("");
945 txtAddress->setText("");
946 //txtAddress2->setText("");
947 txtCity->setText("");
948 //txtPOBox->setText("");
949 txtState->setText("");
950 txtZip->setText("");
951 QLineEdit *txtTmp = cmbCountry->lineEdit();
952 txtTmp->setText("");
953 txtTmp = cmbFileAs->lineEdit();
954 txtTmp->setText("");
955
956}
957
958void ContactEditor::setEntry( const Contact &entry ) {
959
960 cleanupFields();
961
962 ent = entry;
963
964 useFullName = FALSE;
965 txtFirstName->setText( ent.firstName() );
966 txtMiddleName->setText( ent.middleName() );
967 txtLastName->setText( ent.lastName() );
968 txtSuffix->setText( ent.suffix() );
969
970 QString *tmpString = new QString;
971 *tmpString = ent.firstName() + " " + ent.middleName() +
972 + " " + ent.lastName() + " " + ent.suffix();
973
974 txtFullName->setText( tmpString->simplifyWhiteSpace() );
975
976 cmbFileAs->setEditText( ent.fileAs() );
977
978 if (hasTitle)
979 txtJobTitle->setText( ent.jobTitle() );
980
981 if (hasCompany)
982 txtOrganization->setText( ent.company() );
983
984 if (hasNotes)
985 txtNote->setText( ent.notes() );
986
987 if (hasStreet) {
988 (*slHomeAddress)[0] = ent.homeStreet();
989 (*slBusinessAddress)[0] = ent.businessStreet();
990 }
991/*
992 if (hasStreet2) {
993 (*slHomeAddress)[1] = ent.homeStreet2();
994 (*slBusinessAddress)[1] = ent.businessStreet2();
995 }
996
997 if (hasPOBox) {
998 (*slHomeAddress)[2] = ent.homePOBox();
999 (*slBusinessAddress)[2] = ent.businessPOBox();
1000 }
1001*/
1002 if (hasCity) {
1003 (*slHomeAddress)[3] = ent.homeCity();
1004 (*slBusinessAddress)[3] = ent.homeCity();
1005 }
1006
1007 if (hasState) {
1008 (*slHomeAddress)[4] = ent.homeState();
1009 (*slBusinessAddress)[4] = ent.businessState();
1010 }
1011
1012 if (hasZip) {
1013 (*slHomeAddress)[5] = ent.homeZip();
1014 (*slBusinessAddress)[5] = ent.businessZip();
1015 }
1016
1017 QStringList::ConstIterator it;
1018 QListIterator<QLineEdit> itLE( listValue );
1019 for ( it = slDynamicEntries->begin(); it != slDynamicEntries->end(); ++it, ++itLE) {
1020 if ( *it == "Department" )
1021 (*itLE)->setText( ent.department() );
1022
1023 if ( *it == "Company" )
1024 (*itLE)->setText( ent.company() );
1025
1026 if ( *it == "Office" )
1027 (*itLE)->setText( ent.office() );
1028
1029 if ( *it == "Profession" )
1030 (*itLE)->setText( ent.profession() );
1031
1032 if ( *it == "Assistant" )
1033 (*itLE)->setText( ent.assistant() );
1034
1035 if ( *it == "Manager" )
1036 (*itLE)->setText( ent.manager() );
1037
1038 if ( *it == "Spouse" )
1039 (*itLE)->setText( ent.spouse() );
1040
1041 if ( *it == "Birthday" )
1042 (*itLE)->setText( ent.birthday() );
1043
1044 if ( *it == "Anniversary" )
1045 (*itLE)->setText( ent.anniversary() );
1046
1047 if ( *it == "Nickname" )
1048 (*itLE)->setText( ent.nickname() );
1049
1050 if ( *it == "Children" )
1051 (*itLE)->setText( ent.children() );
1052
1053 }
1054
1055 QStringList::Iterator itV;
1056 for ( it = slChooserNames->begin(), itV = slChooserValues->begin(); it != slChooserNames->end(); ++it, ++itV ) {
1057
1058 if ( *it == "Business Phone" )
1059 *itV = ent.businessPhone();
1060/*
1061 if ( *it == "Business 2 Phone" )
1062 *itV = ent.business2Phone();
1063*/
1064 if ( *it == "Business Fax" )
1065 *itV = ent.businessFax();
1066
1067 if ( *it == "Business Mobile" )
1068 *itV = ent.businessMobile();
1069/*
1070 if ( *it == "Company Phone" )
1071 *itV = ent.companyPhone();
1072*/
1073 if ( *it == "Default Email" )
1074 *itV = ent.defaultEmail();
1075
1076 if ( *it == "Emails" )
1077 *itV = ent.emails();
1078
1079 if ( *it == "Home Phone" )
1080 *itV = ent.homePhone();
1081/*
1082 if ( *it == "Home 2 Phone" )
1083 *itV = ent.home2Phone();
1084*/
1085 if ( *it == "Home Fax" )
1086 *itV = ent.homeFax();
1087
1088 if ( *it == "Home Mobile" )
1089 *itV = ent.homeMobile();
1090/*
1091 if ( *it == "Car Phone" )
1092 *itV = ent.carPhone();
1093
1094 if ( *it == "ISDN Phone" )
1095 *itV = ent.ISDNPhone();
1096
1097 if ( *it == "Other Phone" )
1098 *itV = ent.otherPhone();
1099*/
1100 if ( *it == "Business Pager" )
1101 *itV = ent.businessPager();
1102/*
1103 if ( *it == "Home Pager")
1104 *itV = ent.homePager();
1105
1106 if ( *it == "AIM IM" )
1107 *itV = ent.AIMIM();
1108
1109 if ( *it == "ICQ IM" )
1110 *itV = ent.ICQIM();
1111
1112 if ( *it == "Jabber IM" )
1113 *itV = ent.jabberIM();
1114
1115 if ( *it == "MSN IM" )
1116 *itV = ent.MSNIM();
1117
1118 if ( *it == "Yahoo IM" )
1119 *itV = ent.yahooIM();
1120*/
1121 if ( *it == "Home Web Page" )
1122 *itV = ent.homeWebpage();
1123 if ( *it == "Business Web Page" )
1124 *itV = ent.businessWebpage();
1125
1126
1127 }
1128
1129 cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") );
1130
1131 QString gender = ent.gender();
1132 cmbGender->setCurrentItem( gender.toInt() );
1133
1134 txtNote->setText( ent.notes() );
1135
1136}
1137
1138void ContactEditor::saveEntry() {
1139
1140 if ( useFullName == TRUE ) {
1141 txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) );
1142 txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) );
1143 txtLastName->setText( parseName( txtFullName->text(), NAME_L ) );
1144 txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) );
1145
1146 useFullName = FALSE;
1147 }
1148
1149 /*if ( ent.firstName() != txtFirstName->text() ||
1150 ent.lastName != txtLastName->text() ||
1151 ent.middleName != txtMiddleName->text() ) {
1152 */
1153 ent.setFirstName( txtFirstName->text() );
1154 ent.setLastName( txtLastName->text() );
1155 ent.setMiddleName( txtMiddleName->text() );
1156
1157 //}
1158
1159 ent.setFileAs( cmbFileAs->currentText() );
1160
1161 ent.setCategories( cmbCat->currentCategories() );
1162
1163 if (hasTitle)
1164 ent.setJobTitle( txtJobTitle->text() );
1165
1166 if (hasCompany)
1167 ent.setCompany( txtOrganization->text() );
1168
1169 if (hasNotes)
1170 ent.setNotes( txtNote->text() );
1171
1172 if (hasStreet) {
1173 ent.setHomeStreet( (*slHomeAddress)[0] );
1174 ent.setBusinessStreet( (*slBusinessAddress)[0] );
1175 }
1176/*
1177 if (hasStreet2) {
1178 ent.setHomeStreet2( (*slHomeAddress)[1] );
1179 ent.setBusinessStreet2( (*slBusinessAddress)[1] );
1180 }
1181
1182 if (hasPOBox) {
1183 ent.setHomePOBox( (*slHomeAddress)[2] );
1184 ent.setBusinessPOBox( (*slBusinessAddress)[2] );
1185 }
1186*/
1187 if (hasCity) {
1188 ent.setHomeCity( (*slHomeAddress)[3] );
1189 ent.setBusinessCity( (*slBusinessAddress)[3] );
1190 }
1191
1192 if (hasState) {
1193 ent.setHomeState( (*slHomeAddress)[4] );
1194 ent.setBusinessState( (*slBusinessAddress)[4] );
1195 }
1196
1197 if (hasZip) {
1198 ent.setHomeZip( (*slHomeAddress)[5] );
1199 ent.setBusinessZip( (*slBusinessAddress)[5] );
1200 }
1201
1202 QStringList::ConstIterator it;
1203 QListIterator<QLineEdit> itLE( listValue );
1204 for ( it = slDynamicEntries->begin(); it != slDynamicEntries->end(); ++it, ++itLE) {
1205 if ( *it == "Department" )
1206 ent.setDepartment( (*itLE)->text() );
1207
1208 if ( *it == "Company" )
1209 ent.setCompany( (*itLE)->text() );
1210
1211 if ( *it == "Office" )
1212 ent.setOffice( (*itLE)->text() );
1213
1214 if ( *it == "Profession" )
1215 ent.setProfession( (*itLE)->text() );
1216
1217 if ( *it == "Assistant" )
1218 ent.setAssistant( (*itLE)->text() );
1219
1220 if ( *it == "Manager" )
1221 ent.setManager( (*itLE)->text() );
1222
1223 if ( *it == "Spouse" )
1224 ent.setSpouse( (*itLE)->text() );
1225
1226 if ( *it == "Birthday" )
1227 ent.setBirthday( (*itLE)->text() );
1228
1229 if ( *it == "Anniversary" )
1230 ent.setAnniversary( (*itLE)->text() );
1231
1232 if ( *it == "Nickname" )
1233 ent.setNickname( (*itLE)->text() );
1234
1235 if ( *it == "Children" )
1236 ent.setChildren( (*itLE)->text() );
1237
1238 }
1239
1240 QStringList::ConstIterator itV;
1241 for ( it = slChooserNames->begin(), itV = slChooserValues->begin(); it != slChooserNames->end(); ++it, ++itV ) {
1242
1243 if ( *it == "Business Phone" )
1244 ent.setBusinessPhone( *itV );
1245/*
1246 if ( *it == "Business 2 Phone" )
1247 ent.setBusiness2Phone( *itV );
1248*/
1249 if ( *it == "Business Fax" )
1250 ent.setBusinessFax( *itV );
1251
1252 if ( *it == "Business Mobile" )
1253 ent.setBusinessMobile( *itV );
1254/*
1255 if ( *it == "Company Phone" )
1256 ent.setCompanyPhone( *itV );
1257*/
1258 if ( *it == "Default Email" )
1259 ent.setDefaultEmail( *itV );
1260
1261 if ( *it == "Emails" )
1262 ent.setEmails( *itV );
1263
1264 if ( *it == "Home Phone" )
1265 ent.setHomePhone( *itV );
1266/*
1267 if ( *it == "Home 2 Phone" )
1268 ent.setHome2Phone( *itV );
1269*/
1270 if ( *it == "Home Fax" )
1271 ent.setHomeFax( *itV );
1272
1273 if ( *it == "Home Mobile" )
1274 ent.setHomeMobile( *itV );
1275/*
1276 if ( *it == "Car Phone" )
1277 ent.setCarPhone( *itV );
1278
1279 if ( *it == "ISDN Phone" )
1280 ent.setISDNPhone( *itV );
1281
1282 if ( *it == "Other Phone" )
1283 ent.setOtherPhone( *itV );
1284*/
1285 if ( *it == "Business Pager" )
1286 ent.setBusinessPager( *itV );
1287/*
1288 if ( *it == "Home Pager" )
1289 ent.setHomePager( *itV );
1290
1291 if ( *it == "AIM IM" )
1292 ent.setAIMIM( *itV );
1293
1294 if ( *it == "ICQ IM" )
1295 ent.setICQIM( *itV );
1296
1297 if ( *it == "Jabber IM" )
1298 ent.setJabberIM( *itV );
1299
1300 if ( *it == "MSN IM" )
1301 ent.setMSNIM( *itV );
1302
1303 if ( *it == "Yahoo IM" )
1304 ent.setYahooIM( *itV );
1305*/
1306 if ( *it == "Home Web Page" )
1307 ent.setHomeWebpage( *itV );
1308 if ( *it == "Business Web Page" )
1309 ent.setBusinessWebpage( *itV );
1310
1311
1312 }
1313
1314 int gender = cmbGender->currentItem();
1315 ent.setGender( QString::number( gender ) );
1316
1317 QString str = txtNote->text();
1318 if ( !str.isNull() )
1319 ent.setNotes( str );
1320
1321}
1322
1323void parseEmailFrom( const QString &txt, QString &strDefaultEmail,
1324 QString &strAll )
1325{
1326 int where,
1327 start;
1328 if ( txt.isEmpty() )
1329 return;
1330 // find the first
1331 where = txt.find( ',' );
1332 if ( where < 0 ) {
1333 strDefaultEmail = txt;
1334 strAll = txt;
1335 } else {
1336 strDefaultEmail = txt.left( where ).stripWhiteSpace();
1337 strAll = strDefaultEmail;
1338 while ( where > -1 ) {
1339 strAll.append(" ");
1340 start = where;
1341 where = txt.find( ',', where + 1 );
1342 if ( where > - 1 )
1343 strAll.append( txt.mid(start + 1, where - start - 1).stripWhiteSpace() );
1344 else // grab until the end...
1345 strAll.append( txt.right(txt.length() - start - 1).stripWhiteSpace() );
1346 }
1347 }
1348}
1349
1350void parseEmailTo( const QString &strDefaultEmail,
1351 const QString &strOtherEmail, QString &strBack )
1352{
1353 // create a comma dilimeted set of emails...
1354 // use the power of short circuiting...
1355 bool foundDefault = false;
1356 QString strTmp;
1357 int start = 0;
1358 int where;
1359 // start at the beginng.
1360 strBack = strDefaultEmail;
1361 where = 0;
1362 while ( where > -1 ) {
1363 start = where;
1364 where = strOtherEmail.find( ' ', where + 1 );
1365 if ( where > 0 ) {
1366 strTmp = strOtherEmail.mid( start, where - start ).stripWhiteSpace();
1367 } else
1368 strTmp = strOtherEmail.right( strOtherEmail.length() - start ).stripWhiteSpace();
1369 if ( foundDefault || strTmp != strDefaultEmail ) {
1370 strBack.append( ", " );
1371 strBack.append( strTmp );
1372 } else
1373 foundDefault = true;
1374 }
1375}
1376
1377
1378static inline bool containsAlphaNum( const QString &str )
1379{
1380 int i,
1381 count = str.length();
1382 for ( i = 0; i < count; i++ )
1383 if ( !str[i].isSpace() )
1384 return TRUE;
1385 return FALSE;
1386}
1387
1388static inline bool constainsWhiteSpace( const QString &str )
1389{
1390 int i,
1391 count = str.length();
1392 for (i = 0; i < count; i++ )
1393 if ( str[i].isSpace() )
1394 return TRUE;
1395 return FALSE;
1396}
1397
diff --git a/core/pim/addressbook/contacteditor.h b/core/pim/addressbook/contacteditor.h
new file mode 100644
index 0000000..a799672
--- a/dev/null
+++ b/core/pim/addressbook/contacteditor.h
@@ -0,0 +1,158 @@
1/*
2 * Copyright (c) 2002 Michael R. Crawford <mike@tuxnami.org>
3 *
4 * This file is an add-on for the OPIE 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 pacakaging
9 * 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 * This is a rewrite of the abeditor.h file, modified to provide a more
16 * intuitive interface to TrollTech's original Address Book editor. This
17 * is made to operate exactly in interface with the exception of name.
18 *
19 */
20
21#ifndef CONTACTEDITOR_H
22#define CONTACTEDITOR_H
23
24#include <qpe/contact.h>
25
26#include <qdialog.h>
27#include <qlist.h>
28#include <qmap.h>
29#include <qstringlist.h>
30
31const int NAME_LF = 0;
32const int NAME_LFM = 1;
33const int NAME_FL = 2;
34const int NAME_FMLS = 3;
35
36const int NAME_F = 4;
37const int NAME_M = 5;
38const int NAME_L = 6;
39const int NAME_S = 7;
40
41
42class QScrollView;
43class QTabWidget;
44class QMultiLineEdit;
45class QLineEdit;
46class QComboBox;
47class QPushButton;
48class CategorySelect;
49class QLabel;
50
51class ContactEditor : public QDialog {
52 Q_OBJECT
53
54 public:
55 ContactEditor(const Contact &entry,
56 const QValueList<int> *newOrderedValues,
57 QStringList *slNewOrdered,
58 QWidget *parent = 0,
59 const char *name = 0,
60 WFlags fl = 0 );
61 ~ContactEditor();
62 void loadFields();
63 void setNameFocus();
64 Contact entry() const { return ent; }
65
66 public slots:
67 void slotNote();
68 void slotName();
69 void setEntry(const Contact &entry);
70
71 protected slots:
72 void accept();
73
74 private:
75 void init();
76 void initMap();
77 void saveEntry();
78 bool isEmpty();
79 void cleanupFields();
80 QString parseName( QString fullName, int type );
81
82 private slots:
83 void slotChooser1Change( const QString &textChanged );
84 void slotChooser2Change( const QString &textChanged );
85 void slotChooser3Change( const QString &textChanged );
86 void slotCmbChooser1Change( int index );
87 void slotCmbChooser2Change( int index );
88 void slotCmbChooser3Change( int index );
89 void slotAddressTypeChange( int index );
90 void slotAddressChange( const QString &textChanged );
91 void slotAddress2Change( const QString &textChanged );
92 void slotPOBoxChange( const QString &textChanged );
93 void slotCityChange( const QString &textChanged );
94 void slotStateChange( const QString &textChanged );
95 void slotZipChange( const QString &textChanged );
96 void slotCountryChange( const QString &textChanged );
97 void slotFullNameChange( const QString &textChanged );
98
99 private:
100 bool useFullName, hasGender, hasTitle, hasCompany, hasNotes, hasStreet, hasStreet2, hasPOBox, hasCity, hasState, hasZip, hasCountry;
101
102 Contact ent;
103
104 QDialog *dlgNote;
105 QDialog *dlgName;
106
107 QList<QLineEdit> listValue;
108 QList<QLabel> listName;
109 const QValueList<int> *orderedValues;
110 QStringList *slOrdered;
111 QStringList *slDynamicEntries;
112
113 QStringList *slHomeAddress;
114 QStringList *slBusinessAddress;
115 QStringList *slChooserNames;
116 QStringList *slChooserValues;
117
118 QMultiLineEdit *txtNote;
119 QLabel *lblNote;
120
121 //QLineEdit *txtTitle;
122 QLineEdit *txtFirstName;
123 QLineEdit *txtMiddleName;
124 QLineEdit *txtLastName;
125 QLineEdit *txtSuffix;
126
127 QTabWidget *tabMain;
128 QScrollView *svGeneral;
129 QPushButton *btnFullName;
130 QPushButton *btnNote;
131 QLineEdit *txtFullName;
132 QLineEdit *txtJobTitle;
133 QLineEdit *txtOrganization;
134 QLineEdit *txtChooserField1;
135 QLineEdit *txtChooserField2;
136 QLineEdit *txtChooserField3;
137 QComboBox *cmbChooserField1;
138 QComboBox *cmbChooserField2;
139 QComboBox *cmbChooserField3;
140 QComboBox *cmbFileAs;
141 CategorySelect *cmbCat;
142
143 QScrollView *svAddress;
144 QLineEdit *txtAddress;
145 //QLineEdit *txtAddress2;
146 //QLineEdit *txtPOBox;
147 QLineEdit *txtCity;
148 QLineEdit *txtState;
149 QLineEdit *txtZip;
150 QComboBox *cmbAddress;
151 QComboBox *cmbCountry;
152
153 QScrollView *svDetails;
154 QComboBox *cmbGender;
155
156};
157
158#endif