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; |