changeset 11724:a8ec0a291d14

[gaim-migrate @ 14015] If you're online, and sitting around, and la-di-da you enable one of your accounts, it will now use the status currently set in your gtkstatusbox instead of whatever the account was set to when it was disabled committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 22 Oct 2005 22:29:40 +0000
parents 9537977703bb
children 743b574c81b9
files src/gtkaccount.c src/gtkstatusbox.c src/gtkstatusbox.h src/idle.c src/savedstatuses.c src/savedstatuses.h
diffstat 6 files changed, 70 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkaccount.c	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/gtkaccount.c	Sat Oct 22 22:29:40 2005 +0000
@@ -35,6 +35,7 @@
 #include "prefs.h"
 #include "prpl.h"
 #include "request.h"
+#include "savedstatuses.h"
 #include "signals.h"
 #include "util.h"
 
@@ -2129,6 +2130,8 @@
 	GtkTreeModel *model = GTK_TREE_MODEL(dialog->model);
 	GtkTreeIter iter;
 	gboolean enabled;
+	const char *current_savedstatus_name;
+	const GaimSavedStatus *saved_status;
 
 	gtk_tree_model_get_iter_from_string(model, &iter, path_str);
 	gtk_tree_model_get(model, &iter,
@@ -2136,20 +2139,11 @@
 					   COLUMN_ENABLED, &enabled,
 					   -1);
 
-	/* TODO: Set the statuses for this account to match the GtkStatusBox */
-	/*
-	GtkWidget *blist;
-	GtkWidget *statusbox;
-	GaimStatus *status;
-
-	blist = gaim_gtk_blist_get_default_gtk_blist();
-	statusbox = blist->statusbox;
-	status = gaim_gtk_status_box_get_current_status();
-
-	gaim_account_set_status(account, );
-	gaim_account_set_status_vargs(account, );
-	gaim_account_set_status_list(account, );
-	*/
+	/* Set the statuses for this account to the current status */
+	current_savedstatus_name = gaim_prefs_get_string("/core/status/current");
+	saved_status = gaim_savedstatus_find(current_savedstatus_name);
+	gaim_savedstatus_activate_for_account(saved_status, account);
+
 	gaim_account_set_enabled(account, GAIM_GTK_UI, !enabled);
 
 	gtk_list_store_set(dialog->model, &iter,
--- a/src/gtkstatusbox.c	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/gtkstatusbox.c	Sat Oct 22 22:29:40 2005 +0000
@@ -499,11 +499,6 @@
 	gtk_gaim_status_box_refresh(status_box);
 }
 
-void
-gtk_gaim_status_box_activate_saved_status(GaimSavedStatus *saved_status)
-{
-}
-
 static void
 activate_currently_selected_status(GtkGaimStatusBox *status_box)
 {
--- a/src/gtkstatusbox.h	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/gtkstatusbox.h	Sat Oct 22 22:29:40 2005 +0000
@@ -119,8 +119,6 @@
 void
 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box);
 
-void gtk_gaim_status_box_activate_saved_status(GaimSavedStatus *saved_status);
-
 char *gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box);
 
 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box);
--- a/src/idle.c	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/idle.c	Sat Oct 22 22:29:40 2005 +0000
@@ -35,7 +35,6 @@
 
 #include "connection.h"
 #include "debug.h"
-#include "gtkstatusbox.h"
 #include "log.h"
 #include "prefs.h"
 #include "savedstatuses.h"
@@ -158,11 +157,10 @@
 			gaim_debug_info("idle", "Making %s auto-away\n",
 							gaim_account_get_username(account));
 
-			/* TODO XXX STATUS AWAY CORE/UI */
 			/* Mark our accounts "away" using the idleaway status */
 			idleaway_name = gaim_prefs_get_string("/core/status/idleaway");
 			saved_status = gaim_savedstatus_find(idleaway_name);
-			gtk_gaim_status_box_activate_saved_status(saved_status);
+			gaim_savedstatus_activate(saved_status);
 
 			gc->is_auto_away = GAIM_IDLE_AUTO_AWAY;
 		} else {
--- a/src/savedstatuses.c	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/savedstatuses.c	Sat Oct 22 22:29:40 2005 +0000
@@ -498,6 +498,49 @@
 	return (saved_status->substatuses != NULL);
 }
 
+void
+gaim_savedstatus_activate(const GaimSavedStatus *saved_status)
+{
+	GList *accounts;
+
+	accounts = gaim_accounts_get_all_active();
+
+	while (accounts != NULL)
+	{
+		GaimAccount *account;
+
+		account = accounts->data;
+		gaim_savedstatus_activate_for_account(saved_status, account);
+		accounts = accounts->next;
+	}
+}
+
+void
+gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status,
+									  GaimAccount *account)
+{
+	const GList *status_types;
+	GaimStatusType *status_type;
+
+	/* Find the status type that matches the given primitive */
+	status_types = gaim_account_get_status_types(account);
+	while (status_types != NULL)
+	{
+		status_type = status_types->data;
+		if (gaim_status_type_get_primitive(status_type) == saved_status->type)
+		{
+			if (saved_status->message != NULL)
+				gaim_account_set_status(account, gaim_status_type_get_id(status_type),
+										TRUE, "message", saved_status->message, NULL);
+			else
+				gaim_account_set_status(account, gaim_status_type_get_id(status_type),
+										TRUE, NULL);
+			return;
+		}
+		status_types = status_types->next;
+	}
+}
+
 void *
 gaim_savedstatuses_get_handle(void)
 {
--- a/src/savedstatuses.h	Sat Oct 22 22:13:19 2005 +0000
+++ b/src/savedstatuses.h	Sat Oct 22 22:29:40 2005 +0000
@@ -168,6 +168,24 @@
 gboolean gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status);
 
 /**
+ * Sets the statuses for all your accounts to those specified
+ * by the given saved_status.  This function calls
+ * gaim_savedstatus_activate_for_account() for all your accounts.
+ *
+ * @param saved_status The status you want to set your accounts to.
+ */
+void gaim_savedstatus_activate(const GaimSavedStatus *saved_status);
+
+/**
+ * Sets the statuses for a given account to those specified
+ * by the given saved_status.
+ *
+ * @param saved_status The status you want to set your accounts to.
+ * @param account      The account whose statuses you want to change.
+ */
+void gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status, GaimAccount *account);
+
+/**
  * Get the handle for the status subsystem.
  *
  * @return the handle to the status subsystem