~ubuntu-branches/ubuntu/precise/xfce4-power-manager/precise

« back to all changes in this revision

Viewing changes to src/xfpm-power-common.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-09 18:28:34 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20101209182834-tjz13qcewqlq19eu
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * * Copyright (C) 2010 Ali <aliov@xfce.org>
 
3
 *
 
4
 * Licensed under the GNU General Public License Version 2
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <libxfce4util/libxfce4util.h>
 
26
#include <dbus/dbus-glib-lowlevel.h>
 
27
 
 
28
#include "xfpm-power-common.h"
 
29
#include "xfpm-enum-glib.h"
 
30
 
 
31
#include "xfpm-icons.h"
 
32
 
 
33
/**
 
34
 * xfpm_power_enumerate_devices:
 
35
 * 
 
36
 **/
 
37
GPtrArray *
 
38
xfpm_power_enumerate_devices (DBusGProxy *proxy)
 
39
{
 
40
    gboolean ret;
 
41
    GError *error = NULL;
 
42
    GPtrArray *array = NULL;
 
43
    GType g_type_array;
 
44
 
 
45
    g_type_array = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
 
46
    
 
47
    ret = dbus_g_proxy_call (proxy, "EnumerateDevices", &error,
 
48
                             G_TYPE_INVALID,
 
49
                             g_type_array, &array,
 
50
                             G_TYPE_INVALID);
 
51
    if (!ret) 
 
52
    {
 
53
        g_critical ("Couldn't enumerate power devices: %s", error->message);
 
54
        g_error_free (error);
 
55
    }
 
56
    
 
57
    return array;
 
58
}
 
59
 
 
60
/**
 
61
 * xfpm_power_get_interface_properties:
 
62
 * 
 
63
 **/
 
64
GHashTable *xfpm_power_get_interface_properties (DBusGProxy *proxy_prop, const gchar *iface_name)
 
65
{
 
66
    gboolean ret;
 
67
    GError *error = NULL;
 
68
    GHashTable *props = NULL;
 
69
 
 
70
    props = NULL;
 
71
 
 
72
    ret = dbus_g_proxy_call (proxy_prop, "GetAll", &error,
 
73
                             G_TYPE_STRING, iface_name,
 
74
                             G_TYPE_INVALID,
 
75
                             dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props,
 
76
                             G_TYPE_INVALID);
 
77
                            
 
78
    if (!ret) 
 
79
    {
 
80
        g_warning ("Unable to get interface properties for : %s : %s", iface_name, error->message);
 
81
        g_error_free (error);
 
82
    }
 
83
    
 
84
    return props;
 
85
}
 
86
 
 
87
/**
 
88
 * xfpm_power_get_interface_property:
 
89
 * 
 
90
 **/
 
91
GValue xfpm_power_get_interface_property (DBusGProxy *proxy, const gchar *iface_name, const gchar *prop_name)
 
92
{
 
93
    gboolean ret;
 
94
    GError *error = NULL;
 
95
    GValue value = { 0, };
 
96
 
 
97
    ret = dbus_g_proxy_call (proxy, "Get", &error,
 
98
                             G_TYPE_STRING, iface_name,
 
99
                             G_TYPE_STRING, prop_name,
 
100
                             G_TYPE_INVALID,
 
101
                             G_TYPE_VALUE, &value, G_TYPE_INVALID);
 
102
                                                        
 
103
    if (!ret) 
 
104
    {
 
105
        g_warning ("Unable to get property %s on interface  %s : %s", prop_name, iface_name, error->message);
 
106
        g_error_free (error);
 
107
    }
 
108
    
 
109
    return value;
 
110
}
 
111
 
 
112
/**
 
113
 * xfpm_power_translate_device_type:
 
114
 * 
 
115
 **/
 
116
const gchar *
 
117
xfpm_power_translate_device_type (guint type)
 
118
{
 
119
    switch (type)
 
120
    {
 
121
        case XFPM_DEVICE_TYPE_BATTERY:
 
122
            return _("Battery");
 
123
        case XFPM_DEVICE_TYPE_UPS:
 
124
            return _("UPS");
 
125
        case XFPM_DEVICE_TYPE_LINE_POWER:
 
126
            return _("Line power");
 
127
        case XFPM_DEVICE_TYPE_MOUSE:
 
128
            return _("Mouse");
 
129
        case XFPM_DEVICE_TYPE_KBD:
 
130
            return _("Keyboard");
 
131
        case XFPM_DEVICE_TYPE_MONITOR:
 
132
            return _("Monitor");
 
133
        case XFPM_DEVICE_TYPE_PDA:
 
134
            return _("PDA");
 
135
        case XFPM_DEVICE_TYPE_PHONE:
 
136
            return _("Phone");
 
137
        case XFPM_DEVICE_TYPE_UNKNOWN:
 
138
            return _("Unknown");
 
139
    }
 
140
    
 
141
    return _("Battery");
 
142
}
 
143
 
 
144
/**
 
145
 * xfpm_power_translate_technology:
 
146
 * 
 
147
 **/
 
148
const gchar *xfpm_power_translate_technology (guint value)
 
149
{
 
150
    switch (value)
 
151
    {
 
152
        case 0:
 
153
            return _("Unknown");
 
154
        case 1:
 
155
            return _("Lithium ion");
 
156
        case 2:
 
157
            return _("Lithium polymer");
 
158
        case 3:
 
159
            return _("Lithium iron phosphate");
 
160
        case 4:
 
161
            return _("Lead acid");
 
162
        case 5:
 
163
            return _("Nickel cadmium");
 
164
        case 6:
 
165
            return _("Nickel metal hybride");
 
166
    }
 
167
    
 
168
    return _("Unknown");
 
169
}
 
170
 
 
171
const gchar *xfpm_power_get_icon_name (guint device_type)
 
172
{
 
173
    switch (device_type)
 
174
    {
 
175
        case XFPM_DEVICE_TYPE_BATTERY:
 
176
            return XFPM_BATTERY_ICON;
 
177
        case XFPM_DEVICE_TYPE_UPS:
 
178
            return XFPM_UPS_ICON;
 
179
        case XFPM_DEVICE_TYPE_LINE_POWER:
 
180
            return XFPM_AC_ADAPTER_ICON;
 
181
        case XFPM_DEVICE_TYPE_MOUSE:
 
182
            return XFPM_MOUSE_ICON;
 
183
        case XFPM_DEVICE_TYPE_KBD:
 
184
            return XFPM_KBD_ICON;
 
185
        case XFPM_DEVICE_TYPE_MONITOR:
 
186
            return "monitor";
 
187
        case XFPM_DEVICE_TYPE_PDA:
 
188
            return XFPM_PDA_ICON;
 
189
        case XFPM_DEVICE_TYPE_PHONE:
 
190
            return XFPM_PHONE_ICON;
 
191
        case XFPM_DEVICE_TYPE_UNKNOWN:
 
192
            return XFPM_BATTERY_ICON;
 
193
    }
 
194
    
 
195
    return XFPM_BATTERY_ICON;
 
196
}
 
197
 
 
198