Commit c251ddcd authored by Jens Georg's avatar Jens Georg
Browse files

Port sniffer to GTK4

parent 41981fff
Pipeline #290908 passed with stages
in 2 minutes and 10 seconds
......@@ -61,9 +61,9 @@ check-merge-request:
.gssdp.fedora@common:
variables:
BASE_TAG: '2021-05-22.0'
BASE_TAG: '2021-06-19.0'
FDO_UPSTREAM_REPO: GNOME/gssdp
FDO_DISTRIBUTION_PACKAGES: 'clang clang-analyzer gcovr git libasan libubsan python3-gobject python3-pip xmlto'
FDO_DISTRIBUTION_PACKAGES: 'clang clang-analyzer gcovr git libasan libubsan python3-gobject python3-pip xmlto gtk4-devel'
FDO_DISTRIBUTION_EXEC: |
dnf install -y 'dnf-command(builddep)' &&
dnf builddep -y gssdp --setopt=install_weak_deps=False &&
......
......@@ -75,7 +75,7 @@ subdir('libgssdp')
subdir('tests')
if get_option('sniffer')
gtk = dependency('gtk+-3.0', version : '>= 3.12')
gtk = dependency('gtk4', version : '>= 4')
subdir('tools')
endif
......
......@@ -3,4 +3,7 @@
<gresource prefix="/org/gupnp/GSSDP">
<file preprocess="xml-stripblanks" alias="MainWindow.ui">main-window.ui</file>
</gresource>
<gresource prefix="/org/gupnp">
<file preprocess="xml-stripblanks" alias="Logo.svg">images/gupnp-logo-short.svg</file>
</gresource>
</gresources>
......@@ -12,6 +12,8 @@
#include <libsoup/soup.h>
#define LOGO_RESOURCE "/org/gupnp/Logo.svg"
typedef enum
{
PACKET_STORE_COLUMN_TIME,
......@@ -52,7 +54,7 @@ struct _GSSDPDeviceSnifferMainWindow {
// Bound child widgets
GtkWidget *packet_treeview;
GtkWidget *packet_textview;
GtkWidget *capture_button_image;
GtkWidget *capture_button;
GtkWidget *device_treeview;
GtkWidget *details_scrolled;
GMenuModel *sniffer_context_menu;
......@@ -114,9 +116,7 @@ main_window_set_property (GObject *object,
? "media-playback-stop-symbolic"
: "media-playback-start-symbolic";
gtk_image_set_from_icon_name (GTK_IMAGE (self->capture_button_image),
icon_name,
GTK_ICON_SIZE_BUTTON);
gtk_button_set_icon_name(GTK_BUTTON (self->capture_button), icon_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -229,8 +229,8 @@ on_ssdp_message (GSSDPClient *ssdp_client,
return;
if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (self->searchbar))) {
const char *filter =
gtk_entry_get_text (GTK_ENTRY (self->address_filter));
const char *filter = gtk_editable_get_text (
GTK_EDITABLE (self->address_filter));
if (filter != NULL && strcmp (filter, from_ip) != 0)
return;
}
......@@ -453,7 +453,7 @@ gssdp_device_sniffer_main_window_class_init (
gtk_widget_class_bind_template_child (widget_class,
GSSDPDeviceSnifferMainWindow,
capture_button_image);
capture_button);
gtk_widget_class_bind_template_child (widget_class,
GSSDPDeviceSnifferMainWindow,
......@@ -531,23 +531,18 @@ on_realize (GtkWidget *self, gpointer user_data)
{
double w;
double h;
#if GTK_CHECK_VERSION(3, 22, 0)
{
GdkWindow *window = gtk_widget_get_window (self);
GdkDisplay *display = gdk_display_get_default ();
GdkMonitor *monitor =
gdk_display_get_monitor_at_window (display, window);
GdkRectangle rectangle;
gdk_monitor_get_geometry (monitor, &rectangle);
w = rectangle.width * 0.75;
h = rectangle.height * 0.75;
}
#else
w = gdk_screen_width () * 0.75;
h = gdk_screen_height () * 0.75;
#endif
GtkNative *native = gtk_widget_get_native (self);
GdkSurface *surface = gtk_native_get_surface (native);
GdkDisplayManager *mgr = gdk_display_manager_get ();
GdkDisplay *display = gdk_display_manager_get_default_display (mgr);
GdkMonitor *monitor =
gdk_display_get_monitor_at_surface (display, surface);
GdkRectangle rectangle;
gdk_monitor_get_geometry (monitor, &rectangle);
w = rectangle.width * 0.75;
h = rectangle.height * 0.75;
int window_width = CLAMP ((int) w, 10, 1000);
int window_height = CLAMP ((int) h, 10, 800);
......@@ -672,7 +667,11 @@ static void
on_about (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
const char *AUTHORS[] = { "Zeeshan Ali (Khattak) <zeeshanak@gnome.org>",
"Jens Georg <mail@jensge.org>",
NULL };
GdkTexture *logo = gdk_texture_new_from_resource (LOGO_RESOURCE);
gtk_show_about_dialog (
GTK_WINDOW (user_data),
"copyright",
......@@ -688,7 +687,10 @@ on_about (GSimpleAction *action, GVariant *parameter, gpointer user_data)
"translator-credits",
"license-type",
GTK_LICENSE_LGPL_2_1,
"logo", logo,
NULL);
g_object_unref (logo);
}
static void
......@@ -712,7 +714,7 @@ on_set_address_filter (GSimpleAction *action,
PACKET_STORE_COLUMN_IP,
&ip_filter,
-1);
gtk_entry_set_text (GTK_ENTRY (self->address_filter), ip_filter);
gtk_editable_set_text (GTK_EDITABLE (self->address_filter), ip_filter);
g_free (ip_filter);
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (self->searchbar), TRUE);
......@@ -726,46 +728,43 @@ static GActionEntry actions[] = { { "clear-capture", on_clear_capture },
on_set_address_filter } };
static void
do_popup_menu (GSSDPDeviceSnifferMainWindow *self, GdkEventButton *event)
{
gtk_menu_popup_at_pointer (GTK_MENU (self->context_menu),
(event != NULL) ? (GdkEvent *) event
: gtk_get_current_event ());
}
static gboolean
on_popup_menu (GtkWidget *widget, gpointer user_data)
on_button_release (GtkGesture *click,
int n_press,
gdouble x,
gdouble y,
gpointer user_data)
{
GSSDPDeviceSnifferMainWindow *self =
GSSDP_DEVICE_SNIFFER_MAIN_WINDOW (user_data);
do_popup_menu (self, NULL);
GdkEventSequence *sequence = gtk_gesture_single_get_current_sequence (
GTK_GESTURE_SINGLE (click));
return TRUE;
}
GdkEvent *event = gtk_gesture_get_last_event (click, sequence);
static gboolean
on_button_release (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
GSSDPDeviceSnifferMainWindow *self =
GSSDP_DEVICE_SNIFFER_MAIN_WINDOW (user_data);
if (n_press != 1) {
return;
}
if (!gdk_event_triggers_context_menu (event)) {
return;
}
GtkTreeSelection *selection;
gtk_gesture_set_sequence_state (GTK_GESTURE (click), sequence,
GTK_EVENT_SEQUENCE_CLAIMED);
GtkTreeModel *model;
GtkTreeIter iter;
if (event->type != GDK_BUTTON_RELEASE || event->button != 3) {
return FALSE;
}
selection = gtk_tree_view_get_selection (
GtkTreeSelection *selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (self->packet_treeview));
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
return FALSE;
return;
}
do_popup_menu (self, event);
return TRUE;
GdkRectangle rect = { x, y, 1, 1 };
gtk_popover_set_pointing_to (GTK_POPOVER (self->context_menu), &rect);
gtk_popover_popup (GTK_POPOVER (self->context_menu));
}
static void
......@@ -774,9 +773,20 @@ gssdp_device_sniffer_main_window_init (GSSDPDeviceSnifferMainWindow *self)
gtk_widget_init_template (GTK_WIDGET (self));
self->context_menu =
gtk_menu_new_from_model (self->sniffer_context_menu);
gtk_menu_attach_to_widget(GTK_MENU (self->context_menu), self->packet_treeview, NULL);
gtk_popover_menu_new_from_model (self->sniffer_context_menu);
gtk_widget_set_parent (self->context_menu, self->packet_treeview);
gtk_popover_set_position (GTK_POPOVER (self->context_menu),
GTK_POS_BOTTOM);
gtk_popover_set_has_arrow (GTK_POPOVER (self->context_menu), FALSE);
gtk_widget_set_halign (self->context_menu, GTK_ALIGN_START);
GtkGesture *click = gtk_gesture_click_new ();
gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (click),
"packet-treeview-click");
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (click), 3);
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (click), TRUE);
gtk_widget_add_controller (self->packet_treeview,
GTK_EVENT_CONTROLLER (click));
g_signal_connect (G_OBJECT (self),
"realize",
......@@ -790,13 +800,8 @@ gssdp_device_sniffer_main_window_init (GSSDPDeviceSnifferMainWindow *self)
G_CALLBACK (on_packet_selected),
self);
g_signal_connect (G_OBJECT (self->packet_treeview),
"popup-menu",
G_CALLBACK (on_popup_menu),
self);
g_signal_connect (G_OBJECT (self->packet_treeview),
"button-release-event",
g_signal_connect (G_OBJECT (click),
"pressed",
G_CALLBACK (on_button_release),
self);
......
This diff is collapsed.
resource = gnome.compile_resources(
'org.gupnp.GSSDP.DeviceSniffer',
'gssdp-device-sniffer.gresource.xml'
'gssdp-device-sniffer.gresource.xml',
source_dir: [meson.current_source_dir(), meson.source_root() / 'doc']
)
sniffer = executable(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment