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 469-474 Link Here
469
	setSuccess( 0, QString::null );
473
	setSuccess( 0, QString::null );
470
}
474
}
471
475
476
void SSIModifyTask::freeIdOnError()
477
{
478
	if ( m_oldItem.isValid() && m_newItem.isValid() )
479
	{
480
		if ( m_opSubject == Contact || m_opSubject == NoSubject )
481
		{
482
			if ( m_oldItem.bid() != m_newItem.bid() )
483
				m_ssiManager->removeID( m_newItem );
484
		}
485
		else if ( m_opSubject == Group )
486
		{
487
			if ( m_oldItem.gid() != m_newItem.gid() )
488
				m_ssiManager->removeID( m_newItem );
489
		}
490
	}
491
	else if ( m_newItem.isValid() && !m_oldItem )
492
	{
493
		if ( m_opSubject == Group || m_opSubject == Contact ||
494
		     m_opSubject == NoSubject )
495
		{
496
			m_ssiManager->removeID( m_newItem );
497
		}
498
	}
499
}
500
472
void SSIModifyTask::sendEditStart()
501
void SSIModifyTask::sendEditStart()
473
{
502
{
474
	SNAC editStartSnac = { 0x0013, 0x0011, 0x0000, client()->snacSequence() };
503
	SNAC editStartSnac = { 0x0013, 0x0011, 0x0000, client()->snacSequence() };
(-)kopete/protocols/oscar/liboscar/ssimanager.h (+5 lines)
Lines 115-120 Link Here
115
	bool newItem( const Oscar::SSI& item );
115
	bool newItem( const Oscar::SSI& item );
116
	bool removeItem( const Oscar::SSI& item );
116
	bool removeItem( const Oscar::SSI& item );
117
117
118
	void addID( const Oscar::SSI& item );
119
	void removeID( const Oscar::SSI& item );
120
118
signals:
121
signals:
119
	
122
	
120
	//! Emitted when we've added a new contact to the list
123
	//! Emitted when we've added a new contact to the list
Lines 138-143 Link Here
138
	void modifyError( const QString& error );
141
	void modifyError( const QString& error );
139
	
142
	
140
private:
143
private:
144
	WORD findFreeId( const QValueList<WORD>& idList, WORD fromId ) const;
145
		
141
	SSIManagerPrivate* d;
146
	SSIManagerPrivate* d;
142
	Oscar::SSI m_dummyItem;
147
	Oscar::SSI m_dummyItem;
143
};
148
};
(-)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 (-19 / +92 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
	
90
	if ( d->nextContactId == 0xFFFF )
91
	{
92
		kdWarning(OSCAR_RAW_DEBUG) << k_funcinfo << "No free id!" << endl;
93
		return 0xFFFF;
94
	}
95
	
96
	if ( d->itemIdList.contains( d->nextContactId ) == 0 )
97
		d->itemIdList.append( d->nextContactId );
98
		
99
	return d->nextContactId++;
80
}
100
}
81
101
82
WORD SSIManager::nextGroupId()
102
WORD SSIManager::nextGroupId()
83
{
103
{
84
	d->nextGroupId++;
104
	if ( d->nextGroupId == 0 )
85
	return d->nextGroupId;
105
		d->nextGroupId++;
106
	
107
	d->nextGroupId = findFreeId( d->groupIdList, d->nextGroupId );
108
	
109
	if ( d->nextGroupId == 0xFFFF )
110
	{
111
		kdWarning(OSCAR_RAW_DEBUG) << k_funcinfo << "No free group id!" << endl;
112
		return 0xFFFF;
113
	}
114
	
115
	if ( d->groupIdList.contains( d->nextGroupId ) == 0 )
116
		d->groupIdList.append( d->nextGroupId );
117
	
118
	return d->nextGroupId++;
86
}
119
}
87
120
88
WORD SSIManager::numberOfItems() const
121
WORD SSIManager::numberOfItems() const
Lines 390-399 Link Here
390
	if ( !group.name().isEmpty() ) //avoid the group with gid 0 and bid 0
423
	if ( !group.name().isEmpty() ) //avoid the group with gid 0 and bid 0
391
	{	// the group is really new
424
	{	// the group is really new
392
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding group '" << group.name() << "' to SSI list" << endl;
425
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding group '" << group.name() << "' to SSI list" << endl;
393
		if ( group.gid() > d->nextGroupId )
394
			d->nextGroupId = group.gid();
395
		
426
		
396
		d->SSIList.append( group );
427
		d->SSIList.append( group );
428
		addID( group );
397
		emit groupAdded( group );
429
		emit groupAdded( group );
398
		return true;
430
		return true;
399
	}
431
	}
Lines 402-407 Link Here
402
434
403
bool SSIManager::updateGroup( const Oscar::SSI& oldGroup, const Oscar::SSI& newGroup )
435
bool SSIManager::updateGroup( const Oscar::SSI& oldGroup, const Oscar::SSI& newGroup )
404
{
436
{
437
	removeID( oldGroup );
405
	if ( d->SSIList.remove( oldGroup ) == 0 )
438
	if ( d->SSIList.remove( oldGroup ) == 0 )
406
	{
439
	{
407
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No group were removed." << endl;
440
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No group were removed." << endl;
Lines 416-421 Link Here
416
	
449
	
417
	kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Updating group '" << newGroup.name() << "' in SSI list" << endl;
450
	kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Updating group '" << newGroup.name() << "' in SSI list" << endl;
418
	d->SSIList.append( newGroup );
451
	d->SSIList.append( newGroup );
452
	addID( newGroup );
419
	emit groupUpdated( newGroup );
453
	emit groupUpdated( newGroup );
420
	
454
	
421
	return true;
455
	return true;
Lines 426-431 Link Here
426
	QString groupName = group.name();
460
	QString groupName = group.name();
427
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Removing group " << group.name() << endl;
461
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Removing group " << group.name() << endl;
428
	int remcount = d->SSIList.remove( group );
462
	int remcount = d->SSIList.remove( group );
463
	removeID( group );
464
	
429
	if ( remcount == 0 )
465
	if ( remcount == 0 )
430
	{
466
	{
431
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No groups removed" << endl;
467
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No groups removed" << endl;
Lines 452-467 Link Here
452
488
453
bool SSIManager::newContact( const Oscar::SSI& contact )
489
bool SSIManager::newContact( const Oscar::SSI& contact )
454
{
490
{
455
	//what to validate?
456
	if ( contact.bid() > d->nextContactId )
457
	{
458
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Setting next contact ID to " << contact.bid() << endl;
459
		d->nextContactId = contact.bid();
460
	}
461
	
462
	if ( d->SSIList.findIndex( contact ) == -1 )
491
	if ( d->SSIList.findIndex( contact ) == -1 )
463
	{
492
	{
464
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding contact '" << contact.name() << "' to SSI list" << endl;
493
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding contact '" << contact.name() << "' to SSI list" << endl;
494
		addID( contact );
465
		d->SSIList.append( contact );
495
		d->SSIList.append( contact );
466
		emit contactAdded( contact );
496
		emit contactAdded( contact );
467
	}
497
	}
Lines 472-477 Link Here
472
502
473
bool SSIManager::updateContact( const Oscar::SSI& oldContact, const Oscar::SSI& newContact )
503
bool SSIManager::updateContact( const Oscar::SSI& oldContact, const Oscar::SSI& newContact )
474
{
504
{
505
	removeID( oldContact );
475
	if ( d->SSIList.remove( oldContact ) == 0 )
506
	if ( d->SSIList.remove( oldContact ) == 0 )
476
	{
507
	{
477
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No contacts were removed." << endl;
508
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "No contacts were removed." << endl;
Lines 485-490 Link Here
485
	}
516
	}
486
	
517
	
487
	kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Updating contact '" << newContact.name() << "' in SSI list" << endl;
518
	kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Updating contact '" << newContact.name() << "' in SSI list" << endl;
519
	addID( newContact );
488
	d->SSIList.append( newContact );
520
	d->SSIList.append( newContact );
489
	emit contactUpdated( newContact );
521
	emit contactUpdated( newContact );
490
	
522
	
Lines 495-500 Link Here
495
{
527
{
496
	QString contactName = contact.name();
528
	QString contactName = contact.name();
497
	int remcount = d->SSIList.remove( contact );
529
	int remcount = d->SSIList.remove( contact );
530
	removeID( contact );
498
	
531
	
499
	if ( remcount == 0 )
532
	if ( remcount == 0 )
500
	{
533
	{
Lines 520-543 Link Here
520
553
521
bool SSIManager::newItem( const Oscar::SSI& item )
554
bool SSIManager::newItem( const Oscar::SSI& item )
522
{
555
{
523
	if ( item.bid() > d->nextContactId )
524
	{
525
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Setting next contact ID to " << item.bid() << endl;
526
		d->nextContactId = item.bid();
527
	}
528
	
529
	//no error checking for now
556
	//no error checking for now
530
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Adding item " << item.toString() << endl;
557
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Adding item " << item.toString() << endl;
531
	d->SSIList.append( item );
558
	d->SSIList.append( item );
559
	addID( item );
532
	return true;
560
	return true;
533
}
561
}
534
562
535
bool SSIManager::removeItem( const Oscar::SSI& item )
563
bool SSIManager::removeItem( const Oscar::SSI& item )
536
{
564
{
537
	d->SSIList.remove( item );
565
	d->SSIList.remove( item );
566
	removeID( item );
567
	
538
	return true;
568
	return true;
539
}
569
}
540
570
571
void SSIManager::addID( const Oscar::SSI& item )
572
{
573
	if ( item.type() == ROSTER_GROUP )
574
	{
575
		if ( d->groupIdList.contains( item.gid() ) == 0 )
576
			d->groupIdList.append( item.gid() );
577
	}
578
	else
579
	{
580
		if ( d->itemIdList.contains( item.bid() ) == 0 )
581
			d->itemIdList.append( item.bid() );
582
	}
583
}
584
585
void SSIManager::removeID( const Oscar::SSI& item )
586
{
587
	if ( item.type() == ROSTER_GROUP )
588
	{
589
		d->groupIdList.remove( item.gid() );
590
	
591
		if ( d->nextGroupId > item.gid() )
592
			d->nextGroupId = item.gid();
593
	}
594
	else
595
	{
596
		d->itemIdList.remove( item.bid() );
597
		
598
		if ( d->nextContactId > item.bid() )
599
			d->nextContactId = item.bid();
600
	}
601
}
602
603
WORD SSIManager::findFreeId( const QValueList<WORD>& idList, WORD fromId ) const
604
{
605
	for ( WORD id = fromId; id < 0x8000; id++ )
606
	{
607
		if ( idList.contains( id ) == 0 )
608
			return id;
609
	}
610
	
611
	return 0xFFFF;
612
}
613
541
#include "ssimanager.moc"
614
#include "ssimanager.moc"
542
615
543
//kate: tab-width 4; indent-mode csands;
616
//kate: tab-width 4; indent-mode csands;

Return to bug 141675