Commit 21f6e9e0 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

continue work on scripts

parent 55cf40f5
......@@ -124,11 +124,7 @@ gth_metadata_provider_comment_write (GthMetadataProvider *self,
GthFileData *file_data,
const char *attributes)
{
GFileAttributeMatcher *matcher;
matcher = g_file_attribute_matcher_new (attributes);
if (g_file_attribute_matcher_matches (matcher, "comment::*")) {
if (_g_file_attributes_matches (attributes, "comment::*")) {
GthComment *comment;
char *data;
gsize length;
......@@ -163,8 +159,6 @@ gth_metadata_provider_comment_write (GthMetadataProvider *self,
g_free (data);
g_object_unref (comment);
}
g_file_attribute_matcher_unref (matcher);
}
......
......@@ -45,11 +45,7 @@ gth_metadata_provider_exiv2_read (GthMetadataProvider *self,
GthFileData *file_data,
const char *attributes)
{
GFileAttributeMatcher *matcher;
matcher = g_file_attribute_matcher_new (attributes);
if (g_file_attribute_matcher_matches (matcher, "Exif::*,Iptc::*,Xmp::*")) {
if (_g_file_attributes_matches (attributes, "Exif::*,Iptc::*,Xmp::*")) {
char *uri;
char *uri_wo_ext;
char *sidecar_uri;
......@@ -78,8 +74,6 @@ gth_metadata_provider_exiv2_read (GthMetadataProvider *self,
g_free (uri_wo_ext);
g_free (uri);
}
g_file_attribute_matcher_unref (matcher);
}
......
......@@ -45,11 +45,7 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
GthFileData *file_data,
const char *attributes)
{
GFileAttributeMatcher *matcher;
matcher = g_file_attribute_matcher_new (attributes);
if (g_file_attribute_matcher_matches (matcher, "image::*")) {
if (_g_file_attributes_matches (attributes, "image::*")) {
GdkPixbufFormat *format;
GFile *cache_file;
char *filename;
......@@ -76,8 +72,6 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
g_free (filename);
g_object_unref (cache_file);
}
g_file_attribute_matcher_unref (matcher);
}
......
......@@ -16,6 +16,8 @@ liblist_tools_la_SOURCES = \
gth-script-editor-dialog.h \
gth-script-file.c \
gth-script-file.h \
gth-script-task.h \
gth-script-task.c \
main.c
liblist_tools_la_CFLAGS = $(GTHUMB_CFLAGS) $(DISABLE_DEPRECATED) $(WARNINGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
......
......@@ -26,7 +26,9 @@
#include <glib-object.h>
#include <gthumb.h>
#include "actions.h"
#include "callbacks.h"
#include "gth-script-file.h"
#include "gth-script-task.h"
#define BROWSER_DATA_KEY "list-tools-browser-data"
......@@ -76,16 +78,20 @@ activate_script_menu_item (GtkMenuItem *menuitem,
script = gth_script_file_get_script (gth_script_file_get (), g_object_get_data (G_OBJECT (menuitem), "script_id"));
if (script != NULL) {
GList *items;
GList *file_list;
GthTask *task;
GList *items;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (data->browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (data->browser)), items);
task = gth_script_get_task (script, file_list);
gth_browser_exec_task (data->browser, task);
if (file_list != NULL) {
GthTask *task;
task = gth_script_task_new (GTK_WINDOW (data->browser), script, file_list);
gth_browser_exec_task (data->browser, task);
g_object_unref (task);
}
g_object_unref (task);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
......@@ -140,6 +146,8 @@ update_scripts_menu (BrowserData *data)
else
gtk_widget_hide (separator1);
list_tools__gth_browser_update_sensitivity_cb (data->browser);
_g_object_list_unref (script_list);
}
......@@ -197,19 +205,39 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
void
list_tools__gth_browser_update_sensitivity_cb (GthBrowser *browser)
{
/*
BrowserData *data;
GthFileSource *file_source;
int n_selected;
gboolean sensitive;
BrowserData *data;
int n_selected;
gboolean sensitive;
GtkWidget *separator1;
GtkWidget *separator2;
GtkWidget *menu;
data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
g_return_if_fail (data != NULL);
file_source = gth_browser_get_location_source (browser);
n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
sensitive = (n_selected > 0);
sensitive = (n_selected > 0) && (file_source != NULL) && gth_file_source_can_cut (file_source);
gtk_widget_set_sensitive (GTK_WIDGET (data->tool_item), sensitive);
*/
separator1 = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ListToolsPopup/Tools");
separator2 = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ListToolsPopup/Scripts");
menu = gtk_widget_get_parent (separator1);
{
GList *children;
GList *scan;
children = gtk_container_get_children (GTK_CONTAINER (menu));
if (separator1 != NULL) {
for (scan = children; scan; scan = scan->next)
if (scan->data == separator1) {
scan = scan->next;
break;
}
}
else
scan = children;
for (/* void */; scan && (scan->data != separator2); scan = scan->next)
gtk_widget_set_sensitive (scan->data, sensitive);
}
}
uidir = $(datadir)/gthumb/ui
ui_DATA = personalize-scripts.ui script-editor.ui
ui_DATA = ask-value.ui personalize-scripts.ui script-editor.ui
EXTRA_DIST = $(ui_DATA)
-include $(top_srcdir)/git.mk
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="ask_value_dialog">
<property name="width_request">500</property>
<property name="border_width">5</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="request_image">
<property name="width_request">128</property>
<property name="height_request">128</property>
<property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="request_label">
<property name="visible">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="request_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="activates_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label">gtk-execute</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1">cancel_button</action-widget>
<action-widget response="2">ok_button</action-widget>
</action-widgets>
</object>
</interface>
......@@ -104,7 +104,7 @@
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="n_rows">7</property>
<property name="n_rows">10</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
......@@ -160,8 +160,8 @@
</attributes>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
</packing>
</child>
<child>
......@@ -224,8 +224,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
</packing>
</child>
<child>
......@@ -264,8 +264,8 @@
</attributes>
</object>
<packing>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="top_attach">7</property>
<property name="bottom_attach">8</property>
</packing>
</child>
<child>
......@@ -280,29 +280,29 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="top_attach">7</property>
<property name="bottom_attach">8</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" comments="Translate only 'property_name', keeping the underscore if possible.">%prop{ property_name }</property>
<property name="label" translatable="yes" comments="Translate only 'property_name', keeping the underscore if possible.">%attr{ property_name }</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="top_attach">8</property>
<property name="bottom_attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label16">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">A file property</property>
<property name="label" translatable="yes">A file attribute</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
......@@ -310,8 +310,98 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="top_attach">8</property>
<property name="bottom_attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%N</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label18">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The file basename without extension</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label19">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%E</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label20">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The file extension</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label21">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" comments="Translate only 'text'.">%quote{ text }</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">9</property>
<property name="bottom_attach">10</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label22">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Quote the text </property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">9</property>
<property name="bottom_attach">10</property>
</packing>
</child>
</object>
......
......@@ -143,7 +143,7 @@ gth_script_editor_dialog_construct (GthScriptEditorDialog *self,
gtk_window_set_title (GTK_WINDOW (self), title);
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (self), parent);
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (self)->vbox), 5);
gtk_container_set_border_width (GTK_CONTAINER (self), 5);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* GThumb
*
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "gth-script-task.h"
struct _GthScriptTaskPrivate {
GthScript *script;
GtkWindow *parent;
GList *file_list;
GList *current;
GPid pid;
guint script_watch;
GCancellable *cancellable;
};
static gpointer parent_class = NULL;
static void
gth_script_task_finalize (GObject *object)
{
GthScriptTask *self;
self = GTH_SCRIPT_TASK (object);
g_object_unref (self->priv->script);
g_object_unref (self->priv->cancellable);
_g_object_list_unref (self->priv->file_list);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void _gth_script_task_exec (GthScriptTask *self);
static void
_gth_script_task_exec_next_file (GthScriptTask *self)
{
self->priv->current = self->priv->current->next;
if (self->priv->current == NULL)
gth_task_completed (GTH_TASK (self), NULL);
else
_gth_script_task_exec (self);
}
static void
watch_script_cb (GPid pid,
int status,
gpointer data)
{
GthScriptTask *self = data;
GError *error;
g_spawn_close_pid (self->priv->pid);
self->priv->pid = 0;
self->priv->script_watch = 0;
if (status != 0) {
error = g_error_new (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, _("Command exited abnormally with status %d"), status);
gth_task_completed (GTH_TASK (self), error);
return;
}
if (gth_script_for_each_file (self->priv->script))
_gth_script_task_exec_next_file (self);
else
gth_task_completed (GTH_TASK (self), NULL);
}
static void
_gth_script_task_exec (GthScriptTask *self)
{
char *command_line;
GError *error = NULL;
gboolean retval = FALSE;
if (gth_script_for_each_file (self->priv->script)) {
GList *list;
list = g_list_prepend (NULL, self->priv->current->data);
command_line = gth_script_get_command_line (self->priv->script,
self->priv->parent,
list,
&error);
g_list_free (list);
}
else
command_line = gth_script_get_command_line (self->priv->script,
self->priv->parent,
self->priv->file_list,
&error);
if (error == NULL) {
char **argv;
argv = g_new (char *, 4);