From fe343d270ceb034284c7d0216a7d7315e821977d Mon Sep 17 00:00:00 2001 From: "raveit65 (via Travis CI)" Date: Tue, 10 Dec 2024 08:58:29 +0000 Subject: Deploy mate-desktop/mate-power-manager to github.com/mate-desktop/mate-power-manager.git:gh-pages --- .../index.html | 109 + .../report-0aa94a.html | 1105 ++++++++++ .../report-17d4c5.html | 1663 +++++++++++++++ .../report-26c008.html | 958 +++++++++ .../report-6489a3.html | 2194 ++++++++++++++++++++ .../report-6e287d.html | 2194 ++++++++++++++++++++ .../scanview.css | 62 + .../sorttable.js | 492 +++++ 8 files changed, 8777 insertions(+) create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/index.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/report-0aa94a.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/report-17d4c5.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/report-26c008.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/report-6489a3.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/report-6e287d.html create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/scanview.css create mode 100644 2024-02-25-205630-11823-1@c406c230d131_master/sorttable.js (limited to '2024-02-25-205630-11823-1@c406c230d131_master') diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/index.html b/2024-02-25-205630-11823-1@c406c230d131_master/index.html new file mode 100644 index 0000000..1291ac8 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/index.html @@ -0,0 +1,109 @@ + + +rootdir - scan-build results + + + + + + +

rootdir - scan-build results

+ + + + + + + +
User:root@9ae8ada021b9
Working Directory:/rootdir
Command Line:make -j 2
Clang Version:clang version 17.0.6 (Fedora 17.0.6-2.fc39) +
Date:Sun Feb 25 20:56:30 2024
+

Bug Summary

+ + + + + + + +
Bug TypeQuantityDisplay?
All Bugs5
Logic error
Identical conditions1
Unused code
Dead assignment1
Unreachable code3
+

Reports

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Bug GroupBug Type ▾FileFunction/MethodLinePath Length
Unused codeDead assignmentgpm-statistics.cmain15011View Report
Logic errorIdentical conditionsgpm-statistics.cmain14351View Report
Unused codeUnreachable codegpm-dpms.cgpm_dpms_poll_mode_cb2371View Report
Unused codeUnreachable codegpm-brightness.cgpm_brightness_down7641View Report
Unused codeUnreachable codegpm-main.cmain2421View Report
+ + diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/report-0aa94a.html b/2024-02-25-205630-11823-1@c406c230d131_master/report-0aa94a.html new file mode 100644 index 0000000..daa23d2 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/report-0aa94a.html @@ -0,0 +1,1105 @@ + + + +gpm-dpms.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:gpm-dpms.c
Warning:line 237, column 3
This statement is never executed
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gpm-dpms.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/libsecret-1 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libpng16 -I /usr/include/blkid -I /usr/include/libmount -I /usr/include/sysprof-6 -D _REENTRANT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/cloudproviders -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -I /usr/include/libupower-glib -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -D BINDIR="/usr/local/bin" -D SBINDIR="/usr/local/sbin" -D MATELOCALEDIR="/usr/local/share/locale" -D DATADIR="/usr/local/share" -D PREFIX="/usr/local" -D SYSCONFDIR="/usr/local/etc" -D LIBDIR="/usr/local/lib" -D VERSION="1.28.0" -D GPM_ICONS_DATA="/usr/local/share/mate-power-manager/icons" -D GTKBUILDERDIR="/usr/local/share/mate-power-manager" -D UP_DISABLE_DEPRECATED -D G_LOG_DOMAIN="PowerManager" -I .. -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-25-205630-11823-1 -x c gpm-dpms.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
4 * Copyright (C) 2006-2009 Richard Hughes <richard@hughsie.com>
5 * Copyright (C) 2012-2021 MATE Developers
6 *
7 * Licensed under the GNU General Public License Version 2
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#include "config.h"
25
26#include <stdlib.h>
27#include <stdio.h>
28#include <time.h>
29#include <errno(*__errno_location ()).h>
30
31#include <string.h>
32#include <sys/time.h>
33#include <sys/types.h>
34#ifdef HAVE_UNISTD_H1
35#include <unistd.h>
36#endif /* HAVE_UNISTD_H */
37
38#include <gdk/gdk.h>
39#include <gdk/gdkx.h>
40
41#include <X11/Xproto.h>
42#include <X11/extensions/dpms.h>
43
44#include "gpm-dpms.h"
45
46static void gpm_dpms_finalize (GObject *object);
47
48/* until we get a nice event-emitting DPMS extension, we have to poll... */
49#define GPM_DPMS_POLL_TIME10 10
50
51struct GpmDpmsPrivate
52{
53 gboolean dpms_capable;
54 GpmDpmsMode mode;
55 guint timer_id;
56 Display *display;
57};
58
59enum {
60 MODE_CHANGED,
61 LAST_SIGNAL
62};
63
64static guint signals [LAST_SIGNAL] = { 0 };
65static gpointer gpm_dpms_object = NULL((void*)0);
66
67G_DEFINE_TYPE_WITH_PRIVATE (GpmDpms, gpm_dpms, G_TYPE_OBJECT)static void gpm_dpms_init (GpmDpms *self); static void gpm_dpms_class_init
(GpmDpmsClass *klass); static GType gpm_dpms_get_type_once (
void); static gpointer gpm_dpms_parent_class = ((void*)0); static
gint GpmDpms_private_offset; static void gpm_dpms_class_intern_init
(gpointer klass) { gpm_dpms_parent_class = g_type_class_peek_parent
(klass); if (GpmDpms_private_offset != 0) g_type_class_adjust_private_offset
(klass, &GpmDpms_private_offset); gpm_dpms_class_init ((
GpmDpmsClass*) klass); } __attribute__ ((__unused__)) static inline
gpointer gpm_dpms_get_instance_private (GpmDpms *self) { return
(((gpointer) ((guint8*) (self) + (glong) (GpmDpms_private_offset
)))); } GType gpm_dpms_get_type (void) { static gsize static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0
)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id
)); }))) { GType g_define_type_id = gpm_dpms_get_type_once ()
; (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); 0 ?
(void) (*(&static_g_define_type_id) = (g_define_type_id)
) : (void) 0; g_once_init_leave ((&static_g_define_type_id
), (gsize) (g_define_type_id)); })); } return static_g_define_type_id
; } __attribute__ ((__noinline__)) static GType gpm_dpms_get_type_once
(void) { GType g_define_type_id = g_type_register_static_simple
(((GType) ((20) << (2))), g_intern_static_string ("GpmDpms"
), sizeof (GpmDpmsClass), (GClassInitFunc)(void (*)(void)) gpm_dpms_class_intern_init
, sizeof (GpmDpms), (GInstanceInitFunc)(void (*)(void)) gpm_dpms_init
, (GTypeFlags) 0); { {{ GpmDpms_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (GpmDpmsPrivate)); };} } return g_define_type_id
; }
68
69/**
70 * gpm_dpms_error_quark:
71 **/
72GQuark
73gpm_dpms_error_quark (void)
74{
75 static GQuark quark = 0;
76 if (!quark)
77 quark = g_quark_from_static_string ("gpm_dpms_error");
78 return quark;
79}
80
81/**
82 * gpm_dpms_x11_get_mode:
83 **/
84static gboolean
85gpm_dpms_x11_get_mode (GpmDpms *dpms, GpmDpmsMode *mode, GError **error)
86{
87 GpmDpmsMode result;
88 BOOL enabled = FALSE(0);
89 CARD16 state;
90
91 if (dpms->priv->dpms_capable == FALSE(0)) {
92 /* Server or monitor can't DPMS -- assume the monitor is on. */
93 result = GPM_DPMS_MODE_ON;
94 goto out;
95 }
96
97 DPMSInfo (dpms->priv->display, &state, &enabled);
98 if (!enabled) {
99 /* Server says DPMS is disabled -- so the monitor is on. */
100 result = GPM_DPMS_MODE_ON;
101 goto out;
102 }
103
104 switch (state) {
105 case DPMSModeOn0:
106 result = GPM_DPMS_MODE_ON;
107 break;
108 case DPMSModeStandby1:
109 result = GPM_DPMS_MODE_STANDBY;
110 break;
111 case DPMSModeSuspend2:
112 result = GPM_DPMS_MODE_SUSPEND;
113 break;
114 case DPMSModeOff3:
115 result = GPM_DPMS_MODE_OFF;
116 break;
117 default:
118 result = GPM_DPMS_MODE_ON;
119 break;
120 }
121out:
122 if (mode)
123 *mode = result;
124 return TRUE(!(0));
125}
126
127/**
128 * gpm_dpms_x11_set_mode:
129 **/
130static gboolean
131gpm_dpms_x11_set_mode (GpmDpms *dpms, GpmDpmsMode mode, GError **error)
132{
133 GpmDpmsMode current_mode;
134 CARD16 state;
135 CARD16 current_state;
136 BOOL current_enabled;
137
138 if (!dpms->priv->dpms_capable) {
139 g_debug ("not DPMS capable");
140 g_set_error (error, GPM_DPMS_ERRORgpm_dpms_error_quark (), GPM_DPMS_ERROR_GENERAL,
141 "Display is not DPMS capable");
142 return FALSE(0);
143 }
144
145 if (!DPMSInfo (dpms->priv->display, &current_state, &current_enabled)) {
146 g_debug ("couldn't get DPMS info");
147 g_set_error (error, GPM_DPMS_ERRORgpm_dpms_error_quark (), GPM_DPMS_ERROR_GENERAL,
148 "Unable to get DPMS state");
149 return FALSE(0);
150 }
151
152 if (!current_enabled) {
153 g_debug ("DPMS not enabled");
154 g_set_error (error, GPM_DPMS_ERRORgpm_dpms_error_quark (), GPM_DPMS_ERROR_GENERAL,
155 "DPMS is not enabled");
156 return FALSE(0);
157 }
158
159 switch (mode) {
160 case GPM_DPMS_MODE_ON:
161 state = DPMSModeOn0;
162 break;
163 case GPM_DPMS_MODE_STANDBY:
164 state = DPMSModeStandby1;
165 break;
166 case GPM_DPMS_MODE_SUSPEND:
167 state = DPMSModeSuspend2;
168 break;
169 case GPM_DPMS_MODE_OFF:
170 state = DPMSModeOff3;
171 break;
172 default:
173 state = DPMSModeOn0;
174 break;
175 }
176
177 gpm_dpms_x11_get_mode (dpms, &current_mode, NULL((void*)0));
178 if (current_mode != mode) {
179 if (! DPMSForceLevel (dpms->priv->display, state)) {
180 g_set_error (error, GPM_DPMS_ERRORgpm_dpms_error_quark (), GPM_DPMS_ERROR_GENERAL,
181 "Could not change DPMS mode");
182 return FALSE(0);
183 }
184 XSync (dpms->priv->display, FALSE(0));
185 }
186
187 return TRUE(!(0));
188}
189
190/**
191 * gpm_dpms_set_mode:
192 **/
193gboolean
194gpm_dpms_set_mode (GpmDpms *dpms, GpmDpmsMode mode, GError **error)
195{
196 gboolean ret;
197
198 g_return_val_if_fail (GPM_IS_DPMS (dpms), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((dpms)); GType __t = ((gpm_dpms_get_type ())); gboolean __r
; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning ("PowerManager", ((const char
*) (__func__)), "GPM_IS_DPMS (dpms)"); return ((0)); } } while
(0)
;
199
200 if (mode == GPM_DPMS_MODE_UNKNOWN) {
201 g_debug ("mode unknown");
202 g_set_error (error, GPM_DPMS_ERRORgpm_dpms_error_quark (), GPM_DPMS_ERROR_GENERAL,
203 "Unknown DPMS mode");
204 return FALSE(0);
205 }
206
207 ret = gpm_dpms_x11_set_mode (dpms, mode, error);
208 return ret;
209}
210
211/**
212 * gpm_dpms_get_mode:
213 **/
214gboolean
215gpm_dpms_get_mode (GpmDpms *dpms, GpmDpmsMode *mode, GError **error)
216{
217 gboolean ret;
218 if (mode)
219 *mode = GPM_DPMS_MODE_UNKNOWN;
220 ret = gpm_dpms_x11_get_mode (dpms, mode, error);
221 return ret;
222}
223
224/**
225 * gpm_dpms_poll_mode_cb:
226 **/
227static gboolean
228gpm_dpms_poll_mode_cb (GpmDpms *dpms)
229{
230 gboolean ret;
231 GpmDpmsMode mode;
232 GError *error = NULL((void*)0);
233
234 /* Try again */
235 ret = gpm_dpms_x11_get_mode (dpms, &mode, &error);
236 if (!ret) {
237 g_clear_error (&error);
This statement is never executed
238 return TRUE(!(0));
239 }
240
241 if (mode != dpms->priv->mode) {
242 dpms->priv->mode = mode;
243 g_signal_emit (dpms, signals [MODE_CHANGED], 0, mode);
244 }
245
246 return TRUE(!(0));
247}
248
249/**
250 * gpm_dpms_clear_timeouts:
251 **/
252static gboolean
253gpm_dpms_clear_timeouts (GpmDpms *dpms)
254{
255 gboolean ret = FALSE(0);
256
257 /* never going to work */
258 if (!dpms->priv->dpms_capable) {
259 g_debug ("not DPMS capable");
260 goto out;
261 }
262
263 g_debug ("set timeouts to zero");
264 ret = DPMSSetTimeouts (dpms->priv->display, 0, 0, 0);
265
266out:
267 return ret;
268}
269
270/**
271 * gpm_dpms_class_init:
272 **/
273static void
274gpm_dpms_class_init (GpmDpmsClass *klass)
275{
276 GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
277
278 object_class->finalize = gpm_dpms_finalize;
279
280 signals [MODE_CHANGED] =
281 g_signal_new ("mode-changed",
282 G_TYPE_FROM_CLASS (object_class)(((GTypeClass*) (object_class))->g_type), G_SIGNAL_RUN_LAST,
283 G_STRUCT_OFFSET (GpmDpmsClass, mode_changed)((glong) __builtin_offsetof(GpmDpmsClass, mode_changed)),
284 NULL((void*)0), NULL((void*)0), g_cclosure_marshal_VOID__UINT,
285 G_TYPE_NONE((GType) ((1) << (2))), 1, G_TYPE_UINT((GType) ((7) << (2))));
286}
287
288/**
289 * gpm_dpms_init:
290 **/
291static void
292gpm_dpms_init (GpmDpms *dpms)
293{
294 dpms->priv = gpm_dpms_get_instance_private (dpms);
295
296 /* DPMSCapable() can never change for a given display */
297 dpms->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default())(gdk_x11_display_get_xdisplay (gdk_display_get_default()));
298 dpms->priv->dpms_capable = DPMSCapable (dpms->priv->display);
299 dpms->priv->timer_id = g_timeout_add_seconds (GPM_DPMS_POLL_TIME10, (GSourceFunc)gpm_dpms_poll_mode_cb, dpms);
300 g_source_set_name_by_id (dpms->priv->timer_id, "[GpmDpms] poll");
301
302 /* ensure we clear the default timeouts (Standby: 1200s, Suspend: 1800s, Off: 2400s) */
303 gpm_dpms_clear_timeouts (dpms);
304}
305
306/**
307 * gpm_dpms_finalize:
308 **/
309static void
310gpm_dpms_finalize (GObject *object)
311{
312 GpmDpms *dpms;
313
314 g_return_if_fail (object != NULL)do { if ((object != ((void*)0))) { } else { g_return_if_fail_warning
("PowerManager", ((const char*) (__func__)), "object != NULL"
); return; } } while (0)
;
315 g_return_if_fail (GPM_IS_DPMS (object))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((object)); GType __t = ((gpm_dpms_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning ("PowerManager", ((const char
*) (__func__)), "GPM_IS_DPMS (object)"); return; } } while (0
)
;
316
317 dpms = GPM_DPMS (object)((((GpmDpms*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((gpm_dpms_get_type ()))))))
;
318
319 g_return_if_fail (dpms->priv != NULL)do { if ((dpms->priv != ((void*)0))) { } else { g_return_if_fail_warning
("PowerManager", ((const char*) (__func__)), "dpms->priv != NULL"
); return; } } while (0)
;
320
321 if (dpms->priv->timer_id != 0) {
322 g_source_remove (dpms->priv->timer_id);
323 dpms->priv->timer_id = 0;
324 }
325
326 G_OBJECT_CLASS (gpm_dpms_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((gpm_dpms_parent_class)), (((GType) ((20) << (2))))
))))
->finalize (object);
327}
328
329/**
330 * gpm_dpms_new:
331 **/
332GpmDpms *
333gpm_dpms_new (void)
334{
335 if (gpm_dpms_object != NULL((void*)0)) {
336 g_object_ref (gpm_dpms_object)((__typeof__ (gpm_dpms_object)) (g_object_ref) (gpm_dpms_object
))
;
337 } else {
338 gpm_dpms_object = g_object_new (GPM_TYPE_DPMS(gpm_dpms_get_type ()), NULL((void*)0));
339 g_object_add_weak_pointer (gpm_dpms_object, &gpm_dpms_object);
340 }
341 return GPM_DPMS (gpm_dpms_object)((((GpmDpms*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gpm_dpms_object)), ((gpm_dpms_get_type ()))))))
;
342}
343
344/***************************************************************************
345 *** MAKE CHECK TESTS ***
346 ***************************************************************************/
347#ifdef EGG_TEST
348#include "egg-test.h"
349
350void
351gpm_dpms_test (gpointer data)
352{
353 GpmDpms *dpms;
354 gboolean ret;
355 GError *error = NULL((void*)0);
356 EggTest *test = (EggTest *) data;
357
358 if (!egg_test_start (test, "GpmDpms"))
359 return;
360
361 /************************************************************/
362 egg_test_title (test, "get object");
363 dpms = gpm_dpms_new ();
364 if (dpms != NULL((void*)0))
365 egg_test_success (test, NULL((void*)0));
366 else
367 egg_test_failed (test, "got no object");
368
369 /************************************************************/
370 egg_test_title (test, "set on");
371 ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
372 if (ret)
373 egg_test_success (test, NULL((void*)0));
374 else
375 egg_test_failed (test, "failed: %s", error->message);
376
377 g_usleep (2*1000*1000);
378
379 /************************************************************/
380 egg_test_title (test, "set STANDBY");
381 ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_STANDBY, &error);
382 if (ret)
383 egg_test_success (test, NULL((void*)0));
384 else
385 egg_test_failed (test, "failed: %s", error->message);
386
387 g_usleep (2*1000*1000);
388
389 /************************************************************/
390 egg_test_title (test, "set SUSPEND");
391 ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_SUSPEND, &error);
392 if (ret)
393 egg_test_success (test, NULL((void*)0));
394 else
395 egg_test_failed (test, "failed: %s", error->message);
396
397 g_usleep (2*1000*1000);
398
399 /************************************************************/
400 egg_test_title (test, "set OFF");
401 ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, &error);
402 if (ret)
403 egg_test_success (test, NULL((void*)0));
404 else
405 egg_test_failed (test, "failed: %s", error->message);
406
407 g_usleep (2*1000*1000);
408
409 /************************************************************/
410 egg_test_title (test, "set on");
411 ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
412 if (ret)
413 egg_test_success (test, NULL((void*)0));
414 else
415 egg_test_failed (test, "failed: %s", error->message);
416
417 g_usleep (2*1000*1000);
418
419 g_object_unref (dpms);
420
421 egg_test_end (test);
422}
423
424#endif
425
diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/report-17d4c5.html b/2024-02-25-205630-11823-1@c406c230d131_master/report-17d4c5.html new file mode 100644 index 0000000..d4c811f --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/report-17d4c5.html @@ -0,0 +1,1663 @@ + + + +gpm-brightness.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:gpm-brightness.c
Warning:line 764, column 43
This statement is never executed
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gpm-brightness.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/libsecret-1 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libpng16 -I /usr/include/blkid -I /usr/include/libmount -I /usr/include/sysprof-6 -D _REENTRANT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/cloudproviders -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -I /usr/include/libupower-glib -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -D BINDIR="/usr/local/bin" -D SBINDIR="/usr/local/sbin" -D MATELOCALEDIR="/usr/local/share/locale" -D DATADIR="/usr/local/share" -D PREFIX="/usr/local" -D SYSCONFDIR="/usr/local/etc" -D LIBDIR="/usr/local/lib" -D VERSION="1.28.0" -D GPM_ICONS_DATA="/usr/local/share/mate-power-manager/icons" -D GTKBUILDERDIR="/usr/local/share/mate-power-manager" -D UP_DISABLE_DEPRECATED -D G_LOG_DOMAIN="PowerManager" -I .. -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-25-205630-11823-1 -x c gpm-brightness.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008-2010 Richard Hughes <richard@hughsie.com>
4 * Copyright (C) 2012-2021 MATE Developers
5 *
6 * Licensed under the GNU General Public License Version 2
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifdef HAVE_CONFIG_H1
24#include <config.h>
25#endif
26
27#include <stdlib.h>
28#include <stdio.h>
29#include <time.h>
30#include <errno(*__errno_location ()).h>
31
32#include <X11/Xatom.h>
33#include <X11/Xlib.h>
34#include <X11/extensions/Xrandr.h>
35#include <gdk/gdkx.h>
36#include <gtk/gtk.h>
37#include <string.h>
38#include <sys/time.h>
39#include <sys/types.h>
40#ifdef HAVE_UNISTD_H1
41#include <unistd.h>
42#endif /* HAVE_UNISTD_H */
43
44#include "egg-discrete.h"
45
46#include "gpm-brightness.h"
47#include "gpm-common.h"
48#include "gpm-marshal.h"
49
50#define GPM_SOLE_SETTER_USE_CACHE(!(0)) TRUE(!(0)) /* this may be insanity */
51
52struct GpmBrightnessPrivate
53{
54 gboolean has_changed_events;
55 gboolean cache_trusted;
56 guint cache_percentage;
57 guint last_set_hw;
58 Atom backlight;
59 Display *dpy;
60 GdkWindow *root_window;
61 guint shared_value;
62 gboolean has_extension;
63 gboolean hw_changed;
64 /* A cache of XRRScreenResources is used as XRRGetScreenResources is expensive */
65 GPtrArray *resources;
66 gint extension_levels;
67 gint extension_current;
68};
69
70enum {
71 BRIGHTNESS_CHANGED,
72 LAST_SIGNAL
73};
74
75typedef enum {
76 ACTION_BACKLIGHT_GET,
77 ACTION_BACKLIGHT_SET,
78 ACTION_BACKLIGHT_INC,
79 ACTION_BACKLIGHT_DEC
80} GpmXRandROp;
81
82G_DEFINE_TYPE_WITH_PRIVATE (GpmBrightness, gpm_brightness, G_TYPE_OBJECT)static void gpm_brightness_init (GpmBrightness *self); static
void gpm_brightness_class_init (GpmBrightnessClass *klass); static
GType gpm_brightness_get_type_once (void); static gpointer gpm_brightness_parent_class
= ((void*)0); static gint GpmBrightness_private_offset; static
void gpm_brightness_class_intern_init (gpointer klass) { gpm_brightness_parent_class
= g_type_class_peek_parent (klass); if (GpmBrightness_private_offset
!= 0) g_type_class_adjust_private_offset (klass, &GpmBrightness_private_offset
); gpm_brightness_class_init ((GpmBrightnessClass*) klass); }
__attribute__ ((__unused__)) static inline gpointer gpm_brightness_get_instance_private
(GpmBrightness *self) { return (((gpointer) ((guint8*) (self
) + (glong) (GpmBrightness_private_offset)))); } GType gpm_brightness_get_type
(void) { static gsize static_g_define_type_id = 0; if ((__extension__
({ _Static_assert (sizeof *(&static_g_define_type_id) ==
sizeof (gpointer), "Expression evaluates to false"); (void) (
0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0));
(!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id
)); }))) { GType g_define_type_id = gpm_brightness_get_type_once
(); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); 0 ?
(void) (*(&static_g_define_type_id) = (g_define_type_id)
) : (void) 0; g_once_init_leave ((&static_g_define_type_id
), (gsize) (g_define_type_id)); })); } return static_g_define_type_id
; } __attribute__ ((__noinline__)) static GType gpm_brightness_get_type_once
(void) { GType g_define_type_id = g_type_register_static_simple
(((GType) ((20) << (2))), g_intern_static_string ("GpmBrightness"
), sizeof (GpmBrightnessClass), (GClassInitFunc)(void (*)(void
)) gpm_brightness_class_intern_init, sizeof (GpmBrightness), (
GInstanceInitFunc)(void (*)(void)) gpm_brightness_init, (GTypeFlags
) 0); { {{ GpmBrightness_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (GpmBrightnessPrivate)); };} } return
g_define_type_id; }
83
84static guint signals [LAST_SIGNAL] = { 0 };
85static gpointer gpm_brightness_object = NULL((void*)0);
86
87/**
88 * gpm_brightness_helper_strtoint:
89 * @text: The text to be converted
90 * @value: The return numeric return value
91 *
92 * Convert a string to a signed integer value in a safe way.
93 *
94 * Return value: %TRUE if the string was converted correctly
95 **/
96static gboolean
97gpm_brightness_helper_strtoint (const gchar *text, gint *value)
98{
99 gchar *endptr = NULL((void*)0);
100 gint64 value_raw;
101
102 if (text == NULL((void*)0))
103 return FALSE(0);
104
105 value_raw = g_ascii_strtoll (text, &endptr, 10);
106
107 if (endptr == text)
108 return FALSE(0);
109 if (errno(*__errno_location ()) == ERANGE34 || value_raw > G_MAXINT2147483647 || value_raw < G_MININT(-2147483647 -1))
110 return FALSE(0);
111
112 *value = (gint) value_raw;
113 return TRUE(!(0));
114}
115
116/**
117 * gpm_brightness_helper_get_value:
118 **/
119static gint
120gpm_brightness_helper_get_value (const gchar *argument)
121{
122 gboolean ret;
123 GError *error = NULL((void*)0);
124 gchar *stdout_data = NULL((void*)0);
125 gint exit_status = 0;
126 gint value = -1;
127 gchar *command = NULL((void*)0);
128
129 /* get the data */
130 command = g_strdup_printf (SBINDIR"/usr/local/sbin" "/mate-power-backlight-helper --%s", argument);
131 ret = g_spawn_command_line_sync (command,
132 &stdout_data, NULL((void*)0), &exit_status, &error);
133 if (!ret) {
134 g_error ("failed to get value: %s", error->message);
135 g_error_free (error);
136 goto out;
137 }
138 g_debug ("executing %s retval: %i", command, exit_status);
139
140 /* parse for a number */
141 ret = gpm_brightness_helper_strtoint (stdout_data, &value);
142 if (!ret)
143 goto out;
144out:
145 g_free (command);
146 g_free (stdout_data);
147 return value;
148}
149
150/**
151 * gpm_brightness_helper_set_value:
152 **/
153static gboolean
154gpm_brightness_helper_set_value (const gchar *argument, gint value)
155{
156 gboolean ret;
157 GError *error = NULL((void*)0);
158 gint exit_status = 0;
159 gchar *command = NULL((void*)0);
160
161 /* get the data */
162 command = g_strdup_printf ("pkexec " SBINDIR"/usr/local/sbin" "/mate-power-backlight-helper --%s %i", argument, value);
163 ret = g_spawn_command_line_sync (command, NULL((void*)0), NULL((void*)0), &exit_status, &error);
164 if (!ret) {
165 g_error ("failed to get value: %s", error->message);
166 g_error_free (error);
167 goto out;
168 }
169 g_debug ("executing %s retval: %i", command, exit_status);
170out:
171 g_free (command);
172 return ret;
173}
174
175/**
176 * gpm_brightness_get_step:
177 * @levels: The number of levels supported
178 * Return value: the amount of hardware steps to do on each increment or decrement
179 **/
180static guint
181gpm_brightness_get_step (guint levels)
182{
183 /* macbook pro has a bazzillion brightness levels, do in 5% steps */
184 if (levels > 20)
185 return levels / 20;
186 return 1;
187}
188
189/**
190 * gpm_brightness_output_get_internal:
191 **/
192static gboolean
193gpm_brightness_output_get_internal (GpmBrightness *brightness, RROutput output, guint *cur)
194{
195 unsigned long nitems;
196 unsigned long bytes_after;
197 guint *prop;
198 Atom actual_type;
199 int actual_format;
200 gboolean ret = FALSE(0);
201
202 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
203
204 if (brightness->priv->backlight == None0L)
205 return FALSE(0);
206
207 if (XRRGetOutputProperty (brightness->priv->dpy, output, brightness->priv->backlight,
208 0, 4, False0, False0, None0L,
209 &actual_type, &actual_format,
210 &nitems, &bytes_after, ((unsigned char **)&prop)) != Success0) {
211 g_debug ("failed to get property");
212 return FALSE(0);
213 }
214 if (actual_type == XA_INTEGER((Atom) 19) && nitems == 1 && actual_format == 32) {
215 memcpy (cur, prop, sizeof (guint));
216 ret = TRUE(!(0));
217 }
218 XFree (prop);
219 return ret;
220}
221
222/**
223 * gpm_brightness_output_set_internal:
224 **/
225static gboolean
226gpm_brightness_output_set_internal (GpmBrightness *brightness, RROutput output, guint value)
227{
228 GdkDisplay *display;
229
230 gboolean ret = TRUE(!(0));
231
232 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
233
234 /* don't abort on error */
235 display = gdk_display_get_default ();
236 gdk_x11_display_error_trap_push (display);
237 XRRChangeOutputProperty (brightness->priv->dpy, output, brightness->priv->backlight, XA_INTEGER((Atom) 19), 32,
238 PropModeReplace0, (unsigned char *) &value, 1);
239 XFlush (brightness->priv->dpy);
240 gdk_display_flush (display);
241 if (gdk_x11_display_error_trap_pop (display)) {
242 g_warning ("failed to XRRChangeOutputProperty for brightness %u", value);
243 ret = FALSE(0);
244 }
245 /* we changed the hardware */
246 if (ret)
247 brightness->priv->hw_changed = TRUE(!(0));
248 return ret;
249}
250
251/**
252 * gpm_brightness_setup_display:
253 **/
254static gboolean
255gpm_brightness_setup_display (GpmBrightness *brightness)
256{
257 gint major, minor;
258
259 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
260
261 /* get the display */
262 brightness->priv->dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default())(gdk_x11_display_get_xdisplay (gdk_display_get_default()));
263 if (!brightness->priv->dpy) {
264 g_error ("Cannot open display");
265 return FALSE(0);
266 }
267 /* is XRandR new enough? */
268 if (!XRRQueryVersion (brightness->priv->dpy, &major, &minor)) {
269 g_debug ("RandR extension missing");
270 return FALSE(0);
271 }
272 if (major < 1 || (major == 1 && minor < 3)) {
273 g_debug ("RandR version %d.%d too old", major, minor);
274 return FALSE(0);
275 }
276 /* Can we support "Backlight" */
277 brightness->priv->backlight = XInternAtom (brightness->priv->dpy, "Backlight", True1);
278 if (brightness->priv->backlight == None0L) {
279 /* Do we support "BACKLIGHT" (legacy) */
280 brightness->priv->backlight = XInternAtom (brightness->priv->dpy, "BACKLIGHT", True1);
281 if (brightness->priv->backlight == None0L) {
282 g_debug ("No outputs have backlight property");
283 return FALSE(0);
284 }
285 }
286 return TRUE(!(0));
287}
288
289/**
290 * gpm_brightness_output_get_limits:
291 **/
292static gboolean
293gpm_brightness_output_get_limits (GpmBrightness *brightness, RROutput output,
294 guint *min, guint *max)
295{
296 XRRPropertyInfo *info;
297 gboolean ret = TRUE(!(0));
298
299 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
300
301 info = XRRQueryOutputProperty (brightness->priv->dpy, output, brightness->priv->backlight);
302 if (info == NULL((void*)0)) {
303 g_debug ("could not get output property");
304 return FALSE(0);
305 }
306 if (!info->range || info->num_values != 2) {
307 g_debug ("was not range");
308 ret = FALSE(0);
309 goto out;
310 }
311 *min = info->values[0];
312 *max = info->values[1];
313out:
314 XFree (info);
315 return ret;
316}
317
318/**
319 * gpm_brightness_output_get_percentage:
320 **/
321static gboolean
322gpm_brightness_output_get_percentage (GpmBrightness *brightness, RROutput output)
323{
324 guint cur;
325 gboolean ret;
326 guint min, max;
327 guint percentage;
328
329 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
330
331 ret = gpm_brightness_output_get_internal (brightness, output, &cur);
332 if (!ret)
333 return FALSE(0);
334 ret = gpm_brightness_output_get_limits (brightness, output, &min, &max);
335 if (!ret || min == max)
336 return FALSE(0);
337 g_debug ("hard value=%u, min=%u, max=%u", cur, min, max);
338 percentage = egg_discrete_to_percent (cur, (max-min)+1);
339 g_debug ("percentage %u", percentage);
340 brightness->priv->shared_value = percentage;
341 return TRUE(!(0));
342}
343
344/**
345 * gpm_brightness_output_down:
346 **/
347static gboolean
348gpm_brightness_output_down (GpmBrightness *brightness, RROutput output)
349{
350 guint cur;
351 guint step;
352 gboolean ret;
353 guint min, max;
354
355 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
356
357 ret = gpm_brightness_output_get_internal (brightness, output, &cur);
358 if (!ret)
359 return FALSE(0);
360 ret = gpm_brightness_output_get_limits (brightness, output, &min, &max);
361 if (!ret || min == max)
362 return FALSE(0);
363 g_debug ("hard value=%u, min=%u, max=%u", cur, min, max);
364 if (cur == min) {
365 g_debug ("already min");
366 return TRUE(!(0));
367 }
368 step = gpm_brightness_get_step ((max-min)+1);
369 if (cur < step) {
370 g_debug ("truncating to %u", min);
371 cur = min;
372 } else {
373 cur -= step;
374 }
375 ret = gpm_brightness_output_set_internal (brightness, output, cur);
376 return ret;
377}
378
379/**
380 * gpm_brightness_output_up:
381 **/
382static gboolean
383gpm_brightness_output_up (GpmBrightness *brightness, RROutput output)
384{
385 guint cur;
386 gboolean ret;
387 guint min, max;
388
389 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
390
391 ret = gpm_brightness_output_get_internal (brightness, output, &cur);
392 if (!ret)
393 return FALSE(0);
394 ret = gpm_brightness_output_get_limits (brightness, output, &min, &max);
395 if (!ret || min == max)
396 return FALSE(0);
397 g_debug ("hard value=%u, min=%u, max=%u", cur, min, max);
398 if (cur == max) {
399 g_debug ("already max");
400 return TRUE(!(0));
401 }
402 cur += gpm_brightness_get_step ((max-min)+1);
403 if (cur > max) {
404 g_debug ("truncating to %u", max);
405 cur = max;
406 }
407 ret = gpm_brightness_output_set_internal (brightness, output, cur);
408 return ret;
409}
410
411/**
412 * gpm_brightness_output_set:
413 **/
414static gboolean
415gpm_brightness_output_set (GpmBrightness *brightness, RROutput output)
416{
417 guint cur;
418 gboolean ret;
419 guint min, max;
420 gint i;
421 gint shared_value_abs;
422 guint step;
423
424 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
425
426 ret = gpm_brightness_output_get_internal (brightness, output, &cur);
427 if (!ret)
428 return FALSE(0);
429 ret = gpm_brightness_output_get_limits (brightness, output, &min, &max);
430 if (!ret || min == max)
431 return FALSE(0);
432
433 shared_value_abs = egg_discrete_from_percent (brightness->priv->shared_value, (max-min)+1);
434 g_debug ("percent=%u, absolute=%i", brightness->priv->shared_value, shared_value_abs);
435
436 g_debug ("hard value=%u, min=%u, max=%u", cur, min, max);
437 if (shared_value_abs > (gint) max)
438 shared_value_abs = max;
439 if (shared_value_abs < (gint) min)
440 shared_value_abs = min;
441 if ((gint) cur == shared_value_abs) {
442 g_debug ("already set %u", cur);
443 return TRUE(!(0));
444 }
445
446 /* step the correct way */
447 if ((gint) cur < shared_value_abs) {
448
449 /* some adaptors have a large number of steps */
450 step = gpm_brightness_get_step (shared_value_abs - cur);
451 g_debug ("using step of %u", step);
452
453 /* going up */
454 for (i=cur; i<=shared_value_abs; i+=step) {
455 ret = gpm_brightness_output_set_internal (brightness, output, i);
456 if (!ret)
457 break;
458 if ((gint) cur != shared_value_abs)
459 g_usleep (1000 * GPM_BRIGHTNESS_DIM_INTERVAL5);
460 }
461 } else {
462
463 /* some adaptors have a large number of steps */
464 step = gpm_brightness_get_step (cur - shared_value_abs);
465 g_debug ("using step of %u", step);
466
467 /* going down */
468 for (i=cur; i>=shared_value_abs; i-=step) {
469 ret = gpm_brightness_output_set_internal (brightness, output, i);
470 if (!ret)
471 break;
472 if ((gint) cur != shared_value_abs)
473 g_usleep (1000 * GPM_BRIGHTNESS_DIM_INTERVAL5);
474 }
475 }
476 return TRUE(!(0));
477}
478
479/**
480 * gpm_brightness_foreach_resource:
481 **/
482static gboolean
483gpm_brightness_foreach_resource (GpmBrightness *brightness, GpmXRandROp op, XRRScreenResources *resources)
484{
485 gint i;
486 gboolean ret;
487 gboolean success_any = FALSE(0);
488 RROutput output;
489
490 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
491
492 /* do for each output */
493 for (i=0; i<resources->noutput; i++) {
494 output = resources->outputs[i];
495 g_debug ("resource %i of %i", i+1, resources->noutput);
496 if (op==ACTION_BACKLIGHT_GET) {
497 ret = gpm_brightness_output_get_percentage (brightness, output);
498 } else if (op==ACTION_BACKLIGHT_INC) {
499 ret = gpm_brightness_output_up (brightness, output);
500 } else if (op==ACTION_BACKLIGHT_DEC) {
501 ret = gpm_brightness_output_down (brightness, output);
502 } else if (op==ACTION_BACKLIGHT_SET) {
503 ret = gpm_brightness_output_set (brightness, output);
504 } else {
505 ret = FALSE(0);
506 g_warning ("op not known");
507 }
508 if (ret) {
509 success_any = TRUE(!(0));
510 }
511 }
512 return success_any;
513}
514
515/**
516 * gpm_brightness_foreach_screen:
517 **/
518static gboolean
519gpm_brightness_foreach_screen (GpmBrightness *brightness, GpmXRandROp op)
520{
521 guint i;
522 guint length;
523 XRRScreenResources *resource;
524 gboolean ret;
525 gboolean success_any = FALSE(0);
526
527 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
528
529 /* Return immediately if we can't use XRandR */
530 if (!brightness->priv->has_extension)
531 return FALSE(0);
532
533 /* do for each screen */
534 length = brightness->priv->resources->len;
535 for (i=0; i<length; i++) {
536 resource = (XRRScreenResources *) g_ptr_array_index (brightness->priv->resources, i)((brightness->priv->resources)->pdata)[i];
537 g_debug ("using resource %p", resource);
538 ret = gpm_brightness_foreach_resource (brightness, op, resource);
539 if (ret)
540 success_any = TRUE(!(0));
541 }
542 XSync (brightness->priv->dpy, False0);
543 return success_any;
544}
545
546/**
547 * gpm_brightness_trust_cache:
548 * @brightness: This brightness class instance
549 * Return value: if we can trust the cache
550 **/
551static gboolean
552gpm_brightness_trust_cache (GpmBrightness *brightness)
553{
554 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
555 /* only return the cached value if the cache is trusted and we have change events */
556 if (brightness->priv->cache_trusted && brightness->priv->has_changed_events) {
557 g_debug ("using cache for value %u (okay)", brightness->priv->cache_percentage);
558 return TRUE(!(0));
559 }
560
561 /* can we trust that if we set a value 5 minutes ago, will it still be valid now?
562 * if we have multiple things setting policy on the workstation, e.g. fast user switching
563 * or kpowersave, then this will be invalid -- this logic may be insane */
564 if (GPM_SOLE_SETTER_USE_CACHE(!(0)) && brightness->priv->cache_trusted) {
565 g_debug ("using cache for value %u (probably okay)", brightness->priv->cache_percentage);
566 return TRUE(!(0));
567 }
568 return FALSE(0);
569}
570
571/**
572 * gpm_brightness_set:
573 * @brightness: This brightness class instance
574 * @percentage: The percentage brightness
575 * @hw_changed: If the hardware was changed, i.e. the brightness changed
576 * Return value: %TRUE if success, %FALSE if there was an error
577 **/
578gboolean
579gpm_brightness_set (GpmBrightness *brightness, guint percentage, gboolean *hw_changed)
580{
581 gboolean ret = FALSE(0);
582 gboolean trust_cache;
583
584 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
585
586 /* can we check the new value with the cache? */
587 trust_cache = gpm_brightness_trust_cache (brightness);
588 if (trust_cache && percentage == brightness->priv->cache_percentage) {
589 g_debug ("not setting the same value %u", percentage);
590 return TRUE(!(0));
591 }
592
593 /* set the value we want */
594 brightness->priv->shared_value = percentage;
595
596 /* reset to not-changed */
597 brightness->priv->hw_changed = FALSE(0);
598 ret = gpm_brightness_foreach_screen (brightness, ACTION_BACKLIGHT_SET);
599
600 /* legacy fallback */
601 if (!ret) {
602 if (brightness->priv->extension_levels < 0)
603 brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
604 brightness->priv->extension_current = egg_discrete_from_percent (percentage, brightness->priv->extension_levels+1);
605 ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
606 }
607
608 /* did the hardware have to be modified? */
609 if (ret && hw_changed != NULL((void*)0))
610 *hw_changed = brightness->priv->hw_changed;
611
612 /* we did something to the hardware, so untrusted */
613 if (ret)
614 brightness->priv->cache_trusted = FALSE(0);
615
616 return ret;
617}
618
619/**
620 * gpm_brightness_get:
621 * @brightness: This brightness class instance
622 * Return value: The percentage brightness, or -1 for no hardware or error
623 *
624 * Gets the current (or at least what this class thinks is current) percentage
625 * brightness. This is quick as no HAL inquiry is done.
626 **/
627gboolean
628gpm_brightness_get (GpmBrightness *brightness, guint *percentage)
629{
630 gboolean ret = FALSE(0);
631 gboolean trust_cache;
632 guint percentage_local;
633
634 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
635 g_return_val_if_fail (percentage != NULL, FALSE)do { if ((percentage != ((void*)0))) { } else { g_return_if_fail_warning
("PowerManager", ((const char*) (__func__)), "percentage != NULL"
); return ((0)); } } while (0)
;
636
637 /* can we use the cache? */
638 trust_cache = gpm_brightness_trust_cache (brightness);
639 if (trust_cache) {
640 *percentage = brightness->priv->cache_percentage;
641 return TRUE(!(0));
642 }
643
644 /* get the brightness from hardware -- slow */
645 ret = gpm_brightness_foreach_screen (brightness, ACTION_BACKLIGHT_GET);
646 percentage_local = brightness->priv->shared_value;
647
648 /* legacy fallback */
649 if (!ret) {
650 if (brightness->priv->extension_levels < 0)
651 brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
652 brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
653 percentage_local = egg_discrete_to_percent (brightness->priv->extension_current, brightness->priv->extension_levels+1);
654 ret = TRUE(!(0));
655 }
656
657 /* valid? */
658 if (percentage_local > 100) {
659 g_warning ("percentage value of %u will be truncated", percentage_local);
660 percentage_local = 100;
661 }
662
663 /* a new value is always trusted if the method and checks succeed */
664 if (ret) {
665 brightness->priv->cache_percentage = percentage_local;
666 brightness->priv->cache_trusted = TRUE(!(0));
667 *percentage = percentage_local;
668 } else {
669 brightness->priv->cache_trusted = FALSE(0);
670 }
671 return ret;
672}
673
674/**
675 * gpm_brightness_up:
676 * @brightness: This brightness class instance
677 * @hw_changed: If the hardware was changed, i.e. the brightness changed
678 * Return value: %TRUE if success, %FALSE if there was an error
679 *
680 * If possible, put the brightness of the LCD up one unit.
681 **/
682gboolean
683gpm_brightness_up (GpmBrightness *brightness, gboolean *hw_changed)
684{
685 gboolean ret = FALSE(0);
686 guint step;
687
688 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
689
690 /* reset to not-changed */
691 brightness->priv->hw_changed = FALSE(0);
692 ret = gpm_brightness_foreach_screen (brightness, ACTION_BACKLIGHT_INC);
693
694 /* did the hardware have to be modified? */
695 if (ret && hw_changed != NULL((void*)0))
696 *hw_changed = brightness->priv->hw_changed;
697
698 /* we did something to the hardware, so untrusted */
699 if (ret)
700 brightness->priv->cache_trusted = FALSE(0);
701
702 /* legacy fallback */
703 if (!ret) {
704 if (brightness->priv->extension_levels < 0)
705 brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
706 brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
707
708 /* increase by the step, limiting to the maximum possible levels */
709 if (brightness->priv->extension_current < brightness->priv->extension_levels) {
710 step = gpm_brightness_get_step (brightness->priv->extension_levels);
711 brightness->priv->extension_current += step;
712 if (brightness->priv->extension_current > brightness->priv->extension_levels)
713 brightness->priv->extension_current = brightness->priv->extension_levels;
714 ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
715 }
716 if (hw_changed != NULL((void*)0))
717 *hw_changed = ret;
718 brightness->priv->cache_trusted = FALSE(0);
719 goto out;
720 }
721out:
722 return ret;
723}
724
725/**
726 * gpm_brightness_down:
727 * @brightness: This brightness class instance
728 * @hw_changed: If the hardware was changed, i.e. the brightness changed
729 * Return value: %TRUE if success, %FALSE if there was an error
730 *
731 * If possible, put the brightness of the LCD down one unit.
732 **/
733gboolean
734gpm_brightness_down (GpmBrightness *brightness, gboolean *hw_changed)
735{
736 gboolean ret = FALSE(0);
737 guint step;
738
739 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
740
741 /* reset to not-changed */
742 brightness->priv->hw_changed = FALSE(0);
743 ret = gpm_brightness_foreach_screen (brightness, ACTION_BACKLIGHT_DEC);
744
745 /* did the hardware have to be modified? */
746 if (ret && hw_changed != NULL((void*)0))
747 *hw_changed = brightness->priv->hw_changed;
748
749 /* we did something to the hardware, so untrusted */
750 if (ret)
751 brightness->priv->cache_trusted = FALSE(0);
752
753 /* legacy fallback */
754 if (!ret) {
755 if (brightness->priv->extension_levels < 0)
756 brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
757 brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
758
759 /* decrease by the step, limiting to zero */
760 if (brightness->priv->extension_current > 0) {
761 step = gpm_brightness_get_step (brightness->priv->extension_levels);
762 brightness->priv->extension_current -= step;
763 if (brightness->priv->extension_current < 0)
764 brightness->priv->extension_current = 0;
This statement is never executed
765 ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
766 }
767 if (hw_changed != NULL((void*)0))
768 *hw_changed = ret;
769 brightness->priv->cache_trusted = FALSE(0);
770 goto out;
771 }
772out:
773 return ret;
774}
775
776/**
777 * gpm_brightness_may_have_changed:
778 **/
779static void
780gpm_brightness_may_have_changed (GpmBrightness *brightness)
781{
782 gboolean ret;
783 guint percentage;
784 ret = gpm_brightness_get (brightness, &percentage);
785 if (!ret) {
786 g_warning ("failed to get output");
787 return;
788 }
789 g_debug ("emitting brightness-changed (%u)", percentage);
790 g_signal_emit (brightness, signals [BRIGHTNESS_CHANGED], 0, percentage);
791}
792
793/**
794 * gpm_brightness_filter_xevents:
795 **/
796static GdkFilterReturn
797gpm_brightness_filter_xevents (GdkXEvent *xevent, GdkEvent *event, gpointer data)
798{
799 GpmBrightness *brightness = GPM_BRIGHTNESS (data)((((GpmBrightness*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((data)), ((gpm_brightness_get_type ()))))))
;
800 if (event->type == GDK_NOTHING)
801 return GDK_FILTER_CONTINUE;
802 gpm_brightness_may_have_changed (brightness);
803 return GDK_FILTER_CONTINUE;
804}
805
806static void gpm_brightness_update_cache (GpmBrightness *brightness);
807
808/**
809 * gpm_brightness_monitors_changed:
810 **/
811static void
812gpm_brightness_monitors_changed (GdkScreen *screen, GpmBrightness *brightness)
813{
814 g_return_if_fail (GPM_IS_BRIGHTNESS (brightness))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return; } } while (0)
;
815 gpm_brightness_update_cache (brightness);
816}
817
818/**
819 * gpm_brightness_update_cache:
820 **/
821static void
822gpm_brightness_update_cache (GpmBrightness *brightness)
823{
824 guint length;
825 Window root;
826 GdkScreen *gscreen;
827 GdkDisplay *display;
828 XRRScreenResources *resource;
829
830 g_return_if_fail (GPM_IS_BRIGHTNESS (brightness))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return; } } while (0)
;
831
832 /* invalidate and remove all the previous entries */
833 length = brightness->priv->resources->len;
834 if (length > 0)
835 g_ptr_array_set_size (brightness->priv->resources, 0);
836
837 display = gdk_display_get_default ();
838 gscreen = gdk_display_get_default_screen (display);
839
840 /* if we have not setup the changed on the monitor, set it here */
841 if (g_object_get_data (G_OBJECT (gscreen)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gscreen)), (((GType) ((20) << (2))))))))
, "gpk-set-monitors-changed") == NULL((void*)0)) {
842 g_debug ("watching ::monitors_changed on %p", gscreen);
843 g_object_set_data (G_OBJECT (gscreen)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gscreen)), (((GType) ((20) << (2))))))))
, "gpk-set-monitors-changed", (gpointer) "true");
844 g_signal_connect (G_OBJECT (gscreen), "monitors_changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((gscreen)), (((GType) ((20) << (2))
))))))), ("monitors_changed"), (((GCallback) (gpm_brightness_monitors_changed
))), (brightness), ((void*)0), (GConnectFlags) 0)
845 G_CALLBACK (gpm_brightness_monitors_changed), brightness)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((gscreen)), (((GType) ((20) << (2))
))))))), ("monitors_changed"), (((GCallback) (gpm_brightness_monitors_changed
))), (brightness), ((void*)0), (GConnectFlags) 0)
;
846 }
847
848 root = RootWindow (brightness->priv->dpy, 0)((&((_XPrivDisplay)(brightness->priv->dpy))->screens
[0])->root)
;
849
850 gdk_x11_display_error_trap_push (display);
851 resource = XRRGetScreenResourcesCurrent (brightness->priv->dpy, root);
852 if (gdk_x11_display_error_trap_pop (display) || resource == NULL((void*)0)) {
853 g_warning ("failed to XRRGetScreenResourcesCurrent");
854 }
855
856 if (resource != NULL((void*)0)) {
857 g_debug ("adding resource %p", resource);
858 g_ptr_array_add (brightness->priv->resources, resource);
859 }
860}
861
862/**
863 * gpm_brightness_has_hw:
864 **/
865gboolean
866gpm_brightness_has_hw (GpmBrightness *brightness)
867{
868 g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((brightness)); GType __t = ((gpm_brightness_get_type ()))
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning ("PowerManager", (
(const char*) (__func__)), "GPM_IS_BRIGHTNESS (brightness)");
return ((0)); } } while (0)
;
869
870 /* use XRandR first */
871 if (brightness->priv->has_extension)
872 return TRUE(!(0));
873
874 /* fallback to legacy access */
875 if (brightness->priv->extension_levels < 0)
876 brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
877 if (brightness->priv->extension_levels > 0)
878 return TRUE(!(0));
879 return FALSE(0);
880}
881
882/**
883 * gpm_brightness_finalize:
884 **/
885static void
886gpm_brightness_finalize (GObject *object)
887{
888 GpmBrightness *brightness;
889 g_return_if_fail (object != NULL)do { if ((object != ((void*)0))) { } else { g_return_if_fail_warning
("PowerManager", ((const char*) (__func__)), "object != NULL"
); return; } } while (0)
;
890 g_return_if_fail (GPM_IS_BRIGHTNESS (object))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((object)); GType __t = ((gpm_brightness_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning ("PowerManager", ((const char
*) (__func__)), "GPM_IS_BRIGHTNESS (object)"); return; } } while
(0)
;
891 brightness = GPM_BRIGHTNESS (object)((((GpmBrightness*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), ((gpm_brightness_get_type ()))))))
;
892 g_ptr_array_unref (brightness->priv->resources);
893 gdk_window_remove_filter (brightness->priv->root_window,
894 gpm_brightness_filter_xevents, brightness);
895 G_OBJECT_CLASS (gpm_brightness_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((gpm_brightness_parent_class)), (((GType) ((20) << (
2))))))))
->finalize (object);
896}
897
898/**
899 * gpm_brightness_class_init:
900 **/
901static void
902gpm_brightness_class_init (GpmBrightnessClass *klass)
903{
904 GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
905 object_class->finalize = gpm_brightness_finalize;
906
907 signals [BRIGHTNESS_CHANGED] =
908 g_signal_new ("brightness-changed",
909 G_TYPE_FROM_CLASS (object_class)(((GTypeClass*) (object_class))->g_type), G_SIGNAL_RUN_LAST,
910 G_STRUCT_OFFSET (GpmBrightnessClass, brightness_changed)((glong) __builtin_offsetof(GpmBrightnessClass, brightness_changed
))
,
911 NULL((void*)0), NULL((void*)0), g_cclosure_marshal_VOID__UINT,
912 G_TYPE_NONE((GType) ((1) << (2))), 1, G_TYPE_UINT((GType) ((7) << (2))));
913}
914
915/**
916 * gpm_brightness_init:
917 * @brightness: This brightness class instance
918 **/
919static void
920gpm_brightness_init (GpmBrightness *brightness)
921{
922 GdkScreen *screen;
923 GdkDisplay *display;
924 int event_base;
925 int ignore;
926
927 brightness->priv = gpm_brightness_get_instance_private (brightness);
928
929 brightness->priv->cache_trusted = FALSE(0);
930 brightness->priv->has_changed_events = FALSE(0);
931 brightness->priv->cache_percentage = 0;
932 brightness->priv->hw_changed = FALSE(0);
933 brightness->priv->extension_levels = -1;
934 brightness->priv->resources = g_ptr_array_new_with_free_func ((GDestroyNotify) XRRFreeScreenResources);
935
936 /* can we do this */
937 brightness->priv->has_extension = gpm_brightness_setup_display (brightness);
938 if (brightness->priv->has_extension == FALSE(0))
939 g_debug ("no XRANDR extension");
940
941 screen = gdk_screen_get_default ();
942 brightness->priv->root_window = gdk_screen_get_root_window (screen);
943 display = gdk_display_get_default ();
944
945 /* as we a filtering by a window, we have to add an event type */
946 if (!XRRQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default())(gdk_x11_display_get_xdisplay (gdk_display_get_default())), &event_base, &ignore)) {
947 g_warning ("can't get event_base for XRR");
948 }
949 gdk_x11_register_standard_event_type (display, event_base, RRNotify1 + 1);
950 gdk_window_add_filter (brightness->priv->root_window,
951 gpm_brightness_filter_xevents, brightness);
952
953 /* don't abort on error */
954 gdk_x11_display_error_trap_push (display);
955 XRRSelectInput (GDK_DISPLAY_XDISPLAY (gdk_display_get_default())(gdk_x11_display_get_xdisplay (gdk_display_get_default())),
956 GDK_WINDOW_XID (brightness->priv->root_window)(gdk_x11_window_get_xid (brightness->priv->root_window)
)
,
957 RRScreenChangeNotifyMask(1L << 0) |
958 RROutputPropertyNotifyMask(1L << 3)); /* <--- the only one we need, but see rh:345551 */
959 gdk_display_flush (display);
960 if (gdk_x11_display_error_trap_pop (display))
961 g_warning ("failed to select XRRSelectInput");
962
963 /* create cache of XRRScreenResources as XRRGetScreenResources() is slow */
964 gpm_brightness_update_cache (brightness);
965}
966
967/**
968 * gpm_brightness_new:
969 * Return value: A new brightness class instance.
970 * Can return NULL if no suitable hardware is found.
971 **/
972GpmBrightness *
973gpm_brightness_new (void)
974{
975 if (gpm_brightness_object != NULL((void*)0)) {
976 g_object_ref (gpm_brightness_object)((__typeof__ (gpm_brightness_object)) (g_object_ref) (gpm_brightness_object
))
;
977 } else {
978 gpm_brightness_object = g_object_new (GPM_TYPE_BRIGHTNESS(gpm_brightness_get_type ()), NULL((void*)0));
979 g_object_add_weak_pointer (gpm_brightness_object, &gpm_brightness_object);
980 }
981 return GPM_BRIGHTNESS (gpm_brightness_object)((((GpmBrightness*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gpm_brightness_object)), ((gpm_brightness_get_type ())))
)))
;
982}
983
diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/report-26c008.html b/2024-02-25-205630-11823-1@c406c230d131_master/report-26c008.html new file mode 100644 index 0000000..d091f37 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/report-26c008.html @@ -0,0 +1,958 @@ + + + +gpm-main.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:gpm-main.c
Warning:line 242, column 3
This statement is never executed
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gpm-main.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/libsecret-1 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libpng16 -I /usr/include/blkid -I /usr/include/libmount -I /usr/include/sysprof-6 -D _REENTRANT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/cloudproviders -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -I /usr/include/libupower-glib -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -D BINDIR="/usr/local/bin" -D SBINDIR="/usr/local/sbin" -D MATELOCALEDIR="/usr/local/share/locale" -D DATADIR="/usr/local/share" -D PREFIX="/usr/local" -D SYSCONFDIR="/usr/local/etc" -D LIBDIR="/usr/local/lib" -D VERSION="1.28.0" -D GPM_ICONS_DATA="/usr/local/share/mate-power-manager/icons" -D GTKBUILDERDIR="/usr/local/share/mate-power-manager" -D UP_DISABLE_DEPRECATED -D G_LOG_DOMAIN="PowerManager" -I .. -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-25-205630-11823-1 -x c gpm-main.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2005-2007 Richard Hughes <richard@hughsie.com>
4 * Copyright (C) 2012-2021 MATE Developers
5 *
6 * Taken in part from:
7 * - lshal (C) 2003 David Zeuthen, <david@fubar.dk>
8 * - notibat (C) 2004 Benjamin Kahn, <xkahn@zoned.net>
9 *
10 * Licensed under the GNU General Public License Version 2
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27#include "config.h"
28
29#include <string.h>
30#include <unistd.h>
31#include <stdlib.h>
32#include <errno(*__errno_location ()).h>
33#include <locale.h>
34#include <glib.h>
35#include <glib/gi18n.h>
36#include <gtk/gtk.h>
37#include <dbus/dbus-glib.h>
38#include <dbus/dbus-glib-lowlevel.h>
39
40#include "gpm-icon-names.h"
41#include "gpm-common.h"
42#include "gpm-manager.h"
43#include "gpm-session.h"
44
45#include "org.mate.PowerManager.h"
46
47/**
48 * gpm_object_register:
49 * @connection: What we want to register to
50 * @object: The GObject we want to register
51 *
52 * Register org.mate.PowerManager on the session bus.
53 * This function MUST be called before DBUS service will work.
54 *
55 * Return value: success
56 **/
57static gboolean
58gpm_object_register (DBusGConnection *connection,
59 GObject *object)
60{
61 DBusGProxy *bus_proxy = NULL((void*)0);
62 GError *error = NULL((void*)0);
63 guint request_name_result;
64 gboolean ret;
65
66 bus_proxy = dbus_g_proxy_new_for_name (connection,
67 DBUS_SERVICE_DBUS"org.freedesktop.DBus",
68 DBUS_PATH_DBUS"/org/freedesktop/DBus",
69 DBUS_INTERFACE_DBUS"org.freedesktop.DBus");
70
71 ret = dbus_g_proxy_call (bus_proxy, "RequestName", &error,
72 G_TYPE_STRING((GType) ((16) << (2))), GPM_DBUS_SERVICE"org.mate.PowerManager",
73 G_TYPE_UINT((GType) ((7) << (2))), 0,
74 G_TYPE_INVALID((GType) ((0) << (2))),
75 G_TYPE_UINT((GType) ((7) << (2))), &request_name_result,
76 G_TYPE_INVALID((GType) ((0) << (2))));
77 if (error) {
78 g_debug ("ERROR: %s", error->message);
79 g_error_free (error);
80 }
81 if (!ret) {
82 /* abort as the DBUS method failed */
83 g_warning ("RequestName failed!");
84 return FALSE(0);
85 }
86
87 /* free the bus_proxy */
88 g_object_unref (G_OBJECT (bus_proxy)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((bus_proxy)), (((GType) ((20) << (2))))))))
);
89
90 /* already running */
91 if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER1) {
92 return FALSE(0);
93 }
94
95 dbus_g_object_type_install_info (GPM_TYPE_MANAGER(gpm_manager_get_type ()), &dbus_glib_gpm_manager_object_info);
96 dbus_g_error_domain_register (GPM_MANAGER_ERROR(gpm_manager_error_quark ()), NULL((void*)0), GPM_MANAGER_TYPE_ERROR(gpm_manager_error_get_type ()));
97 dbus_g_connection_register_g_object (connection, GPM_DBUS_PATH"/org/mate/PowerManager", object);
98
99 return TRUE(!(0));
100}
101
102/**
103 * timed_exit_cb:
104 * @loop: The main loop
105 *
106 * Exits the main loop, which is helpful for valgrinding g-p-m.
107 *
108 * Return value: FALSE, as we don't want to repeat this action.
109 **/
110static gboolean
111timed_exit_cb (GMainLoop *loop)
112{
113 g_main_loop_quit (loop);
114 return FALSE(0);
115}
116
117/**
118 * gpm_main_stop_cb:
119 **/
120static void
121gpm_main_stop_cb (GpmSession *session, GMainLoop *loop)
122{
123 g_main_loop_quit (loop);
124}
125
126/**
127 * gpm_main_query_end_session_cb:
128 **/
129static void
130gpm_main_query_end_session_cb (GpmSession *session, guint flags, GMainLoop *loop)
131{
132 /* just send response */
133 gpm_session_end_session_response (session, TRUE(!(0)), NULL((void*)0));
134}
135
136/**
137 * gpm_main_end_session_cb:
138 **/
139static void
140gpm_main_end_session_cb (GpmSession *session, guint flags, GMainLoop *loop)
141{
142 /* send response */
143 gpm_session_end_session_response (session, TRUE(!(0)), NULL((void*)0));
144
145 /* exit loop, will unref manager */
146 g_main_loop_quit (loop);
147}
148
149/**
150 * main:
151 **/
152int
153main (int argc, char *argv[])
154{
155 GMainLoop *loop;
156 DBusGConnection *system_connection;
157 DBusGConnection *session_connection;
158 gboolean version = FALSE(0);
159 gboolean timed_exit = FALSE(0);
160 gboolean immediate_exit = FALSE(0);
161 GpmSession *session = NULL((void*)0);
162 GpmManager *manager = NULL((void*)0);
163 GError *error = NULL((void*)0);
164 GOptionContext *context;
165 gint ret;
166 guint timer_id;
167
168 const GOptionEntry options[] = {
169 { "version", '\0', 0, G_OPTION_ARG_NONE, &version,
170 N_("Show version of installed program and exit")("Show version of installed program and exit"), NULL((void*)0) },
171 { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
172 N_("Exit after a small delay (for debugging)")("Exit after a small delay (for debugging)"), NULL((void*)0) },
173 { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit,
174 N_("Exit after the manager has loaded (for debugging)")("Exit after the manager has loaded (for debugging)"), NULL((void*)0) },
175 { NULL((void*)0), 0, 0, G_OPTION_ARG_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0) }
176 };
177
178 setlocale (LC_ALL6, "");
179 bindtextdomain (GETTEXT_PACKAGE"mate-power-manager", MATELOCALEDIR"/usr/local/share/locale");
180 bind_textdomain_codeset (GETTEXT_PACKAGE"mate-power-manager", "UTF-8");
181 textdomain (GETTEXT_PACKAGE"mate-power-manager");
182
183 dbus_g_thread_init ();
184
185 context = g_option_context_new (N_("MATE Power Manager")("MATE Power Manager"));
186 /* TRANSLATORS: program name, a simple app to view pending updates */
187 g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE"mate-power-manager");
188 g_option_context_set_translation_domain(context, GETTEXT_PACKAGE"mate-power-manager");
189 g_option_context_set_summary (context, _("MATE Power Manager")gettext ("MATE Power Manager"));
190 g_option_context_parse (context, &argc, &argv, NULL((void*)0));
191
192 if (version) {
193 g_print ("Version %s\n", VERSION"1.28.0");
194 goto unref_program;
195 }
196
197 dbus_g_thread_init ();
198
199 gtk_init (&argc, &argv);
200
201 g_debug ("MATE %s %s", GPM_NAMEgettext ("Power Manager"), VERSION"1.28.0");
202
203 /* check dbus connections, exit if not valid */
204 system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
205 if (error) {
206 g_warning ("%s", error->message);
207 g_error_free (error);
208 g_error ("This program cannot start until you start "
209 "the dbus system service.\n"
210 "It is <b>strongly recommended</b> you reboot "
211 "your computer after starting this service.");
212 }
213
214 session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
215 if (error) {
216 g_warning ("%s", error->message);
217 g_error_free (error);
218 g_error ("This program cannot start until you start the "
219 "dbus session service.\n\n"
220 "This is usually started automatically in X "
221 "or mate startup when you start a new session.");
222 }
223
224 /* add application specific icons to search path */
225 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
226 GPM_ICONS_DATA"/usr/local/share/mate-power-manager/icons");
227
228 loop = g_main_loop_new (NULL((void*)0), FALSE(0));
229
230 /* optionally register with the session */
231 session = gpm_session_new ();
232 g_signal_connect (session, "stop", G_CALLBACK (gpm_main_stop_cb), loop)g_signal_connect_data ((session), ("stop"), (((GCallback) (gpm_main_stop_cb
))), (loop), ((void*)0), (GConnectFlags) 0)
;
233 g_signal_connect (session, "query-end-session", G_CALLBACK (gpm_main_query_end_session_cb), loop)g_signal_connect_data ((session), ("query-end-session"), (((GCallback
) (gpm_main_query_end_session_cb))), (loop), ((void*)0), (GConnectFlags
) 0)
;
234 g_signal_connect (session, "end-session", G_CALLBACK (gpm_main_end_session_cb), loop)g_signal_connect_data ((session), ("end-session"), (((GCallback
) (gpm_main_end_session_cb))), (loop), ((void*)0), (GConnectFlags
) 0)
;
235 gpm_session_register_client (session, "mate-power-manager", getenv ("DESKTOP_AUTOSTART_ID"));
236
237 /* create a new gui object */
238 manager = gpm_manager_new ();
239
240 if (!gpm_object_register (session_connection, G_OBJECT (manager)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((manager)), (((GType) ((20) << (2))))))))
)) {
241 g_error ("%s is already running in this session.", GPM_NAMEgettext ("Power Manager"));
242 goto unref_program;
This statement is never executed
243 }
244
245 /* register to be a policy agent, just like kpackagekit does */
246 ret = dbus_bus_request_name(dbus_g_connection_get_connection(system_connection),
247 "org.freedesktop.Policy.Power",
248 DBUS_NAME_FLAG_REPLACE_EXISTING0x2, NULL((void*)0));
249 switch (ret) {
250 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER1:
251 g_debug ("Successfully acquired interface org.freedesktop.Policy.Power.");
252 break;
253 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE2:
254 g_debug ("Queued for interface org.freedesktop.Policy.Power.");
255 break;
256 default:
257 break;
258 };
259
260 /* Only timeout and close the mainloop if we have specified it
261 * on the command line */
262 if (timed_exit) {
263 timer_id = g_timeout_add_seconds (20, (GSourceFunc) timed_exit_cb, loop);
264 g_source_set_name_by_id (timer_id, "[GpmMain] timed-exit");
265 }
266
267 if (immediate_exit == FALSE(0)) {
268 g_main_loop_run (loop);
269 }
270
271 g_main_loop_unref (loop);
272
273 g_object_unref (session);
274 g_object_unref (manager);
275unref_program:
276 g_option_context_free (context);
277 return 0;
278}
diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/report-6489a3.html b/2024-02-25-205630-11823-1@c406c230d131_master/report-6489a3.html new file mode 100644 index 0000000..9522dfc --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/report-6489a3.html @@ -0,0 +1,2194 @@ + + + +gpm-statistics.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:gpm-statistics.c
Warning:line 1501, column 2
Value stored to 'widget' is never read
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gpm-statistics.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/libsecret-1 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libpng16 -I /usr/include/blkid -I /usr/include/libmount -I /usr/include/sysprof-6 -D _REENTRANT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/cloudproviders -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -I /usr/include/libupower-glib -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -D BINDIR="/usr/local/bin" -D SBINDIR="/usr/local/sbin" -D MATELOCALEDIR="/usr/local/share/locale" -D DATADIR="/usr/local/share" -D PREFIX="/usr/local" -D SYSCONFDIR="/usr/local/etc" -D LIBDIR="/usr/local/lib" -D VERSION="1.28.0" -D GPM_ICONS_DATA="/usr/local/share/mate-power-manager/icons" -D GTKBUILDERDIR="/usr/local/share/mate-power-manager" -D UP_DISABLE_DEPRECATED -D G_LOG_DOMAIN="PowerManager" -I .. -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-25-205630-11823-1 -x c gpm-statistics.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
4 * Copyright (C) 2012-2021 MATE Developers
5 *
6 * Licensed under the GNU General Public License Version 2
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "config.h"
24
25#include <locale.h>
26
27#include <glib.h>
28#include <glib/gi18n.h>
29
30#include <gtk/gtk.h>
31#include <dbus/dbus-glib.h>
32#include <libupower-glib/upower.h>
33
34#include "egg-color.h"
35#include "egg-array-float.h"
36
37#include "gpm-common.h"
38#include "gpm-icon-names.h"
39#include "gpm-upower.h"
40#include "gpm-graph-widget.h"
41
42static GtkBuilder *builder = NULL((void*)0);
43static GtkListStore *list_store_info = NULL((void*)0);
44static GtkListStore *list_store_devices = NULL((void*)0);
45gchar *current_device = NULL((void*)0);
46static guint history_time;
47static GSettings *settings;
48static gfloat sigma_smoothing = 0.0f;
49static GtkWidget *graph_history = NULL((void*)0);
50static GtkWidget *graph_statistics = NULL((void*)0);
51
52enum {
53 GPM_INFO_COLUMN_TEXT,
54 GPM_INFO_COLUMN_VALUE,
55 GPM_INFO_COLUMN_LAST
56};
57
58enum {
59 GPM_DEVICES_COLUMN_ICON,
60 GPM_DEVICES_COLUMN_TEXT,
61 GPM_DEVICES_COLUMN_ID,
62 GPM_DEVICES_COLUMN_LAST
63};
64
65#define GPM_STATS_CHARGE_DATA_VALUE"charge-data" "charge-data"
66#define GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy" "charge-accuracy"
67#define GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data" "discharge-data"
68#define GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy" "discharge-accuracy"
69
70/* TRANSLATORS: what we've observed about the device */
71#define GPM_STATS_CHARGE_DATA_TEXTgettext ("Charge profile") _("Charge profile")gettext ("Charge profile")
72#define GPM_STATS_DISCHARGE_DATA_TEXTgettext ("Discharge profile") _("Discharge profile")gettext ("Discharge profile")
73/* TRANSLATORS: how accurately we can predict the time remaining of the battery */
74#define GPM_STATS_CHARGE_ACCURACY_TEXTgettext ("Charge accuracy") _("Charge accuracy")gettext ("Charge accuracy")
75#define GPM_STATS_DISCHARGE_ACCURACY_TEXTgettext ("Discharge accuracy") _("Discharge accuracy")gettext ("Discharge accuracy")
76
77#define GPM_HISTORY_RATE_TEXTgettext ("Rate") _("Rate")gettext ("Rate")
78#define GPM_HISTORY_CHARGE_TEXTgettext ("Charge") _("Charge")gettext ("Charge")
79#define GPM_HISTORY_TIME_FULL_TEXTgettext ("Time to full") _("Time to full")gettext ("Time to full")
80#define GPM_HISTORY_TIME_EMPTY_TEXTgettext ("Time to empty") _("Time to empty")gettext ("Time to empty")
81
82#define GPM_HISTORY_POWER_VALUE"power" "power"
83#define GPM_HISTORY_RATE_VALUE"rate" "rate"
84#define GPM_HISTORY_CHARGE_VALUE"charge" "charge"
85#define GPM_HISTORY_TIME_FULL_VALUE"time-full" "time-full"
86#define GPM_HISTORY_TIME_EMPTY_VALUE"time-empty" "time-empty"
87
88#define GPM_HISTORY_MINUTE_TEXTgettext ("10 minutes") _("10 minutes")gettext ("10 minutes")
89#define GPM_HISTORY_HOUR_TEXTgettext ("2 hours") _("2 hours")gettext ("2 hours")
90#define GPM_HISTORY_HOURS_TEXTgettext ("6 hours") _("6 hours")gettext ("6 hours")
91#define GPM_HISTORY_DAY_TEXTgettext ("1 day") _("1 day")gettext ("1 day")
92#define GPM_HISTORY_WEEK_TEXTgettext ("1 week") _("1 week")gettext ("1 week")
93
94#define GPM_HISTORY_MINUTE_VALUE10*60 10*60
95#define GPM_HISTORY_HOUR_VALUE2*60*60 2*60*60
96#define GPM_HISTORY_HOURS_VALUE6*60*60 6*60*60
97#define GPM_HISTORY_DAY_VALUE24*60*60 24*60*60
98#define GPM_HISTORY_WEEK_VALUE7*24*60*60 7*24*60*60
99
100enum stats_type_enum {
101 GPM_STATS_CHARGE_TYPE = 0,
102 GPM_STATS_DISCHARGE_TYPE,
103 GPM_STATS_CHARGE_ACCURACY_TYPE,
104 GPM_STATS_DISCHARGE_ACCURACY_TYPE,
105 GPM_STATS_LAST_TYPE
106};
107static enum stats_type_enum stats_type;
108
109enum history_type_enum {
110 GPM_HISTORY_RATE_TYPE = 0,
111 GPM_HISTORY_CHARGE_TYPE,
112 GPM_HISTORY_TIME_FULL_TYPE,
113 GPM_HISTORY_TIME_EMPTY_TYPE,
114 GPM_HISTORY_POWER_TYPE,
115 GPM_HISTORY_LAST_TYPE
116};
117static enum history_type_enum history_type;
118static const char *history_types [GPM_HISTORY_LAST_TYPE] = {
119 [GPM_HISTORY_RATE_TYPE] = GPM_HISTORY_RATE_VALUE"rate",
120 [GPM_HISTORY_CHARGE_TYPE] = GPM_HISTORY_CHARGE_VALUE"charge",
121 [GPM_HISTORY_TIME_FULL_TYPE] = GPM_HISTORY_TIME_FULL_VALUE"time-full",
122 [GPM_HISTORY_TIME_EMPTY_TYPE] = GPM_HISTORY_TIME_EMPTY_VALUE"time-empty",
123 [GPM_HISTORY_POWER_TYPE] = GPM_HISTORY_POWER_VALUE"power"
124};
125
126/**
127 * gpm_stats_button_help_cb:
128 **/
129static void
130gpm_stats_button_help_cb (GtkWidget *widget, gboolean data)
131{
132 gpm_help_display ("statistics");
133}
134
135/**
136 * gpm_stats_add_info_columns:
137 **/
138static void
139gpm_stats_add_info_columns (GtkTreeView *treeview)
140{
141 GtkCellRenderer *renderer;
142 GtkTreeViewColumn *column;
143
144 /* image */
145 renderer = gtk_cell_renderer_text_new ();
146 column = gtk_tree_view_column_new_with_attributes (_("Attribute")gettext ("Attribute"), renderer,
147 "markup", GPM_INFO_COLUMN_TEXT, NULL((void*)0));
148 gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT);
149 gtk_tree_view_append_column (treeview, column);
150
151 /* column for text */
152 renderer = gtk_cell_renderer_text_new ();
153 column = gtk_tree_view_column_new_with_attributes (_("Value")gettext ("Value"), renderer,
154 "markup", GPM_INFO_COLUMN_VALUE, NULL((void*)0));
155 gtk_tree_view_append_column (treeview, column);
156}
157
158/**
159 * gpm_stats_add_devices_columns:
160 **/
161static void
162gpm_stats_add_devices_columns (GtkTreeView *treeview)
163{
164 GtkCellRenderer *renderer;
165 GtkTreeViewColumn *column;
166
167 /* image */
168 renderer = gtk_cell_renderer_pixbuf_new ();
169 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL((void*)0));
170 column = gtk_tree_view_column_new_with_attributes (_("Image")gettext ("Image"), renderer,
171 "icon-name", GPM_DEVICES_COLUMN_ICON, NULL((void*)0));
172 gtk_tree_view_append_column (treeview, column);
173
174 /* column for text */
175 renderer = gtk_cell_renderer_text_new ();
176 column = gtk_tree_view_column_new_with_attributes (_("Description")gettext ("Description"), renderer,
177 "markup", GPM_DEVICES_COLUMN_TEXT, NULL((void*)0));
178 gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT);
179 gtk_tree_view_append_column (treeview, column);
180 gtk_tree_view_column_set_expand (column, TRUE(!(0)));
181}
182
183/**
184 * gpm_stats_add_info_data:
185 **/
186static void
187gpm_stats_add_info_data (const gchar *attr, const gchar *text)
188{
189 GtkTreeIter iter;
190 gtk_list_store_append (list_store_info, &iter);
191 gtk_list_store_set (list_store_info, &iter,
192 GPM_INFO_COLUMN_TEXT, attr,
193 GPM_INFO_COLUMN_VALUE, text, -1);
194}
195
196/**
197 * gpm_stats_update_smooth_data:
198 **/
199static GPtrArray *
200gpm_stats_update_smooth_data (GPtrArray *list)
201{
202 guint i;
203 GpmPointObj *point;
204 GpmPointObj *point_new;
205 GPtrArray *new;
206 EggArrayFloat *raw;
207 EggArrayFloat *convolved;
208 EggArrayFloat *outliers;
209 EggArrayFloat *gaussian = NULL((void*)0);
210
211 /* convert the y data to a EggArrayFloat array */
212 raw = egg_array_float_new (list->len);
213 for (i=0; i<list->len; i++) {
214 point = (GpmPointObj *) g_ptr_array_index (list, i)((list)->pdata)[i];
215 egg_array_float_set (raw, i, point->y);
216 }
217
218 /* remove any outliers */
219 outliers = egg_array_float_remove_outliers (raw, 3, 0.1);
220
221 /* convolve with gaussian */
222 gaussian = egg_array_float_compute_gaussian (15, sigma_smoothing);
223 convolved = egg_array_float_convolve (outliers, gaussian);
224
225 /* add the smoothed data back into a new array */
226 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
227 for (i=0; i<list->len; i++) {
228 point = (GpmPointObj *) g_ptr_array_index (list, i)((list)->pdata)[i];
229 point_new = g_new0 (GpmPointObj, 1)((GpmPointObj *) g_malloc0_n ((1), sizeof (GpmPointObj)));
230 point_new->color = point->color;
231 point_new->x = point->x;
232 point_new->y = egg_array_float_get (convolved, i);
233 g_ptr_array_add (new, point_new);
234 }
235
236 /* free data */
237 egg_array_float_free (gaussian);
238 egg_array_float_free (raw);
239 egg_array_float_free (convolved);
240 egg_array_float_free (outliers);
241
242 return new;
243}
244
245/**
246 * gpm_stats_time_to_string:
247 **/
248static gchar *
249gpm_stats_time_to_string (gint seconds)
250{
251 gfloat value = seconds;
252
253 if (value < 0) {
254 /* TRANSLATORS: this is when the stats time is not known */
255 return g_strdup (_("Unknown"))g_strdup_inline (gettext ("Unknown"));
256 }
257 if (value < 60) {
258 /* TRANSLATORS: this is a time value, usually to show on a graph */
259 return g_strdup_printf (ngettext ("%.0f second", "%.0f seconds", value), value);
260 }
261 value /= 60.0;
262 if (value < 60) {
263 /* TRANSLATORS: this is a time value, usually to show on a graph */
264 return g_strdup_printf (ngettext ("%.1f minute", "%.1f minutes", value), value);
265 }
266 value /= 60.0;
267 if (value < 60) {
268 /* TRANSLATORS: this is a time value, usually to show on a graph */
269 return g_strdup_printf (ngettext ("%.1f hour", "%.1f hours", value), value);
270 }
271 value /= 24.0;
272 /* TRANSLATORS: this is a time value, usually to show on a graph */
273 return g_strdup_printf (ngettext ("%.1f day", "%.1f days", value), value);
274}
275
276/**
277 * gpm_stats_bool_to_string:
278 **/
279static const gchar *
280gpm_stats_bool_to_string (gboolean ret)
281{
282 return ret ? _("Yes")gettext ("Yes") : _("No")gettext ("No");
283}
284
285/**
286 * gpm_stats_get_printable_device_path:
287 **/
288static gchar *
289gpm_stats_get_printable_device_path (UpDevice *device)
290{
291 const gchar *object_path;
292 gchar *device_path = NULL((void*)0);
293
294 /* get object path */
295 object_path = up_device_get_object_path (device);
296 if (object_path != NULL((void*)0))
297 device_path = g_filename_display_basename (object_path);
298
299 return device_path;
300}
301
302/**
303 * gpm_stats_update_info_page_details:
304 **/
305static void
306gpm_stats_update_info_page_details (UpDevice *device)
307{
308 struct tm *time_tm;
309 time_t t;
310 gchar time_buf[256];
311 gchar *text;
312 guint refreshed;
313 UpDeviceKind kind;
314 UpDeviceState state;
315 UpDeviceTechnology technology;
316 gdouble percentage;
317 gdouble capacity;
318 gdouble energy;
319 gdouble energy_empty;
320 gdouble energy_full;
321 gdouble energy_full_design;
322 gdouble energy_rate;
323 gdouble voltage;
324 gboolean online;
325 gboolean is_present;
326 gboolean power_supply;
327 gboolean is_rechargeable;
328 guint64 update_time;
329 gint64 time_to_full;
330 gint64 time_to_empty;
331 gchar *vendor = NULL((void*)0);
332 gchar *serial = NULL((void*)0);
333 gchar *model = NULL((void*)0);
334 gchar *device_path = NULL((void*)0);
335
336 gtk_list_store_clear (list_store_info);
337
338 /* get device properties */
339 g_object_get (device,
340 "kind", &kind,
341 "state", &state,
342 "percentage", &percentage,
343 "online", &online,
344 "update_time", &update_time,
345 "power_supply", &power_supply,
346 "is_rechargeable", &is_rechargeable,
347 "is-present", &is_present,
348 "time-to-full", &time_to_full,
349 "time-to-empty", &time_to_empty,
350 "technology", &technology,
351 "capacity", &capacity,
352 "energy", &energy,
353 "energy-empty", &energy_empty,
354 "energy-full", &energy_full,
355 "energy-full-design", &energy_full_design,
356 "energy-rate", &energy_rate,
357 "voltage", &voltage,
358 "vendor", &vendor,
359 "serial", &serial,
360 "model", &model,
361 NULL((void*)0));
362
363 /* get a human readable time */
364 t = (time_t) update_time;
365 time_tm = localtime (&t);
366 strftime (time_buf, sizeof time_buf, "%c", time_tm);
367
368 /* remove prefix */
369 device_path = gpm_stats_get_printable_device_path (device);
370 /* TRANSLATORS: the device ID of the current device, e.g. "battery0" */
371 gpm_stats_add_info_data (_("Device")gettext ("Device"), device_path);
372 g_free (device_path);
373
374 gpm_stats_add_info_data (_("Type")gettext ("Type"), gpm_device_kind_to_localised_string (kind, 1));
375 if (vendor != NULL((void*)0) && vendor[0] != '\0')
376 gpm_stats_add_info_data (_("Vendor")gettext ("Vendor"), vendor);
377 if (model != NULL((void*)0) && model[0] != '\0')
378 gpm_stats_add_info_data (_("Model")gettext ("Model"), model);
379 if (serial != NULL((void*)0) && serial[0] != '\0')
380 gpm_stats_add_info_data (_("Serial number")gettext ("Serial number"), serial);
381
382 /* TRANSLATORS: a boolean attribute that means if the device is supplying the
383 * main power for the computer. For instance, an AC adapter or laptop battery
384 * would be TRUE, but a mobile phone or mouse taking power is FALSE */
385 gpm_stats_add_info_data (_("Supply")gettext ("Supply"), gpm_stats_bool_to_string (power_supply));
386
387 refreshed = (int) (time (NULL((void*)0)) - update_time);
388 text = g_strdup_printf (ngettext ("%u second", "%u seconds", refreshed), refreshed);
389
390 /* TRANSLATORS: when the device was last updated with new data. It's
391 * usually a few seconds when a device is discharging or charging. */
392 gpm_stats_add_info_data (_("Refreshed")gettext ("Refreshed"), text);
393 g_free (text);
394
395 if (kind == UP_DEVICE_KIND_BATTERY ||
396 kind == UP_DEVICE_KIND_MOUSE ||
397 kind == UP_DEVICE_KIND_KEYBOARD ||
398 kind == UP_DEVICE_KIND_UPS) {
399 /* TRANSLATORS: Present is whether the device is currently attached
400 * to the computer, as some devices (e.g. laptop batteries) can
401 * be removed, but still observed as devices on the system */
402 gpm_stats_add_info_data (_("Present")gettext ("Present"), gpm_stats_bool_to_string (is_present));
403 }
404 if (kind == UP_DEVICE_KIND_BATTERY ||
405 kind == UP_DEVICE_KIND_MOUSE ||
406 kind == UP_DEVICE_KIND_KEYBOARD) {
407 /* TRANSLATORS: If the device can be recharged, e.g. lithium
408 * batteries rather than alkaline ones */
409 gpm_stats_add_info_data (_("Rechargeable")gettext ("Rechargeable"), gpm_stats_bool_to_string (is_rechargeable));
410 }
411 if (kind == UP_DEVICE_KIND_BATTERY ||
412 kind == UP_DEVICE_KIND_MOUSE ||
413 kind == UP_DEVICE_KIND_KEYBOARD) {
414 /* TRANSLATORS: The state of the device, e.g. "Changing" or "Fully charged" */
415 gpm_stats_add_info_data (_("State")gettext ("State"), gpm_device_state_to_localised_string (state));
416 }
417 if (kind == UP_DEVICE_KIND_BATTERY) {
418 text = g_strdup_printf ("%.1f Wh", energy);
419 gpm_stats_add_info_data (_("Energy")gettext ("Energy"), text);
420 g_free (text);
421 text = g_strdup_printf ("%.1f Wh", energy_empty);
422 gpm_stats_add_info_data (_("Energy when empty")gettext ("Energy when empty"), text);
423 g_free (text);
424 text = g_strdup_printf ("%.1f Wh", energy_full);
425 gpm_stats_add_info_data (_("Energy when full")gettext ("Energy when full"), text);
426 g_free (text);
427 text = g_strdup_printf ("%.1f Wh", energy_full_design);
428 gpm_stats_add_info_data (_("Energy (design)")gettext ("Energy (design)"), text);
429 g_free (text);
430 }
431 if (kind == UP_DEVICE_KIND_BATTERY ||
432 kind == UP_DEVICE_KIND_MONITOR) {
433 text = g_strdup_printf ("%.1f W", energy_rate);
434 /* TRANSLATORS: the rate of discharge for the device */
435 gpm_stats_add_info_data (_("Rate")gettext ("Rate"), text);
436 g_free (text);
437 }
438 if (kind == UP_DEVICE_KIND_UPS ||
439 kind == UP_DEVICE_KIND_BATTERY ||
440 kind == UP_DEVICE_KIND_MONITOR) {
441 text = g_strdup_printf ("%.1f V", voltage);
442 gpm_stats_add_info_data (_("Voltage")gettext ("Voltage"), text);
443 g_free (text);
444 }
445 if (kind == UP_DEVICE_KIND_BATTERY ||
446 kind == UP_DEVICE_KIND_UPS) {
447 if (time_to_full >= 0) {
448 text = gpm_stats_time_to_string (time_to_full);
449 gpm_stats_add_info_data (_("Time to full")gettext ("Time to full"), text);
450 g_free (text);
451 }
452 if (time_to_empty >= 0) {
453 text = gpm_stats_time_to_string (time_to_empty);
454 gpm_stats_add_info_data (_("Time to empty")gettext ("Time to empty"), text);
455 g_free (text);
456 }
457 }
458 if (kind == UP_DEVICE_KIND_BATTERY ||
459 kind == UP_DEVICE_KIND_MOUSE ||
460 kind == UP_DEVICE_KIND_KEYBOARD ||
461 kind == UP_DEVICE_KIND_UPS) {
462 text = g_strdup_printf ("%.1f%%", percentage);
463 /* TRANSLATORS: the amount of charge the cell contains */
464 gpm_stats_add_info_data (_("Percentage")gettext ("Percentage"), text);
465 g_free (text);
466 }
467 if (kind == UP_DEVICE_KIND_BATTERY) {
468 text = g_strdup_printf ("%.1f%%", capacity);
469 /* TRANSLATORS: the capacity of the device, which is basically a measure
470 * of how full it can get, relative to the design capacity */
471 gpm_stats_add_info_data (_("Capacity")gettext ("Capacity"), text);
472 g_free (text);
473 }
474 if (kind == UP_DEVICE_KIND_BATTERY) {
475 /* TRANSLATORS: the type of battery, e.g. lithium or nikel metal hydroxide */
476 gpm_stats_add_info_data (_("Technology")gettext ("Technology"), gpm_device_technology_to_localised_string (technology));
477 }
478 if (kind == UP_DEVICE_KIND_LINE_POWER) {
479 /* TRANSLATORS: this is when the device is plugged in, typically
480 * only shown for the ac adaptor device */
481 gpm_stats_add_info_data (_("Online")gettext ("Online"), gpm_stats_bool_to_string (online));
482 }
483
484 g_free (vendor);
485 g_free (serial);
486 g_free (model);
487}
488
489/**
490 * gpm_stats_set_graph_data:
491 **/
492static void
493gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoothed, gboolean use_points)
494{
495 GPtrArray *smoothed;
496
497 gpm_graph_widget_data_clear (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
);
498
499 /* add correct data */
500 if (!use_smoothed) {
501 if (use_points)
502 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_BOTH, data);
503 else
504 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_LINE, data);
505 } else {
506 smoothed = gpm_stats_update_smooth_data (data);
507 if (use_points)
508 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_POINTS, data);
509 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_LINE, smoothed);
510 g_ptr_array_unref (smoothed);
511 }
512
513 /* show */
514 gtk_widget_show (widget);
515}
516
517/**
518 * gpm_stats_update_info_page_history:
519 **/
520static void
521gpm_stats_update_info_page_history (UpDevice *device)
522{
523 GPtrArray *array;
524 guint i;
525 UpHistoryItem *item;
526 GtkWidget *widget;
527 gboolean checked;
528 gboolean points;
529 GpmPointObj *point;
530 GPtrArray *new;
531 gint32 offset;
532
533 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
534 if (history_type == GPM_HISTORY_CHARGE_TYPE) {
535 g_object_set (graph_history,
536 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
537 "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
538 "autorange-x", FALSE(0),
539 "start-x", -history_time,
540 "stop-x", 0,
541 "autorange-y", FALSE(0),
542 "start-y", 0,
543 "stop-y", 100,
544 NULL((void*)0));
545 } else if (history_type == GPM_HISTORY_RATE_TYPE) {
546 g_object_set (graph_history,
547 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
548 "type-y", GPM_GRAPH_WIDGET_TYPE_POWER,
549 "autorange-x", FALSE(0),
550 "start-x", -history_time,
551 "stop-x", 0,
552 "autorange-y", TRUE(!(0)),
553 NULL((void*)0));
554 } else {
555 g_object_set (graph_history,
556 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
557 "type-y", GPM_GRAPH_WIDGET_TYPE_TIME,
558 "autorange-x", FALSE(0),
559 "start-x", -history_time,
560 "stop-x", 0,
561 "autorange-y", TRUE(!(0)),
562 NULL((void*)0));
563 }
564
565 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_history_nodata"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_history_nodata")
)), ((gtk_widget_get_type ()))))))
;
566 /* The type of history, history_types [history_type], known values are "rate" and "charge". */
567 array = up_device_get_history_sync (device, history_types [history_type], history_time, 150, NULL((void*)0), NULL((void*)0));
568 if (array == NULL((void*)0)) {
569 /* show no data label and hide graph */
570 gtk_widget_hide (graph_history);
571 gtk_widget_show (widget);
572 goto out;
573 }
574
575 /* hide no data and show graph */
576 gtk_widget_hide (widget);
577 gtk_widget_show (graph_history);
578
579 offset = (gint32) (g_get_real_time () / G_USEC_PER_SEC1000000);
580
581 for (i=0; i<array->len; i++) {
582 item = (UpHistoryItem *) g_ptr_array_index (array, i)((array)->pdata)[i];
583
584 /* abandon this point */
585 if (up_history_item_get_state (item) == UP_DEVICE_STATE_UNKNOWN)
586 continue;
587
588 point = gpm_point_obj_new ();
589 point->x = ((gint32) up_history_item_get_time (item)) - offset;
590 point->y = up_history_item_get_value (item);
591 if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
592 point->color = egg_color_from_rgb (255, 0, 0);
593 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
594 point->color = egg_color_from_rgb (0, 0, 255);
595 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
596 point->color = egg_color_from_rgb (200, 0, 0);
597 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
598 point->color = egg_color_from_rgb (0, 0, 200);
599 else {
600 if (history_type == GPM_HISTORY_RATE_TYPE)
601 point->color = egg_color_from_rgb (255, 255, 255);
602 else
603 point->color = egg_color_from_rgb (0, 255, 0);
604 }
605 g_ptr_array_add (new, point);
606 }
607
608 /* render */
609 sigma_smoothing = 2.0;
610 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_history"
))), ((gtk_widget_get_type ()))))))
;
611 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
612 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_history"
))), ((gtk_widget_get_type ()))))))
;
613 points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
614
615 /* present data to graph */
616 gpm_stats_set_graph_data (graph_history, new, checked, points);
617
618 g_ptr_array_unref (array);
619 g_ptr_array_unref (new);
620out:
621 return;
622}
623
624/**
625 * gpm_stats_update_info_page_stats:
626 **/
627static void
628gpm_stats_update_info_page_stats (UpDevice *device)
629{
630 GPtrArray *array;
631 guint i;
632 UpStatsItem *item;
633 GtkWidget *widget;
634 gboolean checked;
635 gboolean points;
636 GpmPointObj *point;
637 GPtrArray *new;
638 gboolean use_data = FALSE(0);
639 const gchar *type = NULL((void*)0);
640
641 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
642 if (stats_type == GPM_STATS_CHARGE_TYPE) {
643 type = "charging";
644 use_data = TRUE(!(0));
645 } else if (stats_type == GPM_STATS_DISCHARGE_TYPE) {
646 type = "discharging";
647 use_data = TRUE(!(0));
648 } else if (stats_type == GPM_STATS_CHARGE_ACCURACY_TYPE) {
649 type = "charging";
650 use_data = FALSE(0);
651 } else if (stats_type == GPM_STATS_DISCHARGE_ACCURACY_TYPE) {
652 type = "discharging";
653 use_data = FALSE(0);
654 } else {
655 g_assert_not_reached ()do { g_assertion_message_expr ("PowerManager", "gpm-statistics.c"
, 655, ((const char*) (__func__)), ((void*)0)); } while (0)
;
656 }
657
658 if (use_data) {
659 g_object_set (graph_statistics,
660 "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
661 "type-y", GPM_GRAPH_WIDGET_TYPE_FACTOR,
662 "autorange-x", TRUE(!(0)),
663 "autorange-y", TRUE(!(0)),
664 NULL((void*)0));
665 } else {
666 g_object_set (graph_statistics,
667 "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
668 "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
669 "autorange-x", TRUE(!(0)),
670 "autorange-y", TRUE(!(0)),
671 NULL((void*)0));
672 }
673
674 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_stats_nodata"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_stats_nodata")))
, ((gtk_widget_get_type ()))))))
;
675 array = up_device_get_statistics_sync (device, type, NULL((void*)0), NULL((void*)0));
676 if (array == NULL((void*)0)) {
677 /* show no data label and hide graph */
678 gtk_widget_hide (graph_statistics);
679 gtk_widget_show (widget);
680 goto out;
681 }
682
683 /* hide no data and show graph */
684 gtk_widget_hide (widget);
685 gtk_widget_show (graph_statistics);
686
687 for (i=0; i<array->len; i++) {
688 item = (UpStatsItem *) g_ptr_array_index (array, i)((array)->pdata)[i];
689 point = gpm_point_obj_new ();
690 point->x = i;
691 if (use_data)
692 point->y = up_stats_item_get_value (item);
693 else
694 point->y = up_stats_item_get_accuracy (item);
695 point->color = egg_color_from_rgb (255, 0, 0);
696 g_ptr_array_add (new, point);
697 }
698
699 /* render */
700 sigma_smoothing = 1.1;
701 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_stats"
))), ((gtk_widget_get_type ()))))))
;
702 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
703 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_stats"
))), ((gtk_widget_get_type ()))))))
;
704 points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
705
706 /* present data to graph */
707 gpm_stats_set_graph_data (graph_statistics, new, checked, points);
708
709 g_ptr_array_unref (array);
710 g_ptr_array_unref (new);
711out:
712 return;
713}
714
715/**
716 * gpm_stats_update_info_data_page:
717 **/
718static void
719gpm_stats_update_info_data_page (UpDevice *device, gint page)
720{
721 if (page == 0)
722 gpm_stats_update_info_page_details (device);
723 else if (page == 1)
724 gpm_stats_update_info_page_history (device);
725 else if (page == 2)
726 gpm_stats_update_info_page_stats (device);
727}
728
729/**
730 * gpm_stats_update_info_data:
731 **/
732static void
733gpm_stats_update_info_data (UpDevice *device)
734{
735 gint page;
736 GtkNotebook *notebook;
737 GtkWidget *page_widget;
738 gboolean has_history;
739 gboolean has_statistics;
740
741 /* get properties */
742 g_object_get (device,
743 "has-history", &has_history,
744 "has-statistics", &has_statistics,
745 NULL((void*)0));
746
747 notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1"))((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "notebook1"))), ((gtk_notebook_get_type
()))))))
;
748
749 /* show info page */
750 page_widget = gtk_notebook_get_nth_page (notebook, 0);
751 gtk_widget_show (page_widget);
752
753 /* hide history if no support */
754 page_widget = gtk_notebook_get_nth_page (notebook, 1);
755 if (has_history)
756 gtk_widget_show (page_widget);
757 else
758 gtk_widget_hide (page_widget);
759
760 /* hide statistics if no support */
761 page_widget = gtk_notebook_get_nth_page (notebook, 2);
762 if (has_statistics)
763 gtk_widget_show (page_widget);
764 else
765 gtk_widget_hide (page_widget);
766
767 page = gtk_notebook_get_current_page (notebook);
768 gpm_stats_update_info_data_page (device, page);
769
770 return;
771}
772
773static void
774gpm_stats_set_title (GtkWindow *window, gint page_num)
775{
776 gchar *title;
777 const gchar * const page_titles[] = {
778 /* TRANSLATORS: shown on the titlebar */
779 N_("Device Information")("Device Information"),
780 /* TRANSLATORS: shown on the titlebar */
781 N_("Device History")("Device History"),
782 /* TRANSLATORS: shown on the titlebar */
783 N_("Device Profile")("Device Profile"),
784 };
785
786 /* TRANSLATORS: shown on the titlebar */
787 title = g_strdup_printf ("%s - %s", _("Power Statistics")gettext ("Power Statistics"), _(page_titles[page_num])gettext (page_titles[page_num]));
788 gtk_window_set_title (window, title);
789 g_free (title);
790}
791
792/**
793 * gpm_stats_notebook_changed_cb:
794 **/
795static void
796gpm_stats_notebook_changed_cb (GtkNotebook *notebook, gpointer page, gint page_num, gpointer user_data)
797{
798 UpDevice *device;
799 GtkWidget *widget;
800
801 /* set the window title depending on the mode */
802 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
803 gpm_stats_set_title (GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
, page_num);
804
805 /* save page in gsettings */
806 g_settings_set_int (settings, GPM_SETTINGS_INFO_PAGE_NUMBER"info-page-number", page_num);
807
808 if (current_device == NULL((void*)0))
809 return;
810
811 device = up_device_new ();
812 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
813 gpm_stats_update_info_data_page (device, page_num);
814 gpm_stats_update_info_data (device);
815 g_object_unref (device);
816}
817
818/**
819 * gpm_stats_button_update_ui:
820 **/
821static void
822gpm_stats_button_update_ui (void)
823{
824 UpDevice *device;
825
826 if (current_device == NULL((void*)0))
827 return;
828
829 device = up_device_new ();
830 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
831 gpm_stats_update_info_data (device);
832 g_object_unref (device);
833}
834
835/**
836 * gpm_stats_devices_treeview_clicked_cb:
837 **/
838static void
839gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data)
840{
841 GtkTreeModel *model;
842 GtkTreeIter iter;
843 UpDevice *device;
844
845 /* This will only work in single or browse selection mode! */
846 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
847 g_free (current_device);
848 gtk_tree_model_get (model, &iter, GPM_DEVICES_COLUMN_ID, &current_device, -1);
849
850 /* save device in gsettings */
851 g_settings_set_string (settings, GPM_SETTINGS_INFO_LAST_DEVICE"info-last-device", current_device);
852
853 /* show transaction_id */
854 g_debug ("selected row is: %s", current_device);
855
856 /* is special device */
857 device = up_device_new ();
858 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
859 gpm_stats_update_info_data (device);
860 g_object_unref (device);
861
862 } else {
863 g_debug ("no row selected");
864 }
865}
866
867/**
868 * gpm_stats_window_activated_cb
869 **/
870static void
871gpm_stats_window_activated_cb (GtkApplication *app, gpointer data)
872{
873 GtkWidget *widget;
874 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
875 gtk_application_add_window (GTK_APPLICATION (app)((((GtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((gtk_application_get_type ()))))))
, GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
);
876 gtk_window_present (GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
);
877}
878
879/**
880 * gpm_stats_device_changed_cb:
881 **/
882static void
883gpm_stats_device_changed_cb (UpDevice *device, GParamSpec *pspec, gpointer user_data)
884{
885 const gchar *object_path;
886 object_path = up_device_get_object_path (device);
887 if (object_path == NULL((void*)0) || current_device == NULL((void*)0))
888 return;
889 g_debug ("changed: %s", object_path);
890 if (g_strcmp0 (current_device, object_path) == 0)
891 gpm_stats_update_info_data (device);
892}
893
894/**
895 * gpm_stats_add_device:
896 **/
897static void
898gpm_stats_add_device (UpDevice *device, GPtrArray *devices)
899{
900 const gchar *id;
901 GtkTreeIter iter;
902 char *icon;
903 UpDeviceKind kind;
904 gchar *label, *vendor, *model;
905
906 if (devices != NULL((void*)0))
907 g_ptr_array_add (devices, device);
908
909 g_signal_connect (device, "notify",g_signal_connect_data ((device), ("notify"), (((GCallback) (gpm_stats_device_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
910 G_CALLBACK (gpm_stats_device_changed_cb), NULL)g_signal_connect_data ((device), ("notify"), (((GCallback) (gpm_stats_device_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
911
912 /* get device properties */
913 g_object_get (device,
914 "kind", &kind,
915 "vendor", &vendor,
916 "model", &model,
917 NULL((void*)0));
918
919 id = up_device_get_object_path (device);
920 if ((vendor != NULL((void*)0) && strlen(vendor) != 0) && (model != NULL((void*)0) && strlen(model) != 0)) {
921 label = g_strdup_printf ("%s %s", vendor, model);
922 }
923 else if((vendor == NULL((void*)0) || strlen(vendor) == 0) && (model != NULL((void*)0) && strlen(model) != 0)) {
924 label = g_strdup_printf ("%s", model);
925 }
926 else {
927 label = g_strdup_printf ("%s", gpm_device_kind_to_localised_string (kind, 1));
928 }
929 icon = gpm_upower_get_device_icon (device);
930
931 gtk_list_store_append (list_store_devices, &iter);
932 gtk_list_store_set (list_store_devices, &iter,
933 GPM_DEVICES_COLUMN_ID, id,
934 GPM_DEVICES_COLUMN_TEXT, label,
935 GPM_DEVICES_COLUMN_ICON, icon, -1);
936 g_free (icon);
937 g_free (label);
938 g_free (vendor);
939 g_free (model);
940}
941
942/**
943 * gpm_stats_device_added_cb:
944 **/
945static void
946gpm_stats_device_added_cb (UpClient *client, UpDevice *device, GPtrArray *devices)
947{
948 const gchar *object_path;
949 object_path = up_device_get_object_path (device);
950 g_debug ("added: %s", object_path);
951
952 gpm_stats_add_device (device, devices);
953}
954
955/**
956 * gpm_stats_device_removed_cb:
957 **/
958static void
959gpm_stats_device_removed_cb (UpClient *client, const gchar *object_path, GPtrArray *devices)
960{
961 GtkTreeIter iter;
962 gchar *id = NULL((void*)0);
963 gboolean ret;
964
965 UpDevice *device_tmp;
966 guint i;
967
968 for (i = 0; i < devices->len; i++) {
969 device_tmp = g_ptr_array_index (devices, i)((devices)->pdata)[i];
970 if (g_strcmp0 (up_device_get_object_path (device_tmp), object_path) == 0) {
971 g_ptr_array_remove_index_fast (devices, i);
972 break;
973 }
974 }
975 g_debug ("removed: %s", object_path);
976 if (g_strcmp0 (current_device, object_path) == 0) {
977 gtk_list_store_clear (list_store_info);
978 }
979
980 /* search the list and remove the object path entry */
981 ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
982 while (ret) {
983 gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter, GPM_DEVICES_COLUMN_ID, &id, -1);
984 if (g_strcmp0 (id, object_path) == 0) {
985 gtk_list_store_remove (list_store_devices, &iter);
986 break;
987 }
988 g_free (id);
989 ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
990 };
991}
992
993/**
994 * gpm_stats_history_type_combo_changed_cb:
995 **/
996static void
997gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
998{
999 guint active;
1000 const gchar *axis_x = NULL((void*)0);
1001 const gchar *axis_y = NULL((void*)0);
1002
1003 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1004
1005 if (active == 0) {
1006 history_type = GPM_HISTORY_RATE_TYPE;
1007 /* TRANSLATORS: this is the X axis on the graph */
1008 axis_x = _("Time elapsed")gettext ("Time elapsed");
1009 /* TRANSLATORS: this is the Y axis on the graph */
1010 axis_y = _("Power")gettext ("Power");
1011 } else if (active == 1) {
1012 history_type = GPM_HISTORY_CHARGE_TYPE;
1013 /* TRANSLATORS: this is the X axis on the graph */
1014 axis_x = _("Time elapsed")gettext ("Time elapsed");
1015 /* TRANSLATORS: this is the Y axis on the graph for the whole battery device */
1016 axis_y = _("Cell charge")gettext ("Cell charge");
1017 } else if (active == 2) {
1018 history_type = GPM_HISTORY_TIME_FULL_TYPE;
1019 /* TRANSLATORS: this is the X axis on the graph */
1020 axis_x = _("Time elapsed")gettext ("Time elapsed");
1021 /* TRANSLATORS: this is the Y axis on the graph */
1022 axis_y = _("Predicted time")gettext ("Predicted time");
1023 } else if (active == 3) {
1024 history_type = GPM_HISTORY_TIME_EMPTY_TYPE;
1025 /* TRANSLATORS: this is the X axis on the graph */
1026 axis_x = _("Time elapsed")gettext ("Time elapsed");
1027 /* TRANSLATORS: this is the Y axis on the graph */
1028 axis_y = _("Predicted time")gettext ("Predicted time");
1029 } else {
1030 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1030, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1031 }
1032
1033 /* set axis */
1034 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_x"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_history_x")
)), ((gtk_widget_get_type ()))))))
;
1035 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_x);
1036 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_y"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_history_y")
)), ((gtk_widget_get_type ()))))))
;
1037 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_y);
1038
1039 gpm_stats_button_update_ui ();
1040
1041 /* save to gsettings */
1042 g_settings_set_string (settings, GPM_SETTINGS_INFO_HISTORY_TYPE"info-history-type", history_types [history_type]);
1043}
1044
1045/**
1046 * gpm_stats_type_combo_changed_cb:
1047 **/
1048static void
1049gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data)
1050{
1051 guint active;
1052 const gchar *axis_x = NULL((void*)0);
1053 const gchar *axis_y = NULL((void*)0);
1054 const char *stats_types [GPM_STATS_LAST_TYPE] = {
1055 [GPM_STATS_CHARGE_TYPE] = GPM_STATS_CHARGE_DATA_VALUE"charge-data",
1056 [GPM_STATS_DISCHARGE_TYPE] = GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy",
1057 [GPM_STATS_CHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data",
1058 [GPM_STATS_DISCHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy"
1059 };
1060
1061 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1062
1063 if (active == 0) {
1064 stats_type = GPM_STATS_CHARGE_TYPE;
1065 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1066 axis_x = _("Cell charge")gettext ("Cell charge");
1067 /* TRANSLATORS: this is the Y axis on the graph */
1068 axis_y = _("Correction factor")gettext ("Correction factor");
1069 } else if (active == 1) {
1070 stats_type = GPM_STATS_CHARGE_ACCURACY_TYPE;
1071 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1072 axis_x = _("Cell charge")gettext ("Cell charge");
1073 /* TRANSLATORS: this is the Y axis on the graph */
1074 axis_y = _("Prediction accuracy")gettext ("Prediction accuracy");
1075 } else if (active == 2) {
1076 stats_type = GPM_STATS_DISCHARGE_TYPE;
1077 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1078 axis_x = _("Cell charge")gettext ("Cell charge");
1079 /* TRANSLATORS: this is the Y axis on the graph */
1080 axis_y = _("Correction factor")gettext ("Correction factor");
1081 } else if (active == 3) {
1082 stats_type = GPM_STATS_DISCHARGE_ACCURACY_TYPE;
1083 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1084 axis_x = _("Cell charge")gettext ("Cell charge");
1085 /* TRANSLATORS: this is the Y axis on the graph */
1086 axis_y = _("Prediction accuracy")gettext ("Prediction accuracy");
1087 } else {
1088 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1088, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1089 }
1090
1091 /* set axis */
1092 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_x"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_stats_x")))
, ((gtk_widget_get_type ()))))))
;
1093 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_x);
1094 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_y"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_stats_y")))
, ((gtk_widget_get_type ()))))))
;
1095 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_y);
1096
1097 gpm_stats_button_update_ui ();
1098
1099 /* save to gsettings */
1100 g_settings_set_string (settings, GPM_SETTINGS_INFO_STATS_TYPE"info-stats-type", stats_types[stats_type]);
1101}
1102
1103/**
1104 * gpm_stats_range_combo_changed:
1105 **/
1106static void
1107gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data)
1108{
1109 guint active;
1110
1111 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1112
1113 if (active == 0)
1114 history_time = GPM_HISTORY_MINUTE_VALUE10*60;
1115 else if (active == 1)
1116 history_time = GPM_HISTORY_HOUR_VALUE2*60*60;
1117 else if (active == 2)
1118 history_time = GPM_HISTORY_HOURS_VALUE6*60*60;
1119 else if (active == 3)
1120 history_time = GPM_HISTORY_DAY_VALUE24*60*60;
1121 else if (active == 4)
1122 history_time = GPM_HISTORY_WEEK_VALUE7*24*60*60;
1123 else
1124 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1124, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1125
1126 /* save to gsettings */
1127 g_settings_set_int (settings, GPM_SETTINGS_INFO_HISTORY_TIME"info-history-time", history_time);
1128
1129 gpm_stats_button_update_ui ();
1130}
1131
1132/**
1133 * gpm_stats_smooth_checkbox_history_cb:
1134 * @widget: The GtkWidget object
1135 **/
1136static void
1137gpm_stats_smooth_checkbox_history_cb (GtkWidget *widget, gpointer data)
1138{
1139 gboolean checked;
1140 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1141 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH"info-history-graph-smooth", checked);
1142 gpm_stats_button_update_ui ();
1143}
1144
1145/**
1146 * gpm_stats_smooth_checkbox_stats_cb:
1147 * @widget: The GtkWidget object
1148 **/
1149static void
1150gpm_stats_smooth_checkbox_stats_cb (GtkWidget *widget, gpointer data)
1151{
1152 gboolean checked;
1153 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1154 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH"info-stats-graph-smooth", checked);
1155 gpm_stats_button_update_ui ();
1156}
1157
1158/**
1159 * gpm_stats_points_checkbox_history_cb:
1160 * @widget: The GtkWidget object
1161 **/
1162static void
1163gpm_stats_points_checkbox_history_cb (GtkWidget *widget, gpointer data)
1164{
1165 gboolean checked;
1166 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1167 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS"info-history-graph-points", checked);
1168 gpm_stats_button_update_ui ();
1169}
1170
1171/**
1172 * gpm_stats_points_checkbox_stats_cb:
1173 * @widget: The GtkWidget object
1174 **/
1175static void
1176gpm_stats_points_checkbox_stats_cb (GtkWidget *widget, gpointer data)
1177{
1178 gboolean checked;
1179 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1180 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_POINTS"info-stats-graph-points", checked);
1181 gpm_stats_button_update_ui ();
1182}
1183
1184/**
1185 * gpm_stats_highlight_device:
1186 **/
1187static void
1188gpm_stats_highlight_device (const gchar *object_path)
1189{
1190 gboolean ret;
1191 gchar *id = NULL((void*)0);
1192 gchar *path_str;
1193 guint i;
1194 GtkTreeIter iter;
1195 GtkTreePath *path;
1196 GtkWidget *widget;
1197
1198 /* check valid */
1199 if (!g_str_has_prefix (object_path, "/")(__builtin_constant_p ("/")? __extension__ ({ const char * const
__str = (object_path); const char * const __prefix = ("/"); gboolean
__result = (0); if (__str == ((void*)0) || __prefix == ((void
*)0)) __result = (g_str_has_prefix) (__str, __prefix); else {
const size_t __str_len = strlen (((__str) + !(__str))); const
size_t __prefix_len = strlen (((__prefix) + !(__prefix))); if
(__str_len >= __prefix_len) __result = memcmp (((__str) +
!(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0; }
__result; }) : (g_str_has_prefix) (object_path, "/") )
)
1200 return;
1201
1202 /* we have to reuse the treeview data as it may be sorted */
1203 ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
1204 for (i=0; ret; i++) {
1205 gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter,
1206 GPM_DEVICES_COLUMN_ID, &id,
1207 -1);
1208 if (g_strcmp0 (id, object_path) == 0) {
1209 path_str = g_strdup_printf ("%u", i);
1210 path = gtk_tree_path_new_from_string (path_str);
1211 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_devices"))), (
(gtk_widget_get_type ()))))))
;
1212 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
, path, NULL((void*)0), NULL((void*)0), FALSE(0));
1213 g_free (path_str);
1214 gtk_tree_path_free (path);
1215 }
1216 g_free (id);
1217 ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
1218 }
1219}
1220
1221/**
1222 * main:
1223 **/
1224int
1225main (int argc, char *argv[])
1226{
1227 GOptionContext *context;
1228 GtkBox *box;
1229 GtkWidget *widget, *window;
1230 GtkTreeSelection *selection;
1231 GtkApplication *app;
1232 gint status;
1233 UpClient *client;
1234 GPtrArray *devices = NULL((void*)0);
1235 UpDevice *device;
1236 UpDeviceKind kind;
1237 guint i, j;
1238 gint page;
1239 gboolean checked;
1240 gchar *last_device = NULL((void*)0);
1241 char *history_type_str;
1242 char *stats_type_str;
1243
1244 const char *history_text [GPM_HISTORY_LAST_TYPE - 1] = {
1245 [GPM_HISTORY_RATE_TYPE] = GPM_HISTORY_RATE_TEXTgettext ("Rate"),
1246 [GPM_HISTORY_CHARGE_TYPE] = GPM_HISTORY_CHARGE_TEXTgettext ("Charge"),
1247 [GPM_HISTORY_TIME_FULL_TYPE] = GPM_HISTORY_TIME_FULL_TEXTgettext ("Time to full"),
1248 [GPM_HISTORY_TIME_EMPTY_TYPE] = GPM_HISTORY_TIME_EMPTY_TEXTgettext ("Time to empty")
1249 };
1250 const char *stats_text [GPM_STATS_LAST_TYPE] = {
1251 [GPM_STATS_CHARGE_TYPE] = GPM_STATS_CHARGE_DATA_TEXTgettext ("Charge profile"),
1252 [GPM_STATS_DISCHARGE_TYPE] = GPM_STATS_DISCHARGE_DATA_TEXTgettext ("Discharge profile"),
1253 [GPM_STATS_CHARGE_ACCURACY_TYPE] = GPM_STATS_CHARGE_ACCURACY_TEXTgettext ("Charge accuracy"),
1254 [GPM_STATS_DISCHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_ACCURACY_TEXTgettext ("Discharge accuracy")
1255 };
1256 const GOptionEntry options[] = {
1257 { "device", '\0', 0, G_OPTION_ARG_STRING, &last_device,
1258 /* TRANSLATORS: show a device by default */
1259 N_("Select this device at startup")("Select this device at startup"), NULL((void*)0) },
1260 { NULL((void*)0), 0, 0, G_OPTION_ARG_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0) }
1261 };
1262
1263 setlocale (LC_ALL6, "");
1264
1265 bindtextdomain (GETTEXT_PACKAGE"mate-power-manager", MATELOCALEDIR"/usr/local/share/locale");
1266 bind_textdomain_codeset (GETTEXT_PACKAGE"mate-power-manager", "UTF-8");
1267 textdomain (GETTEXT_PACKAGE"mate-power-manager");
1268
1269 dbus_g_thread_init ();
1270
1271 context = g_option_context_new (NULL((void*)0));
1272 /* TRANSLATORS: the program name */
1273 g_option_context_set_summary (context, _("Power Statistics")gettext ("Power Statistics"));
1274 g_option_context_add_main_entries (context, options, NULL((void*)0));
1275 g_option_context_parse (context, &argc, &argv, NULL((void*)0));
1276 g_option_context_free (context);
1277
1278 gtk_init (&argc, &argv);
1279
1280 app = gtk_application_new ("org.mate.PowerManager.Statistics", 0);
1281
1282 g_signal_connect (app, "activate",g_signal_connect_data ((app), ("activate"), (((GCallback) (gpm_stats_window_activated_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1283 G_CALLBACK (gpm_stats_window_activated_cb), NULL)g_signal_connect_data ((app), ("activate"), (((GCallback) (gpm_stats_window_activated_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1284
1285 /* add application specific icons to search path */
1286 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
1287 GPM_ICONS_DATA"/usr/local/share/mate-power-manager/icons");
1288
1289 /* get data from the settings */
1290 settings = g_settings_new (GPM_SETTINGS_SCHEMA"org.mate.power-manager");
1291
1292 /* get UI */
1293 builder = gtk_builder_new_from_resource ("/org/mate/powermanager/statistics/gpm-statistics.ui");
1294
1295 /* add history graph */
1296 box = GTK_BOX (gtk_builder_get_object (builder, "hbox_history"))((((GtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "hbox_history"))), ((gtk_box_get_type
()))))))
;
1297 graph_history = gpm_graph_widget_new ();
1298 gtk_box_pack_start (box, graph_history, TRUE(!(0)), TRUE(!(0)), 0);
1299 gtk_widget_set_size_request (graph_history, 400, 250);
1300 gtk_widget_show (graph_history);
1301
1302 /* add statistics graph */
1303 box = GTK_BOX (gtk_builder_get_object (builder, "hbox_statistics"))((((GtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "hbox_statistics"))), (
(gtk_box_get_type ()))))))
;
1304 graph_statistics = gpm_graph_widget_new ();
1305 gtk_box_pack_start (box, graph_statistics, TRUE(!(0)), TRUE(!(0)), 0);
1306 gtk_widget_set_size_request (graph_statistics, 400, 250);
1307 gtk_widget_show (graph_statistics);
1308
1309 window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
1310 gtk_window_set_default_size (GTK_WINDOW(window)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((gtk_window_get_type ()))))))
, 800, 500);
1311 gtk_window_set_default_icon_name (GPM_ICON_APP_ICON"mate-power-manager");
1312
1313 /* Get the main window quit */
1314 widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "button_close"))), ((gtk_widget_get_type
()))))))
;
1315 g_signal_connect_swapped (window, "delete_event", G_CALLBACK (gtk_widget_destroy), window)g_signal_connect_data ((window), ("delete_event"), (((GCallback
) (gtk_widget_destroy))), (window), ((void*)0), G_CONNECT_SWAPPED
)
;
1316 g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_widget_destroy), window)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gtk_widget_destroy))), (window), ((void*)0), G_CONNECT_SWAPPED
)
;
1317 gtk_widget_grab_default (widget);
1318
1319 widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "button_help"))), ((gtk_widget_get_type
()))))))
;
1320 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_button_help_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
1321 G_CALLBACK (gpm_stats_button_help_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_button_help_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
;
1322
1323 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_history"
))), ((gtk_widget_get_type ()))))))
;
1324 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH"info-history-graph-smooth");
1325 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1326 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
1327 G_CALLBACK (gpm_stats_smooth_checkbox_history_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
;
1328
1329 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_stats"
))), ((gtk_widget_get_type ()))))))
;
1330 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH"info-stats-graph-smooth");
1331 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1332 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
1333 G_CALLBACK (gpm_stats_smooth_checkbox_stats_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
;
1334
1335 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_history"
))), ((gtk_widget_get_type ()))))))
;
1336 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS"info-history-graph-points");
1337 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1338 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
1339 G_CALLBACK (gpm_stats_points_checkbox_history_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
;
1340
1341 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_stats"
))), ((gtk_widget_get_type ()))))))
;
1342 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_POINTS"info-stats-graph-points");
1343 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1344 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
1345 G_CALLBACK (gpm_stats_points_checkbox_stats_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
;
1346
1347 widget = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "notebook1"))), ((gtk_widget_get_type
()))))))
;
1348
1349 gtk_widget_add_events (widget, GDK_SCROLL_MASK);
1350 g_signal_connect (widget,g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1351 "scroll-event",g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1352 G_CALLBACK (gpm_notebook_scroll_event_cb),g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1353 NULL)g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
;
1354
1355 page = g_settings_get_int (settings, GPM_SETTINGS_INFO_PAGE_NUMBER"info-page-number");
1356 gtk_notebook_set_current_page (GTK_NOTEBOOK (widget)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_notebook_get_type ()))))))
, page);
1357 g_signal_connect (widget, "switch-page",g_signal_connect_data ((widget), ("switch-page"), (((GCallback
) (gpm_stats_notebook_changed_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
1358 G_CALLBACK (gpm_stats_notebook_changed_cb), NULL)g_signal_connect_data ((widget), ("switch-page"), (((GCallback
) (gpm_stats_notebook_changed_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
;
1359
1360 /* create list stores */
1361 list_store_info = gtk_list_store_new (GPM_INFO_COLUMN_LAST, G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2))));
1362 list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_STRING((GType) ((16) << (2))),
1363 G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2))));
1364
1365 /* create transaction_id tree view */
1366 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_info"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_info"))), ((gtk_widget_get_type
()))))))
;
1367 gtk_tree_view_set_model (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
,
1368 GTK_TREE_MODEL (list_store_info)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_info)), ((gtk_tree_model_get_type ()))))))
);
1369
1370 /* add columns to the tree view */
1371 gpm_stats_add_info_columns (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1372 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
); /* show */
1373
1374 /* create transaction_id tree view */
1375 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_devices"))), (
(gtk_widget_get_type ()))))))
;
1376 gtk_tree_view_set_model (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
,
1377 GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
);
1378 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1379 g_signal_connect (selection, "changed",g_signal_connect_data ((selection), ("changed"), (((GCallback
) (gpm_stats_devices_treeview_clicked_cb))), (((void*)0)), ((
void*)0), (GConnectFlags) 0)
1380 G_CALLBACK (gpm_stats_devices_treeview_clicked_cb), NULL)g_signal_connect_data ((selection), ("changed"), (((GCallback
) (gpm_stats_devices_treeview_clicked_cb))), (((void*)0)), ((
void*)0), (GConnectFlags) 0)
;
1381
1382 /* add columns to the tree view */
1383 gpm_stats_add_devices_columns (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1384 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
); /* show */
1385
1386 history_type_str = g_settings_get_string (settings, GPM_SETTINGS_INFO_HISTORY_TYPE"info-history-type");
1387 if ((history_type_str == NULL((void*)0)) || (strcmp (history_type_str, GPM_HISTORY_CHARGE_VALUE"charge") == 0)) {
1388 history_type = GPM_HISTORY_CHARGE_TYPE;
1389 } else if (strcmp (history_type_str, GPM_HISTORY_RATE_VALUE"rate") == 0) {
1390 history_type = GPM_HISTORY_RATE_TYPE;
1391 } else if (strcmp (history_type_str, GPM_HISTORY_TIME_FULL_VALUE"time-full") == 0) {
1392 history_type = GPM_HISTORY_TIME_FULL_TYPE;
1393 } else if (strcmp (history_type_str, GPM_HISTORY_TIME_EMPTY_VALUE"time-empty") == 0) {
1394 history_type = GPM_HISTORY_TIME_EMPTY_TYPE;
1395 } else if (strcmp (history_type_str, GPM_HISTORY_POWER_VALUE"power") == 0) {
1396 history_type = GPM_HISTORY_POWER_TYPE;
1397 } else {
1398 history_type = GPM_HISTORY_CHARGE_TYPE;
1399 }
1400 g_free (history_type_str);
1401
1402 history_time = g_settings_get_int (settings, GPM_SETTINGS_INFO_HISTORY_TIME"info-history-time");
1403 if (history_time == 0)
1404 history_time = GPM_HISTORY_HOUR_VALUE2*60*60;
1405
1406 stats_type_str = g_settings_get_string (settings, GPM_SETTINGS_INFO_STATS_TYPE"info-stats-type");
1407 if ((stats_type_str == NULL((void*)0)) || (strcmp (stats_type_str, GPM_STATS_CHARGE_DATA_VALUE"charge-data") == 0)) {
1408 stats_type = GPM_STATS_CHARGE_TYPE;
1409 } else if (strcmp (stats_type_str, GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data") == 0) {
1410 stats_type = GPM_STATS_DISCHARGE_TYPE;
1411 } else if (strcmp (stats_type_str, GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy") == 0) {
1412 stats_type = GPM_STATS_CHARGE_ACCURACY_TYPE;
1413 } else if (strcmp (stats_type_str, GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy") == 0) {
1414 stats_type = GPM_STATS_DISCHARGE_ACCURACY_TYPE;
1415 } else {
1416 stats_type = GPM_STATS_CHARGE_TYPE;
1417 }
1418 g_free (stats_type_str);
1419
1420 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_type"
))), ((gtk_widget_get_type ()))))))
;
1421 for (i = 0; i < GPM_HISTORY_LAST_TYPE - 1; i++)
1422 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, history_text[i]);
1423 if (history_type == GPM_HISTORY_RATE_TYPE)
1424 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1425 else
1426 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1427 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_history_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1428 G_CALLBACK (gpm_stats_history_type_combo_changed_cb), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_history_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1429
1430 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_stats_type"))
), ((gtk_widget_get_type ()))))))
;
1431 for (i = 0; i < GPM_STATS_LAST_TYPE; i++)
1432 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, stats_text[i]);
1433 if (stats_type == GPM_STATS_CHARGE_TYPE)
1434 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1435 else if (stats_type == GPM_STATS_CHARGE_TYPE)
1436 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1437 else if (stats_type == GPM_STATS_CHARGE_TYPE)
1438 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 2);
1439 else if (stats_type == GPM_STATS_CHARGE_TYPE)
1440 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1441 else
1442 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 3);
1443 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1444 G_CALLBACK (gpm_stats_type_combo_changed_cb), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1445
1446 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_time"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_time"
))), ((gtk_widget_get_type ()))))))
;
1447 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_MINUTE_TEXTgettext ("10 minutes"));
1448 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_HOUR_TEXTgettext ("2 hours"));
1449 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_HOURS_TEXTgettext ("6 hours"));
1450 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_DAY_TEXTgettext ("1 day"));
1451 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_WEEK_TEXTgettext ("1 week"));
1452 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1453 if (history_time == GPM_HISTORY_MINUTE_VALUE10*60)
1454 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1455 else if (history_time == GPM_HISTORY_HOUR_VALUE2*60*60)
1456 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1457 else
1458 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 2);
1459 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_range_combo_changed
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1460 G_CALLBACK (gpm_stats_range_combo_changed), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_range_combo_changed
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1461
1462 client = up_client_new ();
1463
1464 devices = up_client_get_devices2 (client);
1465
1466 /* add devices in visually pleasing order */
1467 for (j=0; j<UP_DEVICE_KIND_LAST; j++) {
1468 for (i=0; i < devices->len; i++) {
1469 device = g_ptr_array_index (devices, i)((devices)->pdata)[i];
1470 g_object_get (device, "kind", &kind, NULL((void*)0));
1471 if (kind == j)
1472 /* NULL == do not add it to ptr array */
1473 gpm_stats_add_device (device, NULL((void*)0));
1474 }
1475 }
1476
1477 /* connect now the coldplug is done */
1478 g_signal_connect (client, "device-added", G_CALLBACK (gpm_stats_device_added_cb), devices)g_signal_connect_data ((client), ("device-added"), (((GCallback
) (gpm_stats_device_added_cb))), (devices), ((void*)0), (GConnectFlags
) 0)
;
1479 g_signal_connect (client, "device-removed", G_CALLBACK (gpm_stats_device_removed_cb), devices)g_signal_connect_data ((client), ("device-removed"), (((GCallback
) (gpm_stats_device_removed_cb))), (devices), ((void*)0), (GConnectFlags
) 0)
;
1480
1481 /* set current device */
1482 if (devices->len > 0) {
1483 device = g_ptr_array_index (devices, 0)((devices)->pdata)[0];
1484 gpm_stats_update_info_data (device);
1485 current_device = g_strdup (up_device_get_object_path (device))g_strdup_inline (up_device_get_object_path (device));
1486 }
1487
1488 if (last_device == NULL((void*)0))
1489 last_device = g_settings_get_string (settings, GPM_SETTINGS_INFO_LAST_DEVICE"info-last-device");
1490
1491 /* set the correct focus on the last device */
1492 if (last_device != NULL((void*)0))
1493 gpm_stats_highlight_device (last_device);
1494
1495 /* set axis */
1496 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_type"
))), ((gtk_widget_get_type ()))))))
;
1497 gpm_stats_history_type_combo_changed_cb (widget, NULL((void*)0));
1498 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_stats_type"))
), ((gtk_widget_get_type ()))))))
;
1499 gpm_stats_type_combo_changed_cb (widget, NULL((void*)0));
1500
1501 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
Value stored to 'widget' is never read
1502
1503 status = g_application_run (G_APPLICATION (app)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((g_application_get_type ()))))))
, argc, argv);
1504 if (devices != NULL((void*)0))
1505 g_ptr_array_unref (devices);
1506
1507 g_object_unref (settings);
1508 g_object_unref (client);
1509 g_object_unref (builder);
1510 g_object_unref (list_store_info);
1511 g_object_unref (app);
1512 g_free (last_device);
1513 return status;
1514}
diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/report-6e287d.html b/2024-02-25-205630-11823-1@c406c230d131_master/report-6e287d.html new file mode 100644 index 0000000..9c18c13 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/report-6e287d.html @@ -0,0 +1,2194 @@ + + + +gpm-statistics.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:gpm-statistics.c
Warning:line 1435, column 11
expression is identical to previous condition
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gpm-statistics.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/libsecret-1 -I /usr/include/gio-unix-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/sysprof-6 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/libpng16 -I /usr/include/blkid -I /usr/include/libmount -I /usr/include/sysprof-6 -D _REENTRANT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/cloudproviders -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D I_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE -I /usr/include/libupower-glib -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/sysprof-6 -D BINDIR="/usr/local/bin" -D SBINDIR="/usr/local/sbin" -D MATELOCALEDIR="/usr/local/share/locale" -D DATADIR="/usr/local/share" -D PREFIX="/usr/local" -D SYSCONFDIR="/usr/local/etc" -D LIBDIR="/usr/local/lib" -D VERSION="1.28.0" -D GPM_ICONS_DATA="/usr/local/share/mate-power-manager/icons" -D GTKBUILDERDIR="/usr/local/share/mate-power-manager" -D UP_DISABLE_DEPRECATED -D G_LOG_DOMAIN="PowerManager" -I .. -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-25-205630-11823-1 -x c gpm-statistics.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
4 * Copyright (C) 2012-2021 MATE Developers
5 *
6 * Licensed under the GNU General Public License Version 2
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "config.h"
24
25#include <locale.h>
26
27#include <glib.h>
28#include <glib/gi18n.h>
29
30#include <gtk/gtk.h>
31#include <dbus/dbus-glib.h>
32#include <libupower-glib/upower.h>
33
34#include "egg-color.h"
35#include "egg-array-float.h"
36
37#include "gpm-common.h"
38#include "gpm-icon-names.h"
39#include "gpm-upower.h"
40#include "gpm-graph-widget.h"
41
42static GtkBuilder *builder = NULL((void*)0);
43static GtkListStore *list_store_info = NULL((void*)0);
44static GtkListStore *list_store_devices = NULL((void*)0);
45gchar *current_device = NULL((void*)0);
46static guint history_time;
47static GSettings *settings;
48static gfloat sigma_smoothing = 0.0f;
49static GtkWidget *graph_history = NULL((void*)0);
50static GtkWidget *graph_statistics = NULL((void*)0);
51
52enum {
53 GPM_INFO_COLUMN_TEXT,
54 GPM_INFO_COLUMN_VALUE,
55 GPM_INFO_COLUMN_LAST
56};
57
58enum {
59 GPM_DEVICES_COLUMN_ICON,
60 GPM_DEVICES_COLUMN_TEXT,
61 GPM_DEVICES_COLUMN_ID,
62 GPM_DEVICES_COLUMN_LAST
63};
64
65#define GPM_STATS_CHARGE_DATA_VALUE"charge-data" "charge-data"
66#define GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy" "charge-accuracy"
67#define GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data" "discharge-data"
68#define GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy" "discharge-accuracy"
69
70/* TRANSLATORS: what we've observed about the device */
71#define GPM_STATS_CHARGE_DATA_TEXTgettext ("Charge profile") _("Charge profile")gettext ("Charge profile")
72#define GPM_STATS_DISCHARGE_DATA_TEXTgettext ("Discharge profile") _("Discharge profile")gettext ("Discharge profile")
73/* TRANSLATORS: how accurately we can predict the time remaining of the battery */
74#define GPM_STATS_CHARGE_ACCURACY_TEXTgettext ("Charge accuracy") _("Charge accuracy")gettext ("Charge accuracy")
75#define GPM_STATS_DISCHARGE_ACCURACY_TEXTgettext ("Discharge accuracy") _("Discharge accuracy")gettext ("Discharge accuracy")
76
77#define GPM_HISTORY_RATE_TEXTgettext ("Rate") _("Rate")gettext ("Rate")
78#define GPM_HISTORY_CHARGE_TEXTgettext ("Charge") _("Charge")gettext ("Charge")
79#define GPM_HISTORY_TIME_FULL_TEXTgettext ("Time to full") _("Time to full")gettext ("Time to full")
80#define GPM_HISTORY_TIME_EMPTY_TEXTgettext ("Time to empty") _("Time to empty")gettext ("Time to empty")
81
82#define GPM_HISTORY_POWER_VALUE"power" "power"
83#define GPM_HISTORY_RATE_VALUE"rate" "rate"
84#define GPM_HISTORY_CHARGE_VALUE"charge" "charge"
85#define GPM_HISTORY_TIME_FULL_VALUE"time-full" "time-full"
86#define GPM_HISTORY_TIME_EMPTY_VALUE"time-empty" "time-empty"
87
88#define GPM_HISTORY_MINUTE_TEXTgettext ("10 minutes") _("10 minutes")gettext ("10 minutes")
89#define GPM_HISTORY_HOUR_TEXTgettext ("2 hours") _("2 hours")gettext ("2 hours")
90#define GPM_HISTORY_HOURS_TEXTgettext ("6 hours") _("6 hours")gettext ("6 hours")
91#define GPM_HISTORY_DAY_TEXTgettext ("1 day") _("1 day")gettext ("1 day")
92#define GPM_HISTORY_WEEK_TEXTgettext ("1 week") _("1 week")gettext ("1 week")
93
94#define GPM_HISTORY_MINUTE_VALUE10*60 10*60
95#define GPM_HISTORY_HOUR_VALUE2*60*60 2*60*60
96#define GPM_HISTORY_HOURS_VALUE6*60*60 6*60*60
97#define GPM_HISTORY_DAY_VALUE24*60*60 24*60*60
98#define GPM_HISTORY_WEEK_VALUE7*24*60*60 7*24*60*60
99
100enum stats_type_enum {
101 GPM_STATS_CHARGE_TYPE = 0,
102 GPM_STATS_DISCHARGE_TYPE,
103 GPM_STATS_CHARGE_ACCURACY_TYPE,
104 GPM_STATS_DISCHARGE_ACCURACY_TYPE,
105 GPM_STATS_LAST_TYPE
106};
107static enum stats_type_enum stats_type;
108
109enum history_type_enum {
110 GPM_HISTORY_RATE_TYPE = 0,
111 GPM_HISTORY_CHARGE_TYPE,
112 GPM_HISTORY_TIME_FULL_TYPE,
113 GPM_HISTORY_TIME_EMPTY_TYPE,
114 GPM_HISTORY_POWER_TYPE,
115 GPM_HISTORY_LAST_TYPE
116};
117static enum history_type_enum history_type;
118static const char *history_types [GPM_HISTORY_LAST_TYPE] = {
119 [GPM_HISTORY_RATE_TYPE] = GPM_HISTORY_RATE_VALUE"rate",
120 [GPM_HISTORY_CHARGE_TYPE] = GPM_HISTORY_CHARGE_VALUE"charge",
121 [GPM_HISTORY_TIME_FULL_TYPE] = GPM_HISTORY_TIME_FULL_VALUE"time-full",
122 [GPM_HISTORY_TIME_EMPTY_TYPE] = GPM_HISTORY_TIME_EMPTY_VALUE"time-empty",
123 [GPM_HISTORY_POWER_TYPE] = GPM_HISTORY_POWER_VALUE"power"
124};
125
126/**
127 * gpm_stats_button_help_cb:
128 **/
129static void
130gpm_stats_button_help_cb (GtkWidget *widget, gboolean data)
131{
132 gpm_help_display ("statistics");
133}
134
135/**
136 * gpm_stats_add_info_columns:
137 **/
138static void
139gpm_stats_add_info_columns (GtkTreeView *treeview)
140{
141 GtkCellRenderer *renderer;
142 GtkTreeViewColumn *column;
143
144 /* image */
145 renderer = gtk_cell_renderer_text_new ();
146 column = gtk_tree_view_column_new_with_attributes (_("Attribute")gettext ("Attribute"), renderer,
147 "markup", GPM_INFO_COLUMN_TEXT, NULL((void*)0));
148 gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT);
149 gtk_tree_view_append_column (treeview, column);
150
151 /* column for text */
152 renderer = gtk_cell_renderer_text_new ();
153 column = gtk_tree_view_column_new_with_attributes (_("Value")gettext ("Value"), renderer,
154 "markup", GPM_INFO_COLUMN_VALUE, NULL((void*)0));
155 gtk_tree_view_append_column (treeview, column);
156}
157
158/**
159 * gpm_stats_add_devices_columns:
160 **/
161static void
162gpm_stats_add_devices_columns (GtkTreeView *treeview)
163{
164 GtkCellRenderer *renderer;
165 GtkTreeViewColumn *column;
166
167 /* image */
168 renderer = gtk_cell_renderer_pixbuf_new ();
169 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL((void*)0));
170 column = gtk_tree_view_column_new_with_attributes (_("Image")gettext ("Image"), renderer,
171 "icon-name", GPM_DEVICES_COLUMN_ICON, NULL((void*)0));
172 gtk_tree_view_append_column (treeview, column);
173
174 /* column for text */
175 renderer = gtk_cell_renderer_text_new ();
176 column = gtk_tree_view_column_new_with_attributes (_("Description")gettext ("Description"), renderer,
177 "markup", GPM_DEVICES_COLUMN_TEXT, NULL((void*)0));
178 gtk_tree_view_column_set_sort_column_id (column, GPM_INFO_COLUMN_TEXT);
179 gtk_tree_view_append_column (treeview, column);
180 gtk_tree_view_column_set_expand (column, TRUE(!(0)));
181}
182
183/**
184 * gpm_stats_add_info_data:
185 **/
186static void
187gpm_stats_add_info_data (const gchar *attr, const gchar *text)
188{
189 GtkTreeIter iter;
190 gtk_list_store_append (list_store_info, &iter);
191 gtk_list_store_set (list_store_info, &iter,
192 GPM_INFO_COLUMN_TEXT, attr,
193 GPM_INFO_COLUMN_VALUE, text, -1);
194}
195
196/**
197 * gpm_stats_update_smooth_data:
198 **/
199static GPtrArray *
200gpm_stats_update_smooth_data (GPtrArray *list)
201{
202 guint i;
203 GpmPointObj *point;
204 GpmPointObj *point_new;
205 GPtrArray *new;
206 EggArrayFloat *raw;
207 EggArrayFloat *convolved;
208 EggArrayFloat *outliers;
209 EggArrayFloat *gaussian = NULL((void*)0);
210
211 /* convert the y data to a EggArrayFloat array */
212 raw = egg_array_float_new (list->len);
213 for (i=0; i<list->len; i++) {
214 point = (GpmPointObj *) g_ptr_array_index (list, i)((list)->pdata)[i];
215 egg_array_float_set (raw, i, point->y);
216 }
217
218 /* remove any outliers */
219 outliers = egg_array_float_remove_outliers (raw, 3, 0.1);
220
221 /* convolve with gaussian */
222 gaussian = egg_array_float_compute_gaussian (15, sigma_smoothing);
223 convolved = egg_array_float_convolve (outliers, gaussian);
224
225 /* add the smoothed data back into a new array */
226 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
227 for (i=0; i<list->len; i++) {
228 point = (GpmPointObj *) g_ptr_array_index (list, i)((list)->pdata)[i];
229 point_new = g_new0 (GpmPointObj, 1)((GpmPointObj *) g_malloc0_n ((1), sizeof (GpmPointObj)));
230 point_new->color = point->color;
231 point_new->x = point->x;
232 point_new->y = egg_array_float_get (convolved, i);
233 g_ptr_array_add (new, point_new);
234 }
235
236 /* free data */
237 egg_array_float_free (gaussian);
238 egg_array_float_free (raw);
239 egg_array_float_free (convolved);
240 egg_array_float_free (outliers);
241
242 return new;
243}
244
245/**
246 * gpm_stats_time_to_string:
247 **/
248static gchar *
249gpm_stats_time_to_string (gint seconds)
250{
251 gfloat value = seconds;
252
253 if (value < 0) {
254 /* TRANSLATORS: this is when the stats time is not known */
255 return g_strdup (_("Unknown"))g_strdup_inline (gettext ("Unknown"));
256 }
257 if (value < 60) {
258 /* TRANSLATORS: this is a time value, usually to show on a graph */
259 return g_strdup_printf (ngettext ("%.0f second", "%.0f seconds", value), value);
260 }
261 value /= 60.0;
262 if (value < 60) {
263 /* TRANSLATORS: this is a time value, usually to show on a graph */
264 return g_strdup_printf (ngettext ("%.1f minute", "%.1f minutes", value), value);
265 }
266 value /= 60.0;
267 if (value < 60) {
268 /* TRANSLATORS: this is a time value, usually to show on a graph */
269 return g_strdup_printf (ngettext ("%.1f hour", "%.1f hours", value), value);
270 }
271 value /= 24.0;
272 /* TRANSLATORS: this is a time value, usually to show on a graph */
273 return g_strdup_printf (ngettext ("%.1f day", "%.1f days", value), value);
274}
275
276/**
277 * gpm_stats_bool_to_string:
278 **/
279static const gchar *
280gpm_stats_bool_to_string (gboolean ret)
281{
282 return ret ? _("Yes")gettext ("Yes") : _("No")gettext ("No");
283}
284
285/**
286 * gpm_stats_get_printable_device_path:
287 **/
288static gchar *
289gpm_stats_get_printable_device_path (UpDevice *device)
290{
291 const gchar *object_path;
292 gchar *device_path = NULL((void*)0);
293
294 /* get object path */
295 object_path = up_device_get_object_path (device);
296 if (object_path != NULL((void*)0))
297 device_path = g_filename_display_basename (object_path);
298
299 return device_path;
300}
301
302/**
303 * gpm_stats_update_info_page_details:
304 **/
305static void
306gpm_stats_update_info_page_details (UpDevice *device)
307{
308 struct tm *time_tm;
309 time_t t;
310 gchar time_buf[256];
311 gchar *text;
312 guint refreshed;
313 UpDeviceKind kind;
314 UpDeviceState state;
315 UpDeviceTechnology technology;
316 gdouble percentage;
317 gdouble capacity;
318 gdouble energy;
319 gdouble energy_empty;
320 gdouble energy_full;
321 gdouble energy_full_design;
322 gdouble energy_rate;
323 gdouble voltage;
324 gboolean online;
325 gboolean is_present;
326 gboolean power_supply;
327 gboolean is_rechargeable;
328 guint64 update_time;
329 gint64 time_to_full;
330 gint64 time_to_empty;
331 gchar *vendor = NULL((void*)0);
332 gchar *serial = NULL((void*)0);
333 gchar *model = NULL((void*)0);
334 gchar *device_path = NULL((void*)0);
335
336 gtk_list_store_clear (list_store_info);
337
338 /* get device properties */
339 g_object_get (device,
340 "kind", &kind,
341 "state", &state,
342 "percentage", &percentage,
343 "online", &online,
344 "update_time", &update_time,
345 "power_supply", &power_supply,
346 "is_rechargeable", &is_rechargeable,
347 "is-present", &is_present,
348 "time-to-full", &time_to_full,
349 "time-to-empty", &time_to_empty,
350 "technology", &technology,
351 "capacity", &capacity,
352 "energy", &energy,
353 "energy-empty", &energy_empty,
354 "energy-full", &energy_full,
355 "energy-full-design", &energy_full_design,
356 "energy-rate", &energy_rate,
357 "voltage", &voltage,
358 "vendor", &vendor,
359 "serial", &serial,
360 "model", &model,
361 NULL((void*)0));
362
363 /* get a human readable time */
364 t = (time_t) update_time;
365 time_tm = localtime (&t);
366 strftime (time_buf, sizeof time_buf, "%c", time_tm);
367
368 /* remove prefix */
369 device_path = gpm_stats_get_printable_device_path (device);
370 /* TRANSLATORS: the device ID of the current device, e.g. "battery0" */
371 gpm_stats_add_info_data (_("Device")gettext ("Device"), device_path);
372 g_free (device_path);
373
374 gpm_stats_add_info_data (_("Type")gettext ("Type"), gpm_device_kind_to_localised_string (kind, 1));
375 if (vendor != NULL((void*)0) && vendor[0] != '\0')
376 gpm_stats_add_info_data (_("Vendor")gettext ("Vendor"), vendor);
377 if (model != NULL((void*)0) && model[0] != '\0')
378 gpm_stats_add_info_data (_("Model")gettext ("Model"), model);
379 if (serial != NULL((void*)0) && serial[0] != '\0')
380 gpm_stats_add_info_data (_("Serial number")gettext ("Serial number"), serial);
381
382 /* TRANSLATORS: a boolean attribute that means if the device is supplying the
383 * main power for the computer. For instance, an AC adapter or laptop battery
384 * would be TRUE, but a mobile phone or mouse taking power is FALSE */
385 gpm_stats_add_info_data (_("Supply")gettext ("Supply"), gpm_stats_bool_to_string (power_supply));
386
387 refreshed = (int) (time (NULL((void*)0)) - update_time);
388 text = g_strdup_printf (ngettext ("%u second", "%u seconds", refreshed), refreshed);
389
390 /* TRANSLATORS: when the device was last updated with new data. It's
391 * usually a few seconds when a device is discharging or charging. */
392 gpm_stats_add_info_data (_("Refreshed")gettext ("Refreshed"), text);
393 g_free (text);
394
395 if (kind == UP_DEVICE_KIND_BATTERY ||
396 kind == UP_DEVICE_KIND_MOUSE ||
397 kind == UP_DEVICE_KIND_KEYBOARD ||
398 kind == UP_DEVICE_KIND_UPS) {
399 /* TRANSLATORS: Present is whether the device is currently attached
400 * to the computer, as some devices (e.g. laptop batteries) can
401 * be removed, but still observed as devices on the system */
402 gpm_stats_add_info_data (_("Present")gettext ("Present"), gpm_stats_bool_to_string (is_present));
403 }
404 if (kind == UP_DEVICE_KIND_BATTERY ||
405 kind == UP_DEVICE_KIND_MOUSE ||
406 kind == UP_DEVICE_KIND_KEYBOARD) {
407 /* TRANSLATORS: If the device can be recharged, e.g. lithium
408 * batteries rather than alkaline ones */
409 gpm_stats_add_info_data (_("Rechargeable")gettext ("Rechargeable"), gpm_stats_bool_to_string (is_rechargeable));
410 }
411 if (kind == UP_DEVICE_KIND_BATTERY ||
412 kind == UP_DEVICE_KIND_MOUSE ||
413 kind == UP_DEVICE_KIND_KEYBOARD) {
414 /* TRANSLATORS: The state of the device, e.g. "Changing" or "Fully charged" */
415 gpm_stats_add_info_data (_("State")gettext ("State"), gpm_device_state_to_localised_string (state));
416 }
417 if (kind == UP_DEVICE_KIND_BATTERY) {
418 text = g_strdup_printf ("%.1f Wh", energy);
419 gpm_stats_add_info_data (_("Energy")gettext ("Energy"), text);
420 g_free (text);
421 text = g_strdup_printf ("%.1f Wh", energy_empty);
422 gpm_stats_add_info_data (_("Energy when empty")gettext ("Energy when empty"), text);
423 g_free (text);
424 text = g_strdup_printf ("%.1f Wh", energy_full);
425 gpm_stats_add_info_data (_("Energy when full")gettext ("Energy when full"), text);
426 g_free (text);
427 text = g_strdup_printf ("%.1f Wh", energy_full_design);
428 gpm_stats_add_info_data (_("Energy (design)")gettext ("Energy (design)"), text);
429 g_free (text);
430 }
431 if (kind == UP_DEVICE_KIND_BATTERY ||
432 kind == UP_DEVICE_KIND_MONITOR) {
433 text = g_strdup_printf ("%.1f W", energy_rate);
434 /* TRANSLATORS: the rate of discharge for the device */
435 gpm_stats_add_info_data (_("Rate")gettext ("Rate"), text);
436 g_free (text);
437 }
438 if (kind == UP_DEVICE_KIND_UPS ||
439 kind == UP_DEVICE_KIND_BATTERY ||
440 kind == UP_DEVICE_KIND_MONITOR) {
441 text = g_strdup_printf ("%.1f V", voltage);
442 gpm_stats_add_info_data (_("Voltage")gettext ("Voltage"), text);
443 g_free (text);
444 }
445 if (kind == UP_DEVICE_KIND_BATTERY ||
446 kind == UP_DEVICE_KIND_UPS) {
447 if (time_to_full >= 0) {
448 text = gpm_stats_time_to_string (time_to_full);
449 gpm_stats_add_info_data (_("Time to full")gettext ("Time to full"), text);
450 g_free (text);
451 }
452 if (time_to_empty >= 0) {
453 text = gpm_stats_time_to_string (time_to_empty);
454 gpm_stats_add_info_data (_("Time to empty")gettext ("Time to empty"), text);
455 g_free (text);
456 }
457 }
458 if (kind == UP_DEVICE_KIND_BATTERY ||
459 kind == UP_DEVICE_KIND_MOUSE ||
460 kind == UP_DEVICE_KIND_KEYBOARD ||
461 kind == UP_DEVICE_KIND_UPS) {
462 text = g_strdup_printf ("%.1f%%", percentage);
463 /* TRANSLATORS: the amount of charge the cell contains */
464 gpm_stats_add_info_data (_("Percentage")gettext ("Percentage"), text);
465 g_free (text);
466 }
467 if (kind == UP_DEVICE_KIND_BATTERY) {
468 text = g_strdup_printf ("%.1f%%", capacity);
469 /* TRANSLATORS: the capacity of the device, which is basically a measure
470 * of how full it can get, relative to the design capacity */
471 gpm_stats_add_info_data (_("Capacity")gettext ("Capacity"), text);
472 g_free (text);
473 }
474 if (kind == UP_DEVICE_KIND_BATTERY) {
475 /* TRANSLATORS: the type of battery, e.g. lithium or nikel metal hydroxide */
476 gpm_stats_add_info_data (_("Technology")gettext ("Technology"), gpm_device_technology_to_localised_string (technology));
477 }
478 if (kind == UP_DEVICE_KIND_LINE_POWER) {
479 /* TRANSLATORS: this is when the device is plugged in, typically
480 * only shown for the ac adaptor device */
481 gpm_stats_add_info_data (_("Online")gettext ("Online"), gpm_stats_bool_to_string (online));
482 }
483
484 g_free (vendor);
485 g_free (serial);
486 g_free (model);
487}
488
489/**
490 * gpm_stats_set_graph_data:
491 **/
492static void
493gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoothed, gboolean use_points)
494{
495 GPtrArray *smoothed;
496
497 gpm_graph_widget_data_clear (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
);
498
499 /* add correct data */
500 if (!use_smoothed) {
501 if (use_points)
502 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_BOTH, data);
503 else
504 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_LINE, data);
505 } else {
506 smoothed = gpm_stats_update_smooth_data (data);
507 if (use_points)
508 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_POINTS, data);
509 gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget)((((GpmGraphWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gpm_graph_widget_get_type ()))))))
, GPM_GRAPH_WIDGET_PLOT_LINE, smoothed);
510 g_ptr_array_unref (smoothed);
511 }
512
513 /* show */
514 gtk_widget_show (widget);
515}
516
517/**
518 * gpm_stats_update_info_page_history:
519 **/
520static void
521gpm_stats_update_info_page_history (UpDevice *device)
522{
523 GPtrArray *array;
524 guint i;
525 UpHistoryItem *item;
526 GtkWidget *widget;
527 gboolean checked;
528 gboolean points;
529 GpmPointObj *point;
530 GPtrArray *new;
531 gint32 offset;
532
533 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
534 if (history_type == GPM_HISTORY_CHARGE_TYPE) {
535 g_object_set (graph_history,
536 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
537 "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
538 "autorange-x", FALSE(0),
539 "start-x", -history_time,
540 "stop-x", 0,
541 "autorange-y", FALSE(0),
542 "start-y", 0,
543 "stop-y", 100,
544 NULL((void*)0));
545 } else if (history_type == GPM_HISTORY_RATE_TYPE) {
546 g_object_set (graph_history,
547 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
548 "type-y", GPM_GRAPH_WIDGET_TYPE_POWER,
549 "autorange-x", FALSE(0),
550 "start-x", -history_time,
551 "stop-x", 0,
552 "autorange-y", TRUE(!(0)),
553 NULL((void*)0));
554 } else {
555 g_object_set (graph_history,
556 "type-x", GPM_GRAPH_WIDGET_TYPE_TIME,
557 "type-y", GPM_GRAPH_WIDGET_TYPE_TIME,
558 "autorange-x", FALSE(0),
559 "start-x", -history_time,
560 "stop-x", 0,
561 "autorange-y", TRUE(!(0)),
562 NULL((void*)0));
563 }
564
565 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_history_nodata"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_history_nodata")
)), ((gtk_widget_get_type ()))))))
;
566 /* The type of history, history_types [history_type], known values are "rate" and "charge". */
567 array = up_device_get_history_sync (device, history_types [history_type], history_time, 150, NULL((void*)0), NULL((void*)0));
568 if (array == NULL((void*)0)) {
569 /* show no data label and hide graph */
570 gtk_widget_hide (graph_history);
571 gtk_widget_show (widget);
572 goto out;
573 }
574
575 /* hide no data and show graph */
576 gtk_widget_hide (widget);
577 gtk_widget_show (graph_history);
578
579 offset = (gint32) (g_get_real_time () / G_USEC_PER_SEC1000000);
580
581 for (i=0; i<array->len; i++) {
582 item = (UpHistoryItem *) g_ptr_array_index (array, i)((array)->pdata)[i];
583
584 /* abandon this point */
585 if (up_history_item_get_state (item) == UP_DEVICE_STATE_UNKNOWN)
586 continue;
587
588 point = gpm_point_obj_new ();
589 point->x = ((gint32) up_history_item_get_time (item)) - offset;
590 point->y = up_history_item_get_value (item);
591 if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
592 point->color = egg_color_from_rgb (255, 0, 0);
593 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
594 point->color = egg_color_from_rgb (0, 0, 255);
595 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
596 point->color = egg_color_from_rgb (200, 0, 0);
597 else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
598 point->color = egg_color_from_rgb (0, 0, 200);
599 else {
600 if (history_type == GPM_HISTORY_RATE_TYPE)
601 point->color = egg_color_from_rgb (255, 255, 255);
602 else
603 point->color = egg_color_from_rgb (0, 255, 0);
604 }
605 g_ptr_array_add (new, point);
606 }
607
608 /* render */
609 sigma_smoothing = 2.0;
610 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_history"
))), ((gtk_widget_get_type ()))))))
;
611 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
612 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_history"
))), ((gtk_widget_get_type ()))))))
;
613 points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
614
615 /* present data to graph */
616 gpm_stats_set_graph_data (graph_history, new, checked, points);
617
618 g_ptr_array_unref (array);
619 g_ptr_array_unref (new);
620out:
621 return;
622}
623
624/**
625 * gpm_stats_update_info_page_stats:
626 **/
627static void
628gpm_stats_update_info_page_stats (UpDevice *device)
629{
630 GPtrArray *array;
631 guint i;
632 UpStatsItem *item;
633 GtkWidget *widget;
634 gboolean checked;
635 gboolean points;
636 GpmPointObj *point;
637 GPtrArray *new;
638 gboolean use_data = FALSE(0);
639 const gchar *type = NULL((void*)0);
640
641 new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
642 if (stats_type == GPM_STATS_CHARGE_TYPE) {
643 type = "charging";
644 use_data = TRUE(!(0));
645 } else if (stats_type == GPM_STATS_DISCHARGE_TYPE) {
646 type = "discharging";
647 use_data = TRUE(!(0));
648 } else if (stats_type == GPM_STATS_CHARGE_ACCURACY_TYPE) {
649 type = "charging";
650 use_data = FALSE(0);
651 } else if (stats_type == GPM_STATS_DISCHARGE_ACCURACY_TYPE) {
652 type = "discharging";
653 use_data = FALSE(0);
654 } else {
655 g_assert_not_reached ()do { g_assertion_message_expr ("PowerManager", "gpm-statistics.c"
, 655, ((const char*) (__func__)), ((void*)0)); } while (0)
;
656 }
657
658 if (use_data) {
659 g_object_set (graph_statistics,
660 "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
661 "type-y", GPM_GRAPH_WIDGET_TYPE_FACTOR,
662 "autorange-x", TRUE(!(0)),
663 "autorange-y", TRUE(!(0)),
664 NULL((void*)0));
665 } else {
666 g_object_set (graph_statistics,
667 "type-x", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
668 "type-y", GPM_GRAPH_WIDGET_TYPE_PERCENTAGE,
669 "autorange-x", TRUE(!(0)),
670 "autorange-y", TRUE(!(0)),
671 NULL((void*)0));
672 }
673
674 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_stats_nodata"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_stats_nodata")))
, ((gtk_widget_get_type ()))))))
;
675 array = up_device_get_statistics_sync (device, type, NULL((void*)0), NULL((void*)0));
676 if (array == NULL((void*)0)) {
677 /* show no data label and hide graph */
678 gtk_widget_hide (graph_statistics);
679 gtk_widget_show (widget);
680 goto out;
681 }
682
683 /* hide no data and show graph */
684 gtk_widget_hide (widget);
685 gtk_widget_show (graph_statistics);
686
687 for (i=0; i<array->len; i++) {
688 item = (UpStatsItem *) g_ptr_array_index (array, i)((array)->pdata)[i];
689 point = gpm_point_obj_new ();
690 point->x = i;
691 if (use_data)
692 point->y = up_stats_item_get_value (item);
693 else
694 point->y = up_stats_item_get_accuracy (item);
695 point->color = egg_color_from_rgb (255, 0, 0);
696 g_ptr_array_add (new, point);
697 }
698
699 /* render */
700 sigma_smoothing = 1.1;
701 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_stats"
))), ((gtk_widget_get_type ()))))))
;
702 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
703 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_stats"
))), ((gtk_widget_get_type ()))))))
;
704 points = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
705
706 /* present data to graph */
707 gpm_stats_set_graph_data (graph_statistics, new, checked, points);
708
709 g_ptr_array_unref (array);
710 g_ptr_array_unref (new);
711out:
712 return;
713}
714
715/**
716 * gpm_stats_update_info_data_page:
717 **/
718static void
719gpm_stats_update_info_data_page (UpDevice *device, gint page)
720{
721 if (page == 0)
722 gpm_stats_update_info_page_details (device);
723 else if (page == 1)
724 gpm_stats_update_info_page_history (device);
725 else if (page == 2)
726 gpm_stats_update_info_page_stats (device);
727}
728
729/**
730 * gpm_stats_update_info_data:
731 **/
732static void
733gpm_stats_update_info_data (UpDevice *device)
734{
735 gint page;
736 GtkNotebook *notebook;
737 GtkWidget *page_widget;
738 gboolean has_history;
739 gboolean has_statistics;
740
741 /* get properties */
742 g_object_get (device,
743 "has-history", &has_history,
744 "has-statistics", &has_statistics,
745 NULL((void*)0));
746
747 notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1"))((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "notebook1"))), ((gtk_notebook_get_type
()))))))
;
748
749 /* show info page */
750 page_widget = gtk_notebook_get_nth_page (notebook, 0);
751 gtk_widget_show (page_widget);
752
753 /* hide history if no support */
754 page_widget = gtk_notebook_get_nth_page (notebook, 1);
755 if (has_history)
756 gtk_widget_show (page_widget);
757 else
758 gtk_widget_hide (page_widget);
759
760 /* hide statistics if no support */
761 page_widget = gtk_notebook_get_nth_page (notebook, 2);
762 if (has_statistics)
763 gtk_widget_show (page_widget);
764 else
765 gtk_widget_hide (page_widget);
766
767 page = gtk_notebook_get_current_page (notebook);
768 gpm_stats_update_info_data_page (device, page);
769
770 return;
771}
772
773static void
774gpm_stats_set_title (GtkWindow *window, gint page_num)
775{
776 gchar *title;
777 const gchar * const page_titles[] = {
778 /* TRANSLATORS: shown on the titlebar */
779 N_("Device Information")("Device Information"),
780 /* TRANSLATORS: shown on the titlebar */
781 N_("Device History")("Device History"),
782 /* TRANSLATORS: shown on the titlebar */
783 N_("Device Profile")("Device Profile"),
784 };
785
786 /* TRANSLATORS: shown on the titlebar */
787 title = g_strdup_printf ("%s - %s", _("Power Statistics")gettext ("Power Statistics"), _(page_titles[page_num])gettext (page_titles[page_num]));
788 gtk_window_set_title (window, title);
789 g_free (title);
790}
791
792/**
793 * gpm_stats_notebook_changed_cb:
794 **/
795static void
796gpm_stats_notebook_changed_cb (GtkNotebook *notebook, gpointer page, gint page_num, gpointer user_data)
797{
798 UpDevice *device;
799 GtkWidget *widget;
800
801 /* set the window title depending on the mode */
802 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
803 gpm_stats_set_title (GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
, page_num);
804
805 /* save page in gsettings */
806 g_settings_set_int (settings, GPM_SETTINGS_INFO_PAGE_NUMBER"info-page-number", page_num);
807
808 if (current_device == NULL((void*)0))
809 return;
810
811 device = up_device_new ();
812 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
813 gpm_stats_update_info_data_page (device, page_num);
814 gpm_stats_update_info_data (device);
815 g_object_unref (device);
816}
817
818/**
819 * gpm_stats_button_update_ui:
820 **/
821static void
822gpm_stats_button_update_ui (void)
823{
824 UpDevice *device;
825
826 if (current_device == NULL((void*)0))
827 return;
828
829 device = up_device_new ();
830 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
831 gpm_stats_update_info_data (device);
832 g_object_unref (device);
833}
834
835/**
836 * gpm_stats_devices_treeview_clicked_cb:
837 **/
838static void
839gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data)
840{
841 GtkTreeModel *model;
842 GtkTreeIter iter;
843 UpDevice *device;
844
845 /* This will only work in single or browse selection mode! */
846 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
847 g_free (current_device);
848 gtk_tree_model_get (model, &iter, GPM_DEVICES_COLUMN_ID, &current_device, -1);
849
850 /* save device in gsettings */
851 g_settings_set_string (settings, GPM_SETTINGS_INFO_LAST_DEVICE"info-last-device", current_device);
852
853 /* show transaction_id */
854 g_debug ("selected row is: %s", current_device);
855
856 /* is special device */
857 device = up_device_new ();
858 up_device_set_object_path_sync (device, current_device, NULL((void*)0), NULL((void*)0));
859 gpm_stats_update_info_data (device);
860 g_object_unref (device);
861
862 } else {
863 g_debug ("no row selected");
864 }
865}
866
867/**
868 * gpm_stats_window_activated_cb
869 **/
870static void
871gpm_stats_window_activated_cb (GtkApplication *app, gpointer data)
872{
873 GtkWidget *widget;
874 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
875 gtk_application_add_window (GTK_APPLICATION (app)((((GtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((gtk_application_get_type ()))))))
, GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
);
876 gtk_window_present (GTK_WINDOW (widget)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_window_get_type ()))))))
);
877}
878
879/**
880 * gpm_stats_device_changed_cb:
881 **/
882static void
883gpm_stats_device_changed_cb (UpDevice *device, GParamSpec *pspec, gpointer user_data)
884{
885 const gchar *object_path;
886 object_path = up_device_get_object_path (device);
887 if (object_path == NULL((void*)0) || current_device == NULL((void*)0))
888 return;
889 g_debug ("changed: %s", object_path);
890 if (g_strcmp0 (current_device, object_path) == 0)
891 gpm_stats_update_info_data (device);
892}
893
894/**
895 * gpm_stats_add_device:
896 **/
897static void
898gpm_stats_add_device (UpDevice *device, GPtrArray *devices)
899{
900 const gchar *id;
901 GtkTreeIter iter;
902 char *icon;
903 UpDeviceKind kind;
904 gchar *label, *vendor, *model;
905
906 if (devices != NULL((void*)0))
907 g_ptr_array_add (devices, device);
908
909 g_signal_connect (device, "notify",g_signal_connect_data ((device), ("notify"), (((GCallback) (gpm_stats_device_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
910 G_CALLBACK (gpm_stats_device_changed_cb), NULL)g_signal_connect_data ((device), ("notify"), (((GCallback) (gpm_stats_device_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
911
912 /* get device properties */
913 g_object_get (device,
914 "kind", &kind,
915 "vendor", &vendor,
916 "model", &model,
917 NULL((void*)0));
918
919 id = up_device_get_object_path (device);
920 if ((vendor != NULL((void*)0) && strlen(vendor) != 0) && (model != NULL((void*)0) && strlen(model) != 0)) {
921 label = g_strdup_printf ("%s %s", vendor, model);
922 }
923 else if((vendor == NULL((void*)0) || strlen(vendor) == 0) && (model != NULL((void*)0) && strlen(model) != 0)) {
924 label = g_strdup_printf ("%s", model);
925 }
926 else {
927 label = g_strdup_printf ("%s", gpm_device_kind_to_localised_string (kind, 1));
928 }
929 icon = gpm_upower_get_device_icon (device);
930
931 gtk_list_store_append (list_store_devices, &iter);
932 gtk_list_store_set (list_store_devices, &iter,
933 GPM_DEVICES_COLUMN_ID, id,
934 GPM_DEVICES_COLUMN_TEXT, label,
935 GPM_DEVICES_COLUMN_ICON, icon, -1);
936 g_free (icon);
937 g_free (label);
938 g_free (vendor);
939 g_free (model);
940}
941
942/**
943 * gpm_stats_device_added_cb:
944 **/
945static void
946gpm_stats_device_added_cb (UpClient *client, UpDevice *device, GPtrArray *devices)
947{
948 const gchar *object_path;
949 object_path = up_device_get_object_path (device);
950 g_debug ("added: %s", object_path);
951
952 gpm_stats_add_device (device, devices);
953}
954
955/**
956 * gpm_stats_device_removed_cb:
957 **/
958static void
959gpm_stats_device_removed_cb (UpClient *client, const gchar *object_path, GPtrArray *devices)
960{
961 GtkTreeIter iter;
962 gchar *id = NULL((void*)0);
963 gboolean ret;
964
965 UpDevice *device_tmp;
966 guint i;
967
968 for (i = 0; i < devices->len; i++) {
969 device_tmp = g_ptr_array_index (devices, i)((devices)->pdata)[i];
970 if (g_strcmp0 (up_device_get_object_path (device_tmp), object_path) == 0) {
971 g_ptr_array_remove_index_fast (devices, i);
972 break;
973 }
974 }
975 g_debug ("removed: %s", object_path);
976 if (g_strcmp0 (current_device, object_path) == 0) {
977 gtk_list_store_clear (list_store_info);
978 }
979
980 /* search the list and remove the object path entry */
981 ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
982 while (ret) {
983 gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter, GPM_DEVICES_COLUMN_ID, &id, -1);
984 if (g_strcmp0 (id, object_path) == 0) {
985 gtk_list_store_remove (list_store_devices, &iter);
986 break;
987 }
988 g_free (id);
989 ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
990 };
991}
992
993/**
994 * gpm_stats_history_type_combo_changed_cb:
995 **/
996static void
997gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
998{
999 guint active;
1000 const gchar *axis_x = NULL((void*)0);
1001 const gchar *axis_y = NULL((void*)0);
1002
1003 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1004
1005 if (active == 0) {
1006 history_type = GPM_HISTORY_RATE_TYPE;
1007 /* TRANSLATORS: this is the X axis on the graph */
1008 axis_x = _("Time elapsed")gettext ("Time elapsed");
1009 /* TRANSLATORS: this is the Y axis on the graph */
1010 axis_y = _("Power")gettext ("Power");
1011 } else if (active == 1) {
1012 history_type = GPM_HISTORY_CHARGE_TYPE;
1013 /* TRANSLATORS: this is the X axis on the graph */
1014 axis_x = _("Time elapsed")gettext ("Time elapsed");
1015 /* TRANSLATORS: this is the Y axis on the graph for the whole battery device */
1016 axis_y = _("Cell charge")gettext ("Cell charge");
1017 } else if (active == 2) {
1018 history_type = GPM_HISTORY_TIME_FULL_TYPE;
1019 /* TRANSLATORS: this is the X axis on the graph */
1020 axis_x = _("Time elapsed")gettext ("Time elapsed");
1021 /* TRANSLATORS: this is the Y axis on the graph */
1022 axis_y = _("Predicted time")gettext ("Predicted time");
1023 } else if (active == 3) {
1024 history_type = GPM_HISTORY_TIME_EMPTY_TYPE;
1025 /* TRANSLATORS: this is the X axis on the graph */
1026 axis_x = _("Time elapsed")gettext ("Time elapsed");
1027 /* TRANSLATORS: this is the Y axis on the graph */
1028 axis_y = _("Predicted time")gettext ("Predicted time");
1029 } else {
1030 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1030, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1031 }
1032
1033 /* set axis */
1034 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_x"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_history_x")
)), ((gtk_widget_get_type ()))))))
;
1035 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_x);
1036 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_history_y"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_history_y")
)), ((gtk_widget_get_type ()))))))
;
1037 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_y);
1038
1039 gpm_stats_button_update_ui ();
1040
1041 /* save to gsettings */
1042 g_settings_set_string (settings, GPM_SETTINGS_INFO_HISTORY_TYPE"info-history-type", history_types [history_type]);
1043}
1044
1045/**
1046 * gpm_stats_type_combo_changed_cb:
1047 **/
1048static void
1049gpm_stats_type_combo_changed_cb (GtkWidget *widget, gpointer data)
1050{
1051 guint active;
1052 const gchar *axis_x = NULL((void*)0);
1053 const gchar *axis_y = NULL((void*)0);
1054 const char *stats_types [GPM_STATS_LAST_TYPE] = {
1055 [GPM_STATS_CHARGE_TYPE] = GPM_STATS_CHARGE_DATA_VALUE"charge-data",
1056 [GPM_STATS_DISCHARGE_TYPE] = GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy",
1057 [GPM_STATS_CHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data",
1058 [GPM_STATS_DISCHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy"
1059 };
1060
1061 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1062
1063 if (active == 0) {
1064 stats_type = GPM_STATS_CHARGE_TYPE;
1065 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1066 axis_x = _("Cell charge")gettext ("Cell charge");
1067 /* TRANSLATORS: this is the Y axis on the graph */
1068 axis_y = _("Correction factor")gettext ("Correction factor");
1069 } else if (active == 1) {
1070 stats_type = GPM_STATS_CHARGE_ACCURACY_TYPE;
1071 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1072 axis_x = _("Cell charge")gettext ("Cell charge");
1073 /* TRANSLATORS: this is the Y axis on the graph */
1074 axis_y = _("Prediction accuracy")gettext ("Prediction accuracy");
1075 } else if (active == 2) {
1076 stats_type = GPM_STATS_DISCHARGE_TYPE;
1077 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1078 axis_x = _("Cell charge")gettext ("Cell charge");
1079 /* TRANSLATORS: this is the Y axis on the graph */
1080 axis_y = _("Correction factor")gettext ("Correction factor");
1081 } else if (active == 3) {
1082 stats_type = GPM_STATS_DISCHARGE_ACCURACY_TYPE;
1083 /* TRANSLATORS: this is the X axis on the graph for the whole battery device */
1084 axis_x = _("Cell charge")gettext ("Cell charge");
1085 /* TRANSLATORS: this is the Y axis on the graph */
1086 axis_y = _("Prediction accuracy")gettext ("Prediction accuracy");
1087 } else {
1088 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1088, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1089 }
1090
1091 /* set axis */
1092 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_x"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_stats_x")))
, ((gtk_widget_get_type ()))))))
;
1093 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_x);
1094 widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_axis_stats_y"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "label_axis_stats_y")))
, ((gtk_widget_get_type ()))))))
;
1095 gtk_label_set_label (GTK_LABEL(widget)((((GtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_label_get_type ()))))))
, axis_y);
1096
1097 gpm_stats_button_update_ui ();
1098
1099 /* save to gsettings */
1100 g_settings_set_string (settings, GPM_SETTINGS_INFO_STATS_TYPE"info-stats-type", stats_types[stats_type]);
1101}
1102
1103/**
1104 * gpm_stats_range_combo_changed:
1105 **/
1106static void
1107gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data)
1108{
1109 guint active;
1110
1111 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
);
1112
1113 if (active == 0)
1114 history_time = GPM_HISTORY_MINUTE_VALUE10*60;
1115 else if (active == 1)
1116 history_time = GPM_HISTORY_HOUR_VALUE2*60*60;
1117 else if (active == 2)
1118 history_time = GPM_HISTORY_HOURS_VALUE6*60*60;
1119 else if (active == 3)
1120 history_time = GPM_HISTORY_DAY_VALUE24*60*60;
1121 else if (active == 4)
1122 history_time = GPM_HISTORY_WEEK_VALUE7*24*60*60;
1123 else
1124 g_assert (FALSE)do { if ((0)) ; else g_assertion_message_expr ("PowerManager"
, "gpm-statistics.c", 1124, ((const char*) (__func__)), "FALSE"
); } while (0)
;
1125
1126 /* save to gsettings */
1127 g_settings_set_int (settings, GPM_SETTINGS_INFO_HISTORY_TIME"info-history-time", history_time);
1128
1129 gpm_stats_button_update_ui ();
1130}
1131
1132/**
1133 * gpm_stats_smooth_checkbox_history_cb:
1134 * @widget: The GtkWidget object
1135 **/
1136static void
1137gpm_stats_smooth_checkbox_history_cb (GtkWidget *widget, gpointer data)
1138{
1139 gboolean checked;
1140 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1141 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH"info-history-graph-smooth", checked);
1142 gpm_stats_button_update_ui ();
1143}
1144
1145/**
1146 * gpm_stats_smooth_checkbox_stats_cb:
1147 * @widget: The GtkWidget object
1148 **/
1149static void
1150gpm_stats_smooth_checkbox_stats_cb (GtkWidget *widget, gpointer data)
1151{
1152 gboolean checked;
1153 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1154 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH"info-stats-graph-smooth", checked);
1155 gpm_stats_button_update_ui ();
1156}
1157
1158/**
1159 * gpm_stats_points_checkbox_history_cb:
1160 * @widget: The GtkWidget object
1161 **/
1162static void
1163gpm_stats_points_checkbox_history_cb (GtkWidget *widget, gpointer data)
1164{
1165 gboolean checked;
1166 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1167 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS"info-history-graph-points", checked);
1168 gpm_stats_button_update_ui ();
1169}
1170
1171/**
1172 * gpm_stats_points_checkbox_stats_cb:
1173 * @widget: The GtkWidget object
1174 **/
1175static void
1176gpm_stats_points_checkbox_stats_cb (GtkWidget *widget, gpointer data)
1177{
1178 gboolean checked;
1179 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
);
1180 g_settings_set_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_POINTS"info-stats-graph-points", checked);
1181 gpm_stats_button_update_ui ();
1182}
1183
1184/**
1185 * gpm_stats_highlight_device:
1186 **/
1187static void
1188gpm_stats_highlight_device (const gchar *object_path)
1189{
1190 gboolean ret;
1191 gchar *id = NULL((void*)0);
1192 gchar *path_str;
1193 guint i;
1194 GtkTreeIter iter;
1195 GtkTreePath *path;
1196 GtkWidget *widget;
1197
1198 /* check valid */
1199 if (!g_str_has_prefix (object_path, "/")(__builtin_constant_p ("/")? __extension__ ({ const char * const
__str = (object_path); const char * const __prefix = ("/"); gboolean
__result = (0); if (__str == ((void*)0) || __prefix == ((void
*)0)) __result = (g_str_has_prefix) (__str, __prefix); else {
const size_t __str_len = strlen (((__str) + !(__str))); const
size_t __prefix_len = strlen (((__prefix) + !(__prefix))); if
(__str_len >= __prefix_len) __result = memcmp (((__str) +
!(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0; }
__result; }) : (g_str_has_prefix) (object_path, "/") )
)
1200 return;
1201
1202 /* we have to reuse the treeview data as it may be sorted */
1203 ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
1204 for (i=0; ret; i++) {
1205 gtk_tree_model_get (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter,
1206 GPM_DEVICES_COLUMN_ID, &id,
1207 -1);
1208 if (g_strcmp0 (id, object_path) == 0) {
1209 path_str = g_strdup_printf ("%u", i);
1210 path = gtk_tree_path_new_from_string (path_str);
1211 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_devices"))), (
(gtk_widget_get_type ()))))))
;
1212 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
, path, NULL((void*)0), NULL((void*)0), FALSE(0));
1213 g_free (path_str);
1214 gtk_tree_path_free (path);
1215 }
1216 g_free (id);
1217 ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
, &iter);
1218 }
1219}
1220
1221/**
1222 * main:
1223 **/
1224int
1225main (int argc, char *argv[])
1226{
1227 GOptionContext *context;
1228 GtkBox *box;
1229 GtkWidget *widget, *window;
1230 GtkTreeSelection *selection;
1231 GtkApplication *app;
1232 gint status;
1233 UpClient *client;
1234 GPtrArray *devices = NULL((void*)0);
1235 UpDevice *device;
1236 UpDeviceKind kind;
1237 guint i, j;
1238 gint page;
1239 gboolean checked;
1240 gchar *last_device = NULL((void*)0);
1241 char *history_type_str;
1242 char *stats_type_str;
1243
1244 const char *history_text [GPM_HISTORY_LAST_TYPE - 1] = {
1245 [GPM_HISTORY_RATE_TYPE] = GPM_HISTORY_RATE_TEXTgettext ("Rate"),
1246 [GPM_HISTORY_CHARGE_TYPE] = GPM_HISTORY_CHARGE_TEXTgettext ("Charge"),
1247 [GPM_HISTORY_TIME_FULL_TYPE] = GPM_HISTORY_TIME_FULL_TEXTgettext ("Time to full"),
1248 [GPM_HISTORY_TIME_EMPTY_TYPE] = GPM_HISTORY_TIME_EMPTY_TEXTgettext ("Time to empty")
1249 };
1250 const char *stats_text [GPM_STATS_LAST_TYPE] = {
1251 [GPM_STATS_CHARGE_TYPE] = GPM_STATS_CHARGE_DATA_TEXTgettext ("Charge profile"),
1252 [GPM_STATS_DISCHARGE_TYPE] = GPM_STATS_DISCHARGE_DATA_TEXTgettext ("Discharge profile"),
1253 [GPM_STATS_CHARGE_ACCURACY_TYPE] = GPM_STATS_CHARGE_ACCURACY_TEXTgettext ("Charge accuracy"),
1254 [GPM_STATS_DISCHARGE_ACCURACY_TYPE] = GPM_STATS_DISCHARGE_ACCURACY_TEXTgettext ("Discharge accuracy")
1255 };
1256 const GOptionEntry options[] = {
1257 { "device", '\0', 0, G_OPTION_ARG_STRING, &last_device,
1258 /* TRANSLATORS: show a device by default */
1259 N_("Select this device at startup")("Select this device at startup"), NULL((void*)0) },
1260 { NULL((void*)0), 0, 0, G_OPTION_ARG_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0) }
1261 };
1262
1263 setlocale (LC_ALL6, "");
1264
1265 bindtextdomain (GETTEXT_PACKAGE"mate-power-manager", MATELOCALEDIR"/usr/local/share/locale");
1266 bind_textdomain_codeset (GETTEXT_PACKAGE"mate-power-manager", "UTF-8");
1267 textdomain (GETTEXT_PACKAGE"mate-power-manager");
1268
1269 dbus_g_thread_init ();
1270
1271 context = g_option_context_new (NULL((void*)0));
1272 /* TRANSLATORS: the program name */
1273 g_option_context_set_summary (context, _("Power Statistics")gettext ("Power Statistics"));
1274 g_option_context_add_main_entries (context, options, NULL((void*)0));
1275 g_option_context_parse (context, &argc, &argv, NULL((void*)0));
1276 g_option_context_free (context);
1277
1278 gtk_init (&argc, &argv);
1279
1280 app = gtk_application_new ("org.mate.PowerManager.Statistics", 0);
1281
1282 g_signal_connect (app, "activate",g_signal_connect_data ((app), ("activate"), (((GCallback) (gpm_stats_window_activated_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1283 G_CALLBACK (gpm_stats_window_activated_cb), NULL)g_signal_connect_data ((app), ("activate"), (((GCallback) (gpm_stats_window_activated_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1284
1285 /* add application specific icons to search path */
1286 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
1287 GPM_ICONS_DATA"/usr/local/share/mate-power-manager/icons");
1288
1289 /* get data from the settings */
1290 settings = g_settings_new (GPM_SETTINGS_SCHEMA"org.mate.power-manager");
1291
1292 /* get UI */
1293 builder = gtk_builder_new_from_resource ("/org/mate/powermanager/statistics/gpm-statistics.ui");
1294
1295 /* add history graph */
1296 box = GTK_BOX (gtk_builder_get_object (builder, "hbox_history"))((((GtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "hbox_history"))), ((gtk_box_get_type
()))))))
;
1297 graph_history = gpm_graph_widget_new ();
1298 gtk_box_pack_start (box, graph_history, TRUE(!(0)), TRUE(!(0)), 0);
1299 gtk_widget_set_size_request (graph_history, 400, 250);
1300 gtk_widget_show (graph_history);
1301
1302 /* add statistics graph */
1303 box = GTK_BOX (gtk_builder_get_object (builder, "hbox_statistics"))((((GtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "hbox_statistics"))), (
(gtk_box_get_type ()))))))
;
1304 graph_statistics = gpm_graph_widget_new ();
1305 gtk_box_pack_start (box, graph_statistics, TRUE(!(0)), TRUE(!(0)), 0);
1306 gtk_widget_set_size_request (graph_statistics, 400, 250);
1307 gtk_widget_show (graph_statistics);
1308
1309 window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
1310 gtk_window_set_default_size (GTK_WINDOW(window)((((GtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((gtk_window_get_type ()))))))
, 800, 500);
1311 gtk_window_set_default_icon_name (GPM_ICON_APP_ICON"mate-power-manager");
1312
1313 /* Get the main window quit */
1314 widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "button_close"))), ((gtk_widget_get_type
()))))))
;
1315 g_signal_connect_swapped (window, "delete_event", G_CALLBACK (gtk_widget_destroy), window)g_signal_connect_data ((window), ("delete_event"), (((GCallback
) (gtk_widget_destroy))), (window), ((void*)0), G_CONNECT_SWAPPED
)
;
1316 g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_widget_destroy), window)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gtk_widget_destroy))), (window), ((void*)0), G_CONNECT_SWAPPED
)
;
1317 gtk_widget_grab_default (widget);
1318
1319 widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "button_help"))), ((gtk_widget_get_type
()))))))
;
1320 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_button_help_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
1321 G_CALLBACK (gpm_stats_button_help_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_button_help_cb))), (((void*)0)), ((void*)0), (GConnectFlags
) 0)
;
1322
1323 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_history"
))), ((gtk_widget_get_type ()))))))
;
1324 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH"info-history-graph-smooth");
1325 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1326 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
1327 G_CALLBACK (gpm_stats_smooth_checkbox_history_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
;
1328
1329 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_smooth_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_smooth_stats"
))), ((gtk_widget_get_type ()))))))
;
1330 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH"info-stats-graph-smooth");
1331 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1332 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
1333 G_CALLBACK (gpm_stats_smooth_checkbox_stats_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_smooth_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
;
1334
1335 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_history"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_history"
))), ((gtk_widget_get_type ()))))))
;
1336 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS"info-history-graph-points");
1337 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1338 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
1339 G_CALLBACK (gpm_stats_points_checkbox_history_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_history_cb))), (((void*)0)), ((void
*)0), (GConnectFlags) 0)
;
1340
1341 widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_points_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "checkbutton_points_stats"
))), ((gtk_widget_get_type ()))))))
;
1342 checked = g_settings_get_boolean (settings, GPM_SETTINGS_INFO_STATS_GRAPH_POINTS"info-stats-graph-points");
1343 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget)((((GtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_toggle_button_get_type ()))))))
, checked);
1344 g_signal_connect (widget, "clicked",g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
1345 G_CALLBACK (gpm_stats_points_checkbox_stats_cb), NULL)g_signal_connect_data ((widget), ("clicked"), (((GCallback) (
gpm_stats_points_checkbox_stats_cb))), (((void*)0)), ((void*)
0), (GConnectFlags) 0)
;
1346
1347 widget = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "notebook1"))), ((gtk_widget_get_type
()))))))
;
1348
1349 gtk_widget_add_events (widget, GDK_SCROLL_MASK);
1350 g_signal_connect (widget,g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1351 "scroll-event",g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1352 G_CALLBACK (gpm_notebook_scroll_event_cb),g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
1353 NULL)g_signal_connect_data ((widget), ("scroll-event"), (((GCallback
) (gpm_notebook_scroll_event_cb))), (((void*)0)), ((void*)0),
(GConnectFlags) 0)
;
1354
1355 page = g_settings_get_int (settings, GPM_SETTINGS_INFO_PAGE_NUMBER"info-page-number");
1356 gtk_notebook_set_current_page (GTK_NOTEBOOK (widget)((((GtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_notebook_get_type ()))))))
, page);
1357 g_signal_connect (widget, "switch-page",g_signal_connect_data ((widget), ("switch-page"), (((GCallback
) (gpm_stats_notebook_changed_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
1358 G_CALLBACK (gpm_stats_notebook_changed_cb), NULL)g_signal_connect_data ((widget), ("switch-page"), (((GCallback
) (gpm_stats_notebook_changed_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
;
1359
1360 /* create list stores */
1361 list_store_info = gtk_list_store_new (GPM_INFO_COLUMN_LAST, G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2))));
1362 list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_STRING((GType) ((16) << (2))),
1363 G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2))));
1364
1365 /* create transaction_id tree view */
1366 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_info"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_info"))), ((gtk_widget_get_type
()))))))
;
1367 gtk_tree_view_set_model (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
,
1368 GTK_TREE_MODEL (list_store_info)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_info)), ((gtk_tree_model_get_type ()))))))
);
1369
1370 /* add columns to the tree view */
1371 gpm_stats_add_info_columns (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1372 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
); /* show */
1373
1374 /* create transaction_id tree view */
1375 widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_devices"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "treeview_devices"))), (
(gtk_widget_get_type ()))))))
;
1376 gtk_tree_view_set_model (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
,
1377 GTK_TREE_MODEL (list_store_devices)((((GtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list_store_devices)), ((gtk_tree_model_get_type ()))))))
);
1378 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1379 g_signal_connect (selection, "changed",g_signal_connect_data ((selection), ("changed"), (((GCallback
) (gpm_stats_devices_treeview_clicked_cb))), (((void*)0)), ((
void*)0), (GConnectFlags) 0)
1380 G_CALLBACK (gpm_stats_devices_treeview_clicked_cb), NULL)g_signal_connect_data ((selection), ("changed"), (((GCallback
) (gpm_stats_devices_treeview_clicked_cb))), (((void*)0)), ((
void*)0), (GConnectFlags) 0)
;
1381
1382 /* add columns to the tree view */
1383 gpm_stats_add_devices_columns (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
);
1384 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)((((GtkTreeView*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_tree_view_get_type ()))))))
); /* show */
1385
1386 history_type_str = g_settings_get_string (settings, GPM_SETTINGS_INFO_HISTORY_TYPE"info-history-type");
1387 if ((history_type_str == NULL((void*)0)) || (strcmp (history_type_str, GPM_HISTORY_CHARGE_VALUE"charge") == 0)) {
1388 history_type = GPM_HISTORY_CHARGE_TYPE;
1389 } else if (strcmp (history_type_str, GPM_HISTORY_RATE_VALUE"rate") == 0) {
1390 history_type = GPM_HISTORY_RATE_TYPE;
1391 } else if (strcmp (history_type_str, GPM_HISTORY_TIME_FULL_VALUE"time-full") == 0) {
1392 history_type = GPM_HISTORY_TIME_FULL_TYPE;
1393 } else if (strcmp (history_type_str, GPM_HISTORY_TIME_EMPTY_VALUE"time-empty") == 0) {
1394 history_type = GPM_HISTORY_TIME_EMPTY_TYPE;
1395 } else if (strcmp (history_type_str, GPM_HISTORY_POWER_VALUE"power") == 0) {
1396 history_type = GPM_HISTORY_POWER_TYPE;
1397 } else {
1398 history_type = GPM_HISTORY_CHARGE_TYPE;
1399 }
1400 g_free (history_type_str);
1401
1402 history_time = g_settings_get_int (settings, GPM_SETTINGS_INFO_HISTORY_TIME"info-history-time");
1403 if (history_time == 0)
1404 history_time = GPM_HISTORY_HOUR_VALUE2*60*60;
1405
1406 stats_type_str = g_settings_get_string (settings, GPM_SETTINGS_INFO_STATS_TYPE"info-stats-type");
1407 if ((stats_type_str == NULL((void*)0)) || (strcmp (stats_type_str, GPM_STATS_CHARGE_DATA_VALUE"charge-data") == 0)) {
1408 stats_type = GPM_STATS_CHARGE_TYPE;
1409 } else if (strcmp (stats_type_str, GPM_STATS_DISCHARGE_DATA_VALUE"discharge-data") == 0) {
1410 stats_type = GPM_STATS_DISCHARGE_TYPE;
1411 } else if (strcmp (stats_type_str, GPM_STATS_CHARGE_ACCURACY_VALUE"charge-accuracy") == 0) {
1412 stats_type = GPM_STATS_CHARGE_ACCURACY_TYPE;
1413 } else if (strcmp (stats_type_str, GPM_STATS_DISCHARGE_ACCURACY_VALUE"discharge-accuracy") == 0) {
1414 stats_type = GPM_STATS_DISCHARGE_ACCURACY_TYPE;
1415 } else {
1416 stats_type = GPM_STATS_CHARGE_TYPE;
1417 }
1418 g_free (stats_type_str);
1419
1420 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_type"
))), ((gtk_widget_get_type ()))))))
;
1421 for (i = 0; i < GPM_HISTORY_LAST_TYPE - 1; i++)
1422 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, history_text[i]);
1423 if (history_type == GPM_HISTORY_RATE_TYPE)
1424 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1425 else
1426 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1427 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_history_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1428 G_CALLBACK (gpm_stats_history_type_combo_changed_cb), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_history_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1429
1430 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_stats_type"))
), ((gtk_widget_get_type ()))))))
;
1431 for (i = 0; i < GPM_STATS_LAST_TYPE; i++)
1432 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, stats_text[i]);
1433 if (stats_type == GPM_STATS_CHARGE_TYPE)
1434 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1435 else if (stats_type == GPM_STATS_CHARGE_TYPE)
expression is identical to previous condition
1436 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1437 else if (stats_type == GPM_STATS_CHARGE_TYPE)
1438 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 2);
1439 else if (stats_type == GPM_STATS_CHARGE_TYPE)
1440 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1441 else
1442 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 3);
1443 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1444 G_CALLBACK (gpm_stats_type_combo_changed_cb), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_type_combo_changed_cb
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1445
1446 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_time"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_time"
))), ((gtk_widget_get_type ()))))))
;
1447 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_MINUTE_TEXTgettext ("10 minutes"));
1448 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_HOUR_TEXTgettext ("2 hours"));
1449 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_HOURS_TEXTgettext ("6 hours"));
1450 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_DAY_TEXTgettext ("1 day"));
1451 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget)((((GtkComboBoxText*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_text_get_type ()))))))
, GPM_HISTORY_WEEK_TEXTgettext ("1 week"));
1452 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1453 if (history_time == GPM_HISTORY_MINUTE_VALUE10*60)
1454 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 0);
1455 else if (history_time == GPM_HISTORY_HOUR_VALUE2*60*60)
1456 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 1);
1457 else
1458 gtk_combo_box_set_active (GTK_COMBO_BOX (widget)((((GtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((gtk_combo_box_get_type ()))))))
, 2);
1459 g_signal_connect (G_OBJECT (widget), "changed",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_range_combo_changed
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
1460 G_CALLBACK (gpm_stats_range_combo_changed), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((widget)), (((GType) ((20) << (2)))
)))))), ("changed"), (((GCallback) (gpm_stats_range_combo_changed
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
1461
1462 client = up_client_new ();
1463
1464 devices = up_client_get_devices2 (client);
1465
1466 /* add devices in visually pleasing order */
1467 for (j=0; j<UP_DEVICE_KIND_LAST; j++) {
1468 for (i=0; i < devices->len; i++) {
1469 device = g_ptr_array_index (devices, i)((devices)->pdata)[i];
1470 g_object_get (device, "kind", &kind, NULL((void*)0));
1471 if (kind == j)
1472 /* NULL == do not add it to ptr array */
1473 gpm_stats_add_device (device, NULL((void*)0));
1474 }
1475 }
1476
1477 /* connect now the coldplug is done */
1478 g_signal_connect (client, "device-added", G_CALLBACK (gpm_stats_device_added_cb), devices)g_signal_connect_data ((client), ("device-added"), (((GCallback
) (gpm_stats_device_added_cb))), (devices), ((void*)0), (GConnectFlags
) 0)
;
1479 g_signal_connect (client, "device-removed", G_CALLBACK (gpm_stats_device_removed_cb), devices)g_signal_connect_data ((client), ("device-removed"), (((GCallback
) (gpm_stats_device_removed_cb))), (devices), ((void*)0), (GConnectFlags
) 0)
;
1480
1481 /* set current device */
1482 if (devices->len > 0) {
1483 device = g_ptr_array_index (devices, 0)((devices)->pdata)[0];
1484 gpm_stats_update_info_data (device);
1485 current_device = g_strdup (up_device_get_object_path (device))g_strdup_inline (up_device_get_object_path (device));
1486 }
1487
1488 if (last_device == NULL((void*)0))
1489 last_device = g_settings_get_string (settings, GPM_SETTINGS_INFO_LAST_DEVICE"info-last-device");
1490
1491 /* set the correct focus on the last device */
1492 if (last_device != NULL((void*)0))
1493 gpm_stats_highlight_device (last_device);
1494
1495 /* set axis */
1496 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_history_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_history_type"
))), ((gtk_widget_get_type ()))))))
;
1497 gpm_stats_history_type_combo_changed_cb (widget, NULL((void*)0));
1498 widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_stats_type"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "combobox_stats_type"))
), ((gtk_widget_get_type ()))))))
;
1499 gpm_stats_type_combo_changed_cb (widget, NULL((void*)0));
1500
1501 widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"))((((GtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((gtk_builder_get_object (builder, "dialog_stats"))), ((gtk_widget_get_type
()))))))
;
1502
1503 status = g_application_run (G_APPLICATION (app)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((g_application_get_type ()))))))
, argc, argv);
1504 if (devices != NULL((void*)0))
1505 g_ptr_array_unref (devices);
1506
1507 g_object_unref (settings);
1508 g_object_unref (client);
1509 g_object_unref (builder);
1510 g_object_unref (list_store_info);
1511 g_object_unref (app);
1512 g_free (last_device);
1513 return status;
1514}
diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/scanview.css b/2024-02-25-205630-11823-1@c406c230d131_master/scanview.css new file mode 100644 index 0000000..cf8a5a6 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/scanview.css @@ -0,0 +1,62 @@ +body { color:#000000; background-color:#ffffff } +body { font-family: Helvetica, sans-serif; font-size:9pt } +h1 { font-size: 14pt; } +h2 { font-size: 12pt; } +table { font-size:9pt } +table { border-spacing: 0px; border: 1px solid black } +th, table thead { + background-color:#eee; color:#666666; + font-weight: bold; cursor: default; + text-align:center; + font-weight: bold; font-family: Verdana; + white-space:nowrap; +} +.W { font-size:0px } +th, td { padding:5px; padding-left:8px; text-align:left } +td.SUMM_DESC { padding-left:12px } +td.DESC { white-space:pre } +td.Q { text-align:right } +td { text-align:left } +tbody.scrollContent { overflow:auto } + +table.form_group { + background-color: #ccc; + border: 1px solid #333; + padding: 2px; +} + +table.form_inner_group { + background-color: #ccc; + border: 1px solid #333; + padding: 0px; +} + +table.form { + background-color: #999; + border: 1px solid #333; + padding: 2px; +} + +td.form_label { + text-align: right; + vertical-align: top; +} +/* For one line entires */ +td.form_clabel { + text-align: right; + vertical-align: center; +} +td.form_value { + text-align: left; + vertical-align: top; +} +td.form_submit { + text-align: right; + vertical-align: top; +} + +h1.SubmitFail { + color: #f00; +} +h1.SubmitOk { +} diff --git a/2024-02-25-205630-11823-1@c406c230d131_master/sorttable.js b/2024-02-25-205630-11823-1@c406c230d131_master/sorttable.js new file mode 100644 index 0000000..32faa07 --- /dev/null +++ b/2024-02-25-205630-11823-1@c406c230d131_master/sorttable.js @@ -0,0 +1,492 @@ +/* + SortTable + version 2 + 7th April 2007 + Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ + + Instructions: + Download this file + Add to your HTML + Add class="sortable" to any table you'd like to make sortable + Click on the headers to sort + + Thanks to many, many people for contributions and suggestions. + Licenced as X11: http://www.kryogenix.org/code/browser/licence.html + This basically means: do what you want with it. +*/ + + +var stIsIE = /*@cc_on!@*/false; + +sorttable = { + init: function() { + // quit if this function has already been called + if (arguments.callee.done) return; + // flag this function so we don't do the same thing twice + arguments.callee.done = true; + // kill the timer + if (_timer) clearInterval(_timer); + + if (!document.createElement || !document.getElementsByTagName) return; + + sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; + + forEach(document.getElementsByTagName('table'), function(table) { + if (table.className.search(/\bsortable\b/) != -1) { + sorttable.makeSortable(table); + } + }); + + }, + + makeSortable: function(table) { + if (table.getElementsByTagName('thead').length == 0) { + // table doesn't have a tHead. Since it should have, create one and + // put the first table row in it. + the = document.createElement('thead'); + the.appendChild(table.rows[0]); + table.insertBefore(the,table.firstChild); + } + // Safari doesn't support table.tHead, sigh + if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; + + if (table.tHead.rows.length != 1) return; // can't cope with two header rows + + // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as + // "total" rows, for example). This is B&R, since what you're supposed + // to do is put them in a tfoot. So, if there are sortbottom rows, + // for backward compatibility, move them to tfoot (creating it if needed). + sortbottomrows = []; + for (var i=0; i5' : ' ▴'; + this.appendChild(sortrevind); + return; + } + if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { + // if we're already sorted by this column in reverse, just + // re-reverse the table, which is quicker + sorttable.reverse(this.sorttable_tbody); + this.className = this.className.replace('sorttable_sorted_reverse', + 'sorttable_sorted'); + this.removeChild(document.getElementById('sorttable_sortrevind')); + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + return; + } + + // remove sorttable_sorted classes + theadrow = this.parentNode; + forEach(theadrow.childNodes, function(cell) { + if (cell.nodeType == 1) { // an element + cell.className = cell.className.replace('sorttable_sorted_reverse',''); + cell.className = cell.className.replace('sorttable_sorted',''); + } + }); + sortfwdind = document.getElementById('sorttable_sortfwdind'); + if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } + sortrevind = document.getElementById('sorttable_sortrevind'); + if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } + + this.className += ' sorttable_sorted'; + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + + // build an array to sort. This is a Schwartzian transform thing, + // i.e., we "decorate" each row with the actual sort key, + // sort based on the sort keys, and then put the rows back in order + // which is a lot faster because you only do getInnerText once per row + row_array = []; + col = this.sorttable_columnindex; + rows = this.sorttable_tbody.rows; + for (var j=0; j 12) { + // definitely dd/mm + return sorttable.sort_ddmm; + } else if (second > 12) { + return sorttable.sort_mmdd; + } else { + // looks like a date, but we can't tell which, so assume + // that it's dd/mm (English imperialism!) and keep looking + sortfn = sorttable.sort_ddmm; + } + } + } + } + return sortfn; + }, + + getInnerText: function(node) { + // gets the text we want to use for sorting for a cell. + // strips leading and trailing whitespace. + // this is *not* a generic getInnerText function; it's special to sorttable. + // for example, you can override the cell text with a customkey attribute. + // it also gets .value for fields. + + hasInputs = (typeof node.getElementsByTagName == 'function') && + node.getElementsByTagName('input').length; + + if (node.getAttribute("sorttable_customkey") != null) { + return node.getAttribute("sorttable_customkey"); + } + else if (typeof node.textContent != 'undefined' && !hasInputs) { + return node.textContent.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.innerText != 'undefined' && !hasInputs) { + return node.innerText.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.text != 'undefined' && !hasInputs) { + return node.text.replace(/^\s+|\s+$/g, ''); + } + else { + switch (node.nodeType) { + case 3: + if (node.nodeName.toLowerCase() == 'input') { + return node.value.replace(/^\s+|\s+$/g, ''); + } + case 4: + return node.nodeValue.replace(/^\s+|\s+$/g, ''); + break; + case 1: + case 11: + var innerText = ''; + for (var i = 0; i < node.childNodes.length; i++) { + innerText += sorttable.getInnerText(node.childNodes[i]); + } + return innerText.replace(/^\s+|\s+$/g, ''); + break; + default: + return ''; + } + } + }, + + reverse: function(tbody) { + // reverse the rows in a tbody + newrows = []; + for (var i=0; i=0; i--) { + tbody.appendChild(newrows[i]); + } + delete newrows; + }, + + /* sort functions + each sort function takes two parameters, a and b + you are comparing a[0] and b[0] */ + sort_numeric: function(a,b) { + aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); + if (isNaN(aa)) aa = 0; + bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); + if (isNaN(bb)) bb = 0; + return aa-bb; + }, + sort_alpha: function(a,b) { + if (a[0]==b[0]) return 0; + if (a[0] 0 ) { + var q = list[i]; list[i] = list[i+1]; list[i+1] = q; + swap = true; + } + } // for + t--; + + if (!swap) break; + + for(var i = t; i > b; --i) { + if ( comp_func(list[i], list[i-1]) < 0 ) { + var q = list[i]; list[i] = list[i-1]; list[i-1] = q; + swap = true; + } + } // for + b++; + + } // while(swap) + } +} + +/* ****************************************************************** + Supporting functions: bundled here to avoid depending on a library + ****************************************************************** */ + +// Dean Edwards/Matthias Miller/John Resig + +/* for Mozilla/Opera9 */ +if (document.addEventListener) { + document.addEventListener("DOMContentLoaded", sorttable.init, false); +} + +/* for Internet Explorer */ +/*@cc_on @*/ +/*@if (@_win32) + document.write("