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