[gtk+/wip/gbsneto/placessidebar-locations] placesview: initial work on local drives
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gbsneto/placessidebar-locations] placesview: initial work on local drives
- Date: Sun, 31 May 2015 23:49:50 +0000 (UTC)
commit e3a547d40387988ea9418d8c51c09107d801af2e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun May 31 20:49:10 2015 -0300
placesview: initial work on local drives
gtk/gtkplacesview.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 204 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index c9c1180..47b64ff 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -18,24 +18,159 @@
#include "config.h"
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include "gtkintl.h"
#include "gtkplacesview.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;
+ GtkWidget *drives_listbox;
+
guint local_only : 1;
};
+struct _PlacesRow
+{
+ GtkListBoxRow parent_instance;
+ GtkImage *icon_image;
+ GtkLabel *name_label;
+ GtkLabel *path_label;
+};
+
+G_DEFINE_TYPE (PlacesRow, places_row, GTK_TYPE_LIST_BOX_ROW)
+
G_DEFINE_TYPE_WITH_PRIVATE (GtkPlacesView, gtk_places_view, GTK_TYPE_BOX)
enum {
+ PROP_ICON = 1,
+ PROP_NAME,
+ PROP_PATH,
+ NUM_PROPS
+};
+
+enum {
PROP_0,
PROP_LOCAL_ONLY,
LAST_PROP
};
static GParamSpec *properties [LAST_PROP];
+static GParamSpec *row_properties [NUM_PROPS];
+
+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;
+
+ 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;
+
+ 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);
+
+ 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 void
+places_row_init (PlacesRow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
static gboolean
gtk_places_view_real_get_local_only (GtkPlacesView *view)
@@ -107,6 +242,61 @@ gtk_places_view_set_property (GObject *object,
}
static void
+gtk_places_view_constructed (GObject *object)
+{
+ GtkPlacesViewPrivate *priv = GTK_PLACES_VIEW (object)->priv;
+ GList *mounts;
+ GList *l;
+
+ if (G_OBJECT_CLASS (gtk_places_view_parent_class)->constructed)
+ G_OBJECT_CLASS (gtk_places_view_parent_class)->constructed (object);
+
+ mounts = g_volume_monitor_get_mounts (priv->volume_monitor);
+
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ GtkWidget *row;
+ GMount *mount;
+ GDrive *drive;
+ GFile *root;
+ GIcon *icon;
+ gchar *name;
+ gchar *path;
+
+ mount = l->data;
+ drive = g_mount_get_drive (mount);
+
+ /* Removable devices won't appear here */
+ if (drive && g_drive_is_media_removable (drive))
+ {
+ g_object_unref (drive);
+ continue;
+ }
+
+ root = g_mount_get_root (mount);
+ icon = g_mount_get_icon (mount);
+ name = g_mount_get_name (mount);
+ path = g_file_get_path (root);
+
+ row = g_object_new (PLACES_TYPE_ROW,
+ "icon", icon,
+ "name", name,
+ "path", path,
+ NULL);
+
+ gtk_list_box_insert (GTK_LIST_BOX (priv->drives_listbox), row, -1);
+
+ g_clear_object (&root);
+ g_clear_object (&icon);
+ g_clear_object (&drive);
+ g_free (name);
+ g_free (path);
+ }
+
+ g_list_free_full (mounts, g_object_unref);
+}
+
+static void
gtk_places_view_class_init (GtkPlacesViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -116,22 +306,30 @@ gtk_places_view_class_init (GtkPlacesViewClass *klass)
klass->get_local_only = gtk_places_view_real_get_local_only;
object_class->finalize = gtk_places_view_finalize;
+ object_class->constructed = gtk_places_view_constructed;
object_class->get_property = gtk_places_view_get_property;
object_class->set_property = gtk_places_view_set_property;
+ properties[PROP_LOCAL_ONLY] =
+ g_param_spec_boolean ("local-only",
+ P_("Local Only"),
+ P_("Whether the sidebar only includes local files"),
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
/* Bind class to template */
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkplacesview.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, drives_listbox);
}
static void
gtk_places_view_init (GtkPlacesView *self)
{
- GtkPlacesViewPrivate *priv;
-
- priv = gtk_places_view_get_instance_private (self);
- self->priv = priv;
-
- priv->volume_monitor = g_volume_monitor_get ();
+ self->priv = gtk_places_view_get_instance_private (self);
+ self->priv->volume_monitor = g_volume_monitor_get ();
gtk_widget_init_template (GTK_WIDGET (self));
}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]