From 86158d60e767380f19e073bf14bf84d43fcec815 Mon Sep 17 00:00:00 2001 From: Jan Lipovský Date: Sat, 8 Jan 2011 18:05:32 +0100 Subject: Added Extra options; Set as default and load from defalt keyfile; --- .gitignore | 1 + configure.ac | 16 ++++++++++++---- src/Makefile.am | 1 + src/dialogs.c | 20 ++++++++++++++++++++ src/globals.c | 13 +++++++++++++ src/globals.h | 10 +++++++++- src/gncpmount.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/keyfile.c | 6 ++++++ src/main.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ncpwrapper.c | 2 +- 10 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index 06e5a83..f76cfe3 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ src/obj/ src/gncpmount.depend src/gncpmount.layout src/gncpmount +src/gncpmount.cbp diff --git a/configure.ac b/configure.ac index 848930d..2fd7895 100755 --- a/configure.ac +++ b/configure.ac @@ -25,6 +25,16 @@ if test "x$HAVE_PKGCONFIG" = "xno"; then fi +dnl Check for ncpmount first +AC_CHECK_PROG(HAVE_NCPMOUNT, ncpmount, yes, no) +AC_PATH_PROG(NCPMOUNT_PATH, ncpmount, no) + +dnl Give error and exit if we don't have ncpmount +if test "x$HAVE_NCPMOUNT" = "xno"; then + AC_MSG_ERROR(You need to have ncpmount (ncpfs) installed !) +fi + + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.26.0) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) @@ -49,12 +59,10 @@ AC_SUBST(WARN_CFLAGS) # Checks for header files. -#AC_CHECK_HEADERS([gtk/gtk.h locale.h libintl.h]) +AC_CHECK_HEADERS([locale.h libintl.h]) # Checks for typedefs, structures, and compiler characteristics. -#AC_C_INLINE - -# +AC_C_INLINE AC_CONFIG_FILES([Makefile diff --git a/src/Makefile.am b/src/Makefile.am index b23dc4c..ef49aa9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,7 @@ NULL = INCLUDES = \ -DDATADIR=\"$(datadir)\" \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DNCPMOUNT_PATH=\""$(NCPMOUNT_PATH)"\" \ -I$(top_srcdir) \ -I$(top_builddir) \ $(WARN_CFLAGS) \ diff --git a/src/dialogs.c b/src/dialogs.c index 1ab8531..179aef1 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -42,6 +42,7 @@ void save_options_to_cmdparams() set_parameter_text ((options.entry_timeout), &cmd_params.time_out); set_parameter_text ((options.entry_uid), &cmd_params.uid); set_parameter_text ((options.entry_volume), &cmd_params.volume); + set_parameter_text ((options.entry_extraoptions), &cmd_params.extraoptions); /* Checkboxes */ set_parameter_bool ((options.check_b), &cmd_params.b); @@ -133,6 +134,11 @@ set_options_from_cmdparams () else gtk_entry_set_text(GTK_ENTRY(options.entry_volume), ""); + if(cmd_params.extraoptions != NULL) + gtk_entry_set_text(GTK_ENTRY(options.entry_extraoptions), g_shell_unquote(cmd_params.extraoptions, NULL)); + else + gtk_entry_set_text(GTK_ENTRY(options.entry_extraoptions), ""); + /* Checkboxes */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options.check_b), cmd_params.b); @@ -332,6 +338,20 @@ void show_options_dialog () gtk_table_attach (GTK_TABLE(table), hsep, 0, 2, row, row+1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 6, 6); row++; + halign = gtk_alignment_new(0, 0, 0, 1); + label = gtk_label_new (_("Extra options:")); + gtk_container_add(GTK_CONTAINER(halign), label); + gtk_table_attach(GTK_TABLE(table), halign, 0, 1, row, row+1, GTK_FILL , GTK_FILL | GTK_EXPAND, 6, 0); + + options.entry_extraoptions = gtk_entry_new (); + gtk_table_attach_defaults (GTK_TABLE (table), options.entry_extraoptions , 1, 2, row, row+1); + row++; + + /* ----- */ + hsep = gtk_hseparator_new(); + gtk_table_attach (GTK_TABLE(table), hsep, 0, 2, row, row+1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 6, 6); + row++; + /* Prefill set options */ set_options_from_cmdparams(); diff --git a/src/globals.c b/src/globals.c index 86c48f3..2a2c463 100644 --- a/src/globals.c +++ b/src/globals.c @@ -137,6 +137,13 @@ gchar *get_ncpmount_command (gboolean whith_password, gint *length) command = g_string_append (command, cmd_params.codepage); } + /* Extra options */ + if(cmd_params.extraoptions != NULL) + { + command = g_string_append (command, " "); + command = g_string_append (command, g_shell_unquote(cmd_params.extraoptions, NULL)); + } + if(cmd_params.C) { command = g_string_append (command, " -C "); @@ -275,6 +282,12 @@ void clear_cmdparams () cmd_params.mount_point = NULL; } + if(cmd_params.extraoptions != NULL) + { + g_free(cmd_params.extraoptions); + cmd_params.extraoptions = NULL; + } + cmd_params.C = FALSE; cmd_params.n = FALSE; cmd_params.s = FALSE; diff --git a/src/globals.h b/src/globals.h index c442edf..99ec9af 100644 --- a/src/globals.h +++ b/src/globals.h @@ -11,7 +11,12 @@ #define PROG_VERSION "0.0.3" #define GUI_TITLE "gncpmount - 0.0.3" - +/* CB - im using codeblocks */ +#ifdef CB + #define PACKAGE "gncpmount" + #define GNOMELOCALEDIR "/usr/share/locale" + #define NCPMOUNT_PATH "/usr/bin/ncpmount" +#endif /** * Define type TWindow - structure of important widgets in gui @@ -66,6 +71,7 @@ typedef struct opt_struct GtkWidget *entry_dmode; GtkWidget *entry_timeout; GtkWidget *entry_retrycount; + GtkWidget *entry_extraoptions; /* ComboBox */ GtkWidget *combo_signature; @@ -104,6 +110,8 @@ typedef struct params gchar *charset; /* charset used for input and display */ gchar *codepage; /* codepage used on volume, including letters 'cp' */ + gchar *extraoptions; /* extra options - type any parameter which is not in the options dialog */ + /*gchar *cuid; */ /* uid to identify the connection to mount on - Only makes sense for root */ gboolean C; /* don't convert password to uppercase */ diff --git a/src/gncpmount.c b/src/gncpmount.c index 2a98443..2fa0a32 100644 --- a/src/gncpmount.c +++ b/src/gncpmount.c @@ -5,7 +5,7 @@ #include "logo.xpm.h" -#define WIDTH 400 +#define WIDTH -1 #define HEIGHT -1 @@ -154,6 +154,32 @@ open_file () +/** +* Save cmd_params to default file +*/ +static void +set_default () +{ + gchar *path = g_strconcat(g_get_home_dir(),"/.gncpmount", NULL); + gchar *filename = g_strconcat(path, "/default", NULL); + + + if (g_mkdir_with_parents(path,448) < 0) /* Octal - 700*/ + { + show_message(GTK_MESSAGE_ERROR,_("ERROR: Set as default"),"",_("Can't create directory: ~/.gncpmount"),""); + } + + save_gui_to_cmdparams(); + save_cmdparams_to_file (filename); + + show_message(GTK_MESSAGE_INFO,_("Set as default"),"",_("Current state of GUI was set as default."),""); + + g_free (path); + g_free (filename); +} + + + /** * Create Save file dialog * and save cmd_params to file @@ -283,6 +309,8 @@ int main (int argc, char *argv[]) GdkPixbuf *xpm = NULL; + gchar *keyfile_default = g_strconcat(g_get_home_dir(),"/.gncpmount/default", NULL); + setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, GNOMELOCALEDIR); textdomain(PACKAGE); @@ -330,11 +358,16 @@ int main (int argc, char *argv[]) g_signal_connect (GTK_OBJECT (menuitem), "activate", open_file, NULL); gtk_widget_show (menuitem); - menuitem = gtk_menu_item_new_with_mnemonic (_("_Save")); + menuitem = gtk_menu_item_new_with_mnemonic (_("_Save as..")); gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); g_signal_connect (GTK_OBJECT (menuitem), "activate", save_file, NULL); gtk_widget_show (menuitem); + menuitem = gtk_menu_item_new_with_mnemonic (_("_Set as default")); + gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); + g_signal_connect (GTK_OBJECT (menuitem), "activate", set_default, NULL); + gtk_widget_show (menuitem); + menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); gtk_widget_show (menuitem); @@ -500,10 +533,18 @@ int main (int argc, char *argv[]) /* Fill in informations from cmd_params to widgets */ clear_cmdparams (); + + /* Try to load default settings */ + if (g_file_test(keyfile_default, G_FILE_TEST_EXISTS)) + load_cmdparams_from_file (keyfile_default); + + /* Set gui */ set_gui_from_cmdparams(); /* Enter the main loop */ gtk_widget_show_all (gui.win); gtk_main (); + + g_free(keyfile_default); return 0; } diff --git a/src/keyfile.c b/src/keyfile.c index 8000244..69071fe 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -40,6 +40,7 @@ void load_cmdparams_from_file (const gchar *filename) cmd_params.level = g_key_file_get_string (keyfile, "ncpmount_options", "level", NULL); cmd_params.charset = g_key_file_get_string (keyfile, "ncpmount_options", "charset", NULL); cmd_params.codepage = g_key_file_get_string (keyfile, "ncpmount_options", "codepage", NULL); + cmd_params.extraoptions = g_key_file_get_string (keyfile, "ncpmount_options", "extraoptions", NULL); cmd_params.mount_point = g_key_file_get_string (keyfile, "ncpmount_options", "mount_point", NULL); @@ -144,6 +145,11 @@ void save_cmdparams_to_file (const gchar *filename) g_key_file_set_string (keyfile, "ncpmount_options", "codepage", cmd_params.codepage); } + if(cmd_params.extraoptions != NULL) + { + g_key_file_set_string (keyfile, "ncpmount_options", "extraoptions", cmd_params.extraoptions); + } + if(cmd_params.mount_point != NULL) { g_key_file_set_string (keyfile, "ncpmount_options", "mount_point", cmd_params.mount_point); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..65908b2 --- /dev/null +++ b/src/main.c @@ -0,0 +1,49 @@ +#include +#include + +static void helloWorld (GtkWidget *wid, GtkWidget *win) +{ + GtkWidget *dialog = NULL; + + dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!"); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} + +int main (int argc, char *argv[]) +{ + GtkWidget *button = NULL; + GtkWidget *win = NULL; + GtkWidget *vbox = NULL; + + /* Initialize GTK+ */ + g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL); + gtk_init (&argc, &argv); + g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); + + /* Create the main window */ + win = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width (GTK_CONTAINER (win), 8); + gtk_window_set_title (GTK_WINDOW (win), "Hello World"); + gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER); + gtk_widget_realize (win); + g_signal_connect (win, "destroy", gtk_main_quit, NULL); + + /* Create a vertical box with buttons */ + vbox = gtk_vbox_new (TRUE, 6); + gtk_container_add (GTK_CONTAINER (win), vbox); + + button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO); + g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win); + gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); + + button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + g_signal_connect (button, "clicked", gtk_main_quit, NULL); + gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); + + /* Enter the main loop */ + gtk_widget_show_all (win); + gtk_main (); + return 0; +} diff --git a/src/ncpwrapper.c b/src/ncpwrapper.c index e4de9c6..8cdc2b2 100644 --- a/src/ncpwrapper.c +++ b/src/ncpwrapper.c @@ -196,7 +196,7 @@ void run_ncpmount() /*puts (command);*/ g_free(argv[0]); - argv[0] = g_strdup("/usr/bin/ncpmount"); + argv[0] = g_strdup(NCPMOUNT_PATH); /* gchar *argv[] = {"/usr/bin/ncpmount", "-v", NULL};*/ -- cgit