• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

filelight

  • sources
  • kde-4.14
  • kdeutils
  • filelight
  • src
  • part
  • radialMap
builder.cpp
Go to the documentation of this file.
1 /***********************************************************************
2 * Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
3 * Copyright 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License or (at your option) version 3 or any later version
9 * accepted by the membership of KDE e.V. (or its successor approved
10 * by the membership of KDE e.V.), which shall act as a proxy
11 * defined in Section 14 of version 3 of the license.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "builder.h"
23 
24 #include "widget.h"
25 #include <part/Config.h>
26 #include <part/fileTree.h>
27 
28 #include <KGlobal> //locale object
29 #include <KLocale>
30 
31 
32 //**** REMOVE NEED FOR the +1 with MAX_RING_DEPTH uses
33 //**** add some angle bounds checking (possibly in Segment ctor? can I delete in a ctor?)
34 //**** this class is a mess
35 
36 RadialMap::Builder::Builder(RadialMap::Map *m, const Folder* const d, bool fast)
37  : m_map(m)
38  , m_root(d)
39  , m_minSize(static_cast<unsigned int>((d->size() * 3) / (PI * m->height() - m->MAP_2MARGIN)))
40  , m_depth(&m->m_visibleDepth)
41 {
42  m_signature = new Chain<Segment> [*m_depth + 1];
43 
44  if (!fast)//|| *m_depth == 0) //depth 0 is special case usability-wise //**** WHY?!
45  {
46  //determine depth rather than use old one
47  findVisibleDepth(d); //sets m_depth
48  }
49 
50  m_map->setRingBreadth();
51  setLimits(m_map->m_ringBreadth);
52  build(d);
53 
54  m_map->m_signature = m_signature;
55 
56  delete [] m_limits;
57 }
58 
59 
60 void
61 RadialMap::Builder::findVisibleDepth(const Folder* const dir, const unsigned int depth)
62 {
63  //**** because I don't use the same minimumSize criteria as in the visual function
64  // this can lead to incorrect visual representation
65  //**** BUT, you can't set those limits until you know m_depth!
66 
67  //**** also this function doesn't check to see if anything is actually visible
68  // it just assumes that when it reaches a new level everything in it is visible
69  // automatically. This isn't right especially as there might be no files in the
70  // dir provided to this function!
71 
72  static uint stopDepth = 0;
73 
74  if (dir == m_root)
75  {
76  stopDepth = *m_depth;
77  *m_depth = 0;
78  }
79 
80  if (*m_depth < depth) *m_depth = depth;
81  if (*m_depth >= stopDepth) return;
82 
83  for (ConstIterator<File> it = dir->constIterator(); it != dir->end(); ++it)
84  if ((*it)->isFolder() && (*it)->size() > m_minSize)
85  findVisibleDepth((Folder *)*it, depth + 1); //if no files greater than min size the depth is still recorded
86 }
87 
88 void
89 RadialMap::Builder::setLimits(const uint &b) //b = breadth?
90 {
91  double size3 = m_root->size() * 3;
92  double pi2B = PI * 2 * b;
93 
94  m_limits = new uint [*m_depth + 1]; //FIXME delete!
95 
96  for (unsigned int d = 0; d <= *m_depth; ++d)
97  m_limits[d] = (uint)(size3 / (double)(pi2B * (d + 1))); //min is angle that gives 3px outer diameter for that depth
98 }
99 
100 
101 //**** segments currently overlap at edges (i.e. end of first is start of next)
102 bool
103 RadialMap::Builder::build(const Folder* const dir, const unsigned int depth, unsigned int a_start, const unsigned int a_end)
104 {
105  //first iteration: dir == m_root
106 
107  if (dir->children() == 0) //we do fileCount rather than size to avoid chance of divide by zero later
108  return false;
109 
110  uint hiddenSize = 0, hiddenFileCount = 0;
111 
112  for (ConstIterator<File> it = dir->constIterator(); it != dir->end(); ++it)
113  {
114  if ((*it)->size() > m_limits[depth])
115  {
116  unsigned int a_len = (unsigned int)(5760 * ((double)(*it)->size() / (double)m_root->size()));
117 
118  Segment *s = new Segment(*it, a_start, a_len);
119 
120  (m_signature + depth)->append(s);
121 
122  if ((*it)->isFolder())
123  {
124  if (depth != *m_depth)
125  {
126  //recurse
127  s->m_hasHiddenChildren = build((Folder*)*it, depth + 1, a_start, a_start + a_len);
128  }
129  else s->m_hasHiddenChildren = true;
130  }
131 
132  a_start += a_len; //**** should we add 1?
133 
134  } else {
135 
136  hiddenSize += (*it)->size();
137 
138  if ((*it)->isFolder()) //**** considered virtual, but dir wouldn't count itself!
139  hiddenFileCount += static_cast<const Folder*>(*it)->children(); //need to add one to count the dir as well
140 
141  ++hiddenFileCount;
142  }
143  }
144 
145  if (hiddenFileCount == dir->children() && !Config::showSmallFiles)
146  return true;
147 
148  else if ((Config::showSmallFiles && hiddenSize > m_limits[depth]) || (depth == 0 && (hiddenSize > dir->size()/8)) /*|| > size() * 0.75*/)
149  {
150  //append a segment for unrepresented space - a "fake" segment
151 
152  const QString s = i18np("1 file, with an average size of %2",
153  "%1 files, with an average size of %2",
154  hiddenFileCount,
155  KGlobal::locale()->formatByteSize(hiddenSize/hiddenFileCount));
156 
157  (m_signature + depth)->append(new Segment(new File(s.toUtf8(), hiddenSize), a_start, a_end - a_start, true));
158  }
159 
160  return false;
161 }
RadialMap::Builder::Builder
Builder(Map *, const Folder *const, bool fast=false)
Definition: builder.cpp:36
Config.h
File::size
FileSize size() const
Definition: fileTree.h:242
Chain::constIterator
ConstIterator< T > constIterator() const
Definition: fileTree.h:206
RadialMap::Map
Definition: map.h:36
Folder
Definition: fileTree.h:271
fileTree.h
Chain::end
const Link< T > * end() const
Definition: fileTree.h:209
QString
Folder::children
uint children() const
Definition: fileTree.h:276
widget.h
builder.h
Chain
Definition: fileTree.h:40
ConstIterator
Definition: fileTree.h:39
PI
#define PI
Definition: radialMap.h:91
File
Definition: fileTree.h:225
Filelight::m_map
http QObject const QList< QVariant > m_map(0)
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

filelight

Skip menu "filelight"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal