[gnome-photos/wip/rishi/collection: 8/8] source-notification: Support GMount-backed sources for importing



commit 2028857d14cb3f766953daf1facf2d3bc4a6770c
Author: Petr Štětka <stetka peta gmail com>
Date:   Sun Sep 3 01:58:17 2017 +0200

    source-notification: Support GMount-backed sources for importing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751212

 src/photos-source-notification.c |  101 ++++++++++++++++++++++++++++----------
 1 files changed, 75 insertions(+), 26 deletions(-)
---
diff --git a/src/photos-source-notification.c b/src/photos-source-notification.c
index 5637651..ad86bb8 100644
--- a/src/photos-source-notification.c
+++ b/src/photos-source-notification.c
@@ -119,34 +119,77 @@ static void
 photos_source_notification_constructed (GObject *object)
 {
   PhotosSourceNotification *self = PHOTOS_SOURCE_NOTIFICATION (object);
+  GMount *mount;
+  GoaObject *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);
-  /* Translators: %s refers to an online account provider, e.g.,
-   * "Facebook" or "Flickr".
-   */
-  msg = g_strdup_printf (_("Your %s credentials 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);
+  mount = photos_source_get_mount (source);
+  object = photos_source_get_goa_object (source);
 
-  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);
+  if (mount != NULL)
+    {
+      GtkStyleContext *context;
+      GtkWidget *import;
+      GtkWidget *labels;
+      GtkWidget *primary_label;
+      GtkWidget *secondary_label;
+      gchar *name;
+
+      labels = gtk_grid_new ();
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (labels), GTK_ORIENTATION_VERTICAL);
+      gtk_grid_set_row_spacing (GTK_GRID (labels), 3);
+      gtk_container_add (GTK_CONTAINER (self), labels);
+
+      primary_label = gtk_label_new (_("New device discovered"));
+      gtk_widget_set_halign (primary_label, GTK_ALIGN_START);
+      gtk_widget_set_hexpand (primary_label, TRUE);
+      gtk_container_add (GTK_CONTAINER (labels), primary_label);
+
+      name = g_mount_get_name (self->mount);
+      secondary_label = gtk_label_new (name);
+      gtk_widget_set_halign (secondary_label, GTK_ALIGN_START);
+      gtk_widget_set_hexpand (secondary_label, TRUE);
+      context = gtk_widget_get_style_context (secondary_label);
+      gtk_style_context_add_class (context, "dim-label");
+      gtk_container_add (GTK_CONTAINER (labels), secondary_label);
+      g_free (name);
+
+      import = gtk_button_new_with_label (_("Import"));
+      gtk_widget_set_valign (import, GTK_ALIGN_CENTER);
+      gtk_actionable_set_action_name (GTK_ACTIONABLE (import), "app.import");
+      gtk_container_add (GTK_CONTAINER (self), import);
+      g_signal_connect_swapped (import, "clicked", G_CALLBACK (photos_source_notification_settings_clicked), 
self);
+    }
+  else if (object != NULL)
+    {
+      GtkWidget *label;
+      GtkWidget *settings;
+      const gchar *name;
+      gchar *msg;
+
+      name = photos_source_get_name (self->source);
+      /* Translators: %s refers to an online account provider, e.g.,
+       * "Facebook" or "Flickr".
+       */
+      msg = g_strdup_printf (_("Your %s credentials 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);
@@ -249,20 +292,26 @@ photos_source_notification_class_init (PhotosSourceNotificationClass *class)
 GtkWidget *
 photos_source_notification_new (PhotosSource *source)
 {
-  GoaAccount *account;
+  GMount *mount;
   GoaObject *object;
-  gboolean attention_needed;
 
   g_return_val_if_fail (PHOTOS_IS_SOURCE (source), NULL);
 
+  mount = photos_source_get_mount (source);
   object = photos_source_get_goa_object (source);
-  g_return_val_if_fail (GOA_IS_OBJECT (object), NULL);
+  g_return_val_if_fail (G_IS_MOUNT (mount) || GOA_IS_OBJECT (object), NULL);
 
-  account = goa_object_peek_account (object);
-  g_return_val_if_fail (GOA_IS_ACCOUNT (account), NULL);
+  if (object != NULL)
+    {
+      GoaAccount *account;
+      gboolean attention_needed;
+
+      account = goa_object_peek_account (object);
+      g_return_val_if_fail (GOA_IS_ACCOUNT (account), NULL);
 
-  attention_needed = goa_account_get_attention_needed (account);
-  g_return_val_if_fail (attention_needed, NULL);
+      attention_needed = goa_account_get_attention_needed (account);
+      g_return_val_if_fail (attention_needed, NULL);
+    }
 
   return g_object_new (PHOTOS_TYPE_SOURCE_NOTIFICATION, "source", source, NULL);
 }


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