[gnome-commander] Adjust legacy mounting, validate input values of devices dialog
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Adjust legacy mounting, validate input values of devices dialog
- Date: Thu, 5 May 2022 20:31:48 +0000 (UTC)
commit d00089a7b6bd7296813c299703f13a664cd5b23b
Author: Uwe Scholz <u scholz83 gmx de>
Date: Thu May 5 22:17:26 2022 +0200
Adjust legacy mounting, validate input values of devices dialog
src/dialogs/gnome-cmd-options-dialog.cc | 37 +++++++----
src/gnome-cmd-con-device.cc | 106 +++++++++++++++++---------------
2 files changed, 82 insertions(+), 61 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-options-dialog.cc b/src/dialogs/gnome-cmd-options-dialog.cc
index 863ffb15..7314b53a 100644
--- a/src/dialogs/gnome-cmd-options-dialog.cc
+++ b/src/dialogs/gnome-cmd-options-dialog.cc
@@ -1874,30 +1874,35 @@ void get_device_dialog_values (GtkWidget *dialog, gchar **alias, gchar **device_
GtkWidget *mountp_entry = lookup_widget (dialog, "mountp_entry");
GtkWidget *iconWidget = lookup_widget (dialog, "device_iconentry");
- gchar* device = (gchar *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (device_entry));
+ gchar* device = (gchar *) gtk_entry_get_text (GTK_ENTRY (device_entry));
gchar* mountp = (gchar *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mountp_entry));
*alias = (gchar *) gtk_entry_get_text (GTK_ENTRY (alias_entry));
- *device_utf8 = g_filename_to_utf8(device, -1, nullptr, nullptr, nullptr);
- *mountp_utf8 = g_filename_to_utf8(mountp, -1, nullptr, nullptr, nullptr);
+ if (device && strlen(device) > 0)
+ *device_utf8 = g_filename_to_utf8(device, -1, nullptr, nullptr, nullptr);
+ if (mountp && strlen(mountp) > 0)
+ *mountp_utf8 = g_filename_to_utf8(mountp, -1, nullptr, nullptr, nullptr);
// Get device_iconentry path
g_object_get (G_OBJECT (gtk_button_get_image (GTK_BUTTON (iconWidget))), "file", icon_path, NULL);
-
- g_free(device);
g_free(mountp);
}
static void on_add_device_dialog_ok (GtkButton *button, GtkWidget *dialog)
{
- gchar *alias, *device, *mountp, *icon_path;
+ gchar *alias = nullptr;
+ gchar *device = nullptr;
+ gchar *mountp = nullptr;
+ gchar *icon_path = nullptr;
GtkWidget *options_dialog = lookup_widget (dialog, "options_dialog");
GtkWidget *clist = lookup_widget (options_dialog, "device_clist");
get_device_dialog_values (dialog, &alias, &device, &mountp, &icon_path);
- if (!alias || strlen (alias) < 1) return;
+ if ((!alias || strlen (alias) < 1) ||
+ (!device || strlen(device) < 1) ||
+ (!mountp || strlen(mountp) < 1)) return;
GnomeCmdConDevice *dev = gnome_cmd_con_device_new (alias, device, mountp, icon_path);
add_device_to_list (GTK_CLIST (clist), GNOME_CMD_CON_DEVICE (dev));
@@ -1919,7 +1924,9 @@ static void on_edit_device_dialog_ok (GtkButton *button, GtkWidget *dialog)
GtkWidget *clist = lookup_widget (options_dialog, "device_clist");
get_device_dialog_values (dialog, &alias, &device, &mountp, &icon_path);
- if (!alias || strlen (alias) < 1) return;
+ if ((!alias || strlen (alias) < 1) ||
+ (!device || strlen(device) < 1) ||
+ (!mountp || strlen(mountp) < 1)) return;
GnomeCmdConDevice *dev = GNOME_CMD_CON_DEVICE (g_object_get_data (G_OBJECT (options_dialog),
"selected_device"));
if (!dev) return;
@@ -1933,6 +1940,11 @@ static void on_edit_device_dialog_ok (GtkButton *button, GtkWidget *dialog)
}
+static void on_dialog_help (GtkButton *button, GtkWidget *unused)
+{
+ gnome_cmd_help_display ("gnome-commander.xml", "gnome-commander-prefs-devices");
+}
+
static GtkWidget *create_device_dialog (GnomeCmdConDevice *dev, GtkSignalFunc on_ok, GtkSignalFunc
on_cancel, GtkWidget *options_dialog)
{
GtkWidget *table, *entry, *label;
@@ -1952,7 +1964,7 @@ static GtkWidget *create_device_dialog (GnomeCmdConDevice *dev, GtkSignalFunc on
label = create_label (dialog, _("Alias:"));
table_add (table, label, 0, 0, GTK_FILL);
- label = create_label (dialog, _("Device:"));
+ label = create_label (dialog, _("Device/Label:"));
table_add (table, label, 0, 1, GTK_FILL);
label = create_label (dialog, _("Mount point:"));
table_add (table, label, 0, 2, GTK_FILL);
@@ -1965,18 +1977,21 @@ static GtkWidget *create_device_dialog (GnomeCmdConDevice *dev, GtkSignalFunc on
gtk_widget_grab_focus (entry);
if (dev) s = gnome_cmd_con_device_get_device_fn (dev);
- entry = create_file_chooser_button (dialog, "device_entry", s);
+ entry = create_entry (dialog, "device_entry", s);
table_add (table, entry, 1, 1, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
if (dev) s = gnome_cmd_con_device_get_mountp_string (dev);
entry = create_directory_chooser_button (dialog, "mountp_entry", s);
table_add (table, entry, 1, 2, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
- s = gnome_cmd_con_device_get_icon_path (dev);
+ if (dev) s = gnome_cmd_con_device_get_icon_path (dev);
entry = create_icon_button_widget (dialog, "device_iconentry", s);
table_add (table, entry, 1, 3, GTK_FILL);
+ gnome_cmd_dialog_add_button (
+ GNOME_CMD_DIALOG (dialog), GTK_STOCK_HELP,
+ GTK_SIGNAL_FUNC (on_dialog_help), nullptr);
gnome_cmd_dialog_add_button (
GNOME_CMD_DIALOG (dialog), GTK_STOCK_CANCEL,
GTK_SIGNAL_FUNC (on_cancel), dialog);
diff --git a/src/gnome-cmd-con-device.cc b/src/gnome-cmd-con-device.cc
index 006e7470..4a0b112d 100644
--- a/src/gnome-cmd-con-device.cc
+++ b/src/gnome-cmd-con-device.cc
@@ -99,17 +99,18 @@ static void do_legacy_mount(GnomeCmdCon *con)
gchar *cmd = nullptr;
gchar *emsg = nullptr;
- if (dev_con->priv->device_fn != nullptr && dev_con->priv->mountp != nullptr)
+ if (strlen(dev_con->priv->device_fn) == 0)
+ return;
+
+ DEBUG ('m', "mounting %s\n", dev_con->priv->device_fn);
+ if (dev_con->priv->device_fn[0] == G_DIR_SEPARATOR)
{
- DEBUG ('m', "mounting %s\n", dev_con->priv->mountp);
- if (dev_con->priv->device_fn)
- cmd = g_strdup_printf ("mount %s %s", dev_con->priv->device_fn, dev_con->priv->mountp);
- else
- cmd = g_strdup_printf ("mount %s", dev_con->priv->mountp);
+ cmd = g_strdup_printf ("mount %s", dev_con->priv->device_fn);
+ }
+ else
+ {
+ cmd = g_strdup_printf ("mount -L %s", dev_con->priv->device_fn);
}
-
- if (!cmd)
- return;
DEBUG ('m', "Mount command: %s\n", cmd);
ret = system (cmd);
@@ -158,7 +159,8 @@ static void set_con_mount_succeed(GnomeCmdCon *con)
static void set_con_mount_failed(GnomeCmdCon *con)
{
- g_object_unref (con->base_gFileInfo);
+ if (con->base_gFileInfo)
+ g_object_unref (con->base_gFileInfo);
con->base_gFileInfo = nullptr;
con->open_result = GnomeCmdCon::OPEN_FAILED;
con->state = GnomeCmdCon::STATE_CLOSED;
@@ -202,27 +204,20 @@ static void do_legacy_mount_thread_func(GnomeCmdCon *con)
if (!con->base_path)
{
- if (GNOME_CMD_CON_DEVICE(con)->priv->mountp)
- {
- con->base_path = new GnomeCmdPlainPath(GNOME_CMD_CON_DEVICE(con)->priv->mountp);
- }
- else
- {
- con->base_path = new GnomeCmdPlainPath(G_DIR_SEPARATOR_S);
- }
+ con->base_path = new GnomeCmdPlainPath(GNOME_CMD_CON_DEVICE(con)->priv->mountp);
}
do_legacy_mount(con);
- auto gFile = gnome_cmd_con_create_gfile(con, con->base_path);
-
- if (!gFile)
+ if (con->open_result == GnomeCmdCon::OPEN_FAILED)
{
- con->open_failed_error = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to create a GFile object
for the given path.");
+ con->open_failed_error = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to mount %s",
GNOME_CMD_CON_DEVICE (con)->priv->device_fn);
set_con_mount_failed(con);
- g_warning("Unable to create a GFile object for the given path.");
return;
}
+
+ auto gFile = gnome_cmd_con_create_gfile(con, con->base_path);
+
con->base_gFileInfo = g_file_query_info(gFile,
"*",
G_FILE_QUERY_INFO_NONE,
@@ -257,25 +252,27 @@ static void do_mount (GnomeCmdCon *con)
}
// Check if the volume is already mounted:
- auto gMount = g_volume_get_mount (dev_con->priv->gVolume);
- if (gMount)
+ if (dev_con->priv->gVolume)
{
- dev_con->priv->gMount = gMount;
- set_con_base_path_for_gmount(con, dev_con->priv->gMount);
- set_con_base_gfileinfo(con);
- set_con_mount_succeed(con);
- return;
- }
-
- auto gMountOperation = gtk_mount_operation_new ((GtkWindow*) main_win);
+ auto gMount = g_volume_get_mount (dev_con->priv->gVolume);
+ if (gMount)
+ {
+ dev_con->priv->gMount = gMount;
+ set_con_base_path_for_gmount(con, dev_con->priv->gMount);
+ set_con_base_gfileinfo(con);
+ set_con_mount_succeed(con);
+ return;
+ }
- g_volume_mount (dev_con->priv->gVolume,
- G_MOUNT_MOUNT_NONE,
- gMountOperation,
- nullptr,
- mount_finish_callback,
- con);
+ auto gMountOperation = gtk_mount_operation_new ((GtkWindow*) main_win);
+ g_volume_mount (dev_con->priv->gVolume,
+ G_MOUNT_MOUNT_NONE,
+ gMountOperation,
+ nullptr,
+ mount_finish_callback,
+ con);
+ }
}
@@ -292,6 +289,20 @@ static void dev_open (GnomeCmdCon *con)
}
+static void show_message_dialog_volume_unmounted()
+{
+ DEBUG('m', "unmount_callback: succeeded\n");
+ GtkWidget *msgbox;
+ msgbox = gtk_message_dialog_new (*main_win,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Volume successfully unmounted"));
+ gtk_dialog_run (GTK_DIALOG (msgbox));
+ gtk_widget_destroy (msgbox);
+}
+
+
static void unmount_callback(GObject *gMnt, GAsyncResult *result, gpointer user_data)
{
GnomeCmdCon *con = GNOME_CMD_CON (user_data);
@@ -319,16 +330,7 @@ static void unmount_callback(GObject *gMnt, GAsyncResult *result, gpointer user_
con->state = GnomeCmdCon::STATE_CLOSED;
- DEBUG('m', "unmount_callback: succeeded\n");
-
- msgbox = gtk_message_dialog_new (*main_win,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK,
- _("Volume successfully unmounted"));
-
- gtk_dialog_run (GTK_DIALOG (msgbox));
- gtk_widget_destroy (msgbox);
+ show_message_dialog_volume_unmounted();
}
@@ -374,7 +376,11 @@ static gboolean dev_close (GnomeCmdCon *con)
g_free (cmd);
if (ret == 0)
+ {
con->state = GnomeCmdCon::STATE_CLOSED;
+
+ show_message_dialog_volume_unmounted();
+ }
}
}
@@ -577,7 +583,7 @@ void gnome_cmd_con_device_set_device_fn (GnomeCmdConDevice *dev, const gchar *de
g_free (dev->priv->device_fn);
- dev->priv->device_fn = g_strdup (device_fn);
+ dev->priv->device_fn = g_strdup (device_fn ? device_fn : "");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]