|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
2 |
*
|
|
|
2.1.18
by Oliver Grawert
Import upstream version 2.17.91 |
3 |
* Copyright (C) 2005-2007 Richard Hughes <richard@hughsie.com>
|
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
4 |
*
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
5 |
* Licensed under the GNU General Public License Version 2
|
6 |
*
|
|
|
2.1.3
by Daniel Silverstone
Import upstream version 2.13.90 |
7 |
* This program is free software; you can redistribute it and/or modify
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or
|
|
10 |
* (at your option) any later version.
|
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
* GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License
|
|
18 |
* along with this program; if not, write to the Free Software
|
|
|
2.1.49
by Martin Pitt
Import upstream version 2.29.2 |
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
20 |
*/
|
21 |
||
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
22 |
#include "config.h"
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
23 |
|
24 |
#include <glib.h>
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
25 |
#include <string.h>
|
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
26 |
#include <glib/gi18n.h>
|
|
2.1.10
by Oliver Grawert
Import upstream version 2.15.4 |
27 |
#include <gdk/gdk.h>
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
28 |
#include <gtk/gtk.h>
|
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
29 |
|
|
2.1.37
by Ted Gould
Import upstream version 2.24.0 |
30 |
#include "egg-debug.h"
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
31 |
#include "gpm-common.h"
|
32 |
||
|
2.1.10
by Oliver Grawert
Import upstream version 2.15.4 |
33 |
/**
|
34 |
* gpm_get_timestring:
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
35 |
* @time_secs: The time value to convert in seconds
|
|
2.1.10
by Oliver Grawert
Import upstream version 2.15.4 |
36 |
* @cookie: The cookie we are looking for
|
37 |
*
|
|
38 |
* Returns a localised timestring
|
|
39 |
*
|
|
40 |
* Return value: The time string, e.g. "2 hours 3 minutes"
|
|
41 |
**/
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
42 |
gchar * |
43 |
gpm_get_timestring (guint time_secs) |
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
44 |
{
|
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
45 |
char* timestring = NULL; |
|
2.1.3
by Daniel Silverstone
Import upstream version 2.13.90 |
46 |
gint hours; |
47 |
gint minutes; |
|
48 |
||
49 |
/* Add 0.5 to do rounding */
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
50 |
minutes = (int) ( ( time_secs / 60.0 ) + 0.5 ); |
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
51 |
|
52 |
if (minutes == 0) { |
|
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
53 |
timestring = g_strdup (_("Unknown time")); |
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
54 |
return timestring; |
55 |
}
|
|
56 |
||
57 |
if (minutes < 60) { |
|
58 |
timestring = g_strdup_printf (ngettext ("%i minute", |
|
|
2.1.10
by Oliver Grawert
Import upstream version 2.15.4 |
59 |
"%i minutes", |
60 |
minutes), minutes); |
|
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
61 |
return timestring; |
62 |
}
|
|
63 |
||
64 |
hours = minutes / 60; |
|
65 |
minutes = minutes % 60; |
|
66 |
||
|
2.1.3
by Daniel Silverstone
Import upstream version 2.13.90 |
67 |
if (minutes == 0) |
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
68 |
timestring = g_strdup_printf (ngettext ( |
69 |
"%i hour", |
|
70 |
"%i hours", |
|
71 |
hours), hours); |
|
72 |
else
|
|
73 |
/* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
|
|
74 |
* Swap order with "%2$s %2$i %1$s %1$i if needed */
|
|
|
2.1.23
by Oliver Grawert
Import upstream version 2.19.2 |
75 |
timestring = g_strdup_printf (_("%i %s %i %s"), |
|
2.1.2
by Oliver Grawert
Import upstream version 0.3.4 |
76 |
hours, ngettext ("hour", "hours", hours), |
77 |
minutes, ngettext ("minute", "minutes", minutes)); |
|
|
1
by Matthew Garrett
suspend by calling gdm-signal directly, rather than by going through |
78 |
return timestring; |
79 |
}
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
80 |
|
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
81 |
/**
|
82 |
* gpm_icon_policy_from_string:
|
|
83 |
**/
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
84 |
GpmIconPolicy
|
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
85 |
gpm_icon_policy_from_string (const gchar *policy) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
86 |
{
|
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
87 |
if (policy == NULL) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
88 |
return GPM_ICON_POLICY_NEVER; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
89 |
if (g_strcmp0 (policy, "always") == 0) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
90 |
return GPM_ICON_POLICY_ALWAYS; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
91 |
if (g_strcmp0 (policy, "present") == 0) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
92 |
return GPM_ICON_POLICY_PRESENT; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
93 |
if (g_strcmp0 (policy, "charge") == 0) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
94 |
return GPM_ICON_POLICY_CHARGE; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
95 |
if (g_strcmp0 (policy, "low") == 0) |
96 |
return GPM_ICON_POLICY_LOW; |
|
97 |
if (g_strcmp0 (policy, "critical") == 0) |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
98 |
return GPM_ICON_POLICY_CRITICAL; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
99 |
if (g_strcmp0 (policy, "never") == 0) |
100 |
return GPM_ICON_POLICY_NEVER; |
|
101 |
return GPM_ICON_POLICY_NEVER; |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
102 |
}
|
103 |
||
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
104 |
/**
|
105 |
* gpm_icon_policy_to_string:
|
|
106 |
**/
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
107 |
const gchar * |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
108 |
gpm_icon_policy_to_string (GpmIconPolicy policy) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
109 |
{
|
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
110 |
if (policy == GPM_ICON_POLICY_ALWAYS) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
111 |
return "always"; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
112 |
if (policy == GPM_ICON_POLICY_PRESENT) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
113 |
return "present"; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
114 |
if (policy == GPM_ICON_POLICY_CHARGE) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
115 |
return "charge"; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
116 |
if (policy == GPM_ICON_POLICY_LOW) |
117 |
return "low"; |
|
118 |
if (policy == GPM_ICON_POLICY_CRITICAL) |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
119 |
return "critical"; |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
120 |
if (policy == GPM_ICON_POLICY_NEVER) |
121 |
return "never"; |
|
122 |
return "never"; |
|
123 |
}
|
|
124 |
||
125 |
/**
|
|
126 |
* gpm_action_policy_from_string:
|
|
127 |
**/
|
|
128 |
GpmActionPolicy
|
|
129 |
gpm_action_policy_from_string (const gchar *policy) |
|
130 |
{
|
|
131 |
if (policy == NULL) |
|
132 |
return GPM_ACTION_POLICY_NOTHING; |
|
133 |
if (g_strcmp0 (policy, "blank") == 0) |
|
134 |
return GPM_ACTION_POLICY_BLANK; |
|
135 |
if (g_strcmp0 (policy, "shutdown") == 0) |
|
136 |
return GPM_ACTION_POLICY_SHUTDOWN; |
|
137 |
if (g_strcmp0 (policy, "suspend") == 0) |
|
138 |
return GPM_ACTION_POLICY_SUSPEND; |
|
139 |
if (g_strcmp0 (policy, "hibernate") == 0) |
|
140 |
return GPM_ACTION_POLICY_HIBERNATE; |
|
141 |
if (g_strcmp0 (policy, "interactive") == 0) |
|
142 |
return GPM_ACTION_POLICY_INTERACTIVE; |
|
143 |
return GPM_ACTION_POLICY_NOTHING; |
|
144 |
}
|
|
145 |
||
146 |
/**
|
|
147 |
* gpm_action_policy_to_string:
|
|
148 |
**/
|
|
149 |
const gchar * |
|
150 |
gpm_action_policy_to_string (GpmActionPolicy policy) |
|
151 |
{
|
|
152 |
if (policy == GPM_ACTION_POLICY_BLANK) |
|
153 |
return "blank"; |
|
154 |
if (policy == GPM_ACTION_POLICY_SHUTDOWN) |
|
155 |
return "shutdown"; |
|
156 |
if (policy == GPM_ACTION_POLICY_SUSPEND) |
|
157 |
return "suspend"; |
|
158 |
if (policy == GPM_ACTION_POLICY_HIBERNATE) |
|
159 |
return "hibernate"; |
|
160 |
if (policy == GPM_ACTION_POLICY_INTERACTIVE) |
|
161 |
return "interactive"; |
|
162 |
return "nothing"; |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
163 |
}
|
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
164 |
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
165 |
/**
|
166 |
* gpm_help_display:
|
|
167 |
* @link_id: Subsection of gnome-power-manager help section
|
|
168 |
**/
|
|
169 |
void
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
170 |
gpm_help_display (const gchar *link_id) |
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
171 |
{
|
172 |
GError *error = NULL; |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
173 |
gchar *uri; |
174 |
||
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
175 |
if (link_id != NULL) |
176 |
uri = g_strconcat ("ghelp:gnome-power-manager?", link_id, NULL); |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
177 |
else
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
178 |
uri = g_strdup ("ghelp:gnome-power-manager"); |
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
179 |
|
180 |
gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, &error); |
|
181 |
||
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
182 |
if (error != NULL) { |
183 |
GtkWidget *d; |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
184 |
d = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
185 |
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error->message); |
|
186 |
gtk_dialog_run (GTK_DIALOG(d)); |
|
187 |
gtk_widget_destroy (d); |
|
188 |
g_error_free (error); |
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
189 |
}
|
190 |
g_free (uri); |
|
191 |
}
|
|
192 |
||
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
193 |
/***************************************************************************
|
194 |
*** MAKE CHECK TESTS ***
|
|
195 |
***************************************************************************/
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
196 |
#ifdef EGG_TEST
|
197 |
#include "egg-test.h"
|
|
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
198 |
|
199 |
void
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
200 |
gpm_common_test (gpointer data) |
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
201 |
{
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
202 |
EggTest *test = (EggTest *) data; |
203 |
if (egg_test_start (test, "GpmCommon") == FALSE) |
|
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
204 |
return; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
205 |
|
206 |
egg_test_end (test); |
|
|
2.1.26
by Oliver Grawert
Import upstream version 2.19.6 |
207 |
}
|
208 |
||
209 |
#endif
|
|
210 |