"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/systemplugin.cpp" between
krename-4.0.9.tar.gz and krename-4.90.90.tar.gz

About: KRename is a batch file-renamer (KDE).

systemplugin.cpp  (krename-4.0.9):systemplugin.cpp  (krename-4.90.90)
skipping to change at line 26 skipping to change at line 26
***************************************************************************/ ***************************************************************************/
#include "systemplugin.h" #include "systemplugin.h"
#include "batchrenamer.h" #include "batchrenamer.h"
#include <QDate> #include <QDate>
#include <QTime> #include <QTime>
#include <kfileitem.h> #include <kfileitem.h>
#include <kio/netaccess.h> #include <KLocalizedString>
#include <klocale.h> #include <KIO/StatJob>
SystemPlugin::SystemPlugin( PluginLoader* loader ) SystemPlugin::SystemPlugin(PluginLoader *loader)
: FilePlugin( loader ) : FilePlugin(loader)
{ {
this->addSupportedToken("date"); this->addSupportedToken("date");
this->addSupportedToken("date;.*"); this->addSupportedToken("date;.*");
this->addSupportedToken("year"); this->addSupportedToken("year");
this->addSupportedToken("month"); this->addSupportedToken("month");
this->addSupportedToken("day"); this->addSupportedToken("day");
this->addSupportedToken("time"); this->addSupportedToken("time");
this->addSupportedToken("hour"); this->addSupportedToken("hour");
this->addSupportedToken("minute"); this->addSupportedToken("minute");
this->addSupportedToken("second"); this->addSupportedToken("second");
this->addSupportedToken("user"); this->addSupportedToken("user");
this->addSupportedToken("group"); this->addSupportedToken("group");
this->addSupportedToken("creationdate"); this->addSupportedToken("creationdate");
this->addSupportedToken("creationdate;.*"); this->addSupportedToken("creationdate;.*");
this->addSupportedToken("modificationdate"); this->addSupportedToken("modificationdate");
this->addSupportedToken("modificationdate;.*"); this->addSupportedToken("modificationdate;.*");
this->addSupportedToken("accessdate"); this->addSupportedToken("accessdate");
this->addSupportedToken("accessdate;.*"); this->addSupportedToken("accessdate;.*");
this->addSupportedToken("filesize"); this->addSupportedToken("filesize");
m_help.append( Plugin::createHelpEntry("date", i18n("Insert the current date m_help.append(Plugin::createHelpEntry("date", i18n("Insert the current date"
")) ); )));
m_help.append( Plugin::createHelpEntry("date;yyyy-MM-dd", i18n("Insert the c m_help.append(Plugin::createHelpEntry("date;yyyy-MM-dd", i18n("Insert the cu
urrent date using the formatting string yyyy-MM-dd")) ); rrent date using the formatting string yyyy-MM-dd")));
m_help.append( Plugin::createHelpEntry("year", i18n("Insert the current year m_help.append(Plugin::createHelpEntry("year", i18n("Insert the current year"
")) ); )));
m_help.append( Plugin::createHelpEntry("month", i18n("Insert the current mon m_help.append(Plugin::createHelpEntry("month", i18n("Insert the current mont
th as number")) ); h as number")));
m_help.append( Plugin::createHelpEntry("day", i18n("Insert the current day a m_help.append(Plugin::createHelpEntry("day", i18n("Insert the current day as
s number")) ); number")));
m_help.append( Plugin::createHelpEntry("time", i18n("Insert the current time m_help.append(Plugin::createHelpEntry("time", i18n("Insert the current time"
")) ); )));
m_help.append( Plugin::createHelpEntry("hour", i18n("Insert the current hour m_help.append(Plugin::createHelpEntry("hour", i18n("Insert the current hour
as number")) ); as number")));
m_help.append( Plugin::createHelpEntry("minute", i18n("Insert the current mi m_help.append(Plugin::createHelpEntry("minute", i18n("Insert the current min
nute as number")) ); ute as number")));
m_help.append( Plugin::createHelpEntry("second", i18n("Insert the current se m_help.append(Plugin::createHelpEntry("second", i18n("Insert the current sec
cond as number")) ); ond as number")));
m_help.append( Plugin::createHelpEntry("user", i18n("Owner of the file")) ); m_help.append(Plugin::createHelpEntry("user", i18n("Owner of the file")));
m_help.append( Plugin::createHelpEntry("group", i18n("Owning group of the fi m_help.append(Plugin::createHelpEntry("group", i18n("Owning group of the fil
le")) ); e")));
m_help.append( Plugin::createHelpEntry("creationdate", i18n("Insert the file m_help.append(Plugin::createHelpEntry("creationdate", i18n("Insert the files
s creation date"))); creation date")));
m_help.append( Plugin::createHelpEntry("creationdate;yyyy-MM-dd", i18n("Inse m_help.append(Plugin::createHelpEntry("creationdate;yyyy-MM-dd", i18n("Inser
rt the formatted file creation date")) ); t the formatted file creation date")));
m_help.append( Plugin::createHelpEntry("modificationdate", i18n("Insert the m_help.append(Plugin::createHelpEntry("modificationdate", i18n("Insert the f
files modification date")) ); iles modification date")));
m_help.append( Plugin::createHelpEntry("modificationdate;yyyy-MM-dd", i18n(" m_help.append(Plugin::createHelpEntry("modificationdate;yyyy-MM-dd", i18n("I
Insert the formatted modification date")) ); nsert the formatted modification date")));
m_help.append( Plugin::createHelpEntry("accessdate", i18n("Insert the date o m_help.append(Plugin::createHelpEntry("accessdate", i18n("Insert the date of
f the last file access")) ); the last file access")));
m_help.append( Plugin::createHelpEntry("accessdate;yyyy-MM-dd", i18n("Insert m_help.append(Plugin::createHelpEntry("accessdate;yyyy-MM-dd", i18n("Insert
the formatted date of the last file access")) ); the formatted date of the last file access")));
m_help.append( Plugin::createHelpEntry("filesize", i18n("Insert the file siz m_help.append(Plugin::createHelpEntry("filesize", i18n("Insert the file size
e in bytes")) ); in bytes")));
m_name = i18n("Date and system functions"); m_name = i18n("Date and system functions");
m_icon = "system-run"; m_icon = "system-run";
m_comment = i18n("<qt>This plugin contains tokens to get " m_comment = i18n("<qt>This plugin contains tokens to get "
"the creation, modification and last access " "the creation, modification and last access "
"time of files and the current system time and date.</qt>"); "time of files and the current system time and date.</qt>")
;
} }
SystemPlugin::~SystemPlugin() SystemPlugin::~SystemPlugin()
{ {
} }
QString SystemPlugin::processFile( BatchRenamer* b, int index, const QString & f ilenameOrToken, EPluginType ) QString SystemPlugin::processFile(BatchRenamer *b, int index, const QString &fil enameOrToken, EPluginType)
{ {
/* /*
if( token.lower().startsWith( getPattern() ) ) if( token.lower().startsWith( getPattern() ) )
token = token.mid( getPattern().length(), token.length() - getPattern(). length() ); token = token.mid( getPattern().length(), token.length() - getPattern(). length() );
*/ */
QString token( filenameOrToken ); QString token(filenameOrToken);
QDate d = QDate::currentDate(); QDate d = QDate::currentDate();
QTime t = QTime::currentTime(); QTime t = QTime::currentTime();
QString tmp, text; QString tmp, text;
QString format = "dd-MM-yyyy"; QString format = "dd-MM-yyyy";
if( token.contains( ";" ) ) if (token.contains(";")) {
{ format = token.section(';', 1, 1);
format = token.section( ';', 1, 1 ); token = token.section(';', 0, 0).toLower();
token = token.section( ';', 0, 0 ).toLower(); } else {
} else
token = token.toLower(); token = token.toLower();
}
if( token == "date" ) { if (token == "date") {
return QDateTime::currentDateTime().toString( format ); return QDateTime::currentDateTime().toString(format);
} else if( token == "year" ) } else if (token == "year") {
return QString( "%1" ).arg( d.year() ); return QString("%1").arg(d.year());
else if( token == "month" ) } else if (token == "month") {
return tmp.sprintf("%0*i", 2, d.month() ); return tmp.sprintf("%0*i", 2, d.month());
else if( token == "day" ) } else if (token == "day") {
return tmp.sprintf("%0*i", 2, d.day() ); return tmp.sprintf("%0*i", 2, d.day());
else if( token == "time" ) { } else if (token == "time") {
QString hour = QString().sprintf("%0*i", 2, t.hour() ); QString hour = QString().sprintf("%0*i", 2, t.hour());
QString minute = QString().sprintf("%0*i", 2, t.minute() ); QString minute = QString().sprintf("%0*i", 2, t.minute());
QString second = QString().sprintf("%0*i", 2, t.second() ); QString second = QString().sprintf("%0*i", 2, t.second());
return QString( "%1-%2-%3" ).arg( hour ).arg( minute ).arg( second ); return QString("%1-%2-%3").arg(hour).arg(minute).arg(second);
} else if( token == "hour" ) } else if (token == "hour") {
return tmp.sprintf("%0*i", 2, t.hour() ); return tmp.sprintf("%0*i", 2, t.hour());
else if( token == "minute" ) } else if (token == "minute") {
return tmp.sprintf("%0*i", 2, t.minute() ); return tmp.sprintf("%0*i", 2, t.minute());
else if( token == "second" ) } else if (token == "second") {
return tmp.sprintf("%0*i", 2, t.second() ); return tmp.sprintf("%0*i", 2, t.second());
else { } else {
const KUrl & url = b->files()->at( index ).srcUrl(); const QUrl &url = b->files()->at(index).srcUrl();
KIO::UDSEntry entry; KIO::StatJob *statJob = KIO::stat(url, KIO::StatJob::SourceSide, 2);
KIO::NetAccess::stat( url, entry, NULL ); statJob->exec();
KFileItem item( entry, url ); if (statJob->error()) {
if( token == "user" ) return QString();
}
KFileItem item(statJob->statResult(), url);
if (token == "user") {
return item.user(); return item.user();
else if( token == "group" ) } else if (token == "group") {
return item.group(); return item.group();
else if( token == "creationdate" ) } else if (token == "creationdate")
// TODO: Use toDateTime() // TODO: Use toDateTime()
return time( item.time( KFileItem::ModificationTime ).toTime_t(), fo {
rmat ); return time(item.time(KFileItem::ModificationTime).toTime_t(), forma
else if( token == "modificationdate" ) t);
return time( item.time( KFileItem::ModificationTime ).toTime_t(), fo } else if (token == "modificationdate") {
rmat ); return time(item.time(KFileItem::ModificationTime).toTime_t(), forma
else if( token == "accessdate" ) t);
return time( item.time( KFileItem::AccessTime ).toTime_t(), format ) } else if (token == "accessdate") {
; return time(item.time(KFileItem::AccessTime).toTime_t(), format);
else if( token == "filesize" ) } else if (token == "filesize") {
return QString::number( item.size() ); return QString::number(item.size());
}
} }
return QString::null; return QString();
} }
const QString SystemPlugin::time( time_t time, const QString & format ) const QString SystemPlugin::time(time_t time, const QString &format)
{ {
QDateTime dt; QDateTime dt;
dt.setTime_t( time ); dt.setTime_t(time);
return dt.toString( format ); return dt.toString(format);
} }
 End of changes. 15 change blocks. 
89 lines changed or deleted 94 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)