changeset 1802:b135572fcd26

Add urgent flag per screen buffer
author Mikael Berthe <mikael@lilotux.net>
date Sun, 21 Mar 2010 15:13:33 +0100
parents 07e73049f7c5
children 7d3060070d10
files mcabber/mcabber/api.h mcabber/mcabber/roster.c mcabber/mcabber/roster.h mcabber/mcabber/screen.c mcabber/mcabber/screen.h
diffstat 5 files changed, 114 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/api.h	Sun Mar 21 15:10:51 2010 +0100
+++ b/mcabber/mcabber/api.h	Sun Mar 21 15:13:33 2010 +0100
@@ -3,7 +3,7 @@
 
 #include <mcabber/config.h> // For MCABBER_BRANCH
 
-#define MCABBER_API_VERSION 8
+#define MCABBER_API_VERSION 9
 #define MCABBER_API_MIN     8
 
 extern const gchar *mcabber_branch;
--- a/mcabber/mcabber/roster.c	Sun Mar 21 15:10:51 2010 +0100
+++ b/mcabber/mcabber/roster.c	Sun Mar 21 15:13:33 2010 +0100
@@ -103,6 +103,7 @@
 
   /* Flag used for the UI */
   guint flags;
+  guint ui_prio;  // Boolean, positive if "attention" is requested
 
   // list: user -> points to his group; group -> points to its users list
   GSList *list;
@@ -610,6 +611,7 @@
       if (roster_usr->flags & ROSTER_FLAG_MSG)
         unread_list_modified = TRUE;
       roster_usr->flags &= ~ROSTER_FLAG_MSG;
+      roster_usr->ui_prio = 0;
       if (unread_list) {
         GSList *node = g_slist_find(unread_list, roster_usr);
         if (node)
@@ -645,6 +647,7 @@
     if (roster_usr->flags & ROSTER_FLAG_MSG)
       unread_list_modified = TRUE;
     roster_usr->flags &= ~ROSTER_FLAG_MSG;
+    roster_usr->ui_prio = 0;
     if (unread_list) {
       GSList *node = g_slist_find(unread_list, roster_usr);
       if (node)
@@ -683,6 +686,55 @@
   }
 }
 
+//  roster_setuiprio(jid, special, prio_value, action)
+// Set the "attention" priority value for the given roster item.
+// Note that this function doesn't create the roster item if it doesn't exist.
+void roster_setuiprio(const char *jid, guint special, guint value,
+                      enum setuiprio_ops action)
+{
+  guint oldval, newval;
+  roster *roster_usr;
+
+  if (special) {
+    roster_usr = &roster_special;
+  } else {
+    GSList *sl_user = roster_find(jid, jidsearch,
+                        ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
+    if (!sl_user)
+      return;
+
+    roster_usr = (roster*)sl_user->data;
+  }
+  oldval = roster_usr->ui_prio;
+
+  if (action == prio_max)
+    newval = MAX(oldval, value);
+  else if (action == prio_inc)
+    newval = oldval + value;
+  else // prio_set
+    newval = value;
+
+  roster_usr->ui_prio = newval;
+}
+
+guint roster_getuiprio(const char *jid, guint special)
+{
+  roster *roster_usr;
+  GSList *sl_user;
+
+  if (special) {
+    roster_usr = &roster_special;
+    return roster_usr->ui_prio;
+  }
+
+  sl_user = roster_find(jid, jidsearch,
+                        ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
+  if (!sl_user)
+    return 0;
+  roster_usr = (roster*)sl_user->data;
+  return roster_usr->ui_prio;
+}
+
 const char *roster_getname(const char *jid)
 {
   GSList *sl_user;
@@ -1394,6 +1446,12 @@
   return roster_usr->flags;
 }
 
+guint buddy_getuiprio(gpointer rosterdata)
+{
+  roster *roster_usr = rosterdata;
+  return roster_usr->ui_prio;
+}
+
 //  buddy_setonserverflag()
 // Set the on_server flag
 void buddy_setonserverflag(gpointer rosterdata, guint onserver)
--- a/mcabber/mcabber/roster.h	Sun Mar 21 15:10:51 2010 +0100
+++ b/mcabber/mcabber/roster.h	Sun Mar 21 15:13:33 2010 +0100
@@ -9,6 +9,14 @@
 
 #define SPECIAL_BUFFER_STATUS_ID  "[status]"
 
+// Default UI priorities
+#define ROSTER_UI_PRIO_MUC_MESSAGE        20
+#define ROSTER_UI_PRIO_MUC_HL_MESSAGE     30
+#define ROSTER_UI_PRIO_MUC_PRIV_MESSAGE   40
+#define ROSTER_UI_PRIO_PRIVATE_MESSAGE    50
+#define ROSTER_UI_PRIO_ATTENTION_MESSAGE  100
+#define ROSTER_UI_PRIO_STATUS_WIN_MESSAGE 500
+
 enum imstatus {
     offline,
     available,
@@ -57,6 +65,12 @@
   namesearch
 };
 
+enum setuiprio_ops {
+  prio_set, // Set priority
+  prio_max, // Set priority to max(specified, current)
+  prio_inc, // Increment priority
+};
+
 extern char *strprintstatus[];
 
 // Note: do not change the ordering as these values are visible
@@ -166,6 +180,9 @@
                          const char *realjid);
 void    roster_setflags(const char *jid, guint flags, guint value);
 void    roster_msg_setflag(const char *jid, guint special, guint value);
+void    roster_setuiprio(const char *jid, guint special, guint value,
+                         enum setuiprio_ops action);
+guint   roster_getuiprio(const char *jid, guint special);
 const char *roster_getname(const char *jid);
 const char *roster_getnickname(const char *jid);
 void    roster_settype(const char *jid, guint type);
@@ -226,6 +243,7 @@
 void    buddy_del_all_resources(gpointer rosterdata);
 void    buddy_setflags(gpointer rosterdata, guint flags, guint value);
 guint   buddy_getflags(gpointer rosterdata);
+guint   buddy_getuiprio(gpointer rosterdata);
 void    buddy_setonserverflag(gpointer rosterdata, guint onserver);
 guint   buddy_getonserverflag(gpointer rosterdata);
 GList  *buddy_search_jid(const char *jid);
--- a/mcabber/mcabber/screen.c	Sun Mar 21 15:10:51 2010 +0100
+++ b/mcabber/mcabber/screen.c	Sun Mar 21 15:13:33 2010 +0100
@@ -2926,6 +2926,41 @@
     roster_msg_setflag(bjid, special, TRUE);
 }
 
+//  scr_setattentionflag_if_needed(bare_jid, special, value, action)
+// Set the attention flag unless we're already in the jid buffer window
+// TODO: avoid code duplication with scr_setmsgflag_if_needed()
+void scr_setattentionflag_if_needed(const char *bjid, int special,
+                                    guint value, enum setuiprio_ops action)
+{
+  const char *current_id;
+  winbuf *wb;
+  bool iscurrentlocked = FALSE;
+
+  if (!bjid)
+    return;
+
+  wb = scr_search_window(bjid, special);
+  if (!wb)
+    return;
+
+  if (current_buddy) {
+    if (special)
+      current_id = buddy_getname(BUDDATA(current_buddy));
+    else
+      current_id = buddy_getjid(BUDDATA(current_buddy));
+    if (current_id) {
+      winbuf *win_entry = scr_search_window(current_id, special);
+      if (!win_entry) return;
+      iscurrentlocked = win_entry->bd->lock;
+    }
+  } else {
+    current_id = NULL;
+  }
+
+  if (!chatmode || !current_id || strcmp(bjid, current_id) || iscurrentlocked)
+    roster_setuiprio(bjid, special, value, action);
+}
+
 //  scr_set_multimode()
 // Public function to (un)set multimode...
 // Convention:
--- a/mcabber/mcabber/screen.h	Sun Mar 21 15:10:51 2010 +0100
+++ b/mcabber/mcabber/screen.h	Sun Mar 21 15:13:33 2010 +0100
@@ -116,6 +116,8 @@
 void scr_set_multimode(int enable, char *subject);
 int  scr_get_multimode(void);
 void scr_setmsgflag_if_needed(const char *jid, int special);
+void scr_setattentionflag_if_needed(const char *bjid, int special,
+                                    guint value, enum setuiprio_ops action);
 void scr_append_multiline(const char *line);
 const char *scr_get_multiline(void);
 const char *scr_get_multimode_subj(void);