datetimeplugin.cpp (krename-4.0.9) | : | datetimeplugin.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
/*************************************************************************** | /*************************************************************************** | |||
* * | * * | |||
* This program is free software; you can redistribute it and/or modify * | * 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 * | * it under the terms of the GNU General Public License as published by * | |||
* the Free Software Foundation; either version 2 of the License, or * | * the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | * (at your option) any later version. * | |||
* * | * * | |||
***************************************************************************/ | ***************************************************************************/ | |||
#ifndef _WIN32 | #ifndef Q_OS_WIN | |||
#include "datetimeplugin.h" | #include "datetimeplugin.h" | |||
#include <kiconloader.h> | #include <kiconloader.h> | |||
#include <klocale.h> | ||||
#include "ui_datetimepluginwidget.h" | #include "ui_datetimepluginwidget.h" | |||
#include <QDate> | #include <QDate> | |||
#include <QTime> | #include <QTime> | |||
#include <QVBoxLayout> | #include <QUrl> | |||
#include <qplatformdefs.h> | ||||
// OS includes | // OS includes | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <time.h> | #include <time.h> | |||
#include <utime.h> | #include <utime.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <sys/stat.h> | #include <sys/stat.h> | |||
DateTimePlugin::DateTimePlugin( PluginLoader* loader ) | DateTimePlugin::DateTimePlugin(PluginLoader *loader) | |||
: QObject( NULL ), Plugin( loader ) | : QObject(nullptr), Plugin(loader) | |||
{ | { | |||
m_widget = new Ui::DateTimePluginWidget(); | m_widget = new Ui::DateTimePluginWidget(); | |||
} | } | |||
DateTimePlugin::~DateTimePlugin() | DateTimePlugin::~DateTimePlugin() | |||
{ | { | |||
delete m_widget; | delete m_widget; | |||
} | } | |||
const QString DateTimePlugin::name() const | const QString DateTimePlugin::name() const | |||
{ | { | |||
return i18n("Date & Time Plugin"); | return i18n("Date & Time Plugin"); | |||
} | } | |||
const QPixmap DateTimePlugin::icon() const | const QPixmap DateTimePlugin::icon() const | |||
{ | { | |||
return KIconLoader::global()->loadIcon( "chronometer", KIconLoader::NoGroup, KIconLoader::SizeSmall ); | return KIconLoader::global()->loadIcon("chronometer", KIconLoader::NoGroup, KIconLoader::SizeSmall); | |||
} | } | |||
QString DateTimePlugin::processFile( BatchRenamer*, int, const QString & filenam eOrToken, EPluginType ) | QString DateTimePlugin::processFile(BatchRenamer *, int, const QString &filename OrToken, EPluginType) | |||
{ | { | |||
const QString & filename = filenameOrToken; | const QString &filename = filenameOrToken; | |||
bool bModification = m_widget->checkModification->isChecked(); | bool bModification = m_widget->checkModification->isChecked(); | |||
bool bAccess = m_widget->checkAccess->isChecked(); | bool bAccess = m_widget->checkAccess->isChecked(); | |||
QDate date = m_widget->datepicker->date(); | QDate date = m_widget->datepicker->date(); | |||
QTime time( m_widget->spinHour->value(), | QTime time(m_widget->spinHour->value(), | |||
m_widget->spinMinute->value(), | m_widget->spinMinute->value(), | |||
m_widget->spinSecond->value() ); | m_widget->spinSecond->value()); | |||
if( !KUrl( filename ).isLocalFile() ) | if (!QUrl(filename).isLocalFile()) { | |||
return i18n("DateTimePlugin works only with local files. %1 is a remote file.", filename); | return i18n("DateTimePlugin works only with local files. %1 is a remote file.", filename); | |||
} | ||||
if( bModification || bAccess ) | if (bModification || bAccess) { | |||
return changeDateTime( filename, bModification, bAccess, date, time ); | return changeDateTime(filename, bModification, bAccess, date, time); | |||
} | ||||
return QString::null; | return QString(); | |||
} | } | |||
void DateTimePlugin::createUI( QWidget* parent ) const | void DateTimePlugin::createUI(QWidget *parent) const | |||
{ | { | |||
m_widget->setupUi( parent ); | m_widget->setupUi(parent); | |||
connect( m_widget->buttonCurrent, SIGNAL( clicked(bool) ), SLOT( slotGetCurr | connect(m_widget->buttonCurrent, &QPushButton::clicked, | |||
entTime() ) ); | this, &DateTimePlugin::slotGetCurrentTime); | |||
} | } | |||
void DateTimePlugin::slotGetCurrentTime() | void DateTimePlugin::slotGetCurrentTime() | |||
{ | { | |||
m_widget->spinHour->setValue( QTime::currentTime().hour()); | m_widget->spinHour->setValue(QTime::currentTime().hour()); | |||
m_widget->spinMinute->setValue( QTime::currentTime().minute()); | m_widget->spinMinute->setValue(QTime::currentTime().minute()); | |||
m_widget->spinSecond->setValue( QTime::currentTime().second()); | m_widget->spinSecond->setValue(QTime::currentTime().second()); | |||
m_widget->datepicker->setDate( QDate::currentDate() ); | m_widget->datepicker->setDate(QDate::currentDate()); | |||
} | } | |||
QString DateTimePlugin::changeDateTime( const QString & filename, bool bModifica | QString DateTimePlugin::changeDateTime(const QString &filename, bool bModificati | |||
tion, bool bAccess, | on, bool bAccess, | |||
const QDate & date, const QTime & time ) | const QDate &date, const QTime &time) | |||
{ | { | |||
// Initialze fields | // Initialze fields | |||
struct tm tmp; | struct tm tmp; | |||
tmp.tm_mday = date.day(); | tmp.tm_mday = date.day(); | |||
tmp.tm_mon = date.month() - 1; | tmp.tm_mon = date.month() - 1; | |||
tmp.tm_year = date.year() - 1900; | tmp.tm_year = date.year() - 1900; | |||
tmp.tm_hour = time.hour(); | tmp.tm_hour = time.hour(); | |||
tmp.tm_min = time.minute(); | tmp.tm_min = time.minute(); | |||
tmp.tm_sec = time.second(); | tmp.tm_sec = time.second(); | |||
tmp.tm_isdst = -1; | tmp.tm_isdst = -1; | |||
// Create time | // Create time | |||
time_t ti; | time_t ti; | |||
ti = mktime( &tmp ); | ti = mktime(&tmp); | |||
if( ti == -1 ) | if (ti == -1) { | |||
return QString( i18n("Can't change date of file %1. (Cannot mktime)") ). | return i18n("Cannot change date of file %1. (Cannot mktime)", filename); | |||
arg(filename); | } | |||
// Get current values | // Get current values | |||
struct stat st; | QT_STATBUF st; | |||
if( stat( filename.toUtf8().data(), &st ) == -1 ) | if (QT_STAT(filename.toUtf8().data(), &st) == -1) { | |||
return QString( i18n("Can't change date of file %1. (Cannot stat the fil | return i18n("Cannot change date of file %1. (Cannot stat the file)", fil | |||
e)") ).arg(filename); | ename); | |||
} | ||||
// Fill structure; | // Fill structure; | |||
struct utimbuf buf; | struct utimbuf buf; | |||
buf.actime = (bAccess ? ti : st.st_atime); | buf.actime = (bAccess ? ti : st.st_atime); | |||
buf.modtime = (bModification ? ti: st.st_mtime); | buf.modtime = (bModification ? ti : st.st_mtime); | |||
if(utime( filename.toUtf8().data(), &buf ) != 0) | if (utime(filename.toUtf8().data(), &buf) != 0) { | |||
return QString( i18n("Can't change date of file %1. (utime failed)") ).a | return i18n("Cannot change date of file %1. (utime failed)", filename); | |||
rg(filename); | } | |||
return QString::null; | return QString(); | |||
} | } | |||
#include "datetimeplugin.moc" | #endif // Q_OS_WIN | |||
#endif // _WIN32 | ||||
End of changes. 24 change blocks. | ||||
39 lines changed or deleted | 42 lines changed or added |