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
Version: $Name: $ $Revision: 1.12 $
Version: $Name: $ $Revision: 1.13 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 08-Dec-03, ahu: created
*/
// *****************************************************************************
#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
@ -105,6 +105,7 @@ namespace Action {
registerTask(rename, Task::AutoPtr(new Rename));
registerTask(erase, Task::AutoPtr(new Erase));
registerTask(extract, Task::AutoPtr(new Extract));
registerTask(insert, Task::AutoPtr(new Insert));
} // TaskFactory c'tor
Task::AutoPtr TaskFactory::create(TaskType type)
@ -504,11 +505,25 @@ namespace Action {
return 1;
} // Extract::run
int Extract::writeExifData(const Exif::ExifData& exifData) const
int Extract::writeExifData(Exif::ExifData& exifData) const
{
// Todo: implement me!
std::cout << "Sorry, the extract action for Exif data has not been implemented yet.\n";
return 0;
std::string exvPath = Util::dirname(path_) + "/"
+ Util::basename(path_, true) + ".exv";
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
@ -535,6 +550,9 @@ namespace Action {
if (s[0] != 'y' && s[0] != 'Y') return 0;
}
int rc = exifData.writeThumbnail(thumb);
if (rc) {
std::cerr << exifWriteError(rc, thumb) << "\n";
}
return rc;
}
@ -548,6 +566,42 @@ namespace Action {
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)
try {
adjustment_ = Params::instance().adjustment_;
@ -681,7 +735,7 @@ namespace {
std::string error;
switch (rc) {
case -1:
error = "Couldn't open file `" + path + "'";
error = "Failed to open file `" + path + "'";
break;
case -2:
error = "The file contains data of an unknown image type";
@ -710,7 +764,7 @@ namespace {
std::string error;
switch (rc) {
case -1:
error = "Couldn't open file `" + path + "'";
error = "Failed to open file `" + path + "'";
break;
case -2:
error = "The file contains data of an unknown image type";

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

Loading…
Cancel
Save