summaryrefslogtreecommitdiff
path: root/chooser
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2018-12-23 19:41:42 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2018-12-25 12:46:11 +0100
commitacbf696a8d275d6ef7e340d40ae9b68845d7c934 (patch)
treefc15aeff596478785390c2093a9c104108a06d62 /chooser
parentcbfbb322602cff5ee0e8b605a406e459b1d0f922 (diff)
downloadgdm-acbf696a8d275d6ef7e340d40ae9b68845d7c934.tar.gz
host-chooser-widget: use G_DECLARE_FINAL_TYPE
Note that we also removed the finalize() method, as that had become empty and only gave warnings due to unused variables.
Diffstat (limited to 'chooser')
-rw-r--r--chooser/gdm-host-chooser-widget.c180
-rw-r--r--chooser/gdm-host-chooser-widget.h25
2 files changed, 82 insertions, 123 deletions
diff --git a/chooser/gdm-host-chooser-widget.c b/chooser/gdm-host-chooser-widget.c
index ae12b1aa..f9bacc12 100644
--- a/chooser/gdm-host-chooser-widget.c
+++ b/chooser/gdm-host-chooser-widget.c
@@ -47,10 +47,10 @@
#include "gdm-chooser-host.h"
#include "gdm-host-chooser-widget.h"
-#define GDM_HOST_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidgetPrivate))
-
-struct GdmHostChooserWidgetPrivate
+struct _GdmHostChooserWidget
{
+ GtkBox parent;
+
GtkWidget *treeview;
int kind_mask;
@@ -88,7 +88,6 @@ static guint signals [LAST_SIGNAL] = { 0, };
static void gdm_host_chooser_widget_class_init (GdmHostChooserWidgetClass *klass);
static void gdm_host_chooser_widget_init (GdmHostChooserWidget *host_chooser_widget);
-static void gdm_host_chooser_widget_finalize (GObject *object);
G_DEFINE_TYPE (GdmHostChooserWidget, gdm_host_chooser_widget, GTK_TYPE_BOX)
@@ -107,7 +106,7 @@ static void
chooser_host_add (GdmHostChooserWidget *widget,
GdmChooserHost *host)
{
- widget->priv->chooser_hosts = g_slist_prepend (widget->priv->chooser_hosts, host);
+ widget->chooser_hosts = g_slist_prepend (widget->chooser_hosts, host);
}
#if 0
@@ -115,7 +114,7 @@ static void
chooser_host_remove (GdmHostChooserWidget *widget,
GdmChooserHost *host)
{
- widget->priv->chooser_hosts = g_slist_remove (widget->priv->chooser_hosts, host);
+ widget->chooser_hosts = g_slist_remove (widget->chooser_hosts, host);
}
#endif
@@ -153,7 +152,7 @@ find_known_host (GdmHostChooserWidget *widget,
GSList *li;
GdmChooserHost *host;
- for (li = widget->priv->chooser_hosts; li != NULL; li = li->next) {
+ for (li = widget->chooser_hosts; li != NULL; li = li->next) {
GdmAddress *other_address;
host = li->data;
@@ -203,7 +202,7 @@ browser_add_host (GdmHostChooserWidget *widget,
g_free (name);
g_free (desc);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget->priv->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget->treeview));
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model),
@@ -214,7 +213,7 @@ browser_add_host (GdmHostChooserWidget *widget,
-1);
g_free (label);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->priv->treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->treeview));
if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) {
gtk_tree_selection_select_iter (selection, &iter);
}
@@ -249,7 +248,7 @@ decode_packet (GIOChannel *source,
ss_len = (int) sizeof (clnt_ss);
- res = XdmcpFill (widget->priv->socket_fd, &buf, (XdmcpNetaddr)&clnt_ss, &ss_len);
+ res = XdmcpFill (widget->socket_fd, &buf, (XdmcpNetaddr)&clnt_ss, &ss_len);
if G_UNLIKELY (! res) {
g_debug (_("XDMCP: Could not create XDMCP buffer!"));
return TRUE;
@@ -339,7 +338,7 @@ do_ping (GdmHostChooserWidget *widget,
g_debug ("do ping full:%d", full);
- for (l = widget->priv->broadcast_addresses; l != NULL; l = l->next) {
+ for (l = widget->broadcast_addresses; l != NULL; l = l->next) {
GdmAddress *address;
int res;
@@ -347,9 +346,9 @@ do_ping (GdmHostChooserWidget *widget,
gdm_address_debug (address);
errno = 0;
- g_debug ("fd:%d", widget->priv->socket_fd);
- res = XdmcpFlush (widget->priv->socket_fd,
- &widget->priv->broadcast_buf,
+ g_debug ("fd:%d", widget->socket_fd);
+ res = XdmcpFlush (widget->socket_fd,
+ &widget->broadcast_buf,
(XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
(int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
@@ -359,15 +358,15 @@ do_ping (GdmHostChooserWidget *widget,
}
if (full) {
- for (l = widget->priv->query_addresses; l != NULL; l = l->next) {
+ for (l = widget->query_addresses; l != NULL; l = l->next) {
GdmAddress *address;
int res;
address = l->data;
gdm_address_debug (address);
- res = XdmcpFlush (widget->priv->socket_fd,
- &widget->priv->query_buf,
+ res = XdmcpFlush (widget->socket_fd,
+ &widget->query_buf,
(XdmcpNetaddr)gdm_address_peek_sockaddr_storage (address),
(int)gdm_sockaddr_len (gdm_address_peek_sockaddr_storage (address)));
if (! res) {
@@ -382,10 +381,10 @@ ping_try (GdmHostChooserWidget *widget)
{
do_ping (widget, FALSE);
- widget->priv->ping_tries --;
+ widget->ping_tries --;
- if (widget->priv->ping_tries <= 0) {
- widget->priv->ping_try_id = 0;
+ if (widget->ping_tries <= 0) {
+ widget->ping_try_id = 0;
return FALSE;
} else {
return TRUE;
@@ -415,23 +414,23 @@ xdmcp_discover (GdmHostChooserWidget *widget)
do_ping (widget, TRUE);
#if 0
- if (widget->priv->scan_time_id > 0) {
- g_source_remove (widget->priv->scan_time_id);
+ if (widget->scan_time_id > 0) {
+ g_source_remove (widget->scan_time_id);
}
- widget->priv->scan_time_id = g_timeout_add_seconds (SCAN_TIMEOUT,
+ widget->scan_time_id = g_timeout_add_seconds (SCAN_TIMEOUT,
chooser_scan_time_update,
widget);
#endif
/* Note we already used up one try */
- widget->priv->ping_tries = PING_TRIES - 1;
- if (widget->priv->ping_try_id > 0) {
- g_source_remove (widget->priv->ping_try_id);
+ widget->ping_tries = PING_TRIES - 1;
+ if (widget->ping_try_id > 0) {
+ g_source_remove (widget->ping_try_id);
}
- widget->priv->ping_try_id = g_timeout_add_seconds (PING_TIMEOUT,
- (GSourceFunc)ping_try,
- widget);
+ widget->ping_try_id = g_timeout_add_seconds (PING_TIMEOUT,
+ (GSourceFunc)ping_try,
+ widget);
}
/* Find broadcast address for all active, non pointopoint interfaces */
@@ -501,7 +500,7 @@ find_broadcast_addresses (GdmHostChooserWidget *widget)
g_debug ("Adding if %s", name);
gdm_address_debug (address);
- widget->priv->broadcast_addresses = g_slist_append (widget->priv->broadcast_addresses, address);
+ widget->broadcast_addresses = g_slist_append (widget->broadcast_addresses, address);
}
}
}
@@ -515,7 +514,7 @@ add_hosts (GdmHostChooserWidget *widget)
{
int i;
- for (i = 0; widget->priv->hosts != NULL && widget->priv->hosts[i] != NULL; i++) {
+ for (i = 0; widget->hosts != NULL && widget->hosts[i] != NULL; i++) {
struct addrinfo hints;
struct addrinfo *result;
struct addrinfo *ai;
@@ -524,7 +523,7 @@ add_hosts (GdmHostChooserWidget *widget)
char serv_buf [NI_MAXSERV];
const char *serv;
- name = widget->priv->hosts[i];
+ name = widget->hosts[i];
if (strcmp (name, "BROADCAST") == 0) {
find_broadcast_addresses (widget);
@@ -554,14 +553,14 @@ add_hosts (GdmHostChooserWidget *widget)
address = gdm_address_new_from_sockaddr (ai->ai_addr, ai->ai_addrlen);
if (address != NULL) {
- widget->priv->query_addresses = g_slist_append (widget->priv->query_addresses, address);
+ widget->query_addresses = g_slist_append (widget->query_addresses, address);
}
}
freeaddrinfo (result);
}
- if (widget->priv->broadcast_addresses == NULL && widget->priv->query_addresses == NULL) {
+ if (widget->broadcast_addresses == NULL && widget->query_addresses == NULL) {
find_broadcast_addresses (widget);
}
}
@@ -577,30 +576,30 @@ xdmcp_init (GdmHostChooserWidget *widget)
sockopts = 1;
- widget->priv->socket_fd = -1;
+ widget->socket_fd = -1;
/* Open socket for communication */
#ifdef ENABLE_IPV6
- widget->priv->socket_fd = socket (AF_INET6, SOCK_DGRAM, 0);
- if (widget->priv->socket_fd != -1) {
- widget->priv->have_ipv6 = TRUE;
+ widget->socket_fd = socket (AF_INET6, SOCK_DGRAM, 0);
+ if (widget->socket_fd != -1) {
+ widget->have_ipv6 = TRUE;
#ifdef IPV6_V6ONLY
{
int zero = 0;
- if (setsockopt(widget->priv->socket_fd, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) < 0)
+ if (setsockopt(widget->socket_fd, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) < 0)
g_warning("setsockopt(IPV6_V6ONLY): %s", g_strerror(errno));
}
#endif
}
#endif
- if (! widget->priv->have_ipv6) {
- widget->priv->socket_fd = socket (AF_INET, SOCK_DGRAM, 0);
- if (widget->priv->socket_fd == -1) {
+ if (! widget->have_ipv6) {
+ widget->socket_fd = socket (AF_INET, SOCK_DGRAM, 0);
+ if (widget->socket_fd == -1) {
g_critical ("Could not create socket!");
}
}
- res = setsockopt (widget->priv->socket_fd,
+ res = setsockopt (widget->socket_fd,
SOL_SOCKET,
SO_BROADCAST,
(char *) &sockopts,
@@ -615,27 +614,27 @@ xdmcp_init (GdmHostChooserWidget *widget)
header.length = 1;
header.version = XDM_PROTOCOL_VERSION;
aanames.length = 0;
- XdmcpWriteHeader (&widget->priv->broadcast_buf, &header);
- XdmcpWriteARRAYofARRAY8 (&widget->priv->broadcast_buf, &aanames);
+ XdmcpWriteHeader (&widget->broadcast_buf, &header);
+ XdmcpWriteARRAYofARRAY8 (&widget->broadcast_buf, &aanames);
/* Assemble XDMCP QUERY packet in static buffer */
memset (&header, 0, sizeof (XdmcpHeader));
header.opcode = (CARD16) QUERY;
header.length = 1;
header.version = XDM_PROTOCOL_VERSION;
- memset (&widget->priv->query_buf, 0, sizeof (XdmcpBuffer));
- XdmcpWriteHeader (&widget->priv->query_buf, &header);
- XdmcpWriteARRAYofARRAY8 (&widget->priv->query_buf, &aanames);
+ memset (&widget->query_buf, 0, sizeof (XdmcpBuffer));
+ XdmcpWriteHeader (&widget->query_buf, &header);
+ XdmcpWriteARRAYofARRAY8 (&widget->query_buf, &aanames);
add_hosts (widget);
- ioc = g_io_channel_unix_new (widget->priv->socket_fd);
+ ioc = g_io_channel_unix_new (widget->socket_fd);
g_io_channel_set_encoding (ioc, NULL, NULL);
g_io_channel_set_buffered (ioc, FALSE);
- widget->priv->io_watch_id = g_io_add_watch (ioc,
- G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
- (GIOFunc)decode_packet,
- widget);
+ widget->io_watch_id = g_io_add_watch (ioc,
+ G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ (GIOFunc)decode_packet,
+ widget);
g_io_channel_unref (ioc);
}
@@ -655,8 +654,8 @@ gdm_host_chooser_widget_get_host (GdmHostChooserWidget *widget)
g_return_val_if_fail (GDM_IS_HOST_CHOOSER_WIDGET (widget), NULL);
host = NULL;
- if (widget->priv->current_host != NULL) {
- host = g_object_ref (widget->priv->current_host);
+ if (widget->current_host != NULL) {
+ host = g_object_ref (widget->current_host);
}
return host;
@@ -666,8 +665,8 @@ static void
_gdm_host_chooser_widget_set_kind_mask (GdmHostChooserWidget *widget,
int kind_mask)
{
- if (widget->priv->kind_mask != kind_mask) {
- widget->priv->kind_mask = kind_mask;
+ if (widget->kind_mask != kind_mask) {
+ widget->kind_mask = kind_mask;
}
}
@@ -730,29 +729,29 @@ gdm_host_chooser_widget_dispose (GObject *object)
g_debug ("Disposing host_chooser_widget");
- if (widget->priv->broadcast_addresses != NULL) {
- g_slist_foreach (widget->priv->broadcast_addresses,
+ if (widget->broadcast_addresses != NULL) {
+ g_slist_foreach (widget->broadcast_addresses,
(GFunc)gdm_address_free,
NULL);
- g_slist_free (widget->priv->broadcast_addresses);
- widget->priv->broadcast_addresses = NULL;
+ g_slist_free (widget->broadcast_addresses);
+ widget->broadcast_addresses = NULL;
}
- if (widget->priv->query_addresses != NULL) {
- g_slist_foreach (widget->priv->query_addresses,
+ if (widget->query_addresses != NULL) {
+ g_slist_foreach (widget->query_addresses,
(GFunc)gdm_address_free,
NULL);
- g_slist_free (widget->priv->query_addresses);
- widget->priv->query_addresses = NULL;
+ g_slist_free (widget->query_addresses);
+ widget->query_addresses = NULL;
}
- if (widget->priv->chooser_hosts != NULL) {
- g_slist_foreach (widget->priv->chooser_hosts,
+ if (widget->chooser_hosts != NULL) {
+ g_slist_foreach (widget->chooser_hosts,
(GFunc)g_object_unref,
NULL);
- g_slist_free (widget->priv->chooser_hosts);
- widget->priv->chooser_hosts = NULL;
+ g_slist_free (widget->chooser_hosts);
+ widget->chooser_hosts = NULL;
}
- widget->priv->current_host = NULL;
+ widget->current_host = NULL;
G_OBJECT_CLASS (gdm_host_chooser_widget_parent_class)->dispose (object);
}
@@ -766,7 +765,6 @@ gdm_host_chooser_widget_class_init (GdmHostChooserWidgetClass *klass)
object_class->set_property = gdm_host_chooser_widget_set_property;
object_class->constructor = gdm_host_chooser_widget_constructor;
object_class->dispose = gdm_host_chooser_widget_dispose;
- object_class->finalize = gdm_host_chooser_widget_finalize;
g_object_class_install_property (object_class,
PROP_KIND_MASK,
@@ -781,14 +779,12 @@ gdm_host_chooser_widget_class_init (GdmHostChooserWidgetClass *klass)
signals [HOST_ACTIVATED] = g_signal_new ("host-activated",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GdmHostChooserWidgetClass, host_activated),
+ 0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
-
- g_type_class_add_private (klass, sizeof (GdmHostChooserWidgetPrivate));
}
static void
@@ -805,7 +801,7 @@ on_host_selected (GtkTreeSelection *selection,
gtk_tree_model_get (model, &iter, CHOOSER_LIST_HOST_COLUMN, &curhost, -1);
}
- widget->priv->current_host = curhost;
+ widget->current_host = curhost;
}
static void
@@ -825,8 +821,6 @@ gdm_host_chooser_widget_init (GdmHostChooserWidget *widget)
GtkTreeViewColumn *column;
GtkTreeModel *model;
- widget->priv = GDM_HOST_CHOOSER_WIDGET_GET_PRIVATE (widget);
-
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
GTK_SHADOW_IN);
@@ -834,15 +828,15 @@ gdm_host_chooser_widget_init (GdmHostChooserWidget *widget)
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (widget), scrolled, TRUE, TRUE, 0);
- widget->priv->treeview = gtk_tree_view_new ();
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (widget->priv->treeview), FALSE);
- g_signal_connect (widget->priv->treeview,
+ widget->treeview = gtk_tree_view_new ();
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (widget->treeview), FALSE);
+ g_signal_connect (widget->treeview,
"row-activated",
G_CALLBACK (on_row_activated),
widget);
- gtk_container_add (GTK_CONTAINER (scrolled), widget->priv->treeview);
+ gtk_container_add (GTK_CONTAINER (scrolled), widget->treeview);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->priv->treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->treeview));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed",
G_CALLBACK (on_host_selected),
@@ -852,46 +846,32 @@ gdm_host_chooser_widget_init (GdmHostChooserWidget *widget)
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
G_TYPE_POINTER);
- gtk_tree_view_set_model (GTK_TREE_VIEW (widget->priv->treeview), model);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (widget->treeview), model);
column = gtk_tree_view_column_new_with_attributes ("Icon",
gtk_cell_renderer_pixbuf_new (),
"pixbuf", CHOOSER_LIST_ICON_COLUMN,
NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (widget->priv->treeview), column);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (widget->treeview), column);
column = gtk_tree_view_column_new_with_attributes ("Hostname",
gtk_cell_renderer_text_new (),
"markup", CHOOSER_LIST_LABEL_COLUMN,
NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (widget->priv->treeview), column);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (widget->treeview), column);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
CHOOSER_LIST_LABEL_COLUMN,
GTK_SORT_ASCENDING);
}
-static void
-gdm_host_chooser_widget_finalize (GObject *object)
-{
- GdmHostChooserWidget *host_chooser_widget;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GDM_IS_HOST_CHOOSER_WIDGET (object));
-
- host_chooser_widget = GDM_HOST_CHOOSER_WIDGET (object);
-
- g_return_if_fail (host_chooser_widget->priv != NULL);
-
- G_OBJECT_CLASS (gdm_host_chooser_widget_parent_class)->finalize (object);
-}
-
GtkWidget *
gdm_host_chooser_widget_new (int kind_mask)
{
GObject *object;
object = g_object_new (GDM_TYPE_HOST_CHOOSER_WIDGET,
+ "orientation", GTK_ORIENTATION_VERTICAL,
"kind-mask", kind_mask,
NULL);
diff --git a/chooser/gdm-host-chooser-widget.h b/chooser/gdm-host-chooser-widget.h
index 739eac01..48ce4194 100644
--- a/chooser/gdm-host-chooser-widget.h
+++ b/chooser/gdm-host-chooser-widget.h
@@ -27,30 +27,9 @@
G_BEGIN_DECLS
-#define GDM_TYPE_HOST_CHOOSER_WIDGET (gdm_host_chooser_widget_get_type ())
-#define GDM_HOST_CHOOSER_WIDGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidget))
-#define GDM_HOST_CHOOSER_WIDGET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidgetClass))
-#define GDM_IS_HOST_CHOOSER_WIDGET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_HOST_CHOOSER_WIDGET))
-#define GDM_IS_HOST_CHOOSER_WIDGET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_HOST_CHOOSER_WIDGET))
-#define GDM_HOST_CHOOSER_WIDGET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_HOST_CHOOSER_WIDGET, GdmHostChooserWidgetClass))
+#define GDM_TYPE_HOST_CHOOSER_WIDGET (gdm_host_chooser_widget_get_type ())
+G_DECLARE_FINAL_TYPE (GdmHostChooserWidget, gdm_host_chooser_widget, GDM, HOST_CHOOSER_WIDGET, GtkBox)
-typedef struct GdmHostChooserWidgetPrivate GdmHostChooserWidgetPrivate;
-
-typedef struct
-{
- GtkVBox parent;
- GdmHostChooserWidgetPrivate *priv;
-} GdmHostChooserWidget;
-
-typedef struct
-{
- GtkVBoxClass parent_class;
-
- /* signals */
- void (* host_activated) (GdmHostChooserWidget *widget);
-} GdmHostChooserWidgetClass;
-
-GType gdm_host_chooser_widget_get_type (void);
GtkWidget * gdm_host_chooser_widget_new (int kind_mask);
void gdm_host_chooser_widget_set_kind_mask (GdmHostChooserWidget *widget,