static void photos_application_set_bg_download (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosApplication *self = PHOTOS_APPLICATION (user_data); PhotosApplicationPrivate *priv = self->priv; PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object); GError *error; gchar *filename = NULL; error = NULL; filename = photos_base_item_download_finish (item, res, &error); if (error != NULL) { const gchar *uri; uri = photos_base_item_get_uri (item); g_warning ("Unable to extract the local filename for %s", uri); g_error_free (error); goto out; } g_settings_set_string (priv->settings, "picture-uri", filename); g_settings_set_enum (priv->settings, "picture-options", G_DESKTOP_BACKGROUND_STYLE_ZOOM); g_settings_set_enum (priv->settings, "color-shading-type", G_DESKTOP_BACKGROUND_SHADING_SOLID); g_settings_set_string (priv->settings, "primary-color", "#000000000000"); g_settings_set_string (priv->settings, "secondary-color", "#000000000000"); out: g_free (filename); g_object_unref (self); }
static gboolean photos_application_dbus_register (GApplication *application, GDBusConnection *connection, const gchar *object_path, GError **error) { PhotosApplication *self = PHOTOS_APPLICATION (application); gboolean ret_val = FALSE; gchar *search_provider_path = NULL; if (!G_APPLICATION_CLASS (photos_application_parent_class)->dbus_register (application, connection, object_path, error)) goto out; search_provider_path = g_strconcat (object_path, PHOTOS_SEARCH_PROVIDER_PATH_SUFFIX, NULL); if (!photos_search_provider_dbus_export (self->priv->search_provider, connection, search_provider_path, error)) goto out; ret_val = TRUE; out: g_free (search_provider_path); return ret_val; }
static void photos_application_refresh_db (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosApplication *self = PHOTOS_APPLICATION (user_data); PhotosApplicationPrivate *priv = self->priv; GError *error; GomMiner *miner = GOM_MINER (source_object); PhotosApplicationRefreshData *data; priv->miners_running = g_list_remove (priv->miners_running, miner); error = NULL; if (!gom_miner_call_refresh_db_finish (miner, res, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Unable to update the cache: %s", error->message); g_error_free (error); goto out; } data = photos_application_refresh_data_new (self, miner); g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, MINER_REFRESH_TIMEOUT, photos_application_refresh_miner_timeout, data, (GDestroyNotify) photos_application_refresh_data_free); out: g_object_unref (self); g_object_unref (miner); }
static GdkPixbuf * photos_base_item_create_placeholder_icon (const gchar *icon_name) { GApplication *app; GdkPixbuf *centered_pixbuf = NULL; GdkPixbuf *pixbuf = NULL; GdkPixbuf *ret_val = NULL; GError *error; GIcon *icon = NULL; GList *windows; GtkIconInfo *info = NULL; GtkIconTheme *theme; GtkStyleContext *context; gint icon_size; gint scale; app = g_application_get_default (); windows = gtk_application_get_windows (GTK_APPLICATION (app)); if (windows == NULL) goto out; icon = g_themed_icon_new (icon_name); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); theme = gtk_icon_theme_get_default (); info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, 16, scale, GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_FORCE_SYMBOLIC); if (info == NULL) goto out; context = gtk_widget_get_style_context (GTK_WIDGET (windows->data)); error = NULL; pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, &error); if (error != NULL) { g_warning ("Unable to load icon '%s': %s", icon_name, error->message); g_error_free (error); goto out; } icon_size = photos_utils_get_icon_size (); centered_pixbuf = photos_utils_center_pixbuf (pixbuf, icon_size); photos_utils_border_pixbuf (centered_pixbuf); ret_val = centered_pixbuf; centered_pixbuf = NULL; out: g_clear_object (¢ered_pixbuf); g_clear_object (&pixbuf); g_clear_object (&info); g_clear_object (&icon); return ret_val; }
gint photos_utils_get_icon_size (void) { GApplication *app; gint scale; gint size; app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); size = photos_utils_get_icon_size_unscaled (); return scale * size; }
static void photos_application_dbus_unregister (GApplication *application, GDBusConnection *connection, const gchar *object_path) { PhotosApplication *self = PHOTOS_APPLICATION (application); gchar *search_provider_path = NULL; search_provider_path = g_strconcat (object_path, PHOTOS_SEARCH_PROVIDER_PATH_SUFFIX, NULL); photos_search_provider_dbus_unexport (self->priv->search_provider, connection, search_provider_path); G_APPLICATION_CLASS (photos_application_parent_class)->dbus_unregister (application, connection, object_path); g_free (search_provider_path); }
static void photos_application_activate (GApplication *application) { PhotosApplication *self = PHOTOS_APPLICATION (application); PhotosApplicationPrivate *priv = self->priv; if (priv->main_window == NULL) { photos_application_create_window (self); photos_mode_controller_set_window_mode (priv->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW); } gtk_window_present_with_time (GTK_WINDOW (priv->main_window), priv->activation_timestamp); priv->activation_timestamp = GDK_CURRENT_TIME; }
static void photos_base_item_refresh_thumb_path_pixbuf (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosBaseItem *self = PHOTOS_BASE_ITEM (user_data); PhotosBaseItemPrivate *priv = self->priv; GApplication *app; GdkPixbuf *pixbuf = NULL; GdkPixbuf *scaled_pixbuf = NULL; GError *error = NULL; GInputStream *stream = G_INPUT_STREAM (source_object); gint icon_size; gint scale; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (error != NULL) { GFile *file; gchar *uri; file = G_FILE (g_object_get_data (G_OBJECT (stream), "file")); uri = g_file_get_uri (file); g_warning ("Unable to create pixbuf from %s: %s", uri, error->message); priv->failed_thumbnailing = TRUE; priv->thumb_path = NULL; g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL); photos_base_item_set_failed_icon (self); g_free (uri); g_error_free (error); goto out; } app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); icon_size = photos_utils_get_icon_size_unscaled (); scaled_pixbuf = photos_utils_downscale_pixbuf_for_scale (pixbuf, icon_size, scale); photos_base_item_set_original_icon (self, scaled_pixbuf); out: g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_clear_object (&scaled_pixbuf); g_clear_object (&pixbuf); g_object_unref (self); }
static void photos_application_activate_query_executed (TrackerSparqlCursor *cursor, gpointer user_data) { PhotosApplication *self = PHOTOS_APPLICATION (user_data); PhotosApplicationPrivate *priv = self->priv; GObject *item; const gchar *identifier; if (cursor == NULL) goto out; photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor); identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL); item = photos_base_manager_get_object_by_id (priv->item_mngr, identifier); photos_application_activate_item (self, item); out: g_object_unref (self); }
static void photos_application_dispose (GObject *object) { PhotosApplication *self = PHOTOS_APPLICATION (object); PhotosApplicationPrivate *priv = self->priv; if (priv->resource != NULL) { g_resources_unregister (priv->resource); g_resource_unref (priv->resource); priv->resource = NULL; } g_clear_object (&priv->settings); g_clear_object (&priv->fs_action); g_clear_object (&priv->gear_action); g_clear_object (&priv->open_action); g_clear_object (&priv->print_action); g_clear_object (&priv->properties_action); g_clear_object (&priv->search_action); g_clear_object (&priv->sel_all_action); g_clear_object (&priv->sel_none_action); g_clear_object (&priv->set_bg_action); g_clear_object (&priv->facebook_miner); g_clear_object (&priv->flickr_miner); g_clear_object (&priv->item_mngr); g_clear_object (&priv->camera_cache); g_clear_object (&priv->mode_cntrlr); g_clear_object (&priv->search_provider); if (priv->state != NULL) { photos_search_context_state_free (priv->state); priv->state = NULL; } G_OBJECT_CLASS (photos_application_parent_class)->dispose (object); }
static void photos_tool_filter_button_constructed (GObject *object) { PhotosToolFilterButton *self = PHOTOS_TOOL_FILTER_BUTTON (object); GApplication *app; g_autoptr (GdkPixbuf) preview_icon = NULL; GtkWidget *image; PhotosWidgetShader *shader; cairo_surface_t *preview_icon_surface = NULL; /* TODO: use g_autoptr */ gint scale; G_OBJECT_CLASS (photos_tool_filter_button_parent_class)->constructed (object); app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); preview_icon = photos_utils_create_placeholder_icon_for_scale ("content-loading-symbolic", 96, scale); if (preview_icon != NULL) preview_icon_surface = gdk_cairo_surface_create_from_pixbuf (preview_icon, scale, NULL); image = gtk_image_new_from_surface (preview_icon_surface); gtk_container_add (GTK_CONTAINER (self->overlay), image); shader = photos_widget_shader_new (image); gtk_widget_show (image); self->button = gtk_radio_button_new_with_label_from_widget (self->group, self->label); gtk_button_set_always_show_image (GTK_BUTTON (self->button), TRUE); gtk_button_set_image (GTK_BUTTON (self->button), self->overlay); gtk_button_set_image_position (GTK_BUTTON (self->button), GTK_POS_TOP); gtk_button_set_relief (GTK_BUTTON (self->button), GTK_RELIEF_NONE); gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (self->button), FALSE); gtk_container_add (GTK_CONTAINER (self), self->button); g_object_bind_property (self->button, "active", shader, "active", G_BINDING_SYNC_CREATE); g_signal_connect_swapped (self->button, "toggled", G_CALLBACK (photos_tool_filter_button_toggled), self); photos_tool_filter_button_toggled (self); g_clear_pointer (&preview_icon_surface, (GDestroyNotify) cairo_surface_destroy); self->group = NULL; /* We will not need it any more */ }
static void photos_base_item_check_effects_and_update_info (PhotosBaseItem *self) { PhotosBaseItemPrivate *priv = self->priv; GApplication *app; GIcon *pix; GList *emblem_icons = NULL; GList *windows; GdkPixbuf *emblemed_pixbuf = NULL; GdkPixbuf *thumbnailed_pixbuf = NULL; GdkWindow *window; gint scale; if (priv->original_icon == NULL) goto out; emblemed_pixbuf = g_object_ref (priv->original_icon); if (priv->favorite) { pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE); emblem_icons = g_list_prepend (emblem_icons, pix); } if (g_list_length (emblem_icons) > 0) { GIcon *emblemed_icon; GList *l; GtkIconInfo *icon_info; GtkIconTheme *theme; gint height; gint size; gint width; emblem_icons = g_list_reverse (emblem_icons); emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL); for (l = emblem_icons; l != NULL; l = g_list_next (l)) { GEmblem *emblem; GIcon *emblem_icon = G_ICON (l->data); emblem = g_emblem_new (emblem_icon); g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem); g_object_unref (emblem); } theme = gtk_icon_theme_get_default (); width = gdk_pixbuf_get_width (priv->original_icon); height = gdk_pixbuf_get_height (priv->original_icon); size = (width > height) ? width : height; icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE); if (icon_info != NULL) { GError *error = NULL; GdkPixbuf *tmp; tmp = gtk_icon_info_load_icon (icon_info, &error); if (error != NULL) { g_warning ("Unable to render the emblem: %s", error->message); g_error_free (error); } else { g_object_unref (emblemed_pixbuf); emblemed_pixbuf = tmp; } g_object_unref (icon_info); } g_object_unref (emblemed_icon); } g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy); if (priv->thumb_path != NULL) { GtkBorder *slice; slice = photos_utils_get_thumbnail_frame_border (); thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf, "resource:///org/gnome/photos/thumbnail-frame.png", slice, slice); gtk_border_free (slice); } else thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf); app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); windows = gtk_application_get_windows (GTK_APPLICATION (app)); window = gtk_widget_get_window (GTK_WIDGET (windows->data)); priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window); g_signal_emit (self, signals[INFO_UPDATED], 0); out: g_clear_object (&thumbnailed_pixbuf); g_clear_object (&emblemed_pixbuf); g_list_free_full (emblem_icons, g_object_unref); }
static void photos_application_startup (GApplication *application) { PhotosApplication *self = PHOTOS_APPLICATION (application); PhotosApplicationPrivate *priv = self->priv; GError *error; GSimpleAction *action; GrlRegistry *registry; GtkSettings *settings; GVariant *state; G_APPLICATION_CLASS (photos_application_parent_class) ->startup (application); gegl_init (NULL, NULL); grl_init (NULL, NULL); registry = grl_registry_get_default (); error = NULL; if (!grl_registry_load_plugin_by_id (registry, "grl-flickr", &error)) { g_warning ("Unable to load Grilo's Flickr plugin: %s", error->message); g_error_free (error); } priv->settings = g_settings_new ("org.gnome.desktop.background"); priv->resource = photos_get_resource (); g_resources_register (priv->resource); settings = gtk_settings_get_default (); g_object_set (settings, "gtk-application-prefer-dark-theme", TRUE, NULL); priv->facebook_miner = gom_miner_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, "org.gnome.OnlineMiners.Facebook", "/org/gnome/OnlineMiners/Facebook", NULL, NULL); priv->flickr_miner = gom_miner_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, "org.gnome.OnlineMiners.Flickr", "/org/gnome/OnlineMiners/Flickr", NULL, NULL); priv->item_mngr = photos_item_manager_dup_singleton (); /* A dummy reference to keep it alive during the lifetime of the * application. */ priv->camera_cache = photos_camera_cache_dup_singleton (); priv->mode_cntrlr = photos_mode_controller_dup_singleton (); action = g_simple_action_new ("about", NULL); g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_application_about), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action)); g_object_unref (action); priv->fs_action = g_simple_action_new ("fullscreen", NULL); g_signal_connect_swapped (priv->fs_action, "activate", G_CALLBACK (photos_application_fullscreen), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->fs_action)); g_signal_connect_swapped (priv->mode_cntrlr, "can-fullscreen-changed", G_CALLBACK (photos_application_can_fullscreen_changed), self); state = g_variant_new ("b", FALSE); priv->gear_action = g_simple_action_new_stateful ("gear-menu", NULL, state); g_signal_connect (priv->gear_action, "activate", G_CALLBACK (photos_application_action_toggle), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->gear_action)); priv->open_action = g_simple_action_new ("open-current", NULL); g_signal_connect_swapped (priv->open_action, "activate", G_CALLBACK (photos_application_open_current), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->open_action)); priv->print_action = g_simple_action_new ("print-current", NULL); g_signal_connect_swapped (priv->print_action, "activate", G_CALLBACK (photos_application_print_current), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->print_action)); priv->properties_action = g_simple_action_new ("properties", NULL); g_signal_connect_swapped (priv->properties_action, "activate", G_CALLBACK (photos_application_properties), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->properties_action)); priv->remote_display_action = g_simple_action_new ("remote-display-current", NULL); g_signal_connect_swapped (priv->remote_display_action, "activate", G_CALLBACK (photos_application_remote_display_current), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->remote_display_action)); action = g_simple_action_new ("quit", NULL); g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_application_quit), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action)); g_object_unref (action); state = g_variant_new ("b", FALSE); priv->search_action = g_simple_action_new_stateful ("search", NULL, state); g_signal_connect (priv->search_action, "activate", G_CALLBACK (photos_application_action_toggle), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->search_action)); priv->sel_all_action = g_simple_action_new ("select-all", NULL); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_all_action)); priv->sel_none_action = g_simple_action_new ("select-none", NULL); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_none_action)); priv->set_bg_action = g_simple_action_new ("set-background", NULL); g_signal_connect_swapped (priv->set_bg_action, "activate", G_CALLBACK (photos_application_set_bg), self); g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->set_bg_action)); g_signal_connect_swapped (priv->mode_cntrlr, "window-mode-changed", G_CALLBACK (photos_application_window_mode_changed), self); photos_application_init_app_menu (self); gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>q", "app.quit", NULL); gtk_application_add_accelerator (GTK_APPLICATION (self), "F11", "app.fullscreen", NULL); gtk_application_add_accelerator (GTK_APPLICATION (self), "F10", "app.gear-menu", NULL); gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>p", "app.print-current", NULL); gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>f", "app.search", NULL); gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>a", "app.select-all", NULL); }
static PhotosSearchContextState * photos_application_get_state (PhotosSearchContext *context) { PhotosApplication *self = PHOTOS_APPLICATION (context); return self->priv->state; }