changeset 116:1e7e59775f12

[/trunk] Changeset 130 by mikael * Add /status command. * Fix /quit command when there is a trailing word ("/quit bye"...). * Add an extension (.txt) to the TODO file.
author mikael
date Mon, 25 Apr 2005 15:26:17 +0000
parents 33bff2c57293
children e0168cdd9f59
files mcabber/src/commands.c mcabber/src/hooks.c mcabber/src/hooks.h mcabber/src/jabglue.c mcabber/src/jabglue.h
diffstat 6 files changed, 70 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Sun Apr 24 20:50:16 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-
-BUGS:
-
-* Should not stay on buddy buffer when one moves to a group
-* Pending message not displayed if buddy outside Contact window
-
-
-TODO:
-
-* Display status
-* show (how?) we can scroll in roster if not all buddies are displayed
-
-* Commands! :-)
-  - /roster <hide_offline|show_offline|top|bottom>
-  - /group <expand|shrink>
-  - /say blabla
-  - /say_to <jid> blabla
-  - /add <jid> [Name]
-  - /del [jid]
-  - /move [\<jid\>] <group>
-  - /nick (== rename <me> $@)
-  - /rename [\<jid\>] Name
-  - /info [jid]
-  - /request_auth [jid]
-  - /send_auth [jid]
-  - /status [online|avail|invisible|free|dnd|busy|notavail|away]
-    (and common shortcuts: /away, /online, /busy, /dnd)
-  - /rawxml...
-  - /search <\<jid\>|name>
-  - /clear
-  - /help
-* Command line history (^P/^N)
-* External commands for events
-* Multi-lines
-* Handle window resize
-* Save history
-* Shortcut to jump to next message received (shift-tab?)
-* File transfer? :)
-* Conferences :))
-* Show status changes in buddy window (if open)?  Could be great!
-* Auto away
-
--- a/mcabber/src/commands.c	Sun Apr 24 20:50:16 2005 +0000
+++ b/mcabber/src/commands.c	Mon Apr 25 15:26:17 2005 +0000
@@ -33,6 +33,7 @@
 // Commands callbacks
 void do_roster(char *arg);
 void do_clear(char *arg);
+void do_status(char *arg);
 
 // Global variable for the commands list
 static GSList *Commands;
@@ -73,7 +74,7 @@
   cmd_add("say", "Say something to the selected buddy", 0, 0, NULL);
   //cmd_add("search");
   //cmd_add("send_auth");
-  cmd_add("status", "Show or set your status", COMPL_STATUS, 0, NULL);
+  cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
 
   // Status category
   compl_add_category_word(COMPL_STATUS, "online");
@@ -171,9 +172,9 @@
     *p = 0;
 
   // Command "quit"?
-  if (!strcasecmp(line, "/quit")) {
-    return 255;
-  }
+  if (!strncasecmp(line, "/quit", 5))
+    if (!line[5] || line[5] == ' ')
+      return 255;
 
   // Commands handling
   curcmd = cmd_get(line);
@@ -226,3 +227,31 @@
   scr_Clear();
 }
 
+void do_status(char *arg)
+{
+  enum imstatus st;
+
+  if (!arg || (*arg == 0)) {
+    scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]);
+    return;
+  }
+
+  if (!strcmp(arg, "offline"))        st = offline;
+  else if (!strcmp(arg, "online"))    st = available;
+  else if (!strcmp(arg, "avail"))     st = available;
+  else if (!strcmp(arg, "away"))      st = away;
+  else if (!strcmp(arg, "invisible")) st = invisible;
+  else if (!strcmp(arg, "dnd"))       st = dontdisturb;
+  else if (!strcmp(arg, "busy"))      st = occupied;
+  else if (!strcmp(arg, "notavail"))  st = notavail;
+  else if (!strcmp(arg, "free"))      st = freeforchat;
+  else {
+    // XXX TODO no parameter == status request
+    scr_LogPrint("Unrecognized parameter!");
+    return;
+  }
+
+  // XXX special case if offline??
+  jb_setstatus(st, NULL);  // TODO handle message (instead of NULL)
+}
+
--- a/mcabber/src/hooks.c	Sun Apr 24 20:50:16 2005 +0000
+++ b/mcabber/src/hooks.c	Mon Apr 25 15:26:17 2005 +0000
@@ -51,3 +51,18 @@
   hlog_write_status(jid, 0, status);
 }
 
+// XXX Maybe we should get the old status as a parameter and request the
+// current status to jabglue?  Or get both statuses?
+inline void hk_mystatuschange(time_t timestamp,
+        enum imstatus old_status, enum imstatus new_status)
+{
+  if (old_status == new_status)
+    return;
+
+  scr_LogPrint("Your status has changed: [%c>%c]",
+          imstatus2char[old_status], imstatus2char[new_status]);
+  //roster_setstatus(jid, status);
+  //hlog_write_status(NULL, 0, status);
+
+}
+
--- a/mcabber/src/hooks.h	Sun Apr 24 20:50:16 2005 +0000
+++ b/mcabber/src/hooks.h	Mon Apr 25 15:26:17 2005 +0000
@@ -9,5 +9,7 @@
 inline void hk_message_out(const char *jid, time_t timestamp, const char *msg);
 inline void hk_statuschange(const char *jid, time_t timestamp, 
         enum imstatus status);
+inline void hk_mystatuschange(time_t timestamp,
+        enum imstatus old_status, enum imstatus new_status);
 
 #endif /* __HOOKS_H__ */
--- a/mcabber/src/jabglue.c	Sun Apr 24 20:50:16 2005 +0000
+++ b/mcabber/src/jabglue.c	Mon Apr 25 15:26:17 2005 +0000
@@ -36,6 +36,7 @@
 unsigned int KeepaliveDelay;
 static int s_id = 1;  // FIXME which use??
 static int regmode, regdone;
+static enum imstatus mystatus = offline;
 unsigned char online;
 
 char imstatus2char[imstatus_size] = {
@@ -203,9 +204,19 @@
   }
 }
 
-void setjabberstatus(enum imstatus st, char *msg)
+inline enum imstatus jb_getstatus()
+{
+  return mystatus;
+}
+
+void jb_setstatus(enum imstatus st, char *msg)
 {
-  xmlnode x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
+  xmlnode x;
+
+  if (!online)
+    return;
+
+  x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
 
   switch(st) {
     case away:
@@ -243,7 +254,7 @@
             add["prio"].c_str(), (unsigned) -1);
   */
 
-  if (!msg || !*msg) {
+  if (!msg) {
     msg  = ""; // FIXME
     //msg = imstatus2str(st);
   }
@@ -254,9 +265,10 @@
   jab_send(jc, x);
   xmlnode_free(x);
 
-  //sendvisibility();
+  //sendvisibility();   ???
 
-  // XXX logger.putourstatus(proto, getstatus(), ourstatus = st);
+  hk_mystatuschange(0, mystatus, st);
+  mystatus = st;
 }
 
 void jb_send_msg(const char *jid, const char *text)
@@ -276,7 +288,7 @@
 
   //setautostatus(jhook.manualstatus);
 
-  setjabberstatus(1, "I'm here!");
+  jb_setstatus(available, "I'm here!"); // XXX not always "available"...
   buddylist_build();
   /*
   for (i = 0; i < clist.count; i++) {
--- a/mcabber/src/jabglue.h	Sun Apr 24 20:50:16 2005 +0000
+++ b/mcabber/src/jabglue.h	Mon Apr 25 15:26:17 2005 +0000
@@ -30,6 +30,8 @@
 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass);
 void jb_disconnect(void);
 void jb_main();
+inline enum imstatus jb_getstatus();
+void jb_setstatus(enum imstatus st, char *msg);
 void jb_send_msg(const char *, const char *);
 void jb_keepalive();
 inline void jb_reset_keepalive();