• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
kivdirectoryoverlay.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Simon MacMullen
3 
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.
8 
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.
13 
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.
18 */
19 
20 #include <tqdict.h>
21 #include <tqpixmap.h>
22 #include <tqpainter.h>
23 #include <tqbitmap.h>
24 #include <tqimage.h>
25 
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>
33 #include <tdelocale.h>
34 #include <kdebug.h>
35 
36 #include "kivdirectoryoverlay.h"
37 
38 KIVDirectoryOverlay::KIVDirectoryOverlay(KFileIVI* directory)
39 : m_lister(0), m_foundItems(false),
40  m_containsFolder(false), m_popularIcons(0)
41 {
42  if (!m_lister)
43  {
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);
49  }
50  m_directory = directory;
51 }
52 
53 KIVDirectoryOverlay::~KIVDirectoryOverlay()
54 {
55  if (m_lister) m_lister->stop();
56  delete m_lister;
57  delete m_popularIcons;
58 }
59 
60 void KIVDirectoryOverlay::start()
61 {
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());
66  } else {
67  emit finished();
68  }
69 }
70 
71 void KIVDirectoryOverlay::timerEvent(TQTimerEvent *)
72 {
73  m_lister->stop();
74 }
75 
76 void KIVDirectoryOverlay::slotCompleted()
77 {
78  if (!m_popularIcons) return;
79 
80  // Look through the histogram for the most popular mimetype
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 ) {
88  best = currentCount;
89  m_bestIcon = currentIcon.currentKey();
90  }
91  }
92 
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";
97  }
98 
99  if ( best * 2 < total ) {
100  m_bestIcon = "application-vnd.tde.tdemultiple";
101  }
102 
103  if (!m_bestIcon.isNull()) {
104  m_directory->setOverlay(m_bestIcon);
105  }
106 
107  delete m_popularIcons;
108  m_popularIcons = 0;
109 
110  emit finished();
111 }
112 
113 void KIVDirectoryOverlay::slotNewItems( const KFileItemList& items )
114 {
115  if ( !m_popularIcons) return;
116 
117  KFileItemListIterator files( items );
118 
119  KFileItem* file;
120  for ( ; (file = files.current()) != 0; ++files ) {
121  if ( file -> isFile() ) {
122 
123  TQString iconName = file -> iconName();
124  if (!iconName) continue;
125 
126  int* iconCount = m_popularIcons -> find( file -> iconName() );
127  if (!iconCount) {
128  iconCount = new int(0);
129  Q_ASSERT(file);
130  m_popularIcons -> insert(file -> iconName(), iconCount);
131  }
132  (*iconCount)++;
133  } else if ( file -> isDir() ) {
134  m_containsFolder = true;
135  }
136  }
137 
138  m_foundItems = true;
139 }
140 
141 #include "kivdirectoryoverlay.moc"
KFileIVI
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem...
Definition: tdefileivi.h:39

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.8.13
This website is maintained by Timothy Pearson.