root/prefs.c

Revision 6721eef9b2c8afc7192f2acde01bf661087fd148, 3.0 kB (checked in by Leo Antunes <leo@…>, 6 months ago)

clarify prefs label regarding activation while available

  • 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#include <glib.h>
22
23// purple
24#include <debug.h>
25#include <plugin.h>
26#include <version.h>
27#include <savedstatuses.h>
28#include <pluginpref.h>
29
30#include "i18n.h"
31#include "prefs.h"
32
33PurplePluginPrefFrame *get_prefs_frame(PurplePlugin *plugin) {
34        PurplePluginPrefFrame *frame;
35        PurplePluginPref *ppref;
36        GList *statuses;
37
38        purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("creating preferences frame\n"));
39
40        frame = purple_plugin_pref_frame_new();
41
42        ppref = purple_plugin_pref_new_with_name_and_label(AWAYONLOCK_PREF_STATUS, _("Status to set on screensaver activation"));
43        purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE);
44        purple_plugin_pref_add_choice(ppref, _("Default away status"), "");
45
46        statuses = g_list_copy(purple_savedstatuses_get_all());
47
48        for(statuses = g_list_first(statuses);
49            statuses;
50            statuses = g_list_next(statuses)) {
51                if(! purple_savedstatus_is_transient(statuses->data)) {
52                        gchar *creation_time = NULL;
53                        creation_time = g_strdup_printf("%d", purple_savedstatus_get_creation_time(statuses->data));
54                        purple_plugin_pref_add_choice(ppref, (gchar *)purple_savedstatus_get_title(statuses->data), creation_time);
55                        /*
56                         * FIXME: memleak! how can we free this after the frame has
57                         * been destroyed?
58                         */
59                        //g_free(creation_time);
60                }
61        }
62        purple_plugin_pref_frame_add(frame, ppref);
63        g_list_free(statuses);
64
65        ppref = purple_plugin_pref_new_with_name_and_label(AWAYONLOCK_PREF_AVAILABLE_ONLY, _("Activate only if current status set to available"));
66        purple_plugin_pref_frame_add(frame, ppref);
67
68        return frame;
69}
70
71void prefs_status_deleted_cb(PurpleSavedStatus *savedstatus, gpointer data)
72{
73        GList *statuses;
74
75        const char *awayonlock_savedstatus = purple_prefs_get_string(AWAYONLOCK_PREF_STATUS);
76
77        if(g_strcmp0(awayonlock_savedstatus, "") == 0)
78                return; // we use the default, nevermind
79
80        statuses = g_list_copy(purple_savedstatuses_get_all());
81
82        for(statuses = g_list_first(statuses);
83            statuses;
84            statuses = g_list_next(statuses)) {
85                if(purple_savedstatus_get_creation_time(statuses->data) == g_ascii_strtoull(awayonlock_savedstatus,NULL,10)) {
86                        return; // found it, it wasn't deleted
87                }
88        }
89
90        purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("our status got deleted, clearing preference\n"));
91        purple_prefs_set_string(AWAYONLOCK_PREF_STATUS, "");
92}
Note: See TracBrowser for help on using the browser.