[gtk+] placesview: show Computer item



commit a5e762e6a736ebaec8e32afb823f737d7b7def68
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jul 27 16:52:37 2015 -0300

    placesview: show Computer item
    
    GtkPlacesView widget manages persistent locations,
    factoring out GtkPlacesSidebar functionality.
    
    It, however, does not completely shows all sidebar
    locations, since Computer is still missing.
    
    Add a Computer item, adjusting some internal behavior
    to make that possible.

 gtk/gtkplacesview.c           |   37 +++++++++++++++++++++++++++++++++++--
 gtk/gtkplacesviewrow.c        |   25 +++++++++++++++++++++++++
 gtk/gtkplacesviewrowprivate.h |    2 ++
 gtk/ui/gtkplacesviewrow.ui    |    2 ++
 4 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index d05f57d..b685b85 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -342,16 +342,22 @@ activate_row (GtkPlacesView      *view,
   GtkPlacesViewPrivate *priv;
   GVolume *volume;
   GMount *mount;
+  GFile *file;
 
   priv = gtk_places_view_get_instance_private (view);
   mount = gtk_places_view_row_get_mount (row);
   volume = gtk_places_view_row_get_volume (row);
+  file = gtk_places_view_row_get_file (row);
 
-  if (mount)
+  if (file)
+    {
+      emit_open_location (view, file, flags);
+    }
+  else if (mount)
     {
       GFile *location = g_mount_get_root (mount);
 
-      emit_open_location (view, location, GTK_PLACES_OPEN_NORMAL);
+      emit_open_location (view, location, flags);
 
       g_object_unref (location);
     }
@@ -771,6 +777,7 @@ add_volume (GtkPlacesView *view,
                           "path", path ? path : "",
                           "volume", volume,
                           "mount", mount,
+                          "file", NULL,
                           NULL);
 
       insert_row (view, row, is_network);
@@ -814,6 +821,7 @@ add_mount (GtkPlacesView *view,
                           "path", path ? path : "",
                           "volume", NULL,
                           "mount", mount,
+                          "file", NULL,
                           NULL);
 
       insert_row (view, row, is_network);
@@ -847,6 +855,28 @@ add_drive (GtkPlacesView *view,
 }
 
 static void
+add_computer (GtkPlacesView *view)
+{
+  GtkWidget *row;
+  GIcon *icon;
+  GFile *file;
+
+  file = g_file_new_for_path ("/");
+  icon = g_themed_icon_new_with_default_fallbacks ("drive-harddisk");
+
+  row = g_object_new (GTK_TYPE_PLACES_VIEW_ROW,
+                      "icon", icon,
+                      "name", _("Computer"),
+                      "path", "/",
+                      "volume", NULL,
+                      "mount", NULL,
+                      "file", file,
+                      NULL);
+
+  insert_row (view, row, FALSE);
+}
+
+static void
 update_places (GtkPlacesView *view)
 {
   GtkPlacesViewPrivate *priv;
@@ -872,6 +902,9 @@ update_places (GtkPlacesView *view)
   gtk_widget_hide (priv->drives_box);
   gtk_widget_hide (priv->network_grid);
 
+  /* Add "Computer" row */
+  add_computer (view);
+
   /* Add currently connected drives */
   drives = g_volume_monitor_get_connected_drives (priv->volume_monitor);
 
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
index 44c8644..97ce9b6 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -38,6 +38,7 @@ struct _GtkPlacesViewRow
 
   GVolume       *volume;
   GMount        *mount;
+  GFile         *file;
 };
 
 G_DEFINE_TYPE (GtkPlacesViewRow, gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW)
@@ -49,6 +50,7 @@ enum {
   PROP_PATH,
   PROP_VOLUME,
   PROP_MOUNT,
+  PROP_FILE,
   LAST_PROP
 };
 
@@ -89,6 +91,10 @@ gtk_places_view_row_get_property (GObject    *object,
       g_value_set_object (value, self->mount);
       break;
 
+    case PROP_FILE:
+      g_value_set_object (value, self->file);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -127,6 +133,10 @@ gtk_places_view_row_set_property (GObject      *object,
       gtk_widget_set_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
       break;
 
+    case PROP_FILE:
+      self->file = g_value_get_object (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -176,6 +186,13 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
                                G_TYPE_MOUNT,
                                G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  properties[PROP_FILE] =
+          g_param_spec_object ("file",
+                               P_("File represented by the row"),
+                               P_("The file represented by the row, if any"),
+                               G_TYPE_FILE,
+                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
   g_object_class_install_properties (object_class, LAST_PROP, properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkplacesviewrow.ui");
@@ -220,6 +237,14 @@ gtk_places_view_row_get_volume (GtkPlacesViewRow *row)
   return row->volume;
 }
 
+GFile*
+gtk_places_view_row_get_file (GtkPlacesViewRow *row)
+{
+  g_return_val_if_fail (GTK_IS_PLACES_VIEW_ROW (row), NULL);
+
+  return row->file;
+}
+
 GtkWidget*
 gtk_places_view_row_get_eject_button (GtkPlacesViewRow *row)
 {
diff --git a/gtk/gtkplacesviewrowprivate.h b/gtk/gtkplacesviewrowprivate.h
index 150140b..20add04 100644
--- a/gtk/gtkplacesviewrowprivate.h
+++ b/gtk/gtkplacesviewrowprivate.h
@@ -43,6 +43,8 @@ GMount*            gtk_places_view_row_get_mount                 (GtkPlacesViewR
 
 GVolume*           gtk_places_view_row_get_volume                (GtkPlacesViewRow   *row);
 
+GFile*             gtk_places_view_row_get_file                  (GtkPlacesViewRow   *row);
+
 void               gtk_places_view_row_set_busy                  (GtkPlacesViewRow   *row,
                                                                   gboolean            is_busy);
 
diff --git a/gtk/ui/gtkplacesviewrow.ui b/gtk/ui/gtkplacesviewrow.ui
index 926cb4c..6ca241f 100644
--- a/gtk/ui/gtkplacesviewrow.ui
+++ b/gtk/ui/gtkplacesviewrow.ui
@@ -53,6 +53,8 @@
                 <property name="justify">right</property>
                 <property name="ellipsize">middle</property>
                 <property name="xalign">1</property>
+                <property name="width_chars">15</property>
+                <property name="max_width_chars">15</property>
                 <style>
                   <class name="dim-label"/>
                 </style>


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