commit e3792fc84f64bd20d923dd7194fca1bd2036d6a2
parent fdb6f12a57cf57a008485b09a1c363b55278267d
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 17 Jul 2010 17:40:15 +1000
ported to vala
--HG--
rename : src/MainWindow.cpp => src/MainWindow.vala
rename : src/MetadataTreeModel.cpp => src/MetadataTreeModel.vala
rename : src/MetadataTreeView.cpp => src/MetadataTreeView.vala
rename : src/PropertyEditor.cpp => src/PropertyEditor.vala
rename : src/xmpedit.cpp => src/xmpedit.vala
Diffstat:
16 files changed, 140 insertions(+), 260 deletions(-)
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
@@ -1,50 +0,0 @@
-
-#include <giomm/file.h>
-#include <exiv2/convert.hpp>
-#include "MainWindow.h"
-
-MainWindow::MainWindow(const std::string& path) :
- image(Exiv2::ImageFactory::open(path)),
- table(/* rows */ 2, /* cols */ 2),
- image_preview(Gdk::Pixbuf::create_from_file(path, 320, 320)),
- model(MetadataTreeModel::create(property_editors)),
- tree_view(model) {
-
- image->readMetadata();
- Exiv2::XmpData data = image->xmpData();
- for (Exiv2::XmpData::iterator i = data.begin(); i != data.end(); ++ i) {
- property_editors.push_back(PropertyEditor::create(*i));
- }
-
- {
- Glib::RefPtr<Gio::File> file(Gio::File::create_for_path(path));
- set_title(file->get_basename());
- }
- set_default_size(640, 480);
- property_allow_shrink() = true;
-
- table.attach(image_preview,
- 1, 2, 0, 1,
- Gtk::FILL | Gtk::EXPAND, Gtk::FILL,
- 10, 10);
-
- tree_view_scrolled.add(tree_view);
- tree_view_scrolled.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
- table.attach(tree_view_scrolled,
- 0, 1, 0, 2,
- Gtk::FILL, Gtk::FILL | Gtk::EXPAND,
- 0, 0);
-
- detail_scrolled.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
- table.attach(detail_scrolled,
- 1, 2, 1, 2,
- Gtk::FILL | Gtk::EXPAND, Gtk::FILL | Gtk::EXPAND,
- 0, 0);
-
- add(table);
- show_all_children();
-
-}
-
-MainWindow::~MainWindow() {
-}
diff --git a/src/MainWindow.h b/src/MainWindow.h
@@ -1,34 +0,0 @@
-
-#ifndef MAINWINDOW_H_
-#define MAINWINDOW_H_
-
-#include <vector>
-#include <exiv2/image.hpp>
-#include "PropertyEditor.h"
-#include "MetadataTreeModel.h"
-#include "MetadataTreeView.h"
-#include <gtkmm/treeview.h>
-#include <gtkmm/scrolledwindow.h>
-#include <gtkmm/table.h>
-#include <gtkmm/alignment.h>
-#include <gtkmm/window.h>
-
-class MainWindow : public Gtk::Window {
-
-public:
- MainWindow(const std::string& path);
- virtual ~MainWindow();
-
-private:
- Exiv2::Image::AutoPtr image;
- std::vector<boost::shared_ptr<PropertyEditor> > property_editors;
- Gtk::Table table;
- Gtk::Image image_preview;
- Gtk::ScrolledWindow tree_view_scrolled;
- Glib::RefPtr<MetadataTreeModel> model;
- MetadataTreeView tree_view;
- Gtk::ScrolledWindow detail_scrolled;
-
-};
-
-#endif /* MAINWINDOW_H_ */
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
@@ -0,0 +1,51 @@
+
+namespace XmpEdit {
+
+public class MainWindow : Gtk.Window {
+
+ private GExiv2.Metadata image_metadata;
+ private PropertyEditor[] property_editors;
+ 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));
+ //}
+ 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);
+
+ title = File.new_for_path(path).get_basename();
+ default_width = 640;
+ default_height = 480;
+ allow_shrink = true;
+
+ table.attach(image_preview,
+ 1, 2, 0, 1,
+ Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL,
+ 10, 10);
+
+ tree_view_scrolled.add(tree_view);
+ tree_view_scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+ table.attach(tree_view_scrolled,
+ 0, 1, 0, 2,
+ Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND,
+ 0, 0);
+
+ add(table);
+ show_all();
+ }
+
+}
+
+}
diff --git a/src/MetadataTreeModel.cpp b/src/MetadataTreeModel.cpp
@@ -1,20 +0,0 @@
-
-#include "MetadataTreeModel.h"
-
-MetadataTreeModel::MetadataTreeModel(const std::vector<boost::shared_ptr<PropertyEditor> >& property_editors) {
- set_column_types(columns);
-
- for (std::vector<boost::shared_ptr<PropertyEditor> >::const_iterator i = property_editors.begin();
- i != property_editors.end(); ++ i) {
- Row row(*append());
- row[columns.markup_column] = (*i)->get_list_markup();
- }
-}
-
-MetadataTreeModel::~MetadataTreeModel(void) {
-}
-
-Glib::RefPtr<MetadataTreeModel> MetadataTreeModel::create(
- const std::vector<boost::shared_ptr<PropertyEditor> >& property_editors) {
- return Glib::RefPtr<MetadataTreeModel>(new MetadataTreeModel(property_editors));
-}
diff --git a/src/MetadataTreeModel.h b/src/MetadataTreeModel.h
@@ -1,31 +0,0 @@
-
-#ifndef METADATATREEMODEL_H_
-#define METADATATREEMODEL_H_
-
-#include <vector>
-#include <gtkmm/liststore.h>
-#include "PropertyEditor.h"
-
-class MetadataTreeModel : public Gtk::ListStore {
-
-private:
- MetadataTreeModel(const std::vector<boost::shared_ptr<PropertyEditor> >& property_editors);
-
-public:
- virtual ~MetadataTreeModel(void);
- static Glib::RefPtr<MetadataTreeModel> create(const std::vector<boost::shared_ptr<PropertyEditor> >& property_editors);
-
-private:
- struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
- Gtk::TreeModelColumn<Glib::ustring> markup_column; // XXX lame?
- ModelColumns(void) {
- add(markup_column);
- }
- };
-
-public:
- ModelColumns columns;
-
-};
-
-#endif /* METADATATREEMODEL_H_ */
diff --git a/src/MetadataTreeModel.vala b/src/MetadataTreeModel.vala
@@ -0,0 +1,17 @@
+
+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.cpp b/src/MetadataTreeView.cpp
@@ -1,16 +0,0 @@
-
-#include "MetadataTreeView.h"
-
-MetadataTreeView::MetadataTreeView(Glib::RefPtr<MetadataTreeModel> model) :
- column("Image properties") {
- set_model(model);
- cell_renderer.property_ellipsize() = Pango::ELLIPSIZE_END;
- column.set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
- column.set_fixed_width(300);
- column.pack_start(cell_renderer, true);
- column.add_attribute(cell_renderer.property_markup(), model->columns.markup_column);
- append_column(column);
-}
-
-MetadataTreeView::~MetadataTreeView(void) {
-}
diff --git a/src/MetadataTreeView.h b/src/MetadataTreeView.h
@@ -1,21 +0,0 @@
-
-#ifndef METADATATREEVIEW_H_
-#define METADATATREEVIEW_H_
-
-#include <gtkmm/treeview.h>
-#include <gtkmm/cellrenderertext.h>
-#include "MetadataTreeModel.h"
-
-class MetadataTreeView : public Gtk::TreeView {
-
-public:
- MetadataTreeView(Glib::RefPtr<MetadataTreeModel> model);
- virtual ~MetadataTreeView(void);
-
-private:
- Gtk::CellRendererText cell_renderer;
- Gtk::TreeView::Column column;
-
-};
-
-#endif /* METADATATREEVIEW_H_ */
diff --git a/src/MetadataTreeView.vala b/src/MetadataTreeView.vala
@@ -0,0 +1,20 @@
+
+namespace XmpEdit {
+
+public class MetadataTreeView : Gtk.TreeView {
+
+ public MetadataTreeView(MetadataTreeModel model) {
+ set_model(model);
+ 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);
+ append_column(column);
+ }
+
+}
+
+}
diff --git a/src/PropertyEditor.cpp b/src/PropertyEditor.cpp
@@ -1,30 +0,0 @@
-
-#include "PropertyEditor.h"
-
-class UnrecognisedPropertyEditor : public PropertyEditor {
-
-private:
- Exiv2::Xmpdatum& xmp_property;
-
-public:
- UnrecognisedPropertyEditor(Exiv2::Xmpdatum& xmp_property) :
- xmp_property(xmp_property) {
- }
-
- virtual ~UnrecognisedPropertyEditor(void) {
- }
-
- virtual Glib::ustring get_list_markup(void) const {
- Glib::ustring markup("<b>Unknown property (");
- markup += xmp_property.groupName();
- markup += ":";
- markup += xmp_property.tagName();
- markup += ")</b>\n";
- markup += xmp_property.value().toString(); // XXX escape
- return markup;
- }
-};
-
-boost::shared_ptr<PropertyEditor> PropertyEditor::create(Exiv2::Xmpdatum& xmp_property) {
- return boost::shared_ptr<PropertyEditor>(new UnrecognisedPropertyEditor(xmp_property));
-}
diff --git a/src/PropertyEditor.h b/src/PropertyEditor.h
@@ -1,21 +0,0 @@
-
-#ifndef PROPERTYEDITOR_H_
-#define PROPERTYEDITOR_H_
-
-#include <boost/shared_ptr.hpp>
-#include <glibmm/ustring.h>
-#include <exiv2/xmp.hpp>
-
-class PropertyEditor {
-
-public:
- virtual ~PropertyEditor(void) {
- }
-
- virtual Glib::ustring get_list_markup(void) const = 0;
-
- static boost::shared_ptr<PropertyEditor> create(Exiv2::Xmpdatum& xmp_property);
-
-};
-
-#endif /* PROPERTYEDITOR_H_ */
diff --git a/src/PropertyEditor.vala b/src/PropertyEditor.vala
@@ -0,0 +1,19 @@
+
+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
@@ -0,0 +1,7 @@
+bld(
+ features = ['cc', 'cprogram'],
+ source = bld.path.ant_glob('*.vala'),
+ target = 'xmpedit',
+ packages = ['gtk+-2.0', 'gexiv2'],
+ uselib = ['GTK+-2.0', 'GEXIV2']
+)
diff --git a/src/xmpedit.cpp b/src/xmpedit.cpp
@@ -1,25 +0,0 @@
-
-#include <gtkmm/main.h>
-#include <glibmm/optioncontext.h>
-
-#include "MainWindow.h"
-
-int main(int argc, char *argv[]) {
- try {
- 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);
- }
- MainWindow window(argv[1]);
- Gtk::Main::run(window);
- return 0;
- } catch (Glib::OptionError e) {
- std::cerr << argv[0] << ": option error: " << e.what() << std::endl;
- exit(1);
- } catch (Exiv2::Error e) {
- std::cerr << argv[0] << ": exiv2 error: " << e.what() << std::endl;
- exit(3);
- }
-}
diff --git a/src/xmpedit.vala b/src/xmpedit.vala
@@ -0,0 +1,19 @@
+
+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");
+ main_window.destroy.connect(Gtk.main_quit);
+ main_window.show_all();
+ Gtk.main();
+ return 0;
+}
+
+}
diff --git a/wscript b/wscript
@@ -3,19 +3,14 @@ VERSION = '0.1'
top = '.'
out = 'target'
-def set_options(opt):
- opt.tool_options('compiler_cxx')
+def options(opt):
+ opt.tool_options('compiler_cc')
+ opt.tool_options('vala')
def configure(conf):
- conf.check_tool('compiler_cxx')
- conf.check_cfg(package='gtkmm-2.4', args='--cflags --libs', mandatory=True)
- conf.check_cfg(package='giomm-2.4', args='--cflags --libs', mandatory=True)
- conf.check_cfg(package='exiv2', args='--cflags --libs', mandatory=True)
+ 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='gexiv2', args='--cflags --libs', mandatory=True)
def build(bld):
- bld(
- features = ['cxx', 'cprogram'],
- source = bld.path.ant_glob('src/*.cpp'),
- target = 'xmpedit',
- uselib = ['GTKMM-2.4', 'GIOMM-2.4', 'EXIV2']
- )
+ bld.add_subdirs('src')