changeset 13761:ec858948d292

[gaim-migrate @ 16173] SF Patch #1482854 from Sadrul "This exposes the savedstatuses-api to dbus and makes the "setstatus" command work for gaim-remot committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 10 May 2006 17:31:25 +0000
parents fb177706f6ba
children f13659375212
files src/Makefile.am src/dbus-server.c src/gaim-remote.py src/savedstatuses.c
diffstat 4 files changed, 33 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Wed May 10 12:17:21 2006 +0000
+++ b/src/Makefile.am	Wed May 10 17:31:25 2006 +0000
@@ -176,7 +176,7 @@
 dbus_sources  = dbus-server.c dbus-useful.c
 dbus_headers  = dbus-bindings.h dbus-gaim.h dbus-server.h dbus-useful.h dbus-define-api.h
 
-dbus_exported = dbus-useful.h dbus-define-api.h account.h blist.h buddyicon.h connection.h conversation.h core.h roomlist.h status.h server.h
+dbus_exported = dbus-useful.h dbus-define-api.h account.h blist.h buddyicon.h connection.h conversation.h core.h roomlist.h savedstatuses.h status.h server.h
 
 gaim_build_coreheaders = $(addprefix $(srcdir)/, $(gaim_coreheaders))
 dbus_build_exported = $(addprefix $(srcdir)/, $(dbus_exported))
--- a/src/dbus-server.c	Wed May 10 12:17:21 2006 +0000
+++ b/src/dbus-server.c	Wed May 10 17:31:25 2006 +0000
@@ -36,6 +36,7 @@
 #include "dbus-bindings.h"
 #include "debug.h"
 #include "core.h"
+#include "savedstatuses.h"
 #include "value.h"
 
 
--- a/src/gaim-remote.py	Wed May 10 12:17:21 2006 +0000
+++ b/src/gaim-remote.py	Wed May 10 17:31:25 2006 +0000
@@ -97,17 +97,34 @@
                                               params.get("group", ""), "")
 
     elif command == "setstatus":
+        current = gaim.GaimSavedstatusGetCurrent()
+
+        if "status" in params:
+            status_id = params["status"]
+            status_type = gaim.GaimPrimitiveGetTypeFromId(status_id)
+        else:
+            status_type = gaim.GaimSavedStatusGetType(current)
+            status_id = gaim.GaimPrimitiveGetIdFromType(status_type)
+
+        if "message" in params:
+            message = params["message"];
+        else:
+            message = gaim.GaimSavedstatusGetMessage(current)
+
         if "account" in params:
             accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)]
+
+            for account in accounts:
+                status = gaim.GaimAccountGetStatus(account, status_id)
+                type = gaim.GaimStatusGetType(status)
+                gaim.GaimSavedstatusSetSubstatus(current, account, type, message)
+                gaim.GaimSavedstatusActivateForAccount(current, account)
         else:
             accounts = gaim.GaimAccountsGetAllActive()
+            saved = gaim.GaimSavedstatusNew("", status_type)
+            gaim.GaimSavedstatusSetMessage(saved, message)
+            gaim.GaimSavedstatusActivate(saved)
 
-        for account in accounts:
-            status = cgaim.GaimAccountGetStatus(account, params["status"])
-            for key, value in params.items():
-                if key not in ["status", "account"]:
-                    gaim.GaimStatusSetAttrString(status, key, value)
-            gaim.GaimAccountSetStatusVargs(account, params["status"], 1)
         return None
 
     elif command == "getinfo":
--- a/src/savedstatuses.c	Wed May 10 12:17:21 2006 +0000
+++ b/src/savedstatuses.c	Wed May 10 17:31:25 2006 +0000
@@ -1,5 +1,5 @@
 /**
- * @file savedstatus.c Saved Status API
+ * @file savedstatuses.c Saved Status API
  * @ingroup core
  *
  * gaim
@@ -27,6 +27,7 @@
 #include "debug.h"
 #include "notify.h"
 #include "savedstatuses.h"
+#include "dbus-maybe.h"
 #include "status.h"
 #include "util.h"
 #include "xmlnode.h"
@@ -108,6 +109,7 @@
 	g_return_if_fail(substatus != NULL);
 
 	g_free(substatus->message);
+	GAIM_DBUS_UNREGISTER_POINTER(substatus);
 	g_free(substatus);
 }
 
@@ -126,6 +128,7 @@
 		free_saved_status_sub(substatus);
 	}
 
+	GAIM_DBUS_UNREGISTER_POINTER(status);
 	g_free(status);
 }
 
@@ -369,6 +372,7 @@
 	char *data;
 
 	ret = g_new0(GaimSavedStatusSub, 1);
+	GAIM_DBUS_REGISTER_POINTER(ret, GaimSavedStatusSub);
 
 	/* Read the account */
 	node = xmlnode_get_child(substatus, "account");
@@ -442,6 +446,7 @@
 	int i;
 
 	ret = g_new0(GaimSavedStatus, 1);
+	GAIM_DBUS_REGISTER_POINTER(ret, GaimSavedStatus);
 
 	attrib = xmlnode_get_attrib(status, "transient");
 	if ((attrib == NULL) || (strcmp(attrib, "true")))
@@ -547,6 +552,7 @@
 		g_return_val_if_fail(gaim_savedstatus_find(title) == NULL, NULL);
 
 	status = g_new0(GaimSavedStatus, 1);
+	GAIM_DBUS_REGISTER_POINTER(status, GaimSavedStatus);
 	status->title = g_strdup(title);
 	status->type = type;
 	set_creation_time(status, time(NULL));
@@ -613,6 +619,7 @@
 	if (substatus == NULL)
 	{
 		substatus = g_new0(GaimSavedStatusSub, 1);
+		GAIM_DBUS_REGISTER_POINTER(substatus, GaimSavedStatusSub);
 		substatus->account = (GaimAccount *)account;
 		saved_status->substatuses = g_list_prepend(saved_status->substatuses, substatus);
 	}