root/callback.c

Revision 1aef8415e1cd98c88d3980e0d949c832c3ddd7e8, 2.7 kB (checked in by Leo Antunes <leo@…>, 10 months ago)

get saved status before deciding what to do

  • Property mode set to 100644
Line 
1/*
2 awayonlock - plugin to set away status on screensaver activation
3 Copyright (C) 2009  Leo Antunes <leo@costela.net>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc.
18
19*/
20
21// purple
22#include <debug.h>
23#include <plugin.h>
24#include <version.h>
25#include <savedstatuses.h>
26
27#include "i18n.h"
28#include "callback.h"
29#include "prefs.h"
30
31void awayonlock_idle_changed_callback(DBusGProxy *proxy, gboolean screensaver_status, gpointer data) {
32        purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("got message from screensaver: active=%u\n"), screensaver_status);
33
34        PurpleSavedStatus *status_idle;
35
36        const char *awayonlock_savedstatus = purple_prefs_get_string(AWAYONLOCK_PREF_STATUS);
37        if(g_strcmp0(awayonlock_savedstatus, "") == 0) {
38                status_idle = purple_savedstatus_get_idleaway();
39        }
40        else {
41                status_idle = purple_savedstatus_find_by_creation_time(g_ascii_strtoull(awayonlock_savedstatus,NULL,10));
42        }
43
44        gboolean available_only = purple_prefs_get_bool(AWAYONLOCK_PREF_AVAILABLE_ONLY);
45
46        PurpleSavedStatus *status_current = purple_savedstatus_get_current();
47        PurpleSavedStatus *status_saved = purple_savedstatus_find_by_creation_time((time_t)purple_prefs_get_int(AWAYONLOCK_PREF_OLD_STATUS));
48
49        if(screensaver_status && ! purple_savedstatus_is_idleaway() && ((!available_only && purple_savedstatus_get_type(status_current) != PURPLE_STATUS_OFFLINE && purple_savedstatus_get_type(status_current) != PURPLE_STATUS_INVISIBLE) || purple_savedstatus_get_type(status_current) == PURPLE_STATUS_AVAILABLE)) {
50                purple_prefs_set_int(AWAYONLOCK_PREF_OLD_STATUS, (int)purple_savedstatus_get_creation_time(status_current));
51                purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("setting status as '%s' and storing '%s'\n"), purple_savedstatus_get_title(status_idle), purple_savedstatus_get_title(status_current));
52                purple_savedstatus_activate(status_idle);
53        }
54        else if (!screensaver_status && status_saved != NULL && status_saved != status_idle) {
55                purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("restoring status '%s'\n"), purple_savedstatus_get_title(status_saved));
56                purple_savedstatus_activate(status_saved);
57                purple_prefs_set_int(AWAYONLOCK_PREF_OLD_STATUS, 0);
58        }
59        else {
60                purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("ignoring...\n"));
61        }
62}
Note: See TracBrowser for help on using the browser.