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

filelight

  • sources
  • kde-4.12
  • kdeutils
  • filelight
  • src
  • part
summaryWidget.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 "summaryWidget.h"
23 
24 #include "Config.h"
25 #include "fileTree.h"
26 #include "radialMap/radialMap.h"
27 #include "radialMap/widget.h"
28 #include "summaryWidget.moc"
29 
30 #include <KDebug>
31 #include <KIconEffect> //MyRadialMap::mousePressEvent()
32 #include <KIconLoader>
33 #include <KIcon>
34 #include <KLocale>
35 
36 #include <Solid/Device>
37 #include <Solid/StorageAccess>
38 
39 #include <KDiskFreeSpaceInfo>
40 
41 #include <QtGui/QLabel>
42 #include <QtGui/QApplication>
43 #include <QtCore/QByteArray>
44 #include <QtCore/QList>
45 #include <QtGui/QMouseEvent>
46 #include <QtGui/QLayout>
47 
48 struct Disk
49 {
50  QString mount;
51  QString icon;
52 
53  qint64 size;
54  qint64 used;
55  qint64 free; //NOTE used+avail != size (clustersize!)
56 };
57 
58 
59 struct DiskList : QList<Disk>
60 {
61  DiskList();
62 };
63 
64 
65 class MyRadialMap : public RadialMap::Widget
66 {
67 public:
68  MyRadialMap(QWidget *parent)
69  : RadialMap::Widget(parent, true)
70  {
71  }
72 
73  virtual void setCursor(const QCursor &c)
74  {
75  if (focusSegment() && focusSegment()->file()->name() == QLatin1String( "Used" ))
76  RadialMap::Widget::setCursor(c);
77  else
78  unsetCursor();
79  }
80 
81  virtual void mousePressEvent(QMouseEvent *e)
82  {
83  const RadialMap::Segment *segment = focusSegment();
84 
85  //we will allow right clicks to the center circle
86  if (segment == rootSegment() && e->button() == Qt::RightButton)
87  RadialMap::Widget::mousePressEvent(e);
88 
89  //and clicks to the used segment
90  else if (e->button() == Qt::LeftButton ) {
91  const QRect rect(e->x() - 20, e->y() - 20, 40, 40);
92 // KIconEffect::visualActivate(this, rect); TODO: Re-enable
93  emit activated(url());
94  }
95  }
96 };
97 
98 
99 
100 SummaryWidget::SummaryWidget(QWidget *parent)
101  : QWidget(parent)
102 {
103  qApp->setOverrideCursor(Qt::WaitCursor);
104  setLayout(new QGridLayout(this));
105  createDiskMaps();
106  qApp->restoreOverrideCursor();
107 }
108 
109 void SummaryWidget::createDiskMaps()
110 {
111  DiskList disks;
112 
113  const QByteArray free = i18nc("Free space on the disks/partitions", "Free").toUtf8();
114  const QByteArray used = i18nc("Used space on the disks/partitions", "Used").toUtf8();
115 
116  KIconLoader loader;
117  QString text;
118 
119  for (DiskList::ConstIterator it = disks.constBegin(), end = disks.constEnd(); it != end; ++it)
120  {
121  Disk const &disk = *it;
122 
123  if (disk.free == 0 && disk.used == 0)
124  continue;
125 
126  QWidget *volume = new QWidget(this);
127  QVBoxLayout *volumeLayout = new QVBoxLayout(volume);
128  RadialMap::Widget *map = new MyRadialMap(this);
129 
130  QWidget *info = new QWidget(this);
131  info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
132  QHBoxLayout* horizontalLayout = new QHBoxLayout(info);
133 
134  // Create the text and icon under the radialMap.
135  text = QLatin1String( "<b>" ) + disk.mount + i18nc("Percent used disk space on the partition", "</b> (%1% Used)", disk.used*100/disk.size);
136 
137  QLabel *label = new QLabel(text, this);
138  horizontalLayout->addWidget(label);
139  QLabel *icon = new QLabel(this);
140  icon->setPixmap(KIcon(disk.icon).pixmap(16,16));
141  horizontalLayout->addWidget(icon);
142 
143  horizontalLayout->setAlignment(Qt::AlignCenter);
144  volumeLayout->addWidget(map);
145  volumeLayout->addWidget(info);
146 
147  // row (=n/2) column (0 or 1)
148  qobject_cast<QGridLayout*>(layout())->addWidget(volume, layout()->count()/2, layout()->count() % 2);
149 
150  Folder *tree = new Folder(disk.mount.toUtf8());
151  tree->append(free, disk.free);
152  tree->append(used, disk.used);
153 
154  map->create(tree); //must be done when visible
155 
156  connect(map, SIGNAL(activated(KUrl)), SIGNAL(activated(KUrl)));
157  }
158 }
159 
160 DiskList::DiskList()
161 {
162  const Solid::StorageAccess *partition;
163  QStringList partitions;
164 
165  foreach (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess))
166  { // Iterate over all the partitions available.
167 
168  if (!device.is<Solid::StorageAccess>()) continue; // It happens.
169 
170  partition = device.as<Solid::StorageAccess>();
171  if (!partition->isAccessible()) continue;
172 
173  if (partitions.contains(partition->filePath())) // check for duplicate partitions from Solid
174  continue;
175  partitions.append(partition->filePath());
176 
177  KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(partition->filePath());
178  if (!info.isValid()) continue;
179 
180  Disk disk;
181  disk.mount = partition->filePath();
182  disk.icon = device.icon();
183  disk.size = info.size();
184  disk.free = info.available();
185  disk.used = info.used();
186 
187  *this += disk;
188  }
189 }
RadialMap::Widget::Widget
Widget(QWidget *=0, bool=false)
Definition: widget.cpp:39
summaryWidget.h
RadialMap::Widget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: widgetEvents.cpp:193
SummaryWidget::SummaryWidget
SummaryWidget(QWidget *parent)
Definition: summaryWidget.cpp:100
QWidget
RadialMap::Widget
Definition: widget.h:50
Config.h
radialMap.h
Folder
Definition: fileTree.h:271
RadialMap::Widget::focusSegment
const Segment * focusSegment() const
Definition: widget.h:105
fileTree.h
SummaryWidget::activated
void activated(const KUrl &)
RadialMap::Widget::create
void create(const Folder *)
Definition: widget.cpp:103
Folder::append
void append(Folder *d, const char *name=0)
appends a Folder
Definition: fileTree.h:284
Filelight::parent
http QObject * parent
Definition: part.cpp:74
widget.h
RadialMap::Widget::rootSegment
const Segment * rootSegment() const
Definition: widget.h:102
RadialMap::Widget::activated
void activated(const KUrl &)
RadialMap::Widget::url
KUrl url(File const *const =0) const
Definition: widget.cpp:69
RadialMap::Segment
Definition: radialMap.h:31
segment
#define segment
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:08:08 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
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • 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