started implementation of external commands; external Delete should work
authorVladimir Nadvornik <nadvornik@suse.cz>
Wed, 15 Aug 2007 21:37:51 +0000 (21:37 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Wed, 15 Aug 2007 21:37:51 +0000 (21:37 +0000)
src/editors.c
src/editors.h
src/gqview.h
src/preferences.c
src/typedefs.h
src/utilops.c

index e383306..6170591 100644 (file)
@@ -46,7 +46,7 @@ struct _EditorVerboseData {
 };
 
 
-static gchar *editor_slot_defaults[] = {
+static gchar *editor_slot_defaults[GQVIEW_EDITOR_SLOTS * 2] = {
        N_("The Gimp"), "gimp-remote -n %f",
        N_("XV"), "xv %f",
        N_("Xpaint"), "xpaint %f",
@@ -57,10 +57,14 @@ static gchar *editor_slot_defaults[] = {
        NULL, NULL,
        N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %p_tmp %p; then mv %p_tmp %p;else rm %p_tmp;fi",
        N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %p_tmp %p; then mv %p_tmp %p;else rm %p_tmp;fi",
-       NULL, NULL
+       /* special slots */
+       "External Copy command", NULL,
+       "External Move command", NULL,
+       "External Rename command", NULL,
+       "External Delete command", NULL,
+       "External New Folder command", NULL
 };
 
-
 static void editor_verbose_window_progress(EditorVerboseData *vd, const gchar *text);
 static gint editor_command_next(EditorVerboseData *vd);
 
@@ -502,10 +506,11 @@ static gint editor_line_break(const gchar *template, gchar **front, const gchar
  *
  * [1] Note: %v,%V may also be preceded by "%w".
  */
-static void editor_command_run(const gchar *template, const gchar *text, GList *list)
+static gint editor_command_run(const gchar *template, const gchar *text, GList *list)
 {
        gint verbose = FALSE;
        gint for_each = FALSE;
+       gint ret = TRUE;
 
        if (!template || template[0] == '\0') return;
 
@@ -587,36 +592,44 @@ static void editor_command_run(const gchar *template, const gchar *text, GList *
                        }
                else
                        {
-                       system(result->str);
+                       int status = system(result->str);
+                       /* FIXME: consistent return values */
+                       if (!WIFEXITED(status) || WEXITSTATUS(status))
+                               ret = FALSE;
                        }
 
                g_free(front);
                g_string_free(result, TRUE);
                }
+       return ret;
 }
 
-void start_editor_from_path_list(gint n, GList *list)
+gint start_editor_from_path_list(gint n, GList *list)
 {
        gchar *command;
+       gint ret;
 
        if (n < 0 || n >= GQVIEW_EDITOR_SLOTS || !list ||
            !editor_command[n] ||
-           strlen(editor_command[n]) == 0) return;
+           strlen(editor_command[n]) == 0) return FALSE;
 
        command = g_locale_from_utf8(editor_command[n], -1, NULL, NULL, NULL);
-       editor_command_run(command, editor_name[n], list);
+       ret = editor_command_run(command, editor_name[n], list);
        g_free(command);
+       return ret;
 }
 
-void start_editor_from_file(gint n, const gchar *path)
+gint start_editor_from_file(gint n, const gchar *path)
 {
        GList *list;
+       gint ret;
 
-       if (!path) return;
+       if (!path) return FALSE;
 
        list = g_list_append(NULL, (gchar *)path);
-       start_editor_from_path_list(n, list);
+       ret = start_editor_from_path_list(n, list);
        g_list_free(list);
+       return ret;
 }
 
 gint editor_window_flag_set(gint n)
index b03aec7..ea2e7b3 100644 (file)
@@ -15,8 +15,8 @@
 
 
 void editor_reset_defaults(void);
-void start_editor_from_file(gint n, const gchar *path);
-void start_editor_from_path_list(gint n, GList *list);
+gint start_editor_from_file(gint n, const gchar *path);
+gint start_editor_from_path_list(gint n, GList *list);
 
 gint editor_window_flag_set(gint n);
 
index e6e6bc7..52a6c00 100644 (file)
@@ -53,7 +53,6 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk-pixbuf/gdk-pixbuf-loader.h>
 
-#include "typedefs.h"
 
 /*
  *----------------------------------------------------------------------------
 
 #define MOUSEWHEEL_SCROLL_SIZE 20
 
-#define GQVIEW_EDITOR_SLOTS 10
+#define GQVIEW_EDITOR_GENERIC_SLOTS 10
 
 #define COLOR_PROFILE_INPUTS 4
 
+#include "typedefs.h"
+
 /*
  *----------------------------------------------------------------------------
  * globals
index 7c34416..6fc4e8e 100644 (file)
@@ -199,10 +199,13 @@ static void config_window_apply(void)
 
        for(i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
                {
-               g_free(editor_name[i]);
-               editor_name[i] = NULL;
-               buf = gtk_entry_get_text(GTK_ENTRY(editor_name_entry[i]));
-               if (buf && strlen(buf) > 0) editor_name[i] = g_strdup(buf);
+               if (i < GQVIEW_EDITOR_GENERIC_SLOTS)
+                       {
+                       g_free(editor_name[i]);
+                       editor_name[i] = NULL;
+                       buf = gtk_entry_get_text(GTK_ENTRY(editor_name_entry[i]));
+                       if (buf && strlen(buf) > 0) editor_name[i] = g_strdup(buf);
+                       }
 
                g_free(editor_command[i]);
                editor_command[i] = NULL;
@@ -715,7 +718,8 @@ static void editor_default_ok_cb(GenericDialog *gd, gpointer data)
 
        for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
                {
-               gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),
+               if (i < GQVIEW_EDITOR_GENERIC_SLOTS)
+                       gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),
                                   (editor_name[i]) ? editor_name[i] : "");
                gtk_entry_set_text(GTK_ENTRY(editor_command_entry[i]),
                                   (editor_command[i]) ? editor_command[i] : "");
@@ -1117,14 +1121,22 @@ static void config_window_create(void)
                {
                gchar *buf;
 
-               buf = g_strdup_printf("%d", i+1);
-               pref_table_label(table, 0, i+1, buf, 1.0);
-               g_free(buf);
 
-               editor_name_entry[i] = gtk_entry_new();
-               gtk_entry_set_max_length(GTK_ENTRY(editor_name_entry[i]), EDITOR_NAME_MAX_LENGTH);
-               gtk_widget_set_size_request(editor_name_entry[i],80,-1);
-               if (editor_name[i]) gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),editor_name[i]);
+               if (i < GQVIEW_EDITOR_GENERIC_SLOTS)
+                       {
+                       buf = g_strdup_printf("%d", i+1);
+                       pref_table_label(table, 0, i+1, buf, 1.0);
+                       g_free(buf);
+                       editor_name_entry[i] = gtk_entry_new();
+                       gtk_entry_set_max_length(GTK_ENTRY(editor_name_entry[i]), EDITOR_NAME_MAX_LENGTH);
+                       gtk_widget_set_size_request(editor_name_entry[i],80,-1);
+                       if (editor_name[i]) gtk_entry_set_text(GTK_ENTRY(editor_name_entry[i]),editor_name[i]);
+                       }
+               else
+                       {
+                       editor_name_entry[i] = gtk_label_new(editor_name[i]);
+                       }
+               
                gtk_table_attach(GTK_TABLE (table),editor_name_entry[i],1,2,i+1,i+2,
                                 GTK_FILL | GTK_EXPAND, 0, 0, 0);
                gtk_widget_show(editor_name_entry[i]);
index 49d1710..d78c77e 100644 (file)
 #ifndef TYPEDEFS_H
 #define TYPEDEFS_H
 
+typedef enum {
+       CMD_COPY = GQVIEW_EDITOR_GENERIC_SLOTS,
+       CMD_MOVE,
+       CMD_RENAME,
+       CMD_DELETE,
+       CMD_FOLDER,
+       GQVIEW_EDITOR_SLOTS
+} SpecialEditor;
 
 typedef enum {
        SORT_NONE,
index 2bfa526..6051d0e 100644 (file)
@@ -1233,6 +1233,11 @@ static gint file_util_unlink(const gchar *path)
 
        if (!isfile(path)) return FALSE;
 
+       if (editor_command[CMD_DELETE])
+               {
+               return start_editor_from_file(CMD_DELETE, path);
+               }
+
        if (!safe_delete_enable)
                {
                return unlink_file(path);