diff options
Diffstat (limited to 'gncpmount.c')
-rw-r--r-- | gncpmount.c | 99 |
1 files changed, 70 insertions, 29 deletions
diff --git a/gncpmount.c b/gncpmount.c index bd859ba..e508918 100644 --- a/gncpmount.c +++ b/gncpmount.c @@ -8,6 +8,7 @@ #define WIDTH 400 #define HEIGHT -1 + /** * Load savet options to GUI */ @@ -33,6 +34,7 @@ set_gui_from_cmdparams () gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gui.check_n), cmd_params.n); } + /** * Save options set in GUI by user to cmd_params */ @@ -50,6 +52,32 @@ save_gui_to_cmdparams() } +/** +* Check length of all entry and if they are filled enables mount button +*/ +void enable_mount_button () +{ + if (( gtk_entry_get_text_length (GTK_ENTRY(gui.entry_username)) * + gtk_entry_get_text_length (GTK_ENTRY(gui.entry_password)) * + gtk_entry_get_text_length (GTK_ENTRY(gui.entry_server)) * + gtk_entry_get_text_length (GTK_ENTRY(gui.entry_mount_point))) != 0) + { + if(!gui.btn_mount_enable) + { + gui.btn_mount_enable = TRUE; + gtk_widget_set_sensitive (gui.btn_mount, TRUE); + } + } + else + { + if(gui.btn_mount_enable) + { + gui.btn_mount_enable = FALSE; + gtk_widget_set_sensitive (gui.btn_mount, FALSE); + } + } +} + /** * Create Open folder dialog and let user select folder @@ -83,7 +111,6 @@ open_folder (GtkWidget *wid, GtkWidget *win) static void call_ncpmount (GtkWidget *wid, GtkWidget *win) { - /* TODO - kontrola vyplneni udaju */ save_gui_to_cmdparams(); run_ncpmount(); } @@ -120,25 +147,38 @@ passwd_usage (GtkWidget *wid, GtkWidget *win) static void run_options_dialog ( GtkWidget *w, gpointer data ) { - options_dialog(); + show_options_dialog(); } +/** +* Open Show command dialog +*/ +static void +run_command_dialog ( GtkWidget *w, gpointer data ) +{ + save_gui_to_cmdparams(); + show_ncpmount_command(); +} + /** Menu, an array of GtkItemFactoryEntry structures that defines each menu item */ -static GtkItemFactoryEntry menu_items[] = { - { "/_File", NULL, NULL, 0, "<Branch>" }, - { "/File/_New", "<control>N", NULL, 0, "<StockItem>", GTK_STOCK_NEW }, - { "/File/_Load", "<control>L", NULL, 0, "<StockItem>", GTK_STOCK_OPEN }, - { "/File/_Save", "<control>S", NULL, 0, "<StockItem>", GTK_STOCK_SAVE }, - { "/File/sep1", NULL, NULL, 0, "<Separator>" }, - { "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, - { "/Tools", NULL, NULL, 0, "<Branch>" }, - { "/_Tools/Options", "<control>O", run_options_dialog, 0, "<Item>" }, - { "/_Help", NULL, NULL, 0, "<Branch>" }, - { "/_Help/About", NULL, NULL, 0, "<Item>" }, +static GtkItemFactoryEntry menu_items[] = +{ + { "/_File", NULL, NULL, 0, "<Branch>" }, + { "/File/_New", "<control>N", NULL, 0, "<StockItem>", GTK_STOCK_NEW }, + { "/File/_Load", "<control>L", NULL, 0, "<StockItem>", GTK_STOCK_OPEN }, + { "/File/_Save", "<control>S", NULL, 0, "<StockItem>", GTK_STOCK_SAVE }, + { "/File/sep1", NULL, NULL, 0, "<Separator>" }, + { "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, + { "/Tools", NULL, NULL, 0, "<Branch>" }, + { "/_Tools/Options", "<control>O", run_options_dialog, 0, "<Item>" }, + { "/_Tools/Show command", NULL, run_command_dialog, 0, "<Item>" }, + { "/_Help", NULL, NULL, 0, "<Branch>" }, + { "/_Help/About", NULL, NULL, 0, "<Item>" }, }; + /** Menu items count */ static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); @@ -149,30 +189,22 @@ static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); static GtkWidget * get_menubar_menu( GtkWidget *window ) { - GtkItemFactory *item_factory; - GtkAccelGroup *accel_group; + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group; - /* Make an accelerator group (shortcut keys) */ - accel_group = gtk_accel_group_new (); + accel_group = gtk_accel_group_new (); - /* Make an ItemFactory (that makes a menubar) */ - item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", - accel_group); + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", + accel_group); - /* This function generates the menu items. Pass the item factory, - the number of items in the array, the array itself, and any - callback data for the the menu items. */ - gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); - /* Attach the new accelerator group to the window. */ - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); - /* Finally, return the actual menu bar created by the item factory. */ - return gtk_item_factory_get_widget (item_factory, "<main>"); + return gtk_item_factory_get_widget (item_factory, "<main>"); } - int main (int argc, char *argv[]) { GtkWidget *label = NULL; @@ -237,6 +269,7 @@ int main (int argc, char *argv[]) gui.entry_username = gtk_entry_new (); + g_signal_connect (G_OBJECT (gui.entry_username), "changed", G_CALLBACK (enable_mount_button), NULL); gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_username, 1, 2, 0, 1); halign = gtk_alignment_new(0, 0, 0, 1); @@ -247,6 +280,7 @@ int main (int argc, char *argv[]) gui.entry_password = gtk_entry_new (); gtk_entry_set_visibility (GTK_ENTRY(gui.entry_password), FALSE); + g_signal_connect (G_OBJECT (gui.entry_password), "changed", G_CALLBACK (enable_mount_button), NULL); gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_password, 1, 2, 1, 2); /* Chcekbox */ @@ -270,6 +304,7 @@ int main (int argc, char *argv[]) hbox = gtk_hbox_new (FALSE, 2); gtk_table_attach_defaults (GTK_TABLE (gui.table), hbox, 1, 2, 0, 1); gui.entry_mount_point = gtk_entry_new (); + g_signal_connect (G_OBJECT (gui.entry_mount_point), "changed", G_CALLBACK (enable_mount_button), NULL); gtk_container_add(GTK_CONTAINER(hbox), gui.entry_mount_point); gui.btn_browse = gtk_button_new_with_label ("Browse"); @@ -286,6 +321,7 @@ int main (int argc, char *argv[]) gtk_table_attach(GTK_TABLE(gui.table), halign, 0, 1, 2, 3, GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0); gui.entry_server = gtk_entry_new (); + g_signal_connect (G_OBJECT (gui.entry_server), "changed", G_CALLBACK (enable_mount_button), NULL); gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_server, 1, 2, 2, 3); @@ -295,6 +331,7 @@ int main (int argc, char *argv[]) gtk_table_attach(GTK_TABLE(gui.table), halign, 0, 1, 3, 4, GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0); gui.entry_dns_server = gtk_entry_new (); + g_signal_connect (G_OBJECT (gui.entry_dns_server), "changed", G_CALLBACK (enable_mount_button), NULL); gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_dns_server, 1, 2, 3, 4); @@ -309,6 +346,10 @@ int main (int argc, char *argv[]) g_signal_connect (gui.btn_mount, "clicked", G_CALLBACK(call_ncpmount), NULL); gtk_box_pack_start (GTK_BOX (gui.btnbox), gui.btn_mount, TRUE, TRUE, 0); + + gui.btn_mount_enable = FALSE; + gtk_widget_set_sensitive (gui.btn_mount, FALSE); + gui.btn_close = gtk_button_new_from_stock (GTK_STOCK_CLOSE); g_signal_connect (gui.btn_close, "clicked", gtk_main_quit, NULL); gtk_box_pack_start (GTK_BOX (gui.btnbox), gui.btn_close, TRUE, TRUE, 0); |