[gnome-photos] Add PhotosSourceNotification
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosSourceNotification
- Date: Thu, 16 Feb 2017 16:30:36 +0000 (UTC)
commit fbe12f7e7714f68d9d7d5b564374caf2f3210259
Author: Umang Jain <mailumangjain gmail com>
Date: Sat Jan 21 16:40:01 2017 +0530
Add PhotosSourceNotification
Unlike most other notifications, this is not self-managed. It needs to
be explicitly shown and hidden.
Some changes by Debarshi Ray.
https://bugzilla.gnome.org/show_bug.cgi?id=777492
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/photos-source-notification.c | 259 ++++++++++++++++++++++++++++++++++++++
src/photos-source-notification.h | 42 ++++++
4 files changed, 304 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fc4161c..fc42acb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,7 @@ src/photos-selection-toolbar.c
src/photos-share-point-email.c
src/photos-share-point-google.c
src/photos-source-manager.c
+src/photos-source-notification.c
src/photos-spinner-box.c
src/photos-thumbnailer.c
src/photos-tool-colors.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 132cd44..bddc91d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -230,6 +230,8 @@ gnome_photos_SOURCES = \
photos-source.h \
photos-source-manager.c \
photos-source-manager.h \
+ photos-source-notification.c \
+ photos-source-notification.h \
photos-spinner-box.c \
photos-spinner-box.h \
photos-thumbnail-factory.c \
diff --git a/src/photos-source-notification.c b/src/photos-source-notification.c
new file mode 100644
index 0000000..a7379fa
--- /dev/null
+++ b/src/photos-source-notification.c
@@ -0,0 +1,259 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ * Copyright © 2017 Umang Jain
+ *
+ * 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 <glib/gi18n.h>
+
+#include "photos-source-notification.h"
+#include "photos-icons.h"
+
+
+struct _PhotosSourceNotification
+{
+ GtkGrid parent_instance;
+ PhotosSource *source;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SOURCE
+};
+
+enum
+{
+ CLOSED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE (PhotosSourceNotification, photos_source_notification, GTK_TYPE_GRID);
+
+
+static void
+photos_source_notification_close (PhotosSourceNotification *self)
+{
+ g_signal_emit (self, signals[CLOSED], 0);
+}
+
+
+static void
+photos_source_notification_settings_clicked (PhotosSourceNotification *self)
+{
+ GAppInfo *app = NULL;
+ GError *error;
+ GdkAppLaunchContext *ctx = NULL;
+ GdkDisplay *display;
+ GdkScreen *screen;
+ GoaAccount *account;
+ GoaObject *object;
+ const gchar *id;
+ gchar *command_line = NULL;
+
+ object = photos_source_get_goa_object (self->source);
+ g_return_if_fail (GOA_IS_OBJECT (object));
+
+ account = goa_object_peek_account (object);
+ id = goa_account_get_id (account);
+ command_line = g_strconcat ("gnome-control-center online-accounts ", id, NULL);
+
+ error = NULL;
+ app = g_app_info_create_from_commandline (command_line, NULL, G_APP_INFO_CREATE_NONE, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to launch gnome-control-center: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (self));
+ if (screen != NULL)
+ display = gdk_screen_get_display (screen);
+ else
+ display = gdk_display_get_default ();
+
+ ctx = gdk_display_get_app_launch_context (display);
+ if (screen != NULL)
+ gdk_app_launch_context_set_screen (ctx, screen);
+
+ error = NULL;
+ g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to launch gnome-control-center: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ out:
+ g_free (command_line);
+ g_clear_object (&ctx);
+ g_clear_object (&app);
+}
+
+
+static void
+photos_source_notification_constructed (GObject *object)
+{
+ PhotosSourceNotification *self = PHOTOS_SOURCE_NOTIFICATION (object);
+ GtkWidget *close;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *settings;
+ const gchar *name;
+ gchar *msg;
+
+ G_OBJECT_CLASS (photos_source_notification_parent_class)->constructed (object);
+
+ gtk_grid_set_column_spacing (GTK_GRID (self), 12);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
+
+ name = photos_source_get_name (self->source);
+ msg = g_strdup_printf (_("Your %s crendentials have expired"), name);
+
+ label = gtk_label_new (msg);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_container_add (GTK_CONTAINER (self), label);
+ g_free (msg);
+
+ settings = gtk_button_new_with_label (_("Settings"));
+ gtk_widget_set_valign (settings, GTK_ALIGN_CENTER);
+ gtk_container_add (GTK_CONTAINER (self), settings);
+ g_signal_connect_swapped (settings, "clicked", G_CALLBACK (photos_source_notification_settings_clicked),
self);
+
+ image = gtk_image_new_from_icon_name (PHOTOS_ICON_WINDOW_CLOSE_SYMBOLIC, GTK_ICON_SIZE_INVALID);
+ gtk_widget_set_margin_bottom (image, 2);
+ gtk_widget_set_margin_top (image, 2);
+ gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
+
+ close = gtk_button_new ();
+ gtk_widget_set_valign (close, GTK_ALIGN_CENTER);
+ gtk_widget_set_focus_on_click (close, FALSE);
+ gtk_button_set_relief (GTK_BUTTON (close), GTK_RELIEF_NONE);
+ gtk_button_set_image (GTK_BUTTON (close), image);
+ gtk_container_add (GTK_CONTAINER (self), close);
+ g_signal_connect_swapped (close, "clicked", G_CALLBACK (photos_source_notification_close), self);
+}
+
+
+static void
+photos_source_notification_dispose (GObject *object)
+{
+ PhotosSourceNotification *self = PHOTOS_SOURCE_NOTIFICATION (object);
+
+ g_clear_object (&self->source);
+
+ G_OBJECT_CLASS (photos_source_notification_parent_class)->dispose (object);
+}
+
+
+static void
+photos_source_notification_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosSourceNotification *self = PHOTOS_SOURCE_NOTIFICATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_SOURCE:
+ g_value_set_object (value, self->source);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_source_notification_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec
*pspec)
+{
+ PhotosSourceNotification *self = PHOTOS_SOURCE_NOTIFICATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_SOURCE:
+ self->source = PHOTOS_SOURCE (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_source_notification_init (PhotosSourceNotification *self)
+{
+}
+
+
+static void
+photos_source_notification_class_init (PhotosSourceNotificationClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructed = photos_source_notification_constructed;
+ object_class->dispose = photos_source_notification_dispose;
+ object_class->get_property = photos_source_notification_get_property;
+ object_class->set_property = photos_source_notification_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_SOURCE,
+ g_param_spec_object ("source",
+ "PhotosSource instance",
+ "The PhotosSource corresponding to this
notification",
+ PHOTOS_TYPE_SOURCE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+ signals[CLOSED] = g_signal_new ("closed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, /* accumulator */
+ NULL, /* accu_data */
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+}
+
+
+GtkWidget *
+photos_source_notification_new (PhotosSource *source)
+{
+ g_return_val_if_fail (PHOTOS_IS_SOURCE (source), NULL);
+ return g_object_new (PHOTOS_TYPE_SOURCE_NOTIFICATION, "source", source, NULL);
+}
+
+
+PhotosSource *
+photos_source_notification_get_source (PhotosSourceNotification *self)
+{
+ g_return_val_if_fail (PHOTOS_IS_SOURCE_NOTIFICATION (self), NULL);
+ return self->source;
+}
diff --git a/src/photos-source-notification.h b/src/photos-source-notification.h
new file mode 100644
index 0000000..03aaf2c
--- /dev/null
+++ b/src/photos-source-notification.h
@@ -0,0 +1,42 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ * Copyright © 2017 Umang Jain
+ *
+ * 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_SOURCE_NOTIFICATION_H
+#define PHOTOS_SOURCE_NOTIFICATION_H
+
+#include <gtk/gtk.h>
+
+#include "photos-source.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SOURCE_NOTIFICATION (photos_source_notification_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosSourceNotification, photos_source_notification, PHOTOS, SOURCE_NOTIFICATION,
GtkGrid);
+
+GtkWidget *photos_source_notification_new (PhotosSource *source);
+
+PhotosSource *photos_source_notification_get_source (PhotosSourceNotification *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SOURCE_NOTIFICATION_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]