Introduce special buffer stuff
Update roster and commands: add support for a new "special" kind of buffer.
A special buffer "[status]" is automatically created at startup.
--- a/mcabber/src/commands.c Mon May 08 22:38:30 2006 +0200
+++ b/mcabber/src/commands.c Mon May 08 23:45:58 2006 +0200
@@ -1121,7 +1121,8 @@
} else {
if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name);
scr_LogPrint(LPRINT_NORMAL, "Type: %s",
- ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown"));
+ type == ROSTER_TYPE_GROUP ? "group" :
+ (type == ROSTER_TYPE_SPECIAL ? "special" : "unknown"));
}
g_free(buffer);
@@ -1193,6 +1194,10 @@
scr_LogPrint(LPRINT_NORMAL, "You can't rename groups.");
return;
}
+ if (type & ROSTER_TYPE_SPECIAL) {
+ scr_LogPrint(LPRINT_NORMAL, "You can't rename this item.");
+ return;
+ }
newname = g_strdup(arg);
// Remove trailing space
@@ -1231,6 +1236,10 @@
scr_LogPrint(LPRINT_NORMAL, "You can't move groups!");
return;
}
+ if (type & ROSTER_TYPE_SPECIAL) {
+ scr_LogPrint(LPRINT_NORMAL, "You can't move this item.");
+ return;
+ }
newgroupname = g_strdup(arg);
// Remove trailing space
--- a/mcabber/src/main.c Mon May 08 22:38:30 2006 +0200
+++ b/mcabber/src/main.c Mon May 08 23:45:58 2006 +0200
@@ -252,8 +252,9 @@
}
}
- /* Initialize commands system */
+ /* Initialize commands system and roster */
cmd_init();
+ roster_init();
/* Initialize charset */
scr_InitLocaleCharSet();
--- a/mcabber/src/roster.c Mon May 08 22:38:30 2006 +0200
+++ b/mcabber/src/roster.c Mon May 08 23:45:58 2006 +0200
@@ -89,10 +89,20 @@
GList *current_buddy;
GList *alternate_buddy;
+static roster roster_special;
+
void unread_jid_add(const char *jid);
int unread_jid_del(const char *jid);
+/* ### Initialization ### */
+
+void roster_init(void)
+{
+ roster_special.name = "[status]";
+ roster_special.type = ROSTER_TYPE_SPECIAL;
+}
+
/* ### Resources functions ### */
static void free_all_resources(GSList **reslist)
@@ -715,6 +725,8 @@
buddylist = NULL;
}
+ buddylist = g_list_append(buddylist, &roster_special);
+
// Create the new list
while (sl_roster_elt) {
GSList *sl_roster_usrelt;
@@ -936,6 +948,9 @@
if (roster_usr->type & ROSTER_TYPE_GROUP)
return roster_usr->name;
+ if (roster_usr->type & ROSTER_TYPE_SPECIAL)
+ return NULL;
+
// This is a user
return ((roster*)((GSList*)roster_usr->list)->data)->name;
}
@@ -949,6 +964,9 @@
if (roster_usr->type & ROSTER_TYPE_GROUP)
return rosterdata;
+ if (roster_usr->type & ROSTER_TYPE_SPECIAL)
+ return NULL;
+
// This is a user
return (gpointer)((GSList*)roster_usr->list)->data;
}
@@ -1206,6 +1224,8 @@
while (sl_roster_elt) { // group list loop
roster_elt = (roster*) sl_roster_elt->data;
+ if (roster_elt->type & ROSTER_TYPE_SPECIAL)
+ continue; // Skip special items
sl_roster_usrelt = roster_elt->list;
while (sl_roster_usrelt) { // user list loop
roster_usrelt = (roster*) sl_roster_usrelt->data;
--- a/mcabber/src/roster.h Mon May 08 22:38:30 2006 +0200
+++ b/mcabber/src/roster.h Mon May 08 23:45:58 2006 +0200
@@ -63,6 +63,7 @@
#define ROSTER_TYPE_GROUP 2
#define ROSTER_TYPE_AGENT 4
#define ROSTER_TYPE_ROOM 8
+#define ROSTER_TYPE_SPECIAL 16
// Flags:
#define ROSTER_FLAG_MSG 1 // Message not read
@@ -80,6 +81,7 @@
#define CURRENT_JID buddy_getjid(BUDDATA(current_buddy))
// Prototypes...
+void roster_init(void);
GSList *roster_add_group(const char *name);
GSList *roster_add_user(const char *jid, const char *name, const char *group,
guint type, enum subscr esub);
--- a/mcabber/src/screen.c Mon May 08 22:38:30 2006 +0200
+++ b/mcabber/src/screen.c Mon May 08 23:45:58 2006 +0200
@@ -833,7 +833,7 @@
// Set forceupdate to TRUE if doupdate() must be called.
void scr_UpdateChatStatus(int forceupdate)
{
- unsigned short btype, isgrp, ismuc;
+ unsigned short btype, isgrp, ismuc, isspe;
const char *fullname;
const char *msg = NULL;
char status;
@@ -862,10 +862,14 @@
isgrp = btype & ROSTER_TYPE_GROUP;
ismuc = btype & ROSTER_TYPE_ROOM;
+ isspe = btype & ROSTER_TYPE_SPECIAL;
- if (isgrp) {
+ if (isgrp || isspe) {
buf_locale = from_utf8(fullname);
- mvwprintw(chatstatusWnd, 0, 5, "Group: %s", buf_locale);
+ if (isgrp)
+ mvwprintw(chatstatusWnd, 0, 5, "Group: %s", buf_locale);
+ else
+ mvwprintw(chatstatusWnd, 0, 5, "Special buffer: %s", buf_locale);
g_free(buf_locale);
if (forceupdate) {
update_panels();
@@ -985,7 +989,7 @@
rOffset = offset;
for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
- unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid;
+ unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid, isspe;
gchar *rline_locale;
bflags = buddy_getflags(BUDDATA(buddy));
@@ -995,6 +999,7 @@
ishid = bflags & ROSTER_FLAG_HIDE;
isgrp = btype & ROSTER_TYPE_GROUP;
ismuc = btype & ROSTER_TYPE_ROOM;
+ isspe = btype & ROSTER_TYPE_SPECIAL;
if (rOffset > 0) {
rOffset--;
@@ -1049,6 +1054,8 @@
else
sep = "---";
snprintf(rline, Roster_Width, " %c%s %s", pending, sep, name);
+ } else if (isspe) {
+ snprintf(rline, Roster_Width, " %c%s", pending, name);
} else {
char sepleft = '[';
char sepright = ']';