[gnome-photos/wip/rishi/collection: 29/54] Add PhotosRemovableDeviceWidget
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 29/54] Add PhotosRemovableDeviceWidget
- Date: Tue, 6 Feb 2018 23:25:37 +0000 (UTC)
commit 5d979c28f87a26263b9a40396c81248426143cdb
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jan 12 17:27:56 2018 +0100
Add PhotosRemovableDeviceWidget
https://gitlab.gnome.org/GNOME/gnome-photos/issues/29
src/Makefile.am | 3 +
src/photos-removable-device-widget.c | 162 ++++++++++++++++++++++++++++++++++
src/photos-removable-device-widget.h | 42 +++++++++
src/photos-removable-device-widget.ui | 42 +++++++++
src/photos.gresource.xml | 1 +
5 files changed, 250 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ed669f95..f87164fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -205,6 +205,8 @@ gnome_photos_SOURCES = \
photos-query-builder.c \
photos-remote-display-manager.c \
photos-remote-display-manager.h \
+ photos-removable-device-widget.c \
+ photos-removable-device-widget.h \
photos-search-context.c \
photos-search-context.h \
photos-search-controller.c \
@@ -378,6 +380,7 @@ EXTRA_DIST = \
photos-marshalers.list \
photos-menus.ui \
photos-preview-menu.ui \
+ photos-removable-device-widget.ui \
photos-selection-menu.ui \
photos-selection-toolbar.ui \
photos-share-dialog.ui \
diff --git a/src/photos-removable-device-widget.c b/src/photos-removable-device-widget.c
new file mode 100644
index 00000000..35298417
--- /dev/null
+++ b/src/photos-removable-device-widget.c
@@ -0,0 +1,162 @@
+/*
+ * 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 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 "config.h"
+
+#include <gio/gio.h>
+
+#include "photos-removable-device-widget.h"
+
+
+struct _PhotosRemovableDeviceWidget
+{
+ GtkBin parent_instance;
+ GtkWidget *image;
+ GtkWidget *label;
+ PhotosSource *source;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SOURCE,
+};
+
+
+G_DEFINE_TYPE (PhotosRemovableDeviceWidget, photos_removable_device_widget, GTK_TYPE_BIN);
+
+
+static void
+photos_removable_device_widget_dispose (GObject *object)
+{
+ PhotosRemovableDeviceWidget *self = PHOTOS_REMOVABLE_DEVICE_WIDGET (object);
+
+ g_clear_object (&self->source);
+
+ G_OBJECT_CLASS (photos_removable_device_widget_parent_class)->dispose (object);
+}
+
+
+static void
+photos_removable_device_widget_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec
*pspec)
+{
+ PhotosRemovableDeviceWidget *self = PHOTOS_REMOVABLE_DEVICE_WIDGET (object);
+
+ switch (prop_id)
+ {
+ case PROP_SOURCE:
+ {
+ PhotosSource *source;
+
+ source = PHOTOS_SOURCE (g_value_get_object (value));
+ photos_removable_device_widget_set_source (self, source);
+ break;
+ }
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_removable_device_widget_init (PhotosRemovableDeviceWidget *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+
+static void
+photos_removable_device_widget_class_init (PhotosRemovableDeviceWidgetClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->dispose = photos_removable_device_widget_dispose;
+ object_class->set_property = photos_removable_device_widget_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_SOURCE,
+ g_param_spec_object ("source",
+ "Source",
+ "The GMount-backed source being displayed by this
widget",
+ PHOTOS_TYPE_SOURCE,
+ G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/removable-device-widget.ui");
+ gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDeviceWidget, image);
+ gtk_widget_class_bind_template_child (widget_class, PhotosRemovableDeviceWidget, label);
+}
+
+
+GtkWidget *
+photos_removable_device_widget_new (PhotosSource *source)
+{
+ g_return_val_if_fail (source == NULL || PHOTOS_IS_SOURCE (source), NULL);
+
+ if (source != NULL)
+ {
+ GMount *mount;
+
+ mount = photos_source_get_mount (source);
+ g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
+ }
+
+ return g_object_new (PHOTOS_TYPE_REMOVABLE_DEVICE_WIDGET, "source", source, NULL);
+}
+
+
+void
+photos_removable_device_widget_set_source (PhotosRemovableDeviceWidget *self, PhotosSource *source)
+{
+ g_return_if_fail (PHOTOS_IS_REMOVABLE_DEVICE_WIDGET (self));
+ g_return_if_fail (source == NULL || PHOTOS_IS_SOURCE (source));
+
+ if (source != NULL)
+ {
+ GMount *mount;
+
+ mount = photos_source_get_mount (source);
+ g_return_if_fail (G_IS_MOUNT (mount));
+ }
+
+ if (!g_set_object (&self->source, source))
+ goto out;
+
+ if (self->source == NULL)
+ {
+ gtk_image_clear (GTK_IMAGE (self->image));
+ gtk_label_set_label (GTK_LABEL (self->label), "");
+ }
+ else
+ {
+ GIcon *icon;
+ const gchar *name;
+
+ icon = photos_source_get_symbolic_icon (self->source);
+ gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon, GTK_ICON_SIZE_BUTTON);
+
+ name = photos_source_get_name (source);
+ gtk_label_set_label (GTK_LABEL (self->label), name);
+ }
+
+ out:
+ return;
+}
diff --git a/src/photos-removable-device-widget.h b/src/photos-removable-device-widget.h
new file mode 100644
index 00000000..5503f7f8
--- /dev/null
+++ b/src/photos-removable-device-widget.h
@@ -0,0 +1,42 @@
+/*
+ * 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 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 PHOTOS_REMOVABLE_DEVICE_WIDGET_H
+#define PHOTOS_REMOVABLE_DEVICE_WIDGET_H
+
+#include <gtk/gtk.h>
+
+#include "photos-source.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_REMOVABLE_DEVICE_WIDGET (photos_removable_device_widget_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosRemovableDeviceWidget,
+ photos_removable_device_widget,
+ PHOTOS,
+ REMOVABLE_DEVICE_WIDGET,
+ GtkBin);
+
+GtkWidget *photos_removable_device_widget_new (PhotosSource *source);
+
+void photos_removable_device_widget_set_source (PhotosRemovableDeviceWidget *self,
+ PhotosSource *source);
+
+G_END_DECLS
+
+#endif /* PHOTOS_REMOVABLE_DEVICE_WIDGET_H */
diff --git a/src/photos-removable-device-widget.ui b/src/photos-removable-device-widget.ui
new file mode 100644
index 00000000..0cc51de2
--- /dev/null
+++ b/src/photos-removable-device-widget.ui
@@ -0,0 +1,42 @@
+<?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 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/>.
+-->
+<interface>
+ <template class="PhotosRemovableDeviceWidget" parent="GtkBin">
+ <child>
+ <object class="GtkGrid">
+ <property name="column-spacing">12</property>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="use-fallback">1</property>
+ <property name="valign">GTK_ALIGN_CENTER</property>
+ <property name="vexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+ <property name="max-width-chars">24</property>
+ <property name="valign">GTK_ALIGN_CENTER</property>
+ <property name="vexpand">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 2b0aa938..46d06a37 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -27,6 +27,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-device-widget.ui" preprocess="xml-stripblanks"
compressed="true">photos-removable-device-widget.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]