Index: kio/kio/udsentry.h
===================================================================
--- kio/kio/udsentry.h	(revision 1136623)
+++ kio/kio/udsentry.h	(working copy)
@@ -240,6 +240,11 @@
             /// @since 4.5
             UDS_ICON_OVERLAY_NAMES = 26 | UDS_STRING,
 
+            /// A combination of Flags
+            ///
+            /// @since 4.6
+            UDS_FLAGS = 27 | UDS_NUMBER,
+
             /// Extra data (used only if you specified Columns/ColumnsTypes)
             /// KDE 4.0 change: you cannot repeat this entry anymore, use UDS_EXTRA + i
             /// until UDS_EXTRA_END.
Index: kio/kio/kfileitem.h
===================================================================
--- kio/kio/kfileitem.h	(revision 1136623)
+++ kio/kio/kfileitem.h	(working copy)
@@ -62,6 +62,15 @@
     };
 
     /**
+     * @since 4.6
+     */
+    enum Flag {
+        SortFirst = 0x1,
+        SortLast = 0x2
+    };
+    Q_DECLARE_FLAGS(Flags, Flag)
+
+    /**
      * Null KFileItem. Doesn't represent any file, only exists for convenience.
      *
      * NOTE KDE 4.0 when porting from KFileItem* to KFileItem&:
@@ -416,6 +425,11 @@
     QString getToolTipText(int maxcount = 6) const;
 
     /**
+     * @since 4.6
+     */
+    Flags flags() const;
+
+    /**
      * Returns true if files can be dropped over this item.
      * Contrary to popular belief, not only dirs will return true :)
      * Executables, .desktop files, will do so as well.
@@ -657,4 +671,6 @@
  */
 KIO_EXPORT QDebug operator<<(QDebug stream, const KFileItem& item);
 
+Q_DECLARE_OPERATORS_FOR_FLAGS(KFileItem::Flags)
+
 #endif
Index: kio/kio/kfileitem.cpp
===================================================================
--- kio/kio/kfileitem.cpp	(revision 1136623)
+++ kio/kio/kfileitem.cpp	(working copy)
@@ -194,6 +194,8 @@
 
     enum { NumFlags = KFileItem::CreationTime + 1 };
     mutable KDateTime m_time[3];
+
+    KFileItem::Flags m_flags;
 };
 
 void KFileItemPrivate::init()
@@ -280,6 +282,8 @@
         m_url.addPath( m_strName );
 
     m_iconName.clear();
+
+    m_flags = static_cast<KFileItem::Flags>(m_entry.numberValue( KIO::UDSEntry::UDS_FLAGS, 0 ));
 }
 
 inline //because it is used only in one place
@@ -1140,6 +1144,11 @@
     return tip;
 }
 
+KFileItem::Flags KFileItem::flags() const
+{
+    return d->m_flags;
+}
+
 void KFileItem::run( QWidget* parentWidget ) const
 {
     (void) new KRun( targetUrl(), parentWidget, d->m_fileMode, d->m_bIsLocalUrl );
Index: kfile/kdirsortfilterproxymodel.cpp
===================================================================
--- kfile/kdirsortfilterproxymodel.cpp	(revision 1136623)
+++ kfile/kdirsortfilterproxymodel.cpp	(working copy)
@@ -64,7 +64,7 @@
             return result;
         }
     }
-    
+
     return m_naturalSorting ? KStringHandler::naturalCompare(a, b, Qt::CaseSensitive)
                             : QString::compare(a, b, Qt::CaseSensitive);
 }
@@ -145,6 +145,25 @@
 
     const bool isLessThan = (sortOrder() == Qt::AscendingOrder);
 
+    // honor the item flags
+    if (leftFileItem.flags() & KFileItem::SortFirst &&
+        !(rightFileItem.flags() & KFileItem::SortFirst) ) {
+        return isLessThan;
+    }
+    else if (!(leftFileItem.flags() & KFileItem::SortFirst) &&
+             rightFileItem.flags() & KFileItem::SortFirst ) {
+        return !isLessThan;
+    }
+    else if (leftFileItem.flags() & KFileItem::SortLast &&
+             !(rightFileItem.flags() & KFileItem::SortLast) ) {
+        return !isLessThan;
+    }
+    else if (!(leftFileItem.flags() & KFileItem::SortLast) &&
+             rightFileItem.flags() & KFileItem::SortLast ) {
+        return isLessThan;
+    }
+
+
     // Folders go before files if the corresponding setting is set.
     if (d->m_sortFoldersFirst) {
         const bool leftItemIsDir  = leftFileItem.isDir();
