First steps to get a full featured export dialog
authordanigm <dani@danigm.net>
Wed, 23 Jun 2010 00:05:52 +0000 (02:05 +0200)
committerdanigm <dani@danigm.net>
Wed, 23 Jun 2010 00:05:52 +0000 (02:05 +0200)
src/export.c

index 48ba52d..2ddf6d4 100644 (file)
 
 
 gboolean
-tbo_export (TboWindow *tbo, const char *export_to)
+filedialog_cb (GtkWidget *widget, gpointer data)
+{
+    gint response;
+    gchar *filename;
+    GtkWidget *filechooserdialog;
+    GtkEntry *entry = GTK_ENTRY (data);
+
+    filechooserdialog = gtk_file_chooser_dialog_new (_("Export as"),
+                                                     NULL,
+                                                     GTK_FILE_CHOOSER_ACTION_SAVE,
+                                                     GTK_STOCK_CANCEL,
+                                                     GTK_RESPONSE_CANCEL,
+                                                     GTK_STOCK_SAVE,
+                                                     GTK_RESPONSE_ACCEPT,
+                                                     NULL);
+    response = gtk_dialog_run (GTK_DIALOG (filechooserdialog));
+
+    if (response == GTK_RESPONSE_ACCEPT)
+    {
+        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooserdialog));
+        gtk_entry_set_text (entry, filename);
+    }
+
+    gtk_widget_destroy (GTK_WIDGET (filechooserdialog));
+}
+
+gboolean
+tbo_export (TboWindow *tbo, const gchar *export_to)
 {
     cairo_surface_t *surface = NULL;
     cairo_t *cr;
-    int width = tbo->comic->width;
-    int height = tbo->comic->height;
-    char rpath[255];
-    char format_pages[255];
-    char *filename;
+    gint width = tbo->comic->width;
+    gint height = tbo->comic->height;
+    gchar rpath[255];
+    gchar format_pages[255];
+    gchar *filename;
     GList *page_list;
-    int i, n;
+    gint i, n, n2;
     gint response;
 
-    GtkWidget *filechooser;
-    filechooser = gtk_file_chooser_dialog_new (_("Export as"),
-                                               GTK_WINDOW (tbo->window),
-                                               GTK_FILE_CHOOSER_ACTION_SAVE,
-                                               GTK_STOCK_CANCEL,
-                                               GTK_RESPONSE_CANCEL,
-                                               GTK_STOCK_SAVE,
-                                               GTK_RESPONSE_ACCEPT,
-                                               NULL);
+    GtkWidget *dialog;
+    GtkWidget *vbox;
+    GtkWidget *hbox;
+    GtkWidget *fileinput;
+    GtkWidget *filelabel;
+    GtkWidget *filebutton;
+
+    dialog = gtk_dialog_new_with_buttons (_("Export as"),
+                                            GTK_WINDOW (tbo->window),
+                                            GTK_DIALOG_MODAL,
+                                            GTK_STOCK_CANCEL,
+                                            GTK_RESPONSE_CANCEL,
+                                            GTK_STOCK_SAVE,
+                                            GTK_RESPONSE_ACCEPT,
+                                            NULL);
+
+    filebutton = gtk_button_new_from_stock (GTK_STOCK_OPEN);
+    vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+    hbox = gtk_hbox_new (FALSE, 5);
+    filelabel = gtk_label_new (_("Filename: "));
+    fileinput = gtk_entry_new ();
+    gtk_entry_set_text (GTK_ENTRY (fileinput), tbo->comic->title);
+    gtk_container_add (GTK_CONTAINER (hbox), filelabel);
+    gtk_container_add (GTK_CONTAINER (hbox), fileinput);
+    gtk_container_add (GTK_CONTAINER (hbox), filebutton);
+    gtk_container_add (GTK_CONTAINER (vbox), hbox);
+    gtk_widget_show_all (GTK_WIDGET (vbox));
+
+    g_signal_connect (filebutton, "clicked", G_CALLBACK (filedialog_cb), fileinput);
 
-    response = gtk_dialog_run (GTK_DIALOG (filechooser));
+    response = gtk_dialog_run (GTK_DIALOG (dialog));
 
     if (response == GTK_RESPONSE_ACCEPT)
     {
-        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
+        filename = (gchar *)gtk_entry_get_text (GTK_ENTRY (fileinput));
         n = g_list_length (tbo->comic->pages);
+        n2 = n;
         for (i=0; n; n=n/10, i++);
         snprintf (format_pages, 255, "%%s%%0%dd.%%s", i);
         for (i=0, page_list = g_list_first (tbo->comic->pages); page_list; i++, page_list = page_list->next)
         {
             snprintf (rpath, 255, format_pages, filename, i, export_to);
+            if (n2 == 1)
+                snprintf (rpath, 255, "%s.%s", filename, export_to);
             // PDF
             if (strcmp (export_to, "pdf") == 0)
             {
@@ -91,7 +142,7 @@ tbo_export (TboWindow *tbo, const char *export_to)
         }
     }
 
-    gtk_widget_destroy ((GtkWidget *) filechooser);
+    gtk_widget_destroy (GTK_WIDGET (dialog));
 
     return FALSE;
 }