[nautilus] special-location-bar: Extend to support Public folder for sharing
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] special-location-bar: Extend to support Public folder for sharing
- Date: Fri, 15 Jul 2022 06:59:48 +0000 (UTC)
commit c92e98c4bb904b5746ab88efdb5d6f05473e6221
Author: Corey Berla <corey berla me>
Date: Thu Jul 14 16:10:51 2022 -0700
special-location-bar: Extend to support Public folder for sharing
gnome-user-share maintains an extension to create an info bar
in the ~/Public folder notifying the user of the ability to turn
on file sharing. This is broken with 43.alpha because of gtk3-gtk4.
This is a core feature and it will be easier to implement and
maintain in Nautilus itself rather than as an extension.
Extend special-location-bar for the Public folder / sharing.
Use dbus-launcher to open Settings to the "sharing" panel on
button click.
Fixes: https://gitlab.gnome.org/GNOME/gnome-user-share/-/issues/26
Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2155
See: https://gitlab.gnome.org/GNOME/gnome-user-share/-/merge_requests/18
src/nautilus-special-location-bar.c | 62 +++++++++++++++++++++++++++++++++++++
src/nautilus-special-location-bar.h | 5 +--
2 files changed, 65 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-special-location-bar.c b/src/nautilus-special-location-bar.c
index 4e81ff3b5..2c4c5d510 100644
--- a/src/nautilus-special-location-bar.c
+++ b/src/nautilus-special-location-bar.c
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include <string.h>
+#include "nautilus-dbus-launcher.h"
#include "nautilus-special-location-bar.h"
#include "nautilus-enum-types.h"
@@ -31,6 +32,8 @@ struct _NautilusSpecialLocationBar
GtkWidget *label;
GtkWidget *learn_more_label;
+ GtkWidget *button;
+ int button_response;
NautilusSpecialLocation special_location;
};
@@ -40,14 +43,49 @@ enum
PROP_SPECIAL_LOCATION,
};
+enum
+{
+ SPECIAL_LOCATION_SHARING_RESPONSE = 1,
+};
+
G_DEFINE_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, ADW_TYPE_BIN)
+static void
+on_info_bar_response (GtkInfoBar *infobar,
+ gint response_id,
+ gpointer user_data)
+{
+ NautilusSpecialLocationBar *bar = user_data;
+
+ switch (bar->button_response)
+ {
+ case SPECIAL_LOCATION_SHARING_RESPONSE:
+ {
+ GVariant *parameters;
+
+ parameters = g_variant_new_parsed ("('launch-panel', [<('sharing', @av [])>], "
+ "@a{sv} {})");
+ nautilus_dbus_launcher_call (nautilus_dbus_launcher_get (),
+ NAUTILUS_DBUS_LAUNCHER_SETTINGS,
+ "Activate",
+ parameters, NULL);
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ }
+}
+
static void
set_special_location (NautilusSpecialLocationBar *bar,
NautilusSpecialLocation location)
{
char *message;
char *learn_more_markup = NULL;
+ char *button_label = NULL;
switch (location)
{
@@ -64,6 +102,14 @@ set_special_location (NautilusSpecialLocationBar *bar,
}
break;
+ case NAUTILUS_SPECIAL_LOCATION_SHARING:
+ {
+ message = g_strdup (_("Turn on File Sharing to share the contents of this folder over the
network."));
+ button_label = _("Sharing Settings");
+ bar->button_response = SPECIAL_LOCATION_SHARING_RESPONSE;
+ }
+ break;
+
default:
{
g_assert_not_reached ();
@@ -86,6 +132,16 @@ set_special_location (NautilusSpecialLocationBar *bar,
{
gtk_widget_hide (bar->learn_more_label);
}
+
+ if (button_label)
+ {
+ gtk_button_set_label (GTK_BUTTON (bar->button), button_label);
+ gtk_widget_show (bar->button);
+ }
+ else
+ {
+ gtk_widget_hide (bar->button);
+ }
}
static void
@@ -164,6 +220,7 @@ nautilus_special_location_bar_init (NautilusSpecialLocationBar *bar)
{
GtkWidget *info_bar;
PangoAttrList *attrs;
+ GtkWidget *button;
info_bar = gtk_info_bar_new ();
gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
@@ -179,10 +236,15 @@ nautilus_special_location_bar_init (NautilusSpecialLocationBar *bar)
gtk_label_set_ellipsize (GTK_LABEL (bar->label), PANGO_ELLIPSIZE_END);
gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), bar->label);
+ button = gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), "", GTK_RESPONSE_OK);
+ bar->button = button;
+
bar->learn_more_label = gtk_label_new (NULL);
gtk_widget_set_hexpand (bar->learn_more_label, TRUE);
gtk_widget_set_halign (bar->learn_more_label, GTK_ALIGN_END);
gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), bar->learn_more_label);
+
+ g_signal_connect (info_bar, "response", G_CALLBACK (on_info_bar_response), bar);
}
GtkWidget *
diff --git a/src/nautilus-special-location-bar.h b/src/nautilus-special-location-bar.h
index 58928d9f8..3680b58f0 100644
--- a/src/nautilus-special-location-bar.h
+++ b/src/nautilus-special-location-bar.h
@@ -28,8 +28,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, NAUTILUS,
SPECIAL_LOCATION_BAR, AdwBin)
typedef enum {
- NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
- NAUTILUS_SPECIAL_LOCATION_SCRIPTS,
+ NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
+ NAUTILUS_SPECIAL_LOCATION_SCRIPTS,
+ NAUTILUS_SPECIAL_LOCATION_SHARING,
} NautilusSpecialLocation;
GtkWidget *nautilus_special_location_bar_new (NautilusSpecialLocation location);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]