From e4919de8b120ee77e26d8d79febe3ac40666b285 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Thu, 21 May 2009 16:00:56 +0530 Subject: [PATCH 4/4] Support for Date Wise Photo count generation A new class DatePhotoInfo was added. A list of this type of objects is returned by the Engine if required. The query canbe filtered using the paramters of this function. --- src/application/engine.cpp | 8 +++++ src/application/engine.h | 4 ++ src/attribute/Makefile.am | 2 + src/attribute/date-photo-info.cpp | 53 ++++++++++++++++++++++++++++++ src/attribute/date-photo-info.h | 41 +++++++++++++++++++++++ src/common/types.h | 3 ++ src/database/database.cpp | 64 +++++++++++++++++++++++++++++++++++++ src/database/database.h | 45 ++++++++++++++----------- 8 files changed, 200 insertions(+), 20 deletions(-) create mode 100644 src/attribute/date-photo-info.cpp create mode 100644 src/attribute/date-photo-info.h diff --git a/src/application/engine.cpp b/src/application/engine.cpp index 61419d3..4773c01 100644 --- a/src/application/engine.cpp +++ b/src/application/engine.cpp @@ -21,6 +21,7 @@ #include "config.h" #endif // HAVE_CONFIG_H +#include "date-photo-info.h" #include "engine.h" #include "i-photo-destination.h" #include "i-photo-source.h" @@ -340,6 +341,13 @@ Engine::apply_tag_to_photos( PhotoList &photos, const TagPtr &tag ) return; } +DatePhotoInfoList +Engine::get_dates_with_picture_count(gint year, gint month, gint day) +{ + return database_.get_dates_with_picture_count( + year, month, day, observer_ ); +} + Glib::Dispatcher & Engine::photo_import_begin() throw() { diff --git a/src/application/engine.h b/src/application/engine.h index 14917b0..946f839 100644 --- a/src/application/engine.h +++ b/src/application/engine.h @@ -119,6 +119,10 @@ class Engine : void apply_tag_to_photos( PhotoList &photos, const TagPtr &tag ); + + DatePhotoInfoList + get_dates_with_picture_count( + gint year = -1, gint month = -1, gint day = -1); Glib::Dispatcher & photo_import_begin() throw(); diff --git a/src/attribute/Makefile.am b/src/attribute/Makefile.am index 3d4fc98..b2fcf1a 100644 --- a/src/attribute/Makefile.am +++ b/src/attribute/Makefile.am @@ -5,6 +5,8 @@ libattribute_la_SOURCES = \ basic-exif-view-model-column-record.h \ basic-exif-view.cpp \ basic-exif-view.h \ + date-photo-info.cpp \ + date-photo-info.h \ exif-data-key.cpp \ exif-data-key.h \ exif-data.cpp \ diff --git a/src/attribute/date-photo-info.cpp b/src/attribute/date-photo-info.cpp new file mode 100644 index 0000000..531ac23 --- /dev/null +++ b/src/attribute/date-photo-info.cpp @@ -0,0 +1,53 @@ +#include "date-photo-info.h" + +namespace Solang +{ + +DatePhotoInfo::DatePhotoInfo() + :date_(), + count_(0) +{ +} + +DatePhotoInfo::DatePhotoInfo( + const ModificationDate &date, gint count ) + :date_( date ), + count_( count ) +{ +} + +DatePhotoInfo::DatePhotoInfo( const DatePhotoInfo &rhs ) + :date_( rhs.date_ ), + count_( rhs.count_ ) +{ +} + + +DatePhotoInfo::~DatePhotoInfo() +{ +} + +DatePhotoInfo & +DatePhotoInfo::operator =( const DatePhotoInfo &rhs ) +{ + if( this != &rhs ) + { + date_ = rhs.date_; + count_ = rhs.count_; + } + return *this; +} + +void +DatePhotoInfo::set_date( const ModificationDate &date) throw() +{ + date_ = date; +} + +void +DatePhotoInfo::set_count(gint count) throw() +{ + count_ = count; +} + +} diff --git a/src/attribute/date-photo-info.h b/src/attribute/date-photo-info.h new file mode 100644 index 0000000..3c6110a --- /dev/null +++ b/src/attribute/date-photo-info.h @@ -0,0 +1,41 @@ +#ifndef SOLANG_DATE_PHOTO_INFO_H +#define SOLANG_DATE_PHOTO_INFO_H + +#include "modification-date.h" + +namespace Solang +{ + +class DatePhotoInfo +{ + public: + DatePhotoInfo(); + DatePhotoInfo( const ModificationDate &, gint); + DatePhotoInfo( const DatePhotoInfo & ); + ~DatePhotoInfo(); + + DatePhotoInfo & + operator =( const DatePhotoInfo & ); + + inline const ModificationDate & + get_date() const throw(); + + void + set_date( const ModificationDate &) throw(); + + inline gint + get_count() const throw(); + + void + set_count(gint) throw(); + + private: + ModificationDate date_; + gint count_; + +}; + +} //namespace Solang + + +#endif //SOLANG_DATE_PHOTO_INFO_H diff --git a/src/common/types.h b/src/common/types.h index 5750ab4..082a9bd 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -68,6 +68,9 @@ class IPlugin; typedef std::tr1::shared_ptr ConstIPluginPtr; typedef std::tr1::shared_ptr IPluginPtr; +class DatePhotoInfo; +typedef std::list DatePhotoInfoList; + class Photo; typedef std::tr1::shared_ptr ConstPhotoPtr; typedef std::tr1::shared_ptr PhotoPtr; diff --git a/src/database/database.cpp b/src/database/database.cpp index 121c094..27d5f41 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -26,6 +26,7 @@ #include "db-table-factory.h" #include "progress-observer.h" #include "thumbnail.h" +#include "date-photo-info.h" namespace Solang { @@ -211,7 +212,70 @@ PhotoList Database::search( << std::endl; } return photos; +} + +DatePhotoInfoList +Database::get_dates_with_picture_count( + gint year, gint month, gint day, + const ProgressObserverPtr &observer) +{ + Glib::ustring sql + = "select mod_year, mod_month, mod_day, count(*) from photos "; + if( -1 != year ) + { + std::ostringstream sout; + sout<<" and mod_year="< query + = Gnome::Gda::Query::create( gdaDict_ ); + query->set_sql_text( sql ); + Glib::RefPtr model + = Gnome::Gda::DataModelQuery::create( query ); + + gint32 numRows = model->get_n_rows(); + observer->set_num_events( numRows ); + observer->set_event_description( + "Generating summary of photos" ); + + for( gint32 row = 0; row < numRows; row++ ) + { + if( !observer->get_stop() ) + { + infos.push_back( + DatePhotoInfo( + ModificationDate( + model->get_value_at( 0, row ).get_int(), + model->get_value_at( 1, row ).get_int(), + model->get_value_at( 2, row ).get_int()), + model->get_value_at( 3, row ).get_int())); + observer->receive_event_notifiation(); + } + } + } + catch(Glib::Error &e) + { + std::cerr << __FILE__ << ":" << __LINE__ << ", " + << __FUNCTION__ << ": " << e.what() + << std::endl; + } + return infos; } diff --git a/src/database/database.h b/src/database/database.h index fc8350b..5856ba7 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -38,12 +38,12 @@ namespace Solang class Database { private: - static const Glib::ustring DB_NAME; + static const Glib::ustring DB_NAME; Glib::ustring path_; //Path to SQLLite database - Glib::RefPtr gdaClient_; - Glib::RefPtr gdaConnection_; - Glib::RefPtr gdaDict_; - std::map tables_; + Glib::RefPtr gdaClient_; + Glib::RefPtr gdaConnection_; + Glib::RefPtr gdaDict_; + std::map tables_; public: Database( @@ -58,28 +58,33 @@ class Database inline const Glib::ustring &get_path() const; void set_path(const Glib::ustring &path); - void open() throw(Error); + void open() throw(Error); - //Base functions + //Base functions - //Save DBObject(s) to table - void save( DBObject &object ) throw(Error); - void save( const DBObjectList &objects, + //Save DBObject(s) to table + void save( DBObject &object ) throw(Error); + void save( const DBObjectList &objects, ProgressObserverPtr &observer ) throw(Error); - //Get table object - DBTablePtr getTable(const Glib::ustring &tableName) const; + //Get table object + DBTablePtr getTable(const Glib::ustring &tableName) const; - void close() throw(Error); + void close() throw(Error); - //Utility functions - //The following function list of valid photo id's - PhotoList search( - const PhotoSearchCriteriaList &criterion, - const ProgressObserverPtr & observer) throw(Error); + //Utility functions + //The following function list of valid photo id's + PhotoList search( + const PhotoSearchCriteriaList &criterion, + const ProgressObserverPtr & observer) throw(Error); -// TagList getTags(const PhotoPtr &photo) const throw(Error); -// void saveTags(const PhotoPtr &photo) throw(Error); + DatePhotoInfoList + get_dates_with_picture_count( + gint year, gint month, gint day, + const ProgressObserverPtr &); + +// TagList getTags(const PhotoPtr &photo) const throw(Error); +// void saveTags(const PhotoPtr &photo) throw(Error); }; -- 1.6.2.1