[Goodies-commits] r4924 - xfburn/trunk/xfburn
David Mohr
squisher at xfce.org
Mon Jun 9 06:27:02 CEST 2008
Author: squisher
Date: 2008-06-09 04:27:02 +0000 (Mon, 09 Jun 2008)
New Revision: 4924
Modified:
xfburn/trunk/xfburn/xfburn-burn-image-dialog.c
xfburn/trunk/xfburn/xfburn-burn-image-dialog.h
xfburn/trunk/xfburn/xfburn-main.c
Log:
Adding infrastructure for command line options, implement burn image cli option
Modified: xfburn/trunk/xfburn/xfburn-burn-image-dialog.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-burn-image-dialog.c 2008-06-08 23:59:29 UTC (rev 4923)
+++ xfburn/trunk/xfburn/xfburn-burn-image-dialog.c 2008-06-09 04:27:02 UTC (rev 4924)
@@ -561,3 +561,10 @@
return obj;
}
+
+void xfburn_burn_image_dialog_set_filechooser_name ( GtkWidget * dialog, gchar *name)
+{
+ XfburnBurnImageDialogPrivate *priv = XFBURN_BURN_IMAGE_DIALOG_GET_PRIVATE (XFBURN_BURN_IMAGE_DIALOG (dialog));
+
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (priv->chooser_image), name);
+}
Modified: xfburn/trunk/xfburn/xfburn-burn-image-dialog.h
===================================================================
--- xfburn/trunk/xfburn/xfburn-burn-image-dialog.h 2008-06-08 23:59:29 UTC (rev 4923)
+++ xfburn/trunk/xfburn/xfburn-burn-image-dialog.h 2008-06-09 04:27:02 UTC (rev 4924)
@@ -51,6 +51,7 @@
GtkType xfburn_burn_image_dialog_get_type ();
GtkWidget *xfburn_burn_image_dialog_new ();
+void xfburn_burn_image_dialog_set_filechooser_name (GtkWidget * dialog, gchar *name);
G_END_DECLS
Modified: xfburn/trunk/xfburn/xfburn-main.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-main.c 2008-06-08 23:59:29 UTC (rev 4923)
+++ xfburn/trunk/xfburn/xfburn-main.c 2008-06-09 04:27:02 UTC (rev 4924)
@@ -41,14 +41,53 @@
#include "xfburn-utils.h"
#include "xfburn-settings.h"
#include "xfburn-stock.h"
+#include "xfburn-burn-image-dialog.h"
#include "xfburn-main-window.h"
+
+/* internal prototypes */
+static gboolean parse_option (const gchar *option_name, const gchar *value,
+ gpointer data, GError **error);
+
+/* command line parameters */
+static gchar *image_filename = NULL;
+static gboolean show_version = FALSE;
+static gboolean other_action = FALSE;
+static gboolean show_main = FALSE;
+
+static GOptionEntry optionentries[] = {
+ { "burn-image", 'i', G_OPTION_FLAG_OPTIONAL_ARG /* || G_OPTION_FLAG_FILENAME */, G_OPTION_ARG_CALLBACK, &parse_option,
+ "Open the burn image dialog. The filename of the image can optionally be specified as a parameter", NULL },
+ { "version", 'V', G_OPTION_FLAG_NO_ARG , G_OPTION_ARG_NONE, &show_version,
+ "Display program version and exit", NULL },
+ { "main", 'm', G_OPTION_FLAG_NO_ARG , G_OPTION_ARG_NONE, &show_main,
+ "Show main program even when other action is specified on the command line", NULL },
+ { NULL },
+};
+
+static gboolean parse_option (const gchar *option_name, const gchar *value,
+ gpointer data, GError **error)
+{
+ if (strcmp (option_name, "-i") == 0 || strcmp (option_name, "--burn-image") == 0) {
+ if (value == NULL)
+ image_filename = "";
+ else
+ image_filename = g_strdup(value);
+ } else {
+ g_set_error (error, 0, G_OPTION_ERROR_FAILED, "Invalid command line option. Please report, this is a bug.");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* entry point */
int
main (int argc, char **argv)
{
GtkWidget *mainwin;
gint n_drives;
+ GError *error = NULL;
#if DEBUG > 0
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
@@ -56,7 +95,21 @@
g_set_application_name (_("Xfburn"));
- if (argc > 1 && (!strcmp (argv[1], "--version") || !strcmp (argv[1], "-V"))) {
+ g_thread_init (NULL);
+ gdk_threads_init ();
+ gdk_threads_enter ();
+
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+ if (!gtk_init_with_args (&argc, &argv, "", optionentries, GETTEXT_PACKAGE, &error)) {
+ if (error != NULL) {
+ g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"), PACKAGE, error->message, PACKAGE_NAME);
+ g_error_free (error);
+ return 1;
+ }
+ }
+
+ if (show_version) {
g_print ("\tThis is %s version %s for Xfce %s\n", PACKAGE, VERSION, xfce_version_string ());
g_print ("\tbuilt with GTK+-%d.%d.%d, ", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
g_print ("linked with GTK+-%d.%d.%d.\n", gtk_major_version, gtk_minor_version, gtk_micro_version);
@@ -64,12 +117,7 @@
exit (EXIT_SUCCESS);
}
- g_thread_init (NULL);
- gdk_threads_init ();
- gdk_threads_enter ();
- gtk_init (&argc, &argv);
-
xfburn_settings_init ();
#ifdef HAVE_THUNAR_VFS
@@ -79,8 +127,6 @@
g_message ("Thunar-VFS not available, using default implementation");
#endif
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-
xfburn_stock_init ();
n_drives = xfburn_device_list_init ();
if (n_drives < 1) {
@@ -95,11 +141,39 @@
gtk_widget_destroy (GTK_WIDGET (dialog));
}
- mainwin = xfburn_main_window_new ();
+ /* evaluate parsed command line options */
- gtk_widget_show (mainwin);
+ if (image_filename != NULL) {
+ GtkWidget *dialog = xfburn_burn_image_dialog_new ();
+
+ other_action = TRUE;
+ DBG ("image_filename = '%s'\n", image_filename);
+
+ if (*image_filename != '\0') {
+ gchar *image_fullname;
+
+ if (!g_path_is_absolute (image_filename))
+ image_fullname = g_build_filename (g_get_current_dir (), image_filename, NULL);
+ else
+ image_fullname = image_filename;
+
+ if (g_file_test (image_fullname, G_FILE_TEST_EXISTS))
+ xfburn_burn_image_dialog_set_filechooser_name (dialog, image_fullname);
+ else
+ xfce_err ( g_strdup_printf ( _("Image file '%s' does not exist!"), image_fullname));
+ }
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+
+ if (!other_action || show_main) {
+ mainwin = xfburn_main_window_new ();
+
+ gtk_widget_show (mainwin);
- gtk_main ();
+ gtk_main ();
+ }
#ifdef HAVE_THUNAR_VFS
thunar_vfs_shutdown ();
More information about the Goodies-commits
mailing list