[gtk+/wip/gbsneto/placessidebar-locations] placesviewrow: split GtkPlacesView and GtkPlacesViewRow files



commit 7cb795694a9a7c19e465917bb5b825412f7552a0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jun 8 15:27:34 2015 -0300

    placesviewrow: split GtkPlacesView and GtkPlacesViewRow files

 gtk/Makefile.am                              |    6 +-
 gtk/gtkplacessidebar.c                       |    2 +
 gtk/gtkplacesview.c                          |  193 ++---------------------
 gtk/gtkplacesviewrow.c                       |  214 ++++++++++++++++++++++++++
 gtk/gtkplacesviewrow.h                       |   43 +++++
 gtk/ui/{placesrow.ui => gtkplacesviewrow.ui} |    5 +-
 6 files changed, 282 insertions(+), 181 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 8ed0124..6046750 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -475,6 +475,7 @@ gtk_private_h_sources =             \
        gtkorientableprivate.h  \
        gtkpango.h              \
        gtkpathbar.h            \
+       gtkplacesviewrow.h      \
        gtkpopoverprivate.h     \
        gtkprintoperation-private.h \
        gtkprintutils.h         \
@@ -754,6 +755,7 @@ gtk_base_c_sources =                \
        gtkpathbar.c            \
        gtkplacessidebar.c      \
        gtkplacesview.c         \
+       gtkplacesviewrow.c      \
        gtkprintcontext.c       \
        gtkprintoperation.c     \
        gtkprintoperationpreview.c \
@@ -1084,13 +1086,13 @@ templates =                             \
        ui/gtkpagesetupunixdialog.ui    \
        ui/gtkpathbar.ui                \
        ui/gtkplacesview.ui             \
+       ui/gtkplacesviewrow.ui          \
        ui/gtkprintunixdialog.ui        \
        ui/gtkrecentchooserdefault.ui   \
        ui/gtksearchbar.ui              \
        ui/gtkscalebutton.ui            \
        ui/gtkstatusbar.ui              \
-       ui/gtkvolumebutton.ui           \
-       ui/placesrow.ui
+       ui/gtkvolumebutton.ui
 
 #
 # rules to generate built sources
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 9ee18d6..a543d7a 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -1045,6 +1045,8 @@ update_places (GtkPlacesSidebar *sidebar)
       if (!g_drive_is_media_removable (drive))
         continue;
 
+      g_message ("adding drive '%s'", g_drive_get_name (drive));
+
       volumes = g_drive_get_volumes (drive);
       if (volumes != NULL)
         {
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 33107a6..ffc1c34 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -23,15 +23,9 @@
 
 #include "gtkintl.h"
 #include "gtkplacesview.h"
+#include "gtkplacesviewrow.h"
 #include "gtktypebuiltins.h"
 
-/*
- * PlacesRow class definition
- */
-#define PLACES_TYPE_ROW (places_row_get_type ())
-GDK_AVAILABLE_IN_3_18
-G_DECLARE_FINAL_TYPE (PlacesRow, places_row, PLACES, ROW, GtkListBoxRow)
-
 struct _GtkPlacesViewPrivate
 {
   GVolumeMonitor                *volume_monitor;
@@ -48,33 +42,10 @@ struct _GtkPlacesViewPrivate
   GtkWidget                     *recent_servers_listbox;
 
   guint local_only             : 1;
-
 };
 
-struct _PlacesRow
-{
-  GtkListBoxRow parent_instance;
-  GtkImage *icon_image;
-  GtkLabel *name_label;
-  GtkLabel *path_label;
-  GVolume *volume;
-  GMount *mount;
-};
-
-G_DEFINE_TYPE (PlacesRow, places_row, GTK_TYPE_LIST_BOX_ROW)
-
 G_DEFINE_TYPE_WITH_PRIVATE (GtkPlacesView, gtk_places_view, GTK_TYPE_BOX)
 
-/* PlacesRow properties */
-enum {
-  PROP_ICON = 1,
-  PROP_NAME,
-  PROP_PATH,
-  PROP_VOLUME,
-  PROP_MOUNT,
-  NUM_PROPS
-};
-
 /* GtkPlacesView properties & signals */
 enum {
   PROP_0,
@@ -97,7 +68,6 @@ const char *unsupported_protocols [] =
 
 static guint places_view_signals [LAST_SIGNAL] = { 0 };
 static GParamSpec *properties [LAST_PROP];
-static GParamSpec *row_properties [NUM_PROPS];
 
 static void
 emit_open_location (GtkPlacesView      *view,
@@ -116,133 +86,6 @@ emit_open_location (GtkPlacesView      *view,
   g_signal_emit (view, places_view_signals[OPEN_LOCATION], 0, location, open_flags);
 }
 
-static void
-places_row_get_property (GObject    *object,
-                         guint       prop_id,
-                         GValue     *value,
-                         GParamSpec *pspec)
-{
-  PlacesRow *self = PLACES_ROW (object);
-  GIcon *icon = NULL;
-
-  switch (prop_id)
-    {
-    case PROP_ICON:
-      gtk_image_get_gicon (self->icon_image, &icon, NULL);
-      g_value_set_object (value, icon);
-      break;
-
-    case PROP_NAME:
-      g_value_set_string (value, gtk_label_get_label (self->name_label));
-      break;
-
-    case PROP_PATH:
-      g_value_set_string (value, gtk_label_get_label (self->path_label));
-      break;
-
-    case PROP_VOLUME:
-      g_value_set_object (value, self->volume);
-      break;
-
-    case PROP_MOUNT:
-      g_value_set_object (value, self->mount);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-    }
-}
-
-static void
-places_row_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
-{
-  PlacesRow *self = PLACES_ROW (object);
-
-  switch (prop_id)
-    {
-    case PROP_ICON:
-      gtk_image_set_from_gicon (self->icon_image,
-                                g_value_get_object (value),
-                                GTK_ICON_SIZE_LARGE_TOOLBAR);
-      break;
-
-    case PROP_NAME:
-      gtk_label_set_label (self->name_label, g_value_get_string (value));
-      break;
-
-    case PROP_PATH:
-      gtk_label_set_label (self->path_label, g_value_get_string (value));
-      break;
-
-    case PROP_VOLUME:
-      self->volume = g_value_get_object (value);
-      break;
-
-    case PROP_MOUNT:
-      self->mount = g_value_get_object (value);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-    }
-}
-
-static void
-places_row_class_init (PlacesRowClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
-  object_class->get_property = places_row_get_property;
-  object_class->set_property = places_row_set_property;
-
-  row_properties[PROP_ICON] =
-          g_param_spec_object ("icon",
-                               P_("Icon of the row"),
-                               P_("The icon representing the volume"),
-                               G_TYPE_ICON,
-                               G_PARAM_READWRITE);
-
-  row_properties[PROP_NAME] =
-          g_param_spec_string ("name",
-                               P_("Name of the volume"),
-                               P_("The name of the volume"),
-                               "",
-                               G_PARAM_READWRITE);
-
-  row_properties[PROP_PATH] =
-          g_param_spec_string ("path",
-                               P_("Path of the volume"),
-                               P_("The path of the volume"),
-                               "",
-                               G_PARAM_READWRITE);
-
-  row_properties[PROP_VOLUME] =
-          g_param_spec_object ("volume",
-                               P_("Volume represented by the row"),
-                               P_("The volume represented by the row"),
-                               G_TYPE_VOLUME,
-                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
-  row_properties[PROP_MOUNT] =
-          g_param_spec_object ("mount",
-                               P_("Mount represented by the row"),
-                               P_("The mount point represented by the row, if any"),
-                               G_TYPE_MOUNT,
-                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
-  g_object_class_install_properties (object_class, NUM_PROPS, row_properties);
-
-  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/placesrow.ui");
-
-  gtk_widget_class_bind_template_child (widget_class, PlacesRow, icon_image);
-  gtk_widget_class_bind_template_child (widget_class, PlacesRow, name_label);
-  gtk_widget_class_bind_template_child (widget_class, PlacesRow, path_label);
-}
-
 static GBookmarkFile *
 server_list_load (void)
 {
@@ -287,12 +130,6 @@ server_list_save (GBookmarkFile *bookmarks)
        g_free (filename);
 }
 
-static void
-places_row_init (PlacesRow *self)
-{
-  gtk_widget_init_template (GTK_WIDGET (self));
-}
-
 static gboolean
 gtk_places_view_real_get_local_only (GtkPlacesView *view)
 {
@@ -382,7 +219,7 @@ is_external_device (GVolume *volume)
         external |= g_volume_can_eject (volume);
 
       if (mount)
-        external |= g_mount_can_eject (mount) && g_mount_can_unmount (mount);
+        external |= g_mount_can_eject (mount) && !g_mount_can_unmount (mount);
     }
   else
     {
@@ -504,7 +341,7 @@ add_volume (GtkPlacesView *view,
     {
       GtkWidget *row;
 
-      row = g_object_new (PLACES_TYPE_ROW,
+      row = g_object_new (GTK_TYPE_PLACES_VIEW_ROW,
                       "icon", icon,
                       "name", name,
                       "path", path ? path : "",
@@ -578,7 +415,7 @@ add_mount (GtkPlacesView *view,
     {
       GtkWidget *row;
 
-      row = g_object_new (PLACES_TYPE_ROW,
+      row = g_object_new (GTK_TYPE_PLACES_VIEW_ROW,
                       "icon", icon,
                       "name", name,
                       "path", path ? path : "",
@@ -922,32 +759,32 @@ out:
 }
 
 static void
-on_listbox_row_activated (GtkPlacesView *view,
-                          PlacesRow     *row)
+on_listbox_row_activated (GtkPlacesView    *view,
+                          GtkPlacesViewRow *row)
 {
   GtkPlacesViewPrivate *priv;
+  GVolume *volume;
   GFile *location;
+  GMount *mount;
 
   g_return_if_fail (GTK_IS_PLACES_VIEW (view));
-  g_return_if_fail (PLACES_IS_ROW (row));
+  g_return_if_fail (GTK_IS_PLACES_VIEW_ROW (row));
 
   priv = view->priv;
+  mount = gtk_places_view_row_get_mount (row);
+  volume = gtk_places_view_row_get_volume (row);
 
-  if (row->mount)
+  if (mount)
     {
-      location = g_mount_get_root (row->mount);
+      location = g_mount_get_root (mount);
 
       emit_open_location (view, location, GTK_PLACES_OPEN_NORMAL);
 
       g_object_unref (location);
     }
-  else if (row->volume)
+  else if (volume && g_volume_can_mount (volume))
     {
-      /* TODO: mount the volume */
-      g_message ("should mount volume '%s'", g_volume_get_name (row->volume));
-
-      if (g_volume_can_mount (row->volume))
-        mount_volume (view, row->volume);
+        mount_volume (view, volume);
     }
 }
 
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
new file mode 100644
index 0000000..30edbbf
--- /dev/null
+++ b/gtk/gtkplacesviewrow.c
@@ -0,0 +1,214 @@
+/* gtkplacesviewrow.c
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include "gtkintl.h"
+#include "gtkplacesviewrow.h"
+#include "gtktypebuiltins.h"
+
+struct _GtkPlacesViewRow
+{
+  GtkListBoxRow  parent_instance;
+
+  GtkImage      *icon_image;
+  GtkLabel      *name_label;
+  GtkLabel      *path_label;
+
+  GVolume       *volume;
+  GMount        *mount;
+};
+
+G_DEFINE_TYPE (GtkPlacesViewRow, gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW)
+
+enum {
+  PROP_0,
+  PROP_ICON,
+  PROP_NAME,
+  PROP_PATH,
+  PROP_VOLUME,
+  PROP_MOUNT,
+  LAST_PROP
+};
+
+static GParamSpec *properties [LAST_PROP];
+
+static void
+gtk_places_view_row_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  GtkPlacesViewRow *self;
+  GIcon *icon;
+
+  self = GTK_PLACES_VIEW_ROW (object);
+  icon = NULL;
+
+  switch (prop_id)
+    {
+    case PROP_ICON:
+      gtk_image_get_gicon (self->icon_image, &icon, NULL);
+      g_value_set_object (value, icon);
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, gtk_label_get_label (self->name_label));
+      break;
+
+    case PROP_PATH:
+      g_value_set_string (value, gtk_label_get_label (self->path_label));
+      break;
+
+    case PROP_VOLUME:
+      g_value_set_object (value, self->volume);
+      break;
+
+    case PROP_MOUNT:
+      g_value_set_object (value, self->mount);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtk_places_view_row_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  GtkPlacesViewRow *self = GTK_PLACES_VIEW_ROW (object);
+
+  switch (prop_id)
+    {
+    case PROP_ICON:
+      gtk_image_set_from_gicon (self->icon_image,
+                                g_value_get_object (value),
+                                GTK_ICON_SIZE_LARGE_TOOLBAR);
+      break;
+
+    case PROP_NAME:
+      gtk_label_set_label (self->name_label, g_value_get_string (value));
+      break;
+
+    case PROP_PATH:
+      gtk_label_set_label (self->path_label, g_value_get_string (value));
+      break;
+
+    case PROP_VOLUME:
+      self->volume = g_value_get_object (value);
+      break;
+
+    case PROP_MOUNT:
+      self->mount = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->get_property = gtk_places_view_row_get_property;
+  object_class->set_property = gtk_places_view_row_set_property;
+
+  properties[PROP_ICON] =
+          g_param_spec_object ("icon",
+                               P_("Icon of the row"),
+                               P_("The icon representing the volume"),
+                               G_TYPE_ICON,
+                               G_PARAM_READWRITE);
+
+  properties[PROP_NAME] =
+          g_param_spec_string ("name",
+                               P_("Name of the volume"),
+                               P_("The name of the volume"),
+                               "",
+                               G_PARAM_READWRITE);
+
+  properties[PROP_PATH] =
+          g_param_spec_string ("path",
+                               P_("Path of the volume"),
+                               P_("The path of the volume"),
+                               "",
+                               G_PARAM_READWRITE);
+
+  properties[PROP_VOLUME] =
+          g_param_spec_object ("volume",
+                               P_("Volume represented by the row"),
+                               P_("The volume represented by the row"),
+                               G_TYPE_VOLUME,
+                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  properties[PROP_MOUNT] =
+          g_param_spec_object ("mount",
+                               P_("Mount represented by the row"),
+                               P_("The mount point represented by the row, if any"),
+                               G_TYPE_MOUNT,
+                               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");
+
+  gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, icon_image);
+  gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, name_label);
+  gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, path_label);
+}
+
+static void
+gtk_places_view_row_init (GtkPlacesViewRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget*
+gtk_places_view_row_new (GVolume *volume,
+                         GMount  *mount)
+{
+  return g_object_new (GTK_TYPE_PLACES_VIEW_ROW,
+                       "volume", volume,
+                       "mount", mount,
+                       NULL);
+}
+
+GMount*
+gtk_places_view_row_get_mount (GtkPlacesViewRow *row)
+{
+  g_return_val_if_fail (GTK_IS_PLACES_VIEW_ROW (row), NULL);
+
+  return row->mount;
+}
+
+GVolume*
+gtk_places_view_row_get_volume (GtkPlacesViewRow *row)
+{
+  g_return_val_if_fail (GTK_IS_PLACES_VIEW_ROW (row), NULL);
+
+  return row->volume;
+}
diff --git a/gtk/gtkplacesviewrow.h b/gtk/gtkplacesviewrow.h
new file mode 100644
index 0000000..2746a35
--- /dev/null
+++ b/gtk/gtkplacesviewrow.h
@@ -0,0 +1,43 @@
+/* gtkplacesviewrow.h
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_PLACES_VIEW_ROW_H
+#define GTK_PLACES_VIEW_ROW_H
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_PLACES_VIEW_ROW (gtk_places_view_row_get_type())
+
+G_DECLARE_FINAL_TYPE (GtkPlacesViewRow, gtk_places_view_row, GTK, PLACES_VIEW_ROW, GtkListBoxRow)
+
+GtkWidget*         gtk_places_view_row_new                       (GVolume            *volume,
+                                                                  GMount             *mount);
+
+GMount*            gtk_places_view_row_get_mount                 (GtkPlacesViewRow   *row);
+
+GVolume*           gtk_places_view_row_get_volume                (GtkPlacesViewRow   *row);
+
+G_END_DECLS
+
+#endif /* GTK_PLACES_VIEW_ROW_H */
diff --git a/gtk/ui/placesrow.ui b/gtk/ui/gtkplacesviewrow.ui
similarity index 95%
rename from gtk/ui/placesrow.ui
rename to gtk/ui/gtkplacesviewrow.ui
index c92244d..c17a1ed 100644
--- a/gtk/ui/placesrow.ui
+++ b/gtk/ui/gtkplacesviewrow.ui
@@ -2,10 +2,13 @@
 <!-- Generated with glade 3.18.1 -->
 <interface>
   <requires lib="gtk+" version="3.16"/>
-  <template class="PlacesRow" parent="GtkListBoxRow">
+  <template class="GtkPlacesViewRow" parent="GtkListBoxRow">
     <property name="width_request">100</property>
     <property name="visible">True</property>
     <property name="can_focus">True</property>
+    <style>
+      <class name="volume-row" />
+    </style>
     <child>
       <object class="GtkBox" id="box">
         <property name="visible">True</property>


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