Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 141675 | Differences between
and this patch

Collapse All | Expand All

(-)kopete/protocols/oscar/liboscar/ssimodifytask.cpp (+29 lines)
Lines 216-221 Link Here
216
	{
216
	{
217
		WORD ackCode = b->getWord();
217
		WORD ackCode = b->getWord();
218
		kdDebug(OSCAR_RAW_DEBUG) << "Acknowledgement code is " << ackCode << endl;
218
		kdDebug(OSCAR_RAW_DEBUG) << "Acknowledgement code is " << ackCode << endl;
219
		
220
		if ( ackCode != 0x0000 )
221
			freeIdOnError();
222
		
219
		switch( ackCode )
223
		switch( ackCode )
220
		{
224
		{
221
		case 0x0000:
225
		case 0x0000:
Lines 448-453 Link Here
448
	setSuccess( 0, QString::null );
452
	setSuccess( 0, QString::null );
449
}
453
}
450
454
455
void SSIModifyTask::freeIdOnError()
456
{
457
	if ( m_oldItem.isValid() && m_newItem.isValid() )
458
	{
459
		if ( m_opSubject == Contact || m_opSubject == NoSubject )
460
		{
461
			if ( m_oldItem.bid() != m_newItem.bid() )
462
				m_ssiManager->removeID( m_newItem );
463
		}
464
		else if ( m_opSubject == Group )
465
		{
466
			if ( m_oldItem.gid() != m_newItem.gid() )
467
				m_ssiManager->removeID( m_newItem );
468
		}
469
	}
470
	else if ( m_newItem.isValid() && !m_oldItem )
471
	{
472
		if ( m_opSubject == Group || m_opSubject == Contact ||
473
		     m_opSubject == NoSubject )
474
		{
475
			m_ssiManager->removeID( m_newItem );
476
		}
477
	}
478
}
479
451
void SSIModifyTask::sendEditStart()
480
void SSIModifyTask::sendEditStart()
452
{
481
{
453
	SNAC editStartSnac = { 0x0013, 0x0011, 0x0000, client()->snacSequence() };
482
	SNAC editStartSnac = { 0x0013, 0x0011, 0x0000, client()->snacSequence() };
(-)kopete/protocols/oscar/liboscar/ssimanager.h (+5 lines)
Lines 111-116 Link Here
111
	bool newItem( const Oscar::SSI& item );
111
	bool newItem( const Oscar::SSI& item );
112
	bool removeItem( const Oscar::SSI& item );
112
	bool removeItem( const Oscar::SSI& item );
113
113
114
	void addID( const Oscar::SSI& item );
115
	void removeID( const Oscar::SSI& item );
116
114
signals:
117
signals:
115
	
118
	
116
	//! Emitted when we've added a new contact to the list
119
	//! Emitted when we've added a new contact to the list
Lines 128-133 Link Here
128
	void modifyError( const QString& error );
131
	void modifyError( const QString& error );
129
	
132
	
130
private:
133
private:
134
	WORD findFreeId( const QValueList<WORD>& idList, WORD fromId ) const;
135
		
131
	SSIManagerPrivate* d;
136
	SSIManagerPrivate* d;
132
	Oscar::SSI m_dummyItem;
137
	Oscar::SSI m_dummyItem;
133
};
138
};
(-)kopete/protocols/oscar/liboscar/ssimodifytask.h (+3 lines)
Lines 118-123 Link Here
118
	//! Update the SSI Manager with the new data
118
	//! Update the SSI Manager with the new data
119
	void updateSSIManager();
119
	void updateSSIManager();
120
	
120
	
121
	//! Helper function to free id on error
122
	void freeIdOnError();
123
		
121
	//! Send the SSI edit start packet
124
	//! Send the SSI edit start packet
122
	void sendEditStart();
125
	void sendEditStart();
123
	
126
	
(-)kopete/protocols/oscar/liboscar/ssimanager.cpp (-13 / +86 lines)
Lines 29-34 Link Here
29
{
29
{
30
public:
30
public:
31
	QValueList<Oscar::SSI> SSIList;
31
	QValueList<Oscar::SSI> SSIList;
32
	QValueList<WORD> groupIdList;
33
	QValueList<WORD> itemIdList;
32
	WORD lastModTime;
34
	WORD lastModTime;
33
	WORD maxContacts;
35
	WORD maxContacts;
34
	WORD maxGroups;
36
	WORD maxGroups;
Lines 71-88 Link Here
71
		while ( it != d->SSIList.end() && d->SSIList.count() > 0 )
73
		while ( it != d->SSIList.end() && d->SSIList.count() > 0 )
72
			it = d->SSIList.remove( it );
74
			it = d->SSIList.remove( it );
73
	};
75
	};
76
	
77
	d->itemIdList.clear();
78
	d->groupIdList.clear();
79
	d->nextContactId = 0;
80
	d->nextGroupId = 0;
74
}
81
}
75
82
76
WORD SSIManager::nextContactId()
83
WORD SSIManager::nextContactId()
77
{
84
{
78
	d->nextContactId++;
85
	if ( d->nextContactId == 0 )
79
	return d->nextContactId;
86
		d->nextContactId++;
87
	
88
	d->nextContactId = findFreeId( d->itemIdList, d->nextContactId );
89
	if ( d->nextContactId == 0xFFFF )
90
	{
91
		kdWarning(OSCAR_RAW_DEBUG) << k_funcinfo << "No free id!" << endl;
92
		return 0xFFFF;
93
	}
94
	
95
	if ( d->itemIdList.contains( d->nextContactId ) == 0 )
96
		d->itemIdList.append( d->nextContactId );
97
		
98
	return d->nextContactId++;
80
}
99
}
81
100
82
WORD SSIManager::nextGroupId()
101
WORD SSIManager::nextGroupId()
83
{
102
{
84
	d->nextGroupId++;
103
	if ( d->nextGroupId == 0 )
85
	return d->nextGroupId;
104
		d->nextGroupId++;
105
	
106
	d->nextGroupId = findFreeId( d->groupIdList, d->nextGroupId );
107
	if ( d->nextGroupId == 0xFFFF )
108
	{
109
		kdWarning(OSCAR_RAW_DEBUG) << k_funcinfo << "No free group id!" << endl;
110
		return 0xFFFF;
111
	}
112
	
113
	if ( d->groupIdList.contains( d->nextGroupId ) == 0 )
114
		d->groupIdList.append( d->nextGroupId );
115
	
116
	return d->nextGroupId++;
86
}
117
}
87
118
88
WORD SSIManager::numberOfItems() const
119
WORD SSIManager::numberOfItems() const
Lines 379-388 Link Here
379
	if ( !group.name().isEmpty() ) //avoid the group with gid 0 and bid 0
410
	if ( !group.name().isEmpty() ) //avoid the group with gid 0 and bid 0
380
	{	// the group is really new
411
	{	// the group is really new
381
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding group '" << group.name() << "' to SSI list" << endl;
412
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding group '" << group.name() << "' to SSI list" << endl;
382
		if ( group.gid() > d->nextGroupId )
383
			d->nextGroupId = group.gid();
384
		
413
		
385
		d->SSIList.append( group );
414
		d->SSIList.append( group );
415
		addID( group );
386
		emit groupAdded( group );
416
		emit groupAdded( group );
387
		return true;
417
		return true;
388
	}
418
	}
Lines 394-399 Link Here
394
	QString groupName = group.name();
424
	QString groupName = group.name();
395
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Removing group " << group.name() << endl;
425
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Removing group " << group.name() << endl;
396
	int remcount = d->SSIList.remove( group );
426
	int remcount = d->SSIList.remove( group );
427
	removeID( group );
428
	
397
	if ( remcount == 0 )
429
	if ( remcount == 0 )
398
	{
430
	{
399
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No groups removed" << endl;
431
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No groups removed" << endl;
Lines 420-435 Link Here
420
452
421
bool SSIManager::newContact( const Oscar::SSI& contact )
453
bool SSIManager::newContact( const Oscar::SSI& contact )
422
{
454
{
423
	//what to validate?
424
	if ( contact.bid() > d->nextContactId )
425
	{
426
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Setting next contact ID to " << contact.bid() << endl;
427
		d->nextContactId = contact.bid();
428
	}
429
	
430
	if ( d->SSIList.findIndex( contact ) == -1 )
455
	if ( d->SSIList.findIndex( contact ) == -1 )
431
	{
456
	{
432
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding contact '" << contact.name() << "' to SSI list" << endl;
457
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding contact '" << contact.name() << "' to SSI list" << endl;
458
		addID( contact );
433
		d->SSIList.append( contact );
459
		d->SSIList.append( contact );
434
		emit contactAdded( contact );
460
		emit contactAdded( contact );
435
	}
461
	}
Lines 442-447 Link Here
442
{
468
{
443
	QString contactName = contact.name();
469
	QString contactName = contact.name();
444
	int remcount = d->SSIList.remove( contact );
470
	int remcount = d->SSIList.remove( contact );
471
	removeID( contact );
445
	
472
	
446
	if ( remcount == 0 )
473
	if ( remcount == 0 )
447
	{
474
	{
Lines 470-484 Link Here
470
	//no error checking for now
497
	//no error checking for now
471
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Adding item " << item.toString() << endl;
498
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Adding item " << item.toString() << endl;
472
	d->SSIList.append( item );
499
	d->SSIList.append( item );
500
	addID( item );
473
	return true;
501
	return true;
474
}
502
}
475
503
476
bool SSIManager::removeItem( const Oscar::SSI& item )
504
bool SSIManager::removeItem( const Oscar::SSI& item )
477
{
505
{
478
	d->SSIList.remove( item );
506
	d->SSIList.remove( item );
507
	removeID( item );
508
	
479
	return true;
509
	return true;
480
}
510
}
481
511
512
void SSIManager::addID( const Oscar::SSI& item )
513
{
514
	if ( item.type() == ROSTER_GROUP )
515
	{
516
		if ( d->groupIdList.contains( item.gid() ) == 0 )
517
			d->groupIdList.append( item.gid() );
518
	}
519
	else
520
	{
521
		if ( d->itemIdList.contains( item.bid() ) == 0 )
522
			d->itemIdList.append( item.bid() );
523
	}
524
}
525
526
void SSIManager::removeID( const Oscar::SSI& item )
527
{
528
	if ( item.type() == ROSTER_GROUP )
529
	{
530
		d->groupIdList.remove( item.gid() );
531
	
532
		if ( d->nextGroupId > item.gid() )
533
			d->nextGroupId = item.gid();
534
	}
535
	else
536
	{
537
		d->itemIdList.remove( item.bid() );
538
		
539
		if ( d->nextContactId > item.bid() )
540
			d->nextContactId = item.bid();
541
	}
542
}
543
544
WORD SSIManager::findFreeId( const QValueList<WORD>& idList, WORD fromId ) const
545
{
546
	for ( WORD id = fromId; id < 0x8000; id++ )
547
	{
548
		if ( idList.contains( id ) == 0 )
549
			return id;
550
	}
551
	
552
	return 0xFFFF;
553
}
554
482
#include "ssimanager.moc"
555
#include "ssimanager.moc"
483
556
484
//kate: tab-width 4; indent-mode csands;
557
//kate: tab-width 4; indent-mode csands;

Return to bug 141675