Fri, 18 Nov 2005 16:37:51 +0000
[gaim-migrate @ 14436]
SF Patch #1356575 from Kevin Stange (SimGuy)
"This patch moves buddy pounces out of the menu and into
a new dialog, as suggested by Sean. I'm not ready to
say this is finished, but it's a solid starting point
and it does work.
I changed the namespacing a little from gaim_gtkpounce
to gaim_gtk_pounce to be consistent with the rest of Gaim.
I wanted to try to get more information into the pounce
manager, but I wasn't sure how to display it. I
thought perhaps a column containing a row of icons
representing which events are being watched (so the
user can see which of several pounces for the same
buddy are which), however, while I know how to do this,
there aren't icons in Gaim suitable for representing
all the events. Like "returned from away" and
"idle/unidle", as far as I can see. I'm not sure what
else could be shown to make the manager dialog more
"informative."
The dialog updates automatically to show pounces only
for connected accounts and updates when a pounce is
added, changed, or removed in some other way than the
dialog.
I'd like to get feedback on it if anyone has anything
they think I should change or fix, I'll do that and
update this patch. Otherwise, feel free to commit. :)"
As ridingpigs commented in the tracker, this is "far better than the current menu thing."
I made a few small changes to this. I believe most of them were related to adding hooks to disable things if there were no accounts connected. I also sorte
d the Tools menu a bit and updated the docklet to match.
I wish the plugin action code could sort the items it added.
committer: Richard Laager <rlaager@pidgin.im>
| 11907 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | ||
| 25 | #ifdef USE_SCREENSAVER | |
| 26 | # ifndef _WIN32 | |
| 27 | # include <X11/Xlib.h> | |
| 28 | # include <X11/Xutil.h> | |
| 29 | # include <X11/extensions/scrnsaver.h> | |
| 30 | # include <gdk/gdkx.h> | |
| 31 | # else | |
| 32 | # include "idletrack.h" | |
| 33 | # endif | |
| 34 | #endif /* USE_SCREENSAVER */ | |
| 35 | ||
| 36 | #include "connection.h" | |
| 37 | #include "debug.h" | |
| 38 | #include "log.h" | |
| 39 | #include "prefs.h" | |
| 40 | #include "savedstatuses.h" | |
| 41 | #include "signals.h" | |
| 42 | ||
|
11978
5ef1775cc3e9
[gaim-migrate @ 14271]
Mark Doliner <markdoliner@pidgin.im>
parents:
11977
diff
changeset
|
43 | #define IDLEMARK 600 /* 10 minutes! */ |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
44 | #define IDLE_CHECK_INTERVAL 20 /* 20 seconds */ |
| 11907 | 45 | |
| 46 | typedef enum | |
| 47 | { | |
| 48 | GAIM_IDLE_NOT_AWAY = 0, | |
| 49 | GAIM_IDLE_AUTO_AWAY, | |
| 50 | GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY | |
| 51 | ||
| 52 | } GaimAutoAwayState; | |
| 53 | ||
|
11975
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
54 | /** |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
55 | * This is needed for the I'dle Mak'er plugin to work correctly. We |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
56 | * use it to determine if we're the ones who set our accounts idle |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
57 | * or if someone else did it (the I'dle Mak'er plugin, for example). |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
58 | * If our accounts are marked as idle and have_set_idle is FALSE and |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
59 | * the user moves the mouse, then we will NOT unidle our accounts. |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
60 | */ |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
61 | static gboolean have_set_idle = FALSE; |
|
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
62 | |
| 11907 | 63 | #ifdef USE_SCREENSAVER |
| 64 | /** | |
| 65 | * Get the number of seconds the user has been idle. In Unix-world | |
| 66 | * this is based on the X Windows usage. In MS Windows this is based | |
| 67 | * on keyboard/mouse usage. | |
| 68 | * | |
| 69 | * In Debian bug #271639, jwz says: | |
| 70 | * | |
| 71 | * Gaim should simply ask xscreensaver how long the user has been idle: | |
| 72 | * % xscreensaver-command -time | |
| 73 | * XScreenSaver 4.18: screen blanked since Tue Sep 14 14:10:45 2004 | |
| 74 | * | |
| 75 | * Or you can monitor the _SCREENSAVER_STATUS property on root window #0. | |
| 76 | * Element 0 is the status (0, BLANK, LOCK), element 1 is the time_t since | |
| 77 | * the last state change, and subsequent elements are which hack is running | |
| 78 | * on the various screens: | |
| 79 | * % xprop -f _SCREENSAVER_STATUS 32ac -root _SCREENSAVER_STATUS | |
| 80 | * _SCREENSAVER_STATUS(INTEGER) = BLANK, 1095196626, 10, 237 | |
| 81 | * | |
| 82 | * See watch() in xscreensaver/driver/xscreensaver-command.c. | |
| 83 | * | |
| 84 | * @return The number of seconds the user has been idle. | |
| 85 | */ | |
| 86 | static int | |
| 87 | get_idle_time_from_system() | |
| 88 | { | |
| 89 | #ifndef _WIN32 | |
| 90 | static XScreenSaverInfo *mit_info = NULL; | |
| 91 | int event_base, error_base; | |
| 92 | if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) { | |
| 93 | if (mit_info == NULL) { | |
| 94 | mit_info = XScreenSaverAllocInfo(); | |
| 95 | } | |
| 96 | XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info); | |
| 97 | return (mit_info->idle) / 1000; | |
| 98 | } else | |
| 99 | return 0; | |
| 100 | #else | |
| 101 | return (GetTickCount() - wgaim_get_lastactive()) / 1000; | |
| 102 | #endif | |
| 103 | } | |
| 104 | #endif /* USE_SCREENSAVER */ | |
| 105 | ||
| 106 | /* | |
| 107 | * This function should be called when you think your idle state | |
| 108 | * may have changed. Maybe you're over the 10-minute mark and | |
| 109 | * Gaim should start reporting idle time to the server. Maybe | |
| 110 | * you've returned from being idle. Maybe your auto-away message | |
| 111 | * should be set. | |
| 112 | * | |
| 113 | * There is no harm to calling this many many times, other than | |
| 114 | * it will be kinda slow. This is called every 20 seconds by a | |
| 115 | * timer set when an account logs in. It is also called when | |
| 116 | * you send an IM, a chat, etc. | |
| 117 | * | |
| 118 | * This function has 3 sections. | |
| 119 | * 1. Get your idle time. It will query XScreenSaver or Windows | |
| 120 | * or get the Gaim idle time. Whatever. | |
| 121 | * 2. Set or unset your auto-away message. | |
| 122 | * 3. Report your current idle time to the IM server. | |
| 123 | */ | |
| 124 | gint | |
| 125 | gaim_gtk_idle_check(gpointer data) | |
| 126 | { | |
| 127 | GaimConnection *gc = (GaimConnection *)data; | |
| 128 | gboolean report_idle; | |
| 129 | GaimAccount *account; | |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
130 | GaimPresence *presence; |
| 11907 | 131 | time_t t; |
| 132 | int idle_time; | |
| 133 | ||
| 134 | account = gaim_connection_get_account(gc); | |
| 135 | ||
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
136 | presence = gaim_account_get_presence(account); |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
137 | |
| 11907 | 138 | gaim_signal_emit(gaim_blist_get_handle(), "update-idle"); |
| 139 | ||
| 140 | time(&t); | |
| 141 | ||
| 142 | report_idle = gaim_prefs_get_bool("/gaim/gtk/idle/report"); | |
| 143 | ||
| 144 | #ifdef USE_SCREENSAVER | |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
145 | idle_time = get_idle_time_from_system(); |
| 11907 | 146 | #else |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
147 | /* |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
148 | * If Gaim wasn't built with xscreensaver support, then |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
149 | * fallback to calculating our idle time based on when |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
150 | * we last sent a message. |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
151 | */ |
|
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
152 | idle_time = t - gc->last_sent_time; |
| 11907 | 153 | #endif /* USE_SCREENSAVER */ |
| 154 | ||
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
155 | /* Begining of auto-away stuff */ |
| 11907 | 156 | if (gaim_prefs_get_bool("/core/away/away_when_idle") && |
| 157 | (idle_time > (60 * gaim_prefs_get_int("/core/away/mins_before_away"))) | |
| 158 | && (!gc->is_auto_away)) | |
| 159 | { | |
| 160 | if (gaim_presence_is_available(presence)) | |
| 161 | { | |
| 162 | GaimSavedStatus *saved_status; | |
| 163 | ||
| 164 | gaim_debug_info("idle", "Making %s auto-away\n", | |
| 165 | gaim_account_get_username(account)); | |
| 166 | ||
| 167 | /* Mark our accounts "away" using the idleaway status */ | |
|
12125
c1e55f812ded
[gaim-migrate @ 14425]
Mark Doliner <markdoliner@pidgin.im>
parents:
12123
diff
changeset
|
168 | saved_status = gaim_savedstatus_get_idleaway(); |
|
c1e55f812ded
[gaim-migrate @ 14425]
Mark Doliner <markdoliner@pidgin.im>
parents:
12123
diff
changeset
|
169 | gaim_savedstatus_activate_for_account(saved_status, account); |
| 11907 | 170 | |
| 171 | gc->is_auto_away = GAIM_IDLE_AUTO_AWAY; | |
| 172 | } else { | |
| 173 | gc->is_auto_away = GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY; | |
| 174 | } | |
| 175 | ||
| 176 | } else if (gc->is_auto_away && | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
177 | idle_time < 60 * gaim_prefs_get_int("/core/away/mins_before_away")) |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
178 | { |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
179 | /* Return from being idle */ |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
180 | GaimSavedStatus *saved_status; |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
181 | |
| 11907 | 182 | if (gc->is_auto_away == GAIM_IDLE_AWAY_BUT_NOT_AUTO_AWAY) { |
| 183 | gc->is_auto_away = GAIM_IDLE_NOT_AWAY; | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
184 | } else { |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
185 | gc->is_auto_away = GAIM_IDLE_NOT_AWAY; |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
186 | |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
187 | gaim_debug_info("idle", "%s returning from auto-away\n", |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
188 | gaim_account_get_username(account)); |
| 11907 | 189 | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
190 | /* Return our account to its previous status */ |
|
12125
c1e55f812ded
[gaim-migrate @ 14425]
Mark Doliner <markdoliner@pidgin.im>
parents:
12123
diff
changeset
|
191 | saved_status = gaim_savedstatus_get_idleaway(); |
|
c1e55f812ded
[gaim-migrate @ 14425]
Mark Doliner <markdoliner@pidgin.im>
parents:
12123
diff
changeset
|
192 | gaim_savedstatus_activate_for_account(saved_status, account); |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
193 | } |
| 11907 | 194 | } |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
195 | /* End of auto-away stuff */ |
| 11907 | 196 | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
197 | /* Begining of idle reporting stuff */ |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
198 | if (report_idle && idle_time >= IDLEMARK && !have_set_idle && !gaim_presence_is_idle(presence)) |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
199 | { |
| 11907 | 200 | gaim_debug_info("idle", "Setting %s idle %d seconds\n", |
| 201 | gaim_account_get_username(account), idle_time); | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
202 | gaim_presence_set_idle(presence, TRUE, time(NULL) - idle_time); |
|
11975
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
203 | have_set_idle = TRUE; |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
204 | } else if ((!report_idle || idle_time < IDLEMARK) && have_set_idle && gaim_presence_is_idle(presence)) |
|
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
205 | { |
| 11907 | 206 | gaim_debug_info("idle", "Setting %s unidle\n", |
| 207 | gaim_account_get_username(account)); | |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11907
diff
changeset
|
208 | gaim_presence_set_idle(presence, FALSE, time(NULL)); |
|
11975
0abdd0c63f0f
[gaim-migrate @ 14268]
Mark Doliner <markdoliner@pidgin.im>
parents:
11972
diff
changeset
|
209 | have_set_idle = FALSE; |
| 11907 | 210 | } |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
211 | /* End of idle reporting stuff */ |
| 11907 | 212 | |
| 213 | return TRUE; | |
| 214 | } | |
| 215 | ||
| 216 | static void | |
| 217 | im_msg_sent_cb(GaimAccount *account, const char *receiver, | |
| 218 | const char *message, void *data) | |
| 219 | { | |
| 220 | GaimConnection *gc = gaim_account_get_connection(account); | |
| 221 | ||
| 222 | /* After an IM is sent, check our idle time */ | |
| 223 | gaim_gtk_idle_check(gc); | |
| 224 | } | |
| 225 | ||
| 226 | static void | |
| 227 | remove_idle_timer(GaimConnection *gc) | |
| 228 | { | |
| 229 | /* Remove any existing idle_timer */ | |
| 230 | if (gc->idle_timer > 0) | |
| 231 | gaim_timeout_remove(gc->idle_timer); | |
| 232 | gc->idle_timer = 0; | |
| 233 | } | |
| 234 | ||
| 235 | static void | |
| 236 | connection_disconnected_cb(GaimConnection *gc, gpointer user_data) | |
| 237 | { | |
| 238 | remove_idle_timer(gc); | |
| 239 | } | |
| 240 | ||
| 241 | static void | |
| 242 | connection_connected_cb(GaimConnection *gc, gpointer user_data) | |
| 243 | { | |
| 244 | /* Now that we are connected, check for idleness every 20 seconds */ | |
| 245 | remove_idle_timer(gc); | |
|
11977
51548c459a94
[gaim-migrate @ 14270]
Mark Doliner <markdoliner@pidgin.im>
parents:
11975
diff
changeset
|
246 | gc->idle_timer = gaim_timeout_add(IDLE_CHECK_INTERVAL * 1000, gaim_gtk_idle_check, gc); |
| 11907 | 247 | |
| 248 | /* Immediately update our idleness, in case we connected while idle */ | |
| 249 | gaim_gtk_idle_check(gc); | |
| 250 | } | |
| 251 | ||
| 252 | void * | |
| 253 | gaim_gtk_idle_get_handle() | |
| 254 | { | |
| 255 | static int handle; | |
| 256 | ||
| 257 | return &handle; | |
| 258 | } | |
| 259 | ||
| 260 | void | |
| 261 | gaim_gtk_idle_init() | |
| 262 | { | |
| 263 | gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", | |
| 264 | gaim_gtk_idle_get_handle(), | |
| 265 | GAIM_CALLBACK(im_msg_sent_cb), NULL); | |
| 266 | ||
| 267 | gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
| 268 | gaim_gtk_idle_get_handle(), | |
| 269 | GAIM_CALLBACK(connection_connected_cb), NULL); | |
| 270 | gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
| 271 | gaim_gtk_idle_get_handle(), | |
| 272 | GAIM_CALLBACK(connection_disconnected_cb), NULL); | |
| 273 | } | |
| 274 | ||
| 275 | void | |
| 276 | gaim_gtk_idle_uninit() | |
| 277 | { | |
| 278 | gaim_signals_disconnect_by_handle(gaim_gtk_idle_get_handle()); | |
| 279 | } |