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

libkonq

kivfreespaceoverlay.cc

00001 /*  This file is part of the TDE libraries
00002     Copyright (C) 2013 Timothy Pearson
00003     Based on kivdirectoryoverlay.cc
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "config.h"
00022 
00023 #include <tqdict.h>
00024 #include <tqpixmap.h>
00025 #include <tqpainter.h>
00026 #include <tqbitmap.h>
00027 #include <tqimage.h>
00028 #include <tqfile.h>
00029 #include <tqtimer.h>
00030 
00031 #include <tdefileivi.h>
00032 #include <tdefileitem.h>
00033 #include <tdeapplication.h>
00034 #include <kdirlister.h>
00035 #include <kstandarddirs.h>
00036 #include <kiconloader.h>
00037 #include <konq_settings.h>
00038 #include <tdelocale.h>
00039 #include <kdebug.h>
00040 
00041 #ifdef HAVE_STATVFS
00042 # include <sys/statvfs.h>
00043 #else
00044 # include <sys/mount.h>
00045 # define statvfs statfs
00046 # define f_frsize f_bsize
00047 #endif
00048 
00049 #include "kivfreespaceoverlay.h"
00050 
00051 KIVFreeSpaceOverlay::KIVFreeSpaceOverlay(KFileIVI* freespace)
00052 {
00053     m_freespace = freespace;
00054 }
00055 
00056 KIVFreeSpaceOverlay::~KIVFreeSpaceOverlay()
00057 {
00058     //
00059 }
00060 
00061 void KIVFreeSpaceOverlay::start()
00062 {
00063     if ( !m_freespace->item()->isReadable() ) {
00064         emit finished();
00065     }
00066     TQTimer::singleShot(0, this, TQT_SLOT(slotDisplay()));
00067 }
00068 
00069 void KIVFreeSpaceOverlay::timerEvent(TQTimerEvent *)
00070 {
00071     //
00072 }
00073 
00074 void KIVFreeSpaceOverlay::slotDisplay()
00075 {
00076     KFileItem* item = m_freespace->item();
00077     if (item) {
00078         if (item->mimetype().contains("_mounted")) {
00079             bool isLocal = false;
00080             KURL localURL = item->mostLocalURL(isLocal);
00081             if (!isLocal) {
00082                 m_freespace->setOverlayProgressBar(-1);
00083             }
00084             else {
00085                 TQString localPath = localURL.path();
00086                 if (localPath != "") {
00087                     TDEIO::filesize_t m_total = 0;
00088                     TDEIO::filesize_t m_used = 0;
00089                     TDEIO::filesize_t m_free = 0;
00090 
00091                     struct statvfs vfs;
00092                     memset(&vfs, 0, sizeof(vfs));
00093 
00094                     if ( ::statvfs(TQFile::encodeName(localPath), &vfs) != -1 )
00095                     {
00096                         m_total = static_cast<TDEIO::filesize_t>(vfs.f_blocks) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
00097                         m_free = static_cast<TDEIO::filesize_t>(vfs.f_bavail) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
00098                         m_used = m_total - m_free;
00099                         m_freespace->setOverlayProgressBar((m_used/(m_total*1.0))*100.0);
00100                     }
00101                     else {
00102                         m_freespace->setOverlayProgressBar(-1);
00103                     }
00104                 }
00105                 else {
00106                     m_freespace->setOverlayProgressBar(-1);
00107                 }
00108             }
00109         }
00110     }
00111     else {
00112         m_freespace->setOverlayProgressBar(-1);
00113     }
00114 
00115     emit finished();
00116 }
00117 
00118 #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.6.3
This website is maintained by Timothy Pearson.