From kde-commits Sat Feb 05 01:15:38 2011 From: Lamarque Souza Date: Sat, 05 Feb 2011 01:15:38 +0000 To: kde-commits Subject: KDE/kdenetwork/kopete/kopete Message-Id: <20110205011538.B2F38AC8C7 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129686869205313 SVN commit 1218856 by lvsouza: Sorts accounts before adding them to the status bar. Implementation relys on allPluginsLoaded working as expected. I have been using this change for a week, no problems so far. M +40 -14 kopetewindow.cpp --- trunk/KDE/kdenetwork/kopete/kopete/kopetewindow.cpp #1218855:1218856 @@ -311,14 +311,6 @@ connect ( Kopete::IdentityManager::self(), SIGNAL ( identityUnregistered ( const Kopete::Identity* ) ), this, SLOT ( slotIdentityUnregistered ( const Kopete::Identity* ) ) ); - //Connect the appropriate account signals - /* Please note that I tried to put this in the slotAllPluginsLoaded() function - * but it seemed to break the account icons in the statusbar --Matt */ - connect ( Kopete::AccountManager::self(), SIGNAL ( accountRegistered ( Kopete::Account* ) ), - this, SLOT ( slotAccountRegistered ( Kopete::Account* ) ) ); - connect ( Kopete::AccountManager::self(), SIGNAL ( accountUnregistered ( const Kopete::Account* ) ), - this, SLOT ( slotAccountUnregistered ( const Kopete::Account* ) ) ); - connect ( d->autoHideTimer, SIGNAL ( timeout() ), this, SLOT ( slotAutoHide() ) ); connect ( d->contactlist, SIGNAL( visibleContentHeightChanged() ), this, SLOT ( slotStartAutoResizeTimer() ) ); connect ( d->autoResizeTimer, SIGNAL ( timeout() ), this, SLOT ( slotUpdateSize() ) ); @@ -339,11 +331,6 @@ foreach ( Kopete::Identity *i, identityList ) slotIdentityRegistered ( i ); - // If some account already loaded, build the status icon - QList accountList = Kopete::AccountManager::self()->accounts(); - foreach ( Kopete::Account *a, accountList ) - slotAccountRegistered ( a ); - //install an event filter for the quick search toolbar so we can //catch the hide events toolBar ( "quickSearchBar" )->installEventFilter ( this ); @@ -665,6 +652,9 @@ Kopete::AppearanceSettings::self()->writeConfig(); } +bool compareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b); +bool invertedCompareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b); + void KopeteWindow::slotConfigChanged() { bool groupContactByGroupModel = qobject_cast( d->model ); @@ -727,6 +717,7 @@ else { QList accountList = Kopete::AccountManager::self()->accounts(); + qSort(accountList.begin(), accountList.end(), invertedCompareOnlineStatus); foreach ( Kopete::Account *account, accountList ) { KopeteAccountStatusBarIcon *sbIcon = new KopeteAccountStatusBarIcon ( account, d->statusBarWidget ); @@ -912,6 +903,20 @@ KConfigGroup cg( KGlobal::config(), "General Options" ); + // If some account already loaded, build the status icon + QList accountList = Kopete::AccountManager::self()->accounts(); + qSort(accountList.begin(), accountList.end(), invertedCompareOnlineStatus); + foreach ( Kopete::Account *a, accountList ) + slotAccountRegistered ( a ); + + //Connect the appropriate account signals + /* Please note that I tried to put this in the slotAllPluginsLoaded() function + * but it seemed to break the account icons in the statusbar --Matt */ + connect ( Kopete::AccountManager::self(), SIGNAL ( accountRegistered ( Kopete::Account* ) ), + this, SLOT ( slotAccountRegistered ( Kopete::Account* ) ) ); + connect ( Kopete::AccountManager::self(), SIGNAL ( accountUnregistered ( const Kopete::Account* ) ), + this, SLOT ( slotAccountUnregistered ( const Kopete::Account* ) ) ); + if ( d->showIdentityIcons ) { QString identityId = cg.readEntry( "ShownIdentityId", Kopete::IdentityManager::self()->defaultIdentity()->id() ); @@ -1039,9 +1044,28 @@ bool compareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b) { - return (a->myself()->onlineStatus().status() > b->myself()->onlineStatus().status()); + int c = 0; + + if (a->identity() && b->identity()) { + c = QString::localeAwareCompare(a->identity()->label(), b->identity()->label()); } + if (c == 0) { + c = a->myself()->onlineStatus().status() - b->myself()->onlineStatus().status(); + + if (c == 0) { + return (QString::localeAwareCompare(a->protocol()->displayName(), b->protocol()->displayName()) < 0); + } + return (c > 0); + } + return (c < 0); +} + +bool invertedCompareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b) +{ + return !compareOnlineStatus(a, b); +} + void KopeteWindow::makeTrayToolTip() { //FIXME: maybe use identities here? @@ -1193,6 +1217,7 @@ popup->addTitle ( qApp->windowIcon(), KGlobal::caption() ); QList accountList = Kopete::AccountManager::self()->accounts(); + qSort(accountList.begin(), accountList.end(), invertedCompareOnlineStatus); foreach ( Kopete::Account *account, accountList ) { KActionMenu *menu = new KActionMenu ( account->accountId(), account ); @@ -1270,6 +1295,7 @@ { bool changed = false; QList accountList = Kopete::AccountManager::self()->accounts(); + qSort(accountList.begin(), accountList.end(), invertedCompareOnlineStatus); foreach ( Kopete::Account *account, accountList ) { Kopete::Contact *self = account->myself();