[Licq-devel] group signalling proposal

"Eugene Paskevich" <[email protected]> Tue, 20 May 2008 09:31:17 +0300
Newsgroups gmane.network.licq.devel
Organization Raptor's NestSite
Message-ID <[email protected]>
I have made a patch for signalling from the daemon to plugins when groups  
are being added, removed, renamed, or reordered. Since there is no good  
group identification (as it was discussed with Anders in irc), plugins are  
only able to tell what happened with groups but cannot tell which exact  
group(s) the action was performed upon. This has to be discussed further.  
Therefore, the daemon patch in attachment is pretty simple.

As for the qt4-gui patch, it simply made internal model, edit group  
dialog, and mainwin elements to be up-to-date with the group list. Some  
overhead was removed, some added. E.g. mainWindow()->updateGroups() calls  
contactList()->reloadAll() itself so there was no need to call one after  
the other in group menu. Further model improvement of model behavior when  
group list change is signalled has to be discussed.

All this partially addresses the 'Group Handling' point in developer's  
wishlist.

Jon, please comment on the daemon patch.
Anders, please comment on qt4-gui patch.

-- 
Eugene Paskevich             |   *==)-----------   |     Plug me into
[email protected]        |   -----------(==*   |      The Matrix
licq_groups_sig_daemon.patch (application/octet-stream, 2.6 KB)
Index: include/licq_events.h
===================================================================
--- include/licq_events.h	(revision 6196)
+++ include/licq_events.h	(working copy)
@@ -310,11 +310,16 @@
  * SIGNAL_UPDATExLIST -
  *   Indicates that the user list has changed in some way.  The sub-type
  *   will be one of the following.  In all cases the argument is 0.
+ *   In all cases of group signalling UIN will be 0 too.
  *     LIST_ADD - A user was added to the list.  The UIN will be that of
  *     the new user.
  *     LIST_REMOVE - A user was removed from the list.  The UIN will be
  *     that of the removed user.
  *     LIST_ALL - The entire list has been changed.  The UIN will be 0.
+ *     LIST_GROUP_ADD - A group was added to the list.
+ *     LIST_GROUP_REMOVE - A group was removed from the list.
+ *     LIST_GROUP_RENAME - A group was renamed.
+ *     LIST_GROUP_REORDER - Group ordering has changed.
  *
  *  SIGNAL_UPDATExUSER - The user has been modified in some way.  The UIN
  *  is that of the relevant user, and the sub-type indicates what type of
@@ -414,6 +419,10 @@
 const unsigned long LIST_ADD                     = 1;
 const unsigned long LIST_REMOVE                  = 2;
 const unsigned long LIST_ALL                     = 3;
+const unsigned long LIST_GROUP_ADD               = 4;
+const unsigned long LIST_GROUP_REMOVE            = 5;
+const unsigned long LIST_GROUP_RENAME            = 6;
+const unsigned long LIST_GROUP_REORDER           = 7;
 
 /*! \brief Plugin notification messages
 
Index: src/user.cpp
===================================================================
--- src/user.cpp	(revision 6196)
+++ src/user.cpp	(working copy)
@@ -869,8 +869,12 @@
     UnlockGroupList();
   }
 
-  if (bNewGroup && !nID && gLicqDaemon)
-    gLicqDaemon->icqAddGroup(_szName);
+  if (bNewGroup && gLicqDaemon != NULL)
+  {
+    if (nID != 0)
+      gLicqDaemon->icqAddGroup(_szName);
+    gLicqDaemon->PushPluginSignal(new CICQSignal(SIGNAL_UPDATExLIST, LIST_GROUP_ADD, 0));
+  }
 
   return bNewGroup;
 }
@@ -920,6 +924,7 @@
 
   SaveGroups();
   UnlockGroupList();
+  gLicqDaemon->PushPluginSignal(new CICQSignal(SIGNAL_UPDATExLIST, LIST_GROUP_REMOVE, 0));
 }
 
 
@@ -965,6 +970,7 @@
   m_vnGroupsID[g2 - 1] = nTmp;
   SaveGroupIDs();
   UnlockGroupIDList();
+  gLicqDaemon->PushPluginSignal(new CICQSignal(SIGNAL_UPDATExLIST, LIST_GROUP_REORDER, 0));
 }
 
 
@@ -987,6 +993,7 @@
   // If we rename a group on logon, don't send the rename packet
   if (gLicqDaemon && _bUpdate)
     gLicqDaemon->icqRenameGroup(_sz, nGSID);
+  gLicqDaemon->PushPluginSignal(new CICQSignal(SIGNAL_UPDATExLIST, LIST_GROUP_RENAME, 0));
 }
licq_groups_sig_qt4-gui.patch (application/octet-stream, 5.1 KB)
Index: src/dialogs/editgrpdlg.h
===================================================================
--- src/dialogs/editgrpdlg.h	(revision 6196)
+++ src/dialogs/editgrpdlg.h	(working copy)
@@ -22,6 +22,8 @@
 
 #include <QDialog>
 
+class CICQSignal;
+
 class QGroupBox;
 class QLineEdit;
 class QListWidget;
@@ -69,7 +71,7 @@
   void slot_editcancel();
   void slot_default();
   void slot_newuser();
-  void slot_done();
+  void slot_refresh(CICQSignal* sig);
 };
 
 } // namespace LicqQtGui
Index: src/dialogs/editgrpdlg.cpp
===================================================================
--- src/dialogs/editgrpdlg.cpp	(revision 6196)
+++ src/dialogs/editgrpdlg.cpp	(working copy)
@@ -31,10 +31,13 @@
 #include <QPushButton>
 #include <QVBoxLayout>
 
+#include <licq_events.h>
 #include <licq_user.h>
 
+#include "core/licqgui.h"
 #include "core/mainwin.h"
 #include "core/messagebox.h"
+#include "core/signalmanager.h"
 
 #include "helpers/licqstrings.h"
 
@@ -106,6 +109,8 @@
   btnDone->setText(tr("&Done"));
 
   RefreshList();
+  connect(LicqGui::instance()->signalManager(),
+      SIGNAL(updatedList(CICQSignal*)), SLOT(slot_refresh(CICQSignal*)));
 
   connect(btnAdd, SIGNAL(clicked()), SLOT(slot_add()));
   connect(btnRemove, SIGNAL(clicked()), SLOT(slot_remove()));
@@ -114,7 +119,7 @@
   connect(btnDefault, SIGNAL(clicked()), SLOT(slot_default()));
   connect(btnNewUser, SIGNAL(clicked()), SLOT(slot_newuser()));
   connect(btnEdit, SIGNAL(clicked()), SLOT(slot_edit()));
-  connect(btnDone, SIGNAL(clicked()), SLOT(slot_done()));
+  connect(btnDone, SIGNAL(clicked()), SLOT(close()));
   connect(edtName, SIGNAL(returnPressed()), SLOT(slot_editok()));
   connect(btnSave, SIGNAL(clicked()), SLOT(slot_editok()));
 
@@ -270,10 +275,21 @@
 }
 
 
-void EditGrpDlg::slot_done()
+void EditGrpDlg::slot_refresh(CICQSignal* sig)
 {
-  // Daemon doesn't notify when groups change so tell mainwin to update
-  gMainWindow->updateGroups();
+  switch (sig->SubSignal())
+  {
+    case LIST_GROUP_ADD:
+    case LIST_GROUP_REMOVE:
+    case LIST_GROUP_RENAME:
+    case LIST_GROUP_REORDER:
+      break;
 
-  close();
+    default:
+      return;
+  }
+
+  if (btnSave->isEnabled()) // we are editing the group name
+    slot_editcancel();
+  RefreshList();
 }
Index: src/contactlist/contactgroup.cpp
===================================================================
--- src/contactlist/contactgroup.cpp	(revision 6196)
+++ src/contactlist/contactgroup.cpp	(working copy)
@@ -203,8 +203,5 @@
   myName = value.toString();
   gUserManager.RenameGroup(myGroupId, myName.toLocal8Bit());
 
-  // Daemon doesn't signal when groups change so trigger update from here
-  emit dataChanged(this);
-
   return true;
 }
Index: src/contactlist/contactlist.cpp
===================================================================
--- src/contactlist/contactlist.cpp	(revision 6196)
+++ src/contactlist/contactlist.cpp	(working copy)
@@ -92,6 +92,12 @@
     case LIST_REMOVE:
       removeUser(sig->Id(), sig->PPID());
       break;
+
+    case LIST_GROUP_ADD:
+    case LIST_GROUP_REMOVE:
+    case LIST_GROUP_RENAME:
+    case LIST_GROUP_REORDER:
+      reloadAll();
   }
 }
 
Index: src/core/mainwin.cpp
===================================================================
--- src/core/mainwin.cpp	(revision 6196)
+++ src/core/mainwin.cpp	(working copy)
@@ -650,8 +650,15 @@
 
 void MainWindow::slot_updatedList(CICQSignal* sig)
 {
-  switch(sig->SubSignal())
+  switch (sig->SubSignal())
   {
+    case LIST_GROUP_ADD:
+    case LIST_GROUP_REMOVE:
+    case LIST_GROUP_RENAME:
+    case LIST_GROUP_REORDER:
+      updateGroups();
+      break;
+
     case LIST_REMOVE:
       updateEvents();
       break;
@@ -764,10 +771,6 @@
 {
   if (!initial)
   {
-    // Daemon does not send an update when groups change so tell contactList it
-    // needs to update
-    LicqGui::instance()->contactList()->reloadAll();
-
     // update group list in user and system menus
     LicqGui::instance()->userMenu()->updateGroups();
     mySystemMenu->updateGroups();
Index: src/core/groupmenu.cpp
===================================================================
--- src/core/groupmenu.cpp	(revision 6196)
+++ src/core/groupmenu.cpp	(working copy)
@@ -138,20 +138,12 @@
 {
   // Model uses group+1 so substract one before sending to daemon
   gUserManager.SwapGroups(myGroupId, myGroupId - 1);
-
-  // Daemon doesn't notify us when groups change so notify model from here
-  LicqGui::instance()->contactList()->reloadAll();
-  LicqGui::instance()->mainWindow()->updateGroups();
 }
 
 void GroupMenu::moveGroupDown()
 {
   // Model uses group+1 so substract one before sending to daemon
   gUserManager.SwapGroups(myGroupId, myGroupId + 1);
-
-  // Daemon doesn't notify us when groups change so notify model from here
-  LicqGui::instance()->contactList()->reloadAll();
-  LicqGui::instance()->mainWindow()->updateGroups();
 }
 
 void GroupMenu::removeGroup()
@@ -164,10 +156,6 @@
     return;
 
   gUserManager.RemoveGroup(myGroupId);
-
-  // Daemon doesn't notify us when groups change so notify model from here
-  LicqGui::instance()->contactList()->reloadAll();
-  LicqGui::instance()->mainWindow()->updateGroups();
 }
 
 void GroupMenu::addUsersToGroup(QAction* action)