xmpedit

GTK+ editor for XMP metadata embedded in images
git clone https://code.djc.id.au/git/xmpedit/
commit f810675dde348f60ed6d8f84fc8d7877063406ec
parent e3792fc84f64bd20d923dd7194fca1bd2036d6a2
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sun, 18 Jul 2010 18:43:59 +1000

actually displaying something now

--HG--
rename : src/PropertyEditor.vala => src/ImageMetadata.vala

Diffstat:
Asrc/ImageMetadata.vala | 47+++++++++++++++++++++++++++++++++++++++++++++++
Msrc/MainWindow.vala | 14++++----------
Dsrc/MetadataTreeModel.vala | 17-----------------
Msrc/MetadataTreeView.vala | 30+++++++++++++++++++++++++++---
Dsrc/PropertyEditor.vala | 19-------------------
Msrc/wscript_build | 6+++---
Msrc/xmpedit.vala | 15+++++++--------
Mwscript | 1+
8 files changed, 89 insertions(+), 60 deletions(-)
diff --git a/src/ImageMetadata.vala b/src/ImageMetadata.vala
@@ -0,0 +1,47 @@
+
+namespace XmpEdit {
+
+public class PropertyEditor : Object {
+
+    public string prop { get; construct; }
+    public string value { get; construct; }
+    
+    public PropertyEditor(string prop, string value) {
+        Object(prop: prop, value: value);
+    }
+    
+    public string get_list_markup() {
+	    return @"<b>Unknown property ($prop)</b>\n$value";
+	}
+	
+}
+
+public class ImageMetadata : Object {
+
+    private GExiv2.Metadata exiv_metadata;
+    public string path { get; construct; }
+    public Gee.List<PropertyEditor> properties { get; construct; }
+    
+    public signal void updated();
+    
+    public ImageMetadata(string path) {
+        Object(path: path);
+    }
+    
+    construct {
+        properties = new Gee.LinkedList<PropertyEditor>();
+        exiv_metadata = new GExiv2.Metadata();
+    }
+    
+    // ugh, for exceptions
+    public void load() throws GLib.Error {
+        exiv_metadata.open_path(path);
+        foreach (var tag in exiv_metadata.get_xmp_tags()) {
+            properties.add(new PropertyEditor(tag, exiv_metadata.get_xmp_tag_string(tag)));
+        }
+        updated();
+    }
+
+}
+
+}
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
@@ -3,27 +3,21 @@ namespace XmpEdit {
 
 public class MainWindow : Gtk.Window {
 
-    private GExiv2.Metadata image_metadata;
-    private PropertyEditor[] property_editors;
+    private ImageMetadata image_metadata;
     private Gtk.Table table;
     private Gtk.Image image_preview;
     private Gtk.ScrolledWindow tree_view_scrolled;
-    private MetadataTreeModel model;
     private MetadataTreeView tree_view;
     private Gtk.ScrolledWindow detail_scrolled;
     
     public MainWindow(string path) throws GLib.Error {
         Object(type: Gtk.WindowType.TOPLEVEL);
-        image_metadata = new GExiv2.Metadata();
-        image_metadata.open_path(path);
-        //for (Exiv2::XmpData::iterator i = data.begin(); i != data.end(); ++ i) {
-        //    property_editors.push_back(PropertyEditor::create(*i));
-        //}
+        image_metadata = new ImageMetadata(path);
+        image_metadata.load();
         table = new Gtk.Table(/* rows */ 2, /* cols */ 2, /* homogeneous */ false);
         image_preview = new Gtk.Image.from_pixbuf(new Gdk.Pixbuf.from_file_at_scale(path, 320, 320, /* preserve aspect */ true));
         tree_view_scrolled = new Gtk.ScrolledWindow(null, null);
-        model = new MetadataTreeModel({ });
-        tree_view = new MetadataTreeView(model);
+        tree_view = new MetadataTreeView.connected_to(image_metadata);
         
         title = File.new_for_path(path).get_basename();
         default_width = 640;
diff --git a/src/MetadataTreeModel.vala b/src/MetadataTreeModel.vala
@@ -1,17 +0,0 @@
-
-namespace XmpEdit {
-
-public class MetadataTreeModel : Gtk.ListStore {
-
-    public MetadataTreeModel(PropertyEditor[] property_editors) {
-        set_column_types({ typeof(string) });
-        foreach (var property_editor in property_editors) {
-            Gtk.TreeIter row;
-            append(out row);
-            set_value(row, 1, property_editor.get_list_markup());
-        }
-    }
-
-}
-
-}
diff --git a/src/MetadataTreeView.vala b/src/MetadataTreeView.vala
@@ -1,17 +1,41 @@
 
 namespace XmpEdit {
 
+public class MetadataTreeModel : Gtk.ListStore {
+
+    public MetadataTreeModel() {
+        set_column_types({ typeof(string) });
+    }
+    
+    public void populate(ImageMetadata metadata) {
+        clear(); // XXX probably inefficient
+        foreach (var property_editor in metadata.properties) {
+            Gtk.TreeIter row;
+            append(out row);
+            set_value(row, 0, property_editor.get_list_markup());
+        }
+    }
+
+}
+
 public class MetadataTreeView : Gtk.TreeView {
 
-    public MetadataTreeView(MetadataTreeModel model) {
-        set_model(model);
+    private MetadataTreeModel custom_model = new MetadataTreeModel();
+
+    public MetadataTreeView.connected_to(ImageMetadata metadata) {
+        model = custom_model;
+        custom_model.populate(metadata);
+        metadata.updated.connect((t) => { custom_model.populate(t); });
+    }
+    
+    construct {
         Gtk.TreeViewColumn column = new Gtk.TreeViewColumn();
         column.title = "Image properties";
         column.sizing = Gtk.TreeViewColumnSizing.FIXED;
         column.fixed_width = 300;
         Gtk.CellRendererText cell_renderer = new Gtk.CellRendererText();
         column.pack_start(cell_renderer, /* expand */ true);
-        column.add_attribute(cell_renderer, "markup", 1);
+        column.add_attribute(cell_renderer, "markup", 0);
         append_column(column);
     }
 
diff --git a/src/PropertyEditor.vala b/src/PropertyEditor.vala
@@ -1,19 +0,0 @@
-
-namespace XmpEdit {
-
-public class PropertyEditor : Object {
-
-    public string prop { get; construct; }
-    public string value { get; construct; }
-    
-    public PropertyEditor(string prop, string value) {
-        Object(prop: prop, value: value);
-    }
-    
-    public string get_list_markup() {
-	    return @"<b>Unknown property ($prop)</b>\n$value";
-	}
-	
-}
-
-}
diff --git a/src/wscript_build b/src/wscript_build
@@ -1,7 +1,7 @@
 bld(
-    features        = ['cc', 'cprogram'],
+    features        = ['c', 'cprogram'],
     source          = bld.path.ant_glob('*.vala'),
     target          = 'xmpedit',
-    packages        = ['gtk+-2.0', 'gexiv2'],
-    uselib          = ['GTK+-2.0', 'GEXIV2']
+    packages        = ['gtk+-2.0', 'gexiv2', 'gee-1.0'],
+    uselib          = ['GTK+-2.0', 'GEXIV2', 'GEE-1.0']
 )
diff --git a/src/xmpedit.vala b/src/xmpedit.vala
@@ -2,14 +2,13 @@
 namespace XmpEdit {
 
 public static int main (string[] args) {
-    //Glib::OptionContext options("PHOTO_FILENAME");
-    //Gtk::Main kit(argc, argv, options);
-    //if (argc < 2) {
-    //    std::cerr << argv[0] << ": no photo filename supplied" << std::endl;
-    //    exit(2);
-    //}
-    Gtk.init(ref args);
-    MainWindow main_window = new MainWindow("test.jpg");
+    Gtk.init_with_args(ref args, "PHOTO_FILENAME", { }, /* translation_domain */ null);
+    if (args.length < 2) {
+        stderr.puts("xmpedit: no photo filename supplied\n");
+        return 2;
+    }
+    var path = args[1];
+    MainWindow main_window = new MainWindow(path);
     main_window.destroy.connect(Gtk.main_quit);
     main_window.show_all();
     Gtk.main();
diff --git a/wscript b/wscript
@@ -10,6 +10,7 @@ def options(opt):
 def configure(conf):
     conf.check_tool('compiler_cc vala')
     conf.check_cfg(package='gtk+-2.0', atleast_version='2.18.0', args='--cflags --libs', mandatory=True)
+    conf.check_cfg(package='gee-1.0', args='--cflags --libs', mandatory=True)
     conf.check_cfg(package='gexiv2', args='--cflags --libs', mandatory=True)
 
 def build(bld):