void _g_launch_command (GtkWidget *parent, const char *command, const char *name, GList *files) { GError *error = NULL; GAppInfo *app_info; GdkAppLaunchContext *launch_context; app_info = g_app_info_create_from_commandline (command, name, G_APP_INFO_CREATE_SUPPORTS_URIS, &error); if (app_info == NULL) { _gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error); return; } launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, gtk_widget_get_screen (parent)); if (! g_app_info_launch (app_info, files, G_APP_LAUNCH_CONTEXT (launch_context), &error)) { _gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error); return; } g_object_unref (app_info); }
static void list_ready_cb (GList *files, GError *error, gpointer user_data) { DialogData *data = user_data; data->loading_list = FALSE; if (data->cancelling) { gth_file_list_cancel (GTH_FILE_LIST (data->file_list), cancel_done, data); } else if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not load the folder"), error); } else { _g_object_unref (data->last_source); data->last_source = g_file_dup (data->source); data->files = _g_object_list_ref (files); gth_file_list_set_files (GTH_FILE_LIST (data->file_list), data->files); } update_sensitivity (data); }
static void ok_clicked_cb (GtkWidget *widget, DialogData *data) { GList *file_list; GFile *destination; GError *error = NULL; gboolean import; file_list = get_selected_file_list (data); destination = gth_import_preferences_get_destination (); if (! gth_import_task_check_free_space (destination, file_list, &error)) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not import the files"), error); g_clear_error (&error); import = FALSE; } else import = TRUE; _g_object_unref (destination); _g_object_list_unref (file_list); if (! import) return; data->import = TRUE; close_dialog (NULL, data); }
static void loader_completed_cb (GthTask *task, GError *error, gpointer user_data) { LoaderData *loader_data = user_data; DialogData *data = loader_data->data; if (error != NULL) { if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Cannot read file information"), error); loader_data_free (loader_data); if (data->never_shown) close_dialog (data); return; } _g_object_list_unref (data->file_list); data->file_list = _g_object_list_ref (gth_load_file_data_task_get_result (GTH_LOAD_FILE_DATA_TASK (task))); gth_edit_metadata_dialog_set_file_list (GTH_EDIT_METADATA_DIALOG (data->dialog), data->file_list); gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (data->browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_window_present (GTK_WINDOW (data->dialog)); data->never_shown = FALSE; loader_data_free (loader_data); }
static void catalog_save_done_cb (void **buffer, gsize count, GError *error, gpointer user_data) { AddData *add_data = user_data; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (add_data->parent_window), _("Could not add the files to the catalog"), &error); return; } gth_monitor_folder_changed (gth_main_get_default_monitor (), add_data->catalog_file, add_data->files, GTH_MONITOR_EVENT_CREATED); if (add_data->view_destination) gth_browser_go_to (add_data->browser, add_data->catalog_file, NULL); if (add_data->dialog != NULL) gtk_widget_destroy (add_data->dialog); add_data_free (add_data); }
static void remove_catalog (GtkWindow *window, GthFileData *file_data) { GFile *gio_file; GError *error = NULL; gio_file = gth_main_get_gio_file (file_data->file); if (g_file_delete (gio_file, NULL, &error)) { GFile *parent; GList *files; parent = g_file_get_parent (file_data->file); files = g_list_prepend (NULL, g_object_ref (file_data->file)); gth_monitor_folder_changed (gth_main_get_default_monitor (), parent, files, GTH_MONITOR_EVENT_DELETED); _g_object_list_unref (files); _g_object_unref (parent); } else { _gtk_error_dialog_from_gerror_show (window, _("Could not remove the catalog"), error); g_clear_error (&error); } g_object_unref (gio_file); }
static void saver_completed_cb (GthTask *task, GError *error, gpointer user_data) { DialogData *data = user_data; GthMonitor *monitor; GList *scan; monitor = gth_main_get_default_monitor (); for (scan = data->parents; scan; scan = scan->next) gth_monitor_resume (monitor, (GFile *) scan->data); if (error != NULL) { if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not save the file metadata"), error); } else { for (scan = data->file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; GList *files; files = g_list_prepend (NULL, g_object_ref (file_data->file)); gth_monitor_metadata_changed (monitor, file_data); _g_object_list_unref (files); } } if (data->close_dialog) close_dialog (data); dialog_data_unref (data); }
static void catalog_saved_cb (void **buffer, gsize count, GError *error, gpointer user_data) { DialogData *data = user_data; if (error == NULL) { if (! g_file_equal (data->original_file, data->file_data->file)) { GFile *gio_file; gio_file = gth_catalog_file_to_gio_file (data->original_file); g_file_delete (gio_file, NULL, NULL); g_object_unref (gio_file); gth_monitor_file_renamed (gth_main_get_default_monitor (), data->original_file, data->file_data->file); } gth_catalog_update_metadata (data->catalog, data->file_data); gth_monitor_metadata_changed (gth_main_get_default_monitor (), data->file_data); gth_hook_invoke ("dlg-catalog-properties-saved", data->browser, data->file_data, data->catalog); } else _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not save the catalog"), error); gtk_widget_destroy (data->dialog); }
static void catalog_ready_cb (GObject *catalog, GError *error, gpointer user_data) { AddData *add_data = user_data; GList *scan; char *buffer; gsize length; GFile *gio_file; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (add_data->parent_window), _("Could not add the files to the catalog"), &error); return; } add_data->catalog = (GthCatalog *) catalog; for (scan = add_data->files; scan; scan = scan->next) gth_catalog_insert_file (add_data->catalog, (GFile *) scan->data, -1); buffer = gth_catalog_to_data (add_data->catalog, &length); gio_file = gth_catalog_file_to_gio_file (add_data->catalog_file); g_write_file_async (gio_file, buffer, length, TRUE, G_PRIORITY_DEFAULT, NULL, catalog_save_done_cb, add_data); g_object_unref (gio_file); }
static void list_albums_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); GError *error = NULL; _g_object_list_unref (data->albums); data->albums = picasa_web_service_list_albums_finish (picasaweb, result, &error); if (error != NULL) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the album list"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } update_album_list (data); gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (data->browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_window_present (GTK_WINDOW (data->dialog)); }
static void image_buffer_ready_cb (void **buffer, gsize count, GError *error, gpointer user_data) { PicasaAccountPropertiesDialog *self = user_data; GInputStream *stream; GdkPixbuf *pixbuf; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (self), _("Could not load the file"), &error); return; } stream = g_memory_input_stream_new_from_data (*buffer, count, NULL); pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL); if (pixbuf != NULL) { gtk_widget_show (GET_WIDGET ("challange_box")); gtk_image_set_from_pixbuf (GTK_IMAGE (GET_WIDGET ("challenge_image")), pixbuf); g_object_unref (pixbuf); } g_object_unref (stream); }
static void save_screenshot_task_completed_cb (GthTask *task, GError *error, gpointer user_data) { SaveData *save_data = user_data; GthMediaViewerPage *page = save_data->page; if (error != NULL) _gtk_error_dialog_from_gerror_show (GTK_WINDOW (save_data->browser), _("Could not save the file"), error); else if (save_data->playing_before_screenshot) gst_element_set_state (gth_media_viewer_page_get_playbin (page), GST_STATE_PLAYING); save_date_free (save_data); g_object_unref (task); }
static void connection_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GoogleConnection *conn = GOOGLE_CONNECTION (source_object); GError *error = NULL; if (! google_connection_connect_finish (conn, result, &error)) { if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_CAPTCHA_REQUIRED)) { challange_account_dialog (data); } else if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_BAD_AUTHENTICATION)) { account_properties_dialog (data, data->email); } else { if (data->conn != NULL) gth_task_dialog (GTH_TASK (data->conn), TRUE); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not connect to the server"), &error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); } return; } if (! g_list_find_custom (data->accounts, data->email, (GCompareFunc) strcmp)) data->accounts = g_list_append (data->accounts, g_strdup (data->email)); #ifdef HAVE_GNOME_KEYRING if (gnome_keyring_is_available ()) { gnome_keyring_store_password (GNOME_KEYRING_NETWORK_PASSWORD, NULL, _("Picasa Web Album"), data->password, store_password_done_cb, data, NULL, "user", data->email, "server", "picasaweb.google.com", "protocol", "http", NULL); return; } #endif get_album_list (data); }
static void add_photos_to_photoset_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; if (! flickr_service_add_photos_to_set_finish (FLICKR_SERVICE (source_object), result, &error)) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not create the album"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } export_completed_with_success (data); }
static void post_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); GError *error = NULL; if (! picasa_web_service_post_photos_finish (picasaweb, result, &error)) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not upload the files"), error); g_clear_error (&error); return; } export_completed_with_success (data); }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = flickr_service_list_photos_finish (data->service, result, &error); if (error != NULL) { if (data->service != NULL) gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { FlickrPhoto *photo = scan->data; GthFileData *file_data; if (photo->url[FLICKR_URL_O] == NULL) continue; file_data = gth_file_data_new_for_uri (photo->url[FLICKR_URL_O], (photo->mime_type != NULL) ? photo->mime_type : "image/jpeg"); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, FAKE_SIZE); /* set a fake size to make the progress dialog work correctly */ g_file_info_set_attribute_object (file_data->info, "flickr::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_widget_set_sensitive (GET_WIDGET ("download_button"), list != NULL); _g_object_list_unref (list); }
static void activate_open_with_application_item (GtkMenuItem *menuitem, gpointer data) { GthBrowser *browser = data; GList *items; GList *file_list; GList *uris; GList *scan; GAppInfo *appinfo; GdkAppLaunchContext *context; GError *error = NULL; items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser))); file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items); uris = NULL; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; uris = g_list_prepend (uris, g_file_get_uri (file_data->file)); } uris = g_list_reverse (uris); appinfo = g_object_get_data (G_OBJECT (menuitem), "appinfo"); g_return_if_fail (G_IS_APP_INFO (appinfo)); context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (browser))); gdk_app_launch_context_set_timestamp (context, 0); gdk_app_launch_context_set_icon (context, g_app_info_get_icon (appinfo)); if (! g_app_info_launch_uris (appinfo, uris, G_APP_LAUNCH_CONTEXT (context), &error)) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not perform the operation"), error); g_clear_error (&error); } g_object_unref (context); g_list_free (uris); _g_object_list_unref (file_list); _gtk_tree_path_list_free (items); }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = facebook_service_list_photos_finish (data->service, result, &error); if (error != NULL) { if (data->service != NULL) gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { FacebookPhoto *photo = scan->data; GthFileData *file_data; file_data = gth_file_data_new_for_uri (facebook_photo_get_original_url (photo), "image/jpeg"); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, FAKE_SIZE); /* set a fake size to make the progress dialog work correctly */ g_file_info_set_attribute_object (file_data->info, "facebook::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, list != NULL); _g_object_list_unref (list); }
static void create_album_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); PicasaWebAlbum *album; GError *error = NULL; album = picasa_web_service_create_album_finish (picasaweb, result, &error); if (error != NULL) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not create the album"), error); g_clear_error (&error); return; } data->albums = g_list_append (data->albums, album); update_album_list (data); }
static void list_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); GError *error = NULL; GList *list; GList *scan; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _g_object_list_unref (data->photos); data->photos = picasa_web_service_list_albums_finish (picasaweb, result, &error); if (error != NULL) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the photo list"), error); g_clear_error (&error); gtk_widget_destroy (data->dialog); return; } list = NULL; for (scan = data->photos; scan; scan = scan->next) { PicasaWebPhoto *photo = scan->data; GthFileData *file_data; file_data = gth_file_data_new_for_uri (photo->uri, photo->mime_type); g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR); g_file_info_set_size (file_data->info, photo->size); g_file_info_set_attribute_object (file_data->info, "gphoto::object", G_OBJECT (photo)); list = g_list_prepend (list, file_data); } gth_file_list_set_files (GTH_FILE_LIST (data->file_list), list); update_selection_status (data); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, TRUE); _g_object_list_unref (list); }
static void catalog_ready_cb (GObject *object, GError *error, gpointer user_data) { DialogData *data = user_data; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW(data->browser), _("Could not load the catalog"), error); gtk_widget_destroy (data->dialog); return; } data->catalog = g_object_ref (object); if (gth_catalog_get_name (data->catalog) != NULL) { gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), gth_catalog_get_name (data->catalog)); } else if (! gth_datetime_valid_date (gth_catalog_get_date (data->catalog))) { char *basename; char *name; char *utf8_name; basename = g_file_get_basename (data->file_data->file); name = _g_uri_remove_extension (basename); utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), utf8_name); g_free (utf8_name); g_free (name); g_free (basename); } gth_time_selector_set_value (GTH_TIME_SELECTOR (data->time_selector), gth_catalog_get_date (data->catalog)); gth_hook_invoke ("dlg-catalog-properties", data->builder, data->file_data, data->catalog); gtk_widget_show (data->dialog); g_object_unref (object); }
static void list_albums_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; PicasaWebService *picasaweb = PICASA_WEB_SERVICE (source_object); GError *error = NULL; _g_object_list_unref (data->albums); data->albums = picasa_web_service_list_albums_finish (picasaweb, result, &error); if (error != NULL) { if (data->conn != NULL) gth_task_dialog (GTH_TASK (data->conn), TRUE); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not get the album list"), &error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } _g_object_unref (data->user); data->user = g_object_ref (picasa_web_service_get_user (picasaweb)); show_export_dialog (data); }
static void post_photos_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; data->photos_ids = flickr_service_post_photos_finish (FLICKR_SERVICE (source_object), result, &error); if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not upload the files"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } if (data->photoset == NULL) { export_completed_with_success (data); return; } /* create the photoset if it doesn't exists */ if (data->photoset->id == NULL) { char *first_id; first_id = data->photos_ids->data; flickr_photoset_set_primary (data->photoset, first_id); flickr_service_create_photoset (data->service, data->photoset, data->cancellable, create_photoset_ready_cb, data); } else add_photos_to_photoset (data); }
static void create_photoset_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { DialogData *data = user_data; GError *error = NULL; char *primary; primary = g_strdup (data->photoset->primary); g_object_unref (data->photoset); data->photoset = flickr_service_create_photoset_finish (FLICKR_SERVICE (source_object), result, &error); if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not create the album"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); } else { flickr_photoset_set_primary (data->photoset, primary); add_photos_to_photoset (data); } g_free (primary); }
static void search_query_ready_cb (void *buffer, gsize count, GError *error, gpointer user_data) { DialogData *data = user_data; if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { search_completed (data); return; } if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not search for a cover on Internet"), &error); search_completed (data); return; } data->file_list = make_file_list_from_search_result (buffer, count, MAX_IMAGES); start_loading_files (data); }
void dlg_export_to_picasaweb (GthBrowser *browser, GList *file_list) { DialogData *data; GtkTreeSelection *selection; GList *scan; int n_total; goffset total_size; char *total_size_formatted; char *text; data = g_new0 (DialogData, 1); data->browser = browser; data->settings = g_settings_new (GTHUMB_PICASAWEB_SCHEMA); data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb"); data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog"); data->cancellable = g_cancellable_new (); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("name_treeviewcolumn")); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", ALBUM_NAME_COLUMN, NULL); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_EMBLEM_COLUMN, NULL); } _gtk_window_resize_to_fit_screen_height (data->dialog, 500); data->file_list = NULL; n_total = 0; total_size = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if (g_content_type_equals (mime_type, "image/bmp") || g_content_type_equals (mime_type, "image/gif") || g_content_type_equals (mime_type, "image/jpeg") || g_content_type_equals (mime_type, "image/png")) { total_size += g_file_info_get_size (file_data->info); n_total++; data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data)); } } data->file_list = g_list_reverse (data->file_list); if (data->file_list == NULL) { GError *error; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected.")); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error); g_clear_error (&error); destroy_dialog (data); return; } total_size_formatted = g_format_size (total_size); text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text); g_free (text); g_free (total_size_formatted); /* Set the widget data */ data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE); gtk_widget_show (data->list_view); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0); gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING); gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH) != -1); _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT)); /* Set the signals handlers. */ g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (export_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("add_album_button"), "clicked", G_CALLBACK (add_album_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("resize_checkbutton"), "toggled", G_CALLBACK (resize_checkbutton_toggled_cb), data); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview"))); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (selection, "changed", G_CALLBACK (albums_treeview_selection_changed_cb), data); update_sensitivity (data); data->service = picasa_web_service_new (data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (service_account_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (service_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service)); web_service_autoconnect (WEB_SERVICE (data->service)); }
static void screenshot_ready_cb (GdkPixbuf *pixbuf, gpointer user_data) { SaveData *save_data = user_data; GtkWidget *file_sel; if (pixbuf == NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (save_data->browser), _("Could not take a screenshot"), NULL); save_date_free (save_data); return; } save_data->image = gth_image_new_for_pixbuf (pixbuf); file_sel = gth_file_chooser_dialog_new (_("Save Image"), GTK_WINDOW (save_data->browser), "image-saver"); gtk_window_set_modal (GTK_WINDOW (file_sel), TRUE); { char *last_uri; GFile *last_folder; GthFileData *file_data; char *prefix; char *display_name; int attempt; last_uri = g_settings_get_string (save_data->settings, PREF_GSTREAMER_TOOLS_SCREESHOT_LOCATION); if ((last_uri == NULL) || (strcmp (last_uri, "~") == 0) || (strcmp (last_uri, "file://~") == 0)) { const char *dir; dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES); if (dir != NULL) last_folder = g_file_new_for_path (dir); else last_folder = g_file_new_for_uri (get_home_uri ()); } else last_folder = g_file_new_for_uri (last_uri); gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (file_sel), last_folder, NULL); file_data = gth_media_viewer_page_get_file_data (save_data->page); prefix = _g_utf8_remove_extension (g_file_info_get_display_name (file_data->info)); if (prefix == NULL) prefix = g_strdup (C_("Filename", "Screenshot")); display_name = NULL; for (attempt = 1; attempt < MAX_ATTEMPTS; attempt++) { GFile *proposed_file; g_free (display_name); display_name = g_strdup_printf ("%s-%02d.jpeg", prefix, attempt); proposed_file = g_file_get_child_for_display_name (last_folder, display_name, NULL); if ((proposed_file != NULL) && ! g_file_query_exists (proposed_file, NULL)) { g_object_unref (proposed_file); break; } } if (display_name != NULL) { gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_sel), display_name); g_free (display_name); } g_free (prefix); g_object_unref (last_folder); g_free (last_uri); } g_signal_connect (GTK_DIALOG (file_sel), "response", G_CALLBACK (save_as_response_cb), save_data); gtk_widget_show (file_sel); }
void dlg_export_to_flickr (FlickrServer *server, GthBrowser *browser, GList *file_list) { DialogData *data; GList *scan; int n_total; goffset total_size; char *total_size_formatted; char *text; char *title; data = g_new0 (DialogData, 1); data->server = server; data->browser = browser; data->settings = g_settings_new (GTHUMB_FLICKR_SCHEMA); data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("export-to-flickr.ui", "flicker_utils"); data->cancellable = g_cancellable_new (); data->dialog = g_object_new (GTK_TYPE_DIALOG, "transient-for", GTK_WINDOW (browser), "modal", FALSE, "destroy-with-parent", FALSE, "use-header-bar", _gtk_settings_get_dialogs_use_header (), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), _gtk_builder_get_widget (data->builder, "dialog_content")); gtk_dialog_add_buttons (GTK_DIALOG (data->dialog), _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL, _GTK_LABEL_UPLOAD, GTK_RESPONSE_OK, NULL); _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; data->photoset_combobox = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL (GET_WIDGET ("photoset_liststore"))); gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (data->photoset_combobox), PHOTOSET_TITLE_COLUMN); gtk_widget_show (data->photoset_combobox); gtk_container_add (GTK_CONTAINER (GET_WIDGET ("photoset_combobox_container")), data->photoset_combobox); cell_layout = GTK_CELL_LAYOUT (data->photoset_combobox); gtk_cell_layout_clear (cell_layout); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", PHOTOSET_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_TITLE_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_N_PHOTOS_COLUMN, NULL); } data->file_list = NULL; n_total = 0; total_size = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if (g_content_type_equals (mime_type, "image/bmp") || g_content_type_equals (mime_type, "image/gif") || g_content_type_equals (mime_type, "image/jpeg") || g_content_type_equals (mime_type, "image/png")) { total_size += g_file_info_get_size (file_data->info); n_total++; data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data)); } } data->file_list = g_list_reverse (data->file_list); if (data->file_list == NULL) { GError *error; error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected.")); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } total_size_formatted = g_format_size (total_size); text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text); g_free (text); g_free (total_size_formatted); _gtk_window_resize_to_fit_screen_height (data->dialog, 500); /* Set the widget data */ data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE); gtk_widget_show (data->list_view); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0); gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list); gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (data->photoset_combobox))), g_file_info_get_edit_name (data->location->info)); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, FALSE); title = g_strdup_printf (_("Export to %s"), data->server->name); gtk_window_set_title (GTK_WINDOW (data->dialog), title); g_free (title); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH) != -1); _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_HEIGHT)); /* Set the signals handlers. */ g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (export_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("resize_checkbutton"), "toggled", G_CALLBACK (resize_checkbutton_toggled_cb), data); update_sensitivity (data); data->service = flickr_service_new (server, data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (authentication_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (authentication_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service), GTH_TASK_FLAGS_DEFAULT); web_service_autoconnect (WEB_SERVICE (data->service)); }
static void new_catalog_button_clicked_cb (GtkWidget *widget, DialogData *data) { char *name; GthFileData *selected_parent; GFile *parent; GthFileSource *file_source; GFile *gio_parent; GError *error; GFile *gio_file; name = _gtk_request_dialog_run (GTK_WINDOW (data->dialog), GTK_DIALOG_MODAL, _("Enter the catalog name: "), "", 1024, GTK_STOCK_CANCEL, _("C_reate")); if (name == NULL) return; selected_parent = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (data->source_tree)); if (selected_parent != NULL) { GthFileSource *file_source; GFileInfo *info; file_source = gth_main_get_file_source (selected_parent->file); info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES); if (g_file_info_get_attribute_boolean (info, "gthumb::no-child")) parent = g_file_get_parent (selected_parent->file); else parent = g_file_dup (selected_parent->file); g_object_unref (info); g_object_unref (file_source); } else parent = g_file_new_for_uri ("catalog:///"); file_source = gth_main_get_file_source (parent); gio_parent = gth_file_source_to_gio_file (file_source, parent); gio_file = _g_file_create_unique (gio_parent, name, ".catalog", &error); if (gio_file != NULL) { GFile *file; GList *list; file = gth_catalog_file_from_gio_file (gio_file, NULL); list = g_list_prepend (NULL, file); gth_monitor_folder_changed (gth_main_get_default_monitor (), parent, list, GTH_MONITOR_EVENT_CREATED); g_list_free (list); g_object_unref (file); } else _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not create the catalog"), &error); g_object_unref (gio_file); g_object_unref (gio_parent); g_object_unref (file_source); }
static void new_library_button_clicked_cb (GtkWidget *widget, DialogData *data) { char *name; GthFileData *selected_parent; GFile *parent; GthFileSource *file_source; GFile *gio_parent; GError *error = NULL; GFile *gio_file; name = _gtk_request_dialog_run (GTK_WINDOW (data->dialog), GTK_DIALOG_MODAL, _("Enter the library name: "), "", 1024, GTK_STOCK_CANCEL, _("C_reate")); if (name == NULL) return; selected_parent = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (data->source_tree)); if (selected_parent != NULL) { GthFileSource *file_source; GFileInfo *info; file_source = gth_main_get_file_source (selected_parent->file); info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES); if (g_file_info_get_attribute_boolean (info, "gthumb::no-child")) parent = g_file_get_parent (selected_parent->file); else parent = g_file_dup (selected_parent->file); g_object_unref (info); g_object_unref (file_source); } else parent = g_file_new_for_uri ("catalog:///"); file_source = gth_main_get_file_source (parent); gio_parent = gth_file_source_to_gio_file (file_source, parent); gio_file = _g_directory_create_unique (gio_parent, name, "", &error); if (gio_file != NULL) { GFile *file; GList *list; file = gth_catalog_file_from_gio_file (gio_file, NULL); list = g_list_prepend (NULL, file); gth_monitor_folder_changed (gth_main_get_default_monitor (), parent, list, GTH_MONITOR_EVENT_CREATED); g_list_free (list); g_object_unref (file); } else _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not create the library"), &error); g_object_unref (gio_file); g_object_unref (gio_parent); g_object_unref (file_source); /* selected_catalog = gth_folder_tree_get_selected (GTH_FOLDER_TREE (data->source_tree)); parent = get_catalog_parent (selected_catalog->file); new_library = g_file_get_child_for_display_name (parent, name, &error); if ((new_library != NULL) && (strchr (display_name, '/') != NULL)) { error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, _("The name \"%s\" is not valid because it contains the character \"/\". " "Please use a different name."), display_name); g_object_unref (new_library); new_library = NULL; } if (error == NULL) { GFile *gio_file; gio_file = gth_file_source_to_gio_file (data->file_source, new_library); g_file_make_directory (new_library, NULL, &error); g_object_unref (gio_file); } if (error != NULL) _gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not create a new library"), &error); if (new_library != NULL) g_object_unref (new_library); g_object_unref (parent); g_object_unref (selected_catalog); g_free (name); */ }