1 /*
2 * Copyright (C) 2007 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8 #include "main-window.h"
9
10 #include <libgssdp/gssdp.h>
11 #include <libgssdp/gssdp-client-private.h>
12 #include <libsoup/soup.h>
13 #include <gtk/gtk.h>
14 #include <string.h>
15 #include <stdlib.h>
16
17
18 static void
on_activate(GtkApplication * app)19 on_activate (GtkApplication *app)
20 {
21 GtkWindow *window;
22
23 window = gtk_application_get_active_window (app);
24 if (window == NULL) {
25 window = g_object_new (GSSDP_DEVICE_SNIFFER_TYPE_MAIN_WINDOW,
26 "application",
27 app,
28 NULL);
29 }
30
31 gtk_window_present (window);
32 }
33
34 static int
on_command_line(GtkApplication * app,GApplicationCommandLine * cmdline,gpointer user_data)35 on_command_line (GtkApplication *app,
36 GApplicationCommandLine *cmdline,
37 gpointer user_data)
38 {
39 char *iface = NULL;
40 GSocketFamily family = G_SOCKET_FAMILY_INVALID;
41 gboolean six = FALSE;
42
43
44 GVariantDict *args = g_application_command_line_get_options_dict (cmdline);
45
46 GOptionContext *context = g_option_context_new (NULL);
47 g_option_context_set_help_enabled (context, FALSE);
48
49 g_variant_dict_lookup (args, "interface" ,"s", &iface);
50 g_variant_dict_lookup (args, "prefer-v6", "b", &six);
51
52
53 if (six) {
54 family = G_SOCKET_FAMILY_IPV6;
55 } else {
56 family = G_SOCKET_FAMILY_IPV4;
57 }
58
59 GtkWindow *window;
60 window = g_object_new (GSSDP_DEVICE_SNIFFER_TYPE_MAIN_WINDOW,
61 "application",
62 app,
63 "address-family",
64 family,
65 "interface",
66 iface,
67 NULL);
68
69 gtk_window_present (window);
70
71 return EXIT_SUCCESS;
72 }
73
74 GOptionEntry entries[] = { { "interface",
75 'i',
76 0,
77 G_OPTION_ARG_STRING,
78 NULL,
79 "Network interface to listen on",
80 NULL },
81 { "prefer-v6",
82 '6',
83 0,
84 G_OPTION_ARG_NONE,
85 NULL,
86 "Prefer IPv6 for the client",
87 NULL },
88 { NULL , 0, 0, 0, NULL, NULL, NULL} };
89
90 gint
main(gint argc,gchar * argv[])91 main (gint argc, gchar *argv[])
92 {
93 g_type_ensure (G_TYPE_DATE_TIME);
94
95 GtkApplication *app =
96 gtk_application_new ("org.gupnp.GSSDP.DeviceSniffer",
97 G_APPLICATION_HANDLES_COMMAND_LINE);
98
99 g_application_add_main_option_entries (G_APPLICATION (app), entries);
100 g_application_set_option_context_parameter_string (
101 G_APPLICATION (app),
102 "- graphical SSDP debug tool");
103
104 g_signal_connect (G_OBJECT (app),
105 "command-line",
106 G_CALLBACK (on_command_line),
107 NULL);
108 g_signal_connect (G_OBJECT (app),
109 "activate",
110 G_CALLBACK (on_activate),
111 NULL);
112
113 return g_application_run (G_APPLICATION (app), argc, argv);
114 }
115