GCC Code Coverage Report


Directory: ./
File: panels/network/connection-editor/ce-ip-address-entry.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 26 0.0%
Functions: 0 10 0.0%
Branches: 0 17 0.0%

Line Branch Exec Source
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2020 Canonical Ltd.
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <NetworkManager.h>
23
24 #include "ce-ip-address-entry.h"
25
26 struct _CEIPAddressEntry
27 {
28 GtkEntry parent_instance;
29
30 int family;
31 };
32
33 static void ce_ip_address_entry_editable_init (GtkEditableInterface *iface);
34
35 G_DEFINE_TYPE_WITH_CODE (CEIPAddressEntry, ce_ip_address_entry, GTK_TYPE_ENTRY,
36 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
37 ce_ip_address_entry_editable_init))
38
39 static void
40 ce_ip_address_entry_changed (GtkEditable *editable)
41 {
42 CEIPAddressEntry *self = CE_IP_ADDRESS_ENTRY (editable);
43
44 if (ce_ip_address_entry_is_valid (self))
45 gtk_widget_remove_css_class (GTK_WIDGET (self), "error");
46 else
47 gtk_widget_add_css_class (GTK_WIDGET (self), "error");
48 }
49
50 static void
51 ce_ip_address_entry_init (CEIPAddressEntry *self)
52 {
53 }
54
55 static void
56 ce_ip_address_entry_editable_init (GtkEditableInterface *iface)
57 {
58 iface->changed = ce_ip_address_entry_changed;
59 }
60
61 static void
62 ce_ip_address_entry_class_init (CEIPAddressEntryClass *klass)
63 {
64 }
65
66 CEIPAddressEntry *
67 ce_ip_address_entry_new (int family)
68 {
69 CEIPAddressEntry *self;
70
71 self = CE_IP_ADDRESS_ENTRY (g_object_new (ce_ip_address_entry_get_type (), NULL));
72 self->family = family;
73
74 return self;
75 }
76
77 gboolean
78 ce_ip_address_entry_is_empty (CEIPAddressEntry *self)
79 {
80 const gchar *text;
81
82 g_return_val_if_fail (CE_IS_IP_ADDRESS_ENTRY (self), FALSE);
83
84 text = gtk_editable_get_text (GTK_EDITABLE (self));
85 return text[0] == '\0';
86 }
87
88 gboolean
89 ce_ip_address_entry_is_valid (CEIPAddressEntry *self)
90 {
91 const gchar *text;
92
93 g_return_val_if_fail (CE_IS_IP_ADDRESS_ENTRY (self), FALSE);
94
95 text = gtk_editable_get_text (GTK_EDITABLE (self));
96 return text[0] == '\0' || nm_utils_ipaddr_valid (self->family, text);
97 }
98