Ticket #36: offline-group.patch

File offline-group.patch, 17.1 kB (added by amroth, 12 months ago)

Patch to group together offline contacts

  • kmess/contactlistviewitem.cpp

     
    3131#include "kmessdebug.h" 
    3232#include "currentaccount.h" 
    3333#include "contact/contact.h" 
     34#include "contact/group.h" 
    3435#include "emoticonmanager.h" 
     36#include "grouplistviewitem.h" 
    3537 
    3638#ifdef KMESSDEBUG_CONTACTLISTVIEWITEM 
    3739#define KMESSDEBUG_CONTACTLISTVIEWITEM_GENERAL 
     
    385387// Update the visibility of the contact 
    386388void ContactListViewItem::slotUpdateVisiblity() 
    387389{ 
    388   // Visibility depends on whether or not allowed and removed contacts are shown. 
     390  // Visibility of a contact depends on the list grouping mode, and on the contact status. 
     391 
    389392  CurrentAccount *currentAccount = CurrentAccount::instance(); 
     393  int groupMode = currentAccount->getContactsGroupMode(); 
     394  GroupListViewItem *parent = static_cast<GroupListViewItem*>( QListViewItem::parent() ); 
    390395 
    391   if(QListViewItem::parent() == 0 && ! currentAccount->getShowContactsByGroup()) 
     396  // Hide root items if contacts are grouped between online and offline; and when the contact without 
     397  // group is offline if contact sare divided in groups+offline contacts. 
     398  if( parent == 0 && 
     399    ( groupMode == Account::BYSTATUS || (groupMode == Account::MIXED && contact_->isOffline() ) ) ) 
    392400  { 
    393     // Hide root items if contacts are shown in online/offline groups. 
    394     setVisible(false); 
     401    setVisible( false ); 
     402    return; 
    395403  } 
    396   else if(contact_->isOffline() && ! currentAccount->getShowOfflineContacts()) 
     404 
     405  // Hide offline contacts in groups, when in mixed mode 
     406  if(    groupMode == Account::MIXED && contact_->isOffline() 
     407      && parent && ! parent->getGroup()->isSpecialGroup() ) 
    397408  { 
    398     // Hide if online contacts are not shown 
    399     setVisible(false); 
     409    setVisible( false ); 
     410    return; 
    400411  } 
     412 
     413  // Hide if offline contacts are not shown 
     414  if( contact_->isOffline() && ! currentAccount->getShowOfflineContacts() ) 
     415  { 
     416    setVisible( false ); 
     417    return; 
     418  } 
     419 
     420  if( contact_->isFriend() ) 
     421  { 
     422    // Friends should always be visible 
     423    setVisible( true ); 
     424  } 
     425  else if( contact_->isAllowed() ) 
     426  { 
     427    // Whether or not allowed contacts are visible depends on the contact setting 
     428    setVisible( currentAccount->getShowAllowedContacts() ); 
     429  } 
    401430  else 
    402431  { 
    403     if(contact_->isFriend()) 
    404     { 
    405       // Friends should always be visible 
    406       setVisible(true); 
    407     } 
    408     else if(contact_->isAllowed()) 
    409     { 
    410       // Whether or not allowed contacts are visible depends on the contact setting 
    411       setVisible( currentAccount->getShowAllowedContacts() ); 
    412     } 
    413     else 
    414     { 
    415       // Whether or not removed contacts are visible depends on the contact setting 
    416       setVisible( currentAccount->getShowRemovedContacts() ); 
    417     } 
     432    // Whether or not removed contacts are visible depends on the contact setting 
     433    setVisible( currentAccount->getShowRemovedContacts() ); 
    418434  } 
    419435} 
    420436 
  • kmess/kmess.cpp

     
    631631void KMess::changeViewMode(int mode) 
    632632{ 
    633633#ifdef KMESSTEST 
    634   ASSERT( ( mode == 0 ) || ( mode == 1 ) ); 
     634  ASSERT( ( mode >= 0 ) && ( mode <= 2 ) ); 
    635635#endif 
    636   if ( mode == 0 ) 
     636 
     637  switch( currentAccount_->getContactsGroupMode() ) 
    637638  { 
    638     CurrentAccount::instance()->setShowContactsByGroup( true ); 
     639    case 0: CurrentAccount::instance()->setContactsGroupMode( Account::BYGROUP  ); break; 
     640    case 1: CurrentAccount::instance()->setContactsGroupMode( Account::MIXED    ); break; 
     641    case 2: CurrentAccount::instance()->setContactsGroupMode( Account::BYSTATUS ); break; 
     642 
     643    default: 
     644      kdDebug() << "KMess - changeViewMode() - WARNING - Invalid view mode = " << mode << endl; 
     645      break; 
    639646  } 
    640   else if ( mode == 1 ) 
    641   { 
    642     CurrentAccount::instance()->setShowContactsByGroup( false ); 
    643   } 
    644   else 
    645   { 
    646     kdDebug() << "KMess - changeViewMode() - WARNING - Invalid view mode = " << mode << endl; 
    647   } 
    648647} 
    649648 
    650649 
     
    885884  showAllowedAction_->setChecked( currentAccount_->getShowAllowedContacts() ); 
    886885  showOfflineAction_->setChecked( currentAccount_->getShowOfflineContacts() ); 
    887886  showRemovedAction_->setChecked( currentAccount_->getShowRemovedContacts() ); 
    888   if ( currentAccount_->getShowContactsByGroup() ) 
     887 
     888  switch( currentAccount_->getContactsGroupMode() ) 
    889889  { 
    890     viewMode_->setCurrentItem( 0 ); 
     890    case Account::BYSTATUS:  viewMode_->setCurrentItem( 2 ); break; 
     891    case Account::MIXED:     viewMode_->setCurrentItem( 1 ); break; 
     892    case Account::BYGROUP: 
     893    default:                 viewMode_->setCurrentItem( 0 ); break; 
    891894  } 
    892   else 
    893   { 
    894     viewMode_->setCurrentItem( 1 ); 
    895   } 
     895 
    896896  // Show the connected message 
    897897  statusMessage( i18n("Connected"), TYPE_MESSAGE ); 
    898898 
  • kmess/account.cpp

     
    6565   savedChatDirectoryStructure_( 0 ), 
    6666   shakeNudge_(true), 
    6767   showAllowedContacts_(false), 
    68    showContactsByGroup_(true), 
     68   contactsGroupMode_(BYGROUP), 
    6969   showEmail_(true), 
    7070   showMessageTime_(true), 
    7171   showNowListening_(false), 
     
    128128                               account->getFriendlyName(), 
    129129                               account->getPassword() ); 
    130130  setShowAllowedContacts     ( account->getShowAllowedContacts() ); 
    131   setShowContactsByGroup     ( account->getShowContactsByGroup() ); 
     131  setContactsGroupMode       ( account->getContactsGroupMode()  ); 
    132132  setShowOfflineContacts     ( account->getShowOfflineContacts() ); 
    133133  setShowRemovedContacts     ( account->getShowRemovedContacts() ); 
    134134  setEmoticonStyle           ( account->getEmoticonStyle()       ); 
     
    189189  setShowAllowedContacts( account->getShowAllowedContacts() ); 
    190190  setShowOfflineContacts( account->getShowOfflineContacts() ); 
    191191  setShowRemovedContacts( account->getShowRemovedContacts() ); 
    192   setShowContactsByGroup( account->getShowContactsByGroup() ); 
     192  setContactsGroupMode  ( account->getContactsGroupMode()  ); 
    193193  setAutoreplyMessage   ( account->getAutoreplyMessage()    ); 
    194194  setEmailSupported     ( account->getEmailSupported()      ); 
    195195  setGuestAccount       ( account->isGuestAccount()         ); 
     
    488488 
    489489 
    490490 
    491 // Read whether contacts are shown by group or by online/offline. 
    492 bool Account::getShowContactsByGroup() const 
     491// Get how the contacts are grouped together in the contact list. 
     492const int& Account::getContactsGroupMode() const 
    493493{ 
    494   return showContactsByGroup_; 
     494  return contactsGroupMode_; 
    495495} 
    496496 
    497497 
     
    711711  contactFont_.setUnderline      ( config->readBoolEntry( "contactfontunderline",         false                           ) ); 
    712712  contactFont_.setPointSize      ( config->readNumEntry ( "contactfontpointsize",         10                              ) ); 
    713713  contactFontColor_              = config->readEntry    ( "contactfontcolor" ,            "#000000"                         ); 
     714  contactsGroupMode_             = config->readNumEntry ( "contactsGroupMode",            0                                 ); 
    714715  customImageIndex_              = config->readNumEntry ( "customimageindex",             0                                 ); 
    715716  doNotifyContactsOnline_        = config->readBoolEntry( "doNotifyContactsOnline",       true                              ); 
    716717  doNotifyContactsStatus_        = config->readBoolEntry( "doNotifyContactsStatus",       false                             ); 
     
    738739  savedChatDirectoryStructure_   = config->readNumEntry ( "savedChatDirectoryStructure",  0                                 ); 
    739740  shakeNudge_                    = config->readBoolEntry( "shakeNudge",                   true                              ); 
    740741  showAllowedContacts_           = config->readBoolEntry( "showAllowed",                  false                             ); 
    741   showContactsByGroup_           = config->readBoolEntry( "showByGroup",                  true                              ); 
    742742  showEmail_                     = config->readBoolEntry( "showEmail",                    true                              ); 
    743743  showImage_                     = config->readBoolEntry( "showImage",                    true                              ); 
    744744  showMessageTime_               = config->readBoolEntry( "showMessageTime",              true                              ); 
     
    858858    config->writeEntry( "savedChatDirectoryStructure",  savedChatDirectoryStructure_  ); 
    859859    config->writeEntry( "shakeNudge",                   shakeNudge_                   ); 
    860860    config->writeEntry( "showAllowed",                  showAllowedContacts_          ); 
    861     config->writeEntry( "showByGroup",                  showContactsByGroup_          ); 
     861    config->writeEntry( "contactsGroupMode",            contactsGroupMode_            ); 
    862862    config->writeEntry( "showEmail",                    showEmail_                    ); 
    863863    config->writeEntry( "showMessageTime",              showMessageTime_              ); 
    864864    config->writeEntry( "showNowListening",             showNowListening_             ); 
     
    12901290 
    12911291 
    12921292 
    1293 // Set whether contacts are shown by group or by online/offline. 
    1294 void Account::setShowContactsByGroup( bool showContactsByGroup ) 
     1293// Change how the contacts are grouped together in the contact list. 
     1294void Account::setContactsGroupMode( int contactsGroupMode ) 
    12951295{ 
    1296   if ( showContactsByGroup != showContactsByGroup_ ) 
     1296  if ( contactsGroupMode != contactsGroupMode_ ) 
    12971297  { 
    1298     showContactsByGroup_ = showContactsByGroup; 
     1298    contactsGroupMode_ = contactsGroupMode; 
    12991299    emit changedViewMode(); 
    13001300    dirty_ = true; 
    13011301#ifdef KMESSDEBUG_ACCOUNT_DIRTY 
    1302     kdDebug() << "Account::setShowContactsByGroup(): Setting 'dirty' to true." << endl; 
     1302    kdDebug() << "Account::setContactsGroupMode(): Setting 'dirty' to true." << endl; 
    13031303#endif 
    13041304  } 
    13051305} 
  • kmess/account.h

     
    5252                                , BYDAY           = 3 
    5353                                }; 
    5454 
     55    // Groups organization 
     56    enum ListGroupMode { BYGROUP  = 0 // Group all contacts by their group 
     57                       , MIXED    = 1 // As BYGROUP but all offline contacts group together 
     58                       , BYSTATUS = 2 // Group contacts by status, online and offline 
     59                       }; 
     60 
    5561    // The constructor 
    5662    Account(); 
    5763    // The destructor 
     
    7076    const QFont&                 getContactFont() const; 
    7177    // Return the color of the forced contact font. 
    7278    const QString&               getContactFontColor() const; 
     79    // Get how the contacts are grouped together in the contact list. 
     80    const int&                   getContactsGroupMode() const; 
    7381    // Read the email command used when not using hotmail 
    7482    const QString&               getEmailCommand() const; 
    7583    // Return whether email notifications are supported 
     
    114122    const int&                   getSavedChatDirectoryStructure() const; 
    115123    // Read whether or not allowed contacts are shown. 
    116124    bool                         getShowAllowedContacts() const; 
    117     // Read whether contacts are shown by group or by online/offline. 
    118     bool                         getShowContactsByGroup() const; 
    119125    // Read whether the email information should be shown in the main view. 
    120126    bool                         getShowEmail() const; 
    121127    // Read the selected emoticon's list number 
     
    180186    void                         setChatInformation( bool useContactFont, bool useEmoticons, bool useFontEffects, bool showMessageTime, bool groupFollowupMessages, const QString& chatStyle ); 
    181187    // Set chat logging information 
    182188    void                         setChatLoggingInformation( bool saveChats, const QString& saveChatPath, const int& directoryStructure ); 
     189    // Change how the contacts are grouped together in the contact list. 
     190    void                         setContactsGroupMode( int groupMode ); 
    183191    // Set email information 
    184192    void                         setEmailInformation( bool useHotmail, const QString&  emailCommand, bool showEmail, bool showOtherFolders ); 
    185193    // Set the font 
     
    218226    void                         setNotifyEmails( bool doNotifyEmails ); 
    219227    // Set whether or not allowed contacts are shown. 
    220228    void                         setShowAllowedContacts( bool showAllowedContacts ); 
    221     // Set whether contacts are shown by group or by online/offline. 
    222     void                         setShowContactsByGroup( bool showContactsByGroup ); 
    223229    // Set whether offline contacts should be shown. 
    224230    void                         setShowOfflineContacts( bool showOfflineContacts ); 
    225231    // Set whether or not removed (reverse) contacts are shown. 
     
    307313    bool                         shakeNudge_; 
    308314    // Whether or not allowed contacts should be visible. 
    309315    bool                         showAllowedContacts_; 
    310     // Whether contacts should be shown by group (true) or by online/offline status (false). 
    311     bool                         showContactsByGroup_; 
     316    // How contacts should be grouped together in the list. 
     317    int                          contactsGroupMode_; 
    312318    // Whether or not to show any email notifications (the user may not 
    313319    //  have a hotmail account). 
    314320    bool                         showEmail_; 
  • kmess/kmessinterface.cpp

     
    278278#endif 
    279279 
    280280  viewMode_ = new KSelectAction( i18n("&Sort Contacts by"), "view_tree", 0, this, "viewmode"); 
    281   viewModes << i18n("Group") << i18n("Online/Offline"); 
     281  viewModes << i18n("Group") << i18n("Groups/Offline") << i18n("Online/Offline"); 
    282282  viewMode_->setItems(viewModes); 
     283 
    283284  connect ( viewMode_, SIGNAL( activated( int ) ), this, SLOT( changeViewMode( int ) ) ); 
    284285 
    285286  showTransferAction_ = new KAction(i18n("Show &Transfer Window"), "cache", 0, 
  • kmess/kmessview.cpp

     
    13631363 
    13641364  GroupListViewItem *item; 
    13651365  item = new GroupListViewItem(contactListView_, group); 
     1366  int groupMode = currentAccount_->getContactsGroupMode(); 
    13661367 
    13671368  if(! group->isSpecialGroup() || group->getId() == SpecialGroups::INDIVIDUALS) 
    13681369  { 
     
    13701371    connect(item, SIGNAL(moveToGroup(Group*)), this, SLOT(slotForwardMoveContact(Group*))); 
    13711372    connect(item, SIGNAL(copyToGroup(Group*)), this, SLOT(slotForwardCopyContact(Group*))); 
    13721373    // Hide normal group if user likes to sort contacts by online/offline state 
    1373     item->setVisible( currentAccount_->getShowContactsByGroup() ); 
     1374    item->setVisible( groupMode != Account::BYSTATUS ); 
    13741375  } 
    13751376  else 
    13761377  { 
     
    13851386    } 
    13861387    else if(group->getId() == SpecialGroups::ONLINE) 
    13871388    { 
    1388       item->setVisible( ! currentAccount_->getShowContactsByGroup() ); 
     1389      item->setVisible( groupMode == Account::BYSTATUS ); 
    13891390    } 
    13901391    else if(group->getId() == SpecialGroups::OFFLINE) 
    13911392    { 
    1392       item->setVisible( ! currentAccount_->getShowContactsByGroup() && 
    1393                           currentAccount_->getShowOfflineContacts() ); 
     1393      item->setVisible( groupMode == Account::BYSTATUS && currentAccount_->getShowOfflineContacts() ); 
    13941394    } 
    13951395  } 
    13961396} 
     
    16191619  // Read the settings 
    16201620  bool showAllowed = currentAccount_->getShowAllowedContacts(); 
    16211621  bool showRemoved = currentAccount_->getShowRemovedContacts(); 
    1622   bool showByGroup = currentAccount_->getShowContactsByGroup(); 
    16231622  bool showOffline = currentAccount_->getShowOfflineContacts(); 
     1623  int  groupMode   = currentAccount_->getContactsGroupMode(); 
    16241624 
     1625kdDebug() << "TEST - Group mode: " << groupMode << endl; 
    16251626  QString            groupId; 
    16261627  GroupListViewItem *groupItem = findFirstGroup(); 
    1627  
    16281628  while(groupItem != 0) 
    16291629  { 
    16301630    groupId = groupItem->getGroup()->getId(); 
    16311631 
     1632kdDebug() << "TEST - name: " << groupItem->getGroup()->getName() << " - special: " << groupItem->getGroup()->isSpecialGroup() << endl; 
    16321633    // Hide or show the special groups 
    16331634    if(groupId == SpecialGroups::ALLOWED) 
    16341635    { 
     
    16401641    } 
    16411642    else if(groupId == SpecialGroups::ONLINE) 
    16421643    { 
    1643       groupItem->setVisible( ! showByGroup ); 
     1644      groupItem->setVisible( groupMode == Account::BYSTATUS ); 
    16441645    } 
    16451646    else if(groupId == SpecialGroups::OFFLINE) 
    16461647    { 
    1647       groupItem->setVisible( ! showByGroup && showOffline ); 
     1648      // Show both in groups+offline and online+offline display modes 
     1649      groupItem->setVisible( groupMode != Account::BYGROUP && showOffline ); 
    16481650    } 
    16491651    else 
    16501652    { 
     
    16521654      // This feature is used from slotUpdateViewMode() 
    16531655      if(! groupItem->getGroup()->isSpecialGroup()) 
    16541656      { 
    1655         groupItem->setVisible( showByGroup ); 
     1657        groupItem->setVisible( groupMode != Account::BYSTATUS ); 
    16561658      } 
     1659      else 
     1660      { 
     1661        groupItem->setVisible( true ); 
     1662      } 
    16571663    } 
    16581664 
    16591665    groupItem = findNextGroup(groupItem);