summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/timeadjust
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-19 18:22:05 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-19 18:22:05 +0000
commit57e10fedbcb8c3e8c6590ff0935dbf017ce5587f (patch)
tree3000a7649ca4e40e43f9e7feed963236a0b0f56b /kipi-plugins/timeadjust
downloadkipi-plugins-57e10fedbcb8c3e8c6590ff0935dbf017ce5587f.tar.gz
kipi-plugins-57e10fedbcb8c3e8c6590ff0935dbf017ce5587f.zip
Import abandoned KDE3 version of kipi plugins
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/kipi-plugins@1077221 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kipi-plugins/timeadjust')
-rw-r--r--kipi-plugins/timeadjust/Makefile.am25
-rw-r--r--kipi-plugins/timeadjust/kipiplugin_timeadjust.desktop55
-rw-r--r--kipi-plugins/timeadjust/plugin_timeadjust.cpp106
-rw-r--r--kipi-plugins/timeadjust/plugin_timeadjust.h55
-rw-r--r--kipi-plugins/timeadjust/timeadjustdialog.cpp550
-rw-r--r--kipi-plugins/timeadjust/timeadjustdialog.h84
6 files changed, 875 insertions, 0 deletions
diff --git a/kipi-plugins/timeadjust/Makefile.am b/kipi-plugins/timeadjust/Makefile.am
new file mode 100644
index 0000000..66e9ade
--- /dev/null
+++ b/kipi-plugins/timeadjust/Makefile.am
@@ -0,0 +1,25 @@
+INCLUDES = $(KIPI_PLUGINS_COMMON_INCLUDE) $(LIBKEXIV2_CFLAGS) $(LIBKIPI_CFLAGS) $(all_includes)
+
+METASOURCES = AUTO
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = kipiplugin_timeadjust.la
+
+kipiplugin_timeadjust_la_DEPENDENCIES = $(LIBKIPI_LIBS_DEP) $(LIBKEXIV2_LIBS_DEP)
+
+# Srcs for the plugin
+kipiplugin_timeadjust_la_SOURCES = plugin_timeadjust.cpp timeadjustdialog.cpp
+
+# Libs needed by the plugin
+kipiplugin_timeadjust_la_LIBADD = $(LIBKEXIV2_LIBS) $(LIBKIPI_LIBS) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT)
+
+# LD flags for the plugin
+kipiplugin_timeadjust_la_LDFLAGS = $(KIPI_PLUGINS_COMMON_LDFLAGS) -module $(KDE_PLUGIN) $(all_libraries) -lkipiplugins
+
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = kipiplugin_timeadjust.desktop
+
+# i18n translation messages
+messages: rc.cpp
+ $(XGETTEXT) *.cpp *.h -o $(podir)/kipiplugin_timeadjust.pot
+
diff --git a/kipi-plugins/timeadjust/kipiplugin_timeadjust.desktop b/kipi-plugins/timeadjust/kipiplugin_timeadjust.desktop
new file mode 100644
index 0000000..5d4c9bd
--- /dev/null
+++ b/kipi-plugins/timeadjust/kipiplugin_timeadjust.desktop
@@ -0,0 +1,55 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=TimeDateAdjust
+Name[ca]=Ajust de data i hora
+Name[cs]=Nastavení data
+Name[da]=Justér dato og tid
+Name[de]=Zeit und Datum anpassen
+Name[el]=ΡύθμισηΏραςΗμερομηνίας
+Name[es]=Ajustar fecha y hora
+Name[et]=Aja kohendamine
+Name[fi]=Päiväyksen tarkistus
+Name[gl]=Axuste de Data e Hora
+Name[it]=RegolazioneDataOra
+Name[nds]=Tiet topassen
+Name[nl]=Tijd/DatumAanpassen
+Name[pl]=Zmiana daty i godziny
+Name[pt]=Ajuste de Data e Hora
+Name[sr]=Подеси време/датум
+Name[sr@Latn]=Podesi vreme/datum
+Name[sv]=Justera datum och tid
+Name[tg]=ТанзимдиҳииТаърих/Вақт
+Name[tr]=ZamanTarihAyarla
+Name[xx]=xxTimeDateAdjustxx
+Name[zh_CN]=日期时间调整
+Comment=KIPI Time and Date Adjust
+Comment[ca]=Connector del KIPI per ajustar la data i l'hora
+Comment[cs]=KIPI nastavení času a data
+Comment[da]=KIPI-plugin: Justér dato og tid
+Comment[de]=Ein KIPI-Modul zum Setzen von Zeit und Datum
+Comment[el]=Ρύθμιση ώρας και ημερομηνίας του KIPI
+Comment[es]=Ajuste de fecha y hora para KIPI
+Comment[et]=KIPI kuupäeva ja kellaaja kohendamine
+Comment[fi]=Kipi-liitännäinen kuvatiedostojen päiväyksen ja ajan asetusta varten
+Comment[fr]=Module externe KIPI pour ajuster la date et l'heure
+Comment[gl]=Axuste de Data e Hora de KIPI
+Comment[it]=Regolazione di data e ora di KIPI
+Comment[ja]=Kipi 日付と時刻の調整
+Comment[nds]=KIPI-Moduul för't Topassen vun Datum un Tiet
+Comment[nl]=KIPI-plugin voor het aanpassen van de datum/tijd
+Comment[pa]=KIPI ਸਮਾਂ ਅਤੇ ਮਿਤੀ ਅਨੁਕੂਲਣ
+Comment[pl]=Wtyczka KIPI - Zmiana daty i godziny
+Comment[pt]=Ajuste de Data e Hora do KIPI
+Comment[pt_BR]=Ajuste de Hora e Data do KIPI
+Comment[sr]=KIPI-јево подешавање времена и датума
+Comment[sr@Latn]=KIPI-jevo podešavanje vremena i datuma
+Comment[sv]=KIPI-insticksprogram: Justera datum och tid
+Comment[tg]=Модули KIPI барои танзимдиҳии таърих ва вақт
+Comment[tr]=KIPI Zaman ve Tarih Ayarlama
+Comment[xx]=xxKIPI Time and Date Adjustxx
+Comment[zh_CN]=KIPI 时间和日期调整
+Type=Service
+ServiceTypes=KIPI/Plugin
+X-KDE-Library=kipiplugin_timeadjust
+author=Gilles Caulier, caulier dot gilles at gmail dot com
+X-KIPI-ReqFeatures=ImagesHasTime
diff --git a/kipi-plugins/timeadjust/plugin_timeadjust.cpp b/kipi-plugins/timeadjust/plugin_timeadjust.cpp
new file mode 100644
index 0000000..de4f5f6
--- /dev/null
+++ b/kipi-plugins/timeadjust/plugin_timeadjust.cpp
@@ -0,0 +1,106 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2004-05-16
+ * Description : a plugin to set time stamp of picture files.
+ *
+ * Copyright (C) 2003-2005 by Jesper Pedersen <blackie@kde.org>
+ * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program 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 2, or (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * ============================================================ */
+
+// KDE includes.
+
+#include <klocale.h>
+#include <kaction.h>
+#include <kapplication.h>
+#include <kgenericfactory.h>
+#include <klibloader.h>
+#include <kconfig.h>
+#include <kdebug.h>
+
+// LibKIPI includes.
+
+#include <libkipi/imagecollection.h>
+
+// Local includes.
+
+#include "timeadjustdialog.h"
+#include "plugin_timeadjust.h"
+#include "plugin_timeadjust.moc"
+
+typedef KGenericFactory<Plugin_TimeAdjust> Factory;
+
+K_EXPORT_COMPONENT_FACTORY( kipiplugin_timeadjust,
+ Factory("kipiplugin_timeadjust"))
+
+Plugin_TimeAdjust::Plugin_TimeAdjust(QObject *parent, const char*, const QStringList&)
+ : KIPI::Plugin( Factory::instance(), parent, "TimeAdjust")
+{
+ kdDebug( 51001 ) << "Plugin_TimeAdjust plugin loaded" << endl;
+}
+
+void Plugin_TimeAdjust::setup(QWidget* widget)
+{
+ KIPI::Plugin::setup(widget);
+
+ // this is our action shown in the menubar/toolbar of the mainwindow
+
+ m_actionTimeAjust = new KAction (i18n("Adjust Time && Date..."),
+ "clock",
+ 0,
+ this,
+ SLOT(slotActivate()),
+ actionCollection(),
+ "timeadjust");
+
+ addAction(m_actionTimeAjust);
+
+ m_interface = dynamic_cast< KIPI::Interface* >(parent());
+
+ if (!m_interface)
+ {
+ kdError( 51000 ) << "Kipi interface is null!" << endl;
+ return;
+ }
+
+ KIPI::ImageCollection selection = m_interface->currentSelection();
+ m_actionTimeAjust->setEnabled(selection.isValid() &&
+ !selection.images().isEmpty());
+
+ connect(m_interface, SIGNAL(selectionChanged(bool)),
+ m_actionTimeAjust, SLOT(setEnabled(bool)));
+}
+
+void Plugin_TimeAdjust::slotActivate()
+{
+ KIPI::ImageCollection images = m_interface->currentSelection();
+
+ if (!images.isValid() || images.images().isEmpty())
+ return;
+
+ KIPITimeAdjustPlugin::TimeAdjustDialog dlg(m_interface, kapp->activeWindow());
+ dlg.setImages(images.images());
+ dlg.exec();
+}
+
+KIPI::Category Plugin_TimeAdjust::category( KAction* action ) const
+{
+ if ( action == m_actionTimeAjust )
+ return KIPI::IMAGESPLUGIN;
+
+ kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
+ return KIPI::IMAGESPLUGIN; // no warning from compiler, please
+}
diff --git a/kipi-plugins/timeadjust/plugin_timeadjust.h b/kipi-plugins/timeadjust/plugin_timeadjust.h
new file mode 100644
index 0000000..366472f
--- /dev/null
+++ b/kipi-plugins/timeadjust/plugin_timeadjust.h
@@ -0,0 +1,55 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2004-05-16
+ * Description : a plugin to set time stamp of picture files.
+ *
+ * Copyright (C) 2003-2005 by Jesper Pedersen <blackie@kde.org>
+ * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program 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 2, or (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * ============================================================ */
+
+#ifndef PLUGIN_TIMEADJUST_H
+#define PLUGIN_TIMEADJUST_H
+
+// LibKIPI includes.
+
+#include <libkipi/plugin.h>
+
+class KAction;
+
+class Plugin_TimeAdjust : public KIPI::Plugin
+{
+ Q_OBJECT
+
+public:
+
+ Plugin_TimeAdjust(QObject *parent, const char* name, const QStringList &args);
+
+ virtual KIPI::Category category( KAction* action ) const;
+ virtual void setup( QWidget* );
+
+protected slots:
+
+ void slotActivate();
+
+private:
+
+ KAction *m_actionTimeAjust;
+
+ KIPI::Interface *m_interface;
+};
+
+#endif // PLUGIN_TIMEADJUST_H
diff --git a/kipi-plugins/timeadjust/timeadjustdialog.cpp b/kipi-plugins/timeadjust/timeadjustdialog.cpp
new file mode 100644
index 0000000..394c110
--- /dev/null
+++ b/kipi-plugins/timeadjust/timeadjustdialog.cpp
@@ -0,0 +1,550 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2004-05-16
+ * Description : a plugin to set time stamp of picture files.
+ *
+ * Copyright (C) 2003-2005 by Jesper Pedersen <blackie@kde.org>
+ * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program 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 2, or (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * ============================================================ */
+
+// C Ansi includes.
+
+extern "C"
+{
+#include <sys/types.h>
+#include <utime.h>
+}
+
+// Qt includes.
+
+#include <qtooltip.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qvbuttongroup.h>
+#include <qvgroupbox.h>
+#include <qgroupbox.h>
+#include <qhbox.h>
+#include <qcheckbox.h>
+#include <qradiobutton.h>
+#include <qfile.h>
+#include <qspinbox.h>
+#include <qgrid.h>
+#include <qpushbutton.h>
+#include <qframe.h>
+#include <qtoolbutton.h>
+
+// KDE includes.
+
+#include <kiconloader.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <kaboutdata.h>
+#include <khelpmenu.h>
+#include <kiconloader.h>
+#include <kpopupmenu.h>
+#include <kstandarddirs.h>
+#include <kdatetimewidget.h>
+#include <kconfig.h>
+#include <kmessagebox.h>
+
+// LibKipi includes.
+
+#include <libkipi/interface.h>
+#include <libkipi/imageinfo.h>
+
+// LibKExiv2 includes.
+
+#include <libkexiv2/kexiv2.h>
+
+// Local includes.
+
+#include "kpaboutdata.h"
+#include "pluginsversion.h"
+#include "timeadjustdialog.h"
+#include "timeadjustdialog.moc"
+
+namespace KIPITimeAdjustPlugin
+{
+
+class TimeAdjustDialogPrivate
+{
+
+public:
+
+ TimeAdjustDialogPrivate()
+ {
+ add = 0;
+ subtract = 0;
+ exif = 0;
+ custom = 0;
+ syncEXIFDateCheck = 0;
+ syncIPTCDateCheck = 0;
+ exampleBox = 0;
+ adjustValGrp = 0;
+ adjustTypeGrp = 0;
+ infoLabel = 0;
+ exampleAdj = 0;
+ secs = 0;
+ minutes = 0;
+ hours = 0;
+ days = 0;
+ months = 0;
+ years = 0;
+ dateCreatedSel = 0;
+ interface = 0;
+ about = 0;
+ todayBtn = 0;
+ }
+
+ QRadioButton *add;
+ QRadioButton *subtract;
+ QRadioButton *exif;
+ QRadioButton *custom;
+
+ QToolButton *todayBtn;
+
+ QCheckBox *syncEXIFDateCheck;
+ QCheckBox *syncIPTCDateCheck;
+
+ QVGroupBox *exampleBox;
+ QVButtonGroup *adjustValGrp;
+ QButtonGroup *adjustTypeGrp;
+
+ QLabel *infoLabel;
+ QLabel *exampleAdj;
+
+ QSpinBox *secs;
+ QSpinBox *minutes;
+ QSpinBox *hours;
+ QSpinBox *days;
+ QSpinBox *months;
+ QSpinBox *years;
+
+ QDateTime exampleDate;
+
+ KDateTimeWidget *dateCreatedSel;
+
+ KURL::List images;
+
+ KIPI::Interface *interface;
+
+ KIPIPlugins::KPAboutData *about;
+};
+
+TimeAdjustDialog::TimeAdjustDialog(KIPI::Interface* interface, QWidget* parent)
+ : KDialogBase(Plain, i18n("Adjust Time & Date"), Help|Ok|Cancel,
+ Ok, parent, 0, true, true)
+{
+ d = new TimeAdjustDialogPrivate;
+ d->interface = interface;
+
+ QVBoxLayout *vlay = new QVBoxLayout(plainPage());
+
+ // -- About data and help button ----------------------------------------
+
+ d->about = new KIPIPlugins::KPAboutData(I18N_NOOP("Time Adjust"),
+ 0,
+ KAboutData::License_GPL,
+ I18N_NOOP("A Kipi plugin for adjusting time stamp of picture files"),
+ "(c) 2003-2005, Jesper K. Pedersen\n"
+ "(c) 2006-2008, Gilles Caulier");
+
+ d->about->addAuthor("Jesper K. Pedersen", I18N_NOOP("Author"),
+ "blackie@kde.org");
+
+ d->about->addAuthor("Gilles Caulier", I18N_NOOP("Developper and maintainer"),
+ "caulier dot gilles at gmail dot com");
+
+ QPushButton *helpButton = actionButton(Help);
+ KHelpMenu* helpMenu = new KHelpMenu(this, d->about, false);
+ helpMenu->menu()->removeItemAt(0);
+ helpMenu->menu()->insertItem(i18n("Plugin Handbook"), this, SLOT(slotHelp()), 0, -1, 0);
+ helpButton->setPopup(helpMenu->menu());
+
+ // -- Adjustment type ------------------------------------------------------------
+
+ QVGroupBox *adjGB = new QVGroupBox(i18n("Adjustment Type"), plainPage());
+ d->adjustTypeGrp = new QButtonGroup(1, Qt::Horizontal, adjGB);
+ d->add = new QRadioButton(i18n("Add"), d->adjustTypeGrp);
+ d->subtract = new QRadioButton(i18n("Subtract"), d->adjustTypeGrp);
+ d->exif = new QRadioButton(i18n("Set file date to EXIF/IPTC creation date"), d->adjustTypeGrp);
+ d->custom = new QRadioButton(i18n("Custom date"), d->adjustTypeGrp);
+
+ d->adjustTypeGrp->setFrameStyle(QFrame::NoFrame);
+ d->adjustTypeGrp->setInsideMargin(0);
+ d->adjustTypeGrp->setRadioButtonExclusive(true);
+
+ QHBox *hbox = new QHBox(d->adjustTypeGrp);
+ QLabel *space1 = new QLabel(hbox);
+ space1->setFixedWidth(15);
+ d->dateCreatedSel = new KDateTimeWidget(hbox);
+ QLabel *space2 = new QLabel(hbox);
+ space2->setFixedWidth(15);
+ d->todayBtn = new QToolButton(hbox);
+ d->todayBtn->setIconSet(SmallIcon("today"));
+ QToolTip::add(d->todayBtn, i18n("Reset to current date"));
+ new QLabel(hbox);
+
+ d->syncEXIFDateCheck = new QCheckBox(i18n("Update EXIF creation date"), d->adjustTypeGrp);
+ d->syncIPTCDateCheck = new QCheckBox(i18n("Update IPTC creation date"), d->adjustTypeGrp);
+
+ vlay->addWidget(adjGB);
+
+ // -- Adjustments ------------------------------------------------------------
+
+ d->adjustValGrp = new QVButtonGroup(i18n("Adjustments"), plainPage());
+ vlay->addWidget(d->adjustValGrp);
+
+ QWidget* grid = new QWidget(d->adjustValGrp);
+ QGridLayout* gridLay = new QGridLayout(grid, 1, 7, spacingHint());
+ gridLay->setColStretch( 2, 1 );
+ gridLay->setColStretch( 5, 1 );
+
+ QLabel* label = new QLabel( i18n("Hours:"), grid );
+ d->hours = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 0, 0 );
+ gridLay->addWidget( d->hours, 0, 1 );
+
+ label = new QLabel( i18n("Minutes:"), grid );
+ d->minutes = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 0, 3 );
+ gridLay->addWidget( d->minutes, 0, 4 );
+
+ label = new QLabel( i18n("Seconds:"), grid );
+ d->secs = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 0, 6 );
+ gridLay->addWidget( d->secs, 0, 7 );
+
+ label = new QLabel( i18n("Days:"), grid );
+ d->days = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 1, 0 );
+ gridLay->addWidget( d->days, 1, 1 );
+
+ label = new QLabel( i18n("Months:"), grid );
+ d->months = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 1, 3 );
+ gridLay->addWidget( d->months, 1, 4 );
+
+ label = new QLabel( i18n("Years:"), grid );
+ d->years = new QSpinBox( 0, 1000, 1, grid );
+ gridLay->addWidget( label, 1, 6 );
+ gridLay->addWidget( d->years, 1, 7 );
+
+ // -- Example ------------------------------------------------------------
+
+ d->exampleBox = new QVGroupBox(i18n("Example"), plainPage());
+ vlay->addWidget(d->exampleBox);
+
+ d->infoLabel = new QLabel(d->exampleBox);
+ d->exampleAdj = new QLabel(d->exampleBox);
+ d->exampleAdj->setAlignment(Qt::AlignCenter);
+
+ vlay->addStretch();
+
+ // -- Slots/Signals ------------------------------------------------------
+
+ connect(d->adjustTypeGrp, SIGNAL( clicked(int) ),
+ this, SLOT( slotAdjustmentTypeChanged() ));
+
+ connect(d->secs, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->minutes, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->hours, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->days, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->months, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->years, SIGNAL( valueChanged( int ) ),
+ this, SLOT( slotUpdateExample() ));
+
+ connect(d->todayBtn, SIGNAL(clicked()),
+ this, SLOT(slotResetDateToCurrent()));
+
+ // -----------------------------------------------------------------------
+
+ readSettings();
+ slotAdjustmentTypeChanged();
+}
+
+TimeAdjustDialog::~TimeAdjustDialog()
+{
+ delete d->about;
+ delete d;
+}
+
+void TimeAdjustDialog::slotHelp()
+{
+ KApplication::kApplication()->invokeHelp("timeadjust", "kipi-plugins");
+}
+
+void TimeAdjustDialog::slotResetDateToCurrent()
+{
+ d->dateCreatedSel->setDateTime(QDateTime::currentDateTime());
+}
+
+void TimeAdjustDialog::closeEvent(QCloseEvent *e)
+{
+ if (!e) return;
+ saveSettings();
+ e->accept();
+}
+
+void TimeAdjustDialog::slotCancel()
+{
+ saveSettings();
+ KDialogBase::slotCancel();
+}
+
+void TimeAdjustDialog::readSettings()
+{
+ KConfig config("kipirc");
+ config.setGroup("Time Adjust Settings");
+
+ int adjType = config.readNumEntry("Adjustment Type", 0); // add by default.
+ if (adjType == 0) d->add->setChecked(true);
+ if (adjType == 1) d->subtract->setChecked(true);
+ if (adjType == 2) d->exif->setChecked(true);
+ if (adjType == 3) d->custom->setChecked(true);
+
+ QDateTime current = QDateTime::currentDateTime();
+ d->dateCreatedSel->setDateTime(config.readDateTimeEntry("Custom Date", &current));
+
+ d->syncEXIFDateCheck->setChecked(config.readBoolEntry("Sync EXIF Date", true));
+ d->syncIPTCDateCheck->setChecked(config.readBoolEntry("Sync IPTC Date", true));
+ resize(configDialogSize(config, QString("Time Adjust Dialog")));
+}
+
+void TimeAdjustDialog::saveSettings()
+{
+ KConfig config("kipirc");
+ config.setGroup("Time Adjust Settings");
+
+ int adjType = 0; // add
+ if (d->subtract->isChecked()) adjType = 1;
+ if (d->exif->isChecked()) adjType = 2;
+ if (d->custom->isChecked()) adjType = 3;
+ config.writeEntry("Adjustment Type", adjType);
+
+ config.writeEntry("Custom Date", d->dateCreatedSel->dateTime());
+
+ config.writeEntry("Sync EXIF Date", d->syncEXIFDateCheck->isChecked());
+ config.writeEntry("Sync IPTC Date", d->syncIPTCDateCheck->isChecked());
+ saveDialogSize(config, QString("Time Adjust Dialog"));
+ config.sync();
+}
+
+void TimeAdjustDialog::setImages(const KURL::List& images)
+{
+ d->images.clear();
+ int exactCount = 0;
+ int inexactCount = 0;
+
+ for( KURL::List::ConstIterator it = images.begin(); it != images.end(); ++it )
+ {
+ KIPI::ImageInfo info = d->interface->info( *it );
+ if (info.isTimeExact())
+ {
+ exactCount++;
+ d->exampleDate = info.time();
+ d->images.append(*it);
+ }
+ else
+ inexactCount++;
+ }
+
+ if ( inexactCount > 0 )
+ {
+ QString tmpLabel = i18n("1 image will be changed; ",
+ "%n images will be changed; ",
+ exactCount)
+ + i18n("1 image will be skipped due to an inexact date.",
+ "%n images will be skipped due to inexact dates.",
+ inexactCount );
+
+ d->infoLabel->setText(tmpLabel);
+ }
+ else
+ {
+ d->infoLabel->setText(i18n("1 image will be changed",
+ "%n images will be changed",
+ d->images.count()));
+ }
+ // PENDING(blackie) handle all images being inexact.
+
+ slotUpdateExample();
+}
+
+void TimeAdjustDialog::slotUpdateExample()
+{
+ QString oldDate = d->exampleDate.toString(Qt::LocalDate);
+ QDateTime date = updateTime(KURL(), d->exampleDate);
+ QString newDate = date.toString(Qt::LocalDate);
+ d->exampleAdj->setText(i18n("<b>%1</b><br>would, for example, "
+ "change into<br><b>%2</b>")
+ .arg(oldDate).arg(newDate));
+}
+
+void TimeAdjustDialog::slotAdjustmentTypeChanged()
+{
+ d->exampleBox->setEnabled(false);
+ d->adjustValGrp->setEnabled(false);
+ d->dateCreatedSel->setEnabled(false);
+ d->todayBtn->setEnabled(false);
+ d->syncEXIFDateCheck->setEnabled(false);
+ d->syncIPTCDateCheck->setEnabled(false);
+
+ if (d->add->isChecked() || d->subtract->isChecked())
+ {
+ d->exampleBox->setEnabled(true);
+ d->adjustValGrp->setEnabled(true);
+ d->syncEXIFDateCheck->setEnabled(true);
+ d->syncIPTCDateCheck->setEnabled(true);
+ }
+ else if (d->custom->isChecked())
+ {
+ d->dateCreatedSel->setEnabled(true);
+ d->todayBtn->setEnabled(true);
+ d->syncEXIFDateCheck->setEnabled(true);
+ d->syncIPTCDateCheck->setEnabled(true);
+ }
+}
+
+void TimeAdjustDialog::slotOk()
+{
+ KURL::List updatedURLs;
+ QStringList errorFiles;
+
+ for( KURL::List::ConstIterator it = d->images.begin(); it != d->images.end(); ++it )
+ {
+ KURL url = *it;
+ KIPI::ImageInfo info = d->interface->info(url);
+ QDateTime dateTime = info.time();
+ dateTime = updateTime(info.path(), info.time());
+ info.setTime(dateTime);
+
+ if (d->syncEXIFDateCheck->isChecked() || d->syncIPTCDateCheck->isChecked())
+ {
+ bool ret = true;
+ if (!KExiv2Iface::KExiv2::isReadOnly(url.path()))
+ {
+ KExiv2Iface::KExiv2 exiv2Iface;
+
+ ret &= exiv2Iface.load(url.path());
+ if (ret)
+ {
+ if (d->syncEXIFDateCheck->isChecked())
+ {
+ ret &= exiv2Iface.setExifTagString("Exif.Image.DateTime",
+ dateTime.toString(QString("yyyy:MM:dd hh:mm:ss")).ascii());
+ ret &= exiv2Iface.setExifTagString("Exif.Photo.DateTimeOriginal",
+ dateTime.toString(QString("yyyy:MM:dd hh:mm:ss")).ascii());
+ }
+
+ if (d->syncIPTCDateCheck->isChecked())
+ {
+ ret &= exiv2Iface.setIptcTagString("Iptc.Application2.DateCreated",
+ dateTime.date().toString(Qt::ISODate));
+ ret &= exiv2Iface.setIptcTagString("Iptc.Application2.TimeCreated",
+ dateTime.time().toString(Qt::ISODate));
+ }
+
+ ret &= exiv2Iface.save(url.path());
+
+ if (!ret)
+ {
+ kdDebug() << "Failed to save metadata to file " << url.fileName() << endl;
+ }
+ }
+ else
+ {
+ kdDebug() << "Failed to load metadata from file " << url.fileName() << endl;
+ }
+ }
+
+ if (!ret)
+ errorFiles.append(url.fileName());
+ else
+ updatedURLs.append(url);
+ }
+
+ // See B.K.O #138880: set the file acess and modification time (after than Exiv2 play with metadata).
+ struct utimbuf ut;
+ ut.modtime = dateTime.toTime_t();
+ ut.actime = dateTime.toTime_t();
+ ::utime(QFile::encodeName(url.path()), &ut);
+ }
+
+ // We use kipi interface refreshImages() method to tell to host than
+ // metadata from pictures have changed and need to be re-read.
+ d->interface->refreshImages(d->images);
+
+ if (!errorFiles.isEmpty() && (d->syncEXIFDateCheck->isChecked() || d->syncIPTCDateCheck->isChecked()))
+ {
+ KMessageBox::informationList(
+ kapp->activeWindow(),
+ i18n("Unable to set date and time like picture metadata from:"),
+ errorFiles,
+ i18n("Adjust Time & Date"));
+ }
+
+ saveSettings();
+ accept();
+}
+
+QDateTime TimeAdjustDialog::updateTime(const KURL& url, const QDateTime& time) const
+{
+ if (d->custom->isChecked())
+ {
+ return d->dateCreatedSel->dateTime();
+ }
+ else if (d->exif->isChecked())
+ {
+ KExiv2Iface::KExiv2 exiv2Iface;
+ if ( !exiv2Iface.load(url.path()) )
+ return time;
+
+ QDateTime newTime = exiv2Iface.getImageDateTime();
+ if (newTime.isValid())
+ return newTime;
+ else
+ return time;
+ }
+ else
+ {
+ int sign = -1;
+ if (d->add->isChecked())
+ sign = 1;
+
+ QDateTime newTime = time.addSecs( sign * ( d->secs->value()
+ + 60*d->minutes->value()
+ + 60*60*d->hours->value()
+ + 24*60*60*d->days->value() ) );
+ newTime = newTime.addMonths( sign * d->months->value() );
+ newTime = newTime.addYears( sign * d->years->value() );
+ return newTime;
+ }
+}
+
+} // NameSpace KIPITimeAdjustPlugin
diff --git a/kipi-plugins/timeadjust/timeadjustdialog.h b/kipi-plugins/timeadjust/timeadjustdialog.h
new file mode 100644
index 0000000..d8d8196
--- /dev/null
+++ b/kipi-plugins/timeadjust/timeadjustdialog.h
@@ -0,0 +1,84 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2004-05-16
+ * Description : a plugin to set time stamp of picture files.
+ *
+ * Copyright (C) 2003-2005 by Jesper Pedersen <blackie@kde.org>
+ * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program 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 2, or (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * ============================================================ */
+
+#ifndef TIMEADJUSTDIALOG_H
+#define TIMEADJUSTDIALOG_H
+
+// Qt includes.
+
+#include <qdatetime.h>
+
+// KDE includes.
+
+#include <kdialogbase.h>
+#include <kurl.h>
+
+namespace KIPI
+{
+ class Interface;
+}
+
+namespace KIPITimeAdjustPlugin
+{
+
+class TimeAdjustDialogPrivate;
+
+class TimeAdjustDialog :public KDialogBase
+{
+ Q_OBJECT
+
+public:
+
+ TimeAdjustDialog(KIPI::Interface* interface, QWidget* parent);
+ ~TimeAdjustDialog();
+
+ void setImages(const KURL::List& images);
+
+protected:
+
+ void closeEvent(QCloseEvent *);
+
+private slots:
+
+ void slotUpdateExample();
+ void slotAdjustmentTypeChanged();
+ void slotOk();
+ void slotCancel();
+ void slotHelp();
+ void slotResetDateToCurrent();
+
+private:
+
+ void readSettings();
+ void saveSettings();
+ QDateTime updateTime(const KURL& url, const QDateTime& time) const;
+
+private:
+
+ TimeAdjustDialogPrivate *d;
+};
+
+} // NameSpace KIPITimeAdjustPlugin
+
+#endif /* TIMEADJUSTDIALOG_H */
+