krenamemodel.cpp (krename-4.0.9) | : | krenamemodel.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
* 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. * | |||
* * | * * | |||
***************************************************************************/ | ***************************************************************************/ | |||
#include "krenamemodel.h" | #include "krenamemodel.h" | |||
#include "threadedlister.h" | #include "threadedlister.h" | |||
#include <QMimeData> | #include <QMimeData> | |||
#include <QPixmap> | #include <QPixmap> | |||
#include <QApplication> | ||||
#include <kapplication.h> | #include <KLocalizedString> | |||
#include <klocale.h> | ||||
#include <krun.h> | #include <krun.h> | |||
#include <kio/previewjob.h> | #include <kio/previewjob.h> | |||
KRenameModel::KRenameModel( KRenameFile::List* vector ) | KRenameModel::KRenameModel(KRenameFile::List *vector) | |||
: QAbstractListModel(), | : QAbstractListModel(), | |||
m_vector( vector ), | m_vector(vector), | |||
m_preview( false ), | m_preview(false), | |||
m_text( false ), | m_text(false), | |||
m_maxDots( 0 ), | m_maxDots(0), | |||
m_mimeType("text/uri-list"), | m_mimeType("text/uri-list"), | |||
m_eSortMode( eSortMode_Unsorted ), | m_eSortMode(eSortMode_Unsorted), | |||
m_customSortToken( "creationdate;yyyyMMddHHmm" ), | m_customSortToken("creationdate;yyyyMMddHHmm"), | |||
m_eCustomSortMode( KRenameTokenSorter::eSimpleSortMode_Ascending ) | m_eCustomSortMode(KRenameTokenSorter::eSimpleSortMode_Ascending) | |||
{ | { | |||
} | } | |||
KRenameModel::~KRenameModel() | KRenameModel::~KRenameModel() | |||
{ | { | |||
} | } | |||
int KRenameModel::rowCount ( const QModelIndex & index ) const | int KRenameModel::rowCount(const QModelIndex &index) const | |||
{ | { | |||
if( !index.isValid() ) | if (!index.isValid()) { | |||
return m_vector->size(); | return m_vector->size(); | |||
} | ||||
return 0; | return 0; | |||
} | } | |||
QVariant KRenameModel::data ( const QModelIndex & index, int role ) const | QVariant KRenameModel::data(const QModelIndex &index, int role) const | |||
{ | { | |||
if (!index.isValid()) | if (!index.isValid()) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
if (index.row() >= m_vector->size()) | if (index.row() >= m_vector->size()) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
if (role == Qt::DisplayRole) | if (role == Qt::DisplayRole) { | |||
{ | if (!m_preview) { | |||
if (!m_preview) | ||||
{ | ||||
// Only return path | // Only return path | |||
return m_vector->at(index.row()).toString(); | return m_vector->at(index.row()).toString(); | |||
} | } else if (m_preview && m_text) { | |||
else if (m_preview && m_text) | ||||
{ | ||||
// Short filename as first line in bold | // Short filename as first line in bold | |||
// Path as second line | // Path as second line | |||
const KRenameFile & file = m_vector->at(index.row()); | const KRenameFile &file = m_vector->at(index.row()); | |||
QString filename = file.srcFilename(); | QString filename = file.srcFilename(); | |||
if (!file.srcExtension().isEmpty()) | if (!file.srcExtension().isEmpty()) { | |||
{ | filename = filename + '.' + file.srcExtension(); | |||
filename = filename + "." + file.srcExtension(); | ||||
} | } | |||
const QString & prettyUrl = file.toString(); | const QString &prettyUrl = file.toString(); | |||
return "<qt><b>" + filename + "</b><br/>" + | return "<qt><b>" + filename + "</b><br/>" + | |||
prettyUrl + "</qt>"; | prettyUrl + "</qt>"; | |||
} | } | |||
} | } else if (role == Qt::DecorationRole && m_preview) { | |||
else if( role == Qt::DecorationRole && m_preview ) | ||||
{ | ||||
return m_vector->at(index.row()).icon(); | return m_vector->at(index.row()).icon(); | |||
} | } else if (role == Qt::UserRole) { | |||
else if( role == Qt::UserRole ) | ||||
{ | ||||
return m_vector->at(index.row()).toString(); | return m_vector->at(index.row()).toString(); | |||
} | } | |||
return QVariant(); | return QVariant(); | |||
} | } | |||
Qt::ItemFlags KRenameModel::flags(const QModelIndex &index) const | Qt::ItemFlags KRenameModel::flags(const QModelIndex &index) const | |||
{ | { | |||
if (!index.isValid()) | if (!index.isValid()) { | |||
return Qt::ItemIsDropEnabled; | return Qt::ItemIsDropEnabled; | |||
} | ||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDro pEnabled; | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDro pEnabled; | |||
} | } | |||
Qt::DropActions KRenameModel::supportedDropActions() const | Qt::DropActions KRenameModel::supportedDropActions() const | |||
{ | { | |||
return Qt::CopyAction | Qt::MoveAction; | return Qt::CopyAction | Qt::MoveAction; | |||
} | } | |||
QStringList KRenameModel::mimeTypes() const | QStringList KRenameModel::mimeTypes() const | |||
skipping to change at line 124 | skipping to change at line 119 | |||
QStringList types; | QStringList types; | |||
types << m_mimeType; | types << m_mimeType; | |||
return types; | return types; | |||
} | } | |||
bool KRenameModel::dropMimeData(const QMimeData *data, | bool KRenameModel::dropMimeData(const QMimeData *data, | |||
Qt::DropAction action, | Qt::DropAction action, | |||
int, int, | int, int, | |||
const QModelIndex &) | const QModelIndex &) | |||
{ | { | |||
if (action == Qt::IgnoreAction) | if (action == Qt::IgnoreAction) { | |||
return true; | return true; | |||
} | ||||
if (!data->hasFormat( m_mimeType )) | if (!data->hasFormat(m_mimeType)) { | |||
return false; | return false; | |||
} | ||||
KUrl::List dirs; | QList<QUrl> dirs; | |||
KRenameFile::List files; | KRenameFile::List files; | |||
QList<QUrl> urls = data->urls(); | QList<QUrl> urls = data->urls(); | |||
QList<QUrl>::const_iterator it = urls.begin(); | QList<QUrl>::const_iterator it = urls.constBegin(); | |||
KApplication::setOverrideCursor( Qt::BusyCursor ); | QApplication::setOverrideCursor(Qt::BusyCursor); | |||
while( it != urls.end() ) | while (it != urls.constEnd()) { | |||
{ | if ((*it).isValid()) { | |||
if( (*it).isValid() ) | KRenameFile file(*it, m_eSplitMode, m_dot); | |||
{ | ||||
KRenameFile file( *it, m_eSplitMode, m_dot ); | if (file.isValid() && !file.isDirectory()) { | |||
files.append(file); | ||||
if( file.isValid() && !file.isDirectory() ) | } else if (file.isValid() && file.isDirectory()) | |||
files.append( file ); | ||||
else if( file.isValid() && file.isDirectory() ) | ||||
// Add directories recursively | // Add directories recursively | |||
dirs.append( *it ); | { | |||
dirs.append(*it); | ||||
} | ||||
} | } | |||
++it; | ++it; | |||
} | } | |||
this->addFiles( files ); | this->addFiles(files); | |||
if( dirs.count() ) | if (dirs.count()) { | |||
{ | QList<QUrl>::const_iterator it = dirs.constBegin(); | |||
KUrl::List::const_iterator it = dirs.begin(); | ||||
while (it != dirs.constEnd()) { | ||||
while( it != dirs.end() ) | ThreadedLister *thl = new ThreadedLister(*it, nullptr, this); | |||
{ | connect(thl, &ThreadedLister::listerDone, | |||
ThreadedLister* thl = new ThreadedLister( *it, NULL, this ); | this, &KRenameModel::slotListerDone); | |||
connect( thl, SIGNAL( listerDone( ThreadedLister* ) ), SLOT( slotLis | ||||
terDone( ThreadedLister* ) ) ); | thl->setListDirnamesOnly(false); | |||
thl->setListHidden(false); | ||||
thl->setListDirnamesOnly( false ); | thl->setListRecursively(true); | |||
thl->setListHidden( false ); | thl->setListDirnames(false); | |||
thl->setListRecursively( true ); | ||||
thl->setListDirnames( false ); | ||||
thl->start(); | thl->start(); | |||
++it; | ++it; | |||
} | } | |||
} | } else { | |||
else | QApplication::restoreOverrideCursor(); | |||
{ | ||||
KApplication::restoreOverrideCursor(); | ||||
emit filesDropped(); | emit filesDropped(); | |||
} | } | |||
return true; | return true; | |||
} | } | |||
void KRenameModel::slotListerDone( ThreadedLister* lister ) | void KRenameModel::slotListerDone(ThreadedLister *lister) | |||
{ | { | |||
// Delete the listener | // Delete the listener | |||
delete lister; | delete lister; | |||
// restore cursor | // restore cursor | |||
KApplication::restoreOverrideCursor(); | QApplication::restoreOverrideCursor(); | |||
emit filesDropped(); | emit filesDropped(); | |||
} | } | |||
bool KRenameModel::setData(const QModelIndex &index, | bool KRenameModel::setData(const QModelIndex &index, | |||
const QVariant &, int role) | const QVariant &, int role) | |||
{ | { | |||
if (index.isValid() && role == Qt::EditRole) { | if (index.isValid() && role == Qt::EditRole) { | |||
//stringList.replace(index.row(), value.toString()); | //stringList.replace(index.row(), value.toString()); | |||
emit dataChanged(index, index); | emit dataChanged(index, index); | |||
return true; | return true; | |||
} | } | |||
return false; | return false; | |||
} | } | |||
void KRenameModel::addFiles( const KRenameFile::List & files ) | void KRenameModel::addFiles(const KRenameFile::List &files) | |||
{ | { | |||
if( files.count() ) | if (files.count()) { | |||
{ | ||||
int oldMaxDots = m_maxDots; | int oldMaxDots = m_maxDots; | |||
m_vector->reserve( m_vector->count() + files.count() ); | m_vector->reserve(m_vector->count() + files.count()); | |||
this->beginInsertRows( QModelIndex(), m_vector->size(), m_vector->size() + files.count() - 1 ); | this->beginInsertRows(QModelIndex(), m_vector->size(), m_vector->size() + files.count() - 1); | |||
KRenameFile::List::const_iterator it = files.begin(); | KRenameFile::List::const_iterator it = files.begin(); | |||
while( it != files.end() ) | while (it != files.end()) { | |||
{ | m_vector->push_back(*it); | |||
m_vector->push_back( *it ); | ||||
int dots = (*it).dots(); | int dots = (*it).dots(); | |||
if( dots > m_maxDots ) | if (dots > m_maxDots) { | |||
m_maxDots = dots; | m_maxDots = dots; | |||
} | ||||
++it; | ++it; | |||
} | } | |||
this->endInsertRows(); | this->endInsertRows(); | |||
if( m_maxDots > oldMaxDots ) | if (m_maxDots > oldMaxDots) { | |||
emit maxDotsChanged( m_maxDots ); | emit maxDotsChanged(m_maxDots); | |||
} | ||||
// Update sorting | // Update sorting | |||
this->sortFiles( m_eSortMode, m_customSortToken, m_eCustomSortMode ); | this->sortFiles(m_eSortMode, m_customSortToken, m_eCustomSortMode); | |||
// Generate previews if necessary | // Generate previews if necessary | |||
if( m_preview ) | if (m_preview) { | |||
{ | ||||
// Construct a list of KFileItems | // Construct a list of KFileItems | |||
// Only do this is necessary, | // Only do this is necessary, | |||
// as this might create new KFileItems which is slow. | // as this might create new KFileItems which is slow. | |||
KFileItemList fileItems; | KFileItemList fileItems; | |||
it = files.begin(); | it = files.begin(); | |||
while( it != files.end() ) | while (it != files.end()) { | |||
{ | ||||
fileItems << (*it).fileItem(); | fileItems << (*it).fileItem(); | |||
++it; | ++it; | |||
} | } | |||
// TODO: Enable this job, it currently crashes for me | // TODO: Enable this job, it currently crashes for me | |||
// Start a job to create the real file previews | // Start a job to create the real file previews | |||
KIO::PreviewJob* job = KIO::filePreview( fileItems, KRenameFile::get DefaultIconSize() ); | KIO::PreviewJob *job = KIO::filePreview(fileItems, QSize(KRenameFile ::iconSize(), KRenameFile::iconSize())); | |||
connect( job, SIGNAL(gotPreview(const KFileItem &,const QPixmap &)), | connect(job, &KIO::PreviewJob::gotPreview, | |||
this, SLOT(gotPreview(const KFileItem &,const QPixmap &)) ) | this, &KRenameModel::gotPreview); | |||
; | ||||
job->start(); | job->start(); | |||
} | } | |||
} | } | |||
} | } | |||
void KRenameModel::gotPreview (const KFileItem &item, const QPixmap &preview) | void KRenameModel::gotPreview(const KFileItem &item, const QPixmap &preview) | |||
{ | { | |||
/* | /* | |||
const KRenameFile* file = | const KRenameFile* file = | |||
static_cast<const KRenameFile*>(item.extraData(KRenameFile::EXTRA_DATA_K EY)); | static_cast<const KRenameFile*>(item.extraData(KRenameFile::EXTRA_DATA_K EY)); | |||
*/ | */ | |||
KRenameFile* file = NULL; | KRenameFile *file = nullptr; | |||
// TODO: Find a more optimal "search algorithm" .... | // TODO: Find a more optimal "search algorithm" .... | |||
KRenameFile::List::iterator it = m_vector->begin(); | KRenameFile::List::iterator it = m_vector->begin(); | |||
while( it != m_vector->end() ) | while (it != m_vector->end()) { | |||
{ | if ((*it).srcUrl() == item.url()) { | |||
if( (*it).srcUrl() == item.url() ) | ||||
{ | ||||
file = &(*it); | file = &(*it); | |||
break; | break; | |||
} | } | |||
++it; | ++it; | |||
} | } | |||
//it = find( m_vector->begin(), m_vector->end(), item ); | //it = find( m_vector->begin(), m_vector->end(), item ); | |||
if( file != NULL ) // && file->fileItem() == item ) | if (file != nullptr) { // && file->fileItem() == item ) | |||
{ | file->setIcon(preview); | |||
file->setIcon( preview ); | ||||
} | } | |||
} | } | |||
void KRenameModel::removeFiles( const QList<int> & remove ) | void KRenameModel::removeFiles(const QList<int> &remove) | |||
{ | { | |||
int offset = 0; | int offset = 0; | |||
QList<int> copy( remove ); | QList<int> copy(remove); | |||
qSort( copy ); | std::sort(copy.begin(), copy.end()); | |||
QList<int>::const_iterator it = copy.begin(); | QList<int>::const_iterator it = copy.constBegin(); | |||
this->beginRemoveRows( QModelIndex(), *it, copy.back() ); | this->beginRemoveRows(QModelIndex(), *it, copy.back()); | |||
while( it != copy.end() ) | while (it != copy.constEnd()) { | |||
{ | m_vector->erase(m_vector->begin() + *it - offset); | |||
m_vector->erase( m_vector->begin() + *it - offset ); | ||||
++offset; | ++offset; | |||
++it; | ++it; | |||
} | } | |||
this->endRemoveRows(); | this->endRemoveRows(); | |||
} | } | |||
void KRenameModel::sortFiles( ESortMode mode, const QString & customSortToken, K RenameTokenSorter::ESimpleSortMode customSortMode ) | void KRenameModel::sortFiles(ESortMode mode, const QString &customSortToken, KRe nameTokenSorter::ESimpleSortMode customSortMode) | |||
{ | { | |||
beginResetModel(); | ||||
const QString dateSortToken = "creationdate;yyyyMMddHHmm"; | const QString dateSortToken = "creationdate;yyyyMMddHHmm"; | |||
m_eSortMode = mode; | m_eSortMode = mode; | |||
m_customSortToken = customSortToken; | m_customSortToken = customSortToken; | |||
m_eCustomSortMode = customSortMode; | m_eCustomSortMode = customSortMode; | |||
if( mode == eSortMode_Ascending ) | if (mode == eSortMode_Ascending) { | |||
qSort( m_vector->begin(), m_vector->end(), ascendingKRenameFileLessThan | std::sort(m_vector->begin(), m_vector->end(), ascendingKRenameFileLessTh | |||
); | an); | |||
else if( mode == eSortMode_Descending ) | } else if (mode == eSortMode_Descending) { | |||
qSort( m_vector->begin(), m_vector->end(), descendingKRenameFileLessThan | std::sort(m_vector->begin(), m_vector->end(), descendingKRenameFileLessT | |||
); | han); | |||
else if( mode == eSortMode_Numeric ) | } else if (mode == eSortMode_Numeric) { | |||
qSort( m_vector->begin(), m_vector->end(), numericKRenameFileLessThan ); | std::sort(m_vector->begin(), m_vector->end(), numericKRenameFileLessThan | |||
else if( mode == eSortMode_Random ) | ); | |||
qSort( m_vector->begin(), m_vector->end(), randomKRenameFileLessThan ); | } else if (mode == eSortMode_Random) { | |||
else if( mode == eSortMode_AscendingDate ) | std::sort(m_vector->begin(), m_vector->end(), randomKRenameFileLessThan) | |||
{ | ; | |||
} else if (mode == eSortMode_AscendingDate) { | ||||
KRenameTokenSorter sorter(m_renamer, dateSortToken, *m_vector, | KRenameTokenSorter sorter(m_renamer, dateSortToken, *m_vector, | |||
KRenameTokenSorter::eSimpleSortMode_Ascending) ; | KRenameTokenSorter::eSimpleSortMode_Ascending) ; | |||
qSort( m_vector->begin(), m_vector->end(), sorter ); | std::sort(m_vector->begin(), m_vector->end(), sorter); | |||
} | } else if (mode == eSortMode_DescendingDate) { | |||
else if( mode == eSortMode_DescendingDate ) | ||||
{ | ||||
KRenameTokenSorter sorter(m_renamer, dateSortToken, *m_vector, | KRenameTokenSorter sorter(m_renamer, dateSortToken, *m_vector, | |||
KRenameTokenSorter::eSimpleSortMode_Descending ); | KRenameTokenSorter::eSimpleSortMode_Descending ); | |||
qSort( m_vector->begin(), m_vector->end(), sorter ); | std::sort(m_vector->begin(), m_vector->end(), sorter); | |||
} | } else if (mode == eSortMode_Token) { | |||
else if( mode == eSortMode_Token ) | ||||
{ | ||||
KRenameTokenSorter sorter(m_renamer, customSortToken, *m_vector, | KRenameTokenSorter sorter(m_renamer, customSortToken, *m_vector, | |||
customSortMode); | customSortMode); | |||
qSort( m_vector->begin(), m_vector->end(), sorter ); | std::sort(m_vector->begin(), m_vector->end(), sorter); | |||
} | } | |||
else | ||||
return; | ||||
this->reset(); | endResetModel(); | |||
} | } | |||
void KRenameModel::run(const QModelIndex & index, QWidget* window ) const | void KRenameModel::run(const QModelIndex &index, QWidget *window) const | |||
{ | { | |||
KRenameFile file = m_vector->at(index.row()); | KRenameFile file = m_vector->at(index.row()); | |||
new KRun( file.srcUrl(), window ); | new KRun(file.srcUrl(), window); | |||
} | } | |||
const QModelIndex KRenameModel::createIndex( int row ) const | const QModelIndex KRenameModel::createIndex(int row) const | |||
{ | { | |||
return QAbstractItemModel::createIndex( row, 0 ); | return QAbstractItemModel::createIndex(row, 0); | |||
} | } | |||
void KRenameModel::moveFilesUp( const QList<int> & files ) | void KRenameModel::moveFilesUp(const QList<int> &files) | |||
{ | { | |||
int index; | int index; | |||
KRenameFile tmp; | KRenameFile tmp; | |||
QList<int> copy( files ); | QList<int> copy(files); | |||
qSort( copy ); | std::sort(copy.begin(), copy.end()); | |||
QList<int>::const_iterator it = copy.begin(); | beginResetModel(); | |||
while( it != copy.end() ) | QList<int>::const_iterator it = copy.constBegin(); | |||
{ | while (it != copy.constEnd()) { | |||
index = *it; | index = *it; | |||
if( index <= 0 ) // cannot swap top item | if (index <= 0) { // cannot swap top item | |||
{ | ||||
++it; | ++it; | |||
continue; | continue; | |||
} | } | |||
// swap items | // swap items | |||
tmp = m_vector->at( index ); | tmp = m_vector->at(index); | |||
(*m_vector)[index] = KRenameFile( m_vector->at( index - 1 ) ); | (*m_vector)[index] = KRenameFile(m_vector->at(index - 1)); | |||
(*m_vector)[index - 1] = tmp; | (*m_vector)[index - 1] = tmp; | |||
++it; | ++it; | |||
} | } | |||
this->reset(); | endResetModel(); | |||
} | } | |||
void KRenameModel::moveFilesDown( const QList<int> & files ) | void KRenameModel::moveFilesDown(const QList<int> &files) | |||
{ | { | |||
int index; | int index; | |||
KRenameFile tmp; | KRenameFile tmp; | |||
QList<int> copy( files ); | QList<int> copy(files); | |||
// sort the list in reverse order | // sort the list in reverse order | |||
qSort( copy.begin(), copy.end(), qGreater<int>() ); | std::sort(copy.begin(), copy.end(), std::greater<int>()); | |||
QList<int>::const_iterator it = copy.begin(); | beginResetModel(); | |||
while( it != copy.end() ) | QList<int>::const_iterator it = copy.constBegin(); | |||
{ | while (it != copy.constEnd()) { | |||
index = *it; | index = *it; | |||
if( index + 1 >= m_vector->size() ) // cannot swap bottom item | if (index + 1 >= m_vector->size()) { // cannot swap bottom item | |||
{ | ||||
++it; | ++it; | |||
continue; | continue; | |||
} | } | |||
// swap items | // swap items | |||
tmp = m_vector->at( index ); | tmp = m_vector->at(index); | |||
(*m_vector)[index] = KRenameFile( m_vector->at( index + 1 ) ); | (*m_vector)[index] = KRenameFile(m_vector->at(index + 1)); | |||
(*m_vector)[index + 1] = tmp; | (*m_vector)[index + 1] = tmp; | |||
++it; | ++it; | |||
} | } | |||
this->reset(); | endResetModel(); | |||
} | } | |||
////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////// | |||
// Preview model starts below | // Preview model starts below | |||
////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////// | |||
KRenamePreviewModel::KRenamePreviewModel( KRenameFile::List* vector ) | KRenamePreviewModel::KRenamePreviewModel(KRenameFile::List *vector) | |||
: m_vector( vector ) | : m_vector(vector) | |||
{ | { | |||
} | } | |||
KRenamePreviewModel::~KRenamePreviewModel() | KRenamePreviewModel::~KRenamePreviewModel() | |||
{ | { | |||
} | } | |||
int KRenamePreviewModel::rowCount ( const QModelIndex & parent ) const | int KRenamePreviewModel::rowCount(const QModelIndex &parent) const | |||
{ | { | |||
if( !parent.isValid() ) | if (!parent.isValid()) { | |||
return m_vector->size(); | return m_vector->size(); | |||
} | ||||
return 0; | return 0; | |||
} | } | |||
int KRenamePreviewModel::columnCount ( const QModelIndex & ) const | int KRenamePreviewModel::columnCount(const QModelIndex &) const | |||
{ | { | |||
return 2; | return 2; | |||
} | } | |||
QVariant KRenamePreviewModel::headerData ( int section, Qt::Orientation orientat ion, int role ) const | QVariant KRenamePreviewModel::headerData(int section, Qt::Orientation orientatio n, int role) const | |||
{ | { | |||
if (orientation != Qt::Horizontal || section > 1 || role != Qt::DisplayRole ) | if (orientation != Qt::Horizontal || section > 1 || role != Qt::DisplayRole) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
return (section == 0) ? i18n("Origin") : i18n("Renamed"); | return (section == 0) ? i18n("Origin") : i18n("Renamed"); | |||
} | } | |||
QVariant KRenamePreviewModel::data ( const QModelIndex & index, int role ) const | QVariant KRenamePreviewModel::data(const QModelIndex &index, int role) const | |||
{ | { | |||
if (!index.isValid()) | if (!index.isValid()) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
if (index.row() >= m_vector->size()) | if (index.row() >= m_vector->size()) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
if (index.column() >= 2 ) | if (index.column() >= 2) { | |||
return QVariant(); | return QVariant(); | |||
} | ||||
if (role == Qt::DisplayRole) | if (role == Qt::DisplayRole) { | |||
{ | const KRenameFile &file = m_vector->at(index.row()); | |||
const KRenameFile& file = m_vector->at(index.row()); | ||||
QString filename; | QString filename; | |||
QString extension; | QString extension; | |||
QString manual; | QString manual; | |||
if( index.column() ) | if (index.column()) { | |||
{ | ||||
manual = file.manualChanges(); | manual = file.manualChanges(); | |||
if( manual.isNull() ) | if (manual.isNull()) { | |||
{ | ||||
filename = file.dstFilename(); | filename = file.dstFilename(); | |||
extension = file.dstExtension(); | extension = file.dstExtension(); | |||
} | } else { | |||
else | ||||
filename = manual; | filename = manual; | |||
} | } | |||
else | } else { | |||
{ | ||||
filename = file.srcFilename(); | filename = file.srcFilename(); | |||
extension = file.srcExtension(); | extension = file.srcExtension(); | |||
} | } | |||
if( !extension.isEmpty() ) | if (!extension.isEmpty()) { | |||
{ | filename += '.'; | |||
filename += "."; | ||||
filename += extension; | filename += extension; | |||
} | } | |||
if( file.isDirectory() ) | if (file.isDirectory()) { | |||
{ | ||||
filename = (index.column() ? file.dstDirectory() : file.srcDirectory ()) + '/' + filename; | filename = (index.column() ? file.dstDirectory() : file.srcDirectory ()) + '/' + filename; | |||
} | } | |||
return filename; | return filename; | |||
} | } else if (role == Qt::ForegroundRole) { | |||
else if( role == Qt::ForegroundRole ) | const KRenameFile &file = m_vector->at(index.row()); | |||
{ | if (!file.manualChanges().isNull()) { | |||
const KRenameFile& file = m_vector->at(index.row()); | return QVariant(QColor(Qt::blue)); | |||
if( !file.manualChanges().isNull() ) | } | |||
return QVariant( Qt::blue ); | ||||
} | } | |||
/* | /* | |||
Icons are to large, so this is disabled | Icons are to large, so this is disabled | |||
else if( role == Qt::DecorationRole && index.column() == 0 ) | else if( role == Qt::DecorationRole && index.column() == 0 ) | |||
{ | { | |||
return m_vector->at(index.row()).icon(); | return m_vector->at(index.row()).icon(); | |||
} | } | |||
*/ | */ | |||
return QVariant(); | return QVariant(); | |||
} | } | |||
QModelIndex KRenamePreviewModel::parent ( const QModelIndex & ) const | QModelIndex KRenamePreviewModel::parent(const QModelIndex &) const | |||
{ | { | |||
return QModelIndex(); | return QModelIndex(); | |||
} | } | |||
QModelIndex KRenamePreviewModel::sibling ( int, int, const QModelIndex & ) const | QModelIndex KRenamePreviewModel::sibling(int, int, const QModelIndex &) const | |||
{ | { | |||
return QModelIndex(); | return QModelIndex(); | |||
} | } | |||
void KRenamePreviewModel::refresh() | void KRenamePreviewModel::refresh() | |||
{ | { | |||
emit reset(); | beginResetModel(); | |||
endResetModel(); | ||||
} | } | |||
#include "krenamemodel.moc" | ||||
End of changes. 107 change blocks. | ||||
197 lines changed or deleted | 175 lines changed or added |