~xavi-garcia-mena/ubuntu/vivid/upower/percentages-power-off

« back to all changes in this revision

Viewing changes to devkit-power-gobject/dkp-enum.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-02-16 10:16:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100216101624-2cmwqsr1ndftdd87
Tags: upstream-0.9.0+git20100216.72bb2
ImportĀ upstreamĀ versionĀ 0.9.0+git20100216.72bb2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
 
4
 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
 
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 St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#include <glib.h>
 
23
#include <string.h>
 
24
 
 
25
#include "dkp-enum.h"
 
26
 
 
27
/**
 
28
 * dkp_device_type_to_text:
 
29
 **/
 
30
const gchar *
 
31
dkp_device_type_to_text (DkpDeviceType type_enum)
 
32
{
 
33
        const gchar *type = NULL;
 
34
        switch (type_enum) {
 
35
        case DKP_DEVICE_TYPE_LINE_POWER:
 
36
                type = "line-power";
 
37
                break;
 
38
        case DKP_DEVICE_TYPE_BATTERY:
 
39
                type = "battery";
 
40
                break;
 
41
        case DKP_DEVICE_TYPE_UPS:
 
42
                type = "ups";
 
43
                break;
 
44
        case DKP_DEVICE_TYPE_MONITOR:
 
45
                type = "monitor";
 
46
                break;
 
47
        case DKP_DEVICE_TYPE_MOUSE:
 
48
                type = "mouse";
 
49
                break;
 
50
        case DKP_DEVICE_TYPE_KEYBOARD:
 
51
                type = "keyboard";
 
52
                break;
 
53
        case DKP_DEVICE_TYPE_PDA:
 
54
                type = "pda";
 
55
                break;
 
56
        case DKP_DEVICE_TYPE_PHONE:
 
57
                type = "phone";
 
58
                break;
 
59
        default:
 
60
                type = "unknown";
 
61
                break;
 
62
        }
 
63
        return type;
 
64
}
 
65
 
 
66
/**
 
67
 * dkp_device_type_from_text:
 
68
 **/
 
69
DkpDeviceType
 
70
dkp_device_type_from_text (const gchar *type)
 
71
{
 
72
        if (type == NULL)
 
73
                return DKP_DEVICE_TYPE_UNKNOWN;
 
74
        if (g_strcmp0 (type, "line-power") == 0)
 
75
                return DKP_DEVICE_TYPE_LINE_POWER;
 
76
        if (g_strcmp0 (type, "battery") == 0)
 
77
                return DKP_DEVICE_TYPE_BATTERY;
 
78
        if (g_strcmp0 (type, "ups") == 0)
 
79
                return DKP_DEVICE_TYPE_UPS;
 
80
        if (g_strcmp0 (type, "monitor") == 0)
 
81
                return DKP_DEVICE_TYPE_MONITOR;
 
82
        if (g_strcmp0 (type, "mouse") == 0)
 
83
                return DKP_DEVICE_TYPE_MOUSE;
 
84
        if (g_strcmp0 (type, "keyboard") == 0)
 
85
                return DKP_DEVICE_TYPE_KEYBOARD;
 
86
        if (g_strcmp0 (type, "pda") == 0)
 
87
                return DKP_DEVICE_TYPE_PDA;
 
88
        if (g_strcmp0 (type, "phone") == 0)
 
89
                return DKP_DEVICE_TYPE_PHONE;
 
90
        return DKP_DEVICE_TYPE_UNKNOWN;
 
91
}
 
92
 
 
93
/**
 
94
 * dkp_device_state_to_text:
 
95
 **/
 
96
const gchar *
 
97
dkp_device_state_to_text (DkpDeviceState state_enum)
 
98
{
 
99
        const gchar *state = NULL;
 
100
        switch (state_enum) {
 
101
        case DKP_DEVICE_STATE_CHARGING:
 
102
                state = "charging";
 
103
                break;
 
104
        case DKP_DEVICE_STATE_DISCHARGING:
 
105
                state = "discharging";
 
106
                break;
 
107
        case DKP_DEVICE_STATE_EMPTY:
 
108
                state = "empty";
 
109
                break;
 
110
        case DKP_DEVICE_STATE_FULLY_CHARGED:
 
111
                state = "fully-charged";
 
112
                break;
 
113
        case DKP_DEVICE_STATE_PENDING_CHARGE:
 
114
                state = "pending-charge";
 
115
                break;
 
116
        case DKP_DEVICE_STATE_PENDING_DISCHARGE:
 
117
                state = "pending-discharge";
 
118
                break;
 
119
        default:
 
120
                state = "unknown";
 
121
                break;
 
122
        }
 
123
        return state;
 
124
}
 
125
 
 
126
/**
 
127
 * dkp_device_state_from_text:
 
128
 **/
 
129
DkpDeviceState
 
130
dkp_device_state_from_text (const gchar *state)
 
131
{
 
132
        if (state == NULL)
 
133
                return DKP_DEVICE_STATE_UNKNOWN;
 
134
        if (g_strcmp0 (state, "charging") == 0)
 
135
                return DKP_DEVICE_STATE_CHARGING;
 
136
        if (g_strcmp0 (state, "discharging") == 0)
 
137
                return DKP_DEVICE_STATE_DISCHARGING;
 
138
        if (g_strcmp0 (state, "empty") == 0)
 
139
                return DKP_DEVICE_STATE_EMPTY;
 
140
        if (g_strcmp0 (state, "fully-charged") == 0)
 
141
                return DKP_DEVICE_STATE_FULLY_CHARGED;
 
142
        if (g_strcmp0 (state, "pending-charge") == 0)
 
143
                return DKP_DEVICE_STATE_PENDING_CHARGE;
 
144
        if (g_strcmp0 (state, "pending-discharge") == 0)
 
145
                return DKP_DEVICE_STATE_PENDING_DISCHARGE;
 
146
        return DKP_DEVICE_STATE_UNKNOWN;
 
147
}
 
148
 
 
149
/**
 
150
 * dkp_device_technology_to_text:
 
151
 **/
 
152
const gchar *
 
153
dkp_device_technology_to_text (DkpDeviceTechnology technology_enum)
 
154
{
 
155
        const gchar *technology = NULL;
 
156
        switch (technology_enum) {
 
157
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_ION:
 
158
                technology = "lithium-ion";
 
159
                break;
 
160
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
 
161
                technology = "lithium-polymer";
 
162
                break;
 
163
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
 
164
                technology = "lithium-iron-phosphate";
 
165
                break;
 
166
        case DKP_DEVICE_TECHNOLOGY_LEAD_ACID:
 
167
                technology = "lead-acid";
 
168
                break;
 
169
        case DKP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
 
170
                technology = "nickel-cadmium";
 
171
                break;
 
172
        case DKP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
 
173
                technology = "nickel-metal-hydride";
 
174
                break;
 
175
        default:
 
176
                technology = "unknown";
 
177
                break;
 
178
        }
 
179
        return technology;
 
180
}
 
181
 
 
182
/**
 
183
 * dkp_device_technology_from_text:
 
184
 **/
 
185
DkpDeviceTechnology
 
186
dkp_device_technology_from_text (const gchar *technology)
 
187
{
 
188
        if (technology == NULL)
 
189
                return DKP_DEVICE_TECHNOLOGY_UNKNOWN;
 
190
        if (g_strcmp0 (technology, "lithium-ion") == 0)
 
191
                return DKP_DEVICE_TECHNOLOGY_LITHIUM_ION;
 
192
        if (g_strcmp0 (technology, "lithium-polymer") == 0)
 
193
                return DKP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER;
 
194
        if (g_strcmp0 (technology, "lithium-iron-phosphate") == 0)
 
195
                return DKP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE;
 
196
        if (g_strcmp0 (technology, "lead-acid") == 0)
 
197
                return DKP_DEVICE_TECHNOLOGY_LEAD_ACID;
 
198
        if (g_strcmp0 (technology, "nickel-cadmium") == 0)
 
199
                return DKP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM;
 
200
        if (g_strcmp0 (technology, "nickel-metal-hydride") == 0)
 
201
                return DKP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE;
 
202
        return DKP_DEVICE_TECHNOLOGY_UNKNOWN;
 
203
}
 
204
 
 
205
/**
 
206
 * dkp_qos_type_to_text:
 
207
 **/
 
208
const gchar *
 
209
dkp_qos_type_to_text (DkpQosType type)
 
210
{
 
211
        if (type == DKP_QOS_TYPE_NETWORK)
 
212
                return "network";
 
213
        if (type == DKP_QOS_TYPE_CPU_DMA)
 
214
                return "cpu_dma";
 
215
        return NULL;
 
216
}
 
217
 
 
218
/**
 
219
 * dkp_qos_type_from_text:
 
220
 **/
 
221
DkpQosType
 
222
dkp_qos_type_from_text (const gchar *type)
 
223
{
 
224
        if (g_strcmp0 (type, "network") == 0)
 
225
                return DKP_QOS_TYPE_NETWORK;
 
226
        if (g_strcmp0 (type, "cpu_dma") == 0)
 
227
                return DKP_QOS_TYPE_CPU_DMA;
 
228
        return DKP_QOS_TYPE_UNKNOWN;
 
229
}
 
230