Mercurial > pidgin.yaz
changeset 11551:78aad676fdb2
[gaim-migrate @ 13806]
This creates an unidle menu option for the I'dle Mak'er plugin. I like
having this.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 15 Sep 2005 14:54:23 +0000 |
parents | ec2335d98b83 |
children | 11d30825c1bb |
files | COPYRIGHT plugins/idle.c src/status.c |
diffstat | 3 files changed, 156 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Thu Sep 15 06:12:21 2005 +0000 +++ b/COPYRIGHT Thu Sep 15 14:54:23 2005 +0000 @@ -10,6 +10,7 @@ Daniel Atallah Paul Aurich Patrick Aussems +John Bailey Levi Bard Kevin Barry Derek Battams
--- a/plugins/idle.c Thu Sep 15 06:12:21 2005 +0000 +++ b/plugins/idle.c Thu Sep 15 14:54:23 2005 +0000 @@ -1,6 +1,25 @@ -/* a nifty little plugin to set your idle time to whatever you want it to be. - * useful for almost nothing. mostly just a demo plugin. but it's fun to have - * 40-day idle times. +/* + * idle.c - I'dle Mak'er plugin for Gaim + * + * This file is part of Gaim. + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "internal.h" @@ -10,31 +29,71 @@ #include "plugin.h" #include "request.h" #include "server.h" +#include "status.h" #include "version.h" #define IDLE_PLUGIN_ID "gtk-idle" +static GList *idled_accts; + +static gboolean +idle_filter(GaimAccount *acct) +{ + if(g_list_find(idled_accts, acct)) + return TRUE; + + return FALSE; +} + +static void +set_idle_time(GaimAccount *acct, int mins_idle) +{ + time_t t = time(NULL); /* grab the current time */ + GaimConnection *gc = gaim_account_get_connection(acct); + GaimPresence *presence = gaim_account_get_presence(acct); + + gaim_debug(GAIM_DEBUG_INFO, "idle", + "setting idle time for %s to %d\n", + gaim_account_get_username(acct), mins_idle); + + t -= 60 * mins_idle; /* subtract seconds idle from current time */ + gc->last_sent_time = t; + gc->is_idle = 0; + + gaim_presence_set_idle(presence, mins_idle ? TRUE : FALSE, t); +} static void idle_action_ok(void *ignored, GaimRequestFields *fields) { - time_t t; - int tm; - GaimAccount *acct; - GaimConnection *gc; - - tm = gaim_request_fields_get_integer(fields, "mins"); - acct = gaim_request_fields_get_account(fields, "acct"); - gc = gaim_account_get_connection(acct); + GList *l = idled_accts; + gboolean acct_found = FALSE; + int tm = gaim_request_fields_get_integer(fields, "mins"); + GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); - gaim_debug(GAIM_DEBUG_INFO, "idle", - "setting idle time for %s to %d\n", - gaim_account_get_username(acct), tm); - time(&t); - t -= 60 * tm; - gc->last_sent_time = t; - serv_set_idle(gc, 60 * tm); - gc->is_idle = 0; + /* only add the account to the GList if it's not already been idled */ + if((l = g_list_find(idled_accts, acct)) && (GaimAccount *)(l->data) == acct) + acct_found = TRUE; + + if(!acct_found) { + gaim_debug_misc("idle", + "%s hasn't been idled yet; adding to list.\n", + gaim_account_get_username(acct)); + idled_accts = g_list_append(idled_accts, acct); + } + + set_idle_time(acct, tm); +} + +static void +unidle_action_ok(void *ignored, GaimRequestFields *fields) +{ + GaimAccount *acct = gaim_request_fields_get_account(fields, "acct"); + + set_idle_time(acct, 0); /* unidle the account */ + + /* once the account has been unidled it shouldn't be in the list */ + g_list_remove(idled_accts, acct); } @@ -69,6 +128,46 @@ NULL); } +static void +unidle_action(GaimPluginAction *action) +{ + GaimRequestFields *request; + GaimRequestFieldGroup *group; + GaimRequestField *field; + + group = gaim_request_field_group_new(NULL); + + field = gaim_request_field_account_new("acct", _("Account"), NULL); + gaim_request_field_account_set_filter(field, idle_filter); + gaim_request_field_account_set_show_all(field, FALSE); + gaim_request_field_group_add_field(group, field); + + request = gaim_request_fields_new(); + gaim_request_fields_add_group(request, group); + + gaim_request_fields(action->plugin, + N_("I'dle Mak'er"), + _("Unset Account Idle Time"), + NULL, + request, + _("_Unset"), G_CALLBACK(unidle_action_ok), + _("_Cancel"), NULL, + NULL); +} + +static void +unidle_all_action(GaimPluginAction *action) +{ + GList *l; + + /* freeing the list here will cause segfaults if the user idles an account + * after the list is freed */ + for (l = idled_accts; l; l = l->next) { + set_idle_time((GaimAccount *)(l->data), 0); + g_list_remove(idled_accts, l->data); + } + +} static GList * actions(GaimPlugin *plugin, gpointer context) @@ -80,9 +179,30 @@ idle_action); l = g_list_append(l, act); + act = gaim_plugin_action_new(_("Unset Account Idle Time"), + unidle_action); + l = g_list_append(l, act); + + act = gaim_plugin_action_new( + _("Unset Idle Time For All Idled Accounts"), unidle_all_action); + l = g_list_append(l, act); + return l; } +static gboolean +plugin_unload(GaimPlugin *plugin) +{ + GList *l; + + for (l = idled_accts; l; l = l->next) + set_idle_time((GaimAccount *)(l->data), 0); + + g_list_free(idled_accts); + + return TRUE; +} + static GaimPluginInfo info = { GAIM_PLUGIN_MAGIC, @@ -96,12 +216,12 @@ IDLE_PLUGIN_ID, N_("I'dle Mak'er"), VERSION, - N_("Allows you to hand-configure how long you've been idle for"), - N_("Allows you to hand-configure how long you've been idle for"), + N_("Allows you to hand-configure how long you've been idle"), + N_("Allows you to hand-configure how long you've been idle"), "Eric Warmenhoven <eric@warmenhoven.org>", GAIM_WEBSITE, NULL, - NULL, + plugin_unload, NULL, NULL, NULL,
--- a/src/status.c Thu Sep 15 06:12:21 2005 +0000 +++ b/src/status.c Thu Sep 15 14:54:23 2005 +0000 @@ -1366,6 +1366,19 @@ old_idle, idle); } } + else if(gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_ACCOUNT) + { + GaimConnection *gc = + gaim_account_get_connection(gaim_presence_get_account(presence)); + GaimPluginProtocolInfo *prpl_info = NULL; + + if (gc != NULL && gc->prpl != NULL) + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); + + if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && + prpl_info->set_idle) + prpl_info->set_idle(gc, time(NULL) - idle_time); + } } void