[gnome-photos/wip/abono/sidebar: 633/635] WIP Albums



commit 031a8cc51bcbb8555497a5395d5f7be39d373588
Author: Alessandro Bono <abono gnome org>
Date:   Thu Nov 2 15:53:16 2017 +0100

    WIP Albums

 src/photos-properties-sidebar.c  |   71 ++++++++++++++++++++++++++++++++++++++
 src/photos-properties-sidebar.ui |   60 ++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-properties-sidebar.c b/src/photos-properties-sidebar.c
index 3c7c767..f334642 100644
--- a/src/photos-properties-sidebar.c
+++ b/src/photos-properties-sidebar.c
@@ -18,7 +18,10 @@
  * 02110-1301, USA.
  */
 
+#include "config.h"
+
 #include "photos-base-item.h"
+#include "photos-fetch-collections-job.h"
 #include "photos-filterable.h"
 #include "photos-properties-sidebar.h"
 #include "photos-utils.h"
@@ -26,6 +29,7 @@
 struct _PhotosPropertiesSidebar
 {
   GtkScrolledWindow parent_instance;
+  GtkWidget *albums_list_box;
   GtkWidget *description_text_view;
   GtkWidget *title_entry;
   PhotosBaseItem *item;
@@ -70,6 +74,7 @@ photos_properties_sidebar_class_init (PhotosPropertiesSidebarClass *klass)
   object_class->finalize = photos_properties_sidebar_finalize;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/properties-sidebar.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosPropertiesSidebar, albums_list_box);
   gtk_widget_class_bind_template_child (widget_class, PhotosPropertiesSidebar, description_text_view);
   gtk_widget_class_bind_template_child (widget_class, PhotosPropertiesSidebar, title_entry);
 }
@@ -83,6 +88,9 @@ photos_properties_sidebar_init (PhotosPropertiesSidebar *self)
 static void
 photos_properties_sidebar_clear (PhotosPropertiesSidebar *self)
 {
+  GList *children;
+  GList *l;
+
   /* FIXME: g_object_clear () gives problems */
   if (self->item)
     {
@@ -91,11 +99,66 @@ photos_properties_sidebar_clear (PhotosPropertiesSidebar *self)
     }
 
   gtk_entry_set_text (GTK_ENTRY (self->title_entry), "");
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->albums_list_box));
+  for(l = children; l != NULL; l = g_list_next(l))
+    gtk_container_remove (GTK_CONTAINER (self->albums_list_box), GTK_WIDGET (l->data));
+}
+
+
+static void
+photos_properties_sidebar_on_collection_fetched (GObject *source_object,
+                                                 GAsyncResult *res,
+                                                 gpointer user_data)
+{
+  GApplication *app;
+  GError *error = NULL;
+  GList *collection_ids;
+  GList *l;
+  PhotosBaseManager *item_mngr;
+  PhotosFetchCollectionsJob *job = PHOTOS_FETCH_COLLECTIONS_JOB (source_object);
+  PhotosPropertiesSidebar *self = PHOTOS_PROPERTIES_SIDEBAR (user_data);
+  PhotosSearchContextState *state;
+
+  collection_ids = photos_fetch_collections_job_finish (job, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to fetch collections: %s", error->message);
+      g_error_free (error);
+    }
+
+    app = g_application_get_default ();
+    state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+    item_mngr = g_object_ref (state->item_mngr);
+
+    for (l = collection_ids; l != NULL; l = g_list_next (l))
+      {
+        const gchar *collection_name;
+        const gchar *collection_id = l->data;
+        PhotosBaseItem *collection;
+        GtkWidget *label;
+
+        collection = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (item_mngr, collection_id));
+        // avoid to show its folder as a collection
+        if(!photos_base_item_is_collection (collection))
+          continue;
+
+        collection_name = photos_base_item_get_name (collection);
+        label = gtk_label_new (collection_name);
+        gtk_widget_show (label);
+        gtk_list_box_insert (GTK_LIST_BOX (self->albums_list_box), label, 0);
+      }
+
+  g_object_unref (self);
 }
 
+
 void
 photos_properties_sidebar_set_item (PhotosPropertiesSidebar *self, PhotosBaseItem *item)
 {
+  PhotosFetchCollectionsJob *collection_fetcher;
+  const gchar *item_id;
+
   photos_properties_sidebar_clear (self);
 
   self->item = g_object_ref (item);
@@ -105,4 +168,12 @@ photos_properties_sidebar_set_item (PhotosPropertiesSidebar *self, PhotosBaseIte
                             "changed",
                             G_CALLBACK (photos_properties_sidebar_name_update),
                             self);
+
+  item_id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+  collection_fetcher = photos_fetch_collections_job_new (item_id);
+  photos_fetch_collections_job_run (collection_fetcher,
+                                    NULL,
+                                    photos_properties_sidebar_on_collection_fetched,
+                                    g_object_ref (self));
+  g_object_unref (collection_fetcher);
 }
diff --git a/src/photos-properties-sidebar.ui b/src/photos-properties-sidebar.ui
index 647d280..4de4e09 100644
--- a/src/photos-properties-sidebar.ui
+++ b/src/photos-properties-sidebar.ui
@@ -101,6 +101,66 @@
                 <property name="top_attach">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="hexpand">True</property>
+                    <property name="label" translatable="yes">Albums</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">image-edit-symbolic</property>
+                      </object>
+                    </child>
+                    <style>
+                      <class name="circular"/>
+                      <class name="flat"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkListBox" id="albums_list_box">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
           </object>
         </child>
       </object>


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