File: prefs.c

package info (click to toggle)
pidgin-awayonlock 0.5.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 168 kB
  • sloc: ansic: 262; python: 19; makefile: 9
file content (93 lines) | stat: -rw-r--r-- 3,049 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 awayonlock - plugin to set away status on screensaver activation
 Copyright (C) 2009  Leo Antunes <leo@costela.net>

 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.

*/

#include <glib.h>

// purple
#include <debug.h>
#include <plugin.h>
#include <version.h>
#include <savedstatuses.h>
#include <pluginpref.h>

#include "i18n.h"
#include "prefs.h"

PurplePluginPrefFrame *get_prefs_frame(PurplePlugin *plugin) {
	PurplePluginPrefFrame *frame;
	PurplePluginPref *ppref;
	GList *statuses;

	purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("creating preferences frame\n"));

	frame = purple_plugin_pref_frame_new();

	ppref = purple_plugin_pref_new_with_name_and_label(AWAYONLOCK_PREF_STATUS, _("Status to set on screensaver activation"));
	purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE);
	purple_plugin_pref_add_choice(ppref, _("Default away status"), "");

	statuses = g_list_copy(purple_savedstatuses_get_all());

	for(statuses = g_list_first(statuses);
	    statuses;
	    statuses = g_list_next(statuses)) {
		if(! purple_savedstatus_is_transient(statuses->data)) {
			gchar *creation_time = NULL;
			creation_time = g_strdup_printf("%lld", (long long)purple_savedstatus_get_creation_time(statuses->data));
			purple_plugin_pref_add_choice(ppref, (gchar *)purple_savedstatus_get_title(statuses->data), creation_time);
			/*
			 * FIXME: memleak! how can we free this after the frame has
			 * been destroyed?
			 */
			//g_free(creation_time);
		}
	}
	purple_plugin_pref_frame_add(frame, ppref);
	g_list_free(statuses);

	ppref = purple_plugin_pref_new_with_name_and_label(AWAYONLOCK_PREF_AVAILABLE_ONLY, _("Activate only if available"));
	purple_plugin_pref_frame_add(frame, ppref);

	return frame;
}

void prefs_status_deleted_cb(PurpleSavedStatus *savedstatus, gpointer data)
{
	GList *statuses;

	const char *awayonlock_savedstatus = purple_prefs_get_string(AWAYONLOCK_PREF_STATUS);

	if(g_strcmp0(awayonlock_savedstatus, "") == 0)
		return; // we use the default, nevermind

	statuses = g_list_copy(purple_savedstatuses_get_all());

	for(statuses = g_list_first(statuses);
	    statuses;
	    statuses = g_list_next(statuses)) {
		if(purple_savedstatus_get_creation_time(statuses->data) == g_ascii_strtoull(awayonlock_savedstatus,NULL,10)) {
			return; // found it, it wasn't deleted
		}
	}

	purple_debug(PURPLE_DEBUG_INFO, PACKAGE, N_("our status got deleted, clearing preference\n"));
	purple_prefs_set_string(AWAYONLOCK_PREF_STATUS, "");
}