|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
2 |
*
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
3 |
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
4 |
*
|
5 |
* Licensed under the GNU General Public License Version 2
|
|
6 |
*
|
|
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.
|
|
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.
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
20 |
*/
|
21 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
22 |
#include "config.h"
|
23 |
||
24 |
#include <locale.h>
|
|
25 |
||
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
26 |
#include <glib.h>
|
27 |
#include <glib/gi18n.h>
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
28 |
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
29 |
#include <gtk/gtk.h>
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
30 |
#include <dbus/dbus-glib.h>
|
31 |
#include <gconf/gconf-client.h>
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
32 |
#include <devkit-power-gobject/devicekit-power.h>
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
33 |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
34 |
#include "egg-debug.h"
|
35 |
#include "egg-color.h"
|
|
36 |
#include "egg-array-float.h"
|
|
37 |
#include "egg-unique.h"
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
38 |
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
39 |
#include "gpm-common.h"
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
40 |
#include "gpm-stock-icons.h"
|
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
41 |
#include "gpm-upower.h"
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
42 |
#include "gpm-graph-widget.h"
|
43 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
44 |
static GtkBuilder *builder = NULL; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
45 |
static GtkListStore *list_store_info = NULL; |
46 |
static GtkListStore *list_store_devices = NULL; |
|
47 |
static GtkListStore *list_store_wakeups = NULL; |
|
48 |
gchar *current_device = NULL; |
|
49 |
static const gchar *history_type; |
|
50 |
static const gchar *stats_type; |
|
51 |
static guint history_time; |
|
52 |
static GConfClient *gconf_client; |
|
53 |
static gfloat sigma_smoothing = 0.0f; |
|
54 |
static DkpWakeups *wakeups = NULL; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
55 |
static GtkWidget *graph_history = NULL; |
56 |
static GtkWidget *graph_statistics = NULL; |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
57 |
|
58 |
enum { |
|
59 |
GPM_INFO_COLUMN_TEXT, |
|
60 |
GPM_INFO_COLUMN_VALUE, |
|
61 |
GPM_INFO_COLUMN_LAST
|
|
62 |
};
|
|
63 |
||
64 |
enum { |
|
65 |
GPM_DEVICES_COLUMN_ICON, |
|
66 |
GPM_DEVICES_COLUMN_TEXT, |
|
67 |
GPM_DEVICES_COLUMN_ID, |
|
68 |
GPM_DEVICES_COLUMN_LAST
|
|
69 |
};
|
|
70 |
||
71 |
enum { |
|
72 |
GPM_WAKEUPS_COLUMN_ICON, |
|
73 |
GPM_WAKEUPS_COLUMN_ID, |
|
74 |
GPM_WAKEUPS_COLUMN_VALUE, |
|
75 |
GPM_WAKEUPS_COLUMN_CMDLINE, |
|
76 |
GPM_WAKEUPS_COLUMN_DETAILS, |
|
77 |
GPM_WAKEUPS_COLUMN_LAST
|
|
78 |
};
|
|
79 |
||
80 |
#define GPM_HISTORY_RATE_TEXT _("Rate")
|
|
81 |
#define GPM_HISTORY_CHARGE_TEXT _("Charge")
|
|
82 |
#define GPM_HISTORY_TIME_FULL_TEXT _("Time to full")
|
|
83 |
#define GPM_HISTORY_TIME_EMPTY_TEXT _("Time to empty")
|
|
84 |
||
85 |
#define GPM_HISTORY_RATE_VALUE "rate"
|
|
86 |
#define GPM_HISTORY_CHARGE_VALUE "charge"
|
|
87 |
#define GPM_HISTORY_TIME_FULL_VALUE "time-full"
|
|
88 |
#define GPM_HISTORY_TIME_EMPTY_VALUE "time-empty"
|
|
89 |
||
90 |
#define GPM_HISTORY_MINUTE_TEXT _("10 minutes")
|
|
91 |
#define GPM_HISTORY_HOUR_TEXT _("2 hours")
|
|
92 |
#define GPM_HISTORY_DAY_TEXT _("1 day")
|
|
93 |
#define GPM_HISTORY_WEEK_TEXT _("1 week")
|
|
94 |
||
95 |
#define GPM_HISTORY_MINUTE_VALUE 10*60
|
|
96 |
#define GPM_HISTORY_HOUR_VALUE 2*60*60
|
|
97 |
#define GPM_HISTORY_DAY_VALUE 24*60*60
|
|
98 |
#define GPM_HISTORY_WEEK_VALUE 7*24*60*60
|
|
99 |
||
100 |
#define GPM_STATS_CHARGE_DATA_TEXT _("Charge profile")
|
|
101 |
#define GPM_STATS_CHARGE_ACCURACY_TEXT _("Charge accuracy")
|
|
102 |
#define GPM_STATS_DISCHARGE_DATA_TEXT _("Discharge profile")
|
|
103 |
#define GPM_STATS_DISCHARGE_ACCURACY_TEXT _("Discharge accuracy")
|
|
104 |
||
105 |
#define GPM_STATS_CHARGE_DATA_VALUE "charge-data"
|
|
106 |
#define GPM_STATS_CHARGE_ACCURACY_VALUE "charge-accuracy"
|
|
107 |
#define GPM_STATS_DISCHARGE_DATA_VALUE "discharge-data"
|
|
108 |
#define GPM_STATS_DISCHARGE_ACCURACY_VALUE "discharge-accuracy"
|
|
109 |
||
110 |
/**
|
|
111 |
* gpm_stats_button_help_cb:
|
|
112 |
**/
|
|
113 |
static void |
|
114 |
gpm_stats_button_help_cb (GtkWidget *widget, gboolean data) |
|
115 |
{
|
|
|
2.1.49
by Martin Pitt
Import upstream version 2.29.2 |
116 |
gpm_help_display ("statistics"); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
117 |
}
|
118 |
||
119 |
/**
|
|
120 |
* gpm_stats_add_info_columns:
|
|
121 |
**/
|
|
122 |
static void |
|
123 |
gpm_stats_add_info_columns (GtkTreeView *treeview) |
|
124 |
{
|
|
125 |
GtkCellRenderer *renderer; |
|
126 |
GtkTreeViewColumn *column; |
|
127 |
||
128 |
/* image */
|
|
129 |
renderer = gtk_cell_renderer_text_new (); |
|
130 |
column = gtk_tree_view_column_new_with_attributes (_("Attribute"), renderer, |
|
131 |
"markup", GPM_INFO_COLUMN_TEXT, NULL); |
|
132 |
gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT); |
|
133 |
gtk_tree_view_append_column (treeview, column); |
|
134 |
||
135 |
/* column for text */
|
|
136 |
renderer = gtk_cell_renderer_text_new (); |
|
137 |
column = gtk_tree_view_column_new_with_attributes (_("Value"), renderer, |
|
138 |
"markup", GPM_INFO_COLUMN_VALUE, NULL); |
|
139 |
gtk_tree_view_append_column (treeview, column); |
|
140 |
}
|
|
141 |
||
142 |
/**
|
|
143 |
* gpm_stats_add_devices_columns:
|
|
144 |
**/
|
|
145 |
static void |
|
146 |
gpm_stats_add_devices_columns (GtkTreeView *treeview) |
|
147 |
{
|
|
148 |
GtkCellRenderer *renderer; |
|
149 |
GtkTreeViewColumn *column; |
|
150 |
||
151 |
/* image */
|
|
152 |
renderer = gtk_cell_renderer_pixbuf_new (); |
|
153 |
g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL); |
|
154 |
column = gtk_tree_view_column_new_with_attributes (_("Image"), renderer, |
|
155 |
"icon-name", GPM_DEVICES_COLUMN_ICON, NULL); |
|
156 |
gtk_tree_view_append_column (treeview, column); |
|
157 |
||
158 |
/* column for text */
|
|
159 |
renderer = gtk_cell_renderer_text_new (); |
|
160 |
column = gtk_tree_view_column_new_with_attributes (_("Description"), renderer, |
|
161 |
"markup", GPM_DEVICES_COLUMN_TEXT, NULL); |
|
162 |
gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT); |
|
163 |
gtk_tree_view_append_column (treeview, column); |
|
164 |
gtk_tree_view_column_set_expand (column, TRUE); |
|
165 |
}
|
|
166 |
||
167 |
/**
|
|
168 |
* gpm_stats_add_wakeups_columns:
|
|
169 |
**/
|
|
170 |
static void |
|
171 |
gpm_stats_add_wakeups_columns (GtkTreeView *treeview) |
|
172 |
{
|
|
173 |
GtkCellRenderer *renderer; |
|
174 |
GtkTreeViewColumn *column; |
|
175 |
||
176 |
/* image */
|
|
177 |
renderer = gtk_cell_renderer_pixbuf_new (); |
|
178 |
g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); |
|
179 |
column = gtk_tree_view_column_new_with_attributes (_("Type"), renderer, |
|
180 |
"icon-name", GPM_WAKEUPS_COLUMN_ICON, NULL); |
|
181 |
gtk_tree_view_append_column (treeview, column); |
|
182 |
||
183 |
/* column for id */
|
|
184 |
renderer = gtk_cell_renderer_text_new (); |
|
185 |
column = gtk_tree_view_column_new_with_attributes (_("ID"), renderer, |
|
186 |
"markup", GPM_WAKEUPS_COLUMN_ID, NULL); |
|
187 |
gtk_tree_view_append_column (treeview, column); |
|
188 |
gtk_tree_view_column_set_expand (column, TRUE); |
|
189 |
||
190 |
/* column for value */
|
|
191 |
renderer = gtk_cell_renderer_text_new (); |
|
192 |
column = gtk_tree_view_column_new_with_attributes (_("Wakeups"), renderer, |
|
193 |
"markup", GPM_WAKEUPS_COLUMN_VALUE, NULL); |
|
194 |
gtk_tree_view_append_column (treeview, column); |
|
195 |
gtk_tree_view_column_set_expand (column, TRUE); |
|
196 |
||
197 |
/* column for cmdline */
|
|
198 |
renderer = gtk_cell_renderer_text_new (); |
|
199 |
column = gtk_tree_view_column_new_with_attributes (_("Command"), renderer, |
|
200 |
"markup", GPM_WAKEUPS_COLUMN_CMDLINE, NULL); |
|
201 |
gtk_tree_view_append_column (treeview, column); |
|
202 |
gtk_tree_view_column_set_expand (column, TRUE); |
|
203 |
||
204 |
/* column for details */
|
|
205 |
renderer = gtk_cell_renderer_text_new (); |
|
206 |
column = gtk_tree_view_column_new_with_attributes (_("Details"), renderer, |
|
207 |
"markup", GPM_WAKEUPS_COLUMN_DETAILS, NULL); |
|
208 |
gtk_tree_view_append_column (treeview, column); |
|
209 |
gtk_tree_view_column_set_expand (column, TRUE); |
|
210 |
}
|
|
211 |
||
212 |
/**
|
|
213 |
* gpm_stats_add_info_data:
|
|
214 |
**/
|
|
215 |
static void |
|
216 |
gpm_stats_add_info_data (const gchar *attr, const gchar *text) |
|
217 |
{
|
|
218 |
GtkTreeIter iter; |
|
219 |
gtk_list_store_append (list_store_info, &iter); |
|
220 |
gtk_list_store_set (list_store_info, &iter, |
|
221 |
GPM_INFO_COLUMN_TEXT, attr, |
|
222 |
GPM_INFO_COLUMN_VALUE, text, -1); |
|
223 |
}
|
|
224 |
||
225 |
/**
|
|
226 |
* gpm_stats_update_smooth_data:
|
|
227 |
**/
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
228 |
static GPtrArray * |
229 |
gpm_stats_update_smooth_data (GPtrArray *list) |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
230 |
{
|
231 |
guint i; |
|
232 |
GpmPointObj *point; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
233 |
GpmPointObj *point_new; |
234 |
GPtrArray *new; |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
235 |
EggArrayFloat *raw; |
236 |
EggArrayFloat *convolved; |
|
237 |
EggArrayFloat *outliers; |
|
238 |
EggArrayFloat *gaussian = NULL; |
|
239 |
||
240 |
/* convert the y data to a EggArrayFloat array */
|
|
241 |
raw = egg_array_float_new (list->len); |
|
242 |
for (i=0; i<list->len; i++) { |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
243 |
point = (GpmPointObj *) g_ptr_array_index (list, i); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
244 |
egg_array_float_set (raw, i, point->y); |
245 |
}
|
|
246 |
||
247 |
/* remove any outliers */
|
|
248 |
outliers = egg_array_float_remove_outliers (raw, 3, 0.1); |
|
249 |
||
250 |
/* convolve with gaussian */
|
|
251 |
gaussian = egg_array_float_compute_gaussian (15, sigma_smoothing); |
|
252 |
convolved = egg_array_float_convolve (outliers, gaussian); |
|
253 |
||
254 |
/* add the smoothed data back into a new array */
|
|
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
255 |
new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
256 |
for (i=0; i<list->len; i++) { |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
257 |
point = (GpmPointObj *) g_ptr_array_index (list, i); |
258 |
point_new = g_new0 (GpmPointObj, 1); |
|
259 |
point_new->color = point->color; |
|
260 |
point_new->x = point->x; |
|
261 |
point_new->y = egg_array_float_get (convolved, i); |
|
262 |
g_ptr_array_add (new, point_new); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
263 |
}
|
264 |
||
265 |
/* free data */
|
|
266 |
egg_array_float_free (gaussian); |
|
267 |
egg_array_float_free (raw); |
|
268 |
egg_array_float_free (convolved); |
|
269 |
egg_array_float_free (outliers); |
|
270 |
||
271 |
return new; |
|
272 |
}
|
|
273 |
||
274 |
/**
|
|
275 |
* gpm_stats_time_to_text:
|
|
276 |
**/
|
|
277 |
static gchar * |
|
278 |
gpm_stats_time_to_text (gint seconds) |
|
279 |
{
|
|
280 |
gfloat value = seconds; |
|
281 |
||
|
2.1.51
by Martin Pitt
Import upstream version 2.30.0 |
282 |
if (value < 0) { |
283 |
/* TRANSLATORS: this is when the stats time is not known */
|
|
284 |
return g_strdup (_("Unknown")); |
|
285 |
}
|
|
286 |
if (value < 60) { |
|
287 |
/* TRANSLATORS: this is a time value, usually to show on a graph */
|
|
288 |
return g_strdup_printf (ngettext ("%.0f second", "%.0f seconds", value), value); |
|
289 |
}
|
|
290 |
value /= 60.0; |
|
291 |
if (value < 60) { |
|
292 |
/* TRANSLATORS: this is a time value, usually to show on a graph */
|
|
293 |
return g_strdup_printf (ngettext ("%.1f minute", "%.1f minutes", value), value); |
|
294 |
}
|
|
295 |
value /= 60.0; |
|
296 |
if (value < 60) { |
|
297 |
/* TRANSLATORS: this is a time value, usually to show on a graph */
|
|
298 |
return g_strdup_printf (ngettext ("%.1f hour", "%.1f hours", value), value); |
|
299 |
}
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
300 |
value /= 24.0; |
|
2.1.51
by Martin Pitt
Import upstream version 2.30.0 |
301 |
/* TRANSLATORS: this is a time value, usually to show on a graph */
|
302 |
return g_strdup_printf (ngettext ("%.1f day", "%.1f days", value), value); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
303 |
}
|
304 |
||
305 |
/**
|
|
306 |
* gpm_stats_bool_to_text:
|
|
307 |
**/
|
|
308 |
static const gchar * |
|
309 |
gpm_stats_bool_to_text (gboolean ret) |
|
310 |
{
|
|
311 |
return ret ? _("Yes") : _("No"); |
|
312 |
}
|
|
313 |
||
314 |
/**
|
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
315 |
* gpm_stats_get_printable_device_path:
|
316 |
**/
|
|
317 |
static gchar * |
|
318 |
gpm_stats_get_printable_device_path (DkpDevice *device) |
|
319 |
{
|
|
320 |
const gchar *object_path; |
|
321 |
gchar *device_path = NULL; |
|
322 |
||
323 |
/* get object path */
|
|
324 |
object_path = dkp_device_get_object_path (device); |
|
|
2.1.49
by Martin Pitt
Import upstream version 2.29.2 |
325 |
if (object_path != NULL) |
326 |
device_path = g_filename_display_basename (object_path); |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
327 |
|
328 |
return device_path; |
|
329 |
}
|
|
330 |
||
331 |
/**
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
332 |
* gpm_stats_update_info_page_details:
|
333 |
**/
|
|
334 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
335 |
gpm_stats_update_info_page_details (DkpDevice *device) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
336 |
{
|
337 |
struct tm *time_tm; |
|
338 |
time_t t; |
|
339 |
gchar time_buf[256]; |
|
340 |
gchar *text; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
341 |
guint refreshed; |
342 |
DkpDeviceType type; |
|
343 |
DkpDeviceState state; |
|
344 |
DkpDeviceTechnology technology; |
|
345 |
gdouble percentage; |
|
346 |
gdouble capacity; |
|
347 |
gdouble energy; |
|
348 |
gdouble energy_empty; |
|
349 |
gdouble energy_full; |
|
350 |
gdouble energy_full_design; |
|
351 |
gdouble energy_rate; |
|
352 |
gdouble voltage; |
|
353 |
gboolean online; |
|
354 |
gboolean is_present; |
|
355 |
gboolean power_supply; |
|
356 |
gboolean is_rechargeable; |
|
357 |
guint64 update_time; |
|
358 |
gint64 time_to_full; |
|
359 |
gint64 time_to_empty; |
|
360 |
gchar *vendor = NULL; |
|
361 |
gchar *serial = NULL; |
|
362 |
gchar *model = NULL; |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
363 |
gchar *device_path = NULL; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
364 |
|
365 |
gtk_list_store_clear (list_store_info); |
|
366 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
367 |
/* get device properties */
|
368 |
g_object_get (device, |
|
369 |
"type", &type, |
|
370 |
"state", &state, |
|
371 |
"percentage", &percentage, |
|
372 |
"online", &online, |
|
373 |
"update_time", &update_time, |
|
374 |
"power_supply", &power_supply, |
|
375 |
"is_rechargeable", &is_rechargeable, |
|
376 |
"is-present", &is_present, |
|
377 |
"time-to-full", &time_to_full, |
|
378 |
"time-to-empty", &time_to_empty, |
|
379 |
"technology", &technology, |
|
380 |
"capacity", &capacity, |
|
381 |
"energy", &energy, |
|
382 |
"energy-empty", &energy_empty, |
|
383 |
"energy-full", &energy_full, |
|
384 |
"energy-full-design", &energy_full_design, |
|
385 |
"energy-rate", &energy_rate, |
|
386 |
"voltage", &voltage, |
|
387 |
"vendor", &vendor, |
|
388 |
"serial", &serial, |
|
389 |
"model", &model, |
|
390 |
NULL); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
391 |
|
392 |
/* get a human readable time */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
393 |
t = (time_t) update_time; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
394 |
time_tm = localtime (&t); |
395 |
strftime (time_buf, sizeof time_buf, "%c", time_tm); |
|
396 |
||
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
397 |
/* remove prefix */
|
398 |
device_path = gpm_stats_get_printable_device_path (device); |
|
399 |
gpm_stats_add_info_data (_("Device"), device_path); |
|
400 |
g_free (device_path); |
|
401 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
402 |
gpm_stats_add_info_data (_("Type"), gpm_device_type_to_localised_text (type, 1)); |
403 |
if (vendor != NULL && vendor[0] != '\0') |
|
404 |
gpm_stats_add_info_data (_("Vendor"), vendor); |
|
405 |
if (model != NULL && model[0] != '\0') |
|
406 |
gpm_stats_add_info_data (_("Model"), model); |
|
407 |
if (serial != NULL && serial[0] != '\0') |
|
408 |
gpm_stats_add_info_data (_("Serial number"), serial); |
|
409 |
gpm_stats_add_info_data (_("Supply"), gpm_stats_bool_to_text (power_supply)); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
410 |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
411 |
refreshed = (int) (time (NULL) - update_time); |
412 |
text = g_strdup_printf (ngettext ("%d second", "%d seconds", refreshed), refreshed); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
413 |
gpm_stats_add_info_data (_("Refreshed"), text); |
414 |
g_free (text); |
|
415 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
416 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
417 |
type == DKP_DEVICE_TYPE_MOUSE || |
|
418 |
type == DKP_DEVICE_TYPE_KEYBOARD || |
|
419 |
type == DKP_DEVICE_TYPE_UPS) |
|
420 |
gpm_stats_add_info_data (_("Present"), gpm_stats_bool_to_text (is_present)); |
|
421 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
|
422 |
type == DKP_DEVICE_TYPE_MOUSE || |
|
423 |
type == DKP_DEVICE_TYPE_KEYBOARD) |
|
424 |
gpm_stats_add_info_data (_("Rechargeable"), gpm_stats_bool_to_text (is_rechargeable)); |
|
425 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
|
426 |
type == DKP_DEVICE_TYPE_MOUSE || |
|
427 |
type == DKP_DEVICE_TYPE_KEYBOARD) |
|
428 |
gpm_stats_add_info_data (_("State"), dkp_device_state_to_text (state)); |
|
429 |
if (type == DKP_DEVICE_TYPE_BATTERY) { |
|
430 |
text = g_strdup_printf ("%.1f Wh", energy); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
431 |
gpm_stats_add_info_data (_("Energy"), text); |
432 |
g_free (text); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
433 |
text = g_strdup_printf ("%.1f Wh", energy_empty); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
434 |
gpm_stats_add_info_data (_("Energy when empty"), text); |
435 |
g_free (text); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
436 |
text = g_strdup_printf ("%.1f Wh", energy_full); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
437 |
gpm_stats_add_info_data (_("Energy when full"), text); |
438 |
g_free (text); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
439 |
text = g_strdup_printf ("%.1f Wh", energy_full_design); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
440 |
gpm_stats_add_info_data (_("Energy (design)"), text); |
441 |
g_free (text); |
|
442 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
443 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
444 |
type == DKP_DEVICE_TYPE_MONITOR) { |
|
445 |
text = g_strdup_printf ("%.1f W", energy_rate); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
446 |
gpm_stats_add_info_data (_("Rate"), text); |
447 |
g_free (text); |
|
448 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
449 |
if (type == DKP_DEVICE_TYPE_UPS || |
450 |
type == DKP_DEVICE_TYPE_BATTERY || |
|
451 |
type == DKP_DEVICE_TYPE_MONITOR) { |
|
452 |
text = g_strdup_printf ("%.1f V", voltage); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
453 |
gpm_stats_add_info_data (_("Voltage"), text); |
454 |
g_free (text); |
|
455 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
456 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
457 |
type == DKP_DEVICE_TYPE_UPS) { |
|
458 |
if (time_to_full >= 0) { |
|
459 |
text = gpm_stats_time_to_text (time_to_full); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
460 |
gpm_stats_add_info_data (_("Time to full"), text); |
461 |
g_free (text); |
|
462 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
463 |
if (time_to_empty >= 0) { |
464 |
text = gpm_stats_time_to_text (time_to_empty); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
465 |
gpm_stats_add_info_data (_("Time to empty"), text); |
466 |
g_free (text); |
|
467 |
}
|
|
468 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
469 |
if (type == DKP_DEVICE_TYPE_BATTERY || |
470 |
type == DKP_DEVICE_TYPE_MOUSE || |
|
471 |
type == DKP_DEVICE_TYPE_KEYBOARD || |
|
472 |
type == DKP_DEVICE_TYPE_UPS) { |
|
473 |
text = g_strdup_printf ("%.1f%%", percentage); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
474 |
gpm_stats_add_info_data (_("Percentage"), text); |
475 |
g_free (text); |
|
476 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
477 |
if (type == DKP_DEVICE_TYPE_BATTERY) { |
478 |
text = g_strdup_printf ("%.1f%%", capacity); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
479 |
gpm_stats_add_info_data (_("Capacity"), text); |
480 |
g_free (text); |
|
481 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
482 |
if (type == DKP_DEVICE_TYPE_BATTERY) |
483 |
gpm_stats_add_info_data (_("Technology"), gpm_device_technology_to_localised_text (technology)); |
|
484 |
if (type == DKP_DEVICE_TYPE_LINE_POWER) |
|
485 |
gpm_stats_add_info_data (_("Online"), gpm_stats_bool_to_text (online)); |
|
486 |
||
487 |
g_free (vendor); |
|
488 |
g_free (serial); |
|
489 |
g_free (model); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
490 |
}
|
491 |
||
492 |
/**
|
|
493 |
* gpm_stats_set_graph_data:
|
|
494 |
**/
|
|
495 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
496 |
gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoothed, gboolean use_points) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
497 |
{
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
498 |
GPtrArray *smoothed; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
499 |
|
500 |
gpm_graph_widget_data_clear (GPM_GRAPH_WIDGET (widget)); |
|
501 |
||
502 |
/* add correct data */
|
|
503 |
if (!use_smoothed) { |
|
504 |
if (use_points) |
|
505 |
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_BOTH, data); |
|
506 |
else
|
|
507 |
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_LINE, data); |
|
508 |
} else { |
|
509 |
smoothed = gpm_stats_update_smooth_data (data); |
|
510 |
if (use_points) |
|
511 |
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_POINTS, data); |
|
512 |
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_PLOT_LINE, smoothed); |
|
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
513 |
g_ptr_array_unref (smoothed); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
514 |
}
|
515 |
||
516 |
/* show */
|
|
517 |
gtk_widget_show (widget); |
|
518 |
}
|
|
519 |
||
520 |
/**
|
|
521 |
* gpm_stats_update_info_page_history:
|
|
522 |
**/
|
|
523 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
524 |
gpm_stats_update_info_page_history (DkpDevice *device) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
525 |
{
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
526 |
GPtrArray *array; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
527 |
guint i; |
528 |
DkpHistoryObj *hobj; |
|
529 |
GtkWidget *widget; |
|
530 |
gboolean checked; |
|
531 |
gboolean points; |
|
532 |
GpmPointObj *point; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
533 |
GPtrArray *new; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
534 |
gint32 offset = 0; |
535 |
GTimeVal timeval; |
|
536 |
||
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
537 |
new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
538 |
if (g_strcmp0 (history_type, GPM_HISTORY_CHARGE_VALUE) == 0) { |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
539 |
g_object_set (graph_history, |
540 |
"type-x", GPM_GRAPH_WIDGET_TYPE_TIME, |
|
541 |
"type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE, |
|
542 |
"autorange-x", FALSE, |
|
543 |
"start-x", -history_time, |
|
544 |
"stop-x", 0, |
|
545 |
"autorange-y", TRUE, |
|
546 |
NULL); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
547 |
} else if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0) { |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
548 |
g_object_set (graph_history, |
549 |
"type-x", GPM_GRAPH_WIDGET_TYPE_TIME, |
|
550 |
"type-y", GPM_GRAPH_WIDGET_TYPE_POWER, |
|
551 |
"autorange-x", FALSE, |
|
552 |
"start-x", -history_time, |
|
553 |
"stop-x", 0, |
|
554 |
"autorange-y", TRUE, |
|
555 |
NULL); |
|
556 |
} else { |
|
557 |
g_object_set (graph_history, |
|
558 |
"type-x", GPM_GRAPH_WIDGET_TYPE_TIME, |
|
559 |
"type-y", GPM_GRAPH_WIDGET_TYPE_TIME, |
|
560 |
"autorange-x", FALSE, |
|
561 |
"start-x", -history_time, |
|
562 |
"stop-x", 0, |
|
563 |
"autorange-y", TRUE, |
|
564 |
NULL); |
|
565 |
}
|
|
566 |
||
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
567 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_history_nodata")); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
568 |
array = dkp_device_get_history (device, history_type, history_time, 150, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
569 |
if (array == NULL) { |
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
570 |
/* show no data label and hide graph */
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
571 |
gtk_widget_hide (graph_history); |
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
572 |
gtk_widget_show (widget); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
573 |
goto out; |
574 |
}
|
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
575 |
|
576 |
/* hide no data and show graph */
|
|
577 |
gtk_widget_hide (widget); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
578 |
gtk_widget_show (graph_history); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
579 |
|
580 |
g_get_current_time (&timeval); |
|
581 |
offset = timeval.tv_sec; |
|
582 |
||
583 |
for (i=0; i<array->len; i++) { |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
584 |
hobj = (DkpHistoryObj *) g_ptr_array_index (array, i); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
585 |
|
586 |
/* abandon this point */
|
|
587 |
if (hobj->state == DKP_DEVICE_STATE_UNKNOWN) |
|
588 |
continue; |
|
589 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
590 |
point = gpm_point_obj_new (); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
591 |
point->x = (gint32) hobj->time - offset; |
592 |
point->y = hobj->value; |
|
593 |
if (hobj->state == DKP_DEVICE_STATE_CHARGING) |
|
594 |
point->color = egg_color_from_rgb (255, 0, 0); |
|
595 |
else if (hobj->state == DKP_DEVICE_STATE_DISCHARGING) |
|
596 |
point->color = egg_color_from_rgb (0, 0, 255); |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
597 |
#if DKP_CHECK_VERSION(0x009)
|
598 |
else if (hobj->state == DKP_DEVICE_STATE_PENDING_CHARGE) |
|
599 |
point->color = egg_color_from_rgb (200, 0, 0); |
|
600 |
else if (hobj->state == DKP_DEVICE_STATE_PENDING_DISCHARGE) |
|
601 |
point->color = egg_color_from_rgb (0, 0, 200); |
|
602 |
#endif
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
603 |
else { |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
604 |
if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
605 |
point->color = egg_color_from_rgb (255, 255, 255); |
606 |
else
|
|
607 |
point->color = egg_color_from_rgb (0, 255, 0); |
|
608 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
609 |
g_ptr_array_add (new, point); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
610 |
}
|
611 |
||
612 |
/* render */
|
|
613 |
sigma_smoothing = 2.0; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
614 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
615 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
616 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
617 |
points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
618 |
||
619 |
/* present data to graph */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
620 |
gpm_stats_set_graph_data (graph_history, new, checked, points); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
621 |
|
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
622 |
g_ptr_array_unref (array); |
623 |
g_ptr_array_unref (new); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
624 |
out:
|
625 |
return; |
|
626 |
}
|
|
627 |
||
628 |
/**
|
|
629 |
* gpm_stats_update_info_page_stats:
|
|
630 |
**/
|
|
631 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
632 |
gpm_stats_update_info_page_stats (DkpDevice *device) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
633 |
{
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
634 |
GPtrArray *array; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
635 |
guint i; |
636 |
DkpStatsObj *sobj; |
|
637 |
GtkWidget *widget; |
|
638 |
gboolean checked; |
|
639 |
gboolean points; |
|
640 |
GpmPointObj *point; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
641 |
GPtrArray *new; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
642 |
gboolean use_data = FALSE; |
643 |
const gchar *type = NULL; |
|
644 |
||
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
645 |
new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
646 |
if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
647 |
type = "charging"; |
648 |
use_data = TRUE; |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
649 |
} else if (g_strcmp0 (stats_type, GPM_STATS_DISCHARGE_DATA_VALUE) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
650 |
type = "discharging"; |
651 |
use_data = TRUE; |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
652 |
} else if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_ACCURACY_VALUE) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
653 |
type = "charging"; |
654 |
use_data = FALSE; |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
655 |
} else if (g_strcmp0 (stats_type, GPM_STATS_DISCHARGE_ACCURACY_VALUE) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
656 |
type = "discharging"; |
657 |
use_data = FALSE; |
|
658 |
} else { |
|
659 |
g_assert_not_reached (); |
|
660 |
}
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
661 |
|
662 |
if (use_data) { |
|
663 |
g_object_set (graph_statistics, |
|
664 |
"type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE, |
|
665 |
"type-y", GPM_GRAPH_WIDGET_TYPE_FACTOR, |
|
666 |
"autorange-x", TRUE, |
|
667 |
"autorange-y", TRUE, |
|
668 |
NULL); |
|
669 |
} else { |
|
670 |
g_object_set (graph_statistics, |
|
671 |
"type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE, |
|
672 |
"type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE, |
|
673 |
"autorange-x", TRUE, |
|
674 |
"autorange-y", TRUE, |
|
675 |
NULL); |
|
676 |
}
|
|
677 |
||
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
678 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_stats_nodata")); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
679 |
array = dkp_device_get_statistics (device, type, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
680 |
if (array == NULL) { |
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
681 |
/* show no data label and hide graph */
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
682 |
gtk_widget_hide (graph_statistics); |
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
683 |
gtk_widget_show (widget); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
684 |
goto out; |
685 |
}
|
|
686 |
||
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
687 |
/* hide no data and show graph */
|
688 |
gtk_widget_hide (widget); |
|
689 |
gtk_widget_show (graph_statistics); |
|
690 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
691 |
for (i=0; i<array->len; i++) { |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
692 |
sobj = (DkpStatsObj *) g_ptr_array_index (array, i); |
693 |
point = gpm_point_obj_new (); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
694 |
point->x = i; |
695 |
if (use_data) |
|
696 |
point->y = sobj->value; |
|
697 |
else
|
|
698 |
point->y = sobj->accuracy; |
|
699 |
point->color = egg_color_from_rgb (255, 0, 0); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
700 |
g_ptr_array_add (new, point); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
701 |
}
|
702 |
||
703 |
/* render */
|
|
704 |
sigma_smoothing = 1.1; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
705 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
706 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
707 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
708 |
points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
709 |
||
710 |
/* present data to graph */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
711 |
gpm_stats_set_graph_data (graph_statistics, new, checked, points); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
712 |
|
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
713 |
g_ptr_array_unref (array); |
714 |
g_ptr_array_unref (new); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
715 |
out:
|
716 |
return; |
|
717 |
}
|
|
718 |
||
719 |
/**
|
|
720 |
* gpm_stats_update_info_data_page:
|
|
721 |
**/
|
|
722 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
723 |
gpm_stats_update_info_data_page (DkpDevice *device, gint page) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
724 |
{
|
725 |
if (page == 0) |
|
726 |
gpm_stats_update_info_page_details (device); |
|
727 |
else if (page == 1) |
|
728 |
gpm_stats_update_info_page_history (device); |
|
729 |
else if (page == 2) |
|
730 |
gpm_stats_update_info_page_stats (device); |
|
731 |
}
|
|
732 |
||
733 |
/**
|
|
734 |
* gpm_stats_update_info_data:
|
|
735 |
**/
|
|
736 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
737 |
gpm_stats_update_info_data (DkpDevice *device) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
738 |
{
|
739 |
gint page; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
740 |
GtkNotebook *notebook; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
741 |
GtkWidget *page_widget; |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
742 |
gboolean has_history; |
743 |
gboolean has_statistics; |
|
744 |
||
745 |
/* get properties */
|
|
746 |
g_object_get (device, |
|
747 |
"has-history", &has_history, |
|
748 |
"has-statistics", &has_statistics, |
|
749 |
NULL); |
|
750 |
||
751 |
||
752 |
notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1")); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
753 |
|
754 |
/* show info page */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
755 |
page_widget = gtk_notebook_get_nth_page (notebook, 0); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
756 |
gtk_widget_show (page_widget); |
757 |
||
758 |
/* hide history if no support */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
759 |
page_widget = gtk_notebook_get_nth_page (notebook, 1); |
760 |
if (has_history) |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
761 |
gtk_widget_show (page_widget); |
762 |
else
|
|
763 |
gtk_widget_hide (page_widget); |
|
764 |
||
765 |
/* hide statistics if no support */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
766 |
page_widget = gtk_notebook_get_nth_page (notebook, 2); |
767 |
if (has_statistics) |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
768 |
gtk_widget_show (page_widget); |
769 |
else
|
|
770 |
gtk_widget_hide (page_widget); |
|
771 |
||
772 |
/* hide wakeups page */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
773 |
page_widget = gtk_notebook_get_nth_page (notebook, 3); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
774 |
gtk_widget_hide (page_widget); |
775 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
776 |
page = gtk_notebook_get_current_page (notebook); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
777 |
gpm_stats_update_info_data_page (device, page); |
778 |
||
779 |
return; |
|
780 |
}
|
|
781 |
||
782 |
/**
|
|
783 |
* gpm_stats_format_cmdline:
|
|
784 |
**/
|
|
785 |
static gchar * |
|
786 |
gpm_stats_format_cmdline (const DkpWakeupsObj *obj) |
|
787 |
{
|
|
788 |
gchar *found; |
|
789 |
gchar *temp = NULL; |
|
790 |
gchar *cmdline; |
|
791 |
const gchar *temp_ptr; |
|
792 |
||
793 |
/* nothing */
|
|
794 |
if (obj->cmdline == NULL) { |
|
795 |
/* TRANSLATORS: the command line was not provided */
|
|
796 |
temp_ptr = _("No data"); |
|
797 |
goto out; |
|
798 |
}
|
|
799 |
||
800 |
/* common kernel cmd names */
|
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
801 |
if (g_strcmp0 (obj->cmdline, "insmod") == 0) { |
802 |
/* TRANSLATORS: kernel module, usually a device driver */
|
|
803 |
temp_ptr = _("Kernel module"); |
|
804 |
goto out; |
|
805 |
}
|
|
806 |
if (g_strcmp0 (obj->cmdline, "modprobe") == 0) { |
|
807 |
/* TRANSLATORS: kernel module, usually a device driver */
|
|
808 |
temp_ptr = _("Kernel module"); |
|
809 |
goto out; |
|
810 |
}
|
|
811 |
if (g_strcmp0 (obj->cmdline, "swapper") == 0) { |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
812 |
/* TRANSLATORS: kernel housekeeping */
|
813 |
temp_ptr = _("Kernel core"); |
|
814 |
goto out; |
|
815 |
}
|
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
816 |
if (g_strcmp0 (obj->cmdline, "kernel-ipi") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
817 |
/* TRANSLATORS: interrupt between processors */
|
818 |
temp_ptr = _("Interprocessor interrupt"); |
|
819 |
goto out; |
|
820 |
}
|
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
821 |
if (g_strcmp0 (obj->cmdline, "interrupt") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
822 |
/* TRANSLATORS: unknown interrupt */
|
823 |
temp_ptr = _("Interrupt"); |
|
824 |
goto out; |
|
825 |
}
|
|
826 |
||
827 |
/* truncate at first space or ':' */
|
|
828 |
temp = g_strdup (obj->cmdline); |
|
829 |
found = strstr (temp, ":"); |
|
830 |
if (found != NULL) |
|
831 |
*found = '\0'; |
|
832 |
found = strstr (temp, " "); |
|
833 |
if (found != NULL) |
|
834 |
*found = '\0'; |
|
835 |
||
836 |
/* remove path */
|
|
837 |
found = g_strrstr (temp, "/"); |
|
838 |
if (found != NULL && strncmp (temp, "event", 5) != 0) |
|
839 |
temp_ptr = found + 1; |
|
840 |
else
|
|
841 |
temp_ptr = temp; |
|
842 |
||
843 |
out:
|
|
844 |
/* format command line */
|
|
845 |
if (obj->is_userspace) |
|
846 |
cmdline = g_markup_escape_text (temp_ptr, -1); |
|
847 |
else
|
|
848 |
cmdline = g_markup_printf_escaped ("<i>%s</i>", temp_ptr); |
|
849 |
g_free (temp); |
|
850 |
||
851 |
/* return */
|
|
852 |
return cmdline; |
|
853 |
}
|
|
854 |
||
855 |
/**
|
|
856 |
* gpm_stats_format_details:
|
|
857 |
**/
|
|
858 |
static gchar * |
|
859 |
gpm_stats_format_details (const DkpWakeupsObj *obj) |
|
860 |
{
|
|
861 |
gchar *details; |
|
862 |
||
863 |
/* replace common driver names */
|
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
864 |
if (g_strcmp0 (obj->details, "i8042") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
865 |
/* TRANSLATORS: the keyboard and mouse device event */
|
866 |
details = g_strdup (_("PS/2 keyboard/mouse/touchpad")); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
867 |
} else if (g_strcmp0 (obj->details, "acpi") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
868 |
/* TRANSLATORS: ACPI, the Intel power standard on laptops and desktops */
|
869 |
details = g_strdup (_("ACPI")); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
870 |
} else if (g_strcmp0 (obj->details, "ata_piix") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
871 |
/* TRANSLATORS: serial ATA is a new style of hard disk interface */
|
872 |
details = g_strdup (_("Serial ATA")); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
873 |
} else if (g_strcmp0 (obj->details, "libata") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
874 |
/* TRANSLATORS: this is the old-style ATA interface */
|
875 |
details = g_strdup (_("ATA host controller")); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
876 |
} else if (g_strcmp0 (obj->details, "iwl3945") == 0 || g_strcmp0 (obj->details, "iwlagn") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
877 |
/* TRANSLATORS: 802.11 wireless adaptor */
|
878 |
details = g_strdup (_("Intel wireless adaptor")); |
|
879 |
||
880 |
/* try to make the wakeup type nicer */
|
|
881 |
} else if (g_str_has_prefix (obj->details, "__mod_timer")) { |
|
882 |
/* TRANSLATORS: a timer is something that fires periodically */
|
|
883 |
details = g_strdup_printf (_("Timer %s"), obj->details+12); |
|
884 |
} else if (g_str_has_prefix (obj->details, "mod_timer")) { |
|
885 |
/* TRANSLATORS: a timer is something that fires periodically */
|
|
886 |
details = g_strdup_printf (_("Timer %s"), obj->details+10); |
|
887 |
} else if (g_str_has_prefix (obj->details, "hrtimer_start_expires")) { |
|
888 |
/* TRANSLATORS: a timer is something that fires periodically */
|
|
889 |
details = g_strdup_printf (_("Timer %s"), obj->details+22); |
|
890 |
} else if (g_str_has_prefix (obj->details, "hrtimer_start")) { |
|
891 |
/* TRANSLATORS: a timer is something that fires periodically */
|
|
892 |
details = g_strdup_printf (_("Timer %s"), obj->details+14); |
|
893 |
} else if (g_str_has_prefix (obj->details, "do_setitimer")) { |
|
894 |
/* TRANSLATORS: a timer is something that fires periodically */
|
|
895 |
details = g_strdup_printf (_("Timer %s"), obj->details+10); |
|
896 |
} else if (g_str_has_prefix (obj->details, "do_nanosleep")) { |
|
897 |
/* TRANSLATORS: this is a task that's woken up from sleeping */
|
|
898 |
details = g_strdup_printf (_("Sleep %s"), obj->details+13); |
|
899 |
} else if (g_str_has_prefix (obj->details, "enqueue_task_rt")) { |
|
900 |
/* TRANSLATORS: this is a new realtime task */
|
|
901 |
details = g_strdup_printf (_("New task %s"), obj->details+16); |
|
902 |
} else if (g_str_has_prefix (obj->details, "futex_wait")) { |
|
903 |
/* TRANSLATORS: this is a task thats woken to check state */
|
|
904 |
details = g_strdup_printf (_("Wait %s"), obj->details+11); |
|
905 |
} else if (g_str_has_prefix (obj->details, "queue_delayed_work_on")) { |
|
906 |
/* TRANSLATORS: a work queue is a list of work that has to be done */
|
|
907 |
details = g_strdup_printf (_("Work queue %s"), obj->details+22); |
|
908 |
} else if (g_str_has_prefix (obj->details, "queue_delayed_work")) { |
|
909 |
/* TRANSLATORS: a work queue is a list of work that has to be done */
|
|
910 |
details = g_strdup_printf (_("Work queue %s"), obj->details+19); |
|
911 |
} else if (g_str_has_prefix (obj->details, "dst_run_gc")) { |
|
912 |
/* TRANSLATORS: this is when the networking subsystem clears out old entries */
|
|
913 |
details = g_strdup_printf (_("Network route flush %s"), obj->details+11); |
|
914 |
} else if (g_str_has_prefix (obj->details, "usb_hcd_poll_rh_status")) { |
|
915 |
/* TRANSLATORS: activity on the USB bus */
|
|
916 |
details = g_strdup_printf (_("USB activity %s"), obj->details+23); |
|
917 |
} else if (g_str_has_prefix (obj->details, "schedule_hrtimeout_range")) { |
|
918 |
/* TRANSLATORS: we've timed out of an aligned timer */
|
|
919 |
details = g_strdup_printf (_("Wakeup %s"), obj->details+25); |
|
920 |
} else if (g_str_has_prefix (obj->details, "Local timer interrupts")) { |
|
921 |
/* TRANSLATORS: interupts on the system required for basic operation */
|
|
922 |
details = g_strdup (_("Local interrupts")); |
|
923 |
} else if (g_str_has_prefix (obj->details, "Rescheduling interrupts")) { |
|
924 |
/* TRANSLATORS: interrupts when a task gets moved from one core to another */
|
|
925 |
details = g_strdup (_("Rescheduling interrupts")); |
|
926 |
} else |
|
927 |
details = g_markup_escape_text (obj->details, -1); |
|
928 |
||
929 |
return details; |
|
930 |
}
|
|
931 |
/**
|
|
932 |
* gpm_stats_add_wakeups_obj:
|
|
933 |
**/
|
|
934 |
static void |
|
935 |
gpm_stats_add_wakeups_obj (const DkpWakeupsObj *obj) |
|
936 |
{
|
|
937 |
const gchar *icon; |
|
938 |
gchar *value; |
|
939 |
gchar *id; |
|
940 |
gchar *details; |
|
941 |
gchar *cmdline; |
|
942 |
GtkTreeIter iter; |
|
943 |
||
944 |
if (obj->is_userspace) { |
|
945 |
icon = "application-x-executable"; |
|
946 |
id = g_strdup_printf ("%i", obj->id); |
|
947 |
} else { |
|
948 |
icon = "applications-system"; |
|
949 |
if (obj->id < 0xff0) |
|
950 |
id = g_strdup_printf ("IRQ%i", obj->id); |
|
951 |
else
|
|
952 |
id = g_strdup ("IRQx"); |
|
953 |
}
|
|
954 |
||
955 |
/* formate value to one decimal place */
|
|
956 |
value = g_strdup_printf ("%.1f", obj->value); |
|
957 |
||
958 |
/* get formatted lines */
|
|
959 |
cmdline = gpm_stats_format_cmdline (obj); |
|
960 |
details = gpm_stats_format_details (obj); |
|
961 |
||
962 |
gtk_list_store_append (list_store_wakeups, &iter); |
|
963 |
gtk_list_store_set (list_store_wakeups, &iter, |
|
964 |
GPM_WAKEUPS_COLUMN_ID, id, |
|
965 |
GPM_WAKEUPS_COLUMN_VALUE, value, |
|
966 |
GPM_WAKEUPS_COLUMN_CMDLINE, cmdline, |
|
967 |
GPM_WAKEUPS_COLUMN_DETAILS, details, |
|
968 |
GPM_WAKEUPS_COLUMN_ICON, icon, -1); |
|
969 |
g_free (cmdline); |
|
970 |
g_free (details); |
|
971 |
g_free (value); |
|
972 |
g_free (id); |
|
973 |
}
|
|
974 |
||
975 |
/**
|
|
976 |
* gpm_stats_update_wakeups_data:
|
|
977 |
**/
|
|
978 |
static void |
|
979 |
gpm_stats_update_wakeups_data (void) |
|
980 |
{
|
|
981 |
GtkWidget *widget; |
|
982 |
GtkWidget *page_widget; |
|
983 |
guint total; |
|
984 |
DkpWakeupsObj *obj; |
|
985 |
gchar *text; |
|
986 |
guint i; |
|
987 |
GError *error = NULL; |
|
988 |
GPtrArray *array; |
|
989 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
990 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
991 |
|
992 |
/* hide other pages */
|
|
993 |
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 0); |
|
994 |
gtk_widget_hide (page_widget); |
|
995 |
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 1); |
|
996 |
gtk_widget_hide (page_widget); |
|
997 |
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 2); |
|
998 |
gtk_widget_hide (page_widget); |
|
999 |
||
1000 |
/* show wakeups page */
|
|
1001 |
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 3); |
|
1002 |
gtk_widget_show (page_widget); |
|
1003 |
||
1004 |
/* show total */
|
|
1005 |
total = dkp_wakeups_get_total (wakeups, &error); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1006 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_total_wakeups")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1007 |
if (error == NULL) { |
1008 |
text = g_strdup_printf ("%i", total); |
|
1009 |
gtk_label_set_label (GTK_LABEL(widget), text); |
|
1010 |
g_free (text); |
|
1011 |
} else { |
|
1012 |
gtk_label_set_label (GTK_LABEL(widget), error->message); |
|
1013 |
g_error_free (error); |
|
1014 |
}
|
|
1015 |
||
1016 |
/* get data */
|
|
1017 |
gtk_list_store_clear (list_store_wakeups); |
|
1018 |
array = dkp_wakeups_get_data (wakeups, NULL); |
|
1019 |
if (array == NULL) |
|
1020 |
return; |
|
1021 |
for (i=0; i<array->len; i++) { |
|
1022 |
obj = g_ptr_array_index (array, i); |
|
1023 |
gpm_stats_add_wakeups_obj (obj); |
|
1024 |
}
|
|
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
1025 |
g_ptr_array_unref (array); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1026 |
}
|
1027 |
||
1028 |
static void |
|
1029 |
gpm_stats_set_title (GtkWindow *window, gint page_num) |
|
1030 |
{
|
|
1031 |
gchar *title; |
|
1032 |
const gchar * const page_titles[] = { |
|
1033 |
/* TRANSLATORS: shown on the titlebar */
|
|
1034 |
N_("Device Information"), |
|
1035 |
/* TRANSLATORS: shown on the titlebar */
|
|
1036 |
N_("Device History"), |
|
1037 |
/* TRANSLATORS: shown on the titlebar */
|
|
1038 |
N_("Device Profile"), |
|
1039 |
/* TRANSLATORS: shown on the titlebar */
|
|
1040 |
N_("Processor Wakeups") |
|
1041 |
};
|
|
1042 |
||
1043 |
/* TRANSLATORS: shown on the titlebar */
|
|
1044 |
title = g_strdup_printf ("%s - %s", _("Power Statistics"), _(page_titles[page_num])); |
|
1045 |
gtk_window_set_title (window, title); |
|
1046 |
g_free (title); |
|
1047 |
}
|
|
1048 |
||
1049 |
/**
|
|
1050 |
* gpm_stats_notebook_changed_cb:
|
|
1051 |
**/
|
|
1052 |
static void |
|
1053 |
gpm_stats_notebook_changed_cb (GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, gpointer user_data) |
|
1054 |
{
|
|
1055 |
DkpDevice *device; |
|
1056 |
GtkWidget *widget; |
|
1057 |
||
1058 |
/* set the window title depending on the mode */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1059 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1060 |
gpm_stats_set_title (GTK_WINDOW (widget), page_num); |
1061 |
||
1062 |
/* save page in gconf */
|
|
1063 |
gconf_client_set_int (gconf_client, GPM_CONF_INFO_PAGE_NUMBER, page_num, NULL); |
|
1064 |
||
1065 |
if (current_device == NULL) |
|
1066 |
return; |
|
1067 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1068 |
if (g_strcmp0 (current_device, "wakeups") == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1069 |
return; |
1070 |
||
1071 |
device = dkp_device_new (); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1072 |
dkp_device_set_object_path (device, current_device, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1073 |
gpm_stats_update_info_data_page (device, page_num); |
1074 |
gpm_stats_update_info_data (device); |
|
1075 |
g_object_unref (device); |
|
1076 |
}
|
|
1077 |
||
1078 |
/**
|
|
1079 |
* gpm_stats_button_update_ui:
|
|
1080 |
**/
|
|
1081 |
static void |
|
1082 |
gpm_stats_button_update_ui (void) |
|
1083 |
{
|
|
1084 |
DkpDevice *device; |
|
1085 |
device = dkp_device_new (); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1086 |
dkp_device_set_object_path (device, current_device, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1087 |
gpm_stats_update_info_data (device); |
1088 |
g_object_unref (device); |
|
1089 |
}
|
|
1090 |
||
1091 |
/**
|
|
1092 |
* gpm_stats_devices_treeview_clicked_cb:
|
|
1093 |
**/
|
|
1094 |
static void |
|
1095 |
gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data) |
|
1096 |
{
|
|
1097 |
GtkTreeModel *model; |
|
1098 |
GtkTreeIter iter; |
|
1099 |
DkpDevice *device; |
|
1100 |
||
1101 |
/* This will only work in single or browse selection mode! */
|
|
1102 |
if (gtk_tree_selection_get_selected (selection, &model, &iter)) { |
|
1103 |
g_free (current_device); |
|
1104 |
gtk_tree_model_get (model, &iter, GPM_DEVICES_COLUMN_ID, ¤t_device, -1); |
|
1105 |
||
1106 |
/* save device in gconf */
|
|
1107 |
gconf_client_set_string (gconf_client, GPM_CONF_INFO_LAST_DEVICE, current_device, NULL); |
|
1108 |
||
1109 |
/* show transaction_id */
|
|
1110 |
egg_debug ("selected row is: %s", current_device); |
|
1111 |
||
1112 |
/* is special device */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1113 |
if (g_strcmp0 (current_device, "wakeups") == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1114 |
gpm_stats_update_wakeups_data (); |
1115 |
} else { |
|
1116 |
device = dkp_device_new (); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1117 |
dkp_device_set_object_path (device, current_device, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1118 |
gpm_stats_update_info_data (device); |
1119 |
g_object_unref (device); |
|
1120 |
}
|
|
1121 |
||
1122 |
} else { |
|
1123 |
egg_debug ("no row selected"); |
|
1124 |
}
|
|
1125 |
}
|
|
1126 |
||
1127 |
/**
|
|
1128 |
* gpm_stats_window_activated_cb
|
|
1129 |
**/
|
|
1130 |
static void |
|
1131 |
gpm_stats_window_activated_cb (EggUnique *egg_unique, gpointer data) |
|
1132 |
{
|
|
1133 |
GtkWidget *widget; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1134 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1135 |
gtk_window_present (GTK_WINDOW (widget)); |
1136 |
}
|
|
1137 |
||
1138 |
/**
|
|
1139 |
* gpm_stats_add_device:
|
|
1140 |
**/
|
|
1141 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1142 |
gpm_stats_add_device (DkpDevice *device) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1143 |
{
|
1144 |
const gchar *id; |
|
1145 |
GtkTreeIter iter; |
|
1146 |
const gchar *text; |
|
1147 |
const gchar *icon; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1148 |
DkpDeviceType type; |
1149 |
||
1150 |
/* get device properties */
|
|
1151 |
g_object_get (device, |
|
1152 |
"type", &type, |
|
1153 |
NULL); |
|
1154 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1155 |
id = dkp_device_get_object_path (device); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1156 |
text = gpm_device_type_to_localised_text (type, 1); |
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1157 |
icon = gpm_upower_get_device_icon (device); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1158 |
|
1159 |
gtk_list_store_append (list_store_devices, &iter); |
|
1160 |
gtk_list_store_set (list_store_devices, &iter, |
|
1161 |
GPM_DEVICES_COLUMN_ID, id, |
|
1162 |
GPM_DEVICES_COLUMN_TEXT, text, |
|
1163 |
GPM_DEVICES_COLUMN_ICON, icon, -1); |
|
1164 |
}
|
|
1165 |
||
1166 |
/**
|
|
1167 |
* gpm_stats_data_changed_cb:
|
|
1168 |
**/
|
|
1169 |
static void |
|
1170 |
gpm_stats_data_changed_cb (DkpClient *client, gpointer user_data) |
|
1171 |
{
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1172 |
if (g_strcmp0 (current_device, "wakeups") == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1173 |
gpm_stats_update_wakeups_data (); |
1174 |
}
|
|
1175 |
||
1176 |
/**
|
|
1177 |
* gpm_stats_device_added_cb:
|
|
1178 |
**/
|
|
1179 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1180 |
gpm_stats_device_added_cb (DkpClient *client, DkpDevice *device, gpointer user_data) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1181 |
{
|
1182 |
const gchar *object_path; |
|
1183 |
object_path = dkp_device_get_object_path (device); |
|
1184 |
egg_debug ("added: %s", object_path); |
|
1185 |
gpm_stats_add_device (device); |
|
1186 |
}
|
|
1187 |
||
1188 |
/**
|
|
1189 |
* gpm_stats_device_changed_cb:
|
|
1190 |
**/
|
|
1191 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1192 |
gpm_stats_device_changed_cb (DkpClient *client, DkpDevice *device, gpointer user_data) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1193 |
{
|
1194 |
const gchar *object_path; |
|
1195 |
object_path = dkp_device_get_object_path (device); |
|
1196 |
if (object_path == NULL || current_device == NULL) |
|
1197 |
return; |
|
1198 |
egg_debug ("changed: %s", object_path); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1199 |
if (g_strcmp0 (current_device, object_path) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1200 |
gpm_stats_update_info_data (device); |
1201 |
}
|
|
1202 |
||
1203 |
/**
|
|
1204 |
* gpm_stats_device_removed_cb:
|
|
1205 |
**/
|
|
1206 |
static void |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1207 |
gpm_stats_device_removed_cb (DkpClient *client, DkpDevice *device, gpointer user_data) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1208 |
{
|
1209 |
const gchar *object_path; |
|
1210 |
GtkTreeIter iter; |
|
1211 |
gchar *id = NULL; |
|
1212 |
gboolean ret; |
|
1213 |
||
1214 |
object_path = dkp_device_get_object_path (device); |
|
1215 |
egg_debug ("removed: %s", object_path); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1216 |
if (g_strcmp0 (current_device, object_path) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1217 |
gtk_list_store_clear (list_store_info); |
1218 |
}
|
|
1219 |
||
1220 |
/* search the list and remove the object path entry */
|
|
1221 |
ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices), &iter); |
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1222 |
while (ret) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1223 |
gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices), &iter, GPM_DEVICES_COLUMN_ID, &id, -1); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1224 |
if (g_strcmp0 (id, object_path) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1225 |
gtk_list_store_remove (list_store_devices, &iter); |
1226 |
break; |
|
1227 |
}
|
|
1228 |
g_free (id); |
|
1229 |
ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices), &iter); |
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1230 |
};
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1231 |
}
|
1232 |
||
1233 |
/**
|
|
1234 |
* gpm_stats_history_type_combo_changed_cb:
|
|
1235 |
**/
|
|
1236 |
static void |
|
1237 |
gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data) |
|
1238 |
{
|
|
1239 |
gchar *value; |
|
1240 |
const gchar *axis_x = NULL; |
|
1241 |
const gchar *axis_y = NULL; |
|
1242 |
value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1243 |
if (g_strcmp0 (value, GPM_HISTORY_RATE_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1244 |
history_type = GPM_HISTORY_RATE_VALUE; |
1245 |
/* TRANSLATORS: this is the X axis on the graph */
|
|
1246 |
axis_x = _("Time elapsed"); |
|
1247 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1248 |
axis_y = _("Power"); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1249 |
} else if (g_strcmp0 (value, GPM_HISTORY_CHARGE_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1250 |
history_type = GPM_HISTORY_CHARGE_VALUE; |
1251 |
/* TRANSLATORS: this is the X axis on the graph */
|
|
1252 |
axis_x = _("Time elapsed"); |
|
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1253 |
/* TRANSLATORS: this is the Y axis on the graph for the whole battery device */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1254 |
axis_y = _("Cell charge"); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1255 |
} else if (g_strcmp0 (value, GPM_HISTORY_TIME_FULL_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1256 |
history_type = GPM_HISTORY_TIME_FULL_VALUE; |
1257 |
/* TRANSLATORS: this is the X axis on the graph */
|
|
1258 |
axis_x = _("Time elapsed"); |
|
1259 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1260 |
axis_y = _("Predicted time"); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1261 |
} else if (g_strcmp0 (value, GPM_HISTORY_TIME_EMPTY_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1262 |
history_type = GPM_HISTORY_TIME_EMPTY_VALUE; |
1263 |
/* TRANSLATORS: this is the X axis on the graph */
|
|
1264 |
axis_x = _("Time elapsed"); |
|
1265 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1266 |
axis_y = _("Predicted time"); |
|
1267 |
} else { |
|
1268 |
g_assert (FALSE); |
|
1269 |
}
|
|
1270 |
||
1271 |
/* set axis */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1272 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_x")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1273 |
gtk_label_set_label (GTK_LABEL(widget), axis_x); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1274 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_y")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1275 |
gtk_label_set_label (GTK_LABEL(widget), axis_y); |
1276 |
||
1277 |
gpm_stats_button_update_ui (); |
|
1278 |
g_free (value); |
|
1279 |
||
1280 |
/* save to gconf */
|
|
1281 |
gconf_client_set_string (gconf_client, GPM_CONF_INFO_HISTORY_TYPE, history_type, NULL); |
|
1282 |
}
|
|
1283 |
||
1284 |
/**
|
|
1285 |
* gpm_stats_type_combo_changed_cb:
|
|
1286 |
**/
|
|
1287 |
static void |
|
1288 |
gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data) |
|
1289 |
{
|
|
1290 |
gchar *value; |
|
1291 |
const gchar *axis_x = NULL; |
|
1292 |
const gchar *axis_y = NULL; |
|
1293 |
value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1294 |
if (g_strcmp0 (value, GPM_STATS_CHARGE_DATA_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1295 |
stats_type = GPM_STATS_CHARGE_DATA_VALUE; |
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1296 |
/* TRANSLATORS: this is the X axis on the graph for the whole battery device */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1297 |
axis_x = _("Cell charge"); |
1298 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1299 |
axis_y = _("Correction factor"); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1300 |
} else if (g_strcmp0 (value, GPM_STATS_CHARGE_ACCURACY_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1301 |
stats_type = GPM_STATS_CHARGE_ACCURACY_VALUE; |
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1302 |
/* TRANSLATORS: this is the X axis on the graph for the whole battery device */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1303 |
axis_x = _("Cell charge"); |
1304 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1305 |
axis_y = _("Prediction accuracy"); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1306 |
} else if (g_strcmp0 (value, GPM_STATS_DISCHARGE_DATA_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1307 |
stats_type = GPM_STATS_DISCHARGE_DATA_VALUE; |
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1308 |
/* TRANSLATORS: this is the X axis on the graph for the whole battery device */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1309 |
axis_x = _("Cell charge"); |
1310 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1311 |
axis_y = _("Correction factor"); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1312 |
} else if (g_strcmp0 (value, GPM_STATS_DISCHARGE_ACCURACY_TEXT) == 0) { |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1313 |
stats_type = GPM_STATS_DISCHARGE_ACCURACY_VALUE; |
|
2.1.50
by Chris Coulson
Import upstream version 2.29.91 |
1314 |
/* TRANSLATORS: this is the X axis on the graph for the whole battery device */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1315 |
axis_x = _("Cell charge"); |
1316 |
/* TRANSLATORS: this is the Y axis on the graph */
|
|
1317 |
axis_y = _("Prediction accuracy"); |
|
1318 |
} else { |
|
1319 |
g_assert (FALSE); |
|
1320 |
}
|
|
1321 |
||
1322 |
/* set axis */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1323 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_x")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1324 |
gtk_label_set_label (GTK_LABEL(widget), axis_x); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1325 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_y")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1326 |
gtk_label_set_label (GTK_LABEL(widget), axis_y); |
1327 |
||
1328 |
gpm_stats_button_update_ui (); |
|
1329 |
g_free (value); |
|
1330 |
||
1331 |
/* save to gconf */
|
|
1332 |
gconf_client_set_string (gconf_client, GPM_CONF_INFO_STATS_TYPE, stats_type, NULL); |
|
1333 |
}
|
|
1334 |
||
1335 |
/**
|
|
1336 |
* gpm_stats_range_combo_changed:
|
|
1337 |
**/
|
|
1338 |
static void |
|
1339 |
gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data) |
|
1340 |
{
|
|
1341 |
gchar *value; |
|
1342 |
value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1343 |
if (g_strcmp0 (value, GPM_HISTORY_MINUTE_TEXT) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1344 |
history_time = GPM_HISTORY_MINUTE_VALUE; |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1345 |
else if (g_strcmp0 (value, GPM_HISTORY_HOUR_TEXT) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1346 |
history_time = GPM_HISTORY_HOUR_VALUE; |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1347 |
else if (g_strcmp0 (value, GPM_HISTORY_DAY_TEXT) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1348 |
history_time = GPM_HISTORY_DAY_VALUE; |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1349 |
else if (g_strcmp0 (value, GPM_HISTORY_WEEK_TEXT) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1350 |
history_time = GPM_HISTORY_WEEK_VALUE; |
1351 |
else
|
|
1352 |
g_assert (FALSE); |
|
1353 |
||
1354 |
/* save to gconf */
|
|
1355 |
gconf_client_set_int (gconf_client, GPM_CONF_INFO_HISTORY_TIME, history_time, NULL); |
|
1356 |
||
1357 |
gpm_stats_button_update_ui (); |
|
1358 |
g_free (value); |
|
1359 |
}
|
|
1360 |
||
1361 |
/**
|
|
1362 |
* gpm_stats_smooth_checkbox_history_cb:
|
|
1363 |
* @widget: The GtkWidget object
|
|
1364 |
**/
|
|
1365 |
static void |
|
1366 |
gpm_stats_smooth_checkbox_history_cb (GtkWidget *widget, gpointer data) |
|
1367 |
{
|
|
1368 |
gboolean checked; |
|
1369 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
1370 |
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_SMOOTH, checked, NULL); |
|
1371 |
gpm_stats_button_update_ui (); |
|
1372 |
}
|
|
1373 |
||
1374 |
/**
|
|
1375 |
* gpm_stats_smooth_checkbox_stats_cb:
|
|
1376 |
* @widget: The GtkWidget object
|
|
1377 |
**/
|
|
1378 |
static void |
|
1379 |
gpm_stats_smooth_checkbox_stats_cb (GtkWidget *widget, gpointer data) |
|
1380 |
{
|
|
1381 |
gboolean checked; |
|
1382 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
1383 |
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_SMOOTH, checked, NULL); |
|
1384 |
gpm_stats_button_update_ui (); |
|
1385 |
}
|
|
1386 |
||
1387 |
/**
|
|
1388 |
* gpm_stats_points_checkbox_history_cb:
|
|
1389 |
* @widget: The GtkWidget object
|
|
1390 |
**/
|
|
1391 |
static void |
|
1392 |
gpm_stats_points_checkbox_history_cb (GtkWidget *widget, gpointer data) |
|
1393 |
{
|
|
1394 |
gboolean checked; |
|
1395 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
1396 |
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_POINTS, checked, NULL); |
|
1397 |
gpm_stats_button_update_ui (); |
|
1398 |
}
|
|
1399 |
||
1400 |
/**
|
|
1401 |
* gpm_stats_points_checkbox_stats_cb:
|
|
1402 |
* @widget: The GtkWidget object
|
|
1403 |
**/
|
|
1404 |
static void |
|
1405 |
gpm_stats_points_checkbox_stats_cb (GtkWidget *widget, gpointer data) |
|
1406 |
{
|
|
1407 |
gboolean checked; |
|
1408 |
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
|
1409 |
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_POINTS, checked, NULL); |
|
1410 |
gpm_stats_button_update_ui (); |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1411 |
}
|
1412 |
||
1413 |
/**
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1414 |
* gpm_stats_set_combo_simple_text:
|
1415 |
**/
|
|
1416 |
static void |
|
1417 |
gpm_stats_set_combo_simple_text (GtkWidget *combo_box) |
|
1418 |
{
|
|
1419 |
GtkCellRenderer *cell; |
|
1420 |
GtkListStore *store; |
|
1421 |
||
1422 |
store = gtk_list_store_new (1, G_TYPE_STRING); |
|
1423 |
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store)); |
|
1424 |
g_object_unref (store); |
|
1425 |
||
1426 |
cell = gtk_cell_renderer_text_new (); |
|
1427 |
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE); |
|
1428 |
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, |
|
1429 |
"text", 0, |
|
1430 |
NULL); |
|
1431 |
}
|
|
1432 |
||
1433 |
/**
|
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1434 |
* gpm_stats_highlight_device:
|
1435 |
**/
|
|
1436 |
static void |
|
1437 |
gpm_stats_highlight_device (const gchar *object_path) |
|
1438 |
{
|
|
1439 |
gboolean ret; |
|
1440 |
gchar *id = NULL; |
|
1441 |
gchar *path_str; |
|
1442 |
guint i; |
|
1443 |
GtkTreeIter iter; |
|
1444 |
GtkTreePath *path; |
|
1445 |
GtkWidget *widget; |
|
1446 |
||
1447 |
/* check valid */
|
|
1448 |
if (!g_str_has_prefix (object_path, "/")) |
|
1449 |
return; |
|
1450 |
||
1451 |
/* we have to reuse the treeview data as it may be sorted */
|
|
1452 |
ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices), &iter); |
|
1453 |
for (i=0; ret; i++) { |
|
1454 |
gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices), &iter, |
|
1455 |
GPM_DEVICES_COLUMN_ID, &id, |
|
1456 |
-1); |
|
1457 |
if (g_strcmp0 (id, object_path) == 0) { |
|
1458 |
path_str = g_strdup_printf ("%i", i); |
|
1459 |
path = gtk_tree_path_new_from_string (path_str); |
|
1460 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices")); |
|
1461 |
gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (widget), path, NULL, NULL, FALSE); |
|
1462 |
g_free (path_str); |
|
1463 |
gtk_tree_path_free (path); |
|
1464 |
}
|
|
1465 |
g_free (id); |
|
1466 |
ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices), &iter); |
|
1467 |
}
|
|
1468 |
}
|
|
1469 |
||
1470 |
/**
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1471 |
* main:
|
1472 |
**/
|
|
1473 |
int
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1474 |
main (int argc, char *argv[]) |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1475 |
{
|
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1476 |
gboolean verbose = FALSE; |
1477 |
GOptionContext *context; |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1478 |
GtkBox *box; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1479 |
GtkWidget *widget; |
1480 |
GtkTreeSelection *selection; |
|
1481 |
EggUnique *egg_unique; |
|
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1482 |
gboolean ret; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1483 |
DkpClient *client; |
1484 |
GPtrArray *devices; |
|
1485 |
DkpDevice *device; |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
1486 |
DkpDeviceType type; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1487 |
guint i; |
1488 |
gint page; |
|
1489 |
gboolean checked; |
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1490 |
gchar *last_device = NULL; |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1491 |
guint retval; |
1492 |
GError *error = NULL; |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1493 |
|
1494 |
const GOptionEntry options[] = { |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1495 |
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, |
1496 |
/* TRANSLATORS: show verbose debugging */
|
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1497 |
N_("Show extra debugging information"), NULL }, |
|
2.1.48
by Chris Coulson
Import upstream version 2.29.1 |
1498 |
{ "device", '\0', 0, G_OPTION_ARG_STRING, &last_device, |
1499 |
/* TRANSLATORS: show a device by default */
|
|
1500 |
N_("Select this device at startup"), NULL }, |
|
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1501 |
{ NULL} |
1502 |
};
|
|
1503 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1504 |
setlocale (LC_ALL, ""); |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1505 |
|
1506 |
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
|
1507 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
|
1508 |
textdomain (GETTEXT_PACKAGE); |
|
1509 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1510 |
if (! g_thread_supported ()) |
1511 |
g_thread_init (NULL); |
|
1512 |
dbus_g_thread_init (); |
|
1513 |
g_type_init (); |
|
1514 |
||
1515 |
context = g_option_context_new (NULL); |
|
1516 |
/* TRANSLATORS: the program name */
|
|
1517 |
g_option_context_set_summary (context, _("Power Statistics")); |
|
1518 |
g_option_context_add_main_entries (context, options, NULL); |
|
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
1519 |
g_option_context_parse (context, &argc, &argv, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1520 |
g_option_context_free (context); |
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1521 |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1522 |
egg_debug_init (verbose); |
|
2.1.27
by Oliver Grawert
Import upstream version 2.19.92 |
1523 |
gtk_init (&argc, &argv); |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1524 |
|
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1525 |
/* are we already activated? */
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1526 |
egg_unique = egg_unique_new (); |
|
2.1.42
by Martin Pitt
Import upstream version 2.27.2+git20090729 |
1527 |
ret = egg_unique_assign (egg_unique, "org.gnome.PowerManager.Statistics"); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1528 |
if (!ret) |
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1529 |
goto unique_out; |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1530 |
g_signal_connect (egg_unique, "activated", |
1531 |
G_CALLBACK (gpm_stats_window_activated_cb), NULL); |
|
1532 |
||
1533 |
/* add application specific icons to search path */
|
|
1534 |
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), |
|
1535 |
GPM_DATA G_DIR_SEPARATOR_S "icons"); |
|
1536 |
||
1537 |
/* get data from gconf */
|
|
1538 |
gconf_client = gconf_client_get_default (); |
|
1539 |
||
1540 |
/* add application specific icons to search path */
|
|
1541 |
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), |
|
1542 |
GPM_DATA G_DIR_SEPARATOR_S "icons"); |
|
1543 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1544 |
/* get UI */
|
1545 |
builder = gtk_builder_new (); |
|
1546 |
retval = gtk_builder_add_from_file (builder, GPM_DATA "/gpm-statistics.ui", &error); |
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1547 |
if (retval == 0) { |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1548 |
egg_warning ("failed to load ui: %s", error->message); |
1549 |
g_error_free (error); |
|
1550 |
}
|
|
1551 |
||
1552 |
/* add history graph */
|
|
1553 |
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_history")); |
|
1554 |
graph_history = gpm_graph_widget_new (); |
|
1555 |
gtk_box_pack_start (box, graph_history, TRUE, TRUE, 0); |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
1556 |
gtk_widget_set_size_request (graph_history, 400, 250); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1557 |
gtk_widget_show (graph_history); |
1558 |
||
1559 |
/* add statistics graph */
|
|
1560 |
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_statistics")); |
|
1561 |
graph_statistics = gpm_graph_widget_new (); |
|
1562 |
gtk_box_pack_start (box, graph_statistics, TRUE, TRUE, 0); |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
1563 |
gtk_widget_set_size_request (graph_statistics, 400, 250); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1564 |
gtk_widget_show (graph_statistics); |
1565 |
||
1566 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats")); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1567 |
gtk_window_set_default_size (GTK_WINDOW(widget), 800, 500); |
1568 |
gtk_window_set_default_icon_name (GPM_STOCK_APP_ICON); |
|
1569 |
||
1570 |
/* Get the main window quit */
|
|
1571 |
g_signal_connect_swapped (widget, "delete_event", G_CALLBACK (gtk_main_quit), NULL); |
|
1572 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1573 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1574 |
g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL); |
1575 |
gtk_widget_grab_default (widget); |
|
1576 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1577 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1578 |
g_signal_connect (widget, "clicked", |
1579 |
G_CALLBACK (gpm_stats_button_help_cb), NULL); |
|
1580 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1581 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1582 |
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_SMOOTH, NULL); |
1583 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked); |
|
1584 |
g_signal_connect (widget, "clicked", |
|
1585 |
G_CALLBACK (gpm_stats_smooth_checkbox_history_cb), NULL); |
|
1586 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1587 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1588 |
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_SMOOTH, NULL); |
1589 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked); |
|
1590 |
g_signal_connect (widget, "clicked", |
|
1591 |
G_CALLBACK (gpm_stats_smooth_checkbox_stats_cb), NULL); |
|
1592 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1593 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1594 |
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_POINTS, NULL); |
1595 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked); |
|
1596 |
g_signal_connect (widget, "clicked", |
|
1597 |
G_CALLBACK (gpm_stats_points_checkbox_history_cb), NULL); |
|
1598 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1599 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1600 |
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_POINTS, NULL); |
1601 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked); |
|
1602 |
g_signal_connect (widget, "clicked", |
|
1603 |
G_CALLBACK (gpm_stats_points_checkbox_stats_cb), NULL); |
|
1604 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1605 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1606 |
page = gconf_client_get_int (gconf_client, GPM_CONF_INFO_PAGE_NUMBER, NULL); |
1607 |
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), page); |
|
1608 |
g_signal_connect (widget, "switch-page", |
|
1609 |
G_CALLBACK (gpm_stats_notebook_changed_cb), NULL); |
|
1610 |
||
1611 |
/* create list stores */
|
|
1612 |
list_store_info = gtk_list_store_new (GPM_INFO_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING); |
|
1613 |
list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_STRING, |
|
1614 |
G_TYPE_STRING, G_TYPE_STRING); |
|
1615 |
list_store_wakeups = gtk_list_store_new (GPM_WAKEUPS_COLUMN_LAST, G_TYPE_STRING, |
|
1616 |
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
|
1617 |
||
1618 |
/* create transaction_id tree view */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1619 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_info")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1620 |
gtk_tree_view_set_model (GTK_TREE_VIEW (widget), |
1621 |
GTK_TREE_MODEL (list_store_info)); |
|
1622 |
||
1623 |
/* add columns to the tree view */
|
|
1624 |
gpm_stats_add_info_columns (GTK_TREE_VIEW (widget)); |
|
1625 |
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */ |
|
1626 |
||
1627 |
/* create transaction_id tree view */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1628 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1629 |
gtk_tree_view_set_model (GTK_TREE_VIEW (widget), |
1630 |
GTK_TREE_MODEL (list_store_devices)); |
|
1631 |
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); |
|
1632 |
g_signal_connect (selection, "changed", |
|
1633 |
G_CALLBACK (gpm_stats_devices_treeview_clicked_cb), NULL); |
|
1634 |
||
1635 |
/* add columns to the tree view */
|
|
1636 |
gpm_stats_add_devices_columns (GTK_TREE_VIEW (widget)); |
|
1637 |
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */ |
|
1638 |
||
1639 |
/* create wakeups tree view */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1640 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_wakeups")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1641 |
gtk_tree_view_set_model (GTK_TREE_VIEW (widget), |
1642 |
GTK_TREE_MODEL (list_store_wakeups)); |
|
1643 |
||
1644 |
/* add columns to the tree view */
|
|
1645 |
gpm_stats_add_wakeups_columns (GTK_TREE_VIEW (widget)); |
|
1646 |
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */ |
|
1647 |
||
1648 |
history_type = gconf_client_get_string (gconf_client, GPM_CONF_INFO_HISTORY_TYPE, NULL); |
|
1649 |
history_time = gconf_client_get_int (gconf_client, GPM_CONF_INFO_HISTORY_TIME, NULL); |
|
1650 |
if (history_type == NULL) |
|
1651 |
history_type = GPM_HISTORY_CHARGE_VALUE; |
|
1652 |
if (history_time == 0) |
|
1653 |
history_time = GPM_HISTORY_HOUR_VALUE; |
|
1654 |
||
1655 |
stats_type = gconf_client_get_string (gconf_client, GPM_CONF_INFO_STATS_TYPE, NULL); |
|
1656 |
if (stats_type == NULL) |
|
1657 |
stats_type = GPM_STATS_CHARGE_DATA_VALUE; |
|
1658 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1659 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type")); |
1660 |
gpm_stats_set_combo_simple_text (widget); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1661 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_RATE_TEXT); |
1662 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_CHARGE_TEXT); |
|
1663 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_TIME_FULL_TEXT); |
|
1664 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_TIME_EMPTY_TEXT); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1665 |
if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1666 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); |
1667 |
else
|
|
1668 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); |
|
1669 |
g_signal_connect (G_OBJECT (widget), "changed", |
|
1670 |
G_CALLBACK (gpm_stats_history_type_combo_changed_cb), NULL); |
|
1671 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1672 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type")); |
1673 |
gpm_stats_set_combo_simple_text (widget); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1674 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_STATS_CHARGE_DATA_TEXT); |
1675 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_STATS_CHARGE_ACCURACY_TEXT); |
|
1676 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_STATS_DISCHARGE_DATA_TEXT); |
|
1677 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_STATS_DISCHARGE_ACCURACY_TEXT); |
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1678 |
if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1679 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1680 |
else if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1681 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1682 |
else if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1683 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2); |
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1684 |
else if (g_strcmp0 (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1685 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); |
1686 |
else
|
|
1687 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 3); |
|
1688 |
g_signal_connect (G_OBJECT (widget), "changed", |
|
1689 |
G_CALLBACK (gpm_stats_type_combo_changed_cb), NULL); |
|
1690 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1691 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_time")); |
1692 |
gpm_stats_set_combo_simple_text (widget); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1693 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_MINUTE_TEXT); |
1694 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_HOUR_TEXT); |
|
1695 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_DAY_TEXT); |
|
1696 |
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_HISTORY_WEEK_TEXT); |
|
1697 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); |
|
1698 |
if (history_time == GPM_HISTORY_MINUTE_VALUE) |
|
1699 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); |
|
1700 |
else if (history_time == GPM_HISTORY_HOUR_VALUE) |
|
1701 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); |
|
1702 |
else
|
|
1703 |
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2); |
|
1704 |
g_signal_connect (G_OBJECT (widget), "changed", |
|
1705 |
G_CALLBACK (gpm_stats_range_combo_changed), NULL); |
|
1706 |
||
1707 |
client = dkp_client_new (); |
|
1708 |
g_signal_connect (client, "device-added", G_CALLBACK (gpm_stats_device_added_cb), NULL); |
|
1709 |
g_signal_connect (client, "device-removed", G_CALLBACK (gpm_stats_device_removed_cb), NULL); |
|
1710 |
g_signal_connect (client, "device-changed", G_CALLBACK (gpm_stats_device_changed_cb), NULL); |
|
1711 |
||
1712 |
wakeups = dkp_wakeups_new (); |
|
1713 |
g_signal_connect (wakeups, "data-changed", G_CALLBACK (gpm_stats_data_changed_cb), NULL); |
|
1714 |
||
1715 |
/* coldplug */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1716 |
devices = dkp_client_enumerate_devices (client, NULL); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1717 |
if (devices == NULL) |
1718 |
goto out; |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
1719 |
|
1720 |
/* add devices in visually pleasing order */
|
|
1721 |
for (i=0; i < devices->len; i++) { |
|
1722 |
device = g_ptr_array_index (devices, i); |
|
1723 |
g_object_get (device, "type", &type, NULL); |
|
1724 |
if (type == DKP_DEVICE_TYPE_LINE_POWER) |
|
1725 |
gpm_stats_add_device (device); |
|
1726 |
}
|
|
1727 |
for (i=0; i < devices->len; i++) { |
|
1728 |
device = g_ptr_array_index (devices, i); |
|
1729 |
g_object_get (device, "type", &type, NULL); |
|
1730 |
if (type == DKP_DEVICE_TYPE_BATTERY) |
|
1731 |
gpm_stats_add_device (device); |
|
1732 |
}
|
|
1733 |
for (i=0; i < devices->len; i++) { |
|
1734 |
device = g_ptr_array_index (devices, i); |
|
1735 |
g_object_get (device, "type", &type, NULL); |
|
1736 |
if (type == DKP_DEVICE_TYPE_UPS) |
|
1737 |
gpm_stats_add_device (device); |
|
1738 |
}
|
|
1739 |
for (i=0; i < devices->len; i++) { |
|
1740 |
device = g_ptr_array_index (devices, i); |
|
1741 |
g_object_get (device, "type", &type, NULL); |
|
1742 |
if (type == DKP_DEVICE_TYPE_MONITOR) |
|
1743 |
gpm_stats_add_device (device); |
|
1744 |
}
|
|
1745 |
for (i=0; i < devices->len; i++) { |
|
1746 |
device = g_ptr_array_index (devices, i); |
|
1747 |
g_object_get (device, "type", &type, NULL); |
|
1748 |
if (type == DKP_DEVICE_TYPE_MOUSE) |
|
1749 |
gpm_stats_add_device (device); |
|
1750 |
}
|
|
1751 |
for (i=0; i < devices->len; i++) { |
|
1752 |
device = g_ptr_array_index (devices, i); |
|
1753 |
g_object_get (device, "type", &type, NULL); |
|
1754 |
if (type == DKP_DEVICE_TYPE_KEYBOARD) |
|
1755 |
gpm_stats_add_device (device); |
|
1756 |
}
|
|
1757 |
||
1758 |
/* set current device */
|
|
|
2.1.45
by Robert Ancell
Import upstream version 2.27.92 |
1759 |
if (devices->len > 0) { |
1760 |
device = g_ptr_array_index (devices, 0); |
|
1761 |
gpm_stats_update_info_data (device); |
|
1762 |
current_device = g_strdup (dkp_device_get_object_path (device)); |
|
1763 |
}
|
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1764 |
|
|
2.1.48
by Chris Coulson
Import upstream version 2.29.1 |
1765 |
if (last_device == NULL) |
1766 |
last_device = gconf_client_get_string (gconf_client, GPM_CONF_INFO_LAST_DEVICE, NULL); |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1767 |
|
|
2.1.41
by Chris Coulson
Import upstream version 2.27.2 |
1768 |
/* has capability to measure wakeups */
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1769 |
ret = dkp_wakeups_has_capability (wakeups); |
1770 |
if (ret) { |
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1771 |
GtkTreeIter iter; |
1772 |
gtk_list_store_append (list_store_devices, &iter); |
|
1773 |
gtk_list_store_set (list_store_devices, &iter, |
|
1774 |
GPM_DEVICES_COLUMN_ID, "wakeups", |
|
1775 |
/* TRANSLATORS: the icon for the CPU */
|
|
1776 |
GPM_DEVICES_COLUMN_TEXT, _("Processor"), |
|
1777 |
GPM_DEVICES_COLUMN_ICON, "computer", -1); |
|
1778 |
}
|
|
1779 |
||
1780 |
/* set the correct focus on the last device */
|
|
|
2.1.47
by Martin Pitt
Import upstream version 2.28.1 |
1781 |
if (last_device != NULL) |
1782 |
gpm_stats_highlight_device (last_device); |
|
1783 |
||
|
2.1.46
by Martin Pitt
Import upstream version 2.28.0 |
1784 |
g_ptr_array_unref (devices); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1785 |
|
1786 |
/* set axis */
|
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1787 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1788 |
gpm_stats_history_type_combo_changed_cb (widget, NULL); |
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1789 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1790 |
gpm_stats_type_combo_changed_cb (widget, NULL); |
1791 |
||
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1792 |
widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats")); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1793 |
gtk_widget_show (widget); |
1794 |
||
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1795 |
gtk_main (); |
1796 |
||
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1797 |
out:
|
1798 |
g_object_unref (gconf_client); |
|
1799 |
g_object_unref (client); |
|
1800 |
g_object_unref (wakeups); |
|
|
2.1.40
by Martin Pitt
Import upstream version 2.27.1 |
1801 |
g_object_unref (builder); |
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1802 |
g_object_unref (list_store_info); |
|
2.1.34
by Ted Gould
Import upstream version 2.23.1 |
1803 |
unique_out:
|
|
2.1.39
by Martin Pitt
Import upstream version 2.26.1 |
1804 |
g_object_unref (egg_unique); |
|
2.1.48
by Chris Coulson
Import upstream version 2.29.1 |
1805 |
g_free (last_device); |
|
2.1.15
by Riccardo Setti
Import upstream version 2.17.3 |
1806 |
return 0; |
1807 |
}
|