Diffstat (limited to 'core/pim/addressbook/contacteditor.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/addressbook/contacteditor.cpp | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp index d14ac51..d830ad3 100644 --- a/core/pim/addressbook/contacteditor.cpp +++ b/core/pim/addressbook/contacteditor.cpp | |||
@@ -58,38 +58,45 @@ static inline bool constainsWhiteSpace( const QString &str ); | |||
58 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, | 58 | void parseEmailFrom( const QString &txt, QString &strDefaultEmail, |
59 | QString &strAll ); | 59 | QString &strAll ); |
60 | 60 | ||
61 | // helper convert from file format to comma delimited... | 61 | // helper convert from file format to comma delimited... |
62 | void parseEmailTo( const QString &strDefaultEmail, | 62 | void parseEmailTo( const QString &strDefaultEmail, |
63 | const QString &strOtherEmail, QString &strBack ); | 63 | const QString &strOtherEmail, QString &strBack ); |
64 | 64 | ||
65 | ContactEditor::ContactEditor(const OContact &entry, | 65 | ContactEditor::ContactEditor(const OContact &entry, |
66 | QWidget *parent, | 66 | QWidget *parent, |
67 | const char *name, | 67 | const char *name, |
68 | WFlags fl ) | 68 | WFlags fl ) |
69 | : QDialog( parent, name, TRUE, fl ), | 69 | : QDialog( parent, name, TRUE, fl ), |
70 | m_personalView ( false ) | 70 | defaultEmailChooserPosition( -1 ), |
71 | 71 | m_personalView ( false ), | |
72 | cmbDefaultEmail( 0 ), | ||
73 | initializing ( false ) | ||
72 | { | 74 | { |
73 | 75 | ||
76 | initializing = true; | ||
77 | |||
74 | init(); | 78 | init(); |
75 | setEntry( entry ); | 79 | setEntry( entry ); |
76 | cmbDefaultEmail = 0; | 80 | // cmbDefaultEmail = 0; |
77 | defaultEmailChooserPosition = -1; | 81 | // defaultEmailChooserPosition = -1; |
82 | |||
83 | initializing = false; | ||
78 | } | 84 | } |
79 | 85 | ||
80 | ContactEditor::~ContactEditor() { | 86 | ContactEditor::~ContactEditor() { |
81 | } | 87 | } |
82 | 88 | ||
83 | void ContactEditor::init() { | 89 | void ContactEditor::init() { |
90 | qWarning("init() START"); | ||
84 | 91 | ||
85 | useFullName = true; | 92 | useFullName = true; |
86 | 93 | ||
87 | uint i = 0; | 94 | uint i = 0; |
88 | 95 | ||
89 | QStringList trlChooserNames; | 96 | QStringList trlChooserNames; |
90 | 97 | ||
91 | for (i = 0; i <= 6; i++) { | 98 | for (i = 0; i <= 6; i++) { |
92 | slHomeAddress.append( "" ); | 99 | slHomeAddress.append( "" ); |
93 | slBusinessAddress.append( "" ); | 100 | slBusinessAddress.append( "" ); |
94 | } | 101 | } |
95 | 102 | ||
@@ -633,24 +640,26 @@ void ContactEditor::init() { | |||
633 | connect( cmbChooserField2, SIGNAL(activated(int)), | 640 | connect( cmbChooserField2, SIGNAL(activated(int)), |
634 | this, SLOT(slotCmbChooser2Change(int)) ); | 641 | this, SLOT(slotCmbChooser2Change(int)) ); |
635 | connect( cmbChooserField3, SIGNAL(activated(int)), | 642 | connect( cmbChooserField3, SIGNAL(activated(int)), |
636 | this, SLOT(slotCmbChooser3Change(int)) ); | 643 | this, SLOT(slotCmbChooser3Change(int)) ); |
637 | connect( cmbChooserField4, SIGNAL(activated(int)), | 644 | connect( cmbChooserField4, SIGNAL(activated(int)), |
638 | this, SLOT(slotCmbChooser4Change(int)) ); | 645 | this, SLOT(slotCmbChooser4Change(int)) ); |
639 | connect( cmbAddress, SIGNAL(activated(int)), | 646 | connect( cmbAddress, SIGNAL(activated(int)), |
640 | this, SLOT(slotAddressTypeChange(int)) ); | 647 | this, SLOT(slotAddressTypeChange(int)) ); |
641 | 648 | ||
642 | new QPEDialogListener(this); | 649 | new QPEDialogListener(this); |
643 | 650 | ||
644 | setPersonalView ( m_personalView ); | 651 | setPersonalView ( m_personalView ); |
652 | |||
653 | qWarning("init() END"); | ||
645 | } | 654 | } |
646 | 655 | ||
647 | void ContactEditor::defaultEmailChanged(int i){ | 656 | void ContactEditor::defaultEmailChanged(int i){ |
648 | qDebug("defaultEmailChanged"); | 657 | qDebug("defaultEmailChanged"); |
649 | 658 | ||
650 | // was sollte das ? (se) | 659 | // was sollte das ? (se) |
651 | // int index = cmbChooserField1->currentItem(); | 660 | // int index = cmbChooserField1->currentItem(); |
652 | // slChooserValues[index] = cmbDefaultEmail->text(i); | 661 | // slChooserValues[index] = cmbDefaultEmail->text(i); |
653 | 662 | ||
654 | defaultEmail = cmbDefaultEmail->text(i); | 663 | defaultEmail = cmbDefaultEmail->text(i); |
655 | qDebug ("Changed to: %s", defaultEmail.latin1()); | 664 | qDebug ("Changed to: %s", defaultEmail.latin1()); |
656 | 665 | ||
@@ -683,43 +692,52 @@ void ContactEditor::populateDefaultEmailCmb(){ | |||
683 | 692 | ||
684 | // If the current default email is not found in the list, we choose the | 693 | // If the current default email is not found in the list, we choose the |
685 | // first one.. | 694 | // first one.. |
686 | if ( !found ) | 695 | if ( !found ) |
687 | defaultEmail = cmbDefaultEmail->text(0); | 696 | defaultEmail = cmbDefaultEmail->text(0); |
688 | } | 697 | } |
689 | 698 | ||
690 | // Called when any combobox was changed. | 699 | // Called when any combobox was changed. |
691 | // "true" returned if the change was chandled by this function, else it should | 700 | // "true" returned if the change was chandled by this function, else it should |
692 | // be handled by something else.. | 701 | // be handled by something else.. |
693 | bool ContactEditor::cmbChooserChange( int index, QLineEdit *inputWid, int widgetPos ) { | 702 | bool ContactEditor::cmbChooserChange( int index, QLineEdit *inputWid, int widgetPos ) { |
694 | QString type = slChooserNames[index]; | 703 | QString type = slChooserNames[index]; |
695 | qWarning("ContactEditor::cmbChooserChange -> Type: %s", type.latin1() ); | 704 | qWarning("ContactEditor::cmbChooserChange -> Type: %s, WidgetPos: %d", type.latin1(), widgetPos ); |
705 | |||
706 | if ( !initializing ) | ||
707 | contactfields.setFieldOrder( widgetPos-1, index ); | ||
696 | 708 | ||
697 | // Create and connect combobox for selecting the default email | 709 | // Create and connect combobox for selecting the default email |
698 | if ( type == "Default Email"){ | 710 | if ( type == "Default Email"){ |
699 | qWarning("Choosing default-email "); | 711 | qWarning("Choosing default-email (defaultEmailChooserPosition= %d) ", defaultEmailChooserPosition); |
700 | 712 | ||
701 | // More than one defaul-email chooser is not allowed ! | 713 | // More than one defaul-email chooser is not allowed ! |
702 | if ( ( defaultEmailChooserPosition != -1 ) && | 714 | if ( ( defaultEmailChooserPosition != -1 ) && |
703 | defaultEmailChooserPosition != widgetPos ){ | 715 | defaultEmailChooserPosition != widgetPos && !initializing){ |
704 | chooserError( widgetPos ); | 716 | chooserError( widgetPos ); |
705 | return true; | 717 | return true; |
706 | } | 718 | } |
707 | 719 | ||
708 | if ( cmbDefaultEmail ){ | 720 | if ( cmbDefaultEmail ){ |
709 | delete cmbDefaultEmail; | 721 | delete cmbDefaultEmail; |
710 | cmbDefaultEmail = 0l; | 722 | cmbDefaultEmail = 0l; |
711 | } | 723 | } |
712 | cmbDefaultEmail = new QComboBox(inputWid->parentWidget()); | 724 | cmbDefaultEmail = new QComboBox(inputWid->parentWidget()); |
713 | cmbDefaultEmail->setGeometry(inputWid->frameGeometry()); | 725 | cmbDefaultEmail->setGeometry(inputWid->frameGeometry()); /* :SX */ |
726 | |||
727 | QRect rect = inputWid->frameGeometry(); | ||
728 | qWarning("Geometrie: X=%d, Y=%d, Left=%d, Top=%d, Right=%d, Bottom=%d", | ||
729 | rect.x(), rect.y(), rect.left(), rect.top(), rect.right(), rect.bottom()); | ||
730 | QPoint pnt = inputWid->pos(); | ||
731 | qWarning("Position : X=%d, Y=%d", pnt.x(), pnt.y() ); | ||
714 | 732 | ||
715 | connect( cmbDefaultEmail,SIGNAL( activated(int) ), | 733 | connect( cmbDefaultEmail,SIGNAL( activated(int) ), |
716 | SLOT( defaultEmailChanged(int) ) ); | 734 | SLOT( defaultEmailChanged(int) ) ); |
717 | 735 | ||
718 | cmbDefaultEmail->clear(); | 736 | cmbDefaultEmail->clear(); |
719 | cmbDefaultEmail->insertStringList( emails ); | 737 | cmbDefaultEmail->insertStringList( emails ); |
720 | cmbDefaultEmail->show(); | 738 | cmbDefaultEmail->show(); |
721 | 739 | ||
722 | defaultEmailChooserPosition = widgetPos; | 740 | defaultEmailChooserPosition = widgetPos; |
723 | 741 | ||
724 | // Set current default email | 742 | // Set current default email |
725 | populateDefaultEmailCmb(); | 743 | populateDefaultEmailCmb(); |
@@ -935,24 +953,29 @@ void ContactEditor::slotCmbChooser4Change( int index ) { | |||
935 | qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); | 953 | qWarning("ContactEditor::slotCmbChooser4Change( %d )", index); |
936 | 954 | ||
937 | if ( !cmbChooserChange( cmbChooserField4->currentItem(), txtChooserField4, 4) ){ | 955 | if ( !cmbChooserChange( cmbChooserField4->currentItem(), txtChooserField4, 4) ){ |
938 | 956 | ||
939 | txtChooserField4->setText( slChooserValues[index] ); | 957 | txtChooserField4->setText( slChooserValues[index] ); |
940 | txtChooserField4->setFocus(); | 958 | txtChooserField4->setFocus(); |
941 | 959 | ||
942 | } | 960 | } |
943 | } | 961 | } |
944 | 962 | ||
945 | void ContactEditor::slotAddressTypeChange( int index ) { | 963 | void ContactEditor::slotAddressTypeChange( int index ) { |
946 | 964 | ||
965 | |||
966 | if ( !initializing ) | ||
967 | contactfields.setFieldOrder( 4, index ); | ||
968 | |||
969 | |||
947 | if ( index == 0 ) { | 970 | if ( index == 0 ) { |
948 | 971 | ||
949 | txtAddress->setText( slBusinessAddress[0] ); | 972 | txtAddress->setText( slBusinessAddress[0] ); |
950 | //txtAddress2->setText( (*slBusinessAddress)[1] ); | 973 | //txtAddress2->setText( (*slBusinessAddress)[1] ); |
951 | //txtPOBox->setText( (*slBusinessAddress)[2] ); | 974 | //txtPOBox->setText( (*slBusinessAddress)[2] ); |
952 | txtCity->setText( slBusinessAddress[3] ); | 975 | txtCity->setText( slBusinessAddress[3] ); |
953 | txtState->setText( slBusinessAddress[4] ); | 976 | txtState->setText( slBusinessAddress[4] ); |
954 | txtZip->setText( slBusinessAddress[5] ); | 977 | txtZip->setText( slBusinessAddress[5] ); |
955 | QLineEdit *txtTmp = cmbCountry->lineEdit(); | 978 | QLineEdit *txtTmp = cmbCountry->lineEdit(); |
956 | txtTmp->setText( slBusinessAddress[6] ); | 979 | txtTmp->setText( slBusinessAddress[6] ); |
957 | 980 | ||
958 | } else { | 981 | } else { |
@@ -1267,30 +1290,30 @@ void ContactEditor::cleanupFields() { | |||
1267 | txtCity->setText(""); | 1290 | txtCity->setText(""); |
1268 | txtState->setText(""); | 1291 | txtState->setText(""); |
1269 | txtZip->setText(""); | 1292 | txtZip->setText(""); |
1270 | QLineEdit *txtTmp = cmbCountry->lineEdit(); | 1293 | QLineEdit *txtTmp = cmbCountry->lineEdit(); |
1271 | txtTmp->setText(""); | 1294 | txtTmp->setText(""); |
1272 | txtTmp = cmbFileAs->lineEdit(); | 1295 | txtTmp = cmbFileAs->lineEdit(); |
1273 | txtTmp->setText(""); | 1296 | txtTmp->setText(""); |
1274 | 1297 | ||
1275 | } | 1298 | } |
1276 | 1299 | ||
1277 | void ContactEditor::setEntry( const OContact &entry ) { | 1300 | void ContactEditor::setEntry( const OContact &entry ) { |
1278 | 1301 | ||
1302 | initializing = true; | ||
1303 | |||
1279 | cleanupFields(); | 1304 | cleanupFields(); |
1280 | 1305 | ||
1281 | ent = entry; | 1306 | ent = entry; |
1282 | 1307 | ||
1283 | |||
1284 | |||
1285 | emails = QStringList(ent.emailList()); | 1308 | emails = QStringList(ent.emailList()); |
1286 | defaultEmail = ent.defaultEmail(); | 1309 | defaultEmail = ent.defaultEmail(); |
1287 | if (defaultEmail.isEmpty()) defaultEmail = emails[0]; | 1310 | if (defaultEmail.isEmpty()) defaultEmail = emails[0]; |
1288 | qDebug("default email=%s",defaultEmail.latin1()); | 1311 | qDebug("default email=%s",defaultEmail.latin1()); |
1289 | 1312 | ||
1290 | useFullName = false; | 1313 | useFullName = false; |
1291 | txtFirstName->setText( ent.firstName() ); | 1314 | txtFirstName->setText( ent.firstName() ); |
1292 | txtMiddleName->setText( ent.middleName() ); | 1315 | txtMiddleName->setText( ent.middleName() ); |
1293 | txtLastName->setText( ent.lastName() ); | 1316 | txtLastName->setText( ent.lastName() ); |
1294 | txtSuffix->setText( ent.suffix() ); | 1317 | txtSuffix->setText( ent.suffix() ); |
1295 | 1318 | ||
1296 | QString *tmpString = new QString; | 1319 | QString *tmpString = new QString; |
@@ -1446,52 +1469,72 @@ void ContactEditor::setEntry( const OContact &entry ) { | |||
1446 | 1469 | ||
1447 | 1470 | ||
1448 | } | 1471 | } |
1449 | 1472 | ||
1450 | 1473 | ||
1451 | cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); | 1474 | cmbCat->setCategories( ent.categories(), "Contacts", tr("Contacts") ); |
1452 | 1475 | ||
1453 | QString gender = ent.gender(); | 1476 | QString gender = ent.gender(); |
1454 | cmbGender->setCurrentItem( gender.toInt() ); | 1477 | cmbGender->setCurrentItem( gender.toInt() ); |
1455 | 1478 | ||
1456 | txtNote->setText( ent.notes() ); | 1479 | txtNote->setText( ent.notes() ); |
1457 | 1480 | ||
1481 | slotAddressTypeChange( cmbAddress->currentItem() ); | ||
1482 | |||
1483 | // Calling "show()" to arrange all widgets. Otherwise we will get | ||
1484 | // a wrong position of the textfields and are unable to put our | ||
1485 | // default-email combo over it.. This is very ugly ! | ||
1486 | // Does anybody has a better solution ? | ||
1487 | // Basically we should rethink the strategy to hide | ||
1488 | // a textfield with overwriting.. (se) | ||
1489 | show(); | ||
1490 | |||
1491 | // Get combo-settings from contact and set preset.. | ||
1492 | contactfields.loadFromRecord( ent ); | ||
1493 | cmbChooserField1->setCurrentItem( contactfields.getFieldOrder(0, 0) ); | ||
1494 | cmbChooserField2->setCurrentItem( contactfields.getFieldOrder(1, 1) ); | ||
1495 | cmbChooserField3->setCurrentItem( contactfields.getFieldOrder(2, 2) ); | ||
1496 | cmbChooserField4->setCurrentItem( contactfields.getFieldOrder(3, 5) ); | ||
1497 | cmbAddress->setCurrentItem( contactfields.getFieldOrder(4, 1) ); | ||
1458 | slotCmbChooser1Change( cmbChooserField1->currentItem() ); | 1498 | slotCmbChooser1Change( cmbChooserField1->currentItem() ); |
1459 | slotCmbChooser2Change( cmbChooserField2->currentItem() ); | 1499 | slotCmbChooser2Change( cmbChooserField2->currentItem() ); |
1460 | slotCmbChooser3Change( cmbChooserField3->currentItem() ); | 1500 | slotCmbChooser3Change( cmbChooserField3->currentItem() ); |
1461 | 1501 | slotCmbChooser4Change( cmbChooserField4->currentItem() ); | |
1462 | slotAddressTypeChange( cmbAddress->currentItem() ); | 1502 | slotAddressTypeChange( cmbAddress->currentItem() ); |
1463 | 1503 | ||
1464 | // loadFields(); :SX | ||
1465 | updateDatePicker(); | 1504 | updateDatePicker(); |
1505 | |||
1506 | initializing = false; | ||
1466 | } | 1507 | } |
1467 | void ContactEditor::updateDatePicker() | 1508 | void ContactEditor::updateDatePicker() |
1468 | { | 1509 | { |
1469 | // Set DatePicker | 1510 | // Set DatePicker |
1470 | if ( !ent.birthday().isNull() ){ | 1511 | if ( !ent.birthday().isNull() ){ |
1471 | birthdayButton->setText( TimeString::numberDateString( ent.birthday() ) ); | 1512 | birthdayButton->setText( TimeString::numberDateString( ent.birthday() ) ); |
1472 | birthdayPicker->setDate( ent.birthday() ); | 1513 | birthdayPicker->setDate( ent.birthday() ); |
1473 | } else | 1514 | } else |
1474 | birthdayButton->setText( tr ("Unknown") ); | 1515 | birthdayButton->setText( tr ("Unknown") ); |
1475 | 1516 | ||
1476 | if ( !ent.anniversary().isNull() ){ | 1517 | if ( !ent.anniversary().isNull() ){ |
1477 | anniversaryButton->setText( TimeString::numberDateString( ent.anniversary() ) ); | 1518 | anniversaryButton->setText( TimeString::numberDateString( ent.anniversary() ) ); |
1478 | anniversaryPicker->setDate( ent.anniversary() ); | 1519 | anniversaryPicker->setDate( ent.anniversary() ); |
1479 | } else | 1520 | } else |
1480 | anniversaryButton->setText( tr ("Unknown") ); | 1521 | anniversaryButton->setText( tr ("Unknown") ); |
1481 | 1522 | ||
1482 | } | 1523 | } |
1483 | 1524 | ||
1484 | void ContactEditor::saveEntry() { | 1525 | void ContactEditor::saveEntry() { |
1485 | 1526 | ||
1527 | // Store current combo into contact | ||
1528 | contactfields.saveToRecord( ent ); | ||
1486 | 1529 | ||
1487 | if ( useFullName ) { | 1530 | if ( useFullName ) { |
1488 | txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) ); | 1531 | txtFirstName->setText( parseName( txtFullName->text(), NAME_F ) ); |
1489 | txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) ); | 1532 | txtMiddleName->setText( parseName( txtFullName->text(), NAME_M ) ); |
1490 | txtLastName->setText( parseName( txtFullName->text(), NAME_L ) ); | 1533 | txtLastName->setText( parseName( txtFullName->text(), NAME_L ) ); |
1491 | txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); | 1534 | txtSuffix->setText( parseName( txtFullName->text(), NAME_S ) ); |
1492 | 1535 | ||
1493 | useFullName = false; | 1536 | useFullName = false; |
1494 | } | 1537 | } |
1495 | 1538 | ||
1496 | ent.setFirstName( txtFirstName->text() ); | 1539 | ent.setFirstName( txtFirstName->text() ); |
1497 | ent.setLastName( txtLastName->text() ); | 1540 | ent.setLastName( txtLastName->text() ); |