Added Task Insert, implemented extract and insert functionality

v0.27.3
Andreas Huggel 22 years ago
parent 5cb9ec44d2
commit 4bc4a0dc40

@ -20,13 +20,13 @@
*/ */
/* /*
File: actions.cpp File: actions.cpp
Version: $Name: $ $Revision: 1.12 $ Version: $Name: $ $Revision: 1.13 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 08-Dec-03, ahu: created History: 08-Dec-03, ahu: created
*/ */
// ***************************************************************************** // *****************************************************************************
#include "rcsid.hpp" #include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.12 $ $RCSfile: actions.cpp,v $") EXIV2_RCSID("@(#) $Name: $ $Revision: 1.13 $ $RCSfile: actions.cpp,v $")
// ***************************************************************************** // *****************************************************************************
// included header files // included header files
@ -105,6 +105,7 @@ namespace Action {
registerTask(rename, Task::AutoPtr(new Rename)); registerTask(rename, Task::AutoPtr(new Rename));
registerTask(erase, Task::AutoPtr(new Erase)); registerTask(erase, Task::AutoPtr(new Erase));
registerTask(extract, Task::AutoPtr(new Extract)); registerTask(extract, Task::AutoPtr(new Extract));
registerTask(insert, Task::AutoPtr(new Insert));
} // TaskFactory c'tor } // TaskFactory c'tor
Task::AutoPtr TaskFactory::create(TaskType type) Task::AutoPtr TaskFactory::create(TaskType type)
@ -504,11 +505,25 @@ namespace Action {
return 1; return 1;
} // Extract::run } // Extract::run
int Extract::writeExifData(const Exif::ExifData& exifData) const int Extract::writeExifData(Exif::ExifData& exifData) const
{ {
// Todo: implement me! std::string exvPath = Util::dirname(path_) + "/"
std::cout << "Sorry, the extract action for Exif data has not been implemented yet.\n"; + Util::basename(path_, true) + ".exv";
return 0; if (Params::instance().verbose_) {
std::cout << "Writing Exif data to " << exvPath << "\n";
}
if (!Params::instance().force_ && Util::fileExists(exvPath)) {
std::cout << Params::instance().progname()
<< ": Overwrite `" << exvPath << "'? ";
std::string s;
std::cin >> s;
if (s[0] != 'y' && s[0] != 'Y') return 0;
}
int rc = exifData.writeExifData(exvPath);
if (rc) {
std::cerr << exifWriteError(rc, exvPath) << "\n";
}
return rc;
} }
int Extract::writeThumbnail(const Exif::ExifData& exifData) const int Extract::writeThumbnail(const Exif::ExifData& exifData) const
@ -535,6 +550,9 @@ namespace Action {
if (s[0] != 'y' && s[0] != 'Y') return 0; if (s[0] != 'y' && s[0] != 'Y') return 0;
} }
int rc = exifData.writeThumbnail(thumb); int rc = exifData.writeThumbnail(thumb);
if (rc) {
std::cerr << exifWriteError(rc, thumb) << "\n";
}
return rc; return rc;
} }
@ -548,6 +566,42 @@ namespace Action {
return new Extract(*this); return new Extract(*this);
} }
int Insert::run(const std::string& path)
try {
std::string exvPath = Util::dirname(path) + "/"
+ Util::basename(path, true) + ".exv";
Exif::ExifData exifData;
int rc = exifData.read(exvPath);
if (rc) {
std::cerr << exifReadError(rc, exvPath) << "\n";
return rc;
}
if (Params::instance().verbose_) {
std::cout << "Inserting metadata from " << exvPath << "\n";
}
rc = exifData.write(path);
if (rc) {
std::cerr << exifWriteError(rc, path) << "\n";
}
return rc;
}
catch(const Exif::Error& e)
{
std::cerr << "Exif exception in insert action for file " << path
<< ":\n" << e << "\n";
return 1;
} // Insert::run
Insert::AutoPtr Insert::clone() const
{
return AutoPtr(dynamic_cast<Insert*>(clone_()));
}
Task* Insert::clone_() const
{
return new Insert(*this);
}
int Adjust::run(const std::string& path) int Adjust::run(const std::string& path)
try { try {
adjustment_ = Params::instance().adjustment_; adjustment_ = Params::instance().adjustment_;
@ -681,7 +735,7 @@ namespace {
std::string error; std::string error;
switch (rc) { switch (rc) {
case -1: case -1:
error = "Couldn't open file `" + path + "'"; error = "Failed to open file `" + path + "'";
break; break;
case -2: case -2:
error = "The file contains data of an unknown image type"; error = "The file contains data of an unknown image type";
@ -710,7 +764,7 @@ namespace {
std::string error; std::string error;
switch (rc) { switch (rc) {
case -1: case -1:
error = "Couldn't open file `" + path + "'"; error = "Failed to open file `" + path + "'";
break; break;
case -2: case -2:
error = "The file contains data of an unknown image type"; error = "The file contains data of an unknown image type";

@ -22,7 +22,7 @@
@file actions.hpp @file actions.hpp
@brief Implements base class Task, TaskFactory and the various supported @brief Implements base class Task, TaskFactory and the various supported
actions (derived from Task). actions (derived from Task).
@version $Name: $ $Revision: 1.5 $ @version $Name: $ $Revision: 1.6 $
@author Andreas Huggel (ahu) @author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 11-Dec-03, ahu: created @date 11-Dec-03, ahu: created
@ -52,7 +52,7 @@ namespace Exif {
namespace Action { namespace Action {
//! Enumerates all tasks //! Enumerates all tasks
enum TaskType { none, adjust, print, rename, erase, extract }; enum TaskType { none, adjust, print, rename, erase, extract, insert };
// ***************************************************************************** // *****************************************************************************
// class definitions // class definitions
@ -250,13 +250,29 @@ namespace Action {
@brief Write the %Exif data to a file. The filename is composed by @brief Write the %Exif data to a file. The filename is composed by
replacing the suffix of the image filename with ".exf". replacing the suffix of the image filename with ".exf".
*/ */
int writeExifData(const Exif::ExifData& exifData) const; int writeExifData(Exif::ExifData& exifData) const;
private: private:
virtual Task* clone_() const; virtual Task* clone_() const;
std::string path_; std::string path_;
}; // class Extract }; // class Extract
/*!
@brief %Insert the %Exif data from corresponding *.exv files.
*/
class Insert : public Task {
public:
virtual ~Insert() {}
virtual int run(const std::string& path);
typedef std::auto_ptr<Insert> AutoPtr;
AutoPtr clone() const;
private:
virtual Task* clone_() const;
}; // class Insert
} // namespace Action } // namespace Action
#endif // #ifndef ACTIONS_HPP_ #endif // #ifndef ACTIONS_HPP_

Loading…
Cancel
Save