00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <qdict.h>
00021
#include <qpixmap.h>
00022
#include <qpainter.h>
00023
#include <qbitmap.h>
00024
#include <qimage.h>
00025
00026
#include <kfileivi.h>
00027
#include <kfileitem.h>
00028
#include <kapplication.h>
00029
#include <kdirlister.h>
00030
#include <kstandarddirs.h>
00031
#include <kiconloader.h>
00032
#include <konq_settings.h>
00033
#include <klocale.h>
00034
#include <kdebug.h>
00035
00036
#include "kivdirectoryoverlay.h"
00037
00038 KIVDirectoryOverlay::KIVDirectoryOverlay(
KFileIVI* directory)
00039 : m_lister(0), m_foundItems(false),
00040 m_containsFolder(false), m_popularIcons(0)
00041 {
00042
if (!m_lister)
00043 {
00044 m_lister =
new KDirLister;
00045 m_lister->setAutoErrorHandlingEnabled(
false, 0);
00046 connect(m_lister, SIGNAL(completed()), SLOT(slotCompleted()));
00047 connect(m_lister, SIGNAL(newItems(
const KFileItemList& )), SLOT(slotNewItems(
const KFileItemList& )));
00048 m_lister->setShowingDotFiles(
false);
00049 }
00050 m_directory = directory;
00051 }
00052
00053 KIVDirectoryOverlay::~KIVDirectoryOverlay()
00054 {
00055
if (m_lister) m_lister->stop();
00056
delete m_lister;
00057
delete m_popularIcons;
00058 }
00059
00060
void KIVDirectoryOverlay::start()
00061 {
00062
if ( m_directory->item()->isReadable() ) {
00063 m_popularIcons =
new QDict<int>;
00064 m_popularIcons->setAutoDelete(
true);
00065 m_lister->openURL(m_directory->item()->url());
00066 }
else {
00067 emit finished();
00068 }
00069 }
00070
00071
void KIVDirectoryOverlay::timerEvent(QTimerEvent *)
00072 {
00073 m_lister->stop();
00074 }
00075
00076
void KIVDirectoryOverlay::slotCompleted()
00077 {
00078
if (!m_popularIcons)
return;
00079
00080
00081 QDictIterator<int> currentIcon( (*m_popularIcons) );
00082
unsigned int best = 0;
00083
unsigned int total = 0;
00084
for ( ; currentIcon.current(); ++currentIcon ) {
00085
unsigned int currentCount = (*currentIcon.current());
00086 total += currentCount;
00087
if ( best < currentCount ) {
00088 best = currentCount;
00089 m_bestIcon = currentIcon.currentKey();
00090 }
00091 }
00092
00093
00094
00095
if ( m_bestIcon.isNull() && m_containsFolder ) {
00096 m_bestIcon =
"folder";
00097 }
00098
00099
if ( best * 2 < total ) {
00100 m_bestIcon =
"kmultiple";
00101 }
00102
00103
if (!m_bestIcon.isNull()) {
00104 m_directory->setOverlay(m_bestIcon);
00105 }
00106
00107
delete m_popularIcons;
00108 m_popularIcons = 0;
00109
00110 emit finished();
00111 }
00112
00113
void KIVDirectoryOverlay::slotNewItems(
const KFileItemList& items )
00114 {
00115
if ( !m_popularIcons)
return;
00116
00117 KFileItemListIterator files( items );
00118
00119 KFileItem* file;
00120
for ( ; (file = files.current()) != 0; ++files ) {
00121
if ( file -> isFile() ) {
00122
00123 QString iconName = file -> iconName();
00124
if (!iconName)
continue;
00125
00126
int* iconCount = m_popularIcons -> find( file -> iconName() );
00127
if (!iconCount) {
00128 iconCount =
new int(0);
00129 Q_ASSERT(file);
00130 m_popularIcons -> insert(file -> iconName(), iconCount);
00131 }
00132 (*iconCount)++;
00133 }
else if ( file -> isDir() ) {
00134 m_containsFolder =
true;
00135 }
00136 }
00137
00138 m_foundItems =
true;
00139 }
00140
00141
#include "kivdirectoryoverlay.moc"