1
/* This file is part of the KDE libraries
2
Copyright (C) 2002 Simon MacMullen
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
27
#include <kfileitem.h>
28
#include <kapplication.h>
29
#include <kdirlister.h>
30
#include <kstandarddirs.h>
31
#include <kiconloader.h>
32
#include <konq_settings.h>
36
#include "kivdirectoryoverlay.h"
38
KIVDirectoryOverlay::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, SIGNAL(completed()), SLOT(slotCompleted()));
47
connect(m_lister, SIGNAL(newItems( const KFileItemList& )), SLOT(slotNewItems( const KFileItemList& )));
48
m_lister->setShowingDotFiles(false);
50
m_directory = directory;
53
KIVDirectoryOverlay::~KIVDirectoryOverlay()
55
if (m_lister) m_lister->stop();
57
delete m_popularIcons;
60
void KIVDirectoryOverlay::start()
62
if ( m_directory->item()->isReadable() ) {
63
m_popularIcons = new QDict<int>;
64
m_popularIcons->setAutoDelete(true);
65
m_lister->openURL(m_directory->item()->url());
71
void KIVDirectoryOverlay::timerEvent(QTimerEvent *)
76
void KIVDirectoryOverlay::slotCompleted()
78
if (!m_popularIcons) return;
80
// Look through the histogram for the most popular mimetype
81
QDictIterator<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();
93
// Only show folder if there's no other candidate. Most folders contain
94
// folders. We know this.
95
if ( m_bestIcon.isNull() && m_containsFolder ) {
96
m_bestIcon = "folder";
99
if ( best * 2 < total ) {
100
m_bestIcon = "kmultiple";
103
if (!m_bestIcon.isNull()) {
104
m_directory->setOverlay(m_bestIcon);
107
delete m_popularIcons;
113
void 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
QString 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"