[gnome-photos/wip/rishi/collection: 15/17] Add PhotosRemovableDevicesButton



commit ac86f112995b030432852afcb33ae4a469844271
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jan 12 09:43:42 2018 +0100

    Add PhotosRemovableDevicesButton
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751212

 src/Makefile.am                        |   3 +
 src/photos-removable-devices-button.c  | 166 +++++++++++++++++++++++++++++++++
 src/photos-removable-devices-button.h  |  39 ++++++++
 src/photos-removable-devices-button.ui |  79 ++++++++++++++++
 src/photos.gresource.xml               |   1 +
 5 files changed, 288 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b397c814..3c8b4631 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -210,6 +210,8 @@ gnome_photos_SOURCES = \
        photos-query-builder.c \
        photos-remote-display-manager.c \
        photos-remote-display-manager.h \
+       photos-removable-devices-button.c \
+       photos-removable-devices-button.h \
        photos-search-context.c \
        photos-search-context.h \
        photos-search-controller.c \
@@ -387,6 +389,7 @@ EXTRA_DIST = \
        photos-marshalers.list \
        photos-menus.ui \
        photos-preview-menu.ui \
+       photos-removable-devices-button.ui \
        photos-selection-menu.ui \
        photos-selection-toolbar.ui \
        photos-share-dialog.ui \
diff --git a/src/photos-removable-devices-button.c b/src/photos-removable-devices-button.c
new file mode 100644
index 00000000..e8845222
--- /dev/null
+++ b/src/photos-removable-devices-button.c
@@ -0,0 +1,166 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
+#include "photos-search-context.h"
+#include "photos-removable-devices-button.h"
+
+
+struct _PhotosRemovableDevicesButton
+{
+  GtkBin parent_instance;
+  GtkWidget *device_button;
+  GtkWidget *device_widget;
+  GtkWidget *devices_button;
+  GtkWidget *devices_popover;
+  GtkWidget *devices_popover_grid;
+  GtkWidget *stack;
+  PhotosBaseManager *src_mngr;
+};
+
+
+G_DEFINE_TYPE (PhotosRemovableDevicesButton, photos_removable_devices_button, GTK_TYPE_BIN);
+
+
+static void
+photos_removable_devices_button_refresh_devices (PhotosRemovableDevicesButton *self)
+{
+  GList *sources = NULL;
+  gboolean visible = FALSE;
+  guint i;
+  guint n_items;
+
+  photos_removable_device_widget_set_source (PHOTOS_REMOVABLE_DEVICE_WIDGET (self->device_widget), NULL);
+  gtk_container_foreach (GTK_CONTAINER (self->devices_popover_grid), (GtkCallback) gtk_widget_destroy, NULL);
+
+  n_items = g_list_model_get_n_items (G_LIST_MODEL (self->src_mngr));
+  for (i = 0; i < n_items; i++)
+    {
+      GMount *mount;
+      g_autoptr (PhotosSource) source = NULL;
+
+      source = PHOTOS_SOURCE (g_list_model_get_object (G_LIST_MODEL (self->src_mngr), i));
+      mount = photos_source_get_mount (source);
+      if (mount == NULL)
+        continue;
+
+      sources = g_list_prepend (sources, g_object_ref (source));
+    }
+
+  if (sources == NULL)
+    goto out;
+
+  if (sources->next == NULL) /* length == 1 */
+    {
+      PhotosSource *source = PHOTOS_SOURCE (sources->data);
+
+      photos_removable_device_widget_set_source (PHOTOS_REMOVABLE_DEVICE_WIDGET (self->device_widget), 
source);
+      gtk_stack_set_visible_child (GTK_STACK (self->stack), self->device_widget);
+    }
+  else
+    {
+      GList *l;
+
+      for (l = sources; l != NULL; l = l->next)
+        {
+          GtkWidget *device_widget;
+          PhotosSource *source = PHOTOS_SOURCE (l->data);
+
+          device_widget = photos_removable_device_widget_new (source);
+          gtk_container_add (GTK_CONTAINER (self->devices_popover_grid), device_widget);
+          gtk_widget_show_all (device_widget);
+        }
+
+      gtk_stack_set_visible_child (GTK_STACK (self->stack), self->devices_button);
+    }
+
+  visible = TRUE;
+
+ out:
+  gtk_widget_set_visible (self->stack, visible);
+  g_list_free_full (sources, g_object_unref);
+}
+
+
+static void
+photos_removable_devices_button_dispose (GObject *object)
+{
+  PhotosRemovableDevicesButton *self = PHOTOS_REMOVABLE_DEVICES_BUTTON (object);
+
+  g_clear_object (&self->src_mngr);
+
+  G_OBJECT_CLASS (photos_removable_devices_button_parent_class)->dispose (object);
+}
+
+
+static void
+photos_removable_devices_button_init (PhotosRemovableDevicesButton *self)
+{
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  self->src_mngr = g_object_ref (state->src_mngr);
+  g_signal_connect_object (self->src_mngr,
+                           "object-added",
+                           G_CALLBACK (photos_removable_devices_button_refresh_devices),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->src_mngr,
+                           "object-removed",
+                           G_CALLBACK (photos_removable_devices_button_refresh_devices),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  photos_removable_devices_button_refresh_devices (self);
+}
+
+
+static void
+photos_removable_devices_button_class_init (PhotosRemovableDevicesButtonClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_removable_devices_button_dispose;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Photos/removable-devices-button.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, device_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, device_widget);
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, devices_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, devices_popover);
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, devices_popover_grid);
+  gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDevicesButton, stack);
+}
+
+
+GtkWidget *
+photos_removable_devices_button_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_REMOVABLE_DEVICES_BUTTON, NULL);
+}
diff --git a/src/photos-removable-devices-button.h b/src/photos-removable-devices-button.h
new file mode 100644
index 00000000..7c644b3d
--- /dev/null
+++ b/src/photos-removable-devices-button.h
@@ -0,0 +1,39 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_REMOVABLE_DEVICES_BUTTON_H
+#define PHOTOS_REMOVABLE_DEVICES_BUTTON_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_REMOVABLE_DEVICES_BUTTON (photos_removable_devices_button_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosRemovableDevicesButton,
+                      photos_removable_devices_button,
+                      PHOTOS,
+                      REMOVABLE_DEVICES_BUTTON,
+                      GtkBin);
+
+GtkWidget            *photos_removable_devices_button_new               (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_REMOVABLE_DEVICES_BUTTON_H */
diff --git a/src/photos-removable-devices-button.ui b/src/photos-removable-devices-button.ui
new file mode 100644
index 00000000..1baaf540
--- /dev/null
+++ b/src/photos-removable-devices-button.ui
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Photos - access, organize and share your photos on GNOME
+ Copyright © 2018 Red Hat, Inc.
+
+ 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 2
+ 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, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+-->
+<interface>
+  <template class="PhotosRemovableDevicesButton" parent="GtkBin">
+    <child>
+      <object class="GtkStack" id="stack">
+        <property name="no-show-all">1</property>
+        <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
+        <child>
+          <object class="GtkButton" id="device_button">
+            <property name="visible">1</property>
+            <child>
+              <object class="PhotosRemovableDeviceWidget" id="device_widget">
+                <property name="visible">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkMenuButton" id="devices_button">
+            <property name="popover">devices_popover</property>
+            <property name="visible">1</property>
+            <child>
+              <object class="GtkGrid">
+                <property name="column-spacing">12</property>
+                <property name="visible">1</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="label" translatable="yes">Devices</property>
+                    <property name="valign">GTK_ALIGN_CENTER</property>
+                    <property name="vexpand">1</property>
+                    <property name="visible">1</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">pan-down-symbolic</property>
+                    <property name="icon-size">GTK_ICON_SIZE_BUTTON</property>
+                    <property name="valign">GTK_ALIGN_CENTER</property>
+                    <property name="vexpand">1</property>
+                    <property name="visible">1</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkPopover" id="devices_popover">
+    <property name="visible">1</property>
+    <child>
+      <object class="GtkGrid" id="devices_popover_grid">
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <property name="row_spacing">12</property>
+        <property name="visible">1</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index f0676a77..bad0db8c 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -29,6 +29,7 @@
     <file alias="main-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-main-toolbar.ui</file>
     <file alias="main-window.ui" preprocess="xml-stripblanks" compressed="true">photos-main-window.ui</file>
     <file alias="preview-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-preview-menu.ui</file>
+    <file alias="removable-devices-button.ui" preprocess="xml-stripblanks" 
compressed="true">photos-removable-devices-button.ui</file>
     <file alias="selection-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-menu.ui</file>
     <file alias="selection-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-toolbar.ui</file>
     <file alias="share-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-share-dialog.ui</file>


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