[niepce] * Handle label color. Create a new label if need. Implement
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [niepce] * Handle label color. Create a new label if need. Implement
- Date: Mon, 20 Apr 2009 13:58:34 -0400 (EDT)
commit 6ca27049864cc84cc50ca5a3f0db50134339c9cd
Author: Hubert Figuiere <hub figuiere net>
Date: Wed Apr 15 01:07:47 2009 -0400
* Handle label color. Create a new label if need. Implement
undo/redo for label creation.
---
ChangeLog | 5 ++
src/engine/db/label.hpp | 2 +
src/engine/db/library.cpp | 22 ++++++++-
src/engine/db/library.hpp | 4 +-
src/engine/library/commands.cpp | 19 +++++++--
src/engine/library/commands.hpp | 7 ++-
src/fwk/base/color.hpp | 4 +-
src/fwk/toolkit/command.hpp | 60 +++++++++++++++++++++++++-
src/fwk/toolkit/gdkutils.cpp | 18 +++++++-
src/fwk/toolkit/gdkutils.hpp | 9 +++-
src/fwk/toolkit/undo.cpp | 9 ----
src/fwk/toolkit/undo.hpp | 14 ++++++-
src/libraryclient/clientimpl.cpp | 16 ++++++-
src/libraryclient/clientimpl.hpp | 4 +-
src/libraryclient/libraryclient.cpp | 11 ++++-
src/libraryclient/libraryclient.hpp | 6 ++-
src/niepce/ui/dialogs/editlabels.cpp | 75 ++++++++++++++++++++++++--------
src/niepce/ui/dialogs/editlabels.hpp | 3 +
src/niepce/ui/dialogs/editlabels.ui | 25 +++++++++--
src/niepce/ui/niepcewindow.cpp | 51 +++++++++++++++-------
src/niepce/ui/selectioncontroller.cpp | 10 +++--
21 files changed, 294 insertions(+), 80 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b834d0d..34a4111 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-15 Hubert Figuiere <hub figuiere net>
+
+ * Handle label color. Create a new label if need. Implement
+ undo/redo for label creation.
+
2009-04-14 Hubert Figuiere <hub figuiere net>
* Use accessors instead of struct field on GdlDock
diff --git a/src/engine/db/label.hpp b/src/engine/db/label.hpp
index 029a4e9..d9a9d15 100644
--- a/src/engine/db/label.hpp
+++ b/src/engine/db/label.hpp
@@ -54,6 +54,8 @@ public:
{ m_label = l; }
const fwk::RgbColor color() const
{ return m_color; }
+ void set_color(const fwk::RgbColor & c)
+ { m_color = c; }
private:
int m_id;
std::string m_label;
diff --git a/src/engine/db/library.cpp b/src/engine/db/library.cpp
index f585174..21b3ea7 100644
--- a/src/engine/db/library.cpp
+++ b/src/engine/db/library.cpp
@@ -800,11 +800,27 @@ int Library::addLabel(const std::string & name, const fwk::RgbColor & c)
}
-bool Library::renameLabel(int label_id, const std::string & name)
+bool Library::updateLabel(int label_id, const std::string & name, const std::string & color)
{
- SQLStatement sql(boost::format("UPDATE labels SET name='%2%'"
+ SQLStatement sql(boost::format("UPDATE labels SET name='%2%', color='%3%'"
" WHERE id='%1%';")
- % label_id % name);
+ % label_id % name % color);
+ try {
+ return m_dbdrv->execute_statement(sql);
+ }
+ catch(utils::Exception & e)
+ {
+ DBG_OUT("db exception %s", e.what());
+ }
+ return false;
+}
+
+
+bool Library::deleteLabel(int label_id)
+{
+
+ SQLStatement sql(boost::format("DELETE FROM labels "
+ " WHERE id='%1%';") % label_id);
try {
return m_dbdrv->execute_statement(sql);
}
diff --git a/src/engine/db/library.hpp b/src/engine/db/library.hpp
index 0f7852e..bf191b2 100644
--- a/src/engine/db/library.hpp
+++ b/src/engine/db/library.hpp
@@ -67,6 +67,7 @@ public:
NOTIFY_METADATA_QUERIED,
NOTIFY_METADATA_CHANGED,
NOTIFY_LABEL_CHANGED,
+ NOTIFY_LABEL_DELETED,
NOTIFY_XMP_NEEDS_UPDATE,
NOTIFY_FOLDER_COUNTED
} NotifyType;
@@ -168,7 +169,8 @@ public:
void getAllLabels(const eng::Label::ListPtr & l);
int addLabel(const std::string & name, const std::string & color);
int addLabel(const std::string & name, const fwk::RgbColor & c);
- bool renameLabel(int label_id, const std::string & name);
+ bool updateLabel(int label_id, const std::string & name, const std::string & color);
+ bool deleteLabel(int label_id);
/** Trigger the processing of the XMP update queue */
bool processXmpUpdateQueue();
diff --git a/src/engine/library/commands.cpp b/src/engine/library/commands.cpp
index f58b5cc..c9b5b2b 100644
--- a/src/engine/library/commands.cpp
+++ b/src/engine/library/commands.cpp
@@ -149,11 +149,22 @@ void Commands::cmdCreateLabel(const db::Library::Ptr & lib,
}
}
-void Commands::cmdRenameLabel(const db::Library::Ptr & lib,
- int label_id, const std::string & name)
+
+void Commands::cmdDeleteLabel(const db::Library::Ptr & lib,
+ int label_id)
+{
+ lib->deleteLabel(label_id);
+ lib->notify(Library::NOTIFY_LABEL_DELETED, boost::any(label_id));
+}
+
+
+void Commands::cmdUpdateLabel(const db::Library::Ptr & lib,
+ int label_id, const std::string & name,
+ const std::string & color)
{
- lib->renameLabel(label_id, name);
- lib->notify(Library::NOTIFY_LABEL_CHANGED, boost::any(label_id));
+ lib->updateLabel(label_id, name, color);
+ eng::Label::Ptr label(new eng::Label(label_id, name, color));
+ lib->notify(Library::NOTIFY_LABEL_CHANGED, boost::any(label));
}
diff --git a/src/engine/library/commands.hpp b/src/engine/library/commands.hpp
index 20d6980..b8a8986 100644
--- a/src/engine/library/commands.hpp
+++ b/src/engine/library/commands.hpp
@@ -56,8 +56,11 @@ public:
static void cmdListAllLabels(const db::Library::Ptr & lib);
static void cmdCreateLabel(const db::Library::Ptr & lib, const std::string & s,
const std::string & color);
- static void cmdRenameLabel(const db::Library::Ptr & lib,
- int label_id, const std::string & name);
+ static void cmdDeleteLabel(const db::Library::Ptr & lib,
+ int label_id);
+ static void cmdUpdateLabel(const db::Library::Ptr & lib,
+ int label_id, const std::string & name,
+ const std::string & color);
static void cmdProcessXmpUpdateQueue(const db::Library::Ptr & lib);
};
diff --git a/src/fwk/base/color.hpp b/src/fwk/base/color.hpp
index e202798..2787d6a 100644
--- a/src/fwk/base/color.hpp
+++ b/src/fwk/base/color.hpp
@@ -27,11 +27,11 @@
namespace fwk {
- /** A RgbColor tuple (3 components, 8bpp)
+ /** A RgbColor tuple (3 components, 16bpp)
* To be used only for UI.
*/
class RgbColor
- : public std::tr1::array<uint8_t, 3>
+ : public std::tr1::array<uint16_t, 3>
{
public:
RgbColor(value_type r = 0, value_type g = 0, value_type b = 0);
diff --git a/src/fwk/toolkit/command.hpp b/src/fwk/toolkit/command.hpp
index 39871d2..6492ab9 100644
--- a/src/fwk/toolkit/command.hpp
+++ b/src/fwk/toolkit/command.hpp
@@ -29,12 +29,66 @@ class Command
{
public:
typedef boost::function<void (void)> Function;
- Function undo;
- Function redo;
+ virtual void undo() = 0;
+ virtual void redo() = 0;
};
-}
+template <typename _ArgType>
+class CommandWithArg
+ : public Command
+{
+public:
+ typedef boost::function<void (_ArgType)> UndoFunction;
+ typedef boost::function<_ArgType (void)> RedoFunction;
+ CommandWithArg(const RedoFunction & _redo,
+ const UndoFunction & _undo)
+ : m_redo(_redo)
+ , m_undo(_undo)
+ {
+ }
+
+ virtual void undo()
+ {
+ m_undo(m_argstorage);
+ }
+ virtual void redo()
+ {
+ m_argstorage = m_redo();
+ }
+private:
+ RedoFunction m_redo;
+ UndoFunction m_undo;
+ _ArgType m_argstorage;
+};
+template <>
+class CommandWithArg<void>
+ : public Command
+{
+public:
+ typedef boost::function<void (void)> UndoFunction;
+ typedef boost::function<void (void)> RedoFunction;
+ CommandWithArg(const RedoFunction & _redo,
+ const UndoFunction & _undo)
+ : m_redo(_redo)
+ , m_undo(_undo)
+ {
+ }
+
+ virtual void undo()
+ {
+ m_undo();
+ }
+ virtual void redo()
+ {
+ m_redo();
+ }
+private:
+ RedoFunction m_redo;
+ UndoFunction m_undo;
+};
+
+}
#endif
/*
diff --git a/src/fwk/toolkit/gdkutils.cpp b/src/fwk/toolkit/gdkutils.cpp
index de78cc0..5bf0b48 100644
--- a/src/fwk/toolkit/gdkutils.cpp
+++ b/src/fwk/toolkit/gdkutils.cpp
@@ -1,7 +1,7 @@
/*
* niepce - fwk/toolkit/gdkutils.cpp
*
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008-2009 Hubert Figuiere
*
* 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
@@ -74,4 +74,20 @@ namespace fwk {
return pixbuf;
}
+
+ Gdk::Color rgbcolor_to_gdkcolor(const fwk::RgbColor & color)
+ {
+ Gdk::Color gdkcolor;
+ gdkcolor.set_rgb(color[0], color[1], color[2]);
+ return gdkcolor;
+ }
+
+
+ fwk::RgbColor gdkcolor_to_rgbcolor(const Gdk::Color & color)
+ {
+ fwk::RgbColor rgbcolor(color.get_red(), color.get_green(), color.get_blue());
+ return rgbcolor;
+ }
+
+
}
diff --git a/src/fwk/toolkit/gdkutils.hpp b/src/fwk/toolkit/gdkutils.hpp
index e9001be..3cdf3f2 100644
--- a/src/fwk/toolkit/gdkutils.hpp
+++ b/src/fwk/toolkit/gdkutils.hpp
@@ -1,7 +1,7 @@
/*
- * niepce - fwk/toolkit/gdkutils.h
+ * niepce - fwk/toolkit/gdkutils.hpp
*
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008-2009 Hubert Figuiere
*
* 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
@@ -23,6 +23,7 @@
#include <gdkmm/pixbuf.h>
+#include "fwk/base/color.hpp"
namespace fwk {
@@ -34,6 +35,10 @@ namespace fwk {
/** Rotate a pixbuf following the Exif rotation (may mirror too) */
Glib::RefPtr<Gdk::Pixbuf> gdkpixbuf_exif_rotate(const Glib::RefPtr<Gdk::Pixbuf> & pixbuf,
int exif_orientation);
+
+ Gdk::Color rgbcolor_to_gdkcolor(const fwk::RgbColor & color);
+ fwk::RgbColor gdkcolor_to_rgbcolor(const Gdk::Color & color);
+
}
#endif
diff --git a/src/fwk/toolkit/undo.cpp b/src/fwk/toolkit/undo.cpp
index 8973e8c..56b559c 100644
--- a/src/fwk/toolkit/undo.cpp
+++ b/src/fwk/toolkit/undo.cpp
@@ -38,15 +38,6 @@ UndoTransaction::~UndoTransaction()
boost::bind(&boost::checked_delete<Command>, _1));
}
-Command *UndoTransaction::new_command(const Command::Function & _redo,
- const Command::Function & _undo)
-{
- fwk::Command *cmd = new fwk::Command;
- cmd->redo = _redo;
- cmd->undo = _undo;
- add(cmd);
- return cmd;
-}
void UndoTransaction::add(Command * cmd)
{
diff --git a/src/fwk/toolkit/undo.hpp b/src/fwk/toolkit/undo.hpp
index 27f5b29..1b01468 100644
--- a/src/fwk/toolkit/undo.hpp
+++ b/src/fwk/toolkit/undo.hpp
@@ -38,7 +38,9 @@ class UndoTransaction
public:
UndoTransaction(const std::string & n);
~UndoTransaction();
- Command *new_command(const Command::Function &, const Command::Function &);
+ template <typename _RetType>
+ Command *new_command(const typename CommandWithArg<_RetType>::RedoFunction &,
+ const typename CommandWithArg<_RetType>::UndoFunction &);
void undo();
void redo();
/** execute the transaction after adding it. (calls %undo) */
@@ -54,6 +56,16 @@ private:
std::string m_name;
};
+template <typename _ArgType>
+Command *UndoTransaction::new_command(const typename CommandWithArg<_ArgType>::RedoFunction & _redo,
+ const typename CommandWithArg<_ArgType>::UndoFunction & _undo)
+{
+ Command *cmd = new CommandWithArg<_ArgType>(_redo, _undo);
+ add(cmd);
+ return cmd;
+}
+
+
class UndoHistory
: public boost::noncopyable
{
diff --git a/src/libraryclient/clientimpl.cpp b/src/libraryclient/clientimpl.cpp
index d3c7b12..df7555e 100644
--- a/src/libraryclient/clientimpl.cpp
+++ b/src/libraryclient/clientimpl.cpp
@@ -139,11 +139,21 @@ tid_t ClientImpl::createLabel(const std::string & s, const std::string & color)
return id;
}
-tid_t ClientImpl::renameLabel(int label_id, const std::string & new_name)
+tid_t ClientImpl::deleteLabel(int label_id)
{
tid_t id = LibraryClient::newTid();
- Op::Ptr op(new Op(id, boost::bind(&Commands::cmdRenameLabel,
- _1, label_id, new_name)));
+ Op::Ptr op(new Op(id, boost::bind(&Commands::cmdDeleteLabel,
+ _1, label_id)));
+ m_localLibrary->schedule(op);
+ return id;
+}
+
+tid_t ClientImpl::updateLabel(int label_id, const std::string & new_name,
+ const std::string & new_color)
+{
+ tid_t id = LibraryClient::newTid();
+ Op::Ptr op(new Op(id, boost::bind(&Commands::cmdUpdateLabel,
+ _1, label_id, new_name, new_color)));
m_localLibrary->schedule(op);
return id;
}
diff --git a/src/libraryclient/clientimpl.hpp b/src/libraryclient/clientimpl.hpp
index 782308f..29cf37f 100644
--- a/src/libraryclient/clientimpl.hpp
+++ b/src/libraryclient/clientimpl.hpp
@@ -50,7 +50,9 @@ public:
library::tid_t getAllLabels();
library::tid_t createLabel(const std::string & s, const std::string & color);
- library::tid_t renameLabel(int id, const std::string & new_name);
+ library::tid_t deleteLabel(int id);
+ library::tid_t updateLabel(int id, const std::string & new_name,
+ const std::string & new_color);
library::tid_t processXmpUpdateQueue();
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index ec67969..04502f2 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -102,9 +102,16 @@ library::tid_t LibraryClient::createLabel(const std::string & s, const std::stri
}
-library::tid_t LibraryClient::renameLabel(int id, const std::string & new_name)
+library::tid_t LibraryClient::deleteLabel(int id)
{
- return m_pImpl->renameLabel(id, new_name);
+ return m_pImpl->deleteLabel(id);
+}
+
+
+library::tid_t LibraryClient::updateLabel(int id, const std::string & new_name,
+ const std::string & new_color)
+{
+ return m_pImpl->updateLabel(id, new_name, new_color);
}
library::tid_t LibraryClient::processXmpUpdateQueue()
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 51d4728..23b04d1 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -69,8 +69,10 @@ namespace libraryclient {
/** get all the labels */
library::tid_t getAllLabels();
library::tid_t createLabel(const std::string & s, const std::string & color);
- /** rename a label */
- library::tid_t renameLabel(int id, const std::string & new_name);
+ library::tid_t deleteLabel(int id);
+ /** update a label */
+ library::tid_t updateLabel(int id, const std::string & new_name,
+ const std::string & new_color);
/** tell to process the Xmp update Queue */
library::tid_t processXmpUpdateQueue();
diff --git a/src/niepce/ui/dialogs/editlabels.cpp b/src/niepce/ui/dialogs/editlabels.cpp
index 0d2357f..4accd18 100644
--- a/src/niepce/ui/dialogs/editlabels.cpp
+++ b/src/niepce/ui/dialogs/editlabels.cpp
@@ -1,5 +1,5 @@
/*
- * niepce - niepce/ui/dialogs/editlabels.hpp
+ * niepce - niepce/ui/dialogs/editlabels.cpp
*
* Copyright (C) 2009 Hubert Figuiere
*
@@ -28,10 +28,11 @@
#include <gtkmm/label.h>
#include "fwk/utils/debug.h"
-#include "editlabels.hpp"
-#include "libraryclient/libraryclient.hpp"
#include "fwk/toolkit/application.hpp"
+#include "fwk/toolkit/gdkutils.hpp"
#include "fwk/toolkit/undo.hpp"
+#include "libraryclient/libraryclient.hpp"
+#include "editlabels.hpp"
using libraryclient::LibraryClient;
@@ -53,21 +54,29 @@ void EditLabels::setup_widget()
add_header(_("Edit Labels"));
- const char * color_fmt = "color%1%";
+ const char * color_fmt = "colorbutton%1%";
const char * value_fmt = "value%1%";
for(size_t i = 0; i < 5; i++) {
- if(m_labels.size() <= i) {
- break;
- }
- Gtk::Label *colorlbl;
+ bool has_label = m_labels.size() > i;
+
+ Gtk::ColorButton *colorbutton;
Gtk::Entry *labelentry;
- _builder->get_widget(str(boost::format(color_fmt) % (i+1)), colorlbl);
+
+ _builder->get_widget(str(boost::format(color_fmt) % (i+1)), colorbutton);
+ m_colors[i] = colorbutton;
_builder->get_widget(str(boost::format(value_fmt) % (i+1)), labelentry);
DBG_ASSERT(labelentry, "couldn't find label");
- labelentry->set_text(m_labels[i]->label());
- labelentry->property_text().signal_changed().connect(
- sigc::bind(sigc::mem_fun(*this, &EditLabels::label_name_changed), i));
m_entries[i] = labelentry;
+
+ if(has_label) {
+ Gdk::Color color = fwk::rgbcolor_to_gdkcolor(m_labels[i]->color());
+ colorbutton->set_color(color);
+ labelentry->set_text(m_labels[i]->label());
+ }
+ colorbutton->signal_color_set().connect(
+ sigc::bind(sigc::mem_fun(*this, &EditLabels::label_color_changed), i));
+ labelentry->signal_changed().connect(
+ sigc::bind(sigc::mem_fun(*this, &EditLabels::label_name_changed), i));
}
gtkDialog().signal_response().connect(sigc::mem_fun(*this, &EditLabels::update_labels));
}
@@ -79,21 +88,49 @@ void EditLabels::label_name_changed(size_t idx)
}
+void EditLabels::label_color_changed(size_t idx)
+{
+ m_status[idx] = true;
+}
+
void EditLabels::update_labels(int /*response*/)
{
fwk::UndoTransaction *undo = NULL;
- for(int i = 0; i < 5; i++) {
+ for(size_t i = 0; i < 5; i++) {
if(m_status[i]) {
+ bool has_label = m_labels.size() > i;
+
DBG_OUT("updating label %d", i);
- std::string current_name = m_labels[i]->label();
std::string new_name = m_entries[i]->get_text();
+ // a newname is NOT valid.
+ if(new_name.empty()) {
+ continue;
+ }
+ std::string new_color
+ = fwk::gdkcolor_to_rgbcolor(m_colors[i]->get_color()).to_string();
if(!undo) {
- undo = fwk::Application::app()->begin_undo(_("Change Label name"));
+ undo = fwk::Application::app()->begin_undo(_("Change Labels"));
+ }
+
+ if(has_label) {
+ std::string current_name = m_labels[i]->label();
+ std::string current_color = m_labels[i]->color().to_string();
+
+ undo->new_command<void>(
+ boost::bind(&libraryclient::LibraryClient::updateLabel,
+ m_lib_client, m_labels[i]->id(), new_name,
+ new_color),
+ boost::bind(&libraryclient::LibraryClient::updateLabel,
+ m_lib_client, m_labels[i]->id(), current_name,
+ current_color));
+ }
+ else {
+ undo->new_command<int>(
+ boost::bind(&libraryclient::LibraryClient::createLabel,
+ m_lib_client, new_name, new_color),
+ boost::bind(&libraryclient::LibraryClient::deleteLabel,
+ m_lib_client, _1));
}
- undo->new_command(boost::bind(&libraryclient::LibraryClient::renameLabel,
- m_lib_client, m_labels[i]->id(), new_name),
- boost::bind(&libraryclient::LibraryClient::renameLabel,
- m_lib_client, m_labels[i]->id(), current_name));
}
}
if(undo) {
diff --git a/src/niepce/ui/dialogs/editlabels.hpp b/src/niepce/ui/dialogs/editlabels.hpp
index 14eb856..5b2202f 100644
--- a/src/niepce/ui/dialogs/editlabels.hpp
+++ b/src/niepce/ui/dialogs/editlabels.hpp
@@ -23,6 +23,7 @@
#include <tr1/array>
+#include <gtkmm/colorbutton.h>
#include <gtkmm/entry.h>
#include <gtkmm/label.h>
@@ -43,8 +44,10 @@ public:
virtual void setup_widget();
private:
void label_name_changed(size_t idx);
+ void label_color_changed(size_t idx);
void update_labels(int /*response*/);
eng::Label::List m_labels;
+ std::tr1::array<Gtk::ColorButton*, 5> m_colors;
std::tr1::array<Gtk::Entry*, 5> m_entries;
std::tr1::array<bool, 5> m_status;
libraryclient::LibraryClient::Ptr m_lib_client;
diff --git a/src/niepce/ui/dialogs/editlabels.ui b/src/niepce/ui/dialogs/editlabels.ui
index 8ba01d7..8095a18 100644
--- a/src/niepce/ui/dialogs/editlabels.ui
+++ b/src/niepce/ui/dialogs/editlabels.ui
@@ -168,13 +168,19 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="color1">
+ <object class="GtkColorButton" id="colorbutton1">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
</object>
</child>
<child>
- <object class="GtkLabel" id="color2">
+ <object class="GtkColorButton" id="colorbutton2">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
</object>
<packing>
<property name="top_attach">1</property>
@@ -182,8 +188,11 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="color3">
+ <object class="GtkColorButton" id="colorbutton3">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
</object>
<packing>
<property name="top_attach">2</property>
@@ -191,8 +200,11 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="color4">
+ <object class="GtkColorButton" id="colorbutton4">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
</object>
<packing>
<property name="top_attach">3</property>
@@ -200,8 +212,11 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="color5">
+ <object class="GtkColorButton" id="colorbutton5">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
</object>
<packing>
<property name="top_attach">4</property>
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 5c92282..2e1116e 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -495,10 +495,10 @@ void NiepceWindow::on_preferences()
void NiepceWindow::create_initial_labels()
{
- m_libClient->createLabel(_("Label 1"), "");
- m_libClient->createLabel(_("Label 2"), "");
- m_libClient->createLabel(_("Label 3"), "");
- m_libClient->createLabel(_("Label 4"), "");
+ m_libClient->createLabel(_("Label 1"), "255 0 0");
+ m_libClient->createLabel(_("Label 2"), "0 255 0");
+ m_libClient->createLabel(_("Label 3"), "0 0 255");
+ m_libClient->createLabel(_("Label 4"), "100 100 100");
m_libClient->createLabel(_("Label 5"), "");
}
@@ -523,7 +523,37 @@ void NiepceWindow::on_lib_notification(const fwk::Notification::Ptr &n)
m_labels.push_back(*iter);
}
break;
+ }
+ case db::Library::NOTIFY_LABEL_CHANGED:
+ {
+ eng::Label::Ptr & l
+ = boost::any_cast<eng::Label::Ptr &>(ln.param);
+ // TODO: will work as long as we have 5 labels or something.
+ for(eng::Label::List::iterator iter = m_labels.begin();
+ iter != m_labels.end(); ++iter) {
+
+ if((*iter)->id() == l->id()) {
+ (*iter)->set_label(l->label());
+ (*iter)->set_color(l->color());
+ }
}
+ break;
+ }
+ case db::Library::NOTIFY_LABEL_DELETED:
+ {
+ int id = boost::any_cast<int>(ln.param);
+ // TODO: will work as long as we have 5 labels or something.
+ for(eng::Label::List::iterator iter = m_labels.begin();
+ iter != m_labels.end(); ++iter) {
+
+ if((*iter)->id() == id) {
+ DBG_OUT("remove label %d", id);
+ iter = m_labels.erase(iter);
+ break;
+ }
+ }
+ break;
+ }
default:
break;
}
@@ -544,18 +574,7 @@ void NiepceWindow::on_action_edit_labels()
DBG_OUT("edit labels");
// get the labels.
EditLabels::Ptr dlg(new EditLabels(get_labels(), getLibraryClient()));
- int result = dlg->run_modal(shared_frame_ptr());
- switch(result) {
- case 0:
- // ok
- // update the labels.
- break;
- case 1:
- // cancel
- break;
- default:
- break;
- }
+ dlg->run_modal(shared_frame_ptr());
}
void NiepceWindow::set_title(const std::string & title)
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index e2fb901..cd4099e 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -159,10 +159,12 @@ bool SelectionController::_set_metadata(const std::string & undo_label, const db
int meta, int old_value, int new_value)
{
fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(undo_label);
- undo->new_command(boost::bind(&libraryclient::LibraryClient::setMetadata,
- getLibraryClient(), file->id(), meta, new_value),
- boost::bind(&libraryclient::LibraryClient::setMetadata,
- getLibraryClient(), file->id(), meta, old_value));
+ undo->new_command<void>(
+ boost::bind(&libraryclient::LibraryClient::setMetadata,
+ getLibraryClient(), file->id(), meta, new_value),
+ boost::bind(&libraryclient::LibraryClient::setMetadata,
+ getLibraryClient(), file->id(), meta, old_value)
+ );
undo->execute();
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]