[gnome-commander] Move functions from utils.cc into files where they are called



commit bd9a552c677d5f92d513a7ac8c251b0c3a33c55c
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Tue Jun 27 22:55:10 2017 +0200

    Move functions from utils.cc into files where they are called

 src/gnome-cmd-file-list.cc    |  174 +++++++++++++++++++++++++
 src/gnome-cmd-file-popmenu.cc |  110 ++++++++++++++++
 src/utils.cc                  |  288 -----------------------------------------
 src/utils.h                   |    3 -
 4 files changed, 284 insertions(+), 291 deletions(-)
---
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 1fd48c4..6af8a3d 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -30,6 +30,7 @@
 #include "gnome-cmd-file.h"
 #include "gnome-cmd-con-list.h"
 #include "gnome-cmd-main-win.h"
+#include "gnome-cmd-plain-path.h"
 #include "utils.h"
 #include "gnome-cmd-data.h"
 #include "gnome-cmd-xfer.h"
@@ -91,6 +92,14 @@ static GtkTargetEntry drop_types [] =
 static guint signals[LAST_SIGNAL] = { 0 };
 
 
+struct TmpDlData
+{
+    GnomeCmdFile *f;
+    GtkWidget *dialog;
+    gpointer *args;
+};
+
+
 struct GnomeCmdFileListColumn
 {
     guint id;
@@ -1176,6 +1185,171 @@ static gboolean on_button_press (GtkCList *clist, GdkEventButton *event, GnomeCm
 }
 
 
+static void do_mime_exec_single (gpointer *args)
+{
+    g_return_if_fail (args != NULL);
+
+    GnomeCmdApp *app = (GnomeCmdApp *) args[0];
+    gchar *path = (gchar *) args[1];
+    gchar *dpath = (gchar *) args[2];
+
+    string cmd = gnome_cmd_app_get_command (app);
+    cmd += ' ';
+    cmd += stringify (g_shell_quote (path));
+
+    run_command_indir (cmd.c_str(), dpath, gnome_cmd_app_get_requires_terminal (app));
+
+    g_free (path);
+    g_free (dpath);
+    gnome_cmd_app_free (app);
+    g_free (args);
+}
+
+
+static void on_tmp_download_response (GtkWidget *w, gint id, TmpDlData *dldata)
+{
+    if (id == GTK_RESPONSE_YES)
+    {
+        gchar *path_str = get_temp_download_filepath (dldata->f->get_name());
+
+        if (!path_str) return;
+
+        dldata->args[1] = (gpointer) path_str;
+
+        GnomeVFSURI *src_uri = gnome_vfs_uri_dup (dldata->f->get_uri());
+        GnomeCmdPlainPath path(path_str);
+        GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), &path);
+
+        gnome_cmd_xfer_tmp_download (src_uri,
+                                     dest_uri,
+                                     GNOME_VFS_XFER_FOLLOW_LINKS,
+                                     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+                                     GTK_SIGNAL_FUNC (do_mime_exec_single),
+                                     dldata->args);
+    }
+    else
+    {
+        gnome_cmd_app_free ((GnomeCmdApp *) dldata->args[0]);
+        g_free (dldata->args);
+    }
+
+    g_free (dldata);
+    gtk_widget_destroy (dldata->dialog);
+}
+
+
+static void mime_exec_single (GnomeCmdFile *f)
+{
+    g_return_if_fail (f != NULL);
+    g_return_if_fail (f->info != NULL);
+
+    gpointer *args;
+    GnomeVFSMimeApplication *vfs_app;
+    GnomeCmdApp *app;
+
+    if (!f->info->mime_type)
+        return;
+
+    // Check if the file is a binary executable that lacks the executable bit
+
+    if (!f->is_executable())
+    {
+        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
+        {
+            gchar *fname = get_utf8 (f->info->name);
+            gchar *msg = g_strdup_printf (_("“%s” seems to be a binary executable file but it lacks the 
executable bit. Do you want to set it and then run the file?"), fname);
+            gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg,
+                                          _("Make Executable?"),
+                                          -1, _("Cancel"), _("OK"), NULL);
+            g_free (fname);
+            g_free (msg);
+
+            if (ret != 1)  return;  else
+            {
+                GnomeVFSResult result = f->chmod((GnomeVFSFilePermissions) 
(f->info->permissions|GNOME_VFS_PERM_USER_EXEC));
+                if (result != GNOME_VFS_OK)
+                    return;
+            }
+        }
+    }
+
+    // If the file is executable but not a binary file, check if the user wants to exec it or open it
+
+    if (f->is_executable())
+    {
+        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
+        {
+            f->execute();
+            return;
+        }
+        else
+            if (f->mime_begins_with("text/"))
+            {
+                gchar *fname = get_utf8 (f->info->name);
+                gchar *msg = g_strdup_printf (_("“%s” is an executable text file. Do you want to run it, or 
display its contents?"), fname);
+                gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg, _("Run or 
Display"),
+                                              -1, _("Cancel"), _("Display"), _("Run"), NULL);
+                g_free (fname);
+                g_free (msg);
+
+                if (ret != 1)
+                {
+                    if (ret == 2)
+                        f->execute();
+                    return;
+                }
+            }
+    }
+
+    vfs_app = gnome_vfs_mime_get_default_application (f->info->mime_type);
+    if (!vfs_app)
+    {
+        gchar *msg = g_strdup_printf (_("No default application found for the MIME type %s."), 
f->info->mime_type);
+        gnome_cmd_show_message (NULL, msg, "Open the \"File types and programs\" page in the Control Center 
to add one.");
+        g_free (msg);
+        return;
+    }
+
+    app = gnome_cmd_app_new_from_vfs_app (vfs_app);
+    gnome_vfs_mime_application_free (vfs_app);
+
+    args = g_new0 (gpointer, 3);
+
+    if (f->is_local())
+    {
+        args[0] = (gpointer) app;
+        args[1] = (gpointer) f->get_real_path();
+        args[2] = (gpointer) g_path_get_dirname ((gchar *) args[1]);            // set exec dir for local 
files
+        do_mime_exec_single (args);
+    }
+    else
+    {
+        if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
+        {
+            args[0] = (gpointer) app;
+            args[1] = (gpointer) f->get_uri_str();
+            // args[2] is NULL here (don't set exec dir for remote files)
+            do_mime_exec_single (args);
+        }
+        else
+        {
+            gchar *msg = g_strdup_printf (_("%s does not know how to open remote file. Do you want to 
download the file to a temporary location and then open it?"), gnome_cmd_app_get_name (app));
+            GtkWidget *dialog = gtk_message_dialog_new (*main_win, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, 
GTK_BUTTONS_YES_NO, "%s", msg);
+            TmpDlData *dldata = g_new0 (TmpDlData, 1);
+            args[0] = (gpointer) app;
+            // args[2] is NULL here (don't set exec dir for temporarily downloaded files)
+            dldata->f = f;
+            dldata->dialog = dialog;
+            dldata->args = args;
+
+            g_signal_connect (dialog, "response", G_CALLBACK (on_tmp_download_response), dldata);
+            gtk_widget_show (dialog);
+            g_free (msg);
+        }
+    }
+}
+
+
 inline gboolean mime_exec_file (GnomeCmdFile *f)
 {
     g_return_val_if_fail (f != NULL, FALSE);
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index aa7f5e5..97bb11f 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -32,6 +32,9 @@
 #include "gnome-cmd-user-actions.h"
 #include "utils.h"
 #include "cap.h"
+#include "gnome-cmd-con-list.h"
+#include "gnome-cmd-plain-path.h"
+#include "gnome-cmd-xfer.h"
 
 #include <fnmatch.h>
 
@@ -66,6 +69,113 @@ struct GnomeCmdFilePopmenuPrivate
 };
 
 
+static void do_mime_exec_multiple (gpointer *args)
+{
+    GnomeCmdApp *app = (GnomeCmdApp *) args[0];
+    GList *files = (GList *) args[1];
+
+    if (files)
+    {
+        string cmd = gnome_cmd_app_get_command (app);
+
+        set<string> dirs;
+
+        for (; files; files = files->next)
+        {
+            cmd += ' ';
+            cmd += stringify (g_shell_quote ((gchar *) files->data));
+
+            gchar *dpath = g_path_get_dirname ((gchar *) files->data);
+
+            if (dpath)
+                dirs.insert (stringify (dpath));
+        }
+
+        if (dirs.size()==1)
+            run_command_indir (cmd.c_str(), dirs.begin()->c_str(), gnome_cmd_app_get_requires_terminal 
(app));
+        else
+            run_command_indir (cmd.c_str(), NULL, gnome_cmd_app_get_requires_terminal (app));
+
+        g_list_free (files);
+    }
+
+    gnome_cmd_app_free (app);
+    g_free (args);
+}
+
+
+static void mime_exec_multiple (GList *files, GnomeCmdApp *app)
+{
+    g_return_if_fail (files != NULL);
+    g_return_if_fail (app != NULL);
+
+    GList *src_uri_list = NULL;
+    GList *dest_uri_list = NULL;
+    GList *local_files = NULL;
+    gboolean asked = FALSE;
+    guint no_of_remote_files = 0;
+    gint retid;
+
+    for (; files; files = files->next)
+    {
+        GnomeCmdFile *f = (GnomeCmdFile *) files->data;
+
+        if (gnome_vfs_uri_is_local (f->get_uri()))
+            local_files = g_list_append (local_files, f->get_real_path());
+        else
+        {
+            ++no_of_remote_files;
+            if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
+            {
+                local_files = g_list_append (local_files,  f->get_uri_str());
+            }
+            else
+            {
+                if (!asked)
+                {
+                    gchar *msg = g_strdup_printf (ngettext("%s does not know how to open remote file. Do you 
want to download the file to a temporary location and then open it?",
+                                                           "%s does not know how to open remote files. Do 
you want to download the files to a temporary location and then open them?", no_of_remote_files),
+                                                  gnome_cmd_app_get_name (app));
+                    retid = run_simple_dialog (*main_win, TRUE, GTK_MESSAGE_QUESTION, msg, "", -1, _("No"), 
_("Yes"), NULL);
+                    asked = TRUE;
+                }
+
+                if (retid==1)
+                {
+                    gchar *path_str = get_temp_download_filepath (f->get_name());
+
+                    if (!path_str) return;
+
+                    GnomeVFSURI *src_uri = gnome_vfs_uri_dup (f->get_uri());
+                    GnomeCmdPlainPath path(path_str);
+                    GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), &path);
+
+                    src_uri_list = g_list_append (src_uri_list, src_uri);
+                    dest_uri_list = g_list_append (dest_uri_list, dest_uri);
+                    local_files = g_list_append (local_files, path_str);
+                }
+            }
+        }
+    }
+
+    g_list_free (files);
+
+    gpointer *args = g_new0 (gpointer, 2);
+    args[0] = app;
+    args[1] = local_files;
+
+    if (src_uri_list)
+        gnome_cmd_xfer_tmp_download_multiple (src_uri_list,
+                                              dest_uri_list,
+                                              GNOME_VFS_XFER_FOLLOW_LINKS,
+                                              GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+                                              GTK_SIGNAL_FUNC (do_mime_exec_multiple),
+                                              args);
+    else
+        do_mime_exec_multiple (args);
+}
+
+
 inline void exec_with_app (GList *files, GnomeCmdApp *app)
 {
     mime_exec_multiple (files, app);
diff --git a/src/utils.cc b/src/utils.cc
index 3af5731..31dd534 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -30,22 +30,12 @@
 #include "gnome-cmd-includes.h"
 #include "utils.h"
 #include "gnome-cmd-data.h"
-#include "gnome-cmd-plain-path.h"
 #include "imageloader.h"
 #include "gnome-cmd-main-win.h"
-#include "gnome-cmd-con-list.h"
-#include "gnome-cmd-xfer.h"
 
 using namespace std;
 
 
-struct TmpDlData
-{
-    GnomeCmdFile *f;
-    GtkWidget *dialog;
-    gpointer *args;
-};
-
 #define FIX_PW_HACK
 #define STRINGS_TO_URIS_CHUNK 1024
 
@@ -449,284 +439,6 @@ const gchar *time2string (time_t t, const gchar *date_format)
 }
 
 
-inline void no_mime_app_found_error (gchar *mime_type)
-{
-    gchar *msg = g_strdup_printf (_("No default application found for the MIME type %s."), mime_type);
-    gnome_cmd_show_message (NULL, msg, "Open the \"File types and programs\" page in the Control Center to 
add one.");
-    g_free (msg);
-}
-
-
-static void do_mime_exec_single (gpointer *args)
-{
-    g_return_if_fail (args != NULL);
-
-    GnomeCmdApp *app = (GnomeCmdApp *) args[0];
-    gchar *path = (gchar *) args[1];
-    gchar *dpath = (gchar *) args[2];
-
-    string cmd = gnome_cmd_app_get_command (app);
-    cmd += ' ';
-    cmd += stringify (g_shell_quote (path));
-
-    run_command_indir (cmd.c_str(), dpath, gnome_cmd_app_get_requires_terminal (app));
-
-    g_free (path);
-    g_free (dpath);
-    gnome_cmd_app_free (app);
-    g_free (args);
-}
-
-
-static void on_tmp_download_response (GtkWidget *w, gint id, TmpDlData *dldata)
-{
-    if (id == GTK_RESPONSE_YES)
-    {
-        gchar *path_str = get_temp_download_filepath (dldata->f->get_name());
-
-        if (!path_str) return;
-
-        dldata->args[1] = (gpointer) path_str;
-
-        GnomeVFSURI *src_uri = gnome_vfs_uri_dup (dldata->f->get_uri());
-        GnomeCmdPlainPath path(path_str);
-        GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), &path);
-
-        gnome_cmd_xfer_tmp_download (src_uri,
-                                     dest_uri,
-                                     GNOME_VFS_XFER_FOLLOW_LINKS,
-                                     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-                                     GTK_SIGNAL_FUNC (do_mime_exec_single),
-                                     dldata->args);
-    }
-    else
-    {
-        gnome_cmd_app_free ((GnomeCmdApp *) dldata->args[0]);
-        g_free (dldata->args);
-    }
-
-    g_free (dldata);
-    gtk_widget_destroy (dldata->dialog);
-}
-
-
-void mime_exec_single (GnomeCmdFile *f)
-{
-    g_return_if_fail (f != NULL);
-    g_return_if_fail (f->info != NULL);
-
-    gpointer *args;
-    GnomeVFSMimeApplication *vfs_app;
-    GnomeCmdApp *app;
-
-    if (!f->info->mime_type)
-        return;
-
-    // Check if the file is a binary executable that lacks the executable bit
-
-    if (!f->is_executable())
-    {
-        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
-        {
-            gchar *fname = get_utf8 (f->info->name);
-            gchar *msg = g_strdup_printf (_("“%s” seems to be a binary executable file but it lacks the 
executable bit. Do you want to set it and then run the file?"), fname);
-            gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg,
-                                          _("Make Executable?"),
-                                          -1, _("Cancel"), _("OK"), NULL);
-            g_free (fname);
-            g_free (msg);
-
-            if (ret != 1)  return;  else
-            {
-                GnomeVFSResult result = f->chmod((GnomeVFSFilePermissions) 
(f->info->permissions|GNOME_VFS_PERM_USER_EXEC));
-                if (result != GNOME_VFS_OK)
-                    return;
-            }
-        }
-    }
-
-    // If the file is executable but not a binary file, check if the user wants to exec it or open it
-
-    if (f->is_executable())
-    {
-        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
-        {
-            f->execute();
-            return;
-        }
-        else
-            if (f->mime_begins_with("text/"))
-            {
-                gchar *fname = get_utf8 (f->info->name);
-                gchar *msg = g_strdup_printf (_("“%s” is an executable text file. Do you want to run it, or 
display its contents?"), fname);
-                gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg, _("Run or 
Display"),
-                                              -1, _("Cancel"), _("Display"), _("Run"), NULL);
-                g_free (fname);
-                g_free (msg);
-
-                if (ret != 1)
-                {
-                    if (ret == 2)
-                        f->execute();
-                    return;
-                }
-            }
-    }
-
-    vfs_app = gnome_vfs_mime_get_default_application (f->info->mime_type);
-    if (!vfs_app)
-    {
-        no_mime_app_found_error (f->info->mime_type);
-        return;
-    }
-
-    app = gnome_cmd_app_new_from_vfs_app (vfs_app);
-    gnome_vfs_mime_application_free (vfs_app);
-
-    args = g_new0 (gpointer, 3);
-
-    if (f->is_local())
-    {
-        args[0] = (gpointer) app;
-        args[1] = (gpointer) f->get_real_path();
-        args[2] = (gpointer) g_path_get_dirname ((gchar *) args[1]);            // set exec dir for local 
files
-        do_mime_exec_single (args);
-    }
-    else
-    {
-        if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
-        {
-            args[0] = (gpointer) app;
-            args[1] = (gpointer) f->get_uri_str();
-            // args[2] is NULL here (don't set exec dir for remote files)
-            do_mime_exec_single (args);
-        }
-        else
-        {
-            gchar *msg = g_strdup_printf (_("%s does not know how to open remote file. Do you want to 
download the file to a temporary location and then open it?"), gnome_cmd_app_get_name (app));
-            GtkWidget *dialog = gtk_message_dialog_new (*main_win, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, 
GTK_BUTTONS_YES_NO, "%s", msg);
-            TmpDlData *dldata = g_new0 (TmpDlData, 1);
-            args[0] = (gpointer) app;
-            // args[2] is NULL here (don't set exec dir for temporarily downloaded files)
-            dldata->f = f;
-            dldata->dialog = dialog;
-            dldata->args = args;
-
-            g_signal_connect (dialog, "response", G_CALLBACK (on_tmp_download_response), dldata);
-            gtk_widget_show (dialog);
-            g_free (msg);
-        }
-    }
-}
-
-
-static void do_mime_exec_multiple (gpointer *args)
-{
-    GnomeCmdApp *app = (GnomeCmdApp *) args[0];
-    GList *files = (GList *) args[1];
-
-    if (files)
-    {
-        string cmd = gnome_cmd_app_get_command (app);
-
-        set<string> dirs;
-
-        for (; files; files = files->next)
-        {
-            cmd += ' ';
-            cmd += stringify (g_shell_quote ((gchar *) files->data));
-
-            gchar *dpath = g_path_get_dirname ((gchar *) files->data);
-
-            if (dpath)
-                dirs.insert (stringify (dpath));
-        }
-
-        if (dirs.size()==1)
-            run_command_indir (cmd.c_str(), dirs.begin()->c_str(), gnome_cmd_app_get_requires_terminal 
(app));
-        else
-            run_command_indir (cmd.c_str(), NULL, gnome_cmd_app_get_requires_terminal (app));
-
-        g_list_free (files);
-    }
-
-    gnome_cmd_app_free (app);
-    g_free (args);
-}
-
-
-void mime_exec_multiple (GList *files, GnomeCmdApp *app)
-{
-    g_return_if_fail (files != NULL);
-    g_return_if_fail (app != NULL);
-
-    GList *src_uri_list = NULL;
-    GList *dest_uri_list = NULL;
-    GList *local_files = NULL;
-    gboolean asked = FALSE;
-    guint no_of_remote_files = 0;
-    gint retid;
-
-    for (; files; files = files->next)
-    {
-        GnomeCmdFile *f = (GnomeCmdFile *) files->data;
-
-        if (gnome_vfs_uri_is_local (f->get_uri()))
-            local_files = g_list_append (local_files, f->get_real_path());
-        else
-        {
-            ++no_of_remote_files;
-            if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
-            {
-                local_files = g_list_append (local_files,  f->get_uri_str());
-            }
-            else
-            {
-                if (!asked)
-                {
-                    gchar *msg = g_strdup_printf (ngettext("%s does not know how to open remote file. Do you 
want to download the file to a temporary location and then open it?",
-                                                           "%s does not know how to open remote files. Do 
you want to download the files to a temporary location and then open them?", no_of_remote_files),
-                                                  gnome_cmd_app_get_name (app));
-                    retid = run_simple_dialog (*main_win, TRUE, GTK_MESSAGE_QUESTION, msg, "", -1, _("No"), 
_("Yes"), NULL);
-                    asked = TRUE;
-                }
-
-                if (retid==1)
-                {
-                    gchar *path_str = get_temp_download_filepath (f->get_name());
-
-                    if (!path_str) return;
-
-                    GnomeVFSURI *src_uri = gnome_vfs_uri_dup (f->get_uri());
-                    GnomeCmdPlainPath path(path_str);
-                    GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), &path);
-
-                    src_uri_list = g_list_append (src_uri_list, src_uri);
-                    dest_uri_list = g_list_append (dest_uri_list, dest_uri);
-                    local_files = g_list_append (local_files, path_str);
-                }
-            }
-        }
-    }
-
-    g_list_free (files);
-
-    gpointer *args = g_new0 (gpointer, 2);
-    args[0] = app;
-    args[1] = local_files;
-
-    if (src_uri_list)
-        gnome_cmd_xfer_tmp_download_multiple (src_uri_list,
-                                              dest_uri_list,
-                                              GNOME_VFS_XFER_FOLLOW_LINKS,
-                                              GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-                                              GTK_SIGNAL_FUNC (do_mime_exec_multiple),
-                                              args);
-    else
-        do_mime_exec_multiple (args);
-}
-
-
 void clear_event_key (GdkEventKey *event)
 {
     g_return_if_fail (event != NULL);
diff --git a/src/utils.h b/src/utils.h
index 74e840e..8409af0 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -127,9 +127,6 @@ const gchar *perm2numstring (GnomeVFSFilePermissions p, gchar *buf, guint max);
 const gchar *size2string (GnomeVFSFileSize size, GnomeCmdSizeDispMode size_disp_mode);
 const gchar *time2string (time_t t, const gchar *date_format);
 
-void mime_exec_single (GnomeCmdFile *f);
-void mime_exec_multiple (GList *files, GnomeCmdApp *app);
-
 void clear_event_key (GdkEventKey *event);
 
 inline gboolean state_is_blank (gint state)


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