From c79230d8745748bc35ba78285d55bd07a31b5707 Mon Sep 17 00:00:00 2001
From: Santanu Sinha
Date: Sat, 13 Jun 2009 17:26:40 +0530
Subject: [PATCH] Queue based object deletion framework
+ Added command object for DBObject deletion
+ Added queue for storing deletion command
+ Support for tag deletion
+ Added non-deletable "All Photos" tag
+ Support for tag removal from selected pictures
---
src/application/Makefile.am | 4 +-
src/application/application.cpp | 1 +
src/application/deletion-queue.cpp | 124 ++++++++++++++++++++++++++++++++++++
src/application/deletion-queue.h | 91 ++++++++++++++++++++++++++
src/application/engine.cpp | 10 +++-
src/application/engine.h | 15 ++++
src/attribute/photo-tag.cpp | 67 ++++++++++----------
src/attribute/photo-tag.h | 46 +++++++++-----
src/attribute/tag-manager.cpp | 95 +++++++++++++++++++++++++--
src/attribute/tag-manager.h | 6 ++
src/attribute/tag-view.cpp | 8 ++-
src/attribute/tag.cpp | 37 +++++++----
src/attribute/tag.h | 6 ++
src/attribute/thumbnail.cpp | 8 +-
src/common/photo.cpp | 42 ++++++++++--
src/common/photo.h | 74 +++++++++-------------
src/common/types.h | 9 ++-
src/database/Makefile.am | 4 +-
src/database/database.cpp | 20 ++++++
src/database/database.h | 2 +
src/database/db-object.cpp | 50 ++++++++++----
src/database/db-object.h | 76 ++++++++++++++++------
src/database/delete-action.cpp | 83 ++++++++++++++++++++++++
src/database/delete-action.h | 67 +++++++++++++++++++
24 files changed, 776 insertions(+), 169 deletions(-)
create mode 100644 src/application/deletion-queue.cpp
create mode 100644 src/application/deletion-queue.h
create mode 100644 src/database/delete-action.cpp
create mode 100644 src/database/delete-action.h
diff --git a/src/application/Makefile.am b/src/application/Makefile.am
index 63593de..2d3f374 100644
--- a/src/application/Makefile.am
+++ b/src/application/Makefile.am
@@ -3,6 +3,8 @@ bin_PROGRAMS = solang
solang_SOURCES = \
application.cpp \
application.h \
+ deletion-queue.cpp \
+ deletion-queue.h \
engine.cpp \
engine.h \
main.cpp \
@@ -12,11 +14,11 @@ solang_SOURCES = \
solang_LDFLAGS =
solang_LDADD = \
- $(top_builddir)/src/database/libdatabase.la \
$(top_builddir)/src/importer/libimporter.la \
$(top_builddir)/src/renderer/librenderer.la \
$(top_builddir)/src/storage/libstorage.la \
$(top_builddir)/src/attribute/libattribute.la \
+ $(top_builddir)/src/database/libdatabase.la \
$(top_builddir)/src/common/libcommon.la \
$(EXIV2_LIBS) \
$(GPHOTO2_LIBS) \
diff --git a/src/application/application.cpp b/src/application/application.cpp
index ea4c08d..bb80310 100644
--- a/src/application/application.cpp
+++ b/src/application/application.cpp
@@ -347,6 +347,7 @@ Application::run() throw()
void
Application::final() throw()
{
+ engine_.final();
mainWindow_.final();
std::for_each(renderers_.begin(), renderers_.end(),
diff --git a/src/application/deletion-queue.cpp b/src/application/deletion-queue.cpp
new file mode 100644
index 0000000..875bff5
--- /dev/null
+++ b/src/application/deletion-queue.cpp
@@ -0,0 +1,124 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * Copyright (C) 2009 Santanu Sinha
+ *
+ * Solang is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Solang is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
+
+#include "deletion-queue.h"
+#include "progress-observer.h"
+
+namespace Solang
+{
+
+DeletionQueue::DeletionQueue(Database &db)
+ :db_(db),
+ actions_(),
+ mutex_()
+{
+}
+
+DeletionQueue::DeletionQueue( const DeletionQueue &rhs )
+ :db_(rhs.db_),
+ actions_( rhs.actions_ ),
+ mutex_()
+{
+}
+
+DeletionQueue::~DeletionQueue() throw()
+{
+ actions_.clear();
+}
+
+DeletionQueue &
+DeletionQueue::operator = ( const DeletionQueue &rhs )
+{
+ if( this != &rhs )
+ {
+ actions_ = rhs.actions_;
+ }
+
+ return *this;
+}
+
+void
+DeletionQueue::schedule_delete_action(
+ const DeleteActionPtr &action ) throw()
+{
+ Glib::Mutex::Lock lock( mutex_ );
+ //std::cout<<"Added: "<get_command_name()<set_event_description( "Executing delete actions" );
+ observer->set_num_events( actions_.size() );
+ for( DeleteActionList::iterator action = actions_.begin();
+ action != actions_.end(); action++ )
+ {
+ try
+ {
+ execute_action( *action );
+ }
+ catch( Error &e )
+ {
+ e.add_call_info( __FUNCTION__, __FILE__, __LINE__ );
+ observer->reset();
+ throw;
+ }
+ observer->receive_event_notifiation();
+ }
+}
+
+void
+DeletionQueue::execute_action(
+ const DeleteActionPtr &action ) throw(Error)
+{
+ //std::cout<<"Called"<execute( db_ );
+}
+
+} //namespace Solang
diff --git a/src/application/deletion-queue.h b/src/application/deletion-queue.h
new file mode 100644
index 0000000..2b0b883
--- /dev/null
+++ b/src/application/deletion-queue.h
@@ -0,0 +1,91 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * Copyright (C) 2009 Santanu Sinha
+ *
+ * Solang is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Solang is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#ifndef SOLANG_DELETION_QUEUE_H
+#define SOLANG_DELETION_QUEUE_H
+
+#include
+
+#include "delete-action.h"
+#include "error.h"
+#include "types.h"
+
+
+namespace Solang
+{
+
+class DeletionQueue
+{
+ public:
+ DeletionQueue( Database &db );
+
+ DeletionQueue( const DeletionQueue &);
+
+ ~DeletionQueue() throw();
+
+ DeletionQueue &
+ operator = (const DeletionQueue &);
+
+ void
+ schedule_delete_action( const DeleteActionPtr &) throw();
+
+ inline Glib::ustring
+ get_last_action_name() throw();
+
+ inline size_t
+ get_queue_size() const throw();
+
+ void
+ execute_actions() throw(Error);
+
+ void
+ execute_actions(
+ const ProgressObserverPtr &observer ) throw(Error);
+
+ private:
+
+ void
+ execute_action(const DeleteActionPtr &action) throw(Error);
+
+ Database &db_;
+
+ DeleteActionList actions_;
+
+ Glib::Mutex mutex_;
+};
+
+inline Glib::ustring
+DeletionQueue::get_last_action_name() throw()
+{
+ DeleteActionList::iterator it = actions_.begin();
+
+ if( it != actions_.end() )
+ {
+ return (*it)->get_command_name();
+ }
+}
+
+inline size_t
+DeletionQueue::get_queue_size() const throw()
+{
+ return actions_.size();
+}
+
+} //namespace Solang
+
+#endif
diff --git a/src/application/engine.cpp b/src/application/engine.cpp
index 68f942d..9b98724 100644
--- a/src/application/engine.cpp
+++ b/src/application/engine.cpp
@@ -49,7 +49,9 @@ Engine::Engine(int & argc, char ** & argv,
photos_(),
currentStorageSystems_(),
currentRenderer_(),
- database_("")
+ database_(""),
+ criterionRepo_(),
+ deleteActions_( database_ )
{
//TBD::CREATE
{
@@ -72,6 +74,12 @@ void Engine::init(Glib::ustring str)
database_.open();
}
+void Engine::final()
+{
+ std::cout<<"Final"<
#include "database.h"
+#include "deletion-queue.h"
#include "i-storage.h"
#include "non-copyable.h"
#include "photo.h"
@@ -53,6 +54,9 @@ class Engine :
init(Glib::ustring);
void
+ final();
+
+ void
import(const PhotoPtr & photo,
const IPhotoSourcePtr & source,
const IStoragePtr & selected_storage,
@@ -192,6 +196,9 @@ class Engine :
inline SearchCriterionRepo &
get_criterion_repo();
+ inline DeletionQueue &
+ get_delete_actions();
+
private:
PhotoList
create_renderable_list_from_photos(
@@ -233,6 +240,8 @@ class Engine :
Database database_;
SearchCriterionRepo criterionRepo_;
+
+ DeletionQueue deleteActions_;
};
inline const ProgressObserverPtr &
@@ -247,6 +256,12 @@ Engine::get_criterion_repo()
return criterionRepo_;
}
+inline DeletionQueue &
+Engine::get_delete_actions()
+{
+ return deleteActions_;
+}
+
} // namespace Solang
#endif // SOLANG_ENGINE_H
diff --git a/src/attribute/photo-tag.cpp b/src/attribute/photo-tag.cpp
index 4ef0bce..68543f2 100644
--- a/src/attribute/photo-tag.cpp
+++ b/src/attribute/photo-tag.cpp
@@ -1,18 +1,17 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
- * photo-tag.cpp
* Copyright (C) Santanu Sinha 2009
- *
- * photo-tag.cpp is free software: you can redistribute it and/or modify it
+ *
+ * Solang is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * photo-tag.cpp is distributed in the hope that it will be useful, but
+ *
+ * Solang is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
@@ -43,24 +42,26 @@ PhotoTag::~PhotoTag() throw()
{
}
-void PhotoTag::set_tagId_( gint32 tagId )
+void
+PhotoTag::set_tagId_( gint32 tagId )
{
tagId_ = tagId;
}
-void PhotoTag::set_photoId_( gint32 photoId )
+void
+PhotoTag::set_photoId_( gint32 photoId )
{
photoId_ = photoId;
}
-void PhotoTag::insert(
- DataModelPtr &model, gint32 lastIndex) throw(Error)
+void
+PhotoTag::insert( DataModelPtr &model, gint32 lastIndex) throw(Error)
{
std::vector values;
values.push_back( Gnome::Gda::Value( get_photoId_() ) );
- values.push_back( Gnome::Gda::Value( get_tagId_() ) );
+ values.push_back( Gnome::Gda::Value( get_tagId_() ) );
- gint32 row = 0;
+ gint32 row = 0;
try
{
@@ -82,46 +83,44 @@ void PhotoTag::insert(
}
-void PhotoTag::update(
- DataModelPtr &model, gint32 row) throw(Error)
+void
+PhotoTag::update( DataModelPtr &model, gint32 row) throw(Error)
{
-
- return;
-
+ return;
}
-void PhotoTag::create( DataModelPtr& dataModel, gint32 row) throw(Error)
+void
+PhotoTag::create( DataModelPtr& dataModel, gint32 row) throw(Error)
{
set_row_( row );
- set_tagId_( dataModel->get_value_at(
+ set_tagId_( dataModel->get_value_at(
PHOTOID_COL, row ).get_int() );
- set_tagId_( dataModel->get_value_at(
+ set_tagId_( dataModel->get_value_at(
TAGID_COL, row ).get_int() );
return;
}
-#if 0
-Glib::ustring PhotoTag::getCreateSQL() throw(Error)
-{
- std::ostringstream sout;
- Glib::ustring sql("insert into tags(tagid, tag, description, iconPath) values(NULL,'");
- sout<
*
- * photo-tag.h is free software: you can redistribute it and/or modify it
+ * Solang is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * photo-tag.h is distributed in the hope that it will be useful, but
+ * Solang is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
@@ -45,36 +44,51 @@ class PhotoTag :
public:
PhotoTag();
+
PhotoTag( gint32 photoId, gint32 tagId );
+
~PhotoTag() throw();
- inline gint32 get_photoId_() const throw();
- void set_photoId_( gint32 photoId );
+ inline gint32
+ get_photoId_() const throw();
+
+ void
+ set_photoId_( gint32 photoId );
+
+ inline gint32
+ get_tagId_() const throw();
- inline gint32 get_tagId_() const throw();
- void set_tagId_( gint32 tagId );
+ void
+ set_tagId_( gint32 tagId );
- virtual void insert(
- DataModelPtr &model, gint32 lastIndex) throw(Error);
- virtual void update(
- DataModelPtr &model, gint32 row) throw(Error);
+ virtual void
+ insert( DataModelPtr &model, gint32 lastIndex) throw(Error);
- virtual void create(
- DataModelPtr& dataModel, gint32 row) throw(Error);
+ virtual void
+ update( DataModelPtr &model, gint32 row) throw(Error);
+
+ virtual void
+ create( DataModelPtr& dataModel, gint32 row) throw(Error);
virtual Glib::ustring
get_db_object_type_name() const throw();
- virtual Glib::ustring getQueryCriteria() const;
+ virtual DeleteActionPtr
+ get_delete_action() throw();
+
+ virtual Glib::ustring
+ getQueryCriteria() const;
};
-inline gint32 PhotoTag::get_photoId_() const throw()
+inline gint32
+PhotoTag::get_photoId_() const throw()
{
return photoId_;
}
-inline gint32 PhotoTag::get_tagId_() const throw()
+inline gint32
+PhotoTag::get_tagId_() const throw()
{
return tagId_;
}
diff --git a/src/attribute/tag-manager.cpp b/src/attribute/tag-manager.cpp
index c24ad89..2545c71 100644
--- a/src/attribute/tag-manager.cpp
+++ b/src/attribute/tag-manager.cpp
@@ -1,17 +1,17 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* Copyright (C) 2009 Debarshi Ray
- *
+ *
* Solang is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* Solang is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
@@ -24,7 +24,10 @@
#include
#include "application.h"
+#include "delete-action.h"
+#include "deletion-queue.h"
#include "main-window.h"
+#include "photo-tag.h"
#include "renderer.h"
#include "tag-manager.h"
#include "tag-new-dialog.h"
@@ -107,7 +110,9 @@ TagManager::TagManager() throw() :
actionGroup_->add(
Gtk::Action::create(
"ActionTagsDelete", Gtk::Stock::DELETE,
- _("_Delete Selected Tag")));
+ _("_Delete Selected Tag")),
+ Gtk::AccelKey(""),
+ sigc::mem_fun(*this, &TagManager::on_action_tag_delete));
actionGroup_->add(
Gtk::Action::create("ActionTagsAttach", Gtk::Stock::ADD,
@@ -118,21 +123,23 @@ TagManager::TagManager() throw() :
actionGroup_->add(
Gtk::Action::create(
"ActionTagsRemove", Gtk::Stock::REMOVE,
- _("_Remove Tag From Selection")));
+ _("_Remove Tag From Selection")),
+ Gtk::AccelKey(""),
+ sigc::mem_fun(*this, &TagManager::on_action_remove_tag));
scrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC,
Gtk::POLICY_AUTOMATIC);
scrolledWindow_.add(tagView_);
#if 0
tagView_.signal_().connect(
- sigc::mem_fun(
+ sigc::mem_fun(
*this, &TagManager::tag_row_activated ) );
#endif
dockItem_ = gdl_dock_item_new_with_stock(dockItemName_.c_str(),
dockItemTitle_.c_str(),
PACKAGE_TARNAME"-tag",
dockItemBehaviour_);
-
+
gtk_container_add(GTK_CONTAINER(dockItem_),
GTK_WIDGET(vBox_.gobj()));
vBox_.pack_start( scrolledWindow_ );
@@ -226,7 +233,7 @@ TagManager::on_action_tag_edit() throw()
Glib::RefPtr selected
= tagView_.get_selection();
- if( 0 == selected->count_selected_rows() )
+ if( Tag::ALL_PHOTOS_TAGID == selected->count_selected_rows() )
return;
Gtk::TreeModel::iterator item = selected->get_selected();
@@ -272,6 +279,35 @@ TagManager::on_action_tag_edit() throw()
}
void
+TagManager::on_action_tag_delete() throw()
+{
+ Glib::RefPtr selected
+ = tagView_.get_selection();
+
+ if( Tag::ALL_PHOTOS_TAGID == selected->count_selected_rows() )
+ return;
+
+ const TagViewModelColumnRecord &rec
+ = tagView_.get_column_records();
+
+ DeletionQueue &queue
+ = application_->get_engine().get_delete_actions();
+
+ for( Gtk::TreeModel::iterator item = selected->get_selected();
+ item != selected->get_model()->children().end(); item++ )
+ {
+ Gtk::TreeModel::Row row= (*item);
+ TagPtr tag = row[ rec.get_column_tag() ];
+ if( tag && tag->get_tag_id() )
+ {
+ DeleteActionPtr action = tag->get_delete_action();
+ queue.schedule_delete_action( action );
+ }
+
+ }
+}
+
+void
TagManager::on_action_apply_tag() throw()
{
Glib::RefPtr selected
@@ -289,6 +325,9 @@ TagManager::on_action_apply_tag() throw()
Gtk::TreeModel::Row row= (*item);
TagPtr tag = row[ rec.get_column_tag() ];
+ if( Tag::ALL_PHOTOS_TAGID == tag->get_tag_id() )
+ return;
+
Engine &engine = application_->get_engine();
RendererPtr renderer = engine.get_current_renderer();
@@ -301,6 +340,46 @@ TagManager::on_action_apply_tag() throw()
}
void
+TagManager::on_action_remove_tag() 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() ];
+
+ if( Tag::ALL_PHOTOS_TAGID == tag->get_tag_id() )
+ return;
+
+ Engine &engine = application_->get_engine();
+ RendererPtr renderer = engine.get_current_renderer();
+ PhotoList photos = renderer->get_current_selection();
+ DeletionQueue &queue
+ = application_->get_engine().get_delete_actions();
+
+ for( PhotoList::iterator it = photos.begin();
+ it != photos.end(); it++ )
+ {
+ PhotoTag photoTag( (*it)->get_photo_id(),
+ tag->get_tag_id() );
+ DeleteActionPtr action = photoTag.get_delete_action();
+ queue.schedule_delete_action( action );
+ }
+ }
+
+ return;
+}
+
+void
TagManager::populate_view() throw()
{
Engine & engine = application_->get_engine();
diff --git a/src/attribute/tag-manager.h b/src/attribute/tag-manager.h
index ba69b81..2262e4a 100644
--- a/src/attribute/tag-manager.h
+++ b/src/attribute/tag-manager.h
@@ -56,9 +56,15 @@ protected:
on_action_tag_edit() throw();
void
+ on_action_tag_delete() throw();
+
+ void
on_action_apply_tag() throw();
void
+ on_action_remove_tag() throw();
+
+ void
populate_view() throw();
ApplicationPtr application_;
diff --git a/src/attribute/tag-view.cpp b/src/attribute/tag-view.cpp
index ee5e181..12601a6 100644
--- a/src/attribute/tag-view.cpp
+++ b/src/attribute/tag-view.cpp
@@ -99,7 +99,9 @@ TagView::populate(const TagList & tags) throw()
row[modelColumnRecord_.get_column_tag()] = tag;
if( isSelectionAllowed_ )
{
- row[modelColumnRecord_.get_column_selected()] = false;
+ row[modelColumnRecord_.get_column_selected()]
+ = (Tag::ALL_PHOTOS_TAGID != tag->get_tag_id())
+ ? false : true;
}
PixbufPtr pixbuf;
@@ -136,6 +138,10 @@ TagView::on_row_activated ( const Gtk::TreeModel::Path& path,
Gtk::TreeModel::iterator current = listStore_->get_iter( path );
Gtk::TreeModel::Row row = (*current);
+ TagPtr tag = row[modelColumnRecord_.get_column_tag()];
+ if( Tag::ALL_PHOTOS_TAGID == tag->get_tag_id() )
+ return; //User will not be able to unselect
+
row[modelColumnRecord_.get_column_selected()]
= !( row[modelColumnRecord_.get_column_selected()] ) ;
diff --git a/src/attribute/tag.cpp b/src/attribute/tag.cpp
index d53a1a6..1c5bd09 100644
--- a/src/attribute/tag.cpp
+++ b/src/attribute/tag.cpp
@@ -28,6 +28,8 @@
namespace Solang
{
+const gint32 Tag::ALL_PHOTOS_TAGID = 0;
+
const gint32 Tag::TAGID_COL = 0;
const gint32 Tag::NAME_COL = 1;
const gint32 Tag::DESCRIPTION_COL = 2;
@@ -124,25 +126,34 @@ void Tag::create( DataModelPtr& dataModel, gint32 row) throw(Error)
return;
}
-#if 0
-Glib::ustring Tag::getCreateSQL() throw(Error)
-{
- std::ostringstream sout;
- Glib::ustring sql("insert into tags(tagid, tag, description, iconPath) values(NULL,'");
- sout<retrieve(*this);
}
-void Photo::set_disk_file_path(const Glib::ustring & disk_file_path)
+void
+Photo::set_disk_file_path(const Glib::ustring & disk_file_path)
{
diskFilePath_ = disk_file_path;
}
@@ -86,7 +90,8 @@ Photo::set_content_type(const Glib::ustring & contentType) throw()
contentType_ = contentType;
}
-void Photo::insert( DataModelPtr &model, gint32 lastIndex) throw(Error)
+void
+Photo::insert( DataModelPtr &model, gint32 lastIndex) throw(Error)
{
std::vector values;
@@ -121,7 +126,8 @@ void Photo::insert( DataModelPtr &model, gint32 lastIndex) throw(Error)
return;
}
-void Photo::update( DataModelPtr &model, gint32 row) throw(Error)
+void
+Photo::update( DataModelPtr &model, gint32 row) throw(Error)
try
{
if( get_uri().length() > 0
@@ -155,7 +161,8 @@ catch(Glib::Error &e)
throw;
}
-void Photo::create(
+void
+Photo::create(
DataModelPtr& dataModel, int32_t row) throw(Error)
{
set_row_( row );
@@ -181,6 +188,27 @@ void Photo::create(
return;
}
+DeleteActionPtr
+Photo::get_delete_action() throw()
+{
+ DeleteActionPtr action(
+ new DeleteAction( "Photo", this ));
+ if( get_is_deleted() )
+ return action;
+
+ {
+ std::ostringstream sout;
+ sout<<"delete from photos where photoid="<add_command( sout.str() );
+ }
+ {
+ std::ostringstream sout;
+ sout<<"delete from photo_tags where photoid="<add_command( sout.str() );
+ }
+ return action;
+}
+
Glib::ustring
Photo::get_db_object_type_name() const throw()
{
diff --git a/src/common/photo.h b/src/common/photo.h
index 53b6cec..333143b 100644
--- a/src/common/photo.h
+++ b/src/common/photo.h
@@ -2,17 +2,17 @@
/*
* photo.h
* Copyright (C) Santanu Sinha 2009
- *
+ *
* photo.h is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* photo.h is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
@@ -42,11 +42,17 @@ class Photo :
Photo() throw();
~Photo() throw();
- inline gint64 get_photo_id() const throw();
- void set_photoId_( gint64 photoId ) throw();
+ inline gint64
+ get_photo_id() const throw();
- inline const Glib::ustring &get_uri() const throw();
- void set_uri( const Glib::ustring &uri );
+ void
+ set_photoId_( gint64 photoId ) throw();
+
+ inline const Glib::ustring &
+ get_uri() const throw();
+
+ void
+ set_uri( const Glib::ustring &uri );
inline const Glib::ustring &
get_content_type() const throw();
@@ -54,7 +60,7 @@ class Photo :
void
set_content_type( const Glib::ustring &contentType ) throw();
- inline const Glib::ustring
+ inline const Glib::ustring
& get_disk_file_path() const throw();
inline const ModificationDate &
@@ -62,19 +68,7 @@ class Photo :
void
set_modification_date( const ModificationDate &modDate );
-#if 0
- inline const Glib::ustring &
- get_thumbnail_path() const;
-
- void
- set_thumbnail_path(const Glib::ustring & path);
-
- inline const Resolution &
- get_thumbnail_resolution() const throw();
- void
- set_thumbnail_resolution(const Resolution & resolution);
-#endif
inline const Thumbnail &
get_thumbnail() const throw();
@@ -84,39 +78,31 @@ class Photo :
inline const ExifData &
get_exif_data() const throw();
- void
- set_exif_data( const ExifData &exif ) throw();
-#if 0
void
- generate_thumbnail(const Resolution & new_resolution,
- const DatabasePtr & db) throw(Error);
+ set_exif_data( const ExifData &exif ) throw();
void
- generate_thumbnail() throw(Error);
+ set_disk_file_path(const IStoragePtr & storage);
void
- generate_thumbnail(
- const Exiv2::ExifData & exifData) throw(Error);
-#endif
- void set_disk_file_path(const IStoragePtr & storage);
- void set_disk_file_path(const Glib::ustring &disk_file_path);
-
+ set_disk_file_path(const Glib::ustring &disk_file_path);
//Overrides from DBObject
-// virtual Glib::ustring getCreateSQL() throw(Error);
- virtual void insert(
- DataModelPtr &model, gint32 lastIndex) throw(Error);
- virtual void update(
- DataModelPtr &model, gint32 row) throw(Error);
+ virtual void
+ insert( DataModelPtr &model, gint32 lastIndex) throw(Error);
-// void create(Database &db, gint32 row) throw(Error);
+ virtual void
+ update( DataModelPtr &model, gint32 row) throw(Error);
+
+ virtual void
+ create( DataModelPtr& dataModel, gint32 row) throw(Error);
- virtual void create(
- DataModelPtr& dataModel, gint32 row) throw(Error);
-
virtual Glib::ustring
get_db_object_type_name() const throw();
+ virtual DeleteActionPtr
+ get_delete_action() throw();
+
private:
void
make_thumb_path() throw(Error);
@@ -129,7 +115,7 @@ class Photo :
gint64 photoId_;
Glib::ustring uri_; //storage uri
Glib::ustring contentType_; //content type
- Glib::ustring diskFilePath_;
+ Glib::ustring diskFilePath_;
//Date
ModificationDate modDate_;
@@ -142,7 +128,7 @@ class Photo :
};
-inline gint64
+inline gint64
Photo::get_photo_id() const throw()
{
return photoId_;
@@ -153,7 +139,7 @@ Photo::get_uri() const throw()
{
return uri_;
}
-
+
inline const Glib::ustring &
Photo::get_content_type() const throw()
{
diff --git a/src/common/types.h b/src/common/types.h
index ca3bdf4..330e648 100644
--- a/src/common/types.h
+++ b/src/common/types.h
@@ -50,14 +50,19 @@ typedef const Database * ConstDatabasePtr;
typedef Database * DatabasePtr;
class DBObject;
-typedef std::tr1::shared_ptr ConstDBObjectPtr;
-typedef std::tr1::shared_ptr DBObjectPtr;
+typedef const DBObject * ConstDBObjectPtr;
+typedef DBObject * DBObjectPtr;
typedef std::vector DBObjectList;
class DBTable;
typedef std::tr1::shared_ptr ConstDBTablePtr;
typedef std::tr1::shared_ptr DBTablePtr;
+class DeleteAction;
+typedef std::tr1::shared_ptr ConstDeleteActionPtr;
+typedef std::tr1::shared_ptr DeleteActionPtr;
+typedef std::vector DeleteActionList;
+
class ExifDataKey;
typedef std::tr1::shared_ptr ExifDataKeyPtr;
typedef std::vector ExifDataKeyList;
diff --git a/src/database/Makefile.am b/src/database/Makefile.am
index dd9a060..fa5c3b3 100644
--- a/src/database/Makefile.am
+++ b/src/database/Makefile.am
@@ -3,13 +3,15 @@ noinst_LTLIBRARIES = libdatabase.la
libdatabase_la_SOURCES = \
database.cpp \
database.h \
+ delete-action.cpp \
+ delete-action.h \
db-object.cpp \
db-object.h \
db-table.cpp \
db-table-factory.cpp \
db-table-factory.h \
db-table-visitor.cpp \
- db-table-visitor.h \
+ db-table-visitor.h \
db-table.h \
exifs-table.cpp \
exifs-table.h \
diff --git a/src/database/database.cpp b/src/database/database.cpp
index aecc6bd..e41807f 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -161,6 +161,18 @@ DBTablePtr Database::getTable(const Glib::ustring &tableName) const
return DBTablePtr( );
}
+void Database::run_sql( const Glib::ustring &sql ) throw(Error)
+{
+ try
+ {
+ gdaConnection_->execute_non_select_command( sql );
+ }
+ catch(Glib::Error &error)
+ {
+ std::cerr<<"Error: "<close();
@@ -388,6 +400,14 @@ Database::create_db() throw(Error)
description varchar(255),\
iconpath varchar(255))";
gdaConnection_->execute_non_select_command( sql );
+
+ //Create the all photos tag
+ {
+ Glib::ustring sql = "INSERT INTO tags\
+ values(0, 'All Photos', \
+ 'All photos imported in solang','')";
+ gdaConnection_->execute_non_select_command( sql );
+ }
}
//Photo Tags
{
diff --git a/src/database/database.h b/src/database/database.h
index c084692..fabfdb4 100644
--- a/src/database/database.h
+++ b/src/database/database.h
@@ -69,6 +69,8 @@ class Database
//Get table object
DBTablePtr getTable(const Glib::ustring &tableName) const;
+ void run_sql(const Glib::ustring &sql) throw(Error);
+
void close() throw(Error);
//Utility functions
diff --git a/src/database/db-object.cpp b/src/database/db-object.cpp
index 0de132d..b24b41f 100644
--- a/src/database/db-object.cpp
+++ b/src/database/db-object.cpp
@@ -1,23 +1,24 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
- * db-object.cpp
* Copyright (C) Santanu Sinha 2009
- *
- * db-object.cpp is free software: you can redistribute it and/or modify it
+ *
+ * Solang is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * d-b-object.cpp is distributed in the hope that it will be useful, but
+ *
+ * Solang is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
+#ifdef HAVE_CONFIG_H
#include "config.h"
+#endif
#include "database.h"
#include "db-object.h"
@@ -35,7 +36,8 @@ DBObject::~DBObject() throw()
{
}
-void DBObject::save(Database &db) throw(Error)
+void
+DBObject::save(Database &db) throw(Error)
{
if( !get_table_() ) // If this is not in the DB
{
@@ -56,7 +58,8 @@ void DBObject::save(Database &db) throw(Error)
return;
}
-void DBObject::create(Database &db, gint32 row) throw(Error)
+void
+DBObject::create(Database &db, gint32 row) throw(Error)
{
DBTablePtr table;
if( ! (table = get_table_()) )
@@ -64,8 +67,8 @@ void DBObject::create(Database &db, gint32 row) throw(Error)
table = db.getTable(get_db_object_type_name());
set_table_( table );
}
-
- Glib::RefPtr model
+
+ Glib::RefPtr model
= table->get_model();
create( model, row );
@@ -73,7 +76,8 @@ void DBObject::create(Database &db, gint32 row) throw(Error)
}
-void DBObject::update( DataModelPtr &model ) throw(Error)
+void
+DBObject::update( DataModelPtr &model ) throw(Error)
{
try
{
@@ -87,7 +91,8 @@ void DBObject::update( DataModelPtr &model ) throw(Error)
return;
}
-void DBObject::remove( DataModelPtr &model ) throw(Error)
+void
+DBObject::remove( DataModelPtr &model ) throw(Error)
{
try
{
@@ -100,7 +105,8 @@ void DBObject::remove( DataModelPtr &model ) throw(Error)
}
}
-void DBObject::remove( DataModelPtr &model, gint32 row ) throw(Error)
+void
+DBObject::remove( DataModelPtr &model, gint32 row ) throw(Error)
{
try
{
@@ -114,14 +120,28 @@ void DBObject::remove( DataModelPtr &model, gint32 row ) throw(Error)
return;
}
-void DBObject::set_row_( gint32 row ) throw()
+void
+DBObject::remove_physical_existence() throw()
+{
+ //Hoge Hoge :-P
+}
+
+void
+DBObject::set_row_( gint32 row ) throw()
{
row_ = row;
}
-void DBObject::set_table_( const DBTablePtr &table ) throw()
+void
+DBObject::set_table_( const DBTablePtr &table ) throw()
{
table_ = table;
}
+void
+DBObject::set_is_deleted( bool value ) throw()
+{
+ isDeleted_ = value;
+}
+
} //namespace Solang
diff --git a/src/database/db-object.h b/src/database/db-object.h
index 5f79da7..e8a7714 100644
--- a/src/database/db-object.h
+++ b/src/database/db-object.h
@@ -22,6 +22,7 @@
#include
+#include "delete-action.h"
#include "error.h"
#include "non-copyable.h"
#include "types.h"
@@ -39,46 +40,72 @@ class DBObject :
private:
gint32 row_;
DBTablePtr table_;
+ bool isDeleted_;
protected:
DBObject() throw();
public:
- virtual ~DBObject() throw();
-
- void save(Database & db) throw(Error);
-
- virtual void insert(
- DataModelPtr &model, gint32 lastIndex ) throw(Error) = 0;
- virtual void update( DataModelPtr &model ) throw(Error);
- virtual void update(
- DataModelPtr &model, gint32 row ) throw(Error) = 0;
- virtual void remove( DataModelPtr &model ) throw(Error);
- virtual void remove(
- DataModelPtr &model, gint32 row ) throw(Error);
+ virtual
+ ~DBObject() throw();
+
+ void
+ save(Database & db) throw(Error);
+
+ virtual void
+ insert( DataModelPtr &model, gint32 lastIndex) throw(Error)=0;
+
+ virtual void
+ update( DataModelPtr &model ) throw(Error);
+
+ virtual void
+ update( DataModelPtr &model, gint32 row ) throw(Error) = 0;
+
+ virtual void
+ remove( DataModelPtr &model ) throw(Error);
+
+ virtual void
+ remove( DataModelPtr &model, gint32 row ) throw(Error);
+
+ virtual void
+ remove_physical_existence() throw();
//create insert into ... SQL and save this object to DB
//virtual Glib::ustring getCreateSQL() throw(Error) = 0;
- virtual void create(Database & db, gint32 row ) throw(Error);
+ virtual void
+ create(Database & db, gint32 row ) throw(Error);
//Construct object from a row in the
//given datamodel
- virtual void create(
- DataModelPtr& dataModel, gint32 row) throw(Error) = 0;
+ virtual void
+ create( DataModelPtr& dataModel, gint32 row) throw(Error) = 0;
-
//Will be used by DB engine to construct the name
//of tables in indices
virtual Glib::ustring
get_db_object_type_name() const throw() = 0;
- inline gint32 get_row_() const throw();
- void set_row_( gint32 row ) throw();
+ virtual DeleteActionPtr
+ get_delete_action() throw() = 0;
+
+ inline gint32
+ get_row_() const throw();
+
+ void
+ set_row_( gint32 row ) throw();
- inline const DBTablePtr &get_table_() const throw();
- void set_table_( const DBTablePtr &table ) throw();
-
+ inline const DBTablePtr &
+ get_table_() const throw();
+
+ void
+ set_table_( const DBTablePtr &table ) throw();
+
+ inline bool
+ get_is_deleted() const throw();
+
+ void
+ set_is_deleted( bool value ) throw();
};
@@ -89,7 +116,12 @@ inline gint32 DBObject::get_row_() const throw()
inline const DBTablePtr &DBObject::get_table_() const throw()
{
return table_;
-}
+}
+inline bool
+DBObject::get_is_deleted() const throw()
+{
+ return isDeleted_;
+}
} // namespace Solang
diff --git a/src/database/delete-action.cpp b/src/database/delete-action.cpp
new file mode 100644
index 0000000..0a019f3
--- /dev/null
+++ b/src/database/delete-action.cpp
@@ -0,0 +1,83 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * Copyright (C) Santanu Sinha 2009
+ *
+ * Solang is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Solang is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "database.h"
+#include "delete-action.h"
+
+namespace Solang
+{
+
+DeleteAction::DeleteAction( const Glib::ustring &name,
+ const DBObjectPtr &object ) throw()
+ :commandName_( name ),
+ commands_(),
+ object_( object )
+{
+}
+
+DeleteAction::DeleteAction( const DeleteAction &rhs ) throw()
+ : commandName_( rhs.commandName_ ),
+ commands_( rhs.commands_ ),
+ object_( rhs.object_ )
+{
+}
+
+DeleteAction::~DeleteAction() throw()
+{
+}
+
+DeleteAction &
+DeleteAction::operator = ( const DeleteAction &rhs ) throw()
+{
+ if( this != &rhs )
+ {
+ commandName_ = rhs.commandName_;
+ commands_ = rhs.commands_;
+ object_ = rhs .object_;
+ }
+ return *this;
+}
+
+void
+DeleteAction::add_command( const Glib::ustring &sql ) throw()
+{
+ commands_.push_back( sql );
+ return;
+}
+
+void
+DeleteAction::execute( Database &db ) throw()
+{
+ if( object_ && !object_->get_is_deleted() )
+ {
+ //This object has been undeleted
+ return;
+ }
+ for( std::vector::iterator sql = commands_.begin();
+ sql != commands_.end(); sql++ )
+ {
+ db.run_sql( *sql );
+ }
+
+ if( object_ )
+ object_->remove_physical_existence();
+
+ return;
+}
+
+} //namespace Solang
diff --git a/src/database/delete-action.h b/src/database/delete-action.h
new file mode 100644
index 0000000..7f0d50b
--- /dev/null
+++ b/src/database/delete-action.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * Copyright (C) Santanu Sinha 2009
+ *
+ * Solang is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Solang is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#ifndef SOLANG_DELETE_ACTION_H
+#define SOLANG_DELETE_ACTION_H
+
+#include
+
+#include
+
+#include "types.h"
+
+namespace Solang
+{
+
+class DeleteAction
+{
+ public:
+
+ DeleteAction( const Glib::ustring &name,
+ const DBObjectPtr &object ) throw();
+ DeleteAction( const DeleteAction &rhs ) throw();
+ virtual ~DeleteAction() throw();
+
+ DeleteAction &
+ operator = ( const DeleteAction &rhs ) throw();
+
+ void
+ add_command( const Glib::ustring &sql ) throw();
+
+ inline const Glib::ustring &
+ get_command_name() const throw();
+
+ void
+ execute( Database &db ) throw();
+
+ private:
+ Glib::ustring commandName_;
+ std::vector commands_;
+ DBObjectPtr object_;
+
+};
+
+inline const Glib::ustring &
+DeleteAction::get_command_name() const throw()
+{
+ return commandName_;
+}
+
+} //namespace Solang
+
+#endif //SOLANG_DELETE_ACTION_H
--
1.6.3.1