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

libkonq

  • libkonq
kivfreespaceoverlay.cpp
1 /* This file is part of the TDE libraries
2  Copyright (C) 2013 Timothy Pearson
3  Based on kivdirectoryoverlay.cpp
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "config.h"
22 
23 #include <tqdict.h>
24 #include <tqpixmap.h>
25 #include <tqpainter.h>
26 #include <tqbitmap.h>
27 #include <tqimage.h>
28 #include <tqfile.h>
29 #include <tqtimer.h>
30 
31 #include <tdefileivi.h>
32 #include <tdefileitem.h>
33 #include <tdeapplication.h>
34 #include <kdirlister.h>
35 #include <kstandarddirs.h>
36 #include <kiconloader.h>
37 #include <konq_settings.h>
38 #include <tdelocale.h>
39 #include <kdebug.h>
40 
41 #ifdef HAVE_STATVFS
42 # include <sys/statvfs.h>
43 #else
44 # include <sys/mount.h>
45 # define statvfs statfs
46 # define f_frsize f_bsize
47 #endif
48 
49 #include "kivfreespaceoverlay.h"
50 
51 KIVFreeSpaceOverlay::KIVFreeSpaceOverlay(KFileIVI* freespace)
52 {
53  m_freespace = freespace;
54 }
55 
56 KIVFreeSpaceOverlay::~KIVFreeSpaceOverlay()
57 {
58  //
59 }
60 
61 void KIVFreeSpaceOverlay::start()
62 {
63  if ( !m_freespace->item()->isReadable() ) {
64  emit finished();
65  }
66  TQTimer::singleShot(0, this, TQT_SLOT(slotDisplay()));
67 }
68 
69 void KIVFreeSpaceOverlay::timerEvent(TQTimerEvent *)
70 {
71  //
72 }
73 
74 void KIVFreeSpaceOverlay::slotDisplay()
75 {
76  KFileItem* item = m_freespace->item();
77  if (item) {
78  if (item->mimetype().contains("_mounted")) {
79  bool isLocal = false;
80  KURL localURL = item->mostLocalURL(isLocal);
81  if (!isLocal) {
82  m_freespace->setOverlayProgressBar(-1);
83  }
84  else {
85  TQString localPath = localURL.path();
86  if (localPath != "") {
87  TDEIO::filesize_t m_total = 0;
88  TDEIO::filesize_t m_used = 0;
89  TDEIO::filesize_t m_free = 0;
90 
91  struct statvfs vfs;
92  memset(&vfs, 0, sizeof(vfs));
93 
94  if ( ::statvfs(TQFile::encodeName(localPath), &vfs) != -1 )
95  {
96  m_total = static_cast<TDEIO::filesize_t>(vfs.f_blocks) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
97  m_free = static_cast<TDEIO::filesize_t>(vfs.f_bavail) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
98  m_used = m_total - m_free;
99  m_freespace->setOverlayProgressBar((m_used/(m_total*1.0))*100.0);
100  }
101  else {
102  m_freespace->setOverlayProgressBar(-1);
103  }
104  }
105  else {
106  m_freespace->setOverlayProgressBar(-1);
107  }
108  }
109  }
110  }
111  else {
112  m_freespace->setOverlayProgressBar(-1);
113  }
114 
115  emit finished();
116 }
117 
118 #include "kivfreespaceoverlay.moc"

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.1.2
This website is maintained by Timothy Pearson.