From 7fe1e5d7f783f85fb19bf2aec199d4d4fcfb38bf Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Sun, 31 May 2009 12:18:42 +0530 Subject: [PATCH] Content Type Handling + Directory storage saves content Type in database during import + Directory source uses Glib::Dir to create file list + Thumbnail generation support for RAW files + Removal of some dead code --- src/application/application.cpp | 3 + src/attribute/exif-data.cpp | 18 +- src/attribute/modification-date.cpp | 6 +- src/attribute/thumbnail.cpp | 34 +--- src/common/Makefile.am | 2 + src/common/content-type-repo.cpp | 99 ++++++++++ src/common/content-type-repo.h | 65 +++++++ src/common/photo.cpp | 343 +++-------------------------------- src/common/photo.h | 91 ++++------ src/common/types.h | 3 + src/database/database.cpp | 4 +- src/database/photos-table.cpp | 3 +- src/importer/camera-source.cpp | 13 -- src/importer/directory-source.cpp | 39 ++-- src/storage/directory-storage.cpp | 52 ++++-- 15 files changed, 313 insertions(+), 462 deletions(-) create mode 100644 src/common/content-type-repo.cpp create mode 100644 src/common/content-type-repo.h diff --git a/src/application/application.cpp b/src/application/application.cpp index f306ce7..eae6c4d 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -32,6 +32,7 @@ #include "browser-renderer.h" #include "camera-source.h" #include "console-renderer.h" +#include "content-type-repo.h" #include "date-manager.h" #include "directory-source.h" #include "directory-storage.h" @@ -320,6 +321,8 @@ Application::init() throw() engine_.set_current_renderer(browser_renderer); + ContentTypeRepo::instance()->init(); + mainWindow_.init(); initEnd_.emit(*this); diff --git a/src/attribute/exif-data.cpp b/src/attribute/exif-data.cpp index e155b4d..603130c 100644 --- a/src/attribute/exif-data.cpp +++ b/src/attribute/exif-data.cpp @@ -25,15 +25,15 @@ namespace Solang { -const gint32 ExifData::APERTURE_COL = 8; -const gint32 ExifData::SHUTTER_SPEED_COL = 9; -const gint32 ExifData::EXPOSURE_PROGRAM_COL = 10; -const gint32 ExifData::ISO_COL = 11; -const gint32 ExifData::EXPOSURE_METERING_MODE_COL = 12; -const gint32 ExifData::FOCAL_LENGTH_COL = 13; -const gint32 ExifData::WHITE_BALANCE_COL = 14; -const gint32 ExifData::FILM_FOCAL_LENGTH_COL = 15; -const gint32 ExifData::PICTURE_TAKEN_TIME = 16; +const gint32 ExifData::APERTURE_COL = 9; +const gint32 ExifData::SHUTTER_SPEED_COL = 10; +const gint32 ExifData::EXPOSURE_PROGRAM_COL = 11; +const gint32 ExifData::ISO_COL = 12; +const gint32 ExifData::EXPOSURE_METERING_MODE_COL = 13; +const gint32 ExifData::FOCAL_LENGTH_COL = 14; +const gint32 ExifData::WHITE_BALANCE_COL = 15; +const gint32 ExifData::FILM_FOCAL_LENGTH_COL = 16; +const gint32 ExifData::PICTURE_TAKEN_TIME = 17; ExifData::ExifData() : aperture_(), diff --git a/src/attribute/modification-date.cpp b/src/attribute/modification-date.cpp index 3be012e..175a716 100644 --- a/src/attribute/modification-date.cpp +++ b/src/attribute/modification-date.cpp @@ -29,9 +29,9 @@ namespace Solang { -const gint32 ModificationDate::MOD_DAY_COL = 2; -const gint32 ModificationDate::MOD_MONTH_COL = 3; -const gint32 ModificationDate::MOD_YEAR_COL = 4; +const gint32 ModificationDate::MOD_DAY_COL = 3; +const gint32 ModificationDate::MOD_MONTH_COL = 4; +const gint32 ModificationDate::MOD_YEAR_COL = 5; Glib::ustring ModificationDate::get_query_criteria() const throw() diff --git a/src/attribute/thumbnail.cpp b/src/attribute/thumbnail.cpp index 56b61f3..294f7b6 100644 --- a/src/attribute/thumbnail.cpp +++ b/src/attribute/thumbnail.cpp @@ -26,6 +26,7 @@ #include #include +#include "content-type-repo.h" #include "database.h" #include "photo.h" #include "thumbnail.h" @@ -33,9 +34,9 @@ namespace Solang { -const gint32 Thumbnail::PATH_COL = 5; -const gint32 Thumbnail::RES_X_COL = 6; -const gint32 Thumbnail::RES_Y_COL = 7; +const gint32 Thumbnail::PATH_COL = 6; +const gint32 Thumbnail::RES_X_COL = 7; +const gint32 Thumbnail::RES_Y_COL = 8; Thumbnail::Thumbnail( ) : path_(), @@ -159,8 +160,9 @@ Thumbnail::generate(const Exiv2::ExifData & exifData, throw; } -#if 0 - if (!exifData.empty()) + if ( ! ContentTypeRepo::instance()->is_gdk_supported( + photo.get_disk_file_path() ) + && ! exifData.empty()) { // Extract from exif if present. if (-1 == exifData.writeThumbnail(get_path().c_str())) @@ -200,7 +202,6 @@ Thumbnail::generate(const Exiv2::ExifData & exifData, set_resolution( res ); } -#endif if (false == thumbnail_generated) { @@ -247,24 +248,6 @@ void Thumbnail::generate_using_gdkpixbuf(const Glib::ustring & path, const Resolution & new_size_hint) { -#if 0 - Glib::ustring tPath = get_path() + ".jpg"; - set_path( tPath ); - - // Open and copy source image. - Magick::Image source(path); - Magick::Image thumbnail(source); - Magick::Geometry imageDim = thumbnail.density(); - - // We need to keep aspect ratio. - // So we consider the height only to derive the resize ratio. - double ratio = static_cast( - new_size_hint.get_y() / imageDim.height() ); - Magick::Geometry newSize( imageDim.width() * ratio , - imageDim.height() * ratio ); - thumbnail.zoom( newSize ); - thumbnail.write( get_path() ); -#endif PixbufPtr thumbnail; try { @@ -287,7 +270,8 @@ Thumbnail::generate_using_gdkpixbuf(const Glib::ustring & path, thumbnail->save( get_path(), "jpeg" ); - set_resolution( Resolution( thumbnail->get_width(), thumbnail->get_height() ) ); + set_resolution( Resolution( + thumbnail->get_width(), thumbnail->get_height() ) ); return; } diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 998ce25..605d93a 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,6 +1,8 @@ noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = \ + content-type-repo.cpp \ + content-type-repo.h \ error.cpp \ error.h \ id-base.h \ diff --git a/src/common/content-type-repo.cpp b/src/common/content-type-repo.cpp new file mode 100644 index 0000000..cca9c72 --- /dev/null +++ b/src/common/content-type-repo.cpp @@ -0,0 +1,99 @@ +/* -*- 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif // HAVE_CONFIG_H + +#include +#include + +#include +#include +#include + + +#include "content-type-repo.h" + +namespace Solang +{ + +ContentTypeRepo::ContentTypeRepo() throw() + :supportedTypes_() +{ +} + +ContentTypeRepo::~ContentTypeRepo() throw() +{ +} + +void +ContentTypeRepo::init() throw() +{ + PixbufFormatList formats = Gdk::Pixbuf::get_formats(); + for( PixbufFormatList::iterator format = formats.begin(); + format != formats.end(); format++ ) + { + std::vector content_types + = (*format).get_mime_types(); + for( std::vector::iterator content + = content_types.begin(); + content != content_types.end(); content++ ) + { + supportedTypes_.push_back( + Gio::content_type_from_mime_type( *content )); + } + } + std::sort( supportedTypes_.begin(), supportedTypes_.end() ); + std::unique( supportedTypes_.begin(), supportedTypes_.end() ); + return; +} + +Glib::ustring +ContentTypeRepo::get_content_type(const std::string &filename ) const throw() +{ + bool uncertain = false; + Glib::ustring contentType + = Gio::content_type_guess( + filename, std::string(), uncertain ); + + if( uncertain ) + return Glib::ustring(); + + return contentType; +} + +bool +ContentTypeRepo::is_gdk_supported( + const std::string &filename ) const throw() +{ + Glib::ustring contentType = get_content_type( filename ); + return std::binary_search( + supportedTypes_.begin(), supportedTypes_.end(), + contentType ); + +} + +const ContentTypeRepoPtr +ContentTypeRepo::instance() throw() +{ + static ContentTypeRepo repoObj; + return &repoObj; +} + +} //namespace Solang diff --git a/src/common/content-type-repo.h b/src/common/content-type-repo.h new file mode 100644 index 0000000..c1404cb --- /dev/null +++ b/src/common/content-type-repo.h @@ -0,0 +1,65 @@ +/* -*- 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_CONTENT_TYPE_REPO_H +#define SOLANG_CONTENT_TYPE_REPO_H + +#include + +#include "non-copyable.h" +#include "types.h" + +namespace Solang +{ + +class ContentTypeRepo + : public NonCopyable +{ + private: + typedef Gdk::Pixbuf::SListHandle_PixbufFormat + PixbufFormatList; + typedef std::vector + SupportedContentTypeList; + + SupportedContentTypeList supportedTypes_; + + //This is a singleton + ContentTypeRepo() throw(); + + public: + + ~ContentTypeRepo() throw(); + + void + init() throw(); + + Glib::ustring + get_content_type(const std::string &filename ) const throw(); + + bool + is_gdk_supported( + const std::string &filename ) const throw(); + + //Static + static const ContentTypeRepoPtr + instance() throw(); +}; + + +} //namespace Solang +#endif diff --git a/src/common/photo.cpp b/src/common/photo.cpp index f6520b8..5d72295 100644 --- a/src/common/photo.cpp +++ b/src/common/photo.cpp @@ -2,22 +2,24 @@ /* * photo.cpp * Copyright (C) Santanu Sinha 2009 - * + * * photo.cpp 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.cpp 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 @@ -31,11 +33,7 @@ namespace Solang const gint32 Photo::PHOTOID_COL = 0; const gint32 Photo::URI_COL = 1; -#if 0 -const gint32 Photo::THUMBNAIL_PATH_COL = 5; -const gint32 Photo::THUMBNAIL_RES_X_COL = 6; -const gint32 Photo::THUMBNAIL_RES_Y_COL = 7; -#endif +const gint32 Photo::CONTENT_TYPE_COL = 2; Photo::Photo() throw() : DBObject(), @@ -47,17 +45,6 @@ Photo::Photo() throw() : { } -#if 0 -Photo::Photo(gint64 photoId, const Glib::ustring & uri) throw() : - DBObject(), - photoId_(photoId), - uri_(uri), - thumbnail_(), - diskFilePath_() -{ -} -#endif - Photo::~Photo() throw() { } @@ -94,22 +81,18 @@ void Photo::set_disk_file_path(const Glib::ustring & disk_file_path) diskFilePath_ = disk_file_path; } -#if 0 -Glib::ustring Photo::getCreateSQL() throw(Error) +void Photo::set_content_type(const Glib::ustring & contentType) { - Glib::ustring sql("insert into photos (photoid,uri) values(\'"); - sql += photoId_ + "', '" ; - sql += uri_ + "')"; - return sql; + contentType_ = contentType; } -#endif void Photo::insert( DataModelPtr &model, gint32 lastIndex) throw(Error) { std::vector values; values.push_back( Gnome::Gda::Value( lastIndex + 1 ) ); //photoid - values.push_back( Gnome::Gda::Value( get_uri() ) ); + values.push_back( Gnome::Gda::Value( get_uri() ) ); + values.push_back( Gnome::Gda::Value( get_content_type() ) ); modDate_.insert( values ); thumbnail_.insert( values ); @@ -130,61 +113,34 @@ void Photo::insert( DataModelPtr &model, gint32 lastIndex) throw(Error) { //TBD::Error } - + set_row_( row ); set_photoId_( lastIndex + 1 ); -#if 0 - if( thumbnail_ ) - { - thumbnail_->insert( model, get_photoId_() ); - } -#endif - return; } void Photo::update( DataModelPtr &model, gint32 row) throw(Error) try { - if( get_uri().length() > 0 - && get_uri() != model->get_value_at( + if( get_uri().length() > 0 + && get_uri() != model->get_value_at( Photo::URI_COL, row ).get_string() ) { - model->set_value_at( + model->set_value_at( Photo::URI_COL, row, Gnome::Gda::Value( get_uri() ) ); } -#if 0 - if( get_thumbnail_path().length() > 0 - && get_thumbnail_path() != model->get_value_at( - PATH_COL, row ).get_string() ) - { - Gnome::Gda::Value v; - v.set( Glib::ustring( get_thumbnail_path() ) ); - model->set_value_at( - PATH_COL, row, Gnome::Gda::Value( v ) ); - } - - if (0 < get_thumbnail_resolution().get_x() - && get_thumbnail_resolution().get_x() != model->get_value_at( - RES_X_COL, row ).get_int() ) + if( get_content_type().length() > 0 + && get_content_type() != model->get_value_at( + Photo::CONTENT_TYPE_COL, row ).get_string() ) { - model->set_value_at( - RES_X_COL, row, Gnome::Gda::Value( - get_thumbnail_resolution().get_x())); + model->set_value_at( + Photo::CONTENT_TYPE_COL, + row, Gnome::Gda::Value( get_content_type() ) ); } - if (0 < get_thumbnail_resolution().get_y() - && get_thumbnail_resolution().get_y() != model->get_value_at( - RES_Y_COL, row ).get_int() ) - { - model->set_value_at( - RES_Y_COL, row, Gnome::Gda::Value( - get_thumbnail_resolution().get_y())); - } -#endif thumbnail_.update( model, row ); exifData_.update( model, row ); @@ -198,55 +154,17 @@ catch(Glib::Error &e) throw; } - -#if 0 -void Photo::create(Database &db, gint32 row) throw(Error) -{ - DBObject::create( db, row ); - - try - { - thumbnail->DBObject::create( db, row ); - } - catch( Error &error ) - { - error.add_call_info( __FUNCTION__, __FILE__, __LINE__ ); - throw; - } - - ExifData exif(); - - set_exif_data( exif ); - - try - { - exif->DBObject::create( , row ); - } - catch( Error &error ) - { - error.add_call_info( __FUNCTION__, __FILE__, __LINE__ ); - throw; - } - - -} -#endif - void Photo::create( DataModelPtr& dataModel, int32_t row) throw(Error) { set_row_( row ); - set_photoId_( dataModel->get_value_at( + set_photoId_( dataModel->get_value_at( PHOTOID_COL, row ).get_int()); set_uri( dataModel->get_value_at( URI_COL, row ).get_string()); -#if 0 - set_thumbnail_path( dataModel->get_value_at( - PATH_COL, row ).get_string()); - Resolution tmp(dataModel->get_value_at(RES_X_COL, row).get_int(), - dataModel->get_value_at(RES_Y_COL, row).get_int()); - set_thumbnail_resolution(tmp); -#endif + set_content_type( + dataModel->get_value_at( CONTENT_TYPE_COL, row ).get_string()); + ModificationDate date; date.create( dataModel, row ); set_modification_date( date ); @@ -256,14 +174,14 @@ void Photo::create( set_thumbnail( thumb ); ExifData data; - data.create( dataModel, row ); + data.create( dataModel, row ); set_exif_data( data ); - return; - + return; + } -Glib::ustring +Glib::ustring Photo::get_db_object_type_name() const throw() { return "photos"; @@ -275,209 +193,4 @@ Photo::set_modification_date( const ModificationDate &modDate ) modDate_ = modDate; } -#if 0 -void -Photo::set_thumbnail_path(const Glib::ustring & path) -{ - path_ = path; -} - -void -Photo::set_thumbnail_resolution(const Resolution & resolution) -{ - resolution_ = resolution; -} - -void -Photo::generate_thumbnail(const Resolution & new_resolution, - const DatabasePtr & db) throw(Error) -{ - if( new_resolution == get_thumbnail_resolution() - || new_resolution < get_thumbnail_resolution() ) - { - return; - } - - //We assume the photo has physical path - if( photo_->get_disk_file_path().empty() ) - { - //TBD::Error - return; - } - - // We resize the thumbnail only. - // Makes it faster. - generate_using_gdkpixbuf( - get_thumbnail_path(), new_resolution); - - db->save( *this ); - - return; - -} - -void -Photo::generate_thumbnail() throw(Error) -{ - try - { - make_thumb_path(); - } - catch(Error & e) - { - //TBD::Error - throw; - } - - generate_using_gdkpixbuf(photo_->get_disk_file_path(), - Resolution(128, 128)); - - return; -} - -void -Photo::generate_thumbnail(const Exiv2::ExifData & exifData) throw(Error) -{ - // We assume the photo has physical path. - if (photo_->get_disk_file_path().empty()) - { - //TBD::Error - return; - } - - Glib::ustring path; - - bool thumbnail_generated = false; - - try - { - make_thumb_path(); - } - catch(Error & e) - { - std::cerr<<"Error::"<get_disk_file_path(), - Resolution(256, 256)); - } - - return; -} - -void -Photo::make_thumb_path() throw(Error) -{ - Glib::RefPtr tFile - = Gio::File::create_for_path( get_thumbnail_path() ); - std::cout<get_thumbnail_path().substr( - 0,get_thumbnail_path().find( tFile->get_basename())) - <tDestPath - = Gio::File::create_for_path( - tFile->get_thumbnail_path().substr( - 0, get_thumbnail_path().find( - tFile->get_basename())) ); -#ifdef GLIBMM_EXCEPTIONS_ENABLED - try - { - tDestPath->make_directory_with_parents(); - } - catch( Glib::Error &) - { - //TBD::Error - } -#else - std::auto_ptr error; - tDestPath->make_directory_with_parents(error); -#endif - return; -} - -void -Photo::generate_using_gdkpixbuf(const Glib::ustring & path, - const Resolution & new_size_hint) -{ - PixbufPtr thumbnail; - try - { - thumbnail = Gdk::Pixbuf::create_from_file( - path, - -1, //We keep aspect - new_size_hint.get_y(), - true); - } - 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; - } - - thumbnail->save( get_thumbnail_path(), "jpeg" ); - - set_thumbnail_resolution( - Resolution( - thumbnail->get_width(), thumbnail->get_height() ) ); - return; -} -#endif - } // namespace Solang diff --git a/src/common/photo.h b/src/common/photo.h index 4e96016..527aa71 100644 --- a/src/common/photo.h +++ b/src/common/photo.h @@ -40,38 +40,35 @@ class Photo : { public: Photo() throw(); -#if 0 - Photo( gint64 photoId, const Glib::ustring &uri ) throw(); -#endif ~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 ); - - inline const Glib::ustring - & get_disk_file_path() const throw(); + void + set_photoId_( gint64 photoId ) throw(); - inline const ModificationDate & - get_modification_date() const throw(); + inline const Glib::ustring & + get_uri() const throw(); void - set_modification_date( const ModificationDate &modDate ); -#if 0 + set_uri( const Glib::ustring &uri ); + inline const Glib::ustring & - get_thumbnail_path() const; + get_content_type() const throw(); void - set_thumbnail_path(const Glib::ustring & path); - - inline const Resolution & - get_thumbnail_resolution() const throw(); + set_content_type( const Glib::ustring &contentType ); + + inline const Glib::ustring & + get_disk_file_path() const throw(); + + inline const ModificationDate & + get_modification_date() const throw(); void - set_thumbnail_resolution(const Resolution & resolution); -#endif + set_modification_date( const ModificationDate &modDate ); + inline const Thumbnail & get_thumbnail() const throw(); @@ -83,33 +80,23 @@ class Photo : void set_exif_data( const ExifData &exif ) throw(); -#if 0 - void - generate_thumbnail(const Resolution & new_resolution, - const DatabasePtr & db) throw(Error); 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(); @@ -121,18 +108,15 @@ class Photo : private: static const gint32 PHOTOID_COL; static const gint32 URI_COL; + static const gint32 CONTENT_TYPE_COL; gint64 photoId_; Glib::ustring uri_; //storage uri + Glib::ustring contentType_; //content type Glib::ustring diskFilePath_; //Date ModificationDate modDate_; - -#if 0 - Glib::ustring thumbnailPath_; - Resolution thumbnailResolution_; -#endif //Thumbnail Thumbnail thumbnail_; //Exif @@ -153,6 +137,12 @@ Photo::get_uri() const throw() return uri_; } +inline const Glib::ustring & +Photo::get_content_type() const throw() +{ + return contentType_; +} + inline const Thumbnail & Photo::get_thumbnail() const throw() { @@ -177,19 +167,6 @@ Photo::get_modification_date() const throw() return modDate_; } -#if 0 -inline const Glib::ustring & -Photo::get_thumbnail_path() const -{ - return thumbnailPath_; -} - -inline const Photo::Resolution & -Photo::get_thumbnail_resolution() const throw() -{ - return thumbnailResolution_; -} -#endif } // namespace Solang #endif // SOLANG_PHOTO_H diff --git a/src/common/types.h b/src/common/types.h index 28f8ef4..23b70fe 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -37,6 +37,9 @@ class Application; typedef const Application * ConstApplicationPtr; typedef Application * ApplicationPtr; +class ContentTypeRepo; +typedef ContentTypeRepo * ContentTypeRepoPtr; + class Database; typedef const Database * ConstDatabasePtr; typedef Database * DatabasePtr; diff --git a/src/database/database.cpp b/src/database/database.cpp index 0f135af..7cb6d1d 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -224,11 +224,12 @@ PhotoList Database::search( } sql += " )"; } + sql += " order by mod_year,mod_month,mod_day,picture_taken_time"; PhotoList photos; try { - std::cout< query = Gnome::Gda::Query::create( gdaDict_ ); query->set_sql_text( sql ); @@ -363,6 +364,7 @@ Database::create_db() throw(Error) Glib::ustring sql = "CREATE TABLE photos(\ photoid integer primary key,\ uri varchar(255),\ + content_type varchar(50),\ mod_day integer,\ mod_month integer,\ mod_year integer,\ diff --git a/src/database/photos-table.cpp b/src/database/photos-table.cpp index ea9828d..4a655f1 100644 --- a/src/database/photos-table.cpp +++ b/src/database/photos-table.cpp @@ -38,7 +38,8 @@ PhotosTable::~PhotosTable() Glib::ustring PhotosTable::getSelectionQuery() const { - return "select * from photos"; + return "select * from photos order by \ + mod_year, mod_month, mod_day, picture_taken_time"; } Glib::ustring PhotosTable::getInsertQuery() const diff --git a/src/importer/camera-source.cpp b/src/importer/camera-source.cpp index a66c89e..b043272 100644 --- a/src/importer/camera-source.cpp +++ b/src/importer/camera-source.cpp @@ -95,24 +95,11 @@ CameraSource::import(const PhotoPtr & photo, Glib::ustring path = photo->get_disk_file_path(); download_file_from_camera( photo ); storage->save(photo, true); -#if 0 - try - { - Glib::RefPtr file - = Gio::File::create_for_path( path ); - file->remove(); - } - catch( Glib::Error &e ) - { - std::cout<<"Error::"<get_photo_id(), (*it)->get_tag_id()); - //std::cout<<"PhotoId= "<get_photo_id()<<"TagId= "<<(*it)->get_tag_id()<get_photo_id(), (*it)->get_tag_id()); - std::cout<<"PhotoId= "<get_photo_id()<<"TagId= "<<(*it)->get_tag_id()<d_name [0] == '.' ) - continue; - Glib::ustring path = prefix + "/" + nameList[i]->d_name; - struct stat info; - if (-1 == stat(path.c_str(), &info)) + Glib::ustring entryPath = dir + "/" + (*entry); + Glib::RefPtr entryFile + = Gio::File::create_for_path( entryPath ); + if( Gio::FILE_TYPE_DIRECTORY + == entryFile->query_file_type() ) { - //TBD::Error - } - if( S_ISDIR( info.st_mode ) ) - { - create_photo_list( list, - Glib::ustring( nameList[i]->d_name ), path ); + create_photo_list( list, entryPath, entryPath ); } else { - PhotoPtr photo(new Photo()); - list.push_back( photo ); - photo->set_disk_file_path(path); - + Glib::ustring contentType + = ContentTypeRepo::instance()->get_content_type( + entryPath ); + if( contentType.find("image/") == 0 ) + { + PhotoPtr photo(new Photo()); + list.push_back( photo ); + photo->set_disk_file_path( entryPath ); + } } } + return; } Gtk::Widget & diff --git a/src/storage/directory-storage.cpp b/src/storage/directory-storage.cpp index de63787..def4401 100644 --- a/src/storage/directory-storage.cpp +++ b/src/storage/directory-storage.cpp @@ -28,6 +28,7 @@ #include #include +#include "content-type-repo.h" #include "directory-storage.h" #include "exif-data.h" #include "token-replacer.h" @@ -85,29 +86,38 @@ void DirectoryStorage::save(const PhotoPtr &photo, bool move) throw(Error) //Read date and time //else use modification date //Create directory and copy file - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open( - photo->get_disk_file_path().c_str()); - if(image.get() != 0); - image->readMetadata(); - - Exiv2::ExifData &exifData = image->exifData(); - if (exifData.empty()) { - //No exif data - } - - Exiv2::ExifKey key("Exif.Photo.DateTimeOriginal"); - Exiv2::ExifData::iterator dateTime = exifData.findKey( key ); guint32 year=0; guint32 month=0; guint32 day=0; - if( dateTime != exifData.end() ) + Exiv2::Image::AutoPtr image; + Exiv2::ExifData exifData; + try { - std::cout<<(*dateTime).toString()<get_disk_file_path().c_str()); + if(image.get() != 0) + { + image->readMetadata(); + exifData = image->exifData(); + if (exifData.empty()) { + //No exif data + } + + Exiv2::ExifKey key("Exif.Photo.DateTimeOriginal"); + Exiv2::ExifData::iterator dateTime = exifData.findKey( key ); + if( dateTime != exifData.end() ) + { + std::cout<<(*dateTime).toString()<get_content_type( + (*photo).get_disk_file_path() ); photo->set_uri( uri ); + photo->set_content_type( contentType ); photo->set_disk_file_path(filePath); //Set modification date -- 1.6.2.1