PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/dialogs/gnome-cmd-con-dialog.cc

https://gitlab.com/m.schmidt/gnome-commander
C++ | 647 lines | 449 code | 172 blank | 26 comment | 46 complexity | e6dfa0a520bd4e2df7f89459c7fd3bd6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /**
  2. * @file gnome-cmd-con-dialog.cc
  3. * @copyright (C) 2001-2006 Marcus Bjurman\n
  4. * @copyright (C) 2007-2012 Piotr Eljasiak\n
  5. * @copyright (C) 2013-2015 Uwe Scholz\n
  6. *
  7. * @copyright This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * @copyright This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * @copyright You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include <config.h>
  22. #include "gnome-cmd-includes.h"
  23. #include "gnome-cmd-data.h"
  24. #include "utils.h"
  25. #include "dialogs/gnome-cmd-con-dialog.h"
  26. using namespace std;
  27. #define GNOME_CMD_TYPE_CONNECT_DIALOG (gnome_cmd_connect_dialog_get_type())
  28. #define GNOME_CMD_CONNECT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_CMD_TYPE_CONNECT_DIALOG, GnomeCmdConnectDialog))
  29. #define GNOME_CMD_CONNECT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_CMD_TYPE_CONNECT_DIALOG, GnomeCmdConnectDialogClass))
  30. #define GNOME_CMD_IS_CONNECT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_CMD_TYPE_CONNECT_DIALOG)
  31. struct GnomeCmdConnectDialog
  32. {
  33. GtkDialog parent;
  34. class Private;
  35. Private *priv;
  36. operator GtkWidget * () const { return GTK_WIDGET (this); }
  37. operator GtkWindow * () const { return GTK_WINDOW (this); }
  38. operator GtkDialog * () const { return GTK_DIALOG (this); }
  39. gboolean verify_uri();
  40. };
  41. struct GnomeCmdConnectDialogClass
  42. {
  43. GtkDialogClass parent_class;
  44. };
  45. struct GnomeCmdConnectDialog::Private
  46. {
  47. string *alias;
  48. string uri_str;
  49. GnomeCmdCon::Authentication auth;
  50. GtkWidget *required_table;
  51. GtkWidget *optional_table;
  52. GtkWidget *type_combo;
  53. GtkWidget *alias_entry;
  54. GtkWidget *uri_entry;
  55. GtkWidget *server_entry;
  56. GtkWidget *share_entry;
  57. GtkWidget *port_entry;
  58. GtkWidget *folder_entry;
  59. GtkWidget *domain_entry;
  60. GtkWidget *user_entry;
  61. Private();
  62. ~Private();
  63. void setup_for_type();
  64. void show_entry(GtkWidget *table, GtkWidget *entry, const gchar *text, gint &i);
  65. };
  66. inline GnomeCmdConnectDialog::Private::Private()
  67. {
  68. alias = NULL;
  69. auth = GnomeCmdCon::SAVE_PERMANENTLY;
  70. required_table = NULL;
  71. optional_table = NULL;
  72. type_combo = NULL;
  73. alias_entry = gtk_entry_new ();
  74. uri_entry = gtk_entry_new ();
  75. server_entry = gtk_entry_new ();
  76. share_entry = gtk_entry_new ();
  77. port_entry = gtk_entry_new ();
  78. folder_entry = gtk_entry_new ();
  79. domain_entry = gtk_entry_new ();
  80. user_entry = gtk_entry_new ();
  81. gtk_entry_set_activates_default (GTK_ENTRY (alias_entry), TRUE);
  82. gtk_entry_set_activates_default (GTK_ENTRY (uri_entry), TRUE);
  83. gtk_entry_set_activates_default (GTK_ENTRY (server_entry), TRUE);
  84. gtk_entry_set_activates_default (GTK_ENTRY (share_entry), TRUE);
  85. gtk_entry_set_activates_default (GTK_ENTRY (port_entry), TRUE);
  86. gtk_entry_set_activates_default (GTK_ENTRY (folder_entry), TRUE);
  87. gtk_entry_set_activates_default (GTK_ENTRY (user_entry), TRUE);
  88. // We need an extra ref so we can remove them from the table
  89. g_object_ref (alias_entry);
  90. g_object_ref (uri_entry);
  91. g_object_ref (server_entry);
  92. g_object_ref (share_entry);
  93. g_object_ref (port_entry);
  94. g_object_ref (folder_entry);
  95. g_object_ref (domain_entry);
  96. g_object_ref (user_entry);
  97. }
  98. inline GnomeCmdConnectDialog::Private::~Private()
  99. {
  100. g_object_unref (alias_entry);
  101. g_object_unref (uri_entry);
  102. g_object_unref (server_entry);
  103. g_object_unref (share_entry);
  104. g_object_unref (port_entry);
  105. g_object_unref (folder_entry);
  106. g_object_unref (domain_entry);
  107. g_object_unref (user_entry);
  108. delete alias;
  109. }
  110. void GnomeCmdConnectDialog::Private::setup_for_type()
  111. {
  112. gint type = gtk_combo_box_get_active (GTK_COMBO_BOX (type_combo));
  113. if (alias_entry->parent)
  114. gtk_container_remove (GTK_CONTAINER (required_table), alias_entry);
  115. if (uri_entry->parent)
  116. gtk_container_remove (GTK_CONTAINER (required_table), uri_entry);
  117. if (server_entry->parent)
  118. gtk_container_remove (GTK_CONTAINER (required_table), server_entry);
  119. if (share_entry->parent)
  120. gtk_container_remove (GTK_CONTAINER (optional_table), share_entry);
  121. if (port_entry->parent)
  122. gtk_container_remove (GTK_CONTAINER (optional_table), port_entry);
  123. if (folder_entry->parent)
  124. gtk_container_remove (GTK_CONTAINER (optional_table), folder_entry);
  125. if (user_entry->parent)
  126. gtk_container_remove (GTK_CONTAINER (optional_table), user_entry);
  127. if (domain_entry->parent)
  128. gtk_container_remove (GTK_CONTAINER (optional_table), domain_entry);
  129. // Destroy all labels
  130. gtk_container_foreach (GTK_CONTAINER (required_table), (GtkCallback) gtk_widget_destroy, NULL);
  131. gint i = 1;
  132. GtkWidget *table = required_table;
  133. gboolean show_share, show_port, show_user, show_domain;
  134. show_entry (table, alias_entry, _("_Alias:"), i);
  135. switch (type)
  136. {
  137. case CON_URI:
  138. show_entry (table, uri_entry, _("_Location (URI):"), i);
  139. return;
  140. default:
  141. case CON_SSH:
  142. case CON_FTP:
  143. case CON_DAV:
  144. case CON_DAVS:
  145. show_share = FALSE;
  146. show_port = TRUE;
  147. show_user = TRUE;
  148. show_domain = FALSE;
  149. break;
  150. case CON_ANON_FTP:
  151. show_share = FALSE;
  152. show_port = TRUE;
  153. show_user = FALSE;
  154. show_domain = FALSE;
  155. break;
  156. #ifdef HAVE_SAMBA
  157. case CON_SMB:
  158. show_share = TRUE;
  159. show_port = FALSE;
  160. show_user = TRUE;
  161. show_domain = TRUE;
  162. break;
  163. #endif
  164. }
  165. show_entry (table, server_entry, _("_Server:"), i);
  166. GtkWidget *align;
  167. align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  168. gtk_alignment_set_padding (GTK_ALIGNMENT (align), 12, 0, 0, 0);
  169. gtk_table_attach (GTK_TABLE (table), align, 0, 2, i, i+1, GTK_FILL, GTK_FILL, 0, 0);
  170. gtk_widget_show (align);
  171. i++;
  172. gchar *str = g_strdup_printf ("<b>%s</b>", _("Optional information"));
  173. GtkWidget *label = gtk_label_new (str);
  174. g_free (str);
  175. gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
  176. gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  177. gtk_widget_show (label);
  178. gtk_container_add (GTK_CONTAINER (align), label);
  179. align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  180. gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
  181. gtk_table_attach (GTK_TABLE (table), align, 0, 2, i, i+1, GTK_FILL, GTK_FILL, 0, 0);
  182. gtk_widget_show (align);
  183. optional_table = table = gtk_table_new (1, 2, FALSE);
  184. gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  185. gtk_table_set_col_spacings (GTK_TABLE (table), 12);
  186. gtk_widget_show (table);
  187. gtk_container_add (GTK_CONTAINER (align), table);
  188. i = 0;
  189. if (show_share)
  190. show_entry (table, share_entry, _("S_hare:"), i);
  191. if (show_port)
  192. show_entry (table, port_entry, _("_Port:"), i);
  193. show_entry (table, folder_entry, _("_Folder:"), i);
  194. if (show_user)
  195. show_entry (table, user_entry, _("_User name:"), i);
  196. if (show_domain)
  197. show_entry (table, domain_entry, _("_Domain name:"), i);
  198. }
  199. inline void GnomeCmdConnectDialog::Private::show_entry(GtkWidget *table, GtkWidget *entry, const gchar *text, gint &i)
  200. {
  201. GtkWidget *label = gtk_label_new_with_mnemonic (text);
  202. gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  203. gtk_widget_show (label);
  204. gtk_table_attach (GTK_TABLE (table), label, 0, 1, i, i+1, GTK_FILL, GTK_FILL, 0, 0);
  205. gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
  206. gtk_widget_show (entry);
  207. gtk_table_attach (GTK_TABLE (table), entry, 1, 2, i, i+1, GtkAttachOptions (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0);
  208. ++i;
  209. }
  210. inline gboolean GnomeCmdConnectDialog::verify_uri()
  211. {
  212. string uri;
  213. string server;
  214. string share;
  215. string port;
  216. string folder;
  217. string domain;
  218. string user;
  219. string password;
  220. if (priv->uri_entry->parent)
  221. stringify (uri, gtk_editable_get_chars (GTK_EDITABLE (priv->uri_entry), 0, -1));
  222. if (priv->server_entry->parent)
  223. stringify (server, gtk_editable_get_chars (GTK_EDITABLE (priv->server_entry), 0, -1));
  224. if (priv->share_entry->parent)
  225. stringify (share, gtk_editable_get_chars (GTK_EDITABLE (priv->share_entry), 0, -1));
  226. if (priv->port_entry->parent)
  227. stringify (port, gtk_editable_get_chars (GTK_EDITABLE (priv->port_entry), 0, -1));
  228. if (priv->folder_entry->parent)
  229. stringify (folder, gtk_editable_get_chars (GTK_EDITABLE (priv->folder_entry), 0, -1));
  230. if (priv->domain_entry->parent)
  231. stringify (domain, gtk_editable_get_chars (GTK_EDITABLE (priv->domain_entry), 0, -1));
  232. if (priv->user_entry->parent)
  233. stringify (user, gtk_editable_get_chars (GTK_EDITABLE (priv->user_entry), 0, -1));
  234. int type = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->type_combo));
  235. if (type!=CON_URI && server.empty())
  236. {
  237. gnome_cmd_show_message (*this, _("You must enter a name for the server"), _("Please enter a name and try again."));
  238. return FALSE;
  239. }
  240. priv->auth = type==CON_ANON_FTP ? GnomeCmdCon::NOT_REQUIRED : GnomeCmdCon::SAVE_PERMANENTLY;
  241. if (type==CON_ANON_FTP)
  242. user = "anonymous";
  243. gnome_cmd_con_make_uri (uri, (ConnectionMethodID) type, priv->auth==GnomeCmdCon::SAVE_PERMANENTLY, uri, server, share, port, folder, domain, user, password);
  244. if (type==CON_URI && uri.empty())
  245. {
  246. gnome_cmd_show_message (*this,
  247. stringify(g_strdup_printf (_("\"%s\" is not a valid location"), uri.c_str())),
  248. _("Please check spelling and try again."));
  249. return FALSE;
  250. }
  251. if (priv->alias)
  252. stringify (*priv->alias, gtk_editable_get_chars (GTK_EDITABLE (priv->alias_entry), 0, -1));
  253. priv->uri_str = uri;
  254. return TRUE;
  255. }
  256. G_DEFINE_TYPE (GnomeCmdConnectDialog, gnome_cmd_connect_dialog, GTK_TYPE_DIALOG)
  257. static void gnome_cmd_connect_dialog_finalize (GObject *object)
  258. {
  259. GnomeCmdConnectDialog *dialog = GNOME_CMD_CONNECT_DIALOG (object);
  260. delete dialog->priv;
  261. G_OBJECT_CLASS (gnome_cmd_connect_dialog_parent_class)->finalize (object);
  262. }
  263. static void response_callback (GnomeCmdConnectDialog *dialog, int response_id, gpointer data)
  264. {
  265. switch (response_id)
  266. {
  267. case GTK_RESPONSE_OK:
  268. if (!dialog->verify_uri())
  269. g_signal_stop_emission_by_name (dialog, "response");
  270. break;
  271. case GTK_RESPONSE_NONE:
  272. case GTK_RESPONSE_DELETE_EVENT:
  273. case GTK_RESPONSE_CANCEL:
  274. break;
  275. case GTK_RESPONSE_HELP:
  276. gnome_cmd_help_display ("gnome-commander.xml", "gnome-commander-config-remote-connections");
  277. g_signal_stop_emission_by_name (dialog, "response");
  278. break;
  279. default :
  280. g_assert_not_reached ();
  281. }
  282. }
  283. static void gnome_cmd_connect_dialog_class_init (GnomeCmdConnectDialogClass *klass)
  284. {
  285. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  286. object_class->finalize = gnome_cmd_connect_dialog_finalize;
  287. }
  288. static void dlg_changed_callback (GtkComboBox *combo_box, GnomeCmdConnectDialog *dialog)
  289. {
  290. dialog->priv->setup_for_type();
  291. }
  292. static void port_insert_text (GtkEditable *editable, const gchar *new_text, gint new_text_length, gint *position)
  293. {
  294. if (new_text_length < 0)
  295. new_text_length = strlen (new_text);
  296. if (new_text_length!=1 || g_ascii_isdigit (new_text[0]))
  297. return;
  298. gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (editable)));
  299. g_signal_stop_emission_by_name (editable, "insert-text");
  300. }
  301. static void gnome_cmd_connect_dialog_init (GnomeCmdConnectDialog *dialog)
  302. {
  303. GtkWidget *align;
  304. GtkWidget *label;
  305. GtkWidget *table;
  306. GtkWidget *combo;
  307. GtkWidget *check;
  308. GtkWidget *hbox;
  309. GtkWidget *vbox;
  310. dialog->priv = new GnomeCmdConnectDialog::Private;
  311. g_return_if_fail (dialog->priv != NULL);
  312. gtk_window_set_title (*dialog, _("Remote Server"));
  313. gtk_dialog_set_has_separator (*dialog, FALSE);
  314. gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
  315. gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
  316. gtk_window_set_resizable (*dialog, FALSE);
  317. vbox = gtk_vbox_new (FALSE, 6);
  318. gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
  319. gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, FALSE, TRUE, 0);
  320. gtk_widget_show (vbox);
  321. hbox = gtk_hbox_new (FALSE, 6);
  322. gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
  323. gtk_widget_show (hbox);
  324. gchar *str = g_strdup_printf ("<b>%s</b>", _("Service _type:"));
  325. label = gtk_label_new_with_mnemonic (str);
  326. g_free (str);
  327. gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
  328. gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  329. gtk_widget_show (label);
  330. gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  331. dialog->priv->type_combo = combo = gtk_combo_box_new_text ();
  332. // Keep this in sync with enum ConnectionMethodID in gnome-cmd-con.h
  333. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("SSH"));
  334. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("FTP (with login)"));
  335. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Public FTP"));
  336. #ifdef HAVE_SAMBA
  337. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Windows share"));
  338. #endif
  339. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("WebDAV (HTTP)"));
  340. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Secure WebDAV (HTTPS)"));
  341. gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Custom location"));
  342. gtk_widget_show (combo);
  343. gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
  344. gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
  345. g_signal_connect (combo, "changed", G_CALLBACK (dlg_changed_callback), dialog);
  346. align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  347. gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
  348. gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  349. gtk_widget_show (align);
  350. hbox = gtk_hbox_new (FALSE, 6);
  351. gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
  352. gtk_widget_show (hbox);
  353. align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  354. gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
  355. gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
  356. gtk_widget_show (align);
  357. dialog->priv->required_table = table = gtk_table_new (1, 2, FALSE);
  358. gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  359. gtk_table_set_col_spacings (GTK_TABLE (table), 12);
  360. gtk_widget_show (table);
  361. gtk_container_add (GTK_CONTAINER (align), table);
  362. g_signal_connect (dialog->priv->port_entry, "insert-text", G_CALLBACK (port_insert_text), NULL);
  363. dialog->priv->setup_for_type();
  364. gtk_dialog_add_buttons (*dialog,
  365. GTK_STOCK_HELP, GTK_RESPONSE_HELP,
  366. GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  367. GTK_STOCK_OK, GTK_RESPONSE_OK,
  368. NULL);
  369. gtk_dialog_set_default_response (*dialog, GTK_RESPONSE_OK);
  370. g_signal_connect (dialog, "response", G_CALLBACK (response_callback), dialog);
  371. }
  372. /**
  373. * Dialog for setting up a new remote server connection.
  374. */
  375. GnomeCmdConRemote *gnome_cmd_connect_dialog_new (gboolean has_alias)
  376. {
  377. GnomeCmdConnectDialog *dialog = (GnomeCmdConnectDialog *) g_object_new (GNOME_CMD_TYPE_CONNECT_DIALOG, NULL);
  378. g_return_val_if_fail (dialog != NULL, NULL);
  379. if (has_alias)
  380. dialog->priv->alias = new string;
  381. else
  382. gtk_widget_set_sensitive (dialog->priv->alias_entry, FALSE);
  383. gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->type_combo), CON_SSH);
  384. dialog->priv->auth = GnomeCmdCon::SAVE_PERMANENTLY;
  385. gint response = gtk_dialog_run (*dialog);
  386. GnomeCmdConRemote *server = NULL;
  387. if (response==GTK_RESPONSE_OK)
  388. {
  389. const gchar *alias = dialog->priv->alias && !dialog->priv->alias->empty() ? dialog->priv->alias->c_str() : NULL;
  390. server = gnome_cmd_con_remote_new (alias, dialog->priv->uri_str);
  391. GnomeCmdCon *con = GNOME_CMD_CON (server);
  392. con->method = (ConnectionMethodID) gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->type_combo));
  393. con->auth = dialog->priv->auth;
  394. }
  395. gtk_widget_destroy (*dialog);
  396. return server;
  397. }
  398. gboolean gnome_cmd_connect_dialog_edit (GnomeCmdConRemote *server)
  399. {
  400. g_return_val_if_fail (server != NULL, FALSE);
  401. GnomeCmdConnectDialog *dialog = (GnomeCmdConnectDialog *) gtk_widget_new (GNOME_CMD_TYPE_CONNECT_DIALOG, NULL);
  402. g_return_val_if_fail (dialog != NULL, FALSE);
  403. GnomeCmdCon *con = GNOME_CMD_CON (server);
  404. gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->priv->type_combo), con->method);
  405. dialog->priv->auth = con->auth;
  406. if (con->alias)
  407. {
  408. dialog->priv->alias = new string(con->alias);
  409. gtk_entry_set_text (GTK_ENTRY (dialog->priv->alias_entry), con->alias);
  410. }
  411. else
  412. gtk_widget_set_sensitive (dialog->priv->alias_entry, FALSE);
  413. if (con->uri)
  414. {
  415. dialog->priv->uri_str = con->uri;
  416. GnomeVFSURI *uri = gnome_vfs_uri_new (con->uri);
  417. if (uri)
  418. {
  419. gtk_entry_set_text (GTK_ENTRY (dialog->priv->uri_entry), con->uri);
  420. gtk_entry_set_text (GTK_ENTRY (dialog->priv->server_entry), gnome_vfs_uri_get_host_name (uri));
  421. const gchar *path = gnome_vfs_uri_get_path (uri);
  422. const gchar *user_name = gnome_vfs_uri_get_user_name (uri);
  423. guint port = gnome_vfs_uri_get_host_port (uri);
  424. #ifdef HAVE_SAMBA
  425. if (con->method==CON_SMB)
  426. {
  427. gchar **a = g_strsplit (path, "/", 3);
  428. if (g_strv_length (a) > 2)
  429. {
  430. gtk_entry_set_text (GTK_ENTRY (dialog->priv->share_entry), a[1]);
  431. gtk_entry_set_text (GTK_ENTRY (dialog->priv->folder_entry), a[2]);
  432. }
  433. else
  434. gtk_entry_set_text (GTK_ENTRY (dialog->priv->folder_entry), path);
  435. g_strfreev (a);
  436. a = g_strsplit (user_name, ";", 2);
  437. if (g_strv_length (a) > 1)
  438. {
  439. gtk_entry_set_text (GTK_ENTRY (dialog->priv->domain_entry), a[0]);
  440. gtk_entry_set_text (GTK_ENTRY (dialog->priv->user_entry), a[1]);
  441. }
  442. else
  443. gtk_entry_set_text (GTK_ENTRY (dialog->priv->user_entry), user_name);
  444. g_strfreev (a);
  445. }
  446. else
  447. {
  448. #endif
  449. gtk_entry_set_text (GTK_ENTRY (dialog->priv->folder_entry), path);
  450. gtk_entry_set_text (GTK_ENTRY (dialog->priv->user_entry), user_name);
  451. #ifdef HAVE_SAMBA
  452. }
  453. #endif
  454. if (port)
  455. gtk_entry_set_text (GTK_ENTRY (dialog->priv->port_entry), stringify(port).c_str());
  456. gnome_vfs_uri_unref (uri);
  457. }
  458. }
  459. gint response = gtk_dialog_run (*dialog);
  460. if (response==GTK_RESPONSE_OK)
  461. {
  462. GnomeVFSURI *uri = gnome_vfs_uri_new (dialog->priv->uri_str.c_str());
  463. const gchar *alias = dialog->priv->alias ? dialog->priv->alias->c_str() : NULL;
  464. const gchar *host = gnome_vfs_uri_get_host_name (uri);
  465. gnome_cmd_con_set_alias (con, alias);
  466. gnome_cmd_con_set_uri (con, dialog->priv->uri_str);
  467. gnome_cmd_con_set_host_name (con, host);
  468. con->method = (ConnectionMethodID) gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->type_combo));
  469. con->auth = dialog->priv->auth;
  470. gnome_cmd_con_remote_set_host_name (server, host);
  471. gnome_vfs_uri_unref (uri);
  472. }
  473. gtk_widget_destroy (*dialog);
  474. return response==GTK_RESPONSE_OK;
  475. }