diff --git a/.gitignore b/.gitignore index 09b11a8..c68a716 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ Makefile /src/xfce4-screenshooter.desktop* /stamp-h1 src/xfce4-screenshooter.appdata.xml + +# UI header files generated using exo-csource +lib/*_ui.h diff --git a/Makefile.am b/Makefile.am index 5120a2f..4fa5149 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,8 @@ lib_libscreenshooter_la_SOURCES = \ lib/screenshooter-job-callbacks.c lib/screenshooter-job-callbacks.h \ lib/screenshooter-simple-job.c lib/screenshooter-simple-job.h \ lib/screenshooter-utils.c lib/screenshooter-utils.h \ - lib/screenshooter-imgur.c lib/screenshooter-imgur.h + lib/screenshooter-imgur.c lib/screenshooter-imgur.h \ + lib/screenshooter-imgur-dialog.c lib/screenshooter-imgur-dialog.h lib_libscreenshooter_la_CFLAGS = \ -I$(top_srcdir) \ @@ -62,7 +63,8 @@ lib_libscreenshooter_la_LIBADD = \ @XFIXES_LIBS@ lib_libscreenshooter_built_sources = \ - lib/screenshooter-marshal.c lib/screenshooter-marshal.h + lib/screenshooter-marshal.c lib/screenshooter-marshal.h \ + lib/screenshooter-imgur-dialog_ui.h #Autogenerated sources for the library BUILT_SOURCES = $(lib_libscreenshooter_built_sources) @@ -83,6 +85,9 @@ lib/screenshooter-marshal.c: lib/screenshooter-marshal.list Makefile && glib-genmarshal --prefix=_screenshooter_marshal --body $(top_srcdir)/lib/screenshooter-marshal.list >>$@ \ ) +lib/screenshooter-imgur-dialog_ui.h: lib/screenshooter-imgur-dialog.ui + $(AM_V_GEN) exo-csource --static --strip-comments --strip-content --name=screenshooter_imgur_dialog_ui $< >$@ + # Main application src_xfce4_screenshooter_CFLAGS = \ -I$(top_srcdir)/lib/ \ diff --git a/lib/screenshooter-imgur-dialog.c b/lib/screenshooter-imgur-dialog.c new file mode 100644 index 0000000..3fa5fc5 --- /dev/null +++ b/lib/screenshooter-imgur-dialog.c @@ -0,0 +1,241 @@ +#include "screenshooter-imgur-dialog.h" +#include "screenshooter-imgur-dialog_ui.h" + +struct _ScreenshooterImgurDialog +{ + GObject parent; + GtkDialog *window; + GtkEntry *link_entry; + + const gchar *image_url, *thumbnail_url, *small_thumbnail_url; + const gchar *delete_link; + GtkRadioButton *embed_html_toggle, *embed_bb_code_toggle; + GtkRadioButton *embed_tiny_toggle, *embed_medium_toggle, *embed_full_toggle; + GtkRadioButton *embed_link_full_size_toggle; + GtkTextView *embed_text_view; +}; + +G_DEFINE_TYPE (ScreenshooterImgurDialog, screenshooter_imgur_dialog, G_TYPE_OBJECT) + +void cb_link_toggle_full (GtkToggleButton *button, gpointer user_data); +void cb_link_toggle_medium (GtkToggleButton *button, gpointer user_data); +void cb_link_toggle_tiny (GtkToggleButton *button, gpointer user_data); + +void cb_link_copy (GtkWidget *widget, gpointer user_data); +void cb_link_view_in_browser (GtkWidget *widget, gpointer user_data); + +void cb_generate_embed_text (GtkWidget *widget, gpointer user_data); +void cb_embed_text_copy (GtkWidget *widget, gpointer user_data); + +void cb_delete_link_copy (GtkWidget *widget, gpointer user_data); +void cb_delete_link_view (GtkWidget *widget, gpointer user_data); + +void screenshooter_imgur_dialog_init (ScreenshooterImgurDialog *self) +{ + g_object_ref_sink (self); +} + +static void screenshooter_imgur_dialog_class_init (ScreenshooterImgurDialogClass *klass) +{ +} + +ScreenshooterImgurDialog *screenshooter_imgur_dialog_new (const gchar *upload_name, + const gchar *delete_hash) +{ + g_return_if_fail (upload_name != NULL); + + ScreenshooterImgurDialog *self = g_object_new (SCREENSHOOTER_TYPE_IMGUR_DIALOG, NULL); + + self->image_url = g_strdup_printf ("https://imgur.com/%s.png", upload_name); + self->thumbnail_url = g_strdup_printf ("https://imgur.com/%sl.png", upload_name); + self->small_thumbnail_url = g_strdup_printf ("https://imgur.com/%ss.png", upload_name); + self->delete_link = g_strdup_printf ("https://imgur.com/delete/%s", delete_hash); + + GtkBuilder* builder = gtk_builder_new (); + gtk_builder_add_from_string (builder, screenshooter_imgur_dialog_ui, screenshooter_imgur_dialog_ui_length, NULL); + self->window = GTK_DIALOG (gtk_builder_get_object (builder, "imgur_dialog")); + self->link_entry = GTK_ENTRY (gtk_builder_get_object (builder, "link_entry")); + self->embed_text_view = GTK_TEXT_VIEW (gtk_builder_get_object (builder, "embed_text_view")); + gtk_entry_set_text (self->link_entry, self->image_url); + + // Image tab + + GtkRadioButton *link_full_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "link_full_toggle")); + GtkRadioButton *link_medium_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "link_medium_toggle")); + GtkRadioButton *link_tiny_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "link_tiny_toggle")); + + g_signal_connect (link_full_toggle, "toggled", (GCallback) cb_link_toggle_full, (gpointer) self); + g_signal_connect (link_medium_toggle, "toggled", (GCallback) cb_link_toggle_medium, (gpointer) self); + g_signal_connect (link_tiny_toggle, "toggled", (GCallback) cb_link_toggle_tiny, (gpointer) self); + + GtkButton *link_copy_button = GTK_BUTTON (gtk_builder_get_object (builder, "link_copy_button")); + GtkButton *link_view_button = GTK_BUTTON (gtk_builder_get_object (builder, "link_view_button")); + GtkButton *embed_copy_button = GTK_BUTTON (gtk_builder_get_object (builder, "embed_copy_button")); + + g_signal_connect (link_copy_button, "clicked", (GCallback) cb_link_copy, (gpointer) self); + g_signal_connect (link_view_button, "clicked", (GCallback) cb_link_view_in_browser, (gpointer) self); + g_signal_connect (embed_copy_button, "clicked", (GCallback) cb_embed_text_copy, (gpointer) self); + + // Embed tab + + self->embed_html_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_html_toggle")); + self->embed_bb_code_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_bb_code_toggle")); + self->embed_tiny_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_tiny_toggle")); + self->embed_medium_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_medium_toggle")); + self->embed_full_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_full_toggle")); + self->embed_link_full_size_toggle = GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "embed_link_full_size_toggle")); + + // Regenerate the embed text when any togglebutton on the embed tab is toggled + g_signal_connect (self->embed_html_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + g_signal_connect (self->embed_bb_code_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + g_signal_connect (self->embed_tiny_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + g_signal_connect (self->embed_medium_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + g_signal_connect (self->embed_full_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + g_signal_connect (self->embed_link_full_size_toggle, "toggled", (GCallback) cb_generate_embed_text, (gpointer) self); + // Generate default embed text + cb_generate_embed_text (NULL, (gpointer) self); + + // Deletion link tab + + GtkEntry *delete_link_entry = GTK_ENTRY (gtk_builder_get_object (builder, "delete_link_entry")); + gtk_entry_set_text (delete_link_entry, self->delete_link); + + GtkButton *delete_link_copy_button = GTK_BUTTON (gtk_builder_get_object (builder, "delete_link_copy_button")); + GtkButton *delete_link_view_button = GTK_BUTTON (gtk_builder_get_object (builder, "delete_link_view_button")); + + g_signal_connect (delete_link_copy_button, "clicked", G_CALLBACK (cb_delete_link_copy), self); + g_signal_connect (delete_link_view_button, "clicked", G_CALLBACK (cb_delete_link_view), self); + + return self; +} + +void screenshooter_imgur_dialog_run (ScreenshooterImgurDialog *self) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (self)); + + gtk_widget_show_all (gtk_dialog_get_content_area (self->window)); + gtk_dialog_run (self->window); +} + +// Callbacks + +void cb_link_toggle_full (GtkToggleButton *button, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + if (gtk_toggle_button_get_active (button)) + gtk_entry_set_text (dialog->link_entry, dialog->image_url); +} + +void cb_link_toggle_medium (GtkToggleButton *button, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + if (gtk_toggle_button_get_active (button)) + gtk_entry_set_text (dialog->link_entry, dialog->thumbnail_url); +} + +void cb_link_toggle_tiny (GtkToggleButton *button, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + if (gtk_toggle_button_get_active (button)) + gtk_entry_set_text (dialog->link_entry, dialog->small_thumbnail_url); +} + +void cb_link_copy (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + const gchar *text = gtk_entry_get_text (dialog->link_entry); + guint16 len = gtk_entry_get_text_length (dialog->link_entry); + GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, text, len); +} + +void cb_link_view_in_browser (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + const gchar *link = gtk_entry_get_text (dialog->link_entry); + exo_execute_preferred_application ("WebBrowser", link, NULL, NULL, NULL); +} + +void cb_generate_embed_text (GtkWidget* widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + + const gchar *link = NULL; + gboolean link_to_full_size = gtk_toggle_button_get_active (dialog->embed_link_full_size_toggle); + + if (gtk_toggle_button_get_active (dialog->embed_full_toggle)) + link = dialog->image_url; + else if (gtk_toggle_button_get_active (dialog->embed_medium_toggle)) + link = dialog->thumbnail_url; + else if (gtk_toggle_button_get_active (dialog->embed_tiny_toggle)) + link = dialog->small_thumbnail_url; + else + g_return_if_reached (); + + g_return_if_fail (link != NULL); + + const gchar *text = NULL; + + if (gtk_toggle_button_get_active (dialog->embed_html_toggle)) + if (link_to_full_size) + text = g_markup_printf_escaped ("\n \n", dialog->image_url, link); + else + text = g_markup_printf_escaped ("", link); + else if (gtk_toggle_button_get_active (dialog->embed_bb_code_toggle)) + if (link_to_full_size) + text = g_strdup_printf ("[url=%s]\n [img]%s[/img]\n[/url]", dialog->image_url, link); + else + text = g_strdup_printf ("[img]%s[/img]", link); + else + g_return_if_reached (); + + g_return_if_fail (text != NULL); + + gtk_text_buffer_set_text (gtk_text_view_get_buffer (dialog->embed_text_view), text, strlen(text)); + g_free(text); +} + +void cb_embed_text_copy (GtkWidget* widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + + GtkTextIter start, end; + GtkTextBuffer *buffer = gtk_text_view_get_buffer (dialog->embed_text_view); + gtk_text_buffer_get_bounds (buffer, &start, &end); + + const gchar *text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); + guint16 len = strlen(text); + + GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, text, len); +} + +void cb_delete_link_copy (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, dialog->delete_link, strlen (dialog->delete_link)); +} + +void cb_delete_link_view (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (SCREENSHOOTER_IS_IMGUR_DIALOG (user_data)); + + ScreenshooterImgurDialog *dialog = SCREENSHOOTER_IMGUR_DIALOG (user_data); + exo_execute_preferred_application ("WebBrowser", dialog->delete_link, NULL, NULL, NULL); +} \ No newline at end of file diff --git a/lib/screenshooter-imgur-dialog.h b/lib/screenshooter-imgur-dialog.h new file mode 100644 index 0000000..6dce910 --- /dev/null +++ b/lib/screenshooter-imgur-dialog.h @@ -0,0 +1,22 @@ +#ifndef IMGUR_DIALOG_H +#define IMGUR_DIALOG_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +G_BEGIN_DECLS + +#define SCREENSHOOTER_TYPE_IMGUR_DIALOG screenshooter_imgur_dialog_get_type () +G_DECLARE_FINAL_TYPE (ScreenshooterImgurDialog, screenshooter_imgur_dialog, SCREENSHOOTER, IMGUR_DIALOG, GObject) + +ScreenshooterImgurDialog *screenshooter_imgur_dialog_new (const gchar *upload_name, + const gchar *delete_hash); +void screenshooter_imgur_dialog_run (); + +G_END_DECLS + +#endif \ No newline at end of file diff --git a/lib/screenshooter-imgur-dialog.ui b/lib/screenshooter-imgur-dialog.ui new file mode 100644 index 0000000..bb38a07 --- /dev/null +++ b/lib/screenshooter-imgur-dialog.ui @@ -0,0 +1,715 @@ + + + + + + True + False + gtk-copy + + + True + False + web-browser + + + True + False + gtk-copy + + + True + False + gtk-copy + + + True + False + web-browser + + + False + Screenshot - Upload to imgur complete + applets-screenshooter + dialog + + + + + + False + vertical + 5 + + + False + end + + + gtk-close + True + True + True + True + + + True + True + 0 + + + + + False + False + 0 + + + + + True + False + 10 + + + True + False + applets-screenshooter + 6 + + + False + True + 0 + + + + + True + False + Your uploaded image + + + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + True + + + True + False + 10 + 10 + 10 + 10 + vertical + 10 + + + True + False + 20 + + + True + False + Size + + + + + + False + True + 0 + + + + + True + False + 20 + + + Tiny + True + True + False + True + False + link_full_toggle + + + False + True + 0 + + + + + Medium + True + True + False + True + False + link_full_toggle + + + False + True + 1 + + + + + Full + True + True + False + True + False + + + False + True + 2 + + + + + True + True + 1 + + + + + False + True + 0 + + + + + True + False + 20 + + + True + False + Link + + + + + + False + True + 0 + + + + + True + False + 10 + + + True + True + False + + + True + True + 0 + + + + + True + False + 10 + + + True + True + True + Copy + image1 + True + + + False + True + 0 + + + + + True + True + True + View in browser + image2 + + + False + True + 1 + + + + + False + True + 1 + + + + + True + True + 1 + + + + + False + True + 1 + + + + + + + True + False + Image + + + False + True + + + + + True + False + 10 + 10 + 10 + 10 + 10 + 20 + + + True + False + Syntax + + + + + + 0 + 0 + + + + + True + False + 20 + + + HTML + True + True + False + True + False + + + False + True + 0 + + + + + BBCODE + True + True + False + True + False + embed_html_toggle + + + False + True + 1 + + + + + 1 + 0 + + + + + True + False + Code + + + + + + 0 + 3 + + + + + True + False + True + True + 20 + + + True + True + in + + + True + True + False + True + + + + + True + True + 0 + + + + + True + True + True + Copy + center + center + image3 + + + False + True + 1 + + + + + 1 + 3 + + + + + True + False + Show + + + + + + 0 + 2 + + + + + True + False + 20 + + + Tiny + True + True + False + False + embed_full_toggle + + + False + True + 0 + + + + + Medium + True + True + False + False + embed_full_toggle + + + False + True + 1 + + + + + Full + True + True + False + True + False + + + False + True + 2 + + + + + 1 + 2 + + + + + True + False + Type + + + + + + 0 + 1 + + + + + True + False + 20 + + + Direct image + True + True + False + True + False + embed_link_full_size_toggle + + + False + True + 0 + + + + + Link to full size + True + True + False + True + False + + + False + True + 1 + + + + + 1 + 1 + + + + + 1 + + + + + True + False + Embed into code + + + 1 + False + + + + + True + False + 10 + 10 + 10 + 10 + vertical + 10 + + + True + False + 20 + + + True + False + Delete + + + + + + False + True + 0 + + + + + True + False + 20 + + + True + True + False + + + True + True + 0 + + + + + True + True + True + Copy + image4 + + + False + True + 1 + + + + + True + True + True + View in browser + image6 + + + False + True + 2 + + + + + True + True + 1 + + + + + False + True + 0 + + + + + True + False + This link only shows up once. Make sure to save it if you think you might be deleting this image. We don't currently support linking images to Imgur accounts. + True + + + False + True + 1 + + + + + 2 + + + + + True + False + Deletion link + + + 2 + False + + + + + True + True + 1 + + + + + + close_button + + + diff --git a/lib/screenshooter-imgur.c b/lib/screenshooter-imgur.c index a58ea30..16ba77d 100644 --- a/lib/screenshooter-imgur.c +++ b/lib/screenshooter-imgur.c @@ -34,6 +34,7 @@ imgur_upload_job (ScreenshooterJob *job, GArray *param_values, GError **error) { const gchar *image_path, *title; gchar *online_file_name = NULL; + gchar *delete_hash = NULL; const gchar* proxy_uri; SoupURI *soup_proxy_uri; #if DEBUG > 0 @@ -128,15 +129,19 @@ imgur_upload_job (ScreenshooterJob *job, GArray *param_values, GError **error) root_node = xmlDocGetRootElement(doc); for (child_node = root_node->children; child_node; child_node = child_node->next) + { if (xmlStrEqual(child_node->name, (const xmlChar *) "id")) online_file_name = xmlNodeGetContent(child_node); + else if (xmlStrEqual (child_node->name, (const xmlChar *) "deletehash")) + delete_hash = xmlNodeGetContent (child_node); + } TRACE("found picture id %s\n", online_file_name); xmlFreeDoc(doc); soup_buffer_free (buf); g_object_unref (session); g_object_unref (msg); - screenshooter_job_image_uploaded (job, online_file_name); + screenshooter_job_image_uploaded (job, online_file_name, delete_hash); return TRUE; } diff --git a/lib/screenshooter-job-callbacks.c b/lib/screenshooter-job-callbacks.c index 30a91a7..c4220b7 100644 --- a/lib/screenshooter-job-callbacks.c +++ b/lib/screenshooter-job-callbacks.c @@ -18,6 +18,7 @@ */ #include "screenshooter-job-callbacks.h" +#include "screenshooter-imgur-dialog.h" /* Create and return a dialog with a spinner and a translated title * will be used during upload jobs @@ -352,201 +353,13 @@ cb_ask_for_information (ScreenshooterJob *job, void cb_image_uploaded (ScreenshooterJob *job, gchar *upload_name, + gchar *delete_hash, gchar **last_user) { - GtkWidget *dialog; - GtkWidget *main_alignment, *vbox; - GtkWidget *link_label; - GtkWidget *image_link, *thumbnail_link, *small_thumbnail_link; - GtkWidget *example_label, *html_label, *bb_label; - GtkWidget *html_code_view, *bb_code_view; - GtkWidget *html_frame, *bb_frame; - GtkWidget *links_alignment, *code_alignment; - GtkWidget *links_box, *code_box; - - GtkTextBuffer *html_buffer, *bb_buffer; - - const gchar *image_url, *thumbnail_url, *small_thumbnail_url; - const gchar *image_markup, *thumbnail_markup, *small_thumbnail_markup; - const gchar *html_code, *bb_code; - gchar *title; - gchar *last_user_temp; - g_return_if_fail (upload_name != NULL); + g_return_if_fail (delete_hash != NULL); - title = _("My screenshot on Imgur"); - image_url = g_strdup_printf ("https://i.imgur.com/%s.png", upload_name); - thumbnail_url = - g_strdup_printf ("https://imgur.com/%sl.png", upload_name); - small_thumbnail_url = - g_strdup_printf ("https://imgur.com/%ss.png", upload_name); - - image_markup = - g_markup_printf_escaped (_("Full size image"), image_url); - thumbnail_markup = - g_markup_printf_escaped (_("Large thumbnail"), thumbnail_url); - small_thumbnail_markup = - g_markup_printf_escaped (_("Small thumbnail"), small_thumbnail_url); - html_code = - g_markup_printf_escaped ("\n \n", - image_url, thumbnail_url); - bb_code = - g_strdup_printf ("[url=%s]\n [img]%s[/img]\n[/url]", image_url, thumbnail_url); - - /* Dialog */ - dialog = - xfce_titled_dialog_new_with_buttons (title, - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - "gtk-close", - GTK_RESPONSE_CLOSE, - NULL); - - gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 0); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 12); - gtk_window_set_icon_name (GTK_WINDOW (dialog), "applications-internet"); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - /* Create the main alignment for the dialog */ - main_alignment = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1); - gtk_widget_set_hexpand (main_alignment, TRUE); - gtk_widget_set_vexpand (main_alignment, TRUE); - gtk_widget_set_margin_top (main_alignment, 6); - gtk_widget_set_margin_bottom (main_alignment, 0); - gtk_widget_set_margin_start (main_alignment, 10); - gtk_widget_set_margin_end (main_alignment, 10); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), main_alignment, TRUE, TRUE, 0); - - /* Create the main box for the dialog */ - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); - gtk_container_add (GTK_CONTAINER (main_alignment), vbox); - - /* Links bold label */ - link_label = gtk_label_new (""); - gtk_label_set_markup (GTK_LABEL (link_label), - _("" - "Links")); - gtk_widget_set_halign (link_label, GTK_ALIGN_START); - gtk_widget_set_valign (link_label, GTK_ALIGN_START); - gtk_container_add (GTK_CONTAINER (vbox), link_label); - - /* Links alignment */ - links_alignment = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1); - gtk_widget_set_hexpand (links_alignment, TRUE); - gtk_widget_set_vexpand (links_alignment, TRUE); - gtk_widget_set_margin_top (links_alignment, 0); - gtk_widget_set_margin_bottom (links_alignment, 0); - gtk_widget_set_margin_start (links_alignment, 12); - gtk_widget_set_margin_end (links_alignment, 0); - gtk_container_add (GTK_CONTAINER (vbox), links_alignment); - - /* Links box */ - links_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); - gtk_container_set_border_width (GTK_CONTAINER (links_box), 0); - gtk_container_add (GTK_CONTAINER (links_alignment), links_box); - - /* Create the image link */ - image_link = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (image_link), image_markup); - gtk_widget_set_halign (image_link, GTK_ALIGN_START); - gtk_widget_set_valign (image_link, GTK_ALIGN_START); - gtk_widget_set_tooltip_text (image_link, image_url); - gtk_container_add (GTK_CONTAINER (links_box), image_link); - - /* Create the thumbnail link */ - thumbnail_link = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (thumbnail_link), thumbnail_markup); - gtk_widget_set_halign (thumbnail_link, GTK_ALIGN_START); - gtk_widget_set_valign (thumbnail_link, GTK_ALIGN_START); - gtk_widget_set_tooltip_text (thumbnail_link, thumbnail_url); - gtk_container_add (GTK_CONTAINER (links_box), thumbnail_link); - - /* Create the small thumbnail link */ - small_thumbnail_link = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (small_thumbnail_link), small_thumbnail_markup); - gtk_widget_set_halign (small_thumbnail_link, GTK_ALIGN_START); - gtk_widget_set_valign (small_thumbnail_link, GTK_ALIGN_START); - gtk_widget_set_tooltip_text (small_thumbnail_link, small_thumbnail_url); - gtk_container_add (GTK_CONTAINER (links_box), small_thumbnail_link); - - /* Examples bold label */ - example_label = gtk_label_new (""); - gtk_label_set_markup (GTK_LABEL (example_label), - _("" - "Code for a thumbnail pointing to the full size image")); - gtk_widget_set_halign (example_label, GTK_ALIGN_START); - gtk_widget_set_valign (example_label, GTK_ALIGN_START); - gtk_container_add (GTK_CONTAINER (vbox), example_label); - - /* Code alignment */ - code_alignment = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1); - gtk_widget_set_hexpand (code_alignment, TRUE); - gtk_widget_set_vexpand (code_alignment, TRUE); - gtk_widget_set_margin_top (code_alignment, 0); - gtk_widget_set_margin_bottom (code_alignment, 0); - gtk_widget_set_margin_start (code_alignment, 12); - gtk_widget_set_margin_end (code_alignment, 0); - gtk_container_add (GTK_CONTAINER (vbox), code_alignment); - - /* Links box */ - code_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); - gtk_container_set_border_width (GTK_CONTAINER (code_box), 0); - gtk_container_add (GTK_CONTAINER (code_alignment), code_box); - - /* HTML title */ - html_label = gtk_label_new (_("HTML")); - gtk_widget_set_halign (html_label, GTK_ALIGN_START); - gtk_widget_set_valign (html_label, GTK_ALIGN_START); - gtk_container_add (GTK_CONTAINER (code_box), html_label); - - /* HTML frame */ - html_frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (html_frame), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (code_box), html_frame); - - /* HTML code text view */ - html_buffer = gtk_text_buffer_new (NULL); - gtk_text_buffer_set_text (html_buffer, html_code, -1); - - html_code_view = gtk_text_view_new_with_buffer (html_buffer); - gtk_text_view_set_left_margin (GTK_TEXT_VIEW (html_code_view), - 10); - gtk_text_view_set_editable (GTK_TEXT_VIEW (html_code_view), - FALSE); - gtk_container_add (GTK_CONTAINER (html_frame), html_code_view); - - /* BB title */ - bb_label = gtk_label_new (_("BBCode for forums")); - gtk_widget_set_halign (bb_label, GTK_ALIGN_START); - gtk_widget_set_valign (bb_label, GTK_ALIGN_START); - gtk_container_add (GTK_CONTAINER (code_box), bb_label); - - /* BB frame */ - bb_frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (bb_frame), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (code_box), bb_frame); - - /* BBcode text view */ - bb_buffer = gtk_text_buffer_new (NULL); - gtk_text_buffer_set_text (bb_buffer, bb_code, -1); - - bb_code_view = gtk_text_view_new_with_buffer (bb_buffer); - gtk_text_view_set_left_margin (GTK_TEXT_VIEW (bb_code_view), - 10); - gtk_text_view_set_editable (GTK_TEXT_VIEW (bb_code_view), - FALSE); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (bb_code_view), - GTK_WRAP_CHAR); - gtk_container_add (GTK_CONTAINER (bb_frame), bb_code_view); - - /* Show the dialog and run it */ - gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dialog))); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_object_unref (html_buffer); - g_object_unref (bb_buffer); + ScreenshooterImgurDialog* dialog = screenshooter_imgur_dialog_new (upload_name, delete_hash); + screenshooter_imgur_dialog_run (dialog); } diff --git a/lib/screenshooter-job-callbacks.h b/lib/screenshooter-job-callbacks.h index b7daf71..f9c7495 100644 --- a/lib/screenshooter-job-callbacks.h +++ b/lib/screenshooter-job-callbacks.h @@ -52,6 +52,7 @@ cb_update_info (ExoJob *job, void cb_image_uploaded (ScreenshooterJob *job, gchar *upload_name, + gchar *delete_hash, gchar **last_user); void cb_ask_for_information (ScreenshooterJob *job, diff --git a/lib/screenshooter-job.c b/lib/screenshooter-job.c index 8dca9a3..a855d4a 100644 --- a/lib/screenshooter-job.c +++ b/lib/screenshooter-job.c @@ -121,9 +121,9 @@ screenshooter_job_class_init (ScreenshooterJobClass *klass) g_signal_new ("image-uploaded", G_TYPE_FROM_CLASS (klass), G_SIGNAL_NO_HOOKS, 0, NULL, NULL, - _screenshooter_marshal_VOID__STRING, + _screenshooter_marshal_VOID__STRING_STRING, G_TYPE_NONE, - 1, G_TYPE_STRING); + 2, G_TYPE_STRING, G_TYPE_STRING); } @@ -188,10 +188,10 @@ void screenshooter_job_ask_info (ScreenshooterJob *job, void -screenshooter_job_image_uploaded (ScreenshooterJob *job, const gchar *file_name) +screenshooter_job_image_uploaded (ScreenshooterJob *job, const gchar *file_name, const gchar *delete_hash) { g_return_if_fail (SCREENSHOOTER_IS_JOB (job)); TRACE ("Emit image-uploaded signal."); - exo_job_emit (EXO_JOB (job), job_signals[IMAGE_UPLOADED], 0, file_name); + exo_job_emit (EXO_JOB (job), job_signals[IMAGE_UPLOADED], 0, file_name, delete_hash); } diff --git a/lib/screenshooter-job.h b/lib/screenshooter-job.h index ecb3543..d77d2af 100644 --- a/lib/screenshooter-job.h +++ b/lib/screenshooter-job.h @@ -69,7 +69,8 @@ void screenshooter_job_ask_info (ScreenshooterJob *job, void screenshooter_job_image_uploaded (ScreenshooterJob *job, - const gchar *file_name); + const gchar *file_name, + const gchar *delete_hash); G_END_DECLS diff --git a/lib/screenshooter-marshal.list b/lib/screenshooter-marshal.list index c62b28c..d7f4e10 100644 --- a/lib/screenshooter-marshal.list +++ b/lib/screenshooter-marshal.list @@ -1,2 +1,3 @@ VOID:STRING VOID:POINTER,STRING +VOID:STRING,STRING