changeset 13681:c4be649e2aca

[gaim-migrate @ 16084] Fixed a bug where you wouldn't become auto-away when idle if you're a new user and you haven't selected which status to use when auto-awaying. Also improved a few comments. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 23 Apr 2006 02:57:08 +0000
parents 2e0d8828da51
children 48c261f76657
files src/savedstatuses.c src/savedstatuses.h
diffstat 2 files changed, 57 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/savedstatuses.c	Sat Apr 22 21:36:31 2006 +0000
+++ b/src/savedstatuses.c	Sun Apr 23 02:57:08 2006 +0000
@@ -39,6 +39,11 @@
 #define MAX_TRANSIENTS 5
 
 /**
+ * The default message to use when the user becomes auto-away.
+ */
+#define DEFAULT_AUTOAWAY_MESSAGE _("I'm not here right now")
+
+/**
  * The information stores a snap-shot of the statuses of all
  * your accounts.  Basically these are your saved away messages.
  * There is an overall status and message that applies to
@@ -713,29 +718,6 @@
 }
 
 GaimSavedStatus *
-gaim_savedstatus_get_startup()
-{
-	int creation_time;
-	GaimSavedStatus *saved_status = NULL;
-
-	creation_time = gaim_prefs_get_int("/core/savedstatus/startup");
-
-	if (creation_time != 0)
-		saved_status = g_hash_table_lookup(creation_times, &creation_time);
-
-	if (saved_status == NULL)
-	{
-		/* We don't have a status to apply.
-		 * This may be the first login, or the user wants to
-		 * restore the "current" status */
-		saved_status = gaim_savedstatus_get_current();
-	}
-
-	return saved_status;
-}
-
-
-GaimSavedStatus *
 gaim_savedstatus_get_current()
 {
 	int creation_time;
@@ -749,7 +731,7 @@
 	if (saved_status == NULL)
 	{
 		/*
-		 * We don't have a current saved statuses!  This is either a new
+		 * We don't have a current saved status!  This is either a new
 		 * Gaim user or someone upgrading from Gaim 1.5.0 or older, or
 		 * possibly someone who deleted the status they were currently
 		 * using?  In any case, add a default status.
@@ -766,31 +748,57 @@
 gaim_savedstatus_get_idleaway()
 {
 	int creation_time;
-	GaimSavedStatus *saved_status;
+	GaimSavedStatus *saved_status = NULL;
 
 	creation_time = gaim_prefs_get_int("/core/savedstatus/idleaway");
 
-	if (creation_time == 0)
+	if (creation_time != 0)
+		saved_status = g_hash_table_lookup(creation_times, &creation_time);
+
+	if (saved_status == NULL)
 	{
-		/*
-		 * We don't have a current saved statuses!  This is either a new
-		 * Gaim user or someone upgrading from Gaim 1.5.0 or older.  Add
-		 * a default status.
-		 */
-		saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AWAY);
-		gaim_savedstatus_set_message(saved_status, _("I'm not here right now"));
-		gaim_prefs_set_int("/core/savedstatus/idleaway",
-						   gaim_savedstatus_get_creation_time(saved_status));
-	}
-	else
-	{
-		saved_status = g_hash_table_lookup(creation_times, &creation_time);
+		/* We don't have a specified "idle" status!  Weird. */
+		saved_status = gaim_savedstatus_find_transient_by_type_and_message(
+				GAIM_STATUS_AWAY, DEFAULT_AUTOAWAY_MESSAGE);
+
+		if (saved_status == NULL)
+		{
+			saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AWAY);
+			gaim_savedstatus_set_message(saved_status, DEFAULT_AUTOAWAY_MESSAGE);
+			gaim_prefs_set_int("/core/savedstatus/idleaway",
+							   gaim_savedstatus_get_creation_time(saved_status));
+		}
 	}
 
 	return saved_status;
 }
 
 GaimSavedStatus *
+gaim_savedstatus_get_startup()
+{
+	int creation_time;
+	GaimSavedStatus *saved_status = NULL;
+
+	creation_time = gaim_prefs_get_int("/core/savedstatus/startup");
+
+	if (creation_time != 0)
+		saved_status = g_hash_table_lookup(creation_times, &creation_time);
+
+	if (saved_status == NULL)
+	{
+		/*
+		 * We don't have a status to apply.
+		 * This may be the first login, or the user wants to
+		 * restore the "current" status.
+		 */
+		saved_status = gaim_savedstatus_get_current();
+	}
+
+	return saved_status;
+}
+
+
+GaimSavedStatus *
 gaim_savedstatus_find(const char *title)
 {
 	GList *iter;
--- a/src/savedstatuses.h	Sat Apr 22 21:36:31 2006 +0000
+++ b/src/savedstatuses.h	Sun Apr 23 02:57:08 2006 +0000
@@ -174,25 +174,28 @@
  * Returns the currently selected saved status.
  *
  * @return A pointer to the in-use GaimSavedStatus.
+ *         This function never returns NULL.
  */
 GaimSavedStatus *gaim_savedstatus_get_current(void);
 
 /**
- * Returns the status to be used when gaim is starting up
- *
- * @return A pointer to the startup GaimSavedStatus.
- */
-GaimSavedStatus *gaim_savedstatus_get_startup(void);
-
-/**
  * Returns the saved status that gets used when your
  * accounts become idle-away.
  *
  * @return A pointer to the idle-away GaimSavedStatus.
+ *         This function never returns NULL.
  */
 GaimSavedStatus *gaim_savedstatus_get_idleaway(void);
 
 /**
+ * Returns the status to be used when gaim is starting up
+ *
+ * @return A pointer to the startup GaimSavedStatus.
+ *         This function never returns NULL.
+ */
+GaimSavedStatus *gaim_savedstatus_get_startup(void);
+
+/**
  * Finds a saved status with the specified title.
  *
  * @param title The name of the saved status.