GCC Code Coverage Report


Directory: ./
File: panels/power/cc-power-profile-row.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 66 0.0%
Functions: 0 13 0.0%
Branches: 0 29 0.0%

Line Branch Exec Source
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* cc-list-row.c
3 *
4 * Copyright 2020 Red Hat Inc.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author(s):
20 * Bastien Nocera <hadess@hadess.net>
21 *
22 * SPDX-License-Identifier: GPL-3.0-or-later
23 */
24
25 #undef G_LOG_DOMAIN
26 #define G_LOG_DOMAIN "cc-power-profile-row"
27
28 #include <config.h>
29
30 #include <glib/gi18n.h>
31 #include "cc-power-profile-row.h"
32
33 struct _CcPowerProfileRow
34 {
35 AdwActionRow parent_instance;
36
37 GtkCheckButton *button;
38
39 CcPowerProfile power_profile;
40 };
41
42 G_DEFINE_TYPE (CcPowerProfileRow, cc_power_profile_row, ADW_TYPE_ACTION_ROW)
43
44 enum {
45 BUTTON_TOGGLED,
46 N_SIGNALS
47 };
48
49 static guint signals[N_SIGNALS];
50
51 static void
52 cc_power_profile_row_button_toggled_cb (CcPowerProfileRow *self)
53 {
54 g_signal_emit (self, signals[BUTTON_TOGGLED], 0);
55 }
56
57 static void
58 cc_power_profile_row_class_init (CcPowerProfileRowClass *klass)
59 {
60 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
61
62 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/power/cc-power-profile-row.ui");
63
64 gtk_widget_class_bind_template_child (widget_class, CcPowerProfileRow, button);
65
66 gtk_widget_class_bind_template_callback (widget_class, cc_power_profile_row_button_toggled_cb);
67
68 signals[BUTTON_TOGGLED] =
69 g_signal_new ("button-toggled",
70 G_TYPE_FROM_CLASS (klass),
71 G_SIGNAL_RUN_FIRST,
72 0, NULL, NULL,
73 NULL,
74 G_TYPE_NONE, 0);
75 }
76
77 static void
78 cc_power_profile_row_init (CcPowerProfileRow *self)
79 {
80 gtk_widget_init_template (GTK_WIDGET (self));
81 }
82
83 CcPowerProfile
84 cc_power_profile_row_get_profile (CcPowerProfileRow *self)
85 {
86 g_return_val_if_fail (CC_IS_POWER_PROFILE_ROW (self), -1);
87
88 return self->power_profile;
89 }
90
91 GtkCheckButton *
92 cc_power_profile_row_get_radio_button (CcPowerProfileRow *self)
93 {
94 g_return_val_if_fail (CC_IS_POWER_PROFILE_ROW (self), NULL);
95
96 return self->button;
97 }
98
99 void
100 cc_power_profile_row_set_active (CcPowerProfileRow *self,
101 gboolean active)
102 {
103 g_return_if_fail (CC_IS_POWER_PROFILE_ROW (self));
104
105 gtk_check_button_set_active (GTK_CHECK_BUTTON (self->button), active);
106 }
107
108 gboolean
109 cc_power_profile_row_get_active (CcPowerProfileRow *self)
110 {
111 g_return_val_if_fail (CC_IS_POWER_PROFILE_ROW (self), FALSE);
112
113 return gtk_check_button_get_active (GTK_CHECK_BUTTON (self->button));
114 }
115
116 CcPowerProfileRow *
117 cc_power_profile_row_new (CcPowerProfile power_profile)
118 {
119 CcPowerProfileRow *self;
120 const char *text, *subtext;
121
122 self = g_object_new (CC_TYPE_POWER_PROFILE_ROW, NULL);
123
124 self->power_profile = power_profile;
125 switch (self->power_profile)
126 {
127 case CC_POWER_PROFILE_PERFORMANCE:
128 text = C_("Power profile", "P_erformance");
129 subtext = _("High performance and power usage");
130 break;
131 case CC_POWER_PROFILE_BALANCED:
132 text = C_("Power profile", "Ba_lanced");
133 subtext = _("Standard performance and power usage");
134 break;
135 case CC_POWER_PROFILE_POWER_SAVER:
136 text = C_("Power profile", "P_ower Saver");
137 subtext = _("Reduced performance and power usage");
138 break;
139 default:
140 g_assert_not_reached ();
141 }
142
143 adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), text);
144 adw_action_row_set_subtitle (ADW_ACTION_ROW (self), subtext);
145
146 return self;
147 }
148
149 CcPowerProfile
150 cc_power_profile_from_str (const char *profile)
151 {
152 if (g_strcmp0 (profile, "power-saver") == 0)
153 return CC_POWER_PROFILE_POWER_SAVER;
154 if (g_strcmp0 (profile, "balanced") == 0)
155 return CC_POWER_PROFILE_BALANCED;
156 if (g_strcmp0 (profile, "performance") == 0)
157 return CC_POWER_PROFILE_PERFORMANCE;
158
159 g_assert_not_reached ();
160 }
161
162 const char *
163 cc_power_profile_to_str (CcPowerProfile profile)
164 {
165 switch (profile)
166 {
167 case CC_POWER_PROFILE_POWER_SAVER:
168 return "power-saver";
169 case CC_POWER_PROFILE_BALANCED:
170 return "balanced";
171 case CC_POWER_PROFILE_PERFORMANCE:
172 return "performance";
173 default:
174 g_assert_not_reached ();
175 }
176 }
177