Commit 41d645c1 authored by David Faure's avatar David Faure
Browse files

Generate nicer-looking display names, no trashId in front (e.g. "0-").

CCBUG: 183403
Doesn't fix the behavior on drag-n-drop though, yet.
parent 79460818
......@@ -274,7 +274,9 @@ void TrashProtocol::stat(const KUrl& url)
return;
}
QString fileName = filePath.section(QLatin1Char('/'), -1, -1, QString::SectionSkipEmpty);
// For a toplevel file, use the fileId as display name (to hide the trashId)
// For a file in a subdir, use the fileName as is.
QString fileDisplayName = relativePath.isEmpty() ? fileId : url.fileName();
KUrl fileURL;
if ( url.path().length() > 1 ) {
......@@ -285,7 +287,7 @@ void TrashProtocol::stat(const KUrl& url)
TrashedFileInfo info;
ok = impl.infoForFile( trashId, fileId, info );
if ( ok )
ok = createUDSEntry( filePath, fileName, fileURL.fileName(), entry, info );
ok = createUDSEntry( filePath, fileDisplayName, fileURL.fileName(), entry, info );
if ( !ok ) {
error( KIO::ERR_COULD_NOT_STAT, url.prettyUrl() );
......@@ -373,7 +375,8 @@ void TrashProtocol::listDir(const KUrl& url)
TrashedFileInfo infoForItem( info );
infoForItem.origPath += QLatin1Char('/');
infoForItem.origPath += fileName;
if ( ok && createUDSEntry( filePath, fileName, fileName, entry, infoForItem ) ) {
if (createUDSEntry(filePath, fileName, fileName, entry, infoForItem)) {
listEntry( entry, false );
}
}
......@@ -448,7 +451,8 @@ void TrashProtocol::listRoot()
KUrl origURL;
origURL.setPath( (*it).origPath );
entry.clear();
if ( createUDSEntry( (*it).physicalPath, origURL.fileName(), url.fileName(), entry, *it ) )
const QString fileDisplayName = (*it).fileId;
if ( createUDSEntry( (*it).physicalPath, fileDisplayName, url.fileName(), entry, *it ) )
listEntry( entry, false );
}
entry.clear();
......
......@@ -1000,6 +1000,7 @@ void TestTrash::listRootDir()
{
m_entryCount = 0;
m_listResult.clear();
m_displayNameListResult.clear();
KIO::ListJob* job = KIO::listDir( KUrl("trash:/"), KIO::HideProgressInfo );
connect( job, SIGNAL( entries( KIO::Job*, const KIO::UDSEntryList& ) ),
SLOT( slotEntries( KIO::Job*, const KIO::UDSEntryList& ) ) );
......@@ -1008,14 +1009,18 @@ void TestTrash::listRootDir()
kDebug() << "listDir done - m_entryCount=" << m_entryCount;
QVERIFY( m_entryCount > 1 );
kDebug() << m_listResult;
QVERIFY( m_listResult.contains( "." ) == 1 ); // found it, and only once
//kDebug() << m_listResult;
//kDebug() << m_displayNameListResult;
QCOMPARE(m_listResult.count( "." ), 1); // found it, and only once
QCOMPARE(m_displayNameListResult.count( "fileFromHome" ), 1);
QCOMPARE(m_displayNameListResult.count( "fileFromHome 1" ), 1);
}
void TestTrash::listRecursiveRootDir()
{
m_entryCount = 0;
m_listResult.clear();
m_displayNameListResult.clear();
KIO::ListJob* job = KIO::listRecursive( KUrl("trash:/"), KIO::HideProgressInfo );
connect( job, SIGNAL( entries( KIO::Job*, const KIO::UDSEntryList& ) ),
SLOT( slotEntries( KIO::Job*, const KIO::UDSEntryList& ) ) );
......@@ -1024,14 +1029,19 @@ void TestTrash::listRecursiveRootDir()
kDebug() << "listDir done - m_entryCount=" << m_entryCount;
QVERIFY( m_entryCount > 1 );
kDebug() << m_listResult;
QVERIFY( m_listResult.count( "." ) == 1 ); // found it, and only once
//kDebug() << m_listResult;
//kDebug() << m_displayNameListResult;
QCOMPARE(m_listResult.count( "." ), 1); // found it, and only once
QCOMPARE(m_displayNameListResult.count( "fileFromHome" ), 1);
QCOMPARE(m_displayNameListResult.count( "fileFromHome 1" ), 1);
QCOMPARE(m_displayNameListResult.count( "testfile_in_subdir" ), 1);
}
void TestTrash::listSubDir()
{
m_entryCount = 0;
m_listResult.clear();
m_displayNameListResult.clear();
KIO::ListJob* job = KIO::listDir( KUrl("trash:/0-trashDirFromHome"), KIO::HideProgressInfo );
connect( job, SIGNAL( entries( KIO::Job*, const KIO::UDSEntryList& ) ),
SLOT( slotEntries( KIO::Job*, const KIO::UDSEntryList& ) ) );
......@@ -1040,22 +1050,26 @@ void TestTrash::listSubDir()
kDebug() << "listDir done - m_entryCount=" << m_entryCount;
QVERIFY( m_entryCount == 2 );
kDebug() << m_listResult;
QVERIFY( m_listResult.count( "." ) == 1 ); // found it, and only once
QVERIFY( m_listResult.count( "testfile" ) == 1 ); // found it, and only once
//kDebug() << m_listResult;
//kDebug() << m_displayNameListResult;
QCOMPARE(m_listResult.count( "." ), 1); // found it, and only once
QCOMPARE(m_listResult.count( "testfile" ), 1); // found it, and only once
QCOMPARE(m_displayNameListResult.count( "testfile" ), 1);
}
void TestTrash::slotEntries( KIO::Job*, const KIO::UDSEntryList& lst )
{
for( KIO::UDSEntryList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
const KIO::UDSEntry& entry (*it);
QString displayName = entry.stringValue( KIO::UDSEntry::UDS_NAME );
QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
QString displayName = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
KUrl url = entry.stringValue( KIO::UDSEntry::UDS_URL );
kDebug() << displayName << " " << url;
kDebug() << "name" << name << "displayName" << displayName << " UDS_URL=" << url;
if ( !url.isEmpty() ) {
QVERIFY( url.protocol() == "trash" );
}
m_listResult << displayName;
m_listResult << name;
m_displayNameListResult << displayName;
}
m_entryCount += lst.count();
}
......
......@@ -116,6 +116,7 @@ private:
int m_entryCount;
QStringList m_listResult;
QStringList m_displayNameListResult;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment