/
usb_moded-gconf.c
95 lines (78 loc) · 2.29 KB
/
usb_moded-gconf.c
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
94
95
/**
@file usb_moded-gconf.c
Copyright (C) 2010 Nokia Corporation. All rights reserved.
@author: Philippe De Swert <philippe.de-swert@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
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 Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
* Gets information from Gconf for the usb modes
*/
/*============================================================================= */
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include <glib-object.h>
#include <gconf/gconf-client.h>
#include "usb_moded-gconf.h"
#include "usb_moded-gconf-private.h"
#include "usb_moded-modes.h"
#include "usb_moded-log.h"
#include "usb_moded.h"
/** Get the config option set in gconf for the default action
*
* @return The mode to set by default, or NULL on failure
*
*/
const char * get_mode_setting(void)
{
GConfClient *gclient = NULL;
gchar *mode_value;
gclient = gconf_client_get_default();
if (gclient == NULL)
{
log_err("Unable to get GConfClient");
return(0);
}
mode_value = gconf_client_get_string(gclient, USB_MODE_GCONF, NULL);
g_object_unref(gclient);
return(mode_value);
}
/** Set the config option for the default action
*
* @param mode The default action to store in gconf
* @return 0 on on success, 1 on failure
*
*/
int set_mode_setting(const char *mode)
{
GConfClient *gclient = NULL;
if(!valid_mode(mode) || !strcmp(mode, MODE_ASK))
{
gclient = gconf_client_get_default();
if (gclient == NULL)
{
log_err("Unable to get GConfClient");
return(1);
}
if (!gconf_client_set_string(gclient, USB_MODE_GCONF, mode, NULL))
{
log_err("Unable to set GConf key");
g_object_unref(gclient);
return(1);
}
}
else
return(1);
g_object_unref(gclient);
return(0);
}