Separating GUI from VFS



Hello!

I'm applying a patch that moves the dialog for requesting SMB credentials
from vfs/smbfs.c to src/boxes.c and gnome/gdialogs.c.

The interface that has to be exposed goes to vfs/vfs.h.  The
function and the structure it uses are renamed so that they have
less generic names.

The new code in src/boxes.c is an exact copy of the old code from
vfs/smbfs.c.  The new code in gnome/gdialogs.c is a new implementation
using a native GNOME dialog instead of MC dialog.  This was the last user
of the glue code using deprecated GtkTed!

ChangeLog:
	* gnome/gdialogs.c [WITH_SMBFS] (vfs_smb_get_authinfo): New
	function implementing SMB password dialog.
        * src/boxes.c [WITH_SMBFS] (vfs_smb_get_authinfo): Copied from
        vfs/smbfs.c, function authinfo_get_authinfo_from_user().
	* vfs/smbfs.c: Rename authinfo to smb_authinfo and
	authinfo_get_authinfo_from_user() to vfs_smb_get_authinfo()
	and remove their definitions.
	* vfs/vfs.h: Declare smb_authinfo and vfs_smb_get_authinfo().

-- 
Regards,
Pavel Roskin


----------------------------------------------------
--- gnome/gdialogs.c
+++ gnome/gdialogs.c
@@ -2,7 +2,7 @@
 /* New dialogs... */
 #include <config.h>
 #include "panel.h"
-#include <gnome.h>
+#include "x.h"
 #include "dialog.h"
 #include "global.h"
 #include "file.h"
@@ -1100,3 +1100,101 @@ symlink_dialog (char *existing, char *ne
         if (ret != -1)
                 gtk_widget_destroy (dialog);
 }
+
+#ifdef WITH_SMBFS
+struct smb_authinfo *
+vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
+		      const char *user)
+{
+	struct smb_authinfo *return_value;
+	GtkWidget *smbauth_dialog;
+	GtkWidget *domain_entry, *user_entry, *passwd_entry;
+	GtkWidget *domain_label, *user_label, *passwd_label;
+
+	char *title;
+	static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password: ")};
+
+	if (!domain)
+	    domain = "";
+	if (!user)
+	    user = "";
+
+	title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
+
+	/* Create dialog */
+	smbauth_dialog =
+	    gnome_dialog_new(title, GNOME_STOCK_BUTTON_OK,
+			     GNOME_STOCK_BUTTON_CANCEL, NULL);
+	g_free (title);
+	gmc_window_setup_from_panel(GNOME_DIALOG(smbauth_dialog), cpanel);
+
+	domain_label = gtk_label_new(_(labs[0]));
+	gtk_misc_set_alignment(GTK_MISC(domain_label), 0.0, 0.5);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), domain_label, FALSE,
+			   FALSE, 0);
+
+	domain_entry = gnome_entry_new("domain");
+	gnome_entry_load_history(GNOME_ENTRY(domain_entry));
+	gtk_entry_set_text(GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(domain_entry))),
+			   domain);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), domain_entry, FALSE,
+			   FALSE, 0);
+
+	user_label = gtk_label_new(_(labs[1]));
+	gtk_misc_set_alignment(GTK_MISC(user_label), 0.0, 0.5);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), user_label, FALSE,
+			   FALSE, 0);
+
+	user_entry = gnome_entry_new("user");
+	gnome_entry_load_history(GNOME_ENTRY(user_entry));
+	gtk_entry_set_text(GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(user_entry))),
+			   user);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), user_entry, FALSE,
+			   FALSE, 0);
+
+	passwd_label = gtk_label_new(_(labs[2]));
+	gtk_misc_set_alignment(GTK_MISC(passwd_label), 0.0, 0.5);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), passwd_label, FALSE,
+			   FALSE, 0);
+
+	passwd_entry = gtk_entry_new();
+	gtk_entry_set_text(GTK_ENTRY(passwd_entry), "");
+	gtk_entry_set_visibility(GTK_ENTRY(passwd_entry), FALSE);
+	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(smbauth_dialog)->vbox), passwd_entry, FALSE,
+			   FALSE, 0);
+
+	gtk_widget_grab_focus(passwd_entry);
+	gnome_dialog_set_default(GNOME_DIALOG(smbauth_dialog), 0);
+
+	gtk_widget_show_all(GNOME_DIALOG(smbauth_dialog)->vbox);
+
+	switch (gnome_dialog_run(GNOME_DIALOG(smbauth_dialog))) {
+	case 0:
+		return_value = g_new (struct smb_authinfo, 1);
+		if (!return_value)
+			break;
+
+		return_value->host = g_strdup (host);
+		return_value->share = g_strdup (share);
+		return_value->domain =
+			g_strdup(gtk_entry_get_text
+				 (GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(domain_entry)))));
+		return_value->user =
+			g_strdup(gtk_entry_get_text
+				 (GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(user_entry)))));
+		return_value->password = g_strdup(gtk_entry_get_text(GTK_ENTRY(passwd_entry)));
+		break;
+
+	case 1:
+		return_value = 0;
+		break;
+
+	default:
+		return 0;
+	}
+
+	gtk_widget_destroy(smbauth_dialog);
+
+	return return_value;
+}
+#endif /* WITH_SMBFS */
--- src/boxes.c
+++ src/boxes.c
@@ -54,6 +54,10 @@
 #include "selcodepage.h"
 #endif

+#ifdef WITH_SMBFS
+#include "../vfs/vfs.h"		/* smb_authinfo */
+#endif /* WITH_SMBFS */
+
 static int DISPLAY_X = 45, DISPLAY_Y = 14;

 static Dlg_head *dd;
@@ -1038,4 +1042,113 @@ jobs_cmd (void)

     destroy_dlg (jobs_dlg);
 }
-#endif
+#endif /* WITH_BACKGROUND */
+
+#ifdef WITH_SMBFS
+struct smb_authinfo *
+vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
+		      const char *user)
+{
+    static int dialog_x = 44;
+    int dialog_y = 12;
+    struct smb_authinfo *return_value;
+    static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password: ")};
+    static char* buts[] = {N_("&Ok"), N_("&Cancel")};
+    static int ilen = 30, istart = 14;
+    static int b0 = 3, b2 = 30;
+    char *title;
+    WInput *in_password;
+    WInput *in_user;
+    WInput *in_domain;
+    Dlg_head *auth_dlg;
+
+#ifdef ENABLE_NLS
+    static int i18n_flag = 0;
+
+    if (!i18n_flag)
+    {
+        register int i = sizeof(labs)/sizeof(labs[0]);
+        int l1, maxlen = 0;
+
+        while (i--)
+        {
+            l1 = strlen (labs [i] = _(labs [i]));
+            if (l1 > maxlen)
+                maxlen = l1;
+        }
+        i = maxlen + ilen + 7;
+        if (i > dialog_x)
+            dialog_x = i;
+
+        for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
+        {
+            l1 += strlen (buts [i] = _(buts [i]));
+        }
+        l1 += 15;
+        if (l1 > dialog_x)
+            dialog_x = l1;
+
+        ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
+        istart = dialog_x - 3 - ilen;
+
+        b2 = dialog_x - (strlen(buts[1]) + 6);
+
+        i18n_flag = 1;
+    }
+
+#endif /* ENABLE_NLS */
+
+    if (!domain)
+    domain = "";
+    if (!user)
+    user = "";
+
+    auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors,
+                       common_dialog_callback, "[Smb Authinfo]", "smbauthinfo",
+                       DLG_CENTER | DLG_GRID);
+
+    title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
+    x_set_dialog_title (auth_dlg, title);
+    g_free (title);
+
+    in_user  = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
+    add_widget (auth_dlg, in_user);
+
+    in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
+    add_widget (auth_dlg, in_domain);
+    add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
+                 buts[1], 0 ,0, "cancel"));
+    add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
+                 buts[0], 0, 0, "ok"));
+
+    in_password  = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
+    in_password->completion_flags = 0;
+    in_password->is_password = 1;
+    add_widget (auth_dlg, in_password);
+
+    add_widget (auth_dlg, label_new (7, 3, labs[2], "label-passwd"));
+    add_widget (auth_dlg, label_new (5, 3, labs[1], "label-user"));
+    add_widget (auth_dlg, label_new (3, 3, labs[0], "label-domain"));
+
+    run_dlg (auth_dlg);
+
+    switch (auth_dlg->ret_value) {
+    case B_CANCEL:
+        return_value = 0;
+        break;
+    default:
+        return_value = g_new (struct smb_authinfo, 1);
+        if (return_value) {
+            return_value->host = g_strdup (host);
+            return_value->share = g_strdup (share);
+            return_value->domain = g_strdup (in_domain->buffer);
+            return_value->user = g_strdup (in_user->buffer);
+            return_value->password = g_strdup (in_password->buffer);
+        }
+    }
+
+    destroy_dlg (auth_dlg);
+
+    return return_value;
+}
+#endif /* WITH_SMBFS */
--- vfs/smbfs.c
+++ vfs/smbfs.c
@@ -40,9 +40,6 @@
 #include "smbfs.h"
 #include "tcputil.h"
 #include "../src/dialog.h"
-#include "../src/widget.h"
-#include "../src/color.h"
-#include "../src/wtools.h"

 #define SMBFS_MAX_CONNECTIONS 16
 static const char * const IPC = "IPC$";
@@ -89,128 +86,10 @@ typedef struct {
 	uint16 attr;
 } smbfs_handle;

-struct authinfo {
-    char *host;
-    char *share;
-    char *domain;
-    char *user;
-    char *password;
-/*	struct timeval timestamp;*/
-};
-
 static GSList *auth_list;

-static struct authinfo *
-authinfo_get_authinfo_from_user (const char *host,
-                                 const char *share,
-                                 const char *domain,
-                                 const char *user)
-{
-    static int dialog_x = 44;
-    int dialog_y = 12;
-    struct authinfo *return_value;
-    static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password: ")};
-    static char* buts[] = {N_("&Ok"), N_("&Cancel")};
-    static int ilen = 30, istart = 14;
-    static int b0 = 3, b2 = 30;
-    char *title;
-    WInput *in_password;
-    WInput *in_user;
-    WInput *in_domain;
-    Dlg_head *auth_dlg;
-
-#ifdef ENABLE_NLS
-    static int i18n_flag = 0;
-
-    if (!i18n_flag)
-    {
-        register int i = sizeof(labs)/sizeof(labs[0]);
-        int l1, maxlen = 0;
-
-        while (i--)
-        {
-            l1 = strlen (labs [i] = _(labs [i]));
-            if (l1 > maxlen)
-                maxlen = l1;
-        }
-        i = maxlen + ilen + 7;
-        if (i > dialog_x)
-            dialog_x = i;
-
-        for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
-        {
-            l1 += strlen (buts [i] = _(buts [i]));
-        }
-        l1 += 15;
-        if (l1 > dialog_x)
-            dialog_x = l1;
-
-        ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
-        istart = dialog_x - 3 - ilen;
-
-        b2 = dialog_x - (strlen(buts[1]) + 6);
-
-        i18n_flag = 1;
-    }
-
-#endif /* ENABLE_NLS */
-
-    if (!domain)
-    domain = "";
-    if (!user)
-    user = "";
-
-    auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors,
-                       common_dialog_callback, "[Smb Authinfo]", "smbauthinfo",
-                       DLG_CENTER | DLG_GRID);
-
-    title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
-    x_set_dialog_title (auth_dlg, title);
-    g_free (title);
-
-    in_user  = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
-    add_widget (auth_dlg, in_user);
-
-    in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
-    add_widget (auth_dlg, in_domain);
-    add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
-                 buts[1], 0 ,0, "cancel"));
-    add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
-                 buts[0], 0, 0, "ok"));
-
-    in_password  = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
-    in_password->completion_flags = 0;
-    in_password->is_password = 1;
-    add_widget (auth_dlg, in_password);
-
-    add_widget (auth_dlg, label_new (7, 3, labs[2], "label-passwd"));
-    add_widget (auth_dlg, label_new (5, 3, labs[1], "label-user"));
-    add_widget (auth_dlg, label_new (3, 3, labs[0], "label-domain"));
-
-    run_dlg (auth_dlg);
-
-    switch (auth_dlg->ret_value) {
-    case B_CANCEL:
-        return_value = 0;
-        break;
-    default:
-        return_value = g_new (struct authinfo, 1);
-        if (return_value) {
-            return_value->host = g_strdup (host);
-            return_value->share = g_strdup (share);
-            return_value->domain = g_strdup (in_domain->buffer);
-            return_value->user = g_strdup (in_user->buffer);
-            return_value->password = g_strdup (in_password->buffer);
-        }
-    }
-
-    destroy_dlg (auth_dlg);
-
-    return return_value;
-}
-
 static void
-authinfo_free (struct authinfo const *a)
+authinfo_free (struct smb_authinfo const *a)
 {
     g_free (a->host);
     g_free (a->share);
@@ -232,8 +111,8 @@ authinfo_free_all ()
 static gint
 authinfo_compare_host_and_share (gconstpointer _a, gconstpointer _b)
 {
-    struct authinfo const *a = (struct authinfo const *)_a;
-    struct authinfo const *b = (struct authinfo const *)_b;
+    struct smb_authinfo const *a = (struct smb_authinfo const *)_a;
+    struct smb_authinfo const *b = (struct smb_authinfo const *)_b;

     if (!a->host || !a->share || !b->host || !b->share)
         return 1;
@@ -247,8 +126,8 @@ authinfo_compare_host_and_share (gconstp
 static gint
 authinfo_compare_host (gconstpointer _a, gconstpointer _b)
 {
-    struct authinfo const *a = (struct authinfo const *)_a;
-    struct authinfo const *b = (struct authinfo const *)_b;
+    struct smb_authinfo const *a = (struct smb_authinfo const *)_a;
+    struct smb_authinfo const *b = (struct smb_authinfo const *)_b;

     if (!a->host || !b->host)
         return 1;
@@ -263,7 +142,7 @@ static void
 authinfo_add (const char *host, const char *share, const char *domain,
               const char *user, const char *password)
 {
-    struct authinfo *auth = g_new (struct authinfo, 1);
+    struct smb_authinfo *auth = g_new (struct smb_authinfo, 1);

     if (!auth)
         return;
@@ -280,8 +159,8 @@ authinfo_add (const char *host, const ch
 static void
 authinfo_remove (const char *host, const char *share)
 {
-    struct authinfo data;
-    struct authinfo *auth;
+    struct smb_authinfo data;
+    struct smb_authinfo *auth;
     GSList *list;

     data.host = g_strdup (host);
@@ -306,8 +185,8 @@ bucket_set_authinfo (smbfs_connection *b
         const char *domain, const char *user, const char *pass,
         int fallback_to_host)
 {
-    struct authinfo data;
-    struct authinfo *auth;
+    struct smb_authinfo data;
+    struct smb_authinfo *auth;
     GSList *list;

     if (domain && user && pass) {
@@ -343,10 +222,10 @@ bucket_set_authinfo (smbfs_connection *b
         return 1;
     }

-    auth = authinfo_get_authinfo_from_user (bucket->host,
-                                bucket->service,
-                                (domain ? domain : lp_workgroup ()),
-                                user);
+    auth = vfs_smb_get_authinfo (bucket->host,
+				 bucket->service,
+				 (domain ? domain : lp_workgroup ()),
+				 user);
     if (auth) {
         g_free (bucket->domain);
         g_free (bucket->user);
--- vfs/vfs.h
+++ vfs/vfs.h
@@ -349,6 +349,22 @@
 extern char *vfs_get_password (char *msg);
 extern char *vfs_split_url (char *path, char **host, char **user, int *port, char **pass,
 					int default_port, int flags);
+
+#ifdef WITH_SMBFS
+/* Interface for requesting SMB credentials.  */
+struct smb_authinfo {
+    char *host;
+    char *share;
+    char *domain;
+    char *user;
+    char *password;
+};
+
+struct smb_authinfo *
+vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
+		      const char *user);
+#endif /* WITH_SMBFS */
+
 #define URL_DEFAULTANON 1
 #define URL_NOSLASH 2
 extern void vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]