[niepce] Save the properties being edited
- From: Hubert FiguiÃre <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Save the properties being edited
- Date: Sat, 12 Nov 2011 06:17:51 +0000 (UTC)
commit 504fcdf8648897038866bd0b5b78287de9f165b2
Author: Hub Figuiere <hub figuiere net>
Date: Fri Nov 11 19:28:45 2011 -0800
Save the properties being edited
src/engine/db/libfile.cpp | 39 +++++++++--
src/engine/db/libfile.hpp | 6 +-
src/fwk/base/propertybag.hpp | 12 +++-
src/fwk/toolkit/metadatawidget.cpp | 38 +++++++----
src/fwk/toolkit/metadatawidget.hpp | 3 +
src/libraryclient/libraryclient.cpp | 5 +-
src/libraryclient/libraryclient.hpp | 3 +-
src/niepce/ui/imageliststore.cpp | 2 +-
src/niepce/ui/selectioncontroller.cpp | 115 ++++++++++++++++-----------------
src/niepce/ui/selectioncontroller.hpp | 8 ++-
10 files changed, 143 insertions(+), 88 deletions(-)
---
diff --git a/src/engine/db/libfile.cpp b/src/engine/db/libfile.cpp
index 3e781ee..7fa6406 100644
--- a/src/engine/db/libfile.cpp
+++ b/src/engine/db/libfile.cpp
@@ -20,7 +20,7 @@
#include "fwk/base/debug.hpp"
#include "libfile.hpp"
-#include "metadata.hpp"
+#include "properties.hpp"
namespace eng {
@@ -68,20 +68,43 @@ void LibFile::setFileType(FileType v)
m_file_type = v;
}
-void LibFile::setMetaData(int meta, int32_t v)
+void LibFile::setProperty(fwk::PropertyIndex idx, int32_t v)
{
- switch(meta) {
- case MAKE_METADATA_IDX(eng::META_NS_XMPCORE, eng::META_XMPCORE_RATING):
+ switch(idx) {
+ case NpTiffOrientationProp:
+ setOrientation(v);
+ break;
+ case NpXmpRatingProp:
setRating(v);
break;
- case MAKE_METADATA_IDX(eng::META_NS_TIFF, eng::META_TIFF_ORIENTATION):
- setOrientation(v);
+ case NpXmpLabelProp:
+ setLabel(v);
+ break;
+ case NpNiepceFlagProp:
+ setFlag(v);
+ break;
+ default:
+ ERR_OUT("set property %u not handled", idx);
break;
+ }
+}
+
+int32_t LibFile::property(fwk::PropertyIndex idx) const
+{
+ switch(idx) {
+ case NpTiffOrientationProp:
+ return orientation();
+ case NpXmpRatingProp:
+ return rating();
+ case NpXmpLabelProp:
+ return label();
+ case NpNiepceFlagProp:
+ return flag();
default:
- // TODO deal with label as well
- ERR_OUT("unknown meta %d", meta);
+ ERR_OUT("get property %u not handled", idx);
break;
}
+ return -1;
}
/**
diff --git a/src/engine/db/libfile.hpp b/src/engine/db/libfile.hpp
index bbc3646..27f6bac 100644
--- a/src/engine/db/libfile.hpp
+++ b/src/engine/db/libfile.hpp
@@ -25,6 +25,7 @@
#include <tr1/memory>
#include "fwk/toolkit/mimetype.hpp"
+#include "fwk/base/propertybag.hpp"
#include "engine/db/librarytypes.hpp"
#include "engine/db/keyword.hpp"
#include "engine/db/storage.hpp"
@@ -78,6 +79,8 @@ public:
void setFlag(int32_t v);
int32_t flag() const
{ return m_flag; }
+ void setProperty(fwk::PropertyIndex idx, int32_t v);
+ int32_t property(fwk::PropertyIndex idx) const;
/** Setter for the filetype.
* @param v the FILETYPE of the file
@@ -87,9 +90,6 @@ public:
FileType fileType() const
{ return m_file_type; }
- /** set an arbitrary meta data value */
- void setMetaData(int meta, int32_t v);
-
/** return an URI of the real path
* because the Gtk stuff want that.
*/
diff --git a/src/fwk/base/propertybag.hpp b/src/fwk/base/propertybag.hpp
index 4200ac5..638c10f 100644
--- a/src/fwk/base/propertybag.hpp
+++ b/src/fwk/base/propertybag.hpp
@@ -42,11 +42,22 @@ class PropertyBag
{
public:
typedef std::tr1::shared_ptr<PropertyBag> Ptr;
+ typedef std::map<PropertyIndex, PropertyValue> _Map;
+ typedef _Map::const_iterator const_iterator;
bool empty() const
{
return m_bag.empty();
}
+
+ const_iterator begin() const
+ {
+ return m_bag.begin();
+ }
+ const_iterator end() const
+ {
+ return m_bag.end();
+ }
/** return true if a property was removed prior to insertion */
bool set_value_for_property(PropertyIndex idx, const PropertyValue & value);
@@ -57,7 +68,6 @@ public:
/** return true if the property was removed */
bool remove_value_for_property(PropertyIndex idx);
private:
- typedef std::map<PropertyIndex, PropertyValue> _Map;
_Map m_bag;
};
diff --git a/src/fwk/toolkit/metadatawidget.cpp b/src/fwk/toolkit/metadatawidget.cpp
index 35e0c61..904a95f 100644
--- a/src/fwk/toolkit/metadatawidget.cpp
+++ b/src/fwk/toolkit/metadatawidget.cpp
@@ -27,6 +27,7 @@
#include <gtkmm/entry.h>
#include "fwk/base/debug.hpp"
+#include "fwk/base/autoflag.hpp"
#include "fwk/base/fractions.hpp"
#include "fwk/utils/exempi.hpp"
#include "fwk/utils/stringutils.hpp"
@@ -44,7 +45,8 @@ namespace fwk {
MetaDataWidget::MetaDataWidget(const Glib::ustring & title)
: ToolboxItemWidget(title),
m_table(1, 2, false),
- m_fmt(NULL)
+ m_fmt(NULL),
+ m_update(false)
{
add(m_table);
}
@@ -54,10 +56,9 @@ void MetaDataWidget::set_data_format(const MetaDataSectionFormat * fmt)
m_fmt = fmt;
}
-namespace {
-static
-void clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p)
+void MetaDataWidget::clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p)
{
+ AutoFlag flag(m_update);
Gtk::Label * l = dynamic_cast<Gtk::Label*>(p.second);
if(l) {
l->set_text("");
@@ -74,14 +75,13 @@ void clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p)
return;
}
}
-}
void MetaDataWidget::set_data_source(const fwk::PropertyBag & properties)
{
DBG_OUT("set data source");
if(!m_data_map.empty()) {
std::for_each(m_data_map.begin(), m_data_map.end(),
- boost::bind(&clear_widget, _1));
+ boost::bind(&MetaDataWidget::clear_widget, this, _1));
}
if(properties.empty()) {
return;
@@ -140,8 +140,6 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
w = r;
}
else {
- // TODO make it editable
-
if(current->readonly) {
Gtk::Label * l = Gtk::manage(new Gtk::Label());
l->set_alignment(0.0f, 0.5f);
@@ -174,6 +172,7 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
try {
double decimal = fwk::fraction_to_decimal(boost::get<std::string>(value));
std::string frac = boost::lexical_cast<std::string>(decimal);
+ AutoFlag flag(m_update);
static_cast<Gtk::Label*>(w)->set_text(frac);
}
catch(...) {
@@ -185,6 +184,7 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
{
try {
int rating = boost::get<int>(value);
+ AutoFlag flag(m_update);
static_cast<fwk::RatingLabel*>(w)->set_rating(rating);
}
catch(...) {
@@ -192,12 +192,18 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
}
break;
}
- default:
- if(current->readonly) {
- static_cast<Gtk::Label*>(w)->set_text(boost::get<std::string>(value));
+ default:
+ try {
+ AutoFlag flag(m_update);
+ if(current->readonly) {
+ static_cast<Gtk::Label*>(w)->set_text(boost::get<std::string>(value));
+ }
+ else {
+ static_cast<Gtk::Entry*>(w)->set_text(boost::get<std::string>(value));
+ }
}
- else {
- static_cast<Gtk::Entry*>(w)->set_text(boost::get<std::string>(value));
+ catch(...) {
+ DBG_OUT("conversion of '%u' to string failed", current->id);
}
break;
}
@@ -206,6 +212,9 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
void MetaDataWidget::on_str_changed(Gtk::Entry *e, fwk::PropertyIndex prop)
{
+ if(m_update) {
+ return;
+ }
fwk::PropertyBag props;
props.set_value_for_property(prop, fwk::PropertyValue(e->get_text()));
signal_metadata_changed.emit(props);
@@ -213,6 +222,9 @@ void MetaDataWidget::on_str_changed(Gtk::Entry *e, fwk::PropertyIndex prop)
void MetaDataWidget::on_int_changed(int value, fwk::PropertyIndex prop)
{
+ if(m_update) {
+ return;
+ }
fwk::PropertyBag props;
props.set_value_for_property(prop, fwk::PropertyValue(value));
signal_metadata_changed.emit(props);
diff --git a/src/fwk/toolkit/metadatawidget.hpp b/src/fwk/toolkit/metadatawidget.hpp
index f7997cd..5db4120 100644
--- a/src/fwk/toolkit/metadatawidget.hpp
+++ b/src/fwk/toolkit/metadatawidget.hpp
@@ -77,9 +77,12 @@ protected:
void on_str_changed(Gtk::Entry *, fwk::PropertyIndex prop);
void on_int_changed(int, fwk::PropertyIndex prop);
private:
+ void clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p);
+
Gtk::Table m_table;
std::map<const PropertyIndex, Gtk::Widget *> m_data_map;
const MetaDataSectionFormat * m_fmt;
+ bool m_update;
};
}
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index d7065b2..09615f0 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -85,9 +85,10 @@ eng::tid_t LibraryClient::requestMetadata(eng::library_id_t id)
}
/** set the metadata */
-eng::tid_t LibraryClient::setMetadata(library_id_t id, int meta, int value)
+eng::tid_t LibraryClient::setMetadata(library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value)
{
- return m_pImpl->setMetadata(id, meta, value);
+ // FIXME we should pass the value directly
+ return m_pImpl->setMetadata(id, meta, boost::get<int>(value));
}
eng::tid_t LibraryClient::getAllLabels()
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 1095592..91b7ff4 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -23,6 +23,7 @@
#include <string>
#include <tr1/memory>
+#include "fwk/base/propertybag.hpp"
#include "engine/library/clienttypes.hpp"
#include "engine/library/thumbnailcache.hpp"
#include "engine/db/librarytypes.hpp"
@@ -64,7 +65,7 @@ namespace libraryclient {
eng::tid_t requestMetadata(eng::library_id_t id);
/** set the metadata */
- eng::tid_t setMetadata(eng::library_id_t id, int meta, int value);
+ eng::tid_t setMetadata(eng::library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value);
/** get all the labels */
eng::tid_t getAllLabels();
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index 0a089a9..2fba801 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -110,7 +110,7 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
row = *(iter->second);
//
eng::LibFile::Ptr file = row[m_columns.m_libfile];
- file->setMetaData(m.meta, m.value);
+ file->setProperty(m.meta, m.value);
row[m_columns.m_libfile] = file;
}
break;
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index 0282194..fbcb2fb 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -30,6 +30,7 @@
#include "fwk/toolkit/command.hpp"
#include "fwk/toolkit/application.hpp"
#include "engine/db/metadata.hpp"
+#include "engine/db/properties.hpp"
#include "libraryclient/libraryclient.hpp"
#include "niepcewindow.hpp"
#include "selectioncontroller.hpp"
@@ -174,101 +175,99 @@ void SelectionController::rotate(int angle)
}
-bool SelectionController::_set_metadata(const std::string & undo_label, const eng::LibFile::Ptr & file,
- int meta, int old_value, int new_value)
+bool SelectionController::_set_metadata(const std::string & undo_label,
+ const eng::LibFile::Ptr & file,
+ fwk::PropertyIndex meta,
+ int old_value, int new_value)
{
fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(undo_label);
undo->new_command<void>(
boost::bind(&libraryclient::LibraryClient::setMetadata,
- getLibraryClient(), file->id(), meta, new_value),
+ getLibraryClient(), file->id(), meta, fwk::PropertyValue(new_value)),
boost::bind(&libraryclient::LibraryClient::setMetadata,
- getLibraryClient(), file->id(), meta, old_value)
+ getLibraryClient(), file->id(), meta, fwk::PropertyValue(old_value))
);
undo->execute();
return true;
}
+bool SelectionController::_set_metadata(const std::string & undo_label,
+ const eng::LibFile::Ptr & file,
+ const fwk::PropertyBag & props)
+{
+ fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(undo_label);
+ for(fwk::PropertyBag::const_iterator iter = props.begin();
+ iter != props.end(); ++iter) {
+
+ undo->new_command<void>(
+ boost::bind(&libraryclient::LibraryClient::setMetadata,
+ getLibraryClient(), file->id(), iter->first, iter->second),
+ // FIXME. This make undo now work
+ boost::bind(&libraryclient::LibraryClient::setMetadata,
+ getLibraryClient(), file->id(), iter->first, iter->second)
+ );
+ }
+ undo->execute();
+ return true;
+}
void SelectionController::set_label(int label)
{
- DBG_OUT("label = %d", label);
- eng::library_id_t selection = get_selection();
- if(selection >= 0) {
- Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
- if(iter) {
- eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
- DBG_OUT("old label is %d", file->label());
- int old_value = file->label();
- _set_metadata(_("Set Label"), file,
- MAKE_METADATA_IDX(eng::META_NS_XMPCORE, eng::META_XMPCORE_LABEL),
- old_value, label);
- // we need to set the label here so that undo/redo works
- // consistently.
- file->setLabel(label);
- }
- }
+ set_property(eng::NpXmpLabelProp, label);
}
void SelectionController::set_rating(int rating)
{
- DBG_OUT("rating = %d", rating);
- eng::library_id_t selection = get_selection();
- if(selection >= 0) {
- Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
- if(iter) {
- eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
- DBG_OUT("old rating is %d", file->rating());
- int old_value = file->rating();
- _set_metadata(_("Set Rating"), file,
- MAKE_METADATA_IDX(eng::META_NS_XMPCORE, eng::META_XMPCORE_RATING),
- old_value, rating);
- // we need to set the rating here so that undo/redo works
- // consistently.
- file->setRating(rating);
- }
- }
+ set_property(eng::NpXmpRatingProp, rating);
}
void SelectionController::set_flag(int flag)
{
- DBG_OUT("flag = %d", flag);
+ set_property(eng::NpNiepceFlagProp, flag);
+}
+
+void SelectionController::set_property(fwk::PropertyIndex idx, int value)
+{
+ DBG_OUT("property %u = %d", idx, value);
eng::library_id_t selection = get_selection();
if(selection >= 0) {
Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
if(iter) {
eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
- DBG_OUT("old flag is %d", file->flag());
- int old_value = file->flag();
- _set_metadata(_("Set Flag"), file,
- MAKE_METADATA_IDX(eng::META_NS_NIEPCE, eng::META_NIEPCE_FLAG),
- old_value, flag);
- // we need to set the flag here so that undo/redo works
+ DBG_OUT("old property is %d", file->property(idx));
+ int old_value = file->property(idx);
+ const char *action = NULL;
+ switch(idx) {
+ case eng::NpNiepceFlagProp:
+ action = _("Set Flag");
+ break;
+ case eng::NpXmpRatingProp:
+ action = _("Set Rating");
+ break;
+ case eng::NpXmpLabelProp:
+ action = _("Set Label");
+ break;
+ default:
+ action = _("Set Property");
+ break;
+ }
+ _set_metadata(action, file, idx, old_value, value);
+ // we need to set the property here so that undo/redo works
// consistently.
- file->setFlag(flag);
+ file->setProperty(idx, value);
}
- }
+ }
}
-
-void SelectionController::set_properties(const fwk::PropertyBag & /*props*/)
+void SelectionController::set_properties(const fwk::PropertyBag & props)
{
eng::library_id_t selection = get_selection();
if(selection >= 0) {
Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
if(iter) {
-#if 0
eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
- DBG_OUT("old flag is %d", file->flag());
- int old_value = file->flag();
- _set_metadata(_("Set Properties"), file,
- // FIXME
- MAKE_METADATA_IDX(eng::META_NS_XMPCORE, eng::META_XMPCORE_RATING),
- old_value, flag);
- // we need to set the rating here so that undo/redo works
- // consistently.
- file->setFlag(flag);
-#endif
+ _set_metadata(_("Set Properties"), file, props);
}
}
}
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index cf04770..ea6d9ab 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -91,6 +91,8 @@ public:
/** set flag */
void set_flag(int flag);
+ void set_property(fwk::PropertyIndex idx, int value);
+
void set_properties(const fwk::PropertyBag & props);
/** get the current selection
@@ -105,7 +107,11 @@ private:
bool _set_metadata(const std::string & undo_label,
const eng::LibFile::Ptr & file,
- int meta, int old_value, int new_value);
+ fwk::PropertyIndex meta,
+ int old_value, int new_value);
+ bool _set_metadata(const std::string & undo_label,
+ const eng::LibFile::Ptr & file,
+ const fwk::PropertyBag & props);
/** move the selection and emit the signal
* @param backwards true if the move is backwards.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]