From 8084f4ffe2bfe48359009cb2c475a13328429c34 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 1 Nov 2010 23:23:24 +0100 Subject: Ordering files in file: and ftp: embedded protocols --- src/protocolhandler.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/protocolhandler.cpp') diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp index a595394a..a29ff366 100644 --- a/src/protocolhandler.cpp +++ b/src/protocolhandler.cpp @@ -57,6 +57,37 @@ #include +static bool fileItemListLessThan(const KFileItem &s1, const KFileItem &s2) +{ + return s1.name().toLower() < s2.name().toLower(); +} + + +static KFileItemList sortFileList(const KFileItemList &list) +{ + KFileItemList orderedList, dirList, fileList; + + // order dirs before files.. + Q_FOREACH(const KFileItem &item, list) + { + if(item.isDir()) + dirList << item; + else + fileList << item; + } + qStableSort(dirList.begin(), dirList.end(), fileItemListLessThan); + qStableSort(fileList.begin(), fileList.end(), fileItemListLessThan); + + orderedList << dirList; + orderedList << fileList; + + return orderedList; +} + + +// ------------------------------------------------------------------------------------------- + + ProtocolHandler::ProtocolHandler(QObject *parent) : QObject(parent) , _lister( new KDirLister(this) ) @@ -282,7 +313,8 @@ QString ProtocolHandler::dirHandling(const KFileItemList &list) msg += ""; msg += ""; - foreach(const KFileItem &item, list) + KFileItemList orderedList = sortFileList(list); + Q_FOREACH(const KFileItem &item, orderedList) { msg += ""; QString fullPath = item.url().prettyUrl(); -- cgit v1.2.1
" + i18n("Name") + "" + i18n("Size") + "" + i18n("Last Modified") + "