[gtk+] places-sidebar: add optional enter location place



commit 1e925a85ca2acb00f53ce18d72ab3abf003cecbb
Author: William Jon McCann <william jon mccann gmail com>
Date:   Mon Apr 7 18:43:28 2014 -0400

    places-sidebar: add optional enter location place
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722211

 gtk/gtkplacessidebar.c |  104 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkplacessidebar.h |    5 ++
 2 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 7b8fd7a..da0f019 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -165,6 +165,7 @@ struct _GtkPlacesSidebar {
   guint show_desktop_set       : 1;
   guint show_desktop           : 1;
   guint show_connect_to_server : 1;
+  guint show_enter_location    : 1;
   guint local_only             : 1;
 };
 
@@ -192,6 +193,7 @@ struct _GtkPlacesSidebarClass {
                                       GFile              *dest_file,
                                       GList              *source_file_list,
                                       GdkDragAction       action);
+  void    (* show_enter_location)    (GtkPlacesSidebar   *sidebar);
 };
 
 enum {
@@ -219,6 +221,7 @@ typedef enum {
   PLACES_BOOKMARK,
   PLACES_HEADING,
   PLACES_CONNECT_TO_SERVER,
+  PLACES_ENTER_LOCATION,
   PLACES_DROP_FEEDBACK
 } PlaceType;
 
@@ -234,6 +237,7 @@ enum {
   POPULATE_POPUP,
   SHOW_ERROR_MESSAGE,
   SHOW_CONNECT_TO_SERVER,
+  SHOW_ENTER_LOCATION,
   DRAG_ACTION_REQUESTED,
   DRAG_ACTION_ASK,
   DRAG_PERFORM_DROP,
@@ -245,6 +249,7 @@ enum {
   PROP_OPEN_FLAGS,
   PROP_SHOW_DESKTOP,
   PROP_SHOW_CONNECT_TO_SERVER,
+  PROP_SHOW_ENTER_LOCATION,
   PROP_LOCAL_ONLY,
   NUM_PROPERTIES
 };
@@ -363,6 +368,12 @@ emit_show_connect_to_server (GtkPlacesSidebar *sidebar)
   g_signal_emit (sidebar, places_sidebar_signals[SHOW_CONNECT_TO_SERVER], 0);
 }
 
+static void
+emit_show_enter_location (GtkPlacesSidebar *sidebar)
+{
+  g_signal_emit (sidebar, places_sidebar_signals[SHOW_ENTER_LOCATION], 0);
+}
+
 static GdkDragAction
 emit_drag_action_requested (GtkPlacesSidebar *sidebar,
                             GdkDragContext   *context,
@@ -852,6 +863,17 @@ update_places (GtkPlacesSidebar *sidebar)
   /* XDG directories */
   add_special_dirs (sidebar);
 
+  if (sidebar->show_enter_location)
+    {
+      icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
+      add_place (sidebar, PLACES_ENTER_LOCATION,
+                 SECTION_COMPUTER,
+                 _("Enter Location"), icon, NULL,
+                 NULL, NULL, NULL, 0,
+                 _("Manually enter a location"));
+      g_object_unref (icon);
+    }
+
   /* Trash */
   if (!sidebar->local_only)
     {
@@ -2327,6 +2349,10 @@ open_selected_bookmark (GtkPlacesSidebar   *sidebar,
     {
       emit_show_connect_to_server (sidebar);
     }
+  else if (place_type == PLACES_ENTER_LOCATION)
+    {
+      emit_show_enter_location (sidebar);
+    }
   else
     {
       open_selected_volume (sidebar, model, iter, open_flags);
@@ -3899,6 +3925,10 @@ gtk_places_sidebar_set_property (GObject      *obj,
       gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_ENTER_LOCATION:
+      gtk_places_sidebar_set_show_enter_location (sidebar, g_value_get_boolean (value));
+      break;
+
     case PROP_LOCAL_ONLY:
       gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
       break;
@@ -3935,6 +3965,10 @@ gtk_places_sidebar_get_property (GObject    *obj,
       g_value_set_boolean (value, gtk_places_sidebar_get_show_connect_to_server (sidebar));
       break;
 
+    case PROP_SHOW_ENTER_LOCATION:
+      g_value_set_boolean (value, gtk_places_sidebar_get_show_enter_location (sidebar));
+      break;
+
     case PROP_LOCAL_ONLY:
       g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
       break;
@@ -4135,6 +4169,26 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
                         G_TYPE_NONE, 0);
 
   /**
+   * GtkPlacesSidebar::show-enter-location:
+   * @sidebar: the object which received the signal.
+   *
+   * The places sidebar emits this signal when it needs the calling
+   * application to present an way to directly enter a location.
+   * For example, the application may bring up a dialog box asking for
+   * a URL like "http://http.example.com";.
+   *
+   * Since: 3.14
+   */
+  places_sidebar_signals [SHOW_ENTER_LOCATION] =
+          g_signal_new (I_("show-enter-location"),
+                        G_OBJECT_CLASS_TYPE (gobject_class),
+                        G_SIGNAL_RUN_FIRST,
+                        G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_enter_location),
+                        NULL, NULL,
+                        _gtk_marshal_VOID__VOID,
+                        G_TYPE_NONE, 0);
+
+  /**
    * GtkPlacesSidebar::drag-action-requested:
    * @sidebar: the object which received the signal.
    * @context: #GdkDragContext with information about the drag operation
@@ -4244,6 +4298,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
                                 P_("Whether the sidebar includes a builtin shortcut to a 'Connect to server' 
dialog"),
                                 FALSE,
                                 G_PARAM_READWRITE);
+  properties[PROP_SHOW_ENTER_LOCATION] =
+          g_param_spec_boolean ("show-enter-location",
+                                P_("Show 'Enter Location'"),
+                                P_("Whether the sidebar includes a builtin shortcut to manually enter a 
location"),
+                                FALSE,
+                                G_PARAM_READWRITE);
   properties[PROP_LOCAL_ONLY] =
           g_param_spec_boolean ("local-only",
                                 P_("Local Only"),
@@ -4606,6 +4666,50 @@ gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSidebar *sidebar)
 }
 
 /**
+ * gtk_places_sidebar_set_show_enter_location:
+ * @sidebar: a places sidebar
+ * @show_enter_location: whether to show an item for the Connect to Server command
+ *
+ * Sets whether the @sidebar should show an item for connecting to a network server; this is off by default.
+ * An application may want to turn this on if it implements a way for the user to connect
+ * to network servers directly.
+ *
+ * Since: 3.14
+ */
+void
+gtk_places_sidebar_set_show_enter_location (GtkPlacesSidebar *sidebar,
+                                               gboolean          show_enter_location)
+{
+  g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
+
+  show_enter_location = !!show_enter_location;
+  if (sidebar->show_enter_location != show_enter_location)
+    {
+      sidebar->show_enter_location = show_enter_location;
+      update_places (sidebar);
+      g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_ENTER_LOCATION]);
+    }
+}
+
+/**
+ * gtk_places_sidebar_get_show_enter_location:
+ * @sidebar: a places sidebar
+ *
+ * Returns the value previously set with gtk_places_sidebar_set_show_enter_location()
+ *
+ * Returns: %TRUE if the sidebar will display an “Enter Location” item.
+ *
+ * Since: 3.14
+ */
+gboolean
+gtk_places_sidebar_get_show_enter_location (GtkPlacesSidebar *sidebar)
+{
+  g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
+
+  return sidebar->show_enter_location;
+}
+
+/**
  * gtk_places_sidebar_set_local_only:
  * @sidebar: a places sidebar
  * @local_only: whether to show only local files
diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h
index a358f5b..70f1c09 100644
--- a/gtk/gtkplacessidebar.h
+++ b/gtk/gtkplacessidebar.h
@@ -105,6 +105,11 @@ gboolean           gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSideb
 GDK_AVAILABLE_IN_3_10
 void               gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar   *sidebar,
                                                                   gboolean            
show_connect_to_server);
+GDK_AVAILABLE_IN_3_14
+gboolean           gtk_places_sidebar_get_show_enter_location    (GtkPlacesSidebar   *sidebar);
+GDK_AVAILABLE_IN_3_14
+void               gtk_places_sidebar_set_show_enter_location    (GtkPlacesSidebar   *sidebar,
+                                                                  gboolean            show_enter_location);
 
 GDK_AVAILABLE_IN_3_12
 void                 gtk_places_sidebar_set_local_only           (GtkPlacesSidebar   *sidebar,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]