[nautilus/wip/gbsneto/other-locations: 7/7] view: add NautilusView interface



commit 12f39bbb227f9e96c4ab1840241922706f776cc5
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jul 16 22:11:03 2015 -0300

    view: add NautilusView interface
    
    Nautilus is receiving the new Other Locations view
    from the latest Gtk+ versions to match the new proposed
    mockups that shrink the sidebar.
    
    The current hierarchy of classes, however, makes it
    difficult to happen without some refactoring of the
    class hierarchy chain, as they are very coupled.
    
    Create a new abstraction layer by adding an interface
    named NautilusView, that will contain all the necessary
    methods to dettach NautilusFilesView code.

 src/Makefile.am     |    2 +
 src/nautilus-view.c |  217 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-view.h |   76 ++++++++++++++++++
 3 files changed, 295 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d0ba452..03a3fbb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -206,6 +206,8 @@ nautilus_SOURCES = \
        nautilus-toolbar.h                      \
        nautilus-trash-bar.c                    \
        nautilus-trash-bar.h                    \
+       nautilus-view.c                         \
+       nautilus-view.h                         \
        nautilus-window-slot.c                  \
        nautilus-window-slot.h                  \
        nautilus-window-slot-dnd.c              \
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
new file mode 100644
index 0000000..62bc151
--- /dev/null
+++ b/src/nautilus-view.c
@@ -0,0 +1,217 @@
+/* nautilus-view.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 "nautilus-view.h"
+
+#include <glib/gi18n.h>
+
+G_DEFINE_INTERFACE (NautilusView, nautilus_view, GTK_TYPE_WIDGET)
+
+static void
+nautilus_view_default_init (NautilusViewInterface *iface)
+{
+  /**
+   * NautilusView::action-group:
+   *
+   * The action group of the implementing view. Different views may
+   * have different sets of actions.
+   *
+   * Since: 3.18
+   */
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("action-group",
+                                                            _("Action group of the view"),
+                                                            _("The action group of the view"),
+                                                            G_TYPE_ACTION_GROUP,
+                                                            G_PARAM_READABLE));
+
+  /**
+   * NautilusView::loading:
+   *
+   * Whether the view is loading or not.
+   *
+   * Since: 3.18
+   */
+  g_object_interface_install_property (iface,
+                                       g_param_spec_boolean ("loading",
+                                                            _("Whether the view is loading"),
+                                                            _("Whether the view is loading or not"),
+                                                            FALSE,
+                                                            G_PARAM_READABLE));
+
+  /**
+   * NautilusView::location:
+   *
+   * The current location of the view.
+   *
+   * Since: 3.18
+   */
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("location",
+                                                            _("Location the view is displaying"),
+                                                            _("The location the view is displaying"),
+                                                            G_TYPE_FILE,
+                                                            G_PARAM_READABLE));
+
+  /**
+   * NautilusView::search-query:
+   *
+   * The search query the view should search for.
+   *
+   * Since: 3.18
+   */
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("search-query",
+                                                            _("Search query that view is performing"),
+                                                            _("The search query that view is performing"),
+                                                            NAUTILUS_TYPE_QUERY,
+                                                            G_PARAM_READWRITE));
+
+  /**
+   * NautilusView::open-location:
+   * @view: the object which received the signal.
+   * @location: (type Gio.File): #GFile to which the caller should switch.
+   * @flags: a single value from #GtkPlacesOpenFlags specifying how the @location
+   * should be opened.
+   *
+   * Emited when the view wants the parent slot to open a location.
+   *
+   * Since: 3.18
+   */
+  g_signal_new ("open-location",
+                G_TYPE_FROM_INTERFACE (iface),
+                G_SIGNAL_RUN_LAST,
+                G_STRUCT_OFFSET (NautilusViewInterface, open_location),
+                NULL,
+                NULL,
+                g_cclosure_marshal_VOID__VOID,
+                G_TYPE_NONE,
+                2,
+                G_TYPE_FILE,
+                GTK_TYPE_PLACES_OPEN_FLAGS);
+}
+
+/**
+ * nautilus_view_get_action_group:
+ * @view: a #NautilusView
+ *
+ * Retrieves the #GActionGroup grom @view, or %NULL if none is set.
+ *
+ * Returns: (transfer none): the @view's #GActionGroup
+ */
+GActionGroup*
+nautilus_view_get_action_group (NautilusView *view)
+{
+  g_return_val_if_fail (NAUTILUS_IS_VIEW (view), NULL);
+  g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_action_group, NULL);
+
+  return NAUTILUS_VIEW_GET_IFACE (view)->get_action_group (view);
+}
+
+/**
+ * nautilus_view_get_loading:
+ * @view: a #NautilusView
+ *
+ * Retrieves the loading state of @view.
+ *
+ * Returns: %TRUE if @view is loading, %FALSE if it's ready.
+ */
+gboolean
+nautilus_view_get_loading (NautilusView *view)
+{
+  g_return_val_if_fail (NAUTILUS_IS_VIEW (view), FALSE);
+  g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_loading, FALSE);
+
+  return NAUTILUS_VIEW_GET_IFACE (view)->get_loading (view);
+}
+
+/**
+ * nautilus_view_get_location:
+ *
+ * Retrieves the current location that @view is displaying, or %NULL
+ * if none is set.
+ *
+ * Returns: (transfer none): A #GFile representing the location that
+ * @view is displaying.
+ */
+GFile*
+nautilus_view_get_location (NautilusView *view)
+{
+  g_return_val_if_fail (NAUTILUS_IS_VIEW (view), NULL);
+  g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_location, NULL);
+
+  return NAUTILUS_VIEW_GET_IFACE (view)->get_location (view);
+}
+
+/**
+ * nautilus_view_get_search_query:
+ *
+ * Retrieves the current search query that @view is performing, or %NULL
+ * if none is set.
+ *
+ * Returns: (transfer none): A #NautilusQuery representing the search that
+ * @view is displaying.
+ */
+NautilusQuery*
+nautilus_view_get_search_query (NautilusView *view)
+{
+  g_return_val_if_fail (NAUTILUS_IS_VIEW (view), NULL);
+  g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_search_query, NULL);
+
+  return NAUTILUS_VIEW_GET_IFACE (view)->get_search_query (view);
+}
+
+/**
+ * nautilus_view_set_search_query:
+ *
+ * Sets the search query that @view should perform, or %NULL to stop
+ * the current search.
+ *
+ * Returns:
+ */
+void
+nautilus_view_set_search_query (NautilusView  *view,
+                                NautilusQuery *query)
+{
+  g_return_if_fail (NAUTILUS_IS_VIEW (view));
+  g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_search_query);
+
+  NAUTILUS_VIEW_GET_IFACE (view)->set_search_query (view, query);
+}
+
+/**
+ * nautilus_view_popup_pathbar_context_menu:
+ * @view: a #NautilusView
+ * @event: a #GdkEventButton
+ * @location: the location the popup-menu should be created for, or %NULL
+ * for the currently displayed location.
+ *
+ * Shows a popup context menu for the window's pathbar.
+ *
+ * Returns: %TRUE if @view is loading, %FALSE if it's ready.
+ */
+void
+nautilus_view_popup_pathbar_context_menu (NautilusView   *view,
+                                          GdkEventButton *event,
+                                          const gchar    *location)
+{
+  g_return_if_fail (NAUTILUS_IS_VIEW (view));
+  g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->popup_pathbar_context_menu);
+
+  NAUTILUS_VIEW_GET_IFACE (view)->popup_pathbar_context_menu (view, event, location);
+}
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
new file mode 100644
index 0000000..ed32125
--- /dev/null
+++ b/src/nautilus-view.h
@@ -0,0 +1,76 @@
+/* nautilus-view.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 NAUTILUS_VIEW_H
+#define NAUTILUS_VIEW_H
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include <libnautilus-private/nautilus-query.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_VIEW          (nautilus_view_get_type ())
+
+G_DECLARE_INTERFACE (NautilusView, nautilus_view, NAUTILUS, VIEW, GtkWidget)
+
+struct _NautilusViewInterface
+{
+  GTypeInterface parent;
+
+  /* methods */
+  GActionGroup*    (*get_action_group)                         (NautilusView         *view);
+
+  gboolean         (*get_loading)                              (NautilusView         *view);
+
+  GFile*           (*get_location)                             (NautilusView         *view);
+
+  NautilusQuery*   (*get_search_query)                         (NautilusView         *view);
+
+  void             (*set_search_query)                         (NautilusView         *view,
+                                                                NautilusQuery        *query);
+
+  void             (*popup_pathbar_context_menu)               (NautilusView         *view,
+                                                                GdkEventButton       *event,
+                                                                const gchar          *location);
+
+  /* signal slots */
+  void             (*open_location)                            (NautilusView         *view,
+                                                                GFile                *location,
+                                                                GtkPlacesOpenFlags    flags);
+};
+
+GActionGroup*      nautilus_view_get_action_group              (NautilusView         *view);
+
+gboolean           nautilus_view_get_loading                   (NautilusView         *view);
+
+GFile*             nautilus_view_get_location                  (NautilusView         *view);
+
+NautilusQuery*     nautilus_view_get_search_query              (NautilusView         *view);
+
+void               nautilus_view_set_search_query              (NautilusView         *view,
+                                                                NautilusQuery        *query);
+
+void               nautilus_view_popup_pathbar_context_menu    (NautilusView         *view,
+                                                                GdkEventButton       *event,
+                                                                const gchar          *location);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_VIEW_H */


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