1 /*
2  Kopete Oscar Protocol
3  icquserinfowidget.cpp - Display ICQ user info
4 
5  Copyright (c) 2005 Matt Rogers <mattr@kde.org>
6  Copyright (c) 2006 Roman Jarosz <kedgedev@centrum.cz>
7 
8  Kopete (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
9 
10  *************************************************************************
11  *                                                                       *
12  * This library is free software; you can redistribute it and/or         *
13  * modify it under the terms of the GNU Lesser General Public            *
14  * License as published by the Free Software Foundation; either          *
15  * version 2 of the License, or (at your option) any later version.      *
16  *                                                                       *
17  *************************************************************************
18 */
19 
20 #include "icquserinfowidget.h"
21 
22 #include <QTextCodec>
23 #include <QLineEdit>
24 #include <QSpinBox>
25 #include <QStandardItemModel>
26 #include <QHeaderView>
27 
28 #include <kdatewidget.h>
29 #include <kdebug.h>
30 
31 #include <QIcon>
32 #include <KLocalizedString>
33 
34 #include "ui_icqgeneralinfo.h"
35 #include "ui_icqhomeinfowidget.h"
36 #include "ui_icqworkinfowidget.h"
37 #include "ui_icqotherinfowidget.h"
38 #include "ui_icqinterestinfowidget.h"
39 #include "ui_icqorgaffinfowidget.h"
40 
41 #include "oscarutils.h"
42 #include "icqcontact.h"
43 #include "icqaccount.h"
44 #include "icqprotocol.h"
45 
46 #undef timezone
47 
ICQUserInfoWidget(ICQAccount * account,const QString & contactId,QWidget * parent,bool ownInfo)48 ICQUserInfoWidget::ICQUserInfoWidget( ICQAccount* account, const QString& contactId, QWidget * parent, bool ownInfo )
49 : KPageDialog( parent ), m_contact( 0 ), m_account( account ), m_contactId( contactId ), m_ownInfo( ownInfo )
50 {
51 	init();
52 
53 	QObject::connect( m_account->engine(), SIGNAL(receivedIcqLongInfo(QString)),
54 	                  this, SLOT(receivedLongInfo(QString)) );
55 
56 	m_genInfoWidget->uinEdit->setText( contactId );
57 
58 	if ( m_account->isConnected() )
59 		m_account->engine()->requestFullInfo( m_contactId );
60 }
61 
ICQUserInfoWidget(ICQContact * contact,QWidget * parent,bool ownInfo)62 ICQUserInfoWidget::ICQUserInfoWidget( ICQContact* contact, QWidget * parent, bool ownInfo )
63 : KPageDialog( parent ), m_contact( contact ), m_account( static_cast<ICQAccount*>(contact->account()) ),
64   m_contactId( contact->contactId() ), m_ownInfo( ownInfo )
65 {
66 	init();
67 
68 	QObject::connect( contact, SIGNAL(haveBasicInfo(ICQGeneralUserInfo)),
69 	                  this, SLOT(fillBasicInfo(ICQGeneralUserInfo)) );
70 	QObject::connect( contact, SIGNAL(haveWorkInfo(ICQWorkUserInfo)),
71 	                  this, SLOT(fillWorkInfo(ICQWorkUserInfo)) );
72 	QObject::connect( contact, SIGNAL(haveEmailInfo(ICQEmailInfo)),
73 	                  this, SLOT(fillEmailInfo(ICQEmailInfo)) );
74 	QObject::connect( contact, SIGNAL(haveNotesInfo(ICQNotesInfo)),
75 	                  this, SLOT(fillNotesInfo(ICQNotesInfo)) );
76 	QObject::connect( contact, SIGNAL(haveMoreInfo(ICQMoreUserInfo)),
77 	                  this, SLOT(fillMoreInfo(ICQMoreUserInfo)) );
78 	QObject::connect( contact, SIGNAL(haveInterestInfo(ICQInterestInfo)),
79 	                  this, SLOT(fillInterestInfo(ICQInterestInfo)) );
80 	QObject::connect( contact, SIGNAL(haveOrgAffInfo(ICQOrgAffInfo)),
81 	                  this, SLOT(fillOrgAffInfo(ICQOrgAffInfo)) );
82 
83 	ICQProtocol* icqProtocol = static_cast<ICQProtocol*>( m_contact->protocol() );
84 
85 	m_genInfoWidget->uinEdit->setText( m_contact->contactId() );
86 	m_genInfoWidget->aliasEdit->setText( m_contact->ssiItem().alias() );
87 	m_genInfoWidget->ipEdit->setText( m_contact->property( icqProtocol->ipAddress ).value().toString() );
88 
89 	if ( m_account->isConnected() )
90 		m_account->engine()->requestFullInfo( m_contactId );
91 }
92 
init()93 void ICQUserInfoWidget::init()
94 {
95 	setFaceType( KPageDialog::List );
96 	setModal( false );
97 	setWindowTitle( i18n( "ICQ User Information" ) );
98 	setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
99 
100 	if ( m_ownInfo )
101 		button( QDialogButtonBox::Ok )->setDefault( true );
102 	else
103 		button( QDialogButtonBox::Cancel )->setDefault( true );
104 
105 	kDebug(OSCAR_ICQ_DEBUG) << "Creating new icq user info widget";
106 
107 	QWidget *genInfo = new QWidget(this);
108 	m_genInfoWidget = new Ui::ICQGeneralInfoWidget;
109 	m_genInfoWidget->setupUi( genInfo );
110 	KPageWidgetItem *genInfoItem = addPage( genInfo, i18n("General Info") );
111 	genInfoItem->setHeader( i18n("General ICQ Information") );
112     genInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("user-identity")) );
113 
114 	QWidget* homeInfo = new QWidget(this);
115 	m_homeInfoWidget = new Ui::ICQHomeInfoWidget;
116 	m_homeInfoWidget->setupUi( homeInfo );
117 	KPageWidgetItem *homeInfoItem = addPage( homeInfo, i18n("Home Info") );
118 	homeInfoItem->setHeader( i18n("Home Information") );
119     homeInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("go-home")) );
120 
121 	QWidget *workInfo = new QWidget(this);
122 	m_workInfoWidget = new Ui::ICQWorkInfoWidget;
123 	m_workInfoWidget->setupUi( workInfo );
124 	KPageWidgetItem *workInfoItem = addPage( workInfo, i18n("Work Info") );
125 	workInfoItem->setHeader( i18n( "Work Information" ) );
126     workInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("applications-engineering")) );
127 
128 	QWidget *otherInfo = new QWidget(this);
129 	m_otherInfoWidget = new Ui::ICQOtherInfoWidget();
130 	m_otherInfoWidget->setupUi( otherInfo );
131 	KPageWidgetItem *otherInfoItem = addPage( otherInfo, i18n("Other Info") );
132 	otherInfoItem->setHeader( i18n( "Other ICQ Information" ) );
133     otherInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("internet-mail")) );
134 
135 	QWidget *interestInfo = new QWidget(this);
136 	m_interestInfoWidget = new Ui::ICQInterestInfoWidget();
137 	m_interestInfoWidget->setupUi( interestInfo );
138 	KPageWidgetItem *interestInfoItem = addPage( interestInfo, i18n("Interest Info") );
139 	interestInfoItem->setHeader( i18n( "Interest Information" ) );
140     interestInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("applications-games")) );
141 
142 	QWidget *orgAffInfo = new QWidget(this);
143 	m_orgAffInfoWidget = new Ui::ICQOrgAffInfoWidget();
144 	m_orgAffInfoWidget->setupUi( orgAffInfo );
145 	KPageWidgetItem *orgAffInfoItem = addPage( orgAffInfo, i18n("Org & Aff Info") );
146 	orgAffInfoItem->setHeader( i18n( "Organization & Affiliation Information" ) );
147     orgAffInfoItem->setIcon( QIcon::fromTheme(QStringLiteral("preferences-web-browser-identification")) );
148 
149 	m_emailModel = new QStandardItemModel();
150 	QStandardItem *modelItem = new QStandardItem( i18n( "Type" ) );
151 	m_emailModel->setHorizontalHeaderItem( 0, modelItem );
152 	modelItem = new QStandardItem( i18n( "Publish Email/Email" ) );
153 	m_emailModel->setHorizontalHeaderItem( 1, modelItem );
154 
155 	m_otherInfoWidget->emailTableView->setModel( m_emailModel );
156 	m_otherInfoWidget->emailTableView->horizontalHeader()->setStretchLastSection( true );
157 	m_otherInfoWidget->emailTableView->setSelectionMode( QAbstractItemView::SingleSelection );
158 
159 	connect(m_genInfoWidget->birthdayYearSpin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ICQUserInfoWidget::slotUpdateDay);
160 	connect(m_genInfoWidget->birthdayMonthSpin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ICQUserInfoWidget::slotUpdateDay);
161 
162 	connect(m_genInfoWidget->birthdayYearSpin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ICQUserInfoWidget::slotUpdateAge);
163 	connect(m_genInfoWidget->birthdayMonthSpin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ICQUserInfoWidget::slotUpdateAge);
164 	connect(m_genInfoWidget->birthdayDaySpin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ICQUserInfoWidget::slotUpdateAge);
165 
166 	connect(m_orgAffInfoWidget->org1CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotOrg1CategoryChanged);
167 	connect(m_orgAffInfoWidget->org2CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotOrg2CategoryChanged);
168 	connect(m_orgAffInfoWidget->org3CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotOrg3CategoryChanged);
169 
170 	connect(m_orgAffInfoWidget->aff1CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotAff1CategoryChanged);
171 	connect(m_orgAffInfoWidget->aff2CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotAff2CategoryChanged);
172 	connect(m_orgAffInfoWidget->aff3CategoryCombo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotAff3CategoryChanged);
173 
174 	connect(m_interestInfoWidget->topic1Combo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotInterestTopic1Changed);
175 	connect(m_interestInfoWidget->topic2Combo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotInterestTopic2Changed);
176 	connect(m_interestInfoWidget->topic3Combo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotInterestTopic3Changed);
177 	connect(m_interestInfoWidget->topic4Combo, static_cast<void (InfoComboBox::*)(int)>(&InfoComboBox::currentIndexChanged), this, &ICQUserInfoWidget::slotInterestTopic4Changed);
178 
179 	if ( m_ownInfo )
180 	{
181 		connect(m_otherInfoWidget->addEmailButton, &QPushButton::clicked, this, &ICQUserInfoWidget::slotAddEmail);
182 		connect(m_otherInfoWidget->removeEmailButton, &QPushButton::clicked, this, &ICQUserInfoWidget::slotRemoveEmail);
183 		connect(m_otherInfoWidget->upEmailButton, &QPushButton::clicked, this, &ICQUserInfoWidget::slotUpEmail);
184 		connect(m_otherInfoWidget->downEmailButton, &QPushButton::clicked, this, &ICQUserInfoWidget::slotDownEmail);
185 		connect( m_otherInfoWidget->emailTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
186 		         this, SLOT(slotEmailSelectionChanged(QItemSelection)) );
187 	}
188 
189 	m_genInfoWidget->aliasEdit->setReadOnly( m_ownInfo );
190 
191 	//ICQGeneralUserInfo
192 	m_genInfoWidget->nickNameEdit->setReadOnly( !m_ownInfo );
193 	m_genInfoWidget->firstNameEdit->setReadOnly( !m_ownInfo );
194 	m_genInfoWidget->lastNameEdit->setReadOnly( !m_ownInfo );
195 	m_homeInfoWidget->cityEdit->setReadOnly( !m_ownInfo );
196 	m_homeInfoWidget->stateEdit->setReadOnly( !m_ownInfo );
197 	m_homeInfoWidget->phoneEdit->setReadOnly( !m_ownInfo );
198 	m_homeInfoWidget->faxEdit->setReadOnly( !m_ownInfo );
199 	m_homeInfoWidget->addressEdit->setReadOnly( !m_ownInfo );
200 	m_homeInfoWidget->cellEdit->setReadOnly( !m_ownInfo );
201 	m_homeInfoWidget->zipEdit->setReadOnly( !m_ownInfo );
202 
203 	m_genInfoWidget->ageEdit->setReadOnly( !m_ownInfo );
204 	m_genInfoWidget->birthdayDaySpin->setReadOnly( !m_ownInfo );
205 	m_genInfoWidget->birthdayMonthSpin->setReadOnly( !m_ownInfo );
206 	m_genInfoWidget->birthdayYearSpin->setReadOnly( !m_ownInfo );
207 	m_homeInfoWidget->homepageEdit->setReadOnly( !m_ownInfo );
208 	m_homeInfoWidget->oCityEdit->setReadOnly( !m_ownInfo );
209 	m_homeInfoWidget->oStateEdit->setReadOnly( !m_ownInfo );
210 
211 	m_workInfoWidget->cityEdit->setReadOnly( !m_ownInfo );
212 	m_workInfoWidget->stateEdit->setReadOnly( !m_ownInfo );
213 	m_workInfoWidget->phoneEdit->setReadOnly( !m_ownInfo );
214 	m_workInfoWidget->faxEdit->setReadOnly( !m_ownInfo );
215 	m_workInfoWidget->addressEdit->setReadOnly( !m_ownInfo );
216 	m_workInfoWidget->zipEdit->setReadOnly( !m_ownInfo );
217 	m_workInfoWidget->companyEdit->setReadOnly( !m_ownInfo );
218 	m_workInfoWidget->departmentEdit->setReadOnly( !m_ownInfo );
219 	m_workInfoWidget->positionEdit->setReadOnly( !m_ownInfo );
220 	m_workInfoWidget->homepageEdit->setReadOnly( !m_ownInfo );
221 
222 	m_orgAffInfoWidget->org1KeywordEdit->setReadOnly( !m_ownInfo );
223 	m_orgAffInfoWidget->org2KeywordEdit->setReadOnly( !m_ownInfo );
224 	m_orgAffInfoWidget->org3KeywordEdit->setReadOnly( !m_ownInfo );
225 	m_orgAffInfoWidget->aff1KeywordEdit->setReadOnly( !m_ownInfo );
226 	m_orgAffInfoWidget->aff2KeywordEdit->setReadOnly( !m_ownInfo );
227 	m_orgAffInfoWidget->aff3KeywordEdit->setReadOnly( !m_ownInfo );
228 
229 	m_interestInfoWidget->desc1->setReadOnly( !m_ownInfo );
230 	m_interestInfoWidget->desc2->setReadOnly( !m_ownInfo );
231 	m_interestInfoWidget->desc3->setReadOnly( !m_ownInfo );
232 	m_interestInfoWidget->desc4->setReadOnly( !m_ownInfo );
233 
234 	m_otherInfoWidget->notesEdit->setReadOnly( !m_ownInfo );
235 
236 	m_otherInfoWidget->addEmailButton->setEnabled( m_ownInfo );
237 	m_otherInfoWidget->removeEmailButton->setEnabled( false );
238 	m_otherInfoWidget->upEmailButton->setEnabled( false );
239 	m_otherInfoWidget->downEmailButton->setEnabled( false );
240 
241 	if ( !m_ownInfo )
242 	{
243 		m_homeInfoWidget->countryCombo->setReadOnly( true );
244 		m_homeInfoWidget->oCountryCombo->setReadOnly( true );
245 		m_workInfoWidget->countryCombo->setReadOnly( true );
246 		m_genInfoWidget->language1Combo->setReadOnly( true );
247 		m_genInfoWidget->language2Combo->setReadOnly( true );
248 		m_genInfoWidget->language3Combo->setReadOnly( true );
249 		m_genInfoWidget->genderCombo->setReadOnly( true );
250 		m_genInfoWidget->maritalCombo->setReadOnly( true );
251 		m_workInfoWidget->occupationCombo->setReadOnly( true );
252 		m_orgAffInfoWidget->org1CategoryCombo->setReadOnly( true );
253 		m_orgAffInfoWidget->org2CategoryCombo->setReadOnly( true );
254 		m_orgAffInfoWidget->org3CategoryCombo->setReadOnly( true );
255 		m_orgAffInfoWidget->aff1CategoryCombo->setReadOnly( true );
256 		m_orgAffInfoWidget->aff2CategoryCombo->setReadOnly( true );
257 		m_orgAffInfoWidget->aff3CategoryCombo->setReadOnly( true );
258 		m_interestInfoWidget->topic1Combo->setReadOnly( true );
259 		m_interestInfoWidget->topic2Combo->setReadOnly( true );
260 		m_interestInfoWidget->topic3Combo->setReadOnly( true );
261 		m_interestInfoWidget->topic4Combo->setReadOnly( true );
262 		m_genInfoWidget->timezoneCombo->setReadOnly( true );
263 	}
264 
265 	ICQProtocol* icqProtocol = static_cast<ICQProtocol*>( m_account->protocol() );
266 
267 	//Countries
268 	QMap<QString, int> sortedMap( reverseMap( icqProtocol->countries() ) );
269 	QMapIterator<QString, int> it( sortedMap );
270 
271 	while ( it.hasNext() )
272 	{
273 		it.next();
274 		m_homeInfoWidget->countryCombo->addItem( it.key(), it.value() );
275 		m_homeInfoWidget->oCountryCombo->addItem( it.key(), it.value() );
276 		m_workInfoWidget->countryCombo->addItem( it.key(), it.value() );
277 	}
278 
279 	//Languages
280 	sortedMap = reverseMap( icqProtocol->languages() );
281 	it = sortedMap;
282 	while ( it.hasNext() )
283 	{
284 		it.next();
285 		m_genInfoWidget->language1Combo->addItem( it.key(), it.value() );
286 		m_genInfoWidget->language2Combo->addItem( it.key(), it.value() );
287 		m_genInfoWidget->language3Combo->addItem( it.key(), it.value() );
288 	}
289 
290 	//Genders
291 	sortedMap = reverseMap( icqProtocol->genders() );
292 	it = sortedMap;
293 	while ( it.hasNext() )
294 	{
295 		it.next();
296 		m_genInfoWidget->genderCombo->addItem( it.key(), it.value() );
297 	}
298 
299 	//Maritals
300 	sortedMap = reverseMap( icqProtocol->maritals() );
301 	it = sortedMap;
302 	while ( it.hasNext() )
303 	{
304 		it.next();
305 		m_genInfoWidget->maritalCombo->addItem( it.key(), it.value() );
306 	}
307 
308 	//Occupations
309 	sortedMap = reverseMap( icqProtocol->occupations() );
310 	it = sortedMap;
311 	while ( it.hasNext() )
312 	{
313 		it.next();
314 		m_workInfoWidget->occupationCombo->addItem( it.key(), it.value() );
315 	}
316 
317 	//Organizations
318 	sortedMap = reverseMap( icqProtocol->organizations() );
319 	it = sortedMap;
320 	while ( it.hasNext() )
321 	{
322 		it.next();
323 		m_orgAffInfoWidget->org1CategoryCombo->addItem( it.key(), it.value() );
324 		m_orgAffInfoWidget->org2CategoryCombo->addItem( it.key(), it.value() );
325 		m_orgAffInfoWidget->org3CategoryCombo->addItem( it.key(), it.value() );
326 	}
327 
328 	//Affiliations
329 	sortedMap = reverseMap( icqProtocol->affiliations() );
330 	it = sortedMap;
331 	while ( it.hasNext() )
332 	{
333 		it.next();
334 		m_orgAffInfoWidget->aff1CategoryCombo->addItem( it.key(), it.value() );
335 		m_orgAffInfoWidget->aff2CategoryCombo->addItem( it.key(), it.value() );
336 		m_orgAffInfoWidget->aff3CategoryCombo->addItem( it.key(), it.value() );
337 	}
338 
339 	//Interests
340 	sortedMap = reverseMap( icqProtocol->interests() );
341 	it = sortedMap;
342 	while ( it.hasNext() )
343 	{
344 		it.next();
345 		m_interestInfoWidget->topic1Combo->addItem( it.key(), it.value() );
346 		m_interestInfoWidget->topic2Combo->addItem( it.key(), it.value() );
347 		m_interestInfoWidget->topic3Combo->addItem( it.key(), it.value() );
348 		m_interestInfoWidget->topic4Combo->addItem( it.key(), it.value() );
349 	}
350 
351 	//Timezone
352 	QString timezone;
353 	for ( int zone = 24; zone >= -24; zone-- )
354 	{
355 		timezone = QString( "GMT %1%2:%3" )
356 			.arg( ( zone > 0 ) ? "-" : "" )
357 			.arg( qAbs( zone ) / 2, 2, 10, QLatin1Char('0') )
358 			.arg( ( qAbs( zone ) % 2 ) * 30, 2, 10, QLatin1Char('0')  );
359 
360 		m_genInfoWidget->timezoneCombo->addItem( timezone, zone );
361 	}
362 }
363 
~ICQUserInfoWidget()364 ICQUserInfoWidget::~ ICQUserInfoWidget()
365 {
366 	delete m_genInfoWidget;
367 	delete m_homeInfoWidget;
368 	delete m_workInfoWidget;
369 	delete m_otherInfoWidget;
370 	delete m_interestInfoWidget;
371 	delete m_orgAffInfoWidget;
372 	delete m_emailModel;
373 }
374 
getInfoData() const375 QList<ICQInfoBase*> ICQUserInfoWidget::getInfoData() const
376 {
377 	QList<ICQInfoBase*> infoList;
378 
379 	if ( !m_ownInfo )
380 		return infoList;
381 
382 	infoList.append( storeBasicInfo() );
383 	infoList.append( storeMoreInfo() );
384 	infoList.append( storeWorkInfo() );
385 	infoList.append( storeOrgAffInfo() );
386 	infoList.append( storeInterestInfo() );
387 	infoList.append( storeNotesInfo() );
388 	infoList.append( storeEmailInfo() );
389 
390 	return infoList;
391 }
392 
getAlias() const393 QString ICQUserInfoWidget::getAlias() const
394 {
395 	return m_genInfoWidget->aliasEdit->text();
396 }
397 
fillBasicInfo(const ICQGeneralUserInfo & ui)398 void ICQUserInfoWidget::fillBasicInfo( const ICQGeneralUserInfo& ui )
399 {
400 	QTextCodec* codec = getTextCodec();
401 
402 	if ( m_ownInfo )
403 		m_generalUserInfo = ui;
404 
405 	m_genInfoWidget->nickNameEdit->setText( codec->toUnicode( ui.nickName.get() ) );
406 	m_genInfoWidget->firstNameEdit->setText( codec->toUnicode( ui.firstName.get() ) );
407 	m_genInfoWidget->lastNameEdit->setText( codec->toUnicode( ui.lastName.get() ) );
408 	m_homeInfoWidget->cityEdit->setText( codec->toUnicode( ui.city.get() ) );
409 	m_homeInfoWidget->stateEdit->setText( codec->toUnicode( ui.state.get() ) );
410 	m_homeInfoWidget->phoneEdit->setText( codec->toUnicode( ui.phoneNumber.get() ) );
411 	m_homeInfoWidget->faxEdit->setText( codec->toUnicode( ui.faxNumber.get() ) );
412 	m_homeInfoWidget->addressEdit->setText( codec->toUnicode( ui.address.get() ) );
413 	m_homeInfoWidget->cellEdit->setText( codec->toUnicode( ui.cellNumber.get() ) );
414 	m_homeInfoWidget->zipEdit->setText(  codec->toUnicode( ui.zip.get() ) );
415 
416 	m_homeInfoWidget->countryCombo->setCurrentIndex( m_homeInfoWidget->countryCombo->findData( ui.country.get() ) );
417 	m_genInfoWidget->timezoneCombo->setCurrentIndex( m_genInfoWidget->timezoneCombo->findData( ui.timezone.get() ) );
418 
419 	if ( !ui.email.get().isEmpty() )
420 	{
421 		QList<QStandardItem *> items;
422 		QStandardItem *modelItem;
423 
424 		modelItem = new QStandardItem( i18nc("Primary email address", "Primary") );
425 		modelItem->setEditable( false );
426 		modelItem->setSelectable( false );
427 		items.append( modelItem );
428 
429 		modelItem = new QStandardItem( codec->toUnicode( ui.email.get() ) );
430 		modelItem->setEditable( m_ownInfo );
431 		modelItem->setCheckable( true );
432 		modelItem->setCheckState( ( ui.publishEmail.get() ) ? Qt::Checked : Qt::Unchecked );
433 		items.append( modelItem );
434 
435 		m_emailModel->insertRow( 0, items );
436 	}
437 }
438 
fillWorkInfo(const ICQWorkUserInfo & ui)439 void ICQUserInfoWidget::fillWorkInfo( const ICQWorkUserInfo& ui )
440 {
441 	QTextCodec* codec = getTextCodec();
442 
443 	if ( m_ownInfo )
444 		m_workUserInfo = ui;
445 
446 	m_workInfoWidget->cityEdit->setText( codec->toUnicode( ui.city.get() ) );
447 	m_workInfoWidget->stateEdit->setText( codec->toUnicode( ui.state.get() ) );
448 	m_workInfoWidget->phoneEdit->setText( codec->toUnicode( ui.phone.get() ) );
449 	m_workInfoWidget->faxEdit->setText( codec->toUnicode( ui.fax.get() ) );
450 	m_workInfoWidget->addressEdit->setText( codec->toUnicode( ui.address.get() ) );
451 	m_workInfoWidget->zipEdit->setText( codec->toUnicode( ui.zip.get() ) );
452 	m_workInfoWidget->companyEdit->setText( codec->toUnicode( ui.company.get() ) );
453 	m_workInfoWidget->departmentEdit->setText( codec->toUnicode( ui.department.get() ) );
454 	m_workInfoWidget->positionEdit->setText( codec->toUnicode( ui.position.get() ) );
455 	m_workInfoWidget->homepageEdit->setText( codec->toUnicode( ui.homepage.get() ) );
456 
457 	m_workInfoWidget->countryCombo->setCurrentIndex( m_workInfoWidget->countryCombo->findData( ui.country.get() ) );
458 	m_workInfoWidget->occupationCombo->setCurrentIndex( m_workInfoWidget->occupationCombo->findData( ui.occupation.get() ) );
459 }
460 
fillEmailInfo(const ICQEmailInfo & info)461 void ICQUserInfoWidget::fillEmailInfo( const ICQEmailInfo& info )
462 {
463 	QTextCodec* codec = getTextCodec();
464 
465 	if ( m_ownInfo )
466 		m_emailInfo = info;
467 
468 	int size = info.emailList.get().size();
469 	for ( int i = 0; i < size; i++ )
470 	{
471 		int row = m_emailModel->rowCount();
472 
473 		ICQEmailInfo::EmailItem item = info.emailList.get().at(i);
474 		QStandardItem *modelItem = new QStandardItem( i18nc("Other email address", "More")  );
475 		modelItem->setEditable( false );
476 		modelItem->setSelectable( false );
477 		m_emailModel->setItem( row, 0, modelItem );
478 		modelItem = new QStandardItem( codec->toUnicode( item.email ) );
479 		modelItem->setEditable( m_ownInfo );
480 		modelItem->setCheckable( true );
481 		modelItem->setCheckState( ( item.publish ) ? Qt::Checked : Qt::Unchecked );
482 		m_emailModel->setItem( row, 1, modelItem );
483 	}
484 }
485 
fillNotesInfo(const ICQNotesInfo & info)486 void ICQUserInfoWidget::fillNotesInfo( const ICQNotesInfo& info )
487 {
488 	QTextCodec* codec = getTextCodec();
489 
490 	if ( m_ownInfo )
491 		m_notesInfo = info;
492 
493 	m_otherInfoWidget->notesEdit->setPlainText( codec->toUnicode( info.notes.get() ) );
494 }
495 
fillInterestInfo(const ICQInterestInfo & info)496 void ICQUserInfoWidget::fillInterestInfo( const ICQInterestInfo& info )
497 {
498 	QTextCodec* codec = getTextCodec();
499 
500 	if ( m_ownInfo )
501 		m_interestInfo = info;
502 
503 	int index = m_interestInfoWidget->topic1Combo->findData( info.topics[0].get() );
504 	m_interestInfoWidget->topic1Combo->setCurrentIndex( index );
505 	m_interestInfoWidget->desc1->setText( codec->toUnicode( info.descriptions[0].get() ) );
506 
507 	index = m_interestInfoWidget->topic2Combo->findData( info.topics[1].get() );
508 	m_interestInfoWidget->topic2Combo->setCurrentIndex( index );
509 	m_interestInfoWidget->desc2->setText( codec->toUnicode( info.descriptions[1].get() ) );
510 
511 	index = m_interestInfoWidget->topic3Combo->findData( info.topics[2].get() );
512 	m_interestInfoWidget->topic3Combo->setCurrentIndex( index );
513 	m_interestInfoWidget->desc3->setText( codec->toUnicode( info.descriptions[2].get() ) );
514 
515 	index = m_interestInfoWidget->topic4Combo->findData( info.topics[3].get() );
516 	m_interestInfoWidget->topic4Combo->setCurrentIndex( index );
517 	m_interestInfoWidget->desc4->setText( codec->toUnicode( info.descriptions[3].get() ) );
518 }
519 
fillOrgAffInfo(const ICQOrgAffInfo & info)520 void ICQUserInfoWidget::fillOrgAffInfo( const ICQOrgAffInfo& info )
521 {
522 	QTextCodec* codec = getTextCodec();
523 
524 	if ( m_ownInfo )
525 		m_orgAffUserInfo = info;
526 
527 	m_orgAffInfoWidget->org1KeywordEdit->setText( codec->toUnicode( info.org1Keyword.get() ) );
528 	m_orgAffInfoWidget->org2KeywordEdit->setText( codec->toUnicode( info.org2Keyword.get() ) );
529 	m_orgAffInfoWidget->org3KeywordEdit->setText( codec->toUnicode( info.org3Keyword.get() ) );
530 
531 	int index = m_orgAffInfoWidget->org1CategoryCombo->findData( info.org1Category.get() );
532 	m_orgAffInfoWidget->org1CategoryCombo->setCurrentIndex( index );
533 
534 	index = m_orgAffInfoWidget->org2CategoryCombo->findData( info.org2Category.get() );
535 	m_orgAffInfoWidget->org2CategoryCombo->setCurrentIndex( index );
536 
537 	index = m_orgAffInfoWidget->org3CategoryCombo->findData( info.org3Category.get() );
538 	m_orgAffInfoWidget->org3CategoryCombo->setCurrentIndex( index );
539 
540 	m_orgAffInfoWidget->aff1KeywordEdit->setText( codec->toUnicode( info.pastAff1Keyword.get() ) );
541 	m_orgAffInfoWidget->aff2KeywordEdit->setText( codec->toUnicode( info.pastAff2Keyword.get() ) );
542 	m_orgAffInfoWidget->aff3KeywordEdit->setText( codec->toUnicode( info.pastAff3Keyword.get() ) );
543 
544 	index = m_orgAffInfoWidget->aff1CategoryCombo->findData( info.pastAff1Category.get() );
545 	m_orgAffInfoWidget->aff1CategoryCombo->setCurrentIndex( index );
546 
547 	index = m_orgAffInfoWidget->aff2CategoryCombo->findData( info.pastAff2Category.get() );
548 	m_orgAffInfoWidget->aff2CategoryCombo->setCurrentIndex( index );
549 
550 	index = m_orgAffInfoWidget->aff3CategoryCombo->findData( info.pastAff3Category.get() );
551 	m_orgAffInfoWidget->aff3CategoryCombo->setCurrentIndex( index );
552 }
553 
fillMoreInfo(const ICQMoreUserInfo & ui)554 void ICQUserInfoWidget::fillMoreInfo( const ICQMoreUserInfo& ui )
555 {
556 	QTextCodec* codec = getTextCodec();
557 
558 	if ( m_ownInfo )
559 		m_moreUserInfo = ui;
560 
561 	m_genInfoWidget->ageEdit->setText( QString::number( ui.age.get() ) );
562 	m_genInfoWidget->birthdayYearSpin->setValue( ui.birthdayYear.get() );
563 	m_genInfoWidget->birthdayMonthSpin->setValue( ui.birthdayMonth.get() );
564 	m_genInfoWidget->birthdayDaySpin->setValue( ui.birthdayDay.get() );
565 	m_genInfoWidget->genderCombo->setCurrentIndex( m_genInfoWidget->genderCombo->findData( ui.gender.get() ) );
566 	m_homeInfoWidget->homepageEdit->setText( codec->toUnicode( ui.homepage.get() ) );
567 	m_genInfoWidget->maritalCombo->setCurrentIndex( m_genInfoWidget->maritalCombo->findData( ui.marital.get() ) );
568 	m_homeInfoWidget->oCityEdit->setText( codec->toUnicode( ui.ocity.get() ) );
569 	m_homeInfoWidget->oStateEdit->setText( codec->toUnicode( ui.ostate.get() ) );
570 	m_homeInfoWidget->oCountryCombo->setCurrentIndex( m_homeInfoWidget->oCountryCombo->findData( ui.ocountry.get() ) );
571 	m_genInfoWidget->language1Combo->setCurrentIndex( m_genInfoWidget->language1Combo->findData( ui.lang1.get() ) );
572 	m_genInfoWidget->language2Combo->setCurrentIndex( m_genInfoWidget->language2Combo->findData( ui.lang2.get() ) );
573 	m_genInfoWidget->language3Combo->setCurrentIndex( m_genInfoWidget->language3Combo->findData( ui.lang3.get() ) );
574 	m_otherInfoWidget->sendInfoCheck->setChecked( ui.sendInfo.get() );
575 }
576 
receivedLongInfo(const QString & contact)577 void ICQUserInfoWidget::receivedLongInfo( const QString& contact )
578 {
579 	if ( Oscar::normalize( contact ) != Oscar::normalize( m_contactId ) )
580 		return;
581 
582 	kDebug(OSCAR_ICQ_DEBUG) << "received long info from engine";
583 	fillBasicInfo( m_account->engine()->getGeneralInfo( contact ) );
584 	fillWorkInfo( m_account->engine()->getWorkInfo( contact ) );
585 	fillEmailInfo( m_account->engine()->getEmailInfo( contact ) );
586 	fillNotesInfo( m_account->engine()->getNotesInfo( contact ) );
587 	fillMoreInfo( m_account->engine()->getMoreInfo( contact ) );
588 	fillInterestInfo( m_account->engine()->getInterestInfo( contact ) );
589 	fillOrgAffInfo( m_account->engine()->getOrgAffInfo( contact ) );
590 }
591 
slotUpdateDay()592 void ICQUserInfoWidget::slotUpdateDay()
593 {
594 	int year = m_genInfoWidget->birthdayYearSpin->value();
595 	int month = m_genInfoWidget->birthdayMonthSpin->value();
596 	QDate date( year, month, 1 );
597 
598 	if ( date.isValid() )
599 		m_genInfoWidget->birthdayDaySpin->setMaximum( date.daysInMonth() );
600 	else
601 		m_genInfoWidget->birthdayDaySpin->setMaximum( 31 );
602 }
603 
slotUpdateAge()604 void ICQUserInfoWidget::slotUpdateAge()
605 {
606 	QDate now = QDate::currentDate();
607 	int year = m_genInfoWidget->birthdayYearSpin->value();
608 	int month = m_genInfoWidget->birthdayMonthSpin->value();
609 	int day = m_genInfoWidget->birthdayDaySpin->value();
610 
611 	int age = 0;
612 
613 	if ( year > 0 )
614 	{
615 		age = now.year() - year;
616 		if ( month > now.month() )
617 		{
618 			age--;
619 		}
620 		else if ( month == now.month() )
621 		{
622 			if ( day > now.day() )
623 			{
624 				age--;
625 			}
626 		}
627 	}
628 
629 	m_genInfoWidget->ageEdit->setText( QString::number( age ) );
630 }
631 
slotOrg1CategoryChanged(int index)632 void ICQUserInfoWidget::slotOrg1CategoryChanged( int index )
633 {
634 	bool enable = !( m_orgAffInfoWidget->org1CategoryCombo->itemData( index ).toInt() == 0 );
635 	m_orgAffInfoWidget->org1KeywordEdit->setEnabled( enable );
636 }
637 
slotOrg2CategoryChanged(int index)638 void ICQUserInfoWidget::slotOrg2CategoryChanged( int index )
639 {
640 	bool enable = !( m_orgAffInfoWidget->org2CategoryCombo->itemData( index ).toInt() == 0 );
641 	m_orgAffInfoWidget->org2KeywordEdit->setEnabled( enable );
642 }
643 
slotOrg3CategoryChanged(int index)644 void ICQUserInfoWidget::slotOrg3CategoryChanged( int index )
645 {
646 	bool enable = !( m_orgAffInfoWidget->org3CategoryCombo->itemData( index ).toInt() == 0 );
647 	m_orgAffInfoWidget->org3KeywordEdit->setEnabled( enable );
648 }
649 
slotAff1CategoryChanged(int index)650 void ICQUserInfoWidget::slotAff1CategoryChanged( int index )
651 {
652 	bool enable = !( m_orgAffInfoWidget->aff1CategoryCombo->itemData( index ).toInt() == 0 );
653 	m_orgAffInfoWidget->aff1KeywordEdit->setEnabled( enable );
654 }
655 
slotAff2CategoryChanged(int index)656 void ICQUserInfoWidget::slotAff2CategoryChanged( int index )
657 {
658 	bool enable = !( m_orgAffInfoWidget->aff2CategoryCombo->itemData( index ).toInt() == 0 );
659 	m_orgAffInfoWidget->aff2KeywordEdit->setEnabled( enable );
660 }
661 
slotAff3CategoryChanged(int index)662 void ICQUserInfoWidget::slotAff3CategoryChanged( int index )
663 {
664 	bool enable = !( m_orgAffInfoWidget->aff3CategoryCombo->itemData( index ).toInt() == 0 );
665 	m_orgAffInfoWidget->aff3KeywordEdit->setEnabled( enable );
666 }
667 
slotInterestTopic1Changed(int index)668 void ICQUserInfoWidget::slotInterestTopic1Changed( int index )
669 {
670 	bool enable = !( m_interestInfoWidget->topic1Combo->itemData( index ).toInt() == 0 );
671 	m_interestInfoWidget->desc1->setEnabled( enable );
672 }
673 
slotInterestTopic2Changed(int index)674 void ICQUserInfoWidget::slotInterestTopic2Changed( int index )
675 {
676 	bool enable = !( m_interestInfoWidget->topic2Combo->itemData( index ).toInt() == 0 );
677 	m_interestInfoWidget->desc2->setEnabled( enable );
678 }
679 
slotInterestTopic3Changed(int index)680 void ICQUserInfoWidget::slotInterestTopic3Changed( int index )
681 {
682 	bool enable = !( m_interestInfoWidget->topic3Combo->itemData( index ).toInt() == 0 );
683 	m_interestInfoWidget->desc3->setEnabled( enable );
684 }
685 
slotInterestTopic4Changed(int index)686 void ICQUserInfoWidget::slotInterestTopic4Changed( int index )
687 {
688 	bool enable = !( m_interestInfoWidget->topic4Combo->itemData( index ).toInt() == 0 );
689 	m_interestInfoWidget->desc4->setEnabled( enable );
690 }
691 
slotAddEmail()692 void ICQUserInfoWidget::slotAddEmail()
693 {
694 	QItemSelectionModel* selectionModel = m_otherInfoWidget->emailTableView->selectionModel();
695 	QModelIndexList indexes = selectionModel->selectedIndexes();
696 	int row = ( indexes.count() > 0 ) ? indexes.at( 0 ).row() + 1 : m_emailModel->rowCount();
697 
698 	QList<QStandardItem *> items;
699 	QStandardItem *modelItem;
700 
701 	modelItem = new QStandardItem( ( row == 0 ) ? i18nc("Primary email address", "Primary") : i18nc("Other email address", "More") );
702 	modelItem->setEditable( false );
703 	modelItem->setSelectable( false );
704 	items.append( modelItem );
705 
706 	modelItem = new QStandardItem();
707 	modelItem->setEditable( m_ownInfo );
708 	modelItem->setCheckable( true );
709 	modelItem->setCheckState( Qt::Unchecked );
710 	items.append( modelItem );
711 
712 	m_emailModel->insertRow( row, items );
713 	QModelIndex idx = m_emailModel->index( row, 1 );
714 	selectionModel->select( idx, QItemSelectionModel::SelectCurrent );
715 
716 	if ( row == 0 && m_emailModel->rowCount() > 1 )
717 		m_emailModel->item( 1, 0 )->setText( i18nc("Other email address", "More") );
718 }
719 
slotRemoveEmail()720 void ICQUserInfoWidget::slotRemoveEmail()
721 {
722 	QItemSelectionModel* selectionModel = m_otherInfoWidget->emailTableView->selectionModel();
723 	QModelIndexList indexes = selectionModel->selectedIndexes();
724 
725 	if ( indexes.count() > 0 )
726 	{
727 		int row = indexes.at( 0 ).row();
728 		m_emailModel->removeRow( row );
729 
730 		if ( row == 0 && m_emailModel->rowCount() > 0 )
731 			m_emailModel->item( 0, 0 )->setText( i18nc("Primary email address", "Primary") );
732 
733 		QModelIndex idx = m_emailModel->index( ( row > 0 ) ? row - 1 : row , 1 );
734 		selectionModel->select( idx, QItemSelectionModel::SelectCurrent );
735 	}
736 }
737 
slotUpEmail()738 void ICQUserInfoWidget::slotUpEmail()
739 {
740 	QItemSelectionModel* selectionModel = m_otherInfoWidget->emailTableView->selectionModel();
741 	QModelIndexList indexes = selectionModel->selectedIndexes();
742 
743 	if ( indexes.count() > 0 )
744 	{
745 		int row = indexes.at( 0 ).row();
746 		if ( row > 0 )
747 		{
748 			swapEmails( row-1, row );
749 
750 			QModelIndex idx = m_emailModel->index( row - 1, 1 );
751 			selectionModel->select( idx, QItemSelectionModel::SelectCurrent );
752 		}
753 	}
754 }
755 
slotDownEmail()756 void ICQUserInfoWidget::slotDownEmail()
757 {
758 	QItemSelectionModel* selectionModel = m_otherInfoWidget->emailTableView->selectionModel();
759 	QModelIndexList indexes = selectionModel->selectedIndexes();
760 
761 	if ( indexes.count() > 0 )
762 	{
763 		int row = indexes.at( 0 ).row();
764 		if ( row < m_emailModel->rowCount() - 1 )
765 		{
766 			swapEmails( row, row + 1 );
767 
768 			QModelIndex idx = m_emailModel->index( row + 1, 1 );
769 			selectionModel->select( idx, QItemSelectionModel::SelectCurrent );
770 		}
771 	}
772 }
773 
slotEmailSelectionChanged(const QItemSelection & selected)774 void ICQUserInfoWidget::slotEmailSelectionChanged( const QItemSelection& selected )
775 {
776 	QModelIndexList indexes = selected.indexes();
777 	if ( indexes.count() > 0 )
778 	{
779 		int row = indexes.at( 0 ).row();
780 		m_otherInfoWidget->upEmailButton->setEnabled( (row > 0) );
781 		m_otherInfoWidget->downEmailButton->setEnabled( (row < m_emailModel->rowCount()-1 ) );
782 		m_otherInfoWidget->removeEmailButton->setEnabled( true );
783 	}
784 	else
785 	{
786 		m_otherInfoWidget->removeEmailButton->setEnabled( false );
787 		m_otherInfoWidget->upEmailButton->setEnabled( false );
788 		m_otherInfoWidget->downEmailButton->setEnabled( false );
789 	}
790 }
791 
swapEmails(int r1,int r2)792 void ICQUserInfoWidget::swapEmails( int r1, int r2 )
793 {
794 	if ( r1 > r2 )
795 		qSwap( r1, r2 );
796 
797 	QList<QStandardItem *> rowItems1 = m_emailModel->takeRow( r1 );
798 	QList<QStandardItem *> rowItems2 = m_emailModel->takeRow( r2-1 );
799 
800 	rowItems1.at( 0 )->setText( ( r2 == 0 ) ? i18nc("Primary email address", "Primary") : i18nc("Other email address", "More") );
801 	rowItems2.at( 0 )->setText( ( r1 == 0 ) ? i18nc("Primary email address", "Primary") : i18nc("Other email address", "More") );
802 	m_emailModel->insertRow( r1, rowItems2 );
803 	m_emailModel->insertRow( r2, rowItems1 );
804 }
805 
storeBasicInfo() const806 ICQGeneralUserInfo* ICQUserInfoWidget::storeBasicInfo() const
807 {
808 	QTextCodec* codec = getTextCodec();
809 	ICQGeneralUserInfo* info = new ICQGeneralUserInfo( m_generalUserInfo );
810 
811 	//Email is stored in storeEmailInfo(), because if we change primary email we have to update all emails.
812 	info->nickName.set( codec->fromUnicode( m_genInfoWidget->nickNameEdit->text() ) );
813 	info->firstName.set( codec->fromUnicode( m_genInfoWidget->firstNameEdit->text() ) );
814 	info->lastName.set( codec->fromUnicode( m_genInfoWidget->lastNameEdit->text() ) );
815 	info->city.set( codec->fromUnicode( m_homeInfoWidget->cityEdit->text() ) );
816 	info->state.set( codec->fromUnicode( m_homeInfoWidget->stateEdit->text() ) );
817 	info->phoneNumber.set( codec->fromUnicode( m_homeInfoWidget->phoneEdit->text() ) );
818 	info->faxNumber.set( codec->fromUnicode( m_homeInfoWidget->faxEdit->text() ) );
819 	info->address.set( codec->fromUnicode( m_homeInfoWidget->addressEdit->text() ) );
820 	info->cellNumber.set( codec->fromUnicode( m_homeInfoWidget->cellEdit->text() ) );
821 	info->zip.set( codec->fromUnicode( m_homeInfoWidget->zipEdit->text() ) );
822 
823 	int index = m_homeInfoWidget->countryCombo->currentIndex();
824 	info->country.set( m_homeInfoWidget->countryCombo->itemData( index ).toInt() );
825 
826 	index = m_genInfoWidget->timezoneCombo->currentIndex();
827 	info->timezone.set( m_genInfoWidget->timezoneCombo->itemData( index ).toInt() );
828 
829 	return info;
830 }
831 
storeMoreInfo() const832 ICQMoreUserInfo* ICQUserInfoWidget::storeMoreInfo() const
833 {
834 	QTextCodec* codec = getTextCodec();
835 	ICQMoreUserInfo* info = new ICQMoreUserInfo( m_moreUserInfo );
836 
837 	info->age.set( m_genInfoWidget->ageEdit->text().toInt() );
838 	info->birthdayYear.set( m_genInfoWidget->birthdayYearSpin->value() );
839 	info->birthdayMonth.set( m_genInfoWidget->birthdayMonthSpin->value() );
840 	info->birthdayDay.set( m_genInfoWidget->birthdayDaySpin->value() );
841 
842 	int index = m_genInfoWidget->genderCombo->currentIndex();
843 	info->gender.set( m_genInfoWidget->genderCombo->itemData( index ).toInt() );
844 
845 	info->homepage.set( codec->fromUnicode( m_homeInfoWidget->homepageEdit->text() ) );
846 
847 	index = m_genInfoWidget->maritalCombo->currentIndex();
848 	info->marital.set( m_genInfoWidget->maritalCombo->itemData( index ).toInt() );
849 
850 	info->ocity.set( codec->fromUnicode( m_homeInfoWidget->oCityEdit->text() ) );
851 	info->ostate.set( codec->fromUnicode( m_homeInfoWidget->oStateEdit->text() ) );
852 
853 	index = m_homeInfoWidget->oCountryCombo->currentIndex();
854 	info->ocountry.set( m_homeInfoWidget->oCountryCombo->itemData( index ).toInt() );
855 
856 	index = m_genInfoWidget->language1Combo->currentIndex();
857 	info->lang1.set( m_genInfoWidget->language1Combo->itemData( index ).toInt() );
858 
859 	index = m_genInfoWidget->language2Combo->currentIndex();
860 	info->lang2.set( m_genInfoWidget->language2Combo->itemData( index ).toInt() );
861 
862 	index = m_genInfoWidget->language3Combo->currentIndex();
863 	info->lang3.set( m_genInfoWidget->language3Combo->itemData( index ).toInt() );
864 
865 	info->sendInfo.set( m_otherInfoWidget->sendInfoCheck->isChecked() );
866 
867 	return info;
868 }
869 
storeWorkInfo() const870 ICQWorkUserInfo* ICQUserInfoWidget::storeWorkInfo() const
871 {
872 	QTextCodec* codec = getTextCodec();
873 	ICQWorkUserInfo* info = new ICQWorkUserInfo( m_workUserInfo );
874 
875 	info->city.set( codec->fromUnicode( m_workInfoWidget->cityEdit->text() ) );
876 	info->state.set( codec->fromUnicode( m_workInfoWidget->stateEdit->text() ) );
877 	info->phone.set( codec->fromUnicode( m_workInfoWidget->phoneEdit->text() ) );
878 	info->fax.set( codec->fromUnicode( m_workInfoWidget->faxEdit->text() ) );
879 	info->address.set( codec->fromUnicode( m_workInfoWidget->addressEdit->text() ) );
880 	info->zip.set( codec->fromUnicode( m_workInfoWidget->zipEdit->text() ) );
881 	info->company.set( codec->fromUnicode( m_workInfoWidget->companyEdit->text() ) );
882 	info->department.set( codec->fromUnicode( m_workInfoWidget->departmentEdit->text() ) );
883 	info->position.set( codec->fromUnicode( m_workInfoWidget->positionEdit->text() ) );
884 	info->homepage.set( codec->fromUnicode( m_workInfoWidget->homepageEdit->text() ) );
885 
886 	int index = m_workInfoWidget->countryCombo->currentIndex();
887 	info->country.set( m_workInfoWidget->countryCombo->itemData( index ).toInt() );
888 
889 	index = m_workInfoWidget->occupationCombo->currentIndex();
890 	info->occupation.set( m_workInfoWidget->occupationCombo->itemData( index ).toInt() );
891 
892 	return info;
893 }
894 
storeOrgAffInfo() const895 ICQOrgAffInfo* ICQUserInfoWidget::storeOrgAffInfo() const
896 {
897 	QTextCodec* codec = getTextCodec();
898 	ICQOrgAffInfo* info = new ICQOrgAffInfo( m_orgAffUserInfo );
899 
900 	info->org1Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->org1KeywordEdit->text() ) );
901 	info->org2Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->org2KeywordEdit->text() ) );
902 	info->org3Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->org3KeywordEdit->text() ) );
903 
904 	int index = m_orgAffInfoWidget->org1CategoryCombo->currentIndex();
905 	info->org1Category.set( m_orgAffInfoWidget->org1CategoryCombo->itemData( index ).toInt() );
906 
907 	index = m_orgAffInfoWidget->org2CategoryCombo->currentIndex();
908 	info->org2Category.set( m_orgAffInfoWidget->org2CategoryCombo->itemData( index ).toInt() );
909 
910 	index = m_orgAffInfoWidget->org3CategoryCombo->currentIndex();
911 	info->org3Category.set( m_orgAffInfoWidget->org3CategoryCombo->itemData( index ).toInt() );
912 
913 	info->pastAff1Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->aff1KeywordEdit->text() ) );
914 	info->pastAff2Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->aff2KeywordEdit->text() ) );
915 	info->pastAff3Keyword.set( codec->fromUnicode( m_orgAffInfoWidget->aff3KeywordEdit->text() ) );
916 
917 	index = m_orgAffInfoWidget->aff1CategoryCombo->currentIndex();
918 	info->pastAff1Category.set( m_orgAffInfoWidget->aff1CategoryCombo->itemData( index ).toInt() );
919 
920 	index = m_orgAffInfoWidget->aff2CategoryCombo->currentIndex();
921 	info->pastAff2Category.set( m_orgAffInfoWidget->aff2CategoryCombo->itemData( index ).toInt() );
922 
923 	index = m_orgAffInfoWidget->aff3CategoryCombo->currentIndex();
924 	info->pastAff3Category.set( m_orgAffInfoWidget->aff3CategoryCombo->itemData( index ).toInt() );
925 
926 	return info;
927 }
928 
storeInterestInfo() const929 ICQInterestInfo* ICQUserInfoWidget::storeInterestInfo() const
930 {
931 	QTextCodec* codec = getTextCodec();
932 	ICQInterestInfo* info = new ICQInterestInfo( m_interestInfo );
933 
934 	int index = m_interestInfoWidget->topic1Combo->currentIndex();
935 	info->topics[0].set( m_interestInfoWidget->topic1Combo->itemData( index ).toInt() );
936 	info->descriptions[0].set( codec->fromUnicode( m_interestInfoWidget->desc1->text() ) );
937 
938 	index = m_interestInfoWidget->topic2Combo->currentIndex();
939 	info->topics[1].set( m_interestInfoWidget->topic2Combo->itemData( index ).toInt() );
940 	info->descriptions[1].set( codec->fromUnicode( m_interestInfoWidget->desc2->text() ) );
941 
942 	index = m_interestInfoWidget->topic3Combo->currentIndex();
943 	info->topics[2].set( m_interestInfoWidget->topic3Combo->itemData( index ).toInt() );
944 	info->descriptions[2].set( codec->fromUnicode( m_interestInfoWidget->desc3->text() ) );
945 
946 	index = m_interestInfoWidget->topic4Combo->currentIndex();
947 	info->topics[3].set( m_interestInfoWidget->topic4Combo->itemData( index ).toInt() );
948 	info->descriptions[3].set( codec->fromUnicode( m_interestInfoWidget->desc4->text() ) );
949 
950 	return info;
951 }
952 
storeNotesInfo() const953 ICQNotesInfo* ICQUserInfoWidget::storeNotesInfo() const
954 {
955 	QTextCodec* codec = getTextCodec();
956 	ICQNotesInfo* info = new ICQNotesInfo( m_notesInfo );
957 
958 	info->notes.set( codec->fromUnicode( m_otherInfoWidget->notesEdit->toPlainText() ) );
959 
960 	return info;
961 }
962 
storeEmailInfo() const963 ICQEmailInfo* ICQUserInfoWidget::storeEmailInfo() const
964 {
965 	QTextCodec* codec = getTextCodec();
966 	ICQEmailInfo* info = new ICQEmailInfo( m_emailInfo );
967 
968 	//Prepend primary email to emails
969 	QList<ICQEmailInfo::EmailItem> emails = info->emailList.get();
970 	if ( !m_generalUserInfo.email.get().isEmpty() )
971 	{
972 		ICQEmailInfo::EmailItem item;
973 		item.email = m_generalUserInfo.email.get();
974 		item.publish = m_generalUserInfo.publishEmail.get();
975 		emails.prepend( item );
976 	}
977 	info->emailList = emails;
978 
979 	//Store emails
980 	emails.clear();
981 
982 	int size = m_emailModel->rowCount();
983 	for ( int i = 0; i < size; i++ )
984 	{
985 		QStandardItem *modelItem = m_emailModel->item( i, 1 );
986 
987 		ICQEmailInfo::EmailItem item;
988 		item.email = codec->fromUnicode( modelItem->text() );
989 		item.publish = ( i > 0 ) ? ( modelItem->checkState() == Qt::Checked ) : false;
990 		emails.append( item );
991 	}
992 
993 	if ( emails.count() == 0 )
994 	{	// Delete all emails
995 		ICQEmailInfo::EmailItem item;
996 		item.publish = false;
997 		emails.append( item );
998 	}
999 	info->emailList.set( emails );
1000 
1001 	return info;
1002 }
1003 
reverseMap(const QMap<int,QString> & map) const1004 QMap<QString, int> ICQUserInfoWidget::reverseMap( const QMap<int, QString>& map ) const
1005 {
1006 	QMap<QString, int> revMap;
1007 	QMapIterator<int, QString> it( map );
1008 
1009 	while ( it.hasNext() )
1010 	{
1011 		it.next();
1012 		revMap.insert( it.value(), it.key() );
1013 	}
1014 
1015 	return revMap;
1016 }
1017 
getTextCodec() const1018 QTextCodec* ICQUserInfoWidget::getTextCodec() const
1019 {
1020 	return (m_contact) ? m_contact->contactCodec() : m_account->defaultCodec();
1021 }
1022 
1023