summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Lipovský <janlipovsky@gmail.com>2010-12-29 17:56:04 +0100
committerJan Lipovský <janlipovsky@gmail.com>2010-12-29 17:56:04 +0100
commit385f6377ca4f0be4cf4a5b493e8d13995534b5be (patch)
treed0155c60b8e10f8161b84398496d3fac25e5d47c
downloadgncpmount-385f6377ca4f0be4cf4a5b493e8d13995534b5be.tar.gz
gncpmount-385f6377ca4f0be4cf4a5b493e8d13995534b5be.tar.xz
gncpmount-385f6377ca4f0be4cf4a5b493e8d13995534b5be.zip
GUI with Options dialog
-rw-r--r--dialogs.c333
-rw-r--r--dialogs.h11
-rw-r--r--globals.c27
-rw-r--r--globals.h123
-rw-r--r--gncpmount.c312
5 files changed, 806 insertions, 0 deletions
diff --git a/dialogs.c b/dialogs.c
new file mode 100644
index 0000000..2f75057
--- /dev/null
+++ b/dialogs.c
@@ -0,0 +1,333 @@
+#include <gtk/gtk.h>
+#include "dialogs.h"
+
+typedef enum lvl
+{
+ NOT_USED = 0,
+ NEVER,
+ SUPPORTED,
+ PREFERED,
+ REQUIRED
+} TLevel;
+
+gchar *sig_level_texts[] =
+{
+ "Do not use signature level",
+ "Level 0 - never",
+ "Level 1 - supported",
+ "Level 2 - prefered",
+ "Level 3 - required"
+};
+
+
+void save_options_to_cmdparams()
+{
+ gint tmp;
+ set_parameter_text ((options.entry_charset), &cmd_params.charset);
+ set_parameter_text ((options.entry_codepage), &cmd_params.codepage);
+ set_parameter_text ((options.entry_dmode), &cmd_params.dmode);
+ set_parameter_text ((options.entry_fmode), &cmd_params.fmode);
+ set_parameter_text ((options.entry_gid), &cmd_params.gid);
+ set_parameter_text ((options.entry_retrycount), &cmd_params.retry_count);
+ 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);
+
+ /* Checkboxes */
+ set_parameter_bool ((options.check_b), &cmd_params.b);
+ set_parameter_bool ((options.check_C), &cmd_params.C);
+ set_parameter_bool ((options.check_m), &cmd_params.m);
+ set_parameter_bool ((options.check_s), &cmd_params.s);
+
+ tmp = gtk_combo_box_get_active (GTK_COMBO_BOX (options.combo_signature));
+ /* ComboBox */
+ switch(tmp)
+ {
+ case NEVER:
+ g_free(cmd_params.level);
+ cmd_params.level = g_strdup("0");
+ break;
+ case SUPPORTED:
+ g_free(cmd_params.level);
+ cmd_params.level = g_strdup("1");
+ break;
+ case PREFERED:
+ g_free(cmd_params.level);
+ cmd_params.level = g_strdup("2");
+ break;
+ case REQUIRED:
+ g_free(cmd_params.level);
+ cmd_params.level = g_strdup("3");
+ break;
+ default:
+ if(cmd_params.level != NULL)
+ {
+ g_free(cmd_params.level);
+ cmd_params.level = NULL;
+ }
+ break;
+ }
+}
+
+static void
+set_options_from_cmdparams ()
+{
+
+ if(cmd_params.charset != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_charset), cmd_params.charset);
+
+ if(cmd_params.codepage != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_codepage), cmd_params.codepage);
+
+ if(cmd_params.dmode != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_dmode), cmd_params.dmode);
+
+ if(cmd_params.fmode != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_fmode), cmd_params.fmode);
+
+ if(cmd_params.gid != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_gid), cmd_params.gid);
+
+ if(cmd_params.retry_count != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_retrycount), cmd_params.retry_count);
+
+ if(cmd_params.time_out != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_timeout), cmd_params.time_out);
+
+ if(cmd_params.uid != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_uid), cmd_params.uid);
+
+ if(cmd_params.volume != NULL)
+ gtk_entry_set_text(GTK_ENTRY(options.entry_volume), cmd_params.volume);
+
+
+ /* Checkboxes */
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options.check_b), cmd_params.b);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options.check_C), cmd_params.C);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options.check_m), cmd_params.m);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options.check_s), cmd_params.s);
+
+ /* ComboBox */
+ if(cmd_params.level != NULL)
+ {
+ if(cmd_params.level[0] == '0')
+ gtk_combo_box_set_active (GTK_COMBO_BOX (options.combo_signature), 1);
+ else if(cmd_params.level[0] == '1')
+ gtk_combo_box_set_active (GTK_COMBO_BOX (options.combo_signature), 2);
+ else if(cmd_params.level[0] == '2')
+ gtk_combo_box_set_active (GTK_COMBO_BOX (options.combo_signature), 3);
+ else if(cmd_params.level[0] == '3')
+ gtk_combo_box_set_active (GTK_COMBO_BOX (options.combo_signature), 4);
+ }
+ else
+ gtk_combo_box_set_active (GTK_COMBO_BOX (options.combo_signature), 0);
+}
+
+
+
+
+/* Function to open a dialog box displaying the message provided. */
+void options_dialog ()
+{
+ GtkWidget *label, *content_area, *halign, *hsep, *table;
+ gint result, row;
+ row = 0;
+
+ /* Create the widgets */
+ options.dialog = gtk_dialog_new_with_buttons ("Options",
+ GTK_WINDOW (gui.win),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (options.dialog));
+
+
+ /* Page OTIONS */
+ table = gtk_table_new (21, 2, FALSE);
+ gtk_container_add (GTK_CONTAINER (content_area), table);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), "<span weight=\"bold\"><big>Set ncpmount options:</big></span>");
+ gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row+1, GTK_FILL , GTK_FILL | GTK_EXPAND, 6, 0);
+ 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++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Codepage [-p]:");
+ 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_codepage = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_codepage, 1, 2, row, row+1);
+ row++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Charset [-y]:");
+ 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_charset = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_charset, 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++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Signature level [-i]:");
+ 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.combo_signature = gtk_combo_box_new_text();
+ gtk_combo_box_append_text(GTK_COMBO_BOX(options.combo_signature), sig_level_texts[NOT_USED]);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(options.combo_signature), sig_level_texts[NEVER]);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(options.combo_signature), sig_level_texts[SUPPORTED]);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(options.combo_signature), sig_level_texts[PREFERED]);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(options.combo_signature), sig_level_texts[REQUIRED]);
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(options.combo_signature), 0);
+ gtk_table_attach_defaults (GTK_TABLE (table), options.combo_signature, 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++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Volume to mount [-V]:");
+ 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_volume = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_volume, 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++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Mounted files uid [-u]:");
+ 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_uid = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_uid , 1, 2, row, row+1);
+ row++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Mounted files gid [-g]:");
+ 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_gid = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_gid , 1, 2, row, row+1);
+ row++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Files permission [-f]:");
+ 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_fmode = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_fmode , 1, 2, row, row+1);
+ row++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Dirs permission [-d]:");
+ 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_dmode = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_dmode , 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++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Timeout [-t]:");
+ 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_timeout = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_timeout , 1, 2, row, row+1);
+ row++;
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Retry count [-r]:");
+ 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_retrycount = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (table), options.entry_retrycount , 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++;
+
+ options.check_C = gtk_check_button_new_with_label ("Don't convet password to uppercase [-C]");
+ /*g_signal_connect (G_OBJECT (chbox), "toggled", G_CALLBACK (passwd_uppercase), (gpointer) chbox);*/
+ gtk_table_attach_defaults (GTK_TABLE (table), options.check_C, 0, 2, row, row+1);
+ row++;
+
+ options.check_m = gtk_check_button_new_with_label ("Allow multiple logins to server [-m]");
+ /*g_signal_connect (G_OBJECT (chbox), "toggled", G_CALLBACK (passwd_uppercase), (gpointer) chbox);*/
+ gtk_table_attach_defaults (GTK_TABLE (table), options.check_m, 0, 2, row, row+1);
+ row++;
+
+ options.check_s = gtk_check_button_new_with_label ("Enable renaming/deletion of read-only files [-s]");
+ /*g_signal_connect (G_OBJECT (chbox), "toggled", G_CALLBACK (passwd_uppercase), (gpointer) chbox);*/
+ gtk_table_attach_defaults (GTK_TABLE (table), options.check_s, 0, 2, row, row+1);
+ row++;
+
+ options.check_b = gtk_check_button_new_with_label ("Force bindery login to NDS servers [-b]");
+ /*g_signal_connect (G_OBJECT (chbox), "toggled", G_CALLBACK (passwd_uppercase), (gpointer) chbox);*/
+ gtk_table_attach_defaults (GTK_TABLE (table), options.check_b, 0, 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++;
+
+
+
+ set_options_from_cmdparams();
+
+ gtk_widget_show_all (table);
+ result = gtk_dialog_run (GTK_DIALOG(options.dialog));
+ if(result == GTK_RESPONSE_OK)
+ {
+ save_options_to_cmdparams();
+ }
+
+ gtk_widget_destroy (options.dialog);
+}
+
+
+
+#if 0
+
+static void passwd_uppercase (GtkWidget *wid, GtkWidget *win)
+{
+ /* Nastavit -C parametr */
+}
+
+
+
+
+#endif
diff --git a/dialogs.h b/dialogs.h
new file mode 100644
index 0000000..e7543cf
--- /dev/null
+++ b/dialogs.h
@@ -0,0 +1,11 @@
+#ifndef GNCPMOUNT_DIALOGS_H
+#define GNCPMOUNT_DIALOGS_H
+
+#include "globals.h"
+
+/** Shows options dialog */
+void options_dialog ();
+
+
+#endif
+
diff --git a/globals.c b/globals.c
new file mode 100644
index 0000000..cbe5897
--- /dev/null
+++ b/globals.c
@@ -0,0 +1,27 @@
+#include <gtk/gtk.h>
+
+#include "globals.h"
+
+
+void set_parameter_text (GtkWidget *entry, gchar **param)
+{
+ gchar *tmp;
+
+ tmp = g_strdup(gtk_entry_get_text (GTK_ENTRY(entry)));
+
+ g_strstrip(tmp);
+
+ g_free(*param);
+ *param = g_strdup(tmp);
+
+ g_free(tmp);
+}
+
+/**
+* Boolean value in given parameter
+*/
+void set_parameter_bool (GtkWidget *checkbox, gboolean *param)
+{
+ *param = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
+}
+
diff --git a/globals.h b/globals.h
new file mode 100644
index 0000000..95e48d8
--- /dev/null
+++ b/globals.h
@@ -0,0 +1,123 @@
+#ifndef GNCPMOUNT_GLOBALS_H
+#define GNCPMOUNT_GLOBALS_H
+
+#define PROG_VERSION 0.1.2
+#define GUI_TITLE "gncpmount - 0.1.2"
+
+
+/**
+* Define type TWindow - structure of important widgets in gui
+*/
+typedef struct gui_struct
+{
+ GtkWidget *win;
+ GtkWidget *menu;
+ GtkWidget *vbox;
+ GtkWidget *table;
+
+ GtkWidget *check_n;
+
+ GtkWidget *btnbox;
+
+ GtkWidget *notebook;
+
+ /* Buttons */
+ GtkWidget *btn_close;
+ GtkWidget *btn_mount;
+ GtkWidget *btn_browse;
+
+ /* Entry */
+ GtkWidget *entry_username;
+ GtkWidget *entry_password;
+ GtkWidget *entry_server;
+ GtkWidget *entry_mount_point;
+ GtkWidget *entry_dns_server;
+} TWindow;
+
+/** Structure of widgets used in GUI */
+TWindow gui;
+
+
+/**
+* Define type TWindow - structure of important widgets in gui
+*/
+typedef struct opt_struct
+{
+ GtkWidget *dialog;
+
+ /* Entry */
+ GtkWidget *entry_codepage;
+ GtkWidget *entry_charset;
+ GtkWidget *entry_volume;
+ GtkWidget *entry_uid;
+ GtkWidget *entry_gid;
+ GtkWidget *entry_fmode;
+ GtkWidget *entry_dmode;
+ GtkWidget *entry_timeout;
+ GtkWidget *entry_retrycount;
+
+ /* ComboBox */
+ GtkWidget *combo_signature;
+
+ /* Check box */
+ GtkWidget *check_C;
+ GtkWidget *check_s;
+ GtkWidget *check_m;
+ GtkWidget *check_b;
+}TODialog;
+
+/** Structure of widgets used in GUI - Optionns dialog */
+TODialog options;
+
+
+
+/**
+* Parameters which are appent to the ncpmount command
+*/
+typedef struct params
+{
+ gchar *username; /* user name sent to server */
+ gchar *password; /* use this password */
+ gchar *server; /* server name to be used */
+ gchar *dns_name; /* DNS server name to be used when mounting over TCP or UDP */
+ gchar *mount_point; /* mount point directory */
+
+ gchar *volume; /* Volume to mount, for NFS re-eport */
+ gchar *uid; /* uid the mounted files get */
+ gchar *gid; /* gid the mounted files get */
+ gchar *fmode; /* permission the files get (octal notation) */
+ gchar *dmode; /* permission the dirs get (octal notation) */
+ gchar *time_out; /* waiting time (in 1/100s) to wait for an answer from the server. Default: 60 */
+ gchar *retry_count; /* number of retry attempts. Default: 5 */
+ gchar *level; /* signature level */
+ gchar *charset; /* charset used for input and display */
+ gchar *codepage; /* codepage used on volume, including letters 'cp' */
+
+ /*gchar *cuid; */ /* uid to identify the connection to mount on - Only makes sense for root */
+
+ gboolean C; /* don't convert password to uppercase */
+ gboolean n; /* do not use any password */
+ gboolean s; /* enable renaming/deletion of read-only files */
+ gboolean b; /* force bindery login to NDS servers */
+ gboolean m; /* allow multiple logins to server */
+
+} TParameters;
+
+
+TParameters cmd_params;
+
+
+/** Sets given parameter whith given value */
+/*void init_parameters (const gchar *value, gchar **param);*/
+
+/** Sets given parameter whith given value */
+void set_parameter_text (GtkWidget *entry, gchar **param);
+
+
+/** Sets given parameter whith given value */
+void set_parameter_bool (GtkWidget *checkbox, gboolean *param);
+
+
+
+
+#endif
diff --git a/gncpmount.c b/gncpmount.c
new file mode 100644
index 0000000..2a61dae
--- /dev/null
+++ b/gncpmount.c
@@ -0,0 +1,312 @@
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+#include "dialogs.h"
+#include "globals.h"
+
+#define WIDTH 400
+#define HEIGHT -1
+
+
+
+
+/**
+* Show info, error or warning message
+*/
+void
+show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new ( GTK_WINDOW (gui.win),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ type,
+ GTK_BUTTONS_OK,
+ format,
+ msgtxt);
+
+ gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG (dialog),
+ format_sec,
+ msgtxt_sec);
+ gtk_dialog_run ( GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+
+/**
+* Create Open folder dialog and let user select folder
+* for mount point
+*/
+static void
+open_folder (GtkWidget *wid, GtkWidget *win)
+{
+ GtkWidget *dialog;
+ dialog = gtk_file_chooser_dialog_new ("Select folder - mount point",
+ GTK_WINDOW (gui.win),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ char *folder;
+ folder = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ gtk_entry_set_text (GTK_ENTRY (gui.entry_mount_point), folder);
+ g_free (folder);
+ }
+ gtk_widget_destroy (dialog);
+
+}
+
+
+
+static void
+passwd_usage (GtkWidget *wid, GtkWidget *win)
+{
+ cmd_params.n = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gui.check_n));
+
+ gtk_entry_set_editable (GTK_ENTRY(gui.entry_password), !cmd_params.n);
+
+ if(cmd_params.n)
+ {
+ gtk_entry_set_visibility (GTK_ENTRY(gui.entry_password), TRUE);
+ set_parameter_text (gui.entry_password, &(cmd_params.password));
+ gtk_entry_set_text (GTK_ENTRY(gui.entry_password), "no password will be used");
+ }
+ else
+ {
+ gtk_entry_set_visibility (GTK_ENTRY(gui.entry_password), FALSE);
+ if(cmd_params.password != NULL)
+ gtk_entry_set_text (GTK_ENTRY(gui.entry_password), cmd_params.password);
+ }
+}
+
+
+
+static void
+run_options_dialog ( GtkWidget *w, gpointer data )
+{
+ options_dialog(&gui);
+}
+
+
+static void
+set_gui_from_cmdparams ()
+{
+
+ if(cmd_params.username != NULL)
+ gtk_entry_set_text(GTK_ENTRY(gui.entry_username), cmd_params.username);
+
+ if(cmd_params.password != NULL)
+ gtk_entry_set_text(GTK_ENTRY(gui.entry_password), cmd_params.password);
+
+ if(cmd_params.server != NULL)
+ gtk_entry_set_text(GTK_ENTRY(gui.entry_server), cmd_params.server);
+
+ if(cmd_params.dns_name != NULL)
+ gtk_entry_set_text(GTK_ENTRY(gui.entry_dns_server), cmd_params.dns_name);
+
+ if(cmd_params.mount_point != NULL)
+ gtk_entry_set_text(GTK_ENTRY(gui.entry_mount_point), cmd_params.mount_point);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gui.check_n), cmd_params.n);
+}
+
+
+
+
+/* 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 gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
+
+
+/* Returns a menubar widget made from the above menu */
+static GtkWidget *
+get_menubar_menu( GtkWidget *window )
+{
+ GtkItemFactory *item_factory;
+ GtkAccelGroup *accel_group;
+
+ /* Make an accelerator group (shortcut keys) */
+ 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);
+
+ /* 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);
+
+ /* Attach the new accelerator group to the window. */
+ 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>");
+}
+
+
+
+int main (int argc, char *argv[])
+{
+ GtkWidget *label = NULL;
+ GtkWidget *tmp = NULL;
+ GtkWidget *hbox = NULL;
+
+ GtkWidget *halign = NULL;
+
+ GtkWidget *logo = 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 */
+ gui.win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (gui.win), GUI_TITLE );
+ gtk_window_set_position (GTK_WINDOW (gui.win), GTK_WIN_POS_CENTER);
+ gtk_window_set_default_size (GTK_WINDOW (gui.win), WIDTH, HEIGHT);
+ gtk_window_set_resizable (GTK_WINDOW (gui.win), FALSE);
+
+ gtk_widget_realize (gui.win);
+ g_signal_connect (gui.win, "destroy", gtk_main_quit, NULL);
+
+
+ tmp = gtk_vbox_new (FALSE, 1);
+ gtk_container_add (GTK_CONTAINER (gui.win), tmp);
+
+ gui.menu = get_menubar_menu (gui.win);
+ gtk_box_pack_start (GTK_BOX (tmp), gui.menu, FALSE, TRUE, 0);
+
+ /* Create a vertical box */
+ gui.vbox = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (tmp), gui.vbox, FALSE, TRUE, 0);
+
+ gtk_container_set_border_width (GTK_CONTAINER (gui.vbox), 10);
+
+ logo = gtk_image_new_from_file("gncpmount.png");
+ gtk_box_pack_start (GTK_BOX (gui.vbox), logo, TRUE, TRUE, 0);
+
+ /* Create a notebook */
+ gui.notebook = gtk_notebook_new ();
+ gtk_notebook_set_tab_pos (GTK_NOTEBOOK (gui.notebook), GTK_POS_TOP);
+ gtk_box_pack_start (GTK_BOX (gui.vbox), gui.notebook, TRUE, TRUE, 0);
+ gtk_widget_set_size_request(gui.notebook, WIDTH,-1);
+
+
+ /* Page Login */
+
+ /* Create table */
+ gui.table = gtk_table_new (3, 2, FALSE);
+ label = gtk_label_new ("Login");
+ gtk_notebook_prepend_page (GTK_NOTEBOOK (gui.notebook), gui.table, label);
+
+ /* Labels */
+ halign = gtk_alignment_new(0, 0, 0, 1);
+
+ label = gtk_label_new ("Username [-U]:");
+ gtk_container_add(GTK_CONTAINER(halign), label);
+ gtk_table_attach(GTK_TABLE(gui.table), halign, 0, 1, 0, 1, GTK_FILL , GTK_FILL | GTK_EXPAND, 4, 0);
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Password [-P]:");
+ gtk_container_add(GTK_CONTAINER(halign), label);
+ gtk_table_attach(GTK_TABLE(gui.table), halign, 0, 1, 1, 2, GTK_FILL, GTK_FILL | GTK_EXPAND, 4, 0);
+
+ /* Chcekbox */
+ gui.check_n = gtk_check_button_new_with_label ("Do not use any password [-n]");
+ g_signal_connect (G_OBJECT (gui.check_n), "toggled", G_CALLBACK (passwd_usage), NULL);
+ gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.check_n, 1, 2, 2, 3);
+
+
+ /* Entry */
+ gui.entry_username = gtk_entry_new ();
+ gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_username, 1, 2, 0, 1);
+
+ gui.entry_password = gtk_entry_new ();
+ gtk_entry_set_visibility (GTK_ENTRY(gui.entry_password), FALSE);
+ gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_password, 1, 2, 1, 2);
+
+
+
+ /* Page SERVER */
+ gui.table = gtk_table_new (4, 2, FALSE);
+
+ label = gtk_label_new ("Server");
+ gtk_notebook_append_page (GTK_NOTEBOOK (gui.notebook), gui.table, label);
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Mount point:");
+ gtk_container_add(GTK_CONTAINER(halign), label);
+ gtk_table_attach(GTK_TABLE(gui.table), halign, 0, 1, 0, 1, GTK_FILL , GTK_FILL | GTK_EXPAND, 6, 0);
+
+ 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 ();
+ gtk_container_add(GTK_CONTAINER(hbox), gui.entry_mount_point);
+
+ gui.btn_browse = gtk_button_new_with_label ("Browse");
+ g_signal_connect (gui.btn_browse, "clicked", G_CALLBACK (open_folder), NULL);
+ gtk_container_add(GTK_CONTAINER(hbox), gui.btn_browse);
+
+ tmp = gtk_hseparator_new();
+ gtk_table_attach (GTK_TABLE(gui.table), tmp, 0, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 6, 6);
+
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("Server [-S]:");
+ gtk_container_add(GTK_CONTAINER(halign), label);
+ 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 ();
+ gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_server, 1, 2, 2, 3);
+
+
+ halign = gtk_alignment_new(0, 0, 0, 1);
+ label = gtk_label_new ("DNS name [-A]:");
+ gtk_container_add(GTK_CONTAINER(halign), label);
+ 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 ();
+ gtk_table_attach_defaults (GTK_TABLE (gui.table), gui.entry_dns_server, 1, 2, 3, 4);
+
+
+
+ /* Button box */
+ gui.btnbox = gtk_hbutton_box_new();
+ gtk_hbutton_box_set_layout_default(GTK_BUTTONBOX_END);
+ gtk_box_pack_start (GTK_BOX (gui.vbox), gui.btnbox, TRUE, TRUE, 0);
+
+ /* Buttons */
+ gui.btn_mount = gtk_button_new_with_label ("Mount");
+ g_signal_connect (gui.btn_mount, "clicked", gtk_main_quit, NULL);
+ gtk_box_pack_start (GTK_BOX (gui.btnbox), gui.btn_mount, TRUE, TRUE, 0);
+
+ 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);
+
+
+ /* Fill in informations from cmd_params to wiidgets */
+ set_gui_from_cmdparams();
+
+ /* Enter the main loop */
+ gtk_widget_show_all (gui.win);
+ gtk_main ();
+ return 0;
+}