mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
Add a gnet utility
This is currently just a wrapper around GNetworkMonitor.
This commit is contained in:
parent
2705fa7b55
commit
3c1902fcf9
@ -993,6 +993,14 @@ gio_LDADD = libgio-2.0.la \
|
||||
$(top_builddir)/glib/libglib-2.0.la \
|
||||
$(NULL)
|
||||
|
||||
bin_PROGRAMS += gnet
|
||||
gnet_SOURCES = \
|
||||
gnet-tool.c
|
||||
gnet_LDADD = libgio-2.0.la \
|
||||
$(top_builddir)/gobject/libgobject-2.0.la \
|
||||
$(top_builddir)/glib/libglib-2.0.la \
|
||||
$(NULL)
|
||||
|
||||
dist-hook: $(BUILT_EXTRA_DIST)
|
||||
files='$(BUILT_EXTRA_DIST)'; \
|
||||
for f in $$files; do \
|
||||
|
77
gio/gnet-tool.c
Normal file
77
gio/gnet-tool.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2015 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gi18n.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
static void
|
||||
network_changed (GNetworkMonitor *nm,
|
||||
gboolean available,
|
||||
gpointer data)
|
||||
{
|
||||
g_print ("::network-changed available: %d\n", available);
|
||||
}
|
||||
|
||||
static void
|
||||
notify (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer data)
|
||||
{
|
||||
GNetworkMonitor *nm = G_NETWORK_MONITOR (object);
|
||||
|
||||
g_print ("notify::");
|
||||
if (strcmp (pspec->name, "network-available") == 0)
|
||||
g_print ("network-available: %d\n", g_network_monitor_get_network_available (nm));
|
||||
else if (strcmp (pspec->name, "network-metered") == 0)
|
||||
g_print ("network-metered: %d\n", g_network_monitor_get_network_metered (nm));
|
||||
else if (strcmp (pspec->name, "connectivity") == 0)
|
||||
g_print ("connectivity: %d\n", g_network_monitor_get_connectivity (nm));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GNetworkMonitor *nm;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
|
||||
|
||||
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
#endif
|
||||
|
||||
nm = g_network_monitor_get_default ();
|
||||
g_print ("Using %s\n", g_type_name_from_instance (nm));
|
||||
|
||||
g_signal_connect (nm, "network-changed", G_CALLBACK (network_changed), NULL);
|
||||
g_signal_connect (nm, "notify", G_CALLBACK (notify), NULL);
|
||||
|
||||
while (TRUE)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user