[Digikam-devel] [Bug 131558] Camera UI: renaming dialogue can't handle UTF-8 filenames
Marcel Wiesweg
marcel.wiesweg at gmx.de
Sun Aug 13 14:22:50 BST 2006
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=131558
------- Additional Comments From marcel.wiesweg gmx de 2006-08-13 15:22 -------
SVN commit 572652 by mwiesweg:
Make renaming unicode-proof:
- Move generation of new name to RenameCustomizer,
CameraIconView provides necessary information
- Rewrite custom renaming
- remove strftime, use QDateTime
- remove QFile::encodeName to QCString and back to QString conversion,
which break UTF8
CCBUG: 131558
M +8 -25 cameraiconview.cpp
M +1 -1 cameraiconview.h
M +16 -7 renamecustomizer.cpp
M +2 -1 renamecustomizer.h
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameraiconview.cpp #572651:572652
@ -163,7 +163,7 @
{
if (!d->renamer->useDefault())
{
- downloadName = getTemplatedName( d->renamer->nameTemplate(), &info, d->itemDict.count() );
+ downloadName = getTemplatedName( &info, d->itemDict.count() );
}
else
{
@ -225,12 +225,10 @
{
bool useDefault = true;
int startIndex = 0;
- QString nameTemplate;
if (d->renamer)
{
useDefault = d->renamer->useDefault();
- nameTemplate = d->renamer->nameTemplate();
startIndex = d->renamer->startIndex() -1;
}
@ -260,7 +258,7 @
if (viewItem->isSelected())
{
if (!useDefault)
- downloadName = getTemplatedName( nameTemplate, viewItem->itemInfo(), startIndex );
+ downloadName = getTemplatedName( viewItem->itemInfo(), startIndex );
else
downloadName = getCasedName( d->renamer->changeCase(), viewItem->itemInfo() );
@ -282,7 +280,7 @
CameraIconViewItem* viewItem = static_cast<CameraIconViewItem*>(item);
if (!useDefault)
- downloadName = getTemplatedName( nameTemplate, viewItem->itemInfo(), startIndex );
+ downloadName = getTemplatedName( viewItem->itemInfo(), startIndex );
else
downloadName = getCasedName( d->renamer->changeCase(), viewItem->itemInfo() );
@ -298,34 +296,19 @
slotSelectionChanged();
}
-QString CameraIconView::getTemplatedName(const QString& templ, const GPItemInfo* itemInfo, int position)
+QString CameraIconView::getTemplatedName(const GPItemInfo* itemInfo, int position)
{
- if (templ.isEmpty())
- return QString::null;
-
- QString dname(templ);
-
QString ext = itemInfo->name;
int pos = ext.findRev('.');
if (pos < 0)
ext = "";
else
- ext = ext.right( ext.length() - pos - 1);
+ ext = ext.right( ext.length() - pos );
- struct tm* time_tm = ::localtime(&itemInfo->mtime);
- char s[100];
- strftime(s, 100, QFile::encodeName(dname), time_tm);
+ QDateTime mtime;
+ mtime.setTime_t(itemInfo->mtime);
- dname = s;
- dname.replace("%s", "");
-
- dname.sprintf(QFile::encodeName(dname), position+1);
- dname.replace("/","");
-
- dname += '.';
- dname += ext;
-
- return dname;
+ return d->renamer->newName(mtime, position+1, ext);
}
QString CameraIconView::getCasedName(const RenameCustomizer::Case ccase,
--- trunk/extragear/graphics/digikam/utilities/cameragui/cameraiconview.h #572651:572652
@ -112,7 +112,7 @
private:
- QString getTemplatedName(const QString& templ, const GPItemInfo* itemInfo, int position);
+ QString getTemplatedName(const GPItemInfo* itemInfo, int position);
QString getCasedName(const RenameCustomizer::Case ccase, const GPItemInfo* itemInfo);
void uploadItemPopupMenu(const KURL::List& srcURLs);
--- trunk/extragear/graphics/digikam/utilities/cameragui/renamecustomizer.cpp #572651:572652
@ -218,35 +218,44 @
return d->startIndexInput->value();
}
-QString RenameCustomizer::nameTemplate() const
+QString RenameCustomizer::newName(const QDateTime &dateTime, int index, const QString &suffix) const
{
if (d->renameDefault->isChecked())
return QString();
else
{
- QString templ(d->renameCustomPrefix->text());
+ QString name(d->renameCustomPrefix->text());
+ // use the "T" as a delimiter between date and time
+ QString date = dateTime.toString("yyyyMMddThhmmss");
+
+ // it seems that QString::number does not support padding with zeros
+ QString seq;
+ seq.sprintf("-%04d", index);
+
switch (d->renameCustomOptions->currentItem())
{
case ADDDATETIME:
{
- templ += "%Y%m%dT%H%M%S";
+ name += date;
break;
}
case ADDSEQNUMB:
{
- templ += "-%%04d";
+ name += seq;
break;
}
case ADDBOTH:
{
- templ += "%Y%m%dT%H%M%S";
- templ += "-%%04d";
+ name += date;
+ name += seq;
break;
}
}
- return templ;
+ name += suffix;
+
+ return name;
}
}
--- trunk/extragear/graphics/digikam/utilities/cameragui/renamecustomizer.h #572651:572652
@ -27,6 +27,7 @
// Qt includes.
#include <qbuttongroup.h>
+#include <qdatetime.h>
namespace Digikam
{
@ -58,7 +59,7 @
void setUseDefault(bool val);
bool useDefault() const;
- QString nameTemplate() const;
+ QString newName(const QDateTime &date, int index, const QString &suffix) const;
Case changeCase() const;
int startIndex() const;
More information about the Digikam-devel
mailing list