26#include <tdefileivi.h> 
   27#include <tdefileitem.h> 
   28#include <tdeapplication.h> 
   29#include <kdirlister.h> 
   30#include <tdestandarddirs.h> 
   31#include <kiconloader.h> 
   32#include <konq_settings.h> 
   36#include "kivdirectoryoverlay.h" 
   38KIVDirectoryOverlay::KIVDirectoryOverlay(
KFileIVI* directory)
 
   39: m_lister(0), m_foundItems(false),
 
   40  m_containsFolder(false), m_popularIcons(0)
 
   44        m_lister = 
new KDirLister;
 
   45        m_lister->setAutoErrorHandlingEnabled(
false, 0);
 
   46        connect(m_lister, TQ_SIGNAL(completed()), TQ_SLOT(slotCompleted()));
 
   47        connect(m_lister, TQ_SIGNAL(newItems( 
const KFileItemList& )), TQ_SLOT(slotNewItems( 
const KFileItemList& )));
 
   48        m_lister->setShowingDotFiles(
false);
 
   50    m_directory = directory;
 
   53KIVDirectoryOverlay::~KIVDirectoryOverlay()
 
   55    if (m_lister) m_lister->stop();
 
   57    delete m_popularIcons;
 
   60void KIVDirectoryOverlay::start()
 
   62    if ( m_directory->item()->isReadable() ) {
 
   63        m_popularIcons = 
new TQDict<int>;
 
   64        m_popularIcons->setAutoDelete(
true);
 
   65        m_lister->openURL(m_directory->item()->url());
 
   71void KIVDirectoryOverlay::timerEvent(TQTimerEvent *)
 
   76void KIVDirectoryOverlay::slotCompleted()
 
   78    if (!m_popularIcons) 
return;
 
   81    TQDictIterator<int> currentIcon( (*m_popularIcons) );
 
   82    unsigned int best = 0;
 
   83    unsigned int total = 0;
 
   84    for ( ; currentIcon.current(); ++currentIcon ) {
 
   85        unsigned int currentCount = (*currentIcon.current());
 
   86        total += currentCount;
 
   87        if ( best < currentCount ) {
 
   89            m_bestIcon = currentIcon.currentKey();
 
   95    if ( m_bestIcon.isNull() && m_containsFolder ) {
 
   96        m_bestIcon = 
"folder";
 
   99    if ( best * 2 < total ) {
 
  100        m_bestIcon = 
"application-vnd.tde.tdemultiple";
 
  103    if (!m_bestIcon.isNull()) {
 
  104        m_directory->setOverlay(m_bestIcon);
 
  107    delete m_popularIcons;
 
  113void KIVDirectoryOverlay::slotNewItems( 
const KFileItemList& items )
 
  115    if ( !m_popularIcons) 
return;
 
  117    KFileItemListIterator files( items );
 
  120    for ( ; (file = files.current()) != 0; ++files ) {
 
  121        if ( file -> isFile() ) {
 
  123        TQString iconName = file -> iconName();
 
  124        if (!iconName) 
continue;
 
  126        int* iconCount = m_popularIcons -> find( file -> iconName() );
 
  128            iconCount = 
new int(0);
 
  130            m_popularIcons -> insert(file -> iconName(), iconCount);
 
  133        } 
else if ( file -> isDir() ) {
 
  134            m_containsFolder = 
true;
 
  141#include "kivdirectoryoverlay.moc" 
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem,...