From 760acbdf504c728d271e0d65fa57a20144c7eeb9 Mon Sep 17 00:00:00 2001
From: Santanu Sinha
Date: Thu, 21 May 2009 00:22:13 +0530
Subject: [PATCH 1/2] Tag creation and updation
Support for creating new tag and updating a single tag
Items still left todo:
- Delete tag
- Apply Tag to selected pictures
- Remove selected tags from selected pictures
---
src/application/engine.cpp | 1 +
src/attribute/tag-manager.cpp | 74 ++++++++++++-
src/attribute/tag-manager.h | 12 ++-
src/attribute/tag-new-dialog.cpp | 214 ++++++++++++++++++++++++--------------
src/attribute/tag-new-dialog.h | 37 +++++++
src/attribute/tag-view.cpp | 1 +
src/attribute/tag-view.h | 19 +++-
src/attribute/tag.cpp | 61 +++++------
src/attribute/tag.h | 10 +-
9 files changed, 305 insertions(+), 124 deletions(-)
diff --git a/src/application/engine.cpp b/src/application/engine.cpp
index 4587a17..f0419e9 100644
--- a/src/application/engine.cpp
+++ b/src/application/engine.cpp
@@ -319,6 +319,7 @@ Engine::get_tags() const throw()
{
TagPtr tag(new Tag());
tag->create(model, i);
+ tag->set_table_( tagsTable );
tags.push_back(tag);
}
diff --git a/src/attribute/tag-manager.cpp b/src/attribute/tag-manager.cpp
index 86cc1a4..6ff2cb2 100644
--- a/src/attribute/tag-manager.cpp
+++ b/src/attribute/tag-manager.cpp
@@ -100,7 +100,9 @@ TagManager::TagManager() throw() :
actionGroup_->add(
Gtk::Action::create(
"ActionTagsEdit", Gtk::Stock::EDIT,
- _("_Edit Selected Tag...")));
+ _("_Edit Selected Tag...")),
+ Gtk::AccelKey(""),
+ sigc::mem_fun(*this, &TagManager::on_action_tag_edit));
actionGroup_->add(
Gtk::Action::create(
@@ -161,10 +163,9 @@ TagManager::init(Application & application)
{
application_ = &application;
- Engine & engine = application.get_engine();
- TagList tags = engine.get_tags();
- tagView_.populate(tags);
+ Engine & engine = application_->get_engine();
engine.get_criterion_repo().register_source( &tagView_ );
+ populate_view();
MainWindow & main_window = application.get_main_window();
main_window.add_dock_object_left(GDL_DOCK_OBJECT(dockItem_));
@@ -237,6 +238,13 @@ TagManager::on_action_tag_new() throw()
{
case Gtk::RESPONSE_OK:
{
+ TagPtr tag( new Tag() );
+ tag->set_name( tag_new_dialog.get_name() );
+ tag->set_description( tag_new_dialog.get_description() );
+ tag->set_icon_path( tag_new_dialog.get_icon_path() );
+ DatabasePtr db = application_->get_engine().get_db();
+ tag->save( *db );
+ populate_view();
break;
}
@@ -253,4 +261,62 @@ TagManager::on_action_tag_new() throw()
}
}
+void
+TagManager::on_action_tag_edit() throw()
+{
+ Glib::RefPtr selected
+ = tagView_.get_selection();
+
+ if( 0 == selected->count_selected_rows() )
+ return;
+
+ Gtk::TreeModel::iterator item = selected->get_selected();
+ const TagViewModelColumnRecord &rec
+ = tagView_.get_column_records();
+
+ if( item != selected->get_model()->children().end() )
+ {
+ Gtk::TreeModel::Row row= (*item);
+ TagPtr tag = row[ rec.get_column_tag() ];
+
+ TagNewDialog tag_new_dialog( tag );
+ tag_new_dialog.set_transient_for(
+ application_->get_main_window());
+
+ const gint response = tag_new_dialog.run();
+
+ switch (response)
+ {
+ case Gtk::RESPONSE_OK:
+ {
+ tag->set_name( tag_new_dialog.get_name() );
+ tag->set_description( tag_new_dialog.get_description() );
+ tag->set_icon_path( tag_new_dialog.get_icon_path() );
+ DatabasePtr db = application_->get_engine().get_db();
+ tag->save( *db );
+ populate_view();
+ break;
+ }
+
+ case Gtk::RESPONSE_CANCEL:
+ case Gtk::RESPONSE_DELETE_EVENT:
+ {
+ break;
+ }
+
+ default:
+ {
+ break;
+ }
+ }
+ }
+}
+
+void
+TagManager::populate_view() throw()
+{
+ Engine & engine = application_->get_engine();
+ TagList tags = engine.get_tags();
+ tagView_.populate(tags);
+}
} // namespace Solang
diff --git a/src/attribute/tag-manager.h b/src/attribute/tag-manager.h
index 93533dc..9ccdaab 100644
--- a/src/attribute/tag-manager.h
+++ b/src/attribute/tag-manager.h
@@ -58,6 +58,12 @@ protected:
void
on_action_tag_new() throw();
+ void
+ on_action_tag_edit() throw();
+
+ void
+ populate_view() throw();
+
ApplicationPtr application_;
Glib::RefPtr iconFactory_;
@@ -67,15 +73,15 @@ protected:
Gtk::UIManager::ui_merge_id uiID_;
const std::string dockItemName_;
-
+
const Glib::ustring dockItemTitle_;
-
+
GdlDockItemBehavior dockItemBehaviour_;
GtkWidget * dockItem_;
Gtk::VBox vBox_;
-
+
Gtk::ScrolledWindow scrolledWindow_;
Gtk::HBox hBox_;
diff --git a/src/attribute/tag-new-dialog.cpp b/src/attribute/tag-new-dialog.cpp
index 7c89769..f0af41a 100644
--- a/src/attribute/tag-new-dialog.cpp
+++ b/src/attribute/tag-new-dialog.cpp
@@ -27,7 +27,7 @@
#include
#include "tag-new-dialog.h"
-#include "types.h"
+#include "tag.h"
namespace Solang
{
@@ -56,62 +56,49 @@ TagNewDialog::TagNewDialog() throw() :
descriptionTextView_()
{
set_title(_("Create New Tag"));
- set_border_width(12);
- set_default_size(320, 200);
- set_has_separator(false);
-
- Gtk::VBox * const dialog_vbox = get_vbox();
- dialog_vbox->set_spacing(18);
-
- mainTable_.set_col_spacings(12);
- mainTable_.set_row_spacings(6);
- dialog_vbox->pack_start(mainTable_, Gtk::PACK_EXPAND_WIDGET, 0);
-
- iconButton_.set_image(iconImage_);
- iconButton_.set_size_request(64, 64);
- iconButton_.signal_clicked().connect(sigc::mem_fun(*this,
- &TagNewDialog::on_icon_button_clicked));
- mainTable_.attach(iconButton_, 0, 1, 0, 2,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
-
- mainTable_.attach(parentLabel_, 1, 2, 0, 1,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
- mainTable_.attach(parentComboBox_, 2, 3, 0, 1,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
+ setup_gui();
- mainTable_.attach(nameLabel_, 1, 2, 1, 2,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
-
- mainTable_.attach(nameEntry_, 2, 3, 1, 2,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
-
- mainTable_.attach(descriptionLabel_, 1, 2, 2, 3,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
+ show_all_children();
+}
- descriptionScrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC,
- Gtk::POLICY_AUTOMATIC);
- mainTable_.attach(descriptionScrolledWindow_, 2, 3, 2, 3,
- Gtk::FILL | Gtk::EXPAND,
- Gtk::FILL | Gtk::EXPAND,
- 0, 0);
+TagNewDialog::TagNewDialog( const TagPtr &tag ) throw() :
+ Gtk::Dialog(),
+ iconPath_( ),
+ mainTable_(3, 3, false),
+ iconButton_(),
+ iconImage_(Gtk::Stock::MISSING_IMAGE, Gtk::ICON_SIZE_BUTTON),
+ parentLabel_(_("Parent:"),
+ Gtk::ALIGN_LEFT,
+ Gtk::ALIGN_CENTER,
+ false),
+ parentComboBox_(),
+ nameLabel_(_("Name:"),
+ Gtk::ALIGN_LEFT,
+ Gtk::ALIGN_CENTER,
+ false),
+ nameEntry_(),
+ descriptionLabel_(_("Description"),
+ Gtk::ALIGN_LEFT,
+ Gtk::ALIGN_CENTER,
+ false),
+ descriptionScrolledWindow_(),
+ descriptionTextView_()
+{
+ Glib::ustring title = "Edit Tag:" + tag->get_name();
+ set_title(_( title.c_str() ));
- descriptionScrolledWindow_.add(descriptionTextView_);
+ setup_gui();
- add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
- add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
+ //populate
+ if( tag )
+ {
+ nameEntry_.set_text(tag->get_name());
+ Glib::RefPtr description = Gtk::TextBuffer::create();
+ description->set_text( tag->get_description() );
+ descriptionTextView_.set_buffer(description);
+ set_icon(tag->get_icon_path());
+ }
show_all_children();
}
@@ -126,7 +113,7 @@ TagNewDialog::on_delete_event(GdkEventAny * event)
bool return_value = Gtk::Dialog::on_delete_event(event);
hide();
- return return_value;
+ return return_value;
}
void
@@ -193,29 +180,7 @@ TagNewDialog::on_icon_button_clicked() throw()
{
break;
}
- iconPath_ = path;
-
- PixbufPtr pixbuf;
- try
- {
- pixbuf = Gdk::Pixbuf::create_from_file(iconPath_);
- }
- catch (const Glib::FileError & e)
- {
- std::cerr << __FILE__ << ":" << __LINE__ << ", "
- << __FUNCTION__ << ": " << e.what()
- << std::endl;
- return;
- }
- catch (const Gdk::PixbufError & e)
- {
- std::cerr << __FILE__ << ":" << __LINE__ << ", "
- << __FUNCTION__ << ": " << e.what()
- << std::endl;
- return;
- }
-
- iconImage_.set(pixbuf);
+ set_icon( path );
break;
}
@@ -233,4 +198,101 @@ TagNewDialog::on_icon_button_clicked() throw()
}
}
+void
+TagNewDialog::setup_gui() throw()
+{
+ set_border_width(12);
+ set_default_size(320, 200);
+ set_has_separator(false);
+
+ Gtk::VBox * const dialog_vbox = get_vbox();
+ dialog_vbox->set_spacing(18);
+
+ mainTable_.set_col_spacings(12);
+ mainTable_.set_row_spacings(6);
+ dialog_vbox->pack_start(mainTable_, Gtk::PACK_EXPAND_WIDGET, 0);
+
+ iconButton_.set_image(iconImage_);
+ iconButton_.set_size_request(64, 64);
+ iconButton_.signal_clicked().connect(sigc::mem_fun(*this,
+ &TagNewDialog::on_icon_button_clicked));
+ mainTable_.attach(iconButton_, 0, 1, 0, 2,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ mainTable_.attach(parentLabel_, 1, 2, 0, 1,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ mainTable_.attach(parentComboBox_, 2, 3, 0, 1,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ mainTable_.attach(nameLabel_, 1, 2, 1, 2,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ mainTable_.attach(nameEntry_, 2, 3, 1, 2,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ mainTable_.attach(descriptionLabel_, 1, 2, 2, 3,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ descriptionScrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC,
+ Gtk::POLICY_AUTOMATIC);
+ mainTable_.attach(descriptionScrolledWindow_, 2, 3, 2, 3,
+ Gtk::FILL | Gtk::EXPAND,
+ Gtk::FILL | Gtk::EXPAND,
+ 0, 0);
+
+ descriptionScrolledWindow_.add(descriptionTextView_);
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
+
+ return;
+
+}
+
+void
+TagNewDialog::set_icon(const Glib::ustring &iconPath)
+{
+ iconPath_ = iconPath;
+
+ if( iconPath_.empty() )
+ return;
+
+ PixbufPtr pixbuf;
+ try
+ {
+ pixbuf = Gdk::Pixbuf::create_from_file(iconPath_);
+ }
+ catch (const Glib::FileError & e)
+ {
+ std::cerr << __FILE__ << ":" << __LINE__ << ", "
+ << __FUNCTION__ << ": " << e.what()
+ << std::endl;
+ return;
+ }
+ catch (const Gdk::PixbufError & e)
+ {
+ std::cerr << __FILE__ << ":" << __LINE__ << ", "
+ << __FUNCTION__ << ": " << e.what()
+ << std::endl;
+ return;
+ }
+
+ iconImage_.set(pixbuf);
+
+ return;
+}
+
} // namespace Solang
diff --git a/src/attribute/tag-new-dialog.h b/src/attribute/tag-new-dialog.h
index bfb2408..c06ef1d 100644
--- a/src/attribute/tag-new-dialog.h
+++ b/src/attribute/tag-new-dialog.h
@@ -22,6 +22,7 @@
#include
#include
+#include "types.h"
namespace Solang
{
@@ -31,10 +32,20 @@ class TagNewDialog :
{
public:
TagNewDialog() throw();
+ TagNewDialog( const TagPtr &tag ) throw();
virtual
~TagNewDialog() throw();
+ inline Glib::ustring
+ get_name() const;
+
+ inline const std::string &
+ get_icon_path() const;
+
+ inline const Glib::ustring
+ get_description();
+
protected:
virtual bool
on_delete_event(GdkEventAny * event);
@@ -45,6 +56,12 @@ class TagNewDialog :
void
on_icon_button_clicked() throw();
+ void
+ setup_gui() throw();
+
+ void
+ set_icon( const Glib::ustring &iconPath);
+
std::string iconPath_;
Gtk::Table mainTable_;
@@ -70,6 +87,26 @@ class TagNewDialog :
private:
};
+inline Glib::ustring
+TagNewDialog::get_name() const
+{
+ return nameEntry_.get_text();
+}
+
+inline const std::string &
+TagNewDialog::get_icon_path() const
+{
+ return iconPath_;
+}
+
+inline const Glib::ustring
+TagNewDialog::get_description()
+{
+ Glib::RefPtr buf
+ = descriptionTextView_.get_buffer();
+ return buf->get_slice( buf->begin(), buf->end());
+}
+
} // namespace Solang
#endif // SOLANG_TAG_NEW_DIALOG_H
diff --git a/src/attribute/tag-view.cpp b/src/attribute/tag-view.cpp
index f1a9edf..7829cf3 100644
--- a/src/attribute/tag-view.cpp
+++ b/src/attribute/tag-view.cpp
@@ -69,6 +69,7 @@ TagView::configure() throw()
void
TagView::populate(const TagList & tags) throw()
{
+ listStore_->clear();
TagList::const_iterator list_iter;
for (list_iter = tags.begin(); list_iter != tags.end();
diff --git a/src/attribute/tag-view.h b/src/attribute/tag-view.h
index 2a9a7e7..59eb42c 100644
--- a/src/attribute/tag-view.h
+++ b/src/attribute/tag-view.h
@@ -57,7 +57,12 @@ class TagView :
void
clear_tag_selection() throw();
-
+
+ inline const ListStorePtr &
+ get_store() const throw();
+
+ inline const TagViewModelColumnRecord &
+ get_column_records() const throw();
protected:
TagViewModelColumnRecord modelColumnRecord_;
@@ -69,6 +74,18 @@ class TagView :
configure() throw();
};
+inline const ListStorePtr &
+TagView::get_store() const throw()
+{
+ return listStore_;
+}
+
+inline const TagViewModelColumnRecord &
+TagView::get_column_records() const throw()
+{
+ return modelColumnRecord_;
+}
+
} // namespace Solang
#endif // SOLANG_TAG_VIEW_H
diff --git a/src/attribute/tag.cpp b/src/attribute/tag.cpp
index 0a5125a..b6b60b9 100644
--- a/src/attribute/tag.cpp
+++ b/src/attribute/tag.cpp
@@ -38,7 +38,7 @@ Tag::Tag() throw() :
{
}
-Tag::Tag(guint64 tagId, const Glib::ustring & name) throw() :
+Tag::Tag(gint tagId, const Glib::ustring & name) throw() :
tagId_(tagId),
name_(name)
{
@@ -49,7 +49,7 @@ Tag::~Tag() throw()
}
void
-Tag::set_tag_id(guint64 tag_id) throw()
+Tag::set_tag_id(gint tag_id) throw()
{
tagId_ = tag_id;
}
@@ -71,7 +71,7 @@ void Tag::insert(
{
std::list values;
values.push_back( Gnome::Gda::Value( lastIndex + 1 ) ); //tagid
- std::cout<<"Tagid= "< 0
- && get_name() != model->get_value_at(
- NAME_COL, row ).get_string() )
+ try
{
- model->set_value_at(
- NAME_COL, row, Gnome::Gda::Value( get_name()));
+ std::cout< "< values;
+ values.push_back( Gnome::Gda::Value( get_tag_id() ) );
+ values.push_back( Gnome::Gda::Value( get_name() ) );
+ values.push_back( Gnome::Gda::Value( get_description() ) );
+ values.push_back( Gnome::Gda::Value( get_icon_path() ) );
+ model->set_values( row, values );
}
- if( get_description().length() > 0
- && get_description() != model->get_value_at(
- DESCRIPTION_COL, row ).get_string() )
+ catch(Glib::Error &e)
{
- model->set_value_at(
- DESCRIPTION_COL, row,
- Gnome::Gda::Value( get_description() ) );
- }
- if( get_icon_path().length() > 0
- && get_icon_path() != model->get_value_at(
- ICONPATH_COL, row ).get_string() )
- {
- model->set_value_at(
- ICONPATH_COL, row,
- Gnome::Gda::Value( get_icon_path() ) );
+ std::cerr<<"Error::Could not save: "<get_value_at(
- TAGID_COL, row ).get_int() );
+ TAGID_COL, row ).get_int() );
set_name( dataModel->get_value_at(
- NAME_COL, row ).get_string() );
+ NAME_COL, row ).get_string() );
set_description( dataModel->get_value_at(
- DESCRIPTION_COL, row ).get_string() );
+ DESCRIPTION_COL, row ).get_string() );
set_icon_path( dataModel->get_value_at(
- ICONPATH_COL, row ).get_string() );
+ ICONPATH_COL, row ).get_string() );
return;
}
@@ -150,23 +141,23 @@ Glib::ustring Tag::getCreateSQL() throw(Error)
Glib::ustring
Tag::get_db_object_type_name() const throw()
{
- return "tags";
+ return "tags";
}
Glib::ustring
Tag::get_query_criteria() const throw()
{
- std::ostringstream sout;
+ std::ostringstream sout;
- sout << " photo_tags.tagid ="<