From 92d38d07328e398b7f03f8b154e1ecc7ec510949 Mon Sep 17 00:00:00 2001 From: rjarosz Date: Thu, 19 Oct 2006 16:09:33 +0000 Subject: [PATCH] Add support for editing ICQMoreUserInfo. Editing of marital status doesn't work, we don't know a TLV type. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdenetwork@597214 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/oscar/icq/ui/icqgeneralinfo.ui | 291 ++++++++++++++------- .../protocols/oscar/icq/ui/icquserinfowidget.cpp | 187 ++++++++++--- kopete/protocols/oscar/icq/ui/icquserinfowidget.h | 10 +- kopete/protocols/oscar/liboscar/icquserinfo.cpp | 96 +++++-- kopete/protocols/oscar/liboscar/icquserinfo.h | 29 +- 5 files changed, 458 insertions(+), 155 deletions(-) diff --git a/kopete/protocols/oscar/icq/ui/icqgeneralinfo.ui b/kopete/protocols/oscar/icq/ui/icqgeneralinfo.ui index 62cd6f809..97ce1c8df 100644 --- a/kopete/protocols/oscar/icq/ui/icqgeneralinfo.ui +++ b/kopete/protocols/oscar/icq/ui/icqgeneralinfo.ui @@ -6,7 +6,7 @@ 0 0 484 - 500 + 502 @@ -118,16 +118,12 @@ Gen&der: - genderEdit + genderCombo - - - true - - + @@ -164,23 +160,133 @@ - + - &Birthday: + Marital status: - birthday + maritalCombo - - - true + + + + + + &Timezone: + + + timezoneCombo - + + + + + + + + + + Birthday + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + Day: + + + birthdayDaySpin + + + + + + + true + + + 31 + + + + + + + Month: + + + birthdayMonthSpin + + + + + + + true + + + 12 + + + 0 + + + + + + + Year: + + + birthdayYearSpin + + + + + + + true + + + 7999 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -194,43 +300,34 @@ A&ge: - ageSpinBox + ageEdit - - - - - - - Marital status: + + + + + 13 + 0 + 0 + 0 + - - marital + + + 35 + 0 + + + + 3 - - - - true - - - - &Timezone: - - - timezoneCombo - - - - - - @@ -246,8 +343,18 @@ 6 + + + + First: + + + language1Combo + + + - + 7 @@ -256,52 +363,49 @@ 0 - - true - - - - - - - true - - - + + - Third: + Second: - language3Edit + language2Combo - - - true + + + + 7 + 0 + 0 + 0 + - - + + - Second: + Third: - language2Edit + language3Combo - - - - First: - - - language1Edit + + + + + 7 + 0 + 0 + 0 + @@ -330,6 +434,21 @@ + + + + + 7 + 0 + 0 + 0 + + + + true + + + @@ -353,19 +472,12 @@ Country: - oCountryEdit + oCountryCombo - - - true - - - - - + 7 @@ -374,9 +486,6 @@ 0 - - true - @@ -406,19 +515,21 @@ uinEdit ipEdit nickNameEdit - genderEdit + genderCombo firstNameEdit lastNameEdit - birthday - ageSpinBox - marital + maritalCombo timezoneCombo - language1Edit - language2Edit - language3Edit + birthdayDaySpin + birthdayMonthSpin + birthdayYearSpin + ageEdit + language1Combo + language2Combo + language3Combo oCityEdit oStateEdit - oCountryEdit + oCountryCombo diff --git a/kopete/protocols/oscar/icq/ui/icquserinfowidget.cpp b/kopete/protocols/oscar/icq/ui/icquserinfowidget.cpp index 830974b6b..8ff766b07 100644 --- a/kopete/protocols/oscar/icq/ui/icquserinfowidget.cpp +++ b/kopete/protocols/oscar/icq/ui/icquserinfowidget.cpp @@ -95,6 +95,13 @@ ICQUserInfoWidget::ICQUserInfoWidget( QWidget * parent, bool editable ) m_emailModel = new QStringListModel(); m_otherInfoWidget->emailListView->setModel( m_emailModel ); + connect( m_genInfoWidget->birthdayYearSpin, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDay()) ); + connect( m_genInfoWidget->birthdayMonthSpin, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDay()) ); + + connect( m_genInfoWidget->birthdayYearSpin, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateAge()) ); + connect( m_genInfoWidget->birthdayMonthSpin, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateAge()) ); + connect( m_genInfoWidget->birthdayDaySpin, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateAge()) ); + //ICQGeneralUserInfo m_genInfoWidget->nickNameEdit->setReadOnly( !m_editable ); m_genInfoWidget->firstNameEdit->setReadOnly( !m_editable ); @@ -107,7 +114,14 @@ ICQUserInfoWidget::ICQUserInfoWidget( QWidget * parent, bool editable ) m_homeInfoWidget->cellEdit->setReadOnly( !m_editable ); m_homeInfoWidget->zipEdit->setReadOnly( !m_editable ); m_homeInfoWidget->emailEdit->setReadOnly( !m_editable ); - + + m_genInfoWidget->ageEdit->setReadOnly( !m_editable ); + m_genInfoWidget->birthdayDaySpin->setReadOnly( !m_editable ); + m_genInfoWidget->birthdayMonthSpin->setReadOnly( !m_editable ); + m_genInfoWidget->birthdayYearSpin->setReadOnly( !m_editable ); + m_homeInfoWidget->homepageEdit->setReadOnly( !m_editable ); + m_genInfoWidget->oCityEdit->setReadOnly( !m_editable ); + m_genInfoWidget->oStateEdit->setReadOnly( !m_editable ); } ICQUserInfoWidget::~ ICQUserInfoWidget() @@ -137,22 +151,47 @@ void ICQUserInfoWidget::setContact( ICQContact* contact ) QObject::connect( contact, SIGNAL( haveOrgAffInfo( const ICQOrgAffInfo& ) ), this, SLOT( fillOrgAffInfo( const ICQOrgAffInfo& ) ) ); - QMap sortedCountries; - QMapIterator it( static_cast( m_contact->protocol() )->countries() ); + //Countries + QMap sortedMap( reverseMap( static_cast( m_contact->protocol() )->countries() ) ); + QMapIterator it( sortedMap ); while ( it.hasNext() ) { it.next(); - sortedCountries.insert( it.value(), it.key() ); + m_homeInfoWidget->countryCombo->addItem( it.key(), it.value() ); + m_genInfoWidget->oCountryCombo->addItem( it.key(), it.value() ); } - QMapIterator it2( sortedCountries ); - while ( it2.hasNext() ) + //Languages + it = sortedMap = reverseMap( static_cast( m_contact->protocol() )->languages() ); + it = sortedMap; + while ( it.hasNext() ) + { + it.next(); + m_genInfoWidget->language1Combo->addItem( it.key(), it.value() ); + m_genInfoWidget->language2Combo->addItem( it.key(), it.value() ); + m_genInfoWidget->language3Combo->addItem( it.key(), it.value() ); + } + + //Genders + it = sortedMap = reverseMap( static_cast( m_contact->protocol() )->genders() ); + it = sortedMap; + while ( it.hasNext() ) + { + it.next(); + m_genInfoWidget->genderCombo->addItem( it.key(), it.value() ); + } + + //Maritals + it = sortedMap = reverseMap( static_cast( m_contact->protocol() )->maritals() ); + it = sortedMap; + while ( it.hasNext() ) { - it2.next(); - m_homeInfoWidget->countryCombo->addItem( it2.key(), it2.value() ); + it.next(); + m_genInfoWidget->maritalCombo->addItem( it.key(), it.value() ); } + //Timezone QString timezone; for ( int zone = 24; zone >= -24; zone-- ) { @@ -173,6 +212,7 @@ QList ICQUserInfoWidget::getInfoData() const return infoList; infoList.append( storeBasicInfo() ); + infoList.append( storeMoreInfo() ); return infoList; } @@ -302,33 +342,64 @@ void ICQUserInfoWidget::fillOrgAffInfo( const ICQOrgAffInfo& info) void ICQUserInfoWidget::fillMoreInfo( const ICQMoreUserInfo& ui ) { QTextCodec* codec = m_contact->contactCodec(); - m_genInfoWidget->ageSpinBox->setValue( ui.age ); - if ( ui.birthday.isValid() ) - m_genInfoWidget->birthday->setText( KGlobal::locale()->formatDate( ui.birthday,true ) ); - - QString gender = static_cast( m_contact->protocol() )->genders()[ui.gender]; - m_genInfoWidget->genderEdit->setText( gender ); - m_homeInfoWidget->homepageEdit->setText( codec->toUnicode( ui.homepage ) ); - QString ms = static_cast( m_contact->protocol() )->maritals()[ui.marital]; - m_genInfoWidget->marital->setText( ms ); + if ( m_editable ) + m_moreUserInfo = ui; + + m_genInfoWidget->ageEdit->setText( QString::number( ui.age.get() ) ); + m_genInfoWidget->birthdayYearSpin->setValue( ui.birthdayYear.get() ); + m_genInfoWidget->birthdayMonthSpin->setValue( ui.birthdayMonth.get() ); + m_genInfoWidget->birthdayDaySpin->setValue( ui.birthdayDay.get() ); + m_genInfoWidget->genderCombo->setCurrentIndex( m_genInfoWidget->genderCombo->findData( ui.gender.get() ) ); + m_homeInfoWidget->homepageEdit->setText( codec->toUnicode( ui.homepage.get() ) ); + m_genInfoWidget->maritalCombo->setCurrentIndex( m_genInfoWidget->maritalCombo->findData( ui.marital.get() ) ); + m_genInfoWidget->oCityEdit->setText( codec->toUnicode( ui.ocity.get() ) ); + m_genInfoWidget->oStateEdit->setText( codec->toUnicode( ui.ostate.get() ) ); + m_genInfoWidget->oCountryCombo->setCurrentIndex( m_genInfoWidget->oCountryCombo->findData( ui.ocountry.get() ) ); + m_genInfoWidget->language1Combo->setCurrentIndex( m_genInfoWidget->language1Combo->findData( ui.lang1.get() ) ); + m_genInfoWidget->language2Combo->setCurrentIndex( m_genInfoWidget->language2Combo->findData( ui.lang2.get() ) ); + m_genInfoWidget->language3Combo->setCurrentIndex( m_genInfoWidget->language3Combo->findData( ui.lang3.get() ) ); +} - m_genInfoWidget->oCityEdit->setText( codec->toUnicode( ui.ocity) ); - m_genInfoWidget->oStateEdit->setText( codec->toUnicode( ui.ostate) ); - - ICQProtocol* p = static_cast( m_contact->protocol() ); - - QString ocountry = p->countries()[ui.ocountry]; - m_genInfoWidget->oCountryEdit->setText( ocountry ); - - QString lang1 = p->languages()[ui.lang1]; - m_genInfoWidget->language1Edit->setText( lang1 ); - - QString lang2 = p->languages()[ui.lang2]; - m_genInfoWidget->language2Edit->setText( lang2 ); - - QString lang3 = p->languages()[ui.lang3]; - m_genInfoWidget->language3Edit->setText( lang3 ); + +void ICQUserInfoWidget::slotUpdateDay() +{ + int year = m_genInfoWidget->birthdayYearSpin->value(); + int month = m_genInfoWidget->birthdayMonthSpin->value(); + QDate date( year, month, 1 ); + + if ( date.isValid() ) + m_genInfoWidget->birthdayDaySpin->setMaximum( date.daysInMonth() ); + else + m_genInfoWidget->birthdayDaySpin->setMaximum( 31 ); +} + +void ICQUserInfoWidget::slotUpdateAge() +{ + QDate now = QDate::currentDate(); + int year = m_genInfoWidget->birthdayYearSpin->value(); + int month = m_genInfoWidget->birthdayMonthSpin->value(); + int day = m_genInfoWidget->birthdayDaySpin->value(); + + int age = 0; + + if ( year > 0 ) + { + age = now.year() - year; + if ( month > now.month() ) + { + age--; + } + else if ( month == now.month() ) + { + if ( day > now.day() ) + { + age--; + } + } + } + + m_genInfoWidget->ageEdit->setText( QString::number( age ) ); } ICQGeneralUserInfo* ICQUserInfoWidget::storeBasicInfo() const @@ -357,6 +428,56 @@ ICQGeneralUserInfo* ICQUserInfoWidget::storeBasicInfo() const return info; } +ICQMoreUserInfo* ICQUserInfoWidget::storeMoreInfo() const +{ + QTextCodec* codec = m_contact->contactCodec(); + ICQMoreUserInfo* info = new ICQMoreUserInfo( m_moreUserInfo ); + + info->age.set( m_genInfoWidget->ageEdit->text().toInt() ); + info->birthdayYear.set( m_genInfoWidget->birthdayYearSpin->value() ); + info->birthdayMonth.set( m_genInfoWidget->birthdayMonthSpin->value() ); + info->birthdayDay.set( m_genInfoWidget->birthdayDaySpin->value() ); + + int index = m_genInfoWidget->genderCombo->currentIndex(); + info->gender.set( m_genInfoWidget->genderCombo->itemData( index ).toInt() ); + + info->homepage.set( codec->fromUnicode( m_homeInfoWidget->homepageEdit->text() ) ); + + index = m_genInfoWidget->maritalCombo->currentIndex(); + info->marital.set( m_genInfoWidget->maritalCombo->itemData( index ).toInt() ); + + info->ocity.set( codec->fromUnicode( m_genInfoWidget->oCityEdit->text() ) ); + info->ostate.set( codec->fromUnicode( m_genInfoWidget->oStateEdit->text() ) ); + + index = m_genInfoWidget->oCountryCombo->currentIndex(); + info->ocountry.set( m_genInfoWidget->oCountryCombo->itemData( index ).toInt() ); + + index = m_genInfoWidget->language1Combo->currentIndex(); + info->lang1.set( m_genInfoWidget->language1Combo->itemData( index ).toInt() ); + + index = m_genInfoWidget->language2Combo->currentIndex(); + info->lang2.set( m_genInfoWidget->language2Combo->itemData( index ).toInt() ); + + index = m_genInfoWidget->language3Combo->currentIndex(); + info->lang3.set( m_genInfoWidget->language3Combo->itemData( index ).toInt() ); + + return info; +} + +QMap ICQUserInfoWidget::reverseMap( const QMap& map ) const +{ + QMap revMap; + QMapIterator it( map ); + + while ( it.hasNext() ) + { + it.next(); + revMap.insert( it.value(), it.key() ); + } + + return revMap; +} + #include "icquserinfowidget.moc" //kate: indent-mode csands; tab-width 4; space-indent off; replace-tabs off; diff --git a/kopete/protocols/oscar/icq/ui/icquserinfowidget.h b/kopete/protocols/oscar/icq/ui/icquserinfowidget.h index 4b35f9286..4991dcb45 100644 --- a/kopete/protocols/oscar/icq/ui/icquserinfowidget.h +++ b/kopete/protocols/oscar/icq/ui/icquserinfowidget.h @@ -55,9 +55,16 @@ public slots: void fillInterestInfo( const ICQInterestInfo& ); void fillOrgAffInfo( const ICQOrgAffInfo& info); +private slots: + void slotUpdateDay(); + void slotUpdateAge(); + private: ICQGeneralUserInfo* storeBasicInfo() const; - + ICQMoreUserInfo* storeMoreInfo() const; + + QMap reverseMap( const QMap& map ) const; + Ui::ICQGeneralInfoWidget* m_genInfoWidget; Ui::ICQWorkInfoWidget* m_workInfoWidget; Ui::ICQHomeInfoWidget* m_homeInfoWidget; @@ -70,6 +77,7 @@ private: bool m_editable; ICQGeneralUserInfo m_generalUserInfo; + ICQMoreUserInfo m_moreUserInfo; }; #endif diff --git a/kopete/protocols/oscar/liboscar/icquserinfo.cpp b/kopete/protocols/oscar/liboscar/icquserinfo.cpp index a010949c4..faca775d5 100644 --- a/kopete/protocols/oscar/liboscar/icquserinfo.cpp +++ b/kopete/protocols/oscar/liboscar/icquserinfo.cpp @@ -199,14 +199,17 @@ void ICQWorkUserInfo::fill( Buffer* buffer ) ICQMoreUserInfo::ICQMoreUserInfo() { - age = 0; - gender = 0; - lang1 = 0; - lang2 = 0; - lang3 = 0; - ocountry = 0; - marital = 0; - sendInfo = false; + age.init( 0 ); + gender.init( 0 ); + birthdayYear.init( 0 ); + birthdayMonth.init( 0 ); + birthdayDay.init( 0 ); + lang1.init( 0 ); + lang2.init( 0 ); + lang3.init( 0 ); + ocountry.init( 0 ); + marital.init( 0 ); + sendInfo.init( false ); } void ICQMoreUserInfo::fill( Buffer* buffer ) @@ -216,16 +219,9 @@ void ICQMoreUserInfo::fill( Buffer* buffer ) age = buffer->getLEWord(); gender = buffer->getByte(); homepage = buffer->getLELNTS(); - WORD year = buffer->getLEWord(); - BYTE month = buffer->getByte(); - BYTE day = buffer->getByte(); - - // set birthday to NULL if at least one of the values in the buffer is 0 - if ( year == 0 || month == 0 || day == 0 ) - birthday = QDate(); - else - birthday = QDate( year, month, day ); - + birthdayYear = buffer->getLEWord(); + birthdayMonth = buffer->getByte(); + birthdayDay = buffer->getByte(); lang1 = buffer->getByte(); lang2 = buffer->getByte(); lang3 = buffer->getByte(); @@ -240,6 +236,70 @@ void ICQMoreUserInfo::fill( Buffer* buffer ) kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Couldn't parse ICQ work user info packet" << endl; } +void ICQMoreUserInfo::store( Buffer* buffer ) +{ + if ( age.hasChanged() ) + { + buffer->addLETLV16( 0x0172, age.get() ); + } + + if ( gender.hasChanged() ) + { + buffer->addLETLV8( 0x017C, gender.get() ); + } + + if ( homepage.hasChanged() ) + { + Buffer buf; + buf.addLELNTS( homepage.get() ); + buffer->addLETLV( 0x0213, buf ); + } + + if ( birthdayYear.hasChanged() || birthdayMonth.hasChanged() || birthdayDay.hasChanged() ) + { + Buffer buf; + buf.addLEWord( birthdayYear.get() ); + buf.addLEWord( birthdayMonth.get() ); + buf.addLEWord( birthdayDay.get() ); + buffer->addLETLV( 0x023A, buf ); + } + + if ( lang1.hasChanged() || lang2.hasChanged() || lang3.hasChanged() ) + { + buffer->addLETLV16( 0x0186, lang1.get() ); + buffer->addLETLV16( 0x0186, lang2.get() ); + buffer->addLETLV16( 0x0186, lang3.get() ); + } + + if ( ocity.hasChanged() ) + { + Buffer buf; + buf.addLELNTS( ocity.get() ); + buffer->addLETLV( 0x0320, buf ); + } + + if ( ostate.hasChanged() ) + { + Buffer buf; + buf.addLELNTS( ostate.get() ); + buffer->addLETLV( 0x032A, buf ); + } + + if ( ocountry.hasChanged() ) + { + buffer->addLETLV16( 0x0334, ocountry.get() ); + } + +// if ( marital.hasChanged() ) +// { +// } + + if ( sendInfo.hasChanged() ) + { + buffer->addLETLV8( 0x0348, sendInfo.get() ); + } +} + ICQEmailInfo::ICQEmailInfo() { } diff --git a/kopete/protocols/oscar/liboscar/icquserinfo.h b/kopete/protocols/oscar/liboscar/icquserinfo.h index 1beea36e5..f785d9dab 100644 --- a/kopete/protocols/oscar/liboscar/icquserinfo.h +++ b/kopete/protocols/oscar/liboscar/icquserinfo.h @@ -22,7 +22,7 @@ #include #include -#include + #include "kopete_export.h" #include "icqinfovalue.h" @@ -124,20 +124,23 @@ public: ICQMoreUserInfo(); ~ICQMoreUserInfo() {} void fill( Buffer* buffer ); + void store( Buffer* buffer ); public: - int age; - unsigned int gender; - QByteArray homepage; - QDate birthday; - unsigned int lang1; - unsigned int lang2; - unsigned int lang3; - QByteArray ocity; - QByteArray ostate; - int ocountry; - int marital; - bool sendInfo; + ICQInfoValue age; + ICQInfoValue gender; + ICQInfoValue homepage; + ICQInfoValue birthdayDay; + ICQInfoValue birthdayMonth; + ICQInfoValue birthdayYear; + ICQInfoValue lang1; + ICQInfoValue lang2; + ICQInfoValue lang3; + ICQInfoValue ocity; + ICQInfoValue ostate; + ICQInfoValue ocountry; + ICQInfoValue marital; + ICQInfoValue sendInfo; }; class KOPETE_EXPORT ICQEmailInfo : public ICQInfoBase -- 2.11.4.GIT