Skip to content

Commit

Permalink
started implementation of external commands; external Delete should work
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Aug 15, 2007
1 parent 57c15b1 commit 19d0a14
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 27 deletions.
35 changes: 24 additions & 11 deletions src/editors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/editors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions src/gqview.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixbuf-loader.h>

#include "typedefs.h"

/*
*----------------------------------------------------------------------------
Expand All @@ -77,10 +76,12 @@

#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
Expand Down
36 changes: 24 additions & 12 deletions src/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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] : "");
Expand Down Expand Up @@ -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]);
Expand Down
8 changes: 8 additions & 0 deletions src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
#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,
Expand Down
5 changes: 5 additions & 0 deletions src/utilops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 19d0a14

Please sign in to comment.