[gnome-photos/wip/abono/sidebar: 13/14] WIP sidebar



commit f9a4ac9dbee99dd21c0c409d8d93df1bc2501cc3
Author: Alessandro Bono <abono gnome org>
Date:   Sat Nov 12 12:31:50 2016 +0100

    WIP sidebar

 src/photos-properties-sidebar.c  |   77 +++++++++++++++++++++++++++++++++++++-
 src/photos-properties-sidebar.h  |    3 +
 src/photos-properties-sidebar.ui |   29 ++++++++++++++
 3 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/src/photos-properties-sidebar.c b/src/photos-properties-sidebar.c
index 0737e79..942c283 100644
--- a/src/photos-properties-sidebar.c
+++ b/src/photos-properties-sidebar.c
@@ -19,13 +19,17 @@
  */
 
 #include "photos-properties-sidebar.h"
+#include "photos-fetch-collections-job.h"
+#include "photos-filterable.h"
 
 struct _PhotosPropertiesSidebar
 {
   GtkScrolledWindow parent_instance;
   GtkWidget *albums_list_box;
   GtkWidget *description_text_view;
+  GtkWidget *source_grid;
   GtkWidget *title_entry;
+  PhotosBaseItem *item;
 };
 
 struct _PhotosPropertiesSidebarClass
@@ -72,6 +76,39 @@ photos_properties_sidebar_get_property (GObject    *object,
 }
 
 static void
+photos_properties_sidebar_on_collection_fetched (GObject *source_object,
+                                                 GAsyncResult *res,
+                                                 gpointer user_data)
+{
+  PhotosPropertiesSidebar *self = PHOTOS_PROPERTIES_SIDEBAR (user_data);
+  PhotosFetchCollectionsJob *job = PHOTOS_FETCH_COLLECTIONS_JOB (source_object);
+  GError *error = NULL;
+  GList *collection_urns;
+  GList *l;
+  GListStore *collections_model;
+
+  collection_urns = photos_fetch_collections_job_finish (job, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to fetch collections: %s", error->message);
+      g_error_free (error);
+    }
+
+    collections_model = g_list_store_new (photos_base_item_get_type ());
+    for (l = collection_urns; l != NULL; l = g_list_next (l))
+      {
+        const gchar *urn = l->data;
+
+        //TODO
+        GtkWidget *label = gtk_label_new(urn);
+        gtk_widget_show (label);
+        gtk_list_box_insert (GTK_LIST_BOX (self->albums_list_box), label, 0);
+      }
+
+  g_object_unref (self);
+}
+
+static void
 photos_properties_sidebar_set_property (GObject      *object,
                                         guint         prop_id,
                                         const GValue *value,
@@ -99,13 +136,51 @@ photos_properties_sidebar_class_init (PhotosPropertiesSidebarClass *klass)
   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, source_grid);
   gtk_widget_class_bind_template_child (widget_class, PhotosPropertiesSidebar, title_entry);
 }
 
 static void
 photos_properties_sidebar_init (PhotosPropertiesSidebar *self)
 {
+  GtkWidget *label;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  //gtk_list_box_set_placeholder (GTK_LIST_BOX (self->albums_list_box), gtk_label_new ("test"));
+  //TODO
+  label = gtk_label_new("No albums");
+  gtk_widget_show (label);
+  gtk_list_box_set_placeholder (GTK_LIST_BOX (self->albums_list_box), label);
+
+}
+
+void
+photos_properties_sidebar_set_item (PhotosPropertiesSidebar *self, PhotosBaseItem *item)
+{
+  GtkWidget *source_widget;
+  const gchar *resource_urn;
+
+  if (self->item != NULL)
+    {
+      g_object_unref(self->item);
+      //TODO clear
+    }
+
+  self->item = g_object_ref (item);
+
+
+  gtk_entry_set_text (GTK_ENTRY (self->title_entry), photos_base_item_get_name_with_fallback (item));
+
+  resource_urn = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+  PhotosFetchCollectionsJob *collection_fetcher = photos_fetch_collections_job_new (resource_urn);
+  photos_fetch_collections_job_run (collection_fetcher,
+                                    NULL,
+                                    photos_properties_sidebar_on_collection_fetched,
+                                    g_object_ref (self));
+  g_object_unref (collection_fetcher);
+
+  source_widget = photos_base_item_get_source_widget (item);
+  gtk_widget_show (GTK_WIDGET (source_widget));
+  gtk_container_add (GTK_CONTAINER(self->source_grid), source_widget);
+
 }
diff --git a/src/photos-properties-sidebar.h b/src/photos-properties-sidebar.h
index 93f2dcd..76bc4d9 100644
--- a/src/photos-properties-sidebar.h
+++ b/src/photos-properties-sidebar.h
@@ -30,6 +30,9 @@ G_DECLARE_FINAL_TYPE (PhotosPropertiesSidebar, photos_properties_sidebar, PHOTOS
 
 GtkWidget             *photos_properties_sidebar_new                    (void);
 
+void                   photos_properties_sidebar_set_item               (PhotosPropertiesSidebar *self,
+                                                                         PhotosBaseItem *item);
+
 G_END_DECLS
 
 #endif /* PHOTOS_PROPERTIES_SIDEBAR_H */
diff --git a/src/photos-properties-sidebar.ui b/src/photos-properties-sidebar.ui
index 9dc2747..0b71fdb 100644
--- a/src/photos-properties-sidebar.ui
+++ b/src/photos-properties-sidebar.ui
@@ -195,6 +195,35 @@
                 <property name="top_attach">3</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkGrid" id="source_grid">
+                <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="label" translatable="yes">Source</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>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
           </object>
         </child>
       </object>


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