[totem] grilo: Add Selection toolbar



commit e867d7924180f4d43ab2264e6cbc986e443dc370
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jan 23 11:37:18 2014 +0100

    grilo: Add Selection toolbar

 src/plugins/grilo/Makefile.am               |    6 +-
 src/plugins/grilo/grilo.gresource.xml       |    1 +
 src/plugins/grilo/totem-selection-toolbar.c |  326 +++++++++++++++++++++++++++
 src/plugins/grilo/totem-selection-toolbar.h |   70 ++++++
 src/plugins/grilo/totemselectiontoolbar.ui  |   97 ++++++++
 5 files changed, 498 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/grilo/Makefile.am b/src/plugins/grilo/Makefile.am
index dad75b0..775c38d 100644
--- a/src/plugins/grilo/Makefile.am
+++ b/src/plugins/grilo/Makefile.am
@@ -9,12 +9,12 @@ confdir = $(plugindir)
 conf_DATA = totem-grilo.conf
 EXTRA_DIST += $(conf_DATA)
 
-EXTRA_DIST += grilo.gresource.xml totemmaintoolbar.ui grilo.ui
+EXTRA_DIST += grilo.gresource.xml totemmaintoolbar.ui totemselectiontoolbar.ui grilo.ui
 
 griloresources.h: grilo.gresource.xml
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/grilo.gresource.xml \
                --target=$@ --sourcedir=$(srcdir) --c-name _totem --generate-header
-griloresources.c: grilo.gresource.xml totemmaintoolbar.ui grilo.ui griloresources.h
+griloresources.c: grilo.gresource.xml totemmaintoolbar.ui grilo.ui totemselectiontoolbar.ui griloresources.h
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/grilo.gresource.xml \
                --target=$@ --sourcedir=$(srcdir) --c-name _totem --generate-source
 
@@ -28,6 +28,8 @@ libgrilo_la_SOURCES =                         \
        totem-search-entry.h                    \
        totem-main-toolbar.h                    \
        totem-main-toolbar.c                    \
+       totem-selection-toolbar.h               \
+       totem-selection-toolbar.c               \
        icon-helpers.c                          \
        icon-helpers.h                          \
        griloresources.h                        \
diff --git a/src/plugins/grilo/grilo.gresource.xml b/src/plugins/grilo/grilo.gresource.xml
index 6c2e172..c3891cf 100644
--- a/src/plugins/grilo/grilo.gresource.xml
+++ b/src/plugins/grilo/grilo.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/totem/grilo">
     <file compressed="true">totemmaintoolbar.ui</file>
+    <file compressed="true">totemselectiontoolbar.ui</file>
     <file compressed="true">grilo.ui</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/grilo/totem-selection-toolbar.c b/src/plugins/grilo/totem-selection-toolbar.c
new file mode 100644
index 0000000..467b677
--- /dev/null
+++ b/src/plugins/grilo/totem-selection-toolbar.c
@@ -0,0 +1,326 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2013-2014 Red Hat, Inc.
+ *
+ * Authors:
+ * - Bastien Nocera <bnocera redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 2013-2014.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+#include "totem-selection-toolbar.h"
+#include "griloresources.h"
+
+/**
+ * SECTION:totemselectiontoolbar
+ * @Short_description: An toolbar with oft-used buttons.
+ * @Title: TotemSelectionToolbar
+ *
+ * #TotemSelectionToolbar is a toolbar that contains oft-used buttons such as toggles
+ * for select mode, and find mode, or a new button. The widget will also be
+ * styled properly when in specific mode.
+ */
+
+struct _TotemSelectionToolbarPrivate {
+  /* Template widgets */
+  GtkWidget   *add_to_fav;
+  GtkWidget   *play;
+  GtkWidget   *shuffle;
+  GtkWidget   *delete;
+
+  /* Visibility */
+  gboolean     show_delete_button;
+
+  /* Selection mode */
+  guint        n_selected;
+};
+
+G_DEFINE_TYPE_WITH_CODE (TotemSelectionToolbar, totem_selection_toolbar, GTK_TYPE_ACTION_BAR,
+                         G_ADD_PRIVATE (TotemSelectionToolbar));
+
+enum {
+  PROP_0,
+  PROP_SHOW_DELETE_BUTTON,
+  PROP_N_SELECTED
+};
+
+static void
+change_class (GtkWidget  *widget,
+              const char *class,
+              gboolean    add)
+{
+  GtkStyleContext *style;
+
+  style = gtk_widget_get_style_context (widget);
+  if (add)
+    gtk_style_context_add_class (style, class);
+  else
+    gtk_style_context_remove_class (style, class);
+}
+
+static void
+update_toolbar_state (TotemSelectionToolbar *bar)
+{
+  TotemSelectionToolbarPrivate *priv = bar->priv;
+  gboolean sensitive;
+
+  if (priv->n_selected == 0)
+    {
+      sensitive = FALSE;
+      change_class (GTK_WIDGET (priv->delete), "destructive-action", FALSE);
+    }
+  else
+    {
+      sensitive = TRUE;
+      change_class (GTK_WIDGET (priv->delete), "destructive-action", TRUE);
+    }
+
+  gtk_widget_set_sensitive (priv->add_to_fav, sensitive);
+  gtk_widget_set_sensitive (priv->play, sensitive);
+  gtk_widget_set_sensitive (priv->shuffle, sensitive);
+  gtk_widget_set_sensitive (priv->delete, sensitive);
+}
+
+static void
+add_to_fav_clicked_cb (GtkButton        *button,
+                       TotemSelectionToolbar *bar)
+{
+  g_signal_emit_by_name (G_OBJECT (bar), "add-to-favourites-clicked", NULL);
+}
+
+static void
+delete_clicked_cb (GtkButton             *button,
+                   TotemSelectionToolbar *bar)
+{
+  g_signal_emit_by_name (G_OBJECT (bar), "delete-clicked", NULL);
+}
+
+static void
+play_clicked_cb (GtkButton             *button,
+                 TotemSelectionToolbar *bar)
+{
+  g_signal_emit_by_name (G_OBJECT (bar), "play-clicked", NULL);
+}
+
+static void
+shuffle_clicked_cb (GtkButton             *button,
+                    TotemSelectionToolbar *bar)
+{
+  g_signal_emit_by_name (G_OBJECT (bar), "shuffle-clicked", NULL);
+}
+
+static void
+totem_selection_toolbar_set_property (GObject         *object,
+                                      guint            prop_id,
+                                      const GValue    *value,
+                                      GParamSpec      *pspec)
+{
+  TotemSelectionToolbar *bar = TOTEM_SELECTION_TOOLBAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_N_SELECTED:
+      totem_selection_toolbar_set_n_selected (bar, g_value_get_uint (value));
+      break;
+
+    case PROP_SHOW_DELETE_BUTTON:
+      totem_selection_toolbar_set_show_delete_button (bar, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+totem_selection_toolbar_get_property (GObject         *object,
+                                      guint            prop_id,
+                                      GValue          *value,
+                                      GParamSpec      *pspec)
+{
+  TotemSelectionToolbar *bar = TOTEM_SELECTION_TOOLBAR (object);
+  TotemSelectionToolbarPrivate *priv = bar->priv;
+
+  switch (prop_id)
+    {
+    case PROP_N_SELECTED:
+      g_value_set_uint (value, totem_selection_toolbar_get_n_selected (bar));
+      break;
+
+    case PROP_SHOW_DELETE_BUTTON:
+      g_value_set_boolean (value, priv->show_delete_button);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+totem_selection_toolbar_class_init (TotemSelectionToolbarClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->set_property = totem_selection_toolbar_set_property;
+  object_class->get_property = totem_selection_toolbar_get_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_N_SELECTED,
+                                   g_param_spec_uint ("n-selected",
+                                                      "Number of Selected Items",
+                                                      "The number of selected items",
+                                                      0,
+                                                      G_MAXUINT,
+                                                      0,
+                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (object_class,
+                                   PROP_SHOW_DELETE_BUTTON,
+                                   g_param_spec_boolean ("show-delete-button",
+                                                         "Show Delete Button",
+                                                         "Whether the delete button is visible",
+                                                         TRUE,
+                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_signal_new ("add-to-favourites-clicked",
+                G_OBJECT_CLASS_TYPE (klass),
+                0,
+                0,
+                NULL, NULL,
+                g_cclosure_marshal_generic,
+                G_TYPE_NONE, 0, G_TYPE_NONE);
+
+  g_signal_new ("delete-clicked",
+                G_OBJECT_CLASS_TYPE (klass),
+                0,
+                0,
+                NULL, NULL,
+                g_cclosure_marshal_generic,
+                G_TYPE_NONE, 0, G_TYPE_NONE);
+
+  g_signal_new ("play-clicked",
+                G_OBJECT_CLASS_TYPE (klass),
+                0,
+                0,
+                NULL, NULL,
+                g_cclosure_marshal_generic,
+                G_TYPE_NONE, 0, G_TYPE_NONE);
+
+  g_signal_new ("shuffle-clicked",
+                G_OBJECT_CLASS_TYPE (klass),
+                0,
+                0,
+                NULL, NULL,
+                g_cclosure_marshal_generic,
+                G_TYPE_NONE, 0, G_TYPE_NONE);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/totem/grilo/totemselectiontoolbar.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, TotemSelectionToolbar, add_to_fav);
+  gtk_widget_class_bind_template_child_private (widget_class, TotemSelectionToolbar, delete);
+  gtk_widget_class_bind_template_child_private (widget_class, TotemSelectionToolbar, play);
+  gtk_widget_class_bind_template_child_private (widget_class, TotemSelectionToolbar, shuffle);
+}
+
+static void
+totem_selection_toolbar_init (TotemSelectionToolbar *bar)
+{
+  bar->priv = totem_selection_toolbar_get_instance_private (bar);
+
+  gtk_widget_init_template (GTK_WIDGET (bar));
+
+  gtk_widget_hide (bar->priv->add_to_fav);
+
+  g_signal_connect (bar->priv->add_to_fav, "clicked",
+                    G_CALLBACK (add_to_fav_clicked_cb), bar);
+  g_signal_connect (bar->priv->delete, "clicked",
+                    G_CALLBACK (delete_clicked_cb), bar);
+  g_signal_connect (bar->priv->play, "clicked",
+                    G_CALLBACK (play_clicked_cb), bar);
+  g_signal_connect (bar->priv->shuffle, "clicked",
+                    G_CALLBACK (shuffle_clicked_cb), bar);
+};
+
+/**
+ * totem_selection_toolbar_new:
+ *
+ * Creates a #TotemSelectionToolbar.
+ *
+ * Return value: a new #TotemSelectionToolbar
+ *
+ * Since: 3.10
+ **/
+GtkWidget *
+totem_selection_toolbar_new (void)
+{
+  return GTK_WIDGET (g_object_new (TOTEM_TYPE_SELECTION_TOOLBAR, NULL));
+}
+
+void
+totem_selection_toolbar_set_n_selected (TotemSelectionToolbar *bar,
+                                   guint             n_selected)
+{
+  g_return_if_fail (TOTEM_IS_SELECTION_TOOLBAR (bar));
+
+  if (bar->priv->n_selected == n_selected)
+    return;
+
+  bar->priv->n_selected = n_selected;
+
+  update_toolbar_state (bar);
+  g_object_notify (G_OBJECT (bar), "n-selected");
+}
+
+guint
+totem_selection_toolbar_get_n_selected (TotemSelectionToolbar *bar)
+{
+  g_return_val_if_fail (TOTEM_IS_SELECTION_TOOLBAR (bar), 0);
+
+  return bar->priv->n_selected;
+}
+
+void
+totem_selection_toolbar_set_show_delete_button (TotemSelectionToolbar *bar,
+                                                gboolean               show_delete_button)
+{
+  g_return_if_fail (TOTEM_IS_SELECTION_TOOLBAR (bar));
+
+  if (bar->priv->show_delete_button == show_delete_button)
+    return;
+
+  bar->priv->show_delete_button = show_delete_button;
+  gtk_widget_set_visible (bar->priv->delete, bar->priv->show_delete_button);
+
+  g_object_notify (G_OBJECT (bar), "show-delete-button");
+}
+
+gboolean
+totem_selection_toolbar_get_show_delete_button (TotemSelectionToolbar *bar)
+{
+  g_return_val_if_fail (TOTEM_IS_SELECTION_TOOLBAR (bar), 0);
+
+  return bar->priv->show_delete_button;
+}
diff --git a/src/plugins/grilo/totem-selection-toolbar.h b/src/plugins/grilo/totem-selection-toolbar.h
new file mode 100644
index 0000000..b638ff1
--- /dev/null
+++ b/src/plugins/grilo/totem-selection-toolbar.h
@@ -0,0 +1,70 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2013-2014 Red Hat, Inc.
+ *
+ * Authors:
+ * - Bastien Nocera <bnocera redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 2013.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __TOTEM_SELECTION_TOOLBAR_H__
+#define __TOTEM_SELECTION_TOOLBAR_H__
+
+#include <gtk/gtkbox.h>
+
+G_BEGIN_DECLS
+
+#define TOTEM_TYPE_SELECTION_TOOLBAR                 (totem_selection_toolbar_get_type ())
+#define TOTEM_SELECTION_TOOLBAR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
TOTEM_TYPE_SELECTION_TOOLBAR, TotemSelectionToolbar))
+#define TOTEM_SELECTION_TOOLBAR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
TOTEM_TYPE_SELECTION_TOOLBAR, TotemSelectionToolbarClass))
+#define TOTEM_IS_SELECTION_TOOLBAR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
TOTEM_TYPE_SELECTION_TOOLBAR))
+#define TOTEM_IS_SELECTION_TOOLBAR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
TOTEM_TYPE_SELECTION_TOOLBAR))
+#define TOTEM_SELECTION_TOOLBAR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
TOTEM_TYPE_SELECTION_TOOLBAR, TotemSelectionToolbarClass))
+
+typedef struct _TotemSelectionToolbar        TotemSelectionToolbar;
+typedef struct _TotemSelectionToolbarPrivate TotemSelectionToolbarPrivate;
+typedef struct _TotemSelectionToolbarClass   TotemSelectionToolbarClass;
+
+struct _TotemSelectionToolbar
+{
+  /*< private >*/
+  GtkActionBar parent;
+
+  TotemSelectionToolbarPrivate *priv;
+};
+
+struct _TotemSelectionToolbarClass
+{
+  GtkActionBarClass parent_class;
+};
+
+GType           totem_selection_toolbar_get_type               (void) G_GNUC_CONST;
+GtkWidget*      totem_selection_toolbar_new                    (void);
+void            totem_selection_toolbar_set_n_selected         (TotemSelectionToolbar *bar,
+                                                               guint                  n_selected);
+guint           totem_selection_toolbar_get_n_selected         (TotemSelectionToolbar *bar);
+void            totem_selection_toolbar_set_show_delete_button (TotemSelectionToolbar *bar,
+                                                                gboolean               show_delete_button);
+gboolean        totem_selection_toolbar_get_show_delete_button (TotemSelectionToolbar *bar);
+
+G_END_DECLS
+
+#endif /* __TOTEM_SELECTION_TOOLBAR_H__ */
diff --git a/src/plugins/grilo/totemselectiontoolbar.ui b/src/plugins/grilo/totemselectiontoolbar.ui
new file mode 100644
index 0000000..a6f81b7
--- /dev/null
+++ b/src/plugins/grilo/totemselectiontoolbar.ui
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="totem">
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="TotemSelectionToolbar" parent="GtkActionBar">
+    <property name="app_paintable">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin">6</property>
+      <child>
+        <object class="GtkButton" id="add_to_fav">
+          <property name="visible">True</property>
+          <property name="can_focus">True</property>
+          <property name="receives_default">True</property>
+          <property name="no-show-all">True</property>
+          <child internal-child="accessible">
+            <object class="AtkObject" id="add-to-fav-atkobject">
+              <property name="AtkObject::accessible-name" translatable="yes">Add to Favourites</property>
+            </object>
+         </child>
+          <style>
+            <class name="image-button"/>
+          </style>
+          <child>
+            <object class="GtkImage" id="add_to_fav_image">
+              <property name="visible">True</property>
+              <property name="can_focus">False</property>
+              <property name="icon_name">emblem-favorite-symbolic</property>
+              <property name="icon_size">1</property>
+            </object>
+          </child>
+        </object>
+        <packing>
+          <property name="pack_type">start</property>
+        </packing>
+      </child>
+      <child>
+        <object class="GtkButton" id="play">
+          <property name="visible">True</property>
+          <property name="can_focus">True</property>
+          <property name="receives_default">True</property>
+          <property name="no-show-all">True</property>
+          <property name="label">Play</property>
+          <child internal-child="accessible">
+            <object class="AtkObject" id="play-atkobject">
+              <property name="AtkObject::accessible-name" translatable="yes">Play</property>
+            </object>
+         </child>
+          <style>
+            <class name="image-button"/>
+          </style>
+        </object>
+        <packing>
+          <property name="pack_type">start</property>
+        </packing>
+      </child>
+      <child>
+        <object class="GtkButton" id="shuffle">
+          <property name="visible">True</property>
+          <property name="can_focus">True</property>
+          <property name="receives_default">True</property>
+          <property name="no-show-all">True</property>
+          <property name="label">Shuffle</property>
+          <child internal-child="accessible">
+            <object class="AtkObject" id="shuffle-atkobject">
+              <property name="AtkObject::accessible-name" translatable="yes">Shuffle</property>
+            </object>
+         </child>
+          <style>
+            <class name="image-button"/>
+          </style>
+        </object>
+        <packing>
+          <property name="pack_type">start</property>
+        </packing>
+      </child>
+      <child>
+        <object class="GtkButton" id="delete">
+          <property name="visible">True</property>
+          <property name="can_focus">True</property>
+          <property name="receives_default">True</property>
+         <property name="no-show-all">True</property>
+         <property name="label">Delete</property>
+          <child internal-child="accessible">
+            <object class="AtkObject" id="delete-atkobject">
+              <property name="AtkObject::accessible-name" translatable="yes">Delete</property>
+            </object>
+         </child>
+          <style>
+            <class name="image-button"/>
+            <class name="destructive-action"/>
+          </style>
+        </object>
+        <packing>
+          <property name="pack_type">end</property>
+        </packing>
+      </child>
+  </template>
+</interface>


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