Mercurial > pidgin
comparison src/savedstatuses.c @ 14128:a8a033a89ee0
[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 <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 15 Aug 2006 08:22:29 +0000 |
| parents | ec858948d292 |
| children |
comparison
equal
deleted
inserted
replaced
| 14127:9a4b76c288aa | 14128:a8a033a89ee0 |
|---|---|
| 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 */ | 24 */ |
| 25 #include "internal.h" | 25 #include "internal.h" |
| 26 | 26 |
| 27 #include "debug.h" | 27 #include "debug.h" |
| 28 #include "idle.h" | |
| 28 #include "notify.h" | 29 #include "notify.h" |
| 29 #include "savedstatuses.h" | 30 #include "savedstatuses.h" |
| 30 #include "dbus-maybe.h" | 31 #include "dbus-maybe.h" |
| 31 #include "status.h" | 32 #include "status.h" |
| 32 #include "util.h" | 33 #include "util.h" |
| 674 | 675 |
| 675 /* | 676 /* |
| 676 * If we just deleted our current status or our idleaway status, | 677 * If we just deleted our current status or our idleaway status, |
| 677 * then set the appropriate pref back to 0. | 678 * then set the appropriate pref back to 0. |
| 678 */ | 679 */ |
| 679 current = gaim_prefs_get_int("/core/savedstatus/current"); | 680 current = gaim_prefs_get_int("/core/savedstatus/default"); |
| 680 if (current == creation_time) | 681 if (current == creation_time) |
| 681 gaim_prefs_set_int("/core/savedstatus/current", 0); | 682 gaim_prefs_set_int("/core/savedstatus/default", 0); |
| 682 | 683 |
| 683 idleaway = gaim_prefs_get_int("/core/savedstatus/idleaway"); | 684 idleaway = gaim_prefs_get_int("/core/savedstatus/idleaway"); |
| 684 if (idleaway == creation_time) | 685 if (idleaway == creation_time) |
| 685 gaim_prefs_set_int("/core/savedstatus/idleaway", 0); | 686 gaim_prefs_set_int("/core/savedstatus/idleaway", 0); |
| 686 | 687 |
| 723 | 724 |
| 724 return popular; | 725 return popular; |
| 725 } | 726 } |
| 726 | 727 |
| 727 GaimSavedStatus * | 728 GaimSavedStatus * |
| 728 gaim_savedstatus_get_current() | 729 gaim_savedstatus_get_current(void) |
| 730 { | |
| 731 if (gaim_savedstatus_is_idleaway()) | |
| 732 return gaim_savedstatus_get_idleaway(); | |
| 733 else | |
| 734 return gaim_savedstatus_get_default(); | |
| 735 } | |
| 736 | |
| 737 GaimSavedStatus * | |
| 738 gaim_savedstatus_get_default() | |
| 729 { | 739 { |
| 730 int creation_time; | 740 int creation_time; |
| 731 GaimSavedStatus *saved_status = NULL; | 741 GaimSavedStatus *saved_status = NULL; |
| 732 | 742 |
| 733 creation_time = gaim_prefs_get_int("/core/savedstatus/current"); | 743 creation_time = gaim_prefs_get_int("/core/savedstatus/default"); |
| 734 | 744 |
| 735 if (creation_time != 0) | 745 if (creation_time != 0) |
| 736 saved_status = g_hash_table_lookup(creation_times, &creation_time); | 746 saved_status = g_hash_table_lookup(creation_times, &creation_time); |
| 737 | 747 |
| 738 if (saved_status == NULL) | 748 if (saved_status == NULL) |
| 742 * Gaim user or someone upgrading from Gaim 1.5.0 or older, or | 752 * Gaim user or someone upgrading from Gaim 1.5.0 or older, or |
| 743 * possibly someone who deleted the status they were currently | 753 * possibly someone who deleted the status they were currently |
| 744 * using? In any case, add a default status. | 754 * using? In any case, add a default status. |
| 745 */ | 755 */ |
| 746 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AVAILABLE); | 756 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AVAILABLE); |
| 747 gaim_prefs_set_int("/core/savedstatus/current", | 757 gaim_prefs_set_int("/core/savedstatus/default", |
| 748 gaim_savedstatus_get_creation_time(saved_status)); | 758 gaim_savedstatus_get_creation_time(saved_status)); |
| 749 } | 759 } |
| 750 | 760 |
| 751 return saved_status; | 761 return saved_status; |
| 752 } | 762 } |
| 776 gaim_savedstatus_get_creation_time(saved_status)); | 786 gaim_savedstatus_get_creation_time(saved_status)); |
| 777 } | 787 } |
| 778 } | 788 } |
| 779 | 789 |
| 780 return saved_status; | 790 return saved_status; |
| 791 } | |
| 792 | |
| 793 gboolean | |
| 794 gaim_savedstatus_is_idleaway() | |
| 795 { | |
| 796 return gaim_prefs_get_bool("/core/savedstatus/isidleaway"); | |
| 797 } | |
| 798 | |
| 799 void | |
| 800 gaim_savedstatus_set_idleaway(gboolean idleaway) | |
| 801 { | |
| 802 GList *accounts, *node; | |
| 803 GaimSavedStatus *old, *saved_status; | |
| 804 | |
| 805 if (gaim_savedstatus_is_idleaway() == idleaway) | |
| 806 /* Don't need to do anything */ | |
| 807 return; | |
| 808 | |
| 809 /* Changing our status makes us un-idle */ | |
| 810 if (!idleaway) | |
| 811 gaim_idle_touch(); | |
| 812 | |
| 813 old = gaim_savedstatus_get_current(); | |
| 814 gaim_prefs_set_bool("/core/savedstatus/isidleaway", idleaway); | |
| 815 saved_status = gaim_savedstatus_get_current(); | |
| 816 | |
| 817 accounts = gaim_accounts_get_all_active(); | |
| 818 for (node = accounts; node != NULL; node = node->next) | |
| 819 { | |
| 820 GaimAccount *account; | |
| 821 GaimPresence *presence; | |
| 822 GaimStatus *status; | |
| 823 | |
| 824 account = node->data; | |
| 825 presence = gaim_account_get_presence(account); | |
| 826 status = gaim_presence_get_active_status(presence); | |
| 827 | |
| 828 if (!idleaway || gaim_status_is_available(status)) | |
| 829 gaim_savedstatus_activate_for_account(saved_status, account); | |
| 830 } | |
| 831 | |
| 832 g_list_free(accounts); | |
| 833 | |
| 834 gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed", | |
| 835 saved_status, old); | |
| 781 } | 836 } |
| 782 | 837 |
| 783 GaimSavedStatus * | 838 GaimSavedStatus * |
| 784 gaim_savedstatus_get_startup() | 839 gaim_savedstatus_get_startup() |
| 785 { | 840 { |
| 999 gaim_savedstatus_activate_for_account(saved_status, account); | 1054 gaim_savedstatus_activate_for_account(saved_status, account); |
| 1000 } | 1055 } |
| 1001 | 1056 |
| 1002 g_list_free(accounts); | 1057 g_list_free(accounts); |
| 1003 | 1058 |
| 1004 gaim_prefs_set_int("/core/savedstatus/current", | 1059 gaim_prefs_set_int("/core/savedstatus/default", |
| 1005 gaim_savedstatus_get_creation_time(saved_status)); | 1060 gaim_savedstatus_get_creation_time(saved_status)); |
| 1061 gaim_savedstatus_set_idleaway(FALSE); | |
| 1006 | 1062 |
| 1007 gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed", | 1063 gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed", |
| 1008 saved_status, old); | 1064 saved_status, old); |
| 1009 | |
| 1010 } | 1065 } |
| 1011 | 1066 |
| 1012 void | 1067 void |
| 1013 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status, | 1068 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status, |
| 1014 GaimAccount *account) | 1069 GaimAccount *account) |
| 1068 * gaim_savedstatus_get_idleaway() and either of those functions | 1123 * gaim_savedstatus_get_idleaway() and either of those functions |
| 1069 * sees a creation_time of 0, then it will create a default | 1124 * sees a creation_time of 0, then it will create a default |
| 1070 * saved status and return that to the user. | 1125 * saved status and return that to the user. |
| 1071 */ | 1126 */ |
| 1072 gaim_prefs_add_none("/core/savedstatus"); | 1127 gaim_prefs_add_none("/core/savedstatus"); |
| 1073 gaim_prefs_add_int("/core/savedstatus/current", 0); | 1128 gaim_prefs_add_int("/core/savedstatus/default", 0); |
| 1074 gaim_prefs_add_int("/core/savedstatus/startup", 0); | 1129 gaim_prefs_add_int("/core/savedstatus/startup", 0); |
| 1075 gaim_prefs_add_bool("/core/savedstatus/startup_current_status", TRUE); | 1130 gaim_prefs_add_bool("/core/savedstatus/startup_current_status", TRUE); |
| 1076 gaim_prefs_add_int("/core/savedstatus/idleaway", 0); | 1131 gaim_prefs_add_int("/core/savedstatus/idleaway", 0); |
| 1132 gaim_prefs_add_bool("/core/savedstatus/isidleaway", FALSE); | |
| 1077 | 1133 |
| 1078 load_statuses(); | 1134 load_statuses(); |
| 1079 | 1135 |
| 1080 gaim_signal_register(handle, "savedstatus-changed", | 1136 gaim_signal_register(handle, "savedstatus-changed", |
| 1081 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | 1137 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
