# HG changeset patch # User Mark Doliner # Date 1155630149 0 # Node ID a8a033a89ee03aba2323ac686fb8b861eac4e897 # Parent 9a4b76c288aa6619c816877d9499900458addc85 [gaim-migrate @ 16766] I'm hoping this will fix a lot of the remaining idle-away problems, like not correctly returning from idle-away. This change also causes the gtkstatusbox to show your idle-away status when you are idle-away. Please test everything and let me know if there are any problems. committer: Tailor Script diff -r 9a4b76c288aa -r a8a033a89ee0 src/connection.h --- a/src/connection.h Tue Aug 15 07:23:13 2006 +0000 +++ b/src/connection.h Tue Aug 15 08:22:29 2006 +0000 @@ -89,8 +89,6 @@ guint keepalive; /**< Keep-alive. */ - gboolean is_auto_away; /**< Whether or not it's auto-away. */ - gboolean wants_to_die; /**< Wants to Die state. This is set when the user chooses to log out, or when the protocol is diff -r 9a4b76c288aa -r a8a033a89ee0 src/gtkstatusbox.c --- a/src/gtkstatusbox.c Tue Aug 15 07:23:13 2006 +0000 +++ b/src/gtkstatusbox.c Tue Aug 15 08:22:29 2006 +0000 @@ -257,6 +257,7 @@ statusbox, GAIM_CALLBACK(account_status_changed_cb)); statusbox->status_changed_signal = 0; } + gaim_signals_disconnect_by_handle(statusbox); gaim_prefs_disconnect_by_handle(statusbox); G_OBJECT_CLASS(parent_class)->finalize(obj); @@ -829,8 +830,7 @@ } static void -current_status_pref_changed_cb(const char *name, GaimPrefType type, - gconstpointer val, gpointer data) +current_savedstatus_changed_cb(GaimSavedStatus *now, GaimSavedStatus *old, gpointer data) { GtkGaimStatusBox *status_box = data; @@ -1000,8 +1000,10 @@ gtk_gaim_status_box_regenerate(status_box); gtk_gaim_status_box_refresh(status_box); - gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", - current_status_pref_changed_cb, status_box); + gaim_signal_connect(gaim_savedstatuses_get_handle(), "savedstatus-changed", + status_box, + GAIM_CALLBACK(current_savedstatus_changed_cb), + status_box); gaim_prefs_connect_callback(status_box, "/gaim/gtk/blist/show_buddy_icons", buddy_list_details_pref_changed_cb, status_box); gaim_prefs_connect_callback(status_box, "/gaim/gtk/conversations/spellcheck", @@ -1253,9 +1255,8 @@ * "Saved..." or a popular status then do nothing. * Popular statuses are * activated elsewhere, and we update the status_box - * accordingly by monitoring the preference - * "/core/savedstatus/current" and then calling - * status_menu_refresh_iter() + * accordingly by connecting to the savedstatus-changed + * signal and then calling status_menu_refresh_iter() */ if (type != GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) return; diff -r 9a4b76c288aa -r a8a033a89ee0 src/idle.c --- a/src/idle.c Tue Aug 15 07:23:13 2006 +0000 +++ b/src/idle.c Tue Aug 15 08:22:29 2006 +0000 @@ -58,63 +58,6 @@ static time_t last_active_time = 0; static void -set_account_autoaway(GaimConnection *gc) -{ - GaimAccount *account; - GaimPresence *presence; - GaimStatus *status; - - if (gc->is_auto_away) - /* This account is already auto-away! */ - return; - - account = gaim_connection_get_account(gc); - presence = gaim_account_get_presence(account); - status = gaim_presence_get_active_status(presence); - - if (gaim_status_is_available(status)) - { - GaimSavedStatus *saved_status; - - gaim_debug_info("idle", "Making %s auto-away\n", - gaim_account_get_username(account)); - - saved_status = gaim_savedstatus_get_idleaway(); - gaim_savedstatus_activate_for_account(saved_status, account); - - gc->is_auto_away = GAIM_IDLE_AUTO_AWAY; - } else { - gc->is_auto_away = GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY; - } -} - -static void -unset_account_autoaway(GaimConnection *gc) -{ - GaimAccount *account; - GaimSavedStatus *saved_status; - - account = gaim_connection_get_account(gc); - - if (!gc->is_auto_away) - /* This account is already not auto-away! */ - return; - - if (gc->is_auto_away == GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY) { - gc->is_auto_away = GAIM_IDLE_NOT_AWAY; - } else { - gc->is_auto_away = GAIM_IDLE_NOT_AWAY; - - gaim_debug_info("idle", "%s returning from auto-away\n", - gaim_account_get_username(account)); - - /* Return our account to its previous status */ - saved_status = gaim_savedstatus_get_current(); - gaim_savedstatus_activate_for_account(saved_status, account); - } -} - -static void set_account_idle(GaimAccount *account, int time_idle) { GaimPresence *presence; @@ -203,13 +146,11 @@ if (auto_away && (time_idle > (60 * gaim_prefs_get_int("/core/away/mins_before_away")))) { - for (l = gaim_connections_get_all(); l != NULL; l = l->next) - set_account_autoaway(l->data); + gaim_savedstatus_set_idleaway(TRUE); } else if (time_idle < 60 * gaim_prefs_get_int("/core/away/mins_before_away")) { - for (l = gaim_connections_get_all(); l != NULL; l = l->next) - unset_account_autoaway(l->data); + gaim_savedstatus_set_idleaway(FALSE); } /* Idle reporting stuff */ @@ -252,7 +193,6 @@ account = gaim_connection_get_account(gc); set_account_unidle(account); - unset_account_autoaway(gc); } void diff -r 9a4b76c288aa -r a8a033a89ee0 src/savedstatuses.c --- a/src/savedstatuses.c Tue Aug 15 07:23:13 2006 +0000 +++ b/src/savedstatuses.c Tue Aug 15 08:22:29 2006 +0000 @@ -25,6 +25,7 @@ #include "internal.h" #include "debug.h" +#include "idle.h" #include "notify.h" #include "savedstatuses.h" #include "dbus-maybe.h" @@ -676,9 +677,9 @@ * If we just deleted our current status or our idleaway status, * then set the appropriate pref back to 0. */ - current = gaim_prefs_get_int("/core/savedstatus/current"); + current = gaim_prefs_get_int("/core/savedstatus/default"); if (current == creation_time) - gaim_prefs_set_int("/core/savedstatus/current", 0); + gaim_prefs_set_int("/core/savedstatus/default", 0); idleaway = gaim_prefs_get_int("/core/savedstatus/idleaway"); if (idleaway == creation_time) @@ -725,12 +726,21 @@ } GaimSavedStatus * -gaim_savedstatus_get_current() +gaim_savedstatus_get_current(void) +{ + if (gaim_savedstatus_is_idleaway()) + return gaim_savedstatus_get_idleaway(); + else + return gaim_savedstatus_get_default(); +} + +GaimSavedStatus * +gaim_savedstatus_get_default() { int creation_time; GaimSavedStatus *saved_status = NULL; - creation_time = gaim_prefs_get_int("/core/savedstatus/current"); + creation_time = gaim_prefs_get_int("/core/savedstatus/default"); if (creation_time != 0) saved_status = g_hash_table_lookup(creation_times, &creation_time); @@ -744,7 +754,7 @@ * using? In any case, add a default status. */ saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AVAILABLE); - gaim_prefs_set_int("/core/savedstatus/current", + gaim_prefs_set_int("/core/savedstatus/default", gaim_savedstatus_get_creation_time(saved_status)); } @@ -780,6 +790,51 @@ return saved_status; } +gboolean +gaim_savedstatus_is_idleaway() +{ + return gaim_prefs_get_bool("/core/savedstatus/isidleaway"); +} + +void +gaim_savedstatus_set_idleaway(gboolean idleaway) +{ + GList *accounts, *node; + GaimSavedStatus *old, *saved_status; + + if (gaim_savedstatus_is_idleaway() == idleaway) + /* Don't need to do anything */ + return; + + /* Changing our status makes us un-idle */ + if (!idleaway) + gaim_idle_touch(); + + old = gaim_savedstatus_get_current(); + gaim_prefs_set_bool("/core/savedstatus/isidleaway", idleaway); + saved_status = gaim_savedstatus_get_current(); + + accounts = gaim_accounts_get_all_active(); + for (node = accounts; node != NULL; node = node->next) + { + GaimAccount *account; + GaimPresence *presence; + GaimStatus *status; + + account = node->data; + presence = gaim_account_get_presence(account); + status = gaim_presence_get_active_status(presence); + + if (!idleaway || gaim_status_is_available(status)) + gaim_savedstatus_activate_for_account(saved_status, account); + } + + g_list_free(accounts); + + gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed", + saved_status, old); +} + GaimSavedStatus * gaim_savedstatus_get_startup() { @@ -1001,12 +1056,12 @@ g_list_free(accounts); - gaim_prefs_set_int("/core/savedstatus/current", + gaim_prefs_set_int("/core/savedstatus/default", gaim_savedstatus_get_creation_time(saved_status)); + gaim_savedstatus_set_idleaway(FALSE); gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed", saved_status, old); - } void @@ -1070,10 +1125,11 @@ * saved status and return that to the user. */ gaim_prefs_add_none("/core/savedstatus"); - gaim_prefs_add_int("/core/savedstatus/current", 0); + gaim_prefs_add_int("/core/savedstatus/default", 0); gaim_prefs_add_int("/core/savedstatus/startup", 0); gaim_prefs_add_bool("/core/savedstatus/startup_current_status", TRUE); gaim_prefs_add_int("/core/savedstatus/idleaway", 0); + gaim_prefs_add_bool("/core/savedstatus/isidleaway", FALSE); load_statuses(); diff -r 9a4b76c288aa -r a8a033a89ee0 src/savedstatuses.h --- a/src/savedstatuses.h Tue Aug 15 07:23:13 2006 +0000 +++ b/src/savedstatuses.h Tue Aug 15 08:22:29 2006 +0000 @@ -171,7 +171,9 @@ GList *gaim_savedstatuses_get_popular(unsigned int how_many); /** - * Returns the currently selected saved status. + * Returns the currently selected saved status. If we are idle + * then this returns gaim_savedstatus_get_idleaway(). Otherwise + * it returns gaim_savedstatus_get_default(). * * @return A pointer to the in-use GaimSavedStatus. * This function never returns NULL. @@ -179,7 +181,16 @@ GaimSavedStatus *gaim_savedstatus_get_current(void); /** - * Returns the saved status that gets used when your + * Returns the default saved status that is used when our + * accounts are not idle-away. + * + * @return A pointer to the in-use GaimSavedStatus. + * This function never returns NULL. + */ +GaimSavedStatus *gaim_savedstatus_get_default(void); + +/** + * Returns the saved status that is used when your * accounts become idle-away. * * @return A pointer to the idle-away GaimSavedStatus. @@ -188,6 +199,23 @@ GaimSavedStatus *gaim_savedstatus_get_idleaway(void); /** + * Return TRUE if we are currently idle-away. Otherwise + * returns FALSE. + * + * @return TRUE if our accounts have been set to idle-away. + */ +gboolean gaim_savedstatus_is_idleaway(void); + +/** + * Set whether accounts in Gaim are idle-away or not. + * + * @param TRUE if accounts should be switched to use the + * idle-away saved status. FALSE if they should + * be switched to use the default status. + */ +void gaim_savedstatus_set_idleaway(gboolean idleaway); + +/** * Returns the status to be used when gaim is starting up * * @return A pointer to the startup GaimSavedStatus.