xmpedit

GTK+ editor for XMP metadata embedded in images
git clone https://code.djc.id.au/git/xmpedit/
commit 8acc519882c8bca5706b7fdc81fff181f19f3603
parent 756b5bc756577244b551dbec38fd506919471793
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sun, 30 May 2010 12:04:13 +1000

display markup in property list

Diffstat:
MMainWindow.cpp | 6++----
MMainWindow.h | 3++-
MMakefile | 6++++--
MMetadataTreeModel.cpp | 16+++++++---------
MMetadataTreeModel.h | 6++----
AMetadataTreeView.cpp | 13+++++++++++++
AMetadataTreeView.h | 21+++++++++++++++++++++
7 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/MainWindow.cpp b/MainWindow.cpp
@@ -4,7 +4,8 @@
 
 MainWindow::MainWindow(const std::string& path) :
     image_preview(Gdk::Pixbuf::create_from_file(path, 320, 320)),
-    model(MetadataTreeModel::create(path)) {
+    model(MetadataTreeModel::create(path)),
+    tree_view(model) {
 
     {
         Glib::RefPtr<Gio::File> file(Gio::File::create_for_path(path));
@@ -15,9 +16,6 @@ MainWindow::MainWindow(const std::string& path) :
 
     vbox.pack_start(image_preview, Gtk::PACK_SHRINK, 10);
 
-    tree_view.set_model(model);
-    tree_view.append_column("Predicate", model->columns.pred_column);
-    tree_view.append_column("Value", model->columns.value_column);
     scrolled.add(tree_view);
     scrolled.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
     vbox.pack_start(scrolled, Gtk::PACK_EXPAND_WIDGET);
diff --git a/MainWindow.h b/MainWindow.h
@@ -3,6 +3,7 @@
 #define MAINWINDOW_H_
 
 #include "MetadataTreeModel.h"
+#include "MetadataTreeView.h"
 #include <gtkmm/treeview.h>
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/box.h>
@@ -19,7 +20,7 @@ private:
     Gtk::Image image_preview;
     Gtk::ScrolledWindow scrolled;
     Glib::RefPtr<MetadataTreeModel> model;
-    Gtk::TreeView tree_view;
+    MetadataTreeView tree_view;
 
 };
 
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@
 CXXFLAGS = -O2 -g -Wall -fmessage-length=0 $(shell pkg-config giomm-2.4 --cflags) $(shell pkg-config gtkmm-2.4 --cflags) $(shell pkg-config exiv2 --cflags)
 LDFLAGS = -Wl,-O1 -Wl,--as-needed
-OBJS = xmpedit.o MainWindow.o MetadataTreeModel.o
+OBJS = xmpedit.o MainWindow.o MetadataTreeModel.o MetadataTreeView.o
 LIBS = $(shell pkg-config giomm-2.4 --libs) $(shell pkg-config gtkmm-2.4 --libs) $(shell pkg-config exiv2 --libs)
 TARGET = xmpedit
 
@@ -9,10 +9,12 @@ $(TARGET): $(OBJS)
 
 xmpedit.o: xmpedit.cpp MainWindow.h
 
-MainWindow.o: MainWindow.cpp MainWindow.h MetadataTreeModel.h
+MainWindow.o: MainWindow.cpp MainWindow.h MetadataTreeModel.h MetadataTreeView.h
 
 MetadataTreeModel.o: MetadataTreeModel.cpp MetadataTreeModel.h
 
+MetadataTreeView.o: MetadataTreeView.cpp MetadataTreeView.h MetadataTreeModel.h
+
 .PHONY: all
 all: $(TARGET)
 
diff --git a/MetadataTreeModel.cpp b/MetadataTreeModel.cpp
@@ -11,15 +11,13 @@ MetadataTreeModel::MetadataTreeModel(const std::string& path) {
 
     for (Exiv2::XmpData::const_iterator i = data.begin(); i != data.end(); ++ i) {
         Row row(*append());
-        Glib::ustring pred(i->groupName());
-        pred += ":";
-        pred += i->tagName();
-        row[columns.pred_column] = pred;
-        Glib::ustring value(i->value().toString());
-        value += " [";
-        value += i->typeName();
-        value += "]";
-        row[columns.value_column] = value;
+        Glib::ustring markup("<b>Unknown property (");
+        markup += i->groupName();
+        markup += ":";
+        markup += i->tagName();
+        markup += ")</b>\n";
+        markup += i->value().toString(); // XXX escape
+        row[columns.markup_column] = markup;
     }
 }
 
diff --git a/MetadataTreeModel.h b/MetadataTreeModel.h
@@ -15,11 +15,9 @@ public:
 
 private:
     struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
-        Gtk::TreeModelColumn<Glib::ustring> pred_column;
-        Gtk::TreeModelColumn<Glib::ustring> value_column;
+        Gtk::TreeModelColumn<Glib::ustring> markup_column; // XXX lame?
         ModelColumns(void) {
-            add(pred_column);
-            add(value_column);
+            add(markup_column);
         }
     };
 
diff --git a/MetadataTreeView.cpp b/MetadataTreeView.cpp
@@ -0,0 +1,13 @@
+
+#include "MetadataTreeView.h"
+
+MetadataTreeView::MetadataTreeView(Glib::RefPtr<MetadataTreeModel> model) :
+	column("Image properties") {
+	set_model(model);
+	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/MetadataTreeView.h b/MetadataTreeView.h
@@ -0,0 +1,21 @@
+
+#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_ */