Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 |
|
|
/* cc-wwan-network-dialog.c |
3 |
|
|
* |
4 |
|
|
* Copyright 2019,2022 Purism SPC |
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 |
|
|
* Mohammed Sadiq <sadiq@sadiqpk.org> |
21 |
|
|
* |
22 |
|
|
* SPDX-License-Identifier: GPL-3.0-or-later |
23 |
|
|
*/ |
24 |
|
|
|
25 |
|
|
#undef G_LOG_DOMAIN |
26 |
|
|
#define G_LOG_DOMAIN "cc-wwan-details-dialog" |
27 |
|
|
|
28 |
|
|
#include <config.h> |
29 |
|
|
#include <glib/gi18n.h> |
30 |
|
|
#include <libmm-glib.h> |
31 |
|
|
|
32 |
|
|
#include "cc-wwan-details-dialog.h" |
33 |
|
|
#include "cc-wwan-resources.h" |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* @short_description: Dialog to Show Device Details |
37 |
|
|
*/ |
38 |
|
|
|
39 |
|
|
struct _CcWwanDetailsDialog |
40 |
|
|
{ |
41 |
|
|
GtkDialog parent_instance; |
42 |
|
|
|
43 |
|
|
GtkLabel *device_identifier; |
44 |
|
|
GtkLabel *device_model; |
45 |
|
|
GtkLabel *firmware_version; |
46 |
|
|
GtkLabel *identifier_label; |
47 |
|
|
GtkLabel *manufacturer; |
48 |
|
|
GtkLabel *network_status; |
49 |
|
|
GtkLabel *network_type; |
50 |
|
|
GtkLabel *operator_name; |
51 |
|
|
GtkLabel *own_numbers; |
52 |
|
|
GtkLabel *signal_strength; |
53 |
|
|
|
54 |
|
|
CcWwanDevice *device; |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
✗ |
G_DEFINE_TYPE (CcWwanDetailsDialog, cc_wwan_details_dialog, GTK_TYPE_DIALOG) |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
enum { |
61 |
|
|
PROP_0, |
62 |
|
|
PROP_DEVICE, |
63 |
|
|
N_PROPS |
64 |
|
|
}; |
65 |
|
|
|
66 |
|
|
static GParamSpec *properties[N_PROPS]; |
67 |
|
|
|
68 |
|
|
static void |
69 |
|
✗ |
cc_wwan_details_update_network_status (CcWwanDetailsDialog *self) |
70 |
|
|
{ |
71 |
|
|
CcWwanState state; |
72 |
|
|
|
73 |
|
✗ |
g_assert (CC_IS_WWAN_DETAILS_DIALOG (self)); |
74 |
|
|
|
75 |
|
✗ |
state = cc_wwan_device_get_network_state (self->device); |
76 |
|
|
|
77 |
|
✗ |
switch (state) |
78 |
|
|
{ |
79 |
|
✗ |
case CC_WWAN_REGISTRATION_STATE_IDLE: |
80 |
|
✗ |
gtk_label_set_label (self->network_status, _("Not Registered")); |
81 |
|
✗ |
break; |
82 |
|
|
|
83 |
|
✗ |
case CC_WWAN_REGISTRATION_STATE_REGISTERED: |
84 |
|
✗ |
gtk_label_set_label (self->network_status, _("Registered")); |
85 |
|
✗ |
break; |
86 |
|
|
|
87 |
|
✗ |
case CC_WWAN_REGISTRATION_STATE_ROAMING: |
88 |
|
✗ |
gtk_label_set_label (self->network_status, _("Roaming")); |
89 |
|
✗ |
break; |
90 |
|
|
|
91 |
|
✗ |
case CC_WWAN_REGISTRATION_STATE_SEARCHING: |
92 |
|
✗ |
gtk_label_set_label (self->network_status, _("Searching")); |
93 |
|
✗ |
break; |
94 |
|
|
|
95 |
|
✗ |
case CC_WWAN_REGISTRATION_STATE_DENIED: |
96 |
|
✗ |
gtk_label_set_label (self->network_status, _("Denied")); |
97 |
|
✗ |
break; |
98 |
|
|
|
99 |
|
✗ |
default: |
100 |
|
✗ |
gtk_label_set_label (self->network_status, _("Unknown")); |
101 |
|
✗ |
break; |
102 |
|
|
} |
103 |
|
✗ |
} |
104 |
|
|
|
105 |
|
|
static void |
106 |
|
✗ |
cc_wwan_details_signal_changed_cb (CcWwanDetailsDialog *self) |
107 |
|
|
{ |
108 |
|
✗ |
g_autofree gchar *network_type_string = NULL; |
109 |
|
✗ |
g_autofree gchar *signal_string = NULL; |
110 |
|
|
const gchar *operator_name; |
111 |
|
|
|
112 |
|
✗ |
g_assert (CC_IS_WWAN_DETAILS_DIALOG (self)); |
113 |
|
|
|
114 |
|
✗ |
operator_name = cc_wwan_device_get_operator_name (self->device); |
115 |
|
✗ |
if (operator_name) |
116 |
|
✗ |
gtk_label_set_label (self->operator_name, operator_name); |
117 |
|
|
|
118 |
|
✗ |
network_type_string = cc_wwan_device_dup_network_type_string (self->device); |
119 |
|
✗ |
if (network_type_string) |
120 |
|
✗ |
gtk_label_set_label (self->network_type, network_type_string); |
121 |
|
|
|
122 |
|
✗ |
signal_string = cc_wwan_device_dup_signal_string (self->device); |
123 |
|
✗ |
if (signal_string) |
124 |
|
✗ |
gtk_label_set_label (self->signal_strength, signal_string); |
125 |
|
|
|
126 |
|
✗ |
cc_wwan_details_update_network_status (self); |
127 |
|
✗ |
} |
128 |
|
|
|
129 |
|
|
static void |
130 |
|
✗ |
cc_wwan_details_update_hardware_details (CcWwanDetailsDialog *self) |
131 |
|
|
{ |
132 |
|
|
const gchar *str; |
133 |
|
|
|
134 |
|
✗ |
g_assert (CC_IS_WWAN_DETAILS_DIALOG (self)); |
135 |
|
|
|
136 |
|
✗ |
str = cc_wwan_device_get_manufacturer (self->device); |
137 |
|
✗ |
if (str) |
138 |
|
✗ |
gtk_label_set_label (self->manufacturer, str); |
139 |
|
|
|
140 |
|
✗ |
str = cc_wwan_device_get_model (self->device); |
141 |
|
✗ |
if (str) |
142 |
|
✗ |
gtk_label_set_label (self->device_model, str); |
143 |
|
|
|
144 |
|
✗ |
str = cc_wwan_device_get_firmware_version (self->device); |
145 |
|
✗ |
if (str) |
146 |
|
✗ |
gtk_label_set_label (self->firmware_version, str); |
147 |
|
|
|
148 |
|
✗ |
str = cc_wwan_device_get_identifier (self->device); |
149 |
|
✗ |
if (str) |
150 |
|
✗ |
gtk_label_set_label (self->device_identifier, str); |
151 |
|
✗ |
} |
152 |
|
|
|
153 |
|
|
static void |
154 |
|
✗ |
cc_wwan_details_dialog_set_property (GObject *object, |
155 |
|
|
guint prop_id, |
156 |
|
|
const GValue *value, |
157 |
|
|
GParamSpec *pspec) |
158 |
|
|
{ |
159 |
|
✗ |
CcWwanDetailsDialog *self = CC_WWAN_DETAILS_DIALOG (object); |
160 |
|
|
|
161 |
|
✗ |
switch (prop_id) |
162 |
|
|
{ |
163 |
|
✗ |
case PROP_DEVICE: |
164 |
|
✗ |
self->device = g_value_dup_object (value); |
165 |
|
✗ |
break; |
166 |
|
|
|
167 |
|
✗ |
default: |
168 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
169 |
|
|
} |
170 |
|
✗ |
} |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
✗ |
cc_wwan_details_dialog_constructed (GObject *object) |
174 |
|
|
{ |
175 |
|
✗ |
CcWwanDetailsDialog *self = CC_WWAN_DETAILS_DIALOG (object); |
176 |
|
✗ |
g_autofree char *numbers = NULL; |
177 |
|
|
|
178 |
|
✗ |
G_OBJECT_CLASS (cc_wwan_details_dialog_parent_class)->constructed (object); |
179 |
|
|
|
180 |
|
✗ |
g_signal_connect_object (self->device, "notify::signal", |
181 |
|
|
G_CALLBACK (cc_wwan_details_signal_changed_cb), |
182 |
|
|
self, G_CONNECT_SWAPPED); |
183 |
|
|
|
184 |
|
✗ |
numbers = cc_wwan_device_dup_own_numbers (self->device); |
185 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->own_numbers), !!numbers); |
186 |
|
|
|
187 |
|
✗ |
if (numbers) |
188 |
|
✗ |
gtk_label_set_text (self->own_numbers, numbers); |
189 |
|
|
|
190 |
|
✗ |
cc_wwan_details_signal_changed_cb (self); |
191 |
|
✗ |
cc_wwan_details_update_hardware_details (self); |
192 |
|
✗ |
} |
193 |
|
|
|
194 |
|
|
static void |
195 |
|
✗ |
cc_wwan_details_dialog_dispose (GObject *object) |
196 |
|
|
{ |
197 |
|
✗ |
CcWwanDetailsDialog *self = CC_WWAN_DETAILS_DIALOG (object); |
198 |
|
|
|
199 |
|
✗ |
g_clear_object (&self->device); |
200 |
|
|
|
201 |
|
✗ |
G_OBJECT_CLASS (cc_wwan_details_dialog_parent_class)->dispose (object); |
202 |
|
✗ |
} |
203 |
|
|
|
204 |
|
|
static void |
205 |
|
✗ |
cc_wwan_details_dialog_class_init (CcWwanDetailsDialogClass *klass) |
206 |
|
|
{ |
207 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
208 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
209 |
|
|
|
210 |
|
✗ |
object_class->set_property = cc_wwan_details_dialog_set_property; |
211 |
|
✗ |
object_class->constructed = cc_wwan_details_dialog_constructed; |
212 |
|
✗ |
object_class->dispose = cc_wwan_details_dialog_dispose; |
213 |
|
|
|
214 |
|
✗ |
properties[PROP_DEVICE] = |
215 |
|
✗ |
g_param_spec_object ("device", |
216 |
|
|
"Device", |
217 |
|
|
"The WWAN Device", |
218 |
|
|
CC_TYPE_WWAN_DEVICE, |
219 |
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); |
220 |
|
|
|
221 |
|
✗ |
g_object_class_install_properties (object_class, N_PROPS, properties); |
222 |
|
|
|
223 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, |
224 |
|
|
"/org/gnome/control-center/wwan/cc-wwan-details-dialog.ui"); |
225 |
|
|
|
226 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, device_identifier); |
227 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, device_model); |
228 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, firmware_version); |
229 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, identifier_label); |
230 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, manufacturer); |
231 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, network_status); |
232 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, network_type); |
233 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, operator_name); |
234 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, own_numbers); |
235 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcWwanDetailsDialog, signal_strength); |
236 |
|
✗ |
} |
237 |
|
|
|
238 |
|
|
static void |
239 |
|
✗ |
cc_wwan_details_dialog_init (CcWwanDetailsDialog *self) |
240 |
|
|
{ |
241 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
242 |
|
✗ |
} |
243 |
|
|
|
244 |
|
|
GtkWindow * |
245 |
|
✗ |
cc_wwan_details_dialog_new (GtkWindow *parent_window, |
246 |
|
|
CcWwanDevice *device) |
247 |
|
|
{ |
248 |
|
✗ |
g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL); |
249 |
|
✗ |
g_return_val_if_fail (CC_IS_WWAN_DEVICE (device), NULL); |
250 |
|
|
|
251 |
|
✗ |
return GTK_WINDOW (g_object_new (CC_TYPE_WWAN_DETAILS_DIALOG, |
252 |
|
|
"transient-for", parent_window, |
253 |
|
|
"use-header-bar", 1, |
254 |
|
|
"device", device, |
255 |
|
|
NULL)); |
256 |
|
|
} |
257 |
|
|
|