[extsay] Multiple improvements
authorMikael Berthe <mikael@lilotux.net>
Sat, 03 Apr 2010 00:50:17 +0200
changeset 23 cf95a475825c
parent 22 b6b45c2eb022
child 24 81cbb47f1aa6
[extsay] Multiple improvements
extsay-ng/README
extsay-ng/extsay.sh
extsay-ng/extsayng.c
--- a/extsay-ng/README	Fri Apr 02 23:45:20 2010 +0200
+++ b/extsay-ng/README	Sat Apr 03 00:50:17 2010 +0200
@@ -2,6 +2,7 @@
     ** Module extsay-ng **
 
 To use this module, you have to be running the screen utility.
+MCabber's FIFO system must be enabled.
 
 Copy the script extsay.sh to some place on your system and set the mcabber
 option 'extsay_script_path' to the file path.  You can set it in your mcabber
@@ -11,10 +12,11 @@
 
 When you type /extsay, the module will send a command to screen to open a
 new window and run the helper script in it.
+This helper scripts launches an editor ($EDITOR), and sends the message using
+the FIFO mechanism.
 
-WARNING: If you do not provide a JID, the selected user _at the time you
-close the editor_ will be used.  Be careful not to select another contact
-while you're editing your message!
+Please note that this script will not work if the editor does detach from
+the terminal.
 
 Hope you find this module useful, do not hesitate to send patches for
 improvements!
--- a/extsay-ng/extsay.sh	Fri Apr 02 23:45:20 2010 +0200
+++ b/extsay-ng/extsay.sh	Sat Apr 03 00:50:17 2010 +0200
@@ -30,10 +30,12 @@
 # Send the message using MCabber's pipe
 if [ -s $tf ]; then
     cmd="say_to -f $tf $jid"
-    echo $cmd >> $FIFOPATH
+else
+    cmd="echo [extsay] The file has not been modified.  Message cancelled."
 fi
+echo $cmd >> $FIFOPATH
 
 # Do not remove the file too soon
-(sleep 20 ; rm $tf)&
+setsid sh -c "cd / && sleep 20 && rm $tf & :" /dev/null 2>&1 < /dev/null
 
 exit 0
--- a/extsay-ng/extsayng.c	Fri Apr 02 23:45:20 2010 +0200
+++ b/extsay-ng/extsayng.c	Sat Apr 03 00:50:17 2010 +0200
@@ -45,7 +45,7 @@
 };
 
 // Forks and run the external helper script
-static void screen_run_script(const char *args)
+static void screen_run_script(const gchar *args)
 {
   GError *err = NULL;
   gchar *argv[] = { "screen", "-r", "-X", "screen", NULL, NULL, NULL };
@@ -65,19 +65,34 @@
     argv[5] = ".";
 
   ret = g_spawn_async(NULL, argv, NULL,
-                      G_SPAWN_SEARCH_PATH, //|
-                      //  G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
+                      G_SPAWN_SEARCH_PATH |
+                        G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
                       NULL, NULL, NULL, &err);
 
   if (!ret)
     scr_LogPrint(LPRINT_NORMAL, err->message);
 }
 
-static void do_extsayng(char *args)
+static void do_extsayng(gchar *args)
 {
-  // TODO - check the selected item is a real contact
-  // (not a special buffer, nor a group...)
-  // TODO provide JID if it isn't provided
+  gpointer bud;
+
+  if (!args || !*args || !g_strcmp0(args, ".")) {
+    if (!current_buddy) {
+      scr_LogPrint(LPRINT_NORMAL, "Please select a buddy.");
+      return;
+    }
+
+    bud = BUDDATA(current_buddy);
+    if (!(buddy_gettype(bud) &
+          (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM))) {
+      scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
+      return;
+    }
+
+    args = (gchar*)buddy_getjid(bud);
+  }
+
   screen_run_script(args);
 }