summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2013-04-13 22:41:07 -0500
committerTimothy Pearson <[email protected]>2013-04-13 22:41:07 -0500
commit9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67 (patch)
tree93678c9bd7fd986e44911b920bc066c591274dae
parent3df12cd87674fdfbc2afa21584e1f3e558fa873b (diff)
downloadtdebase-9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67.tar.gz
tdebase-9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67.zip
Add initial media device free space overlay to Konqueror icon view
-rw-r--r--konqueror/iconview/konq_iconview.cc76
-rw-r--r--konqueror/iconview/konq_iconview.h5
-rw-r--r--konqueror/iconview/konq_iconview.rc1
-rw-r--r--libkonq/CMakeLists.txt9
-rw-r--r--libkonq/Makefile.am2
-rw-r--r--libkonq/kivfreespaceoverlay.cc131
-rw-r--r--libkonq/kivfreespaceoverlay.h56
-rw-r--r--libkonq/konq_propsview.cc20
-rw-r--r--libkonq/konq_propsview.h4
-rw-r--r--libkonq/tdefileivi.cc72
-rw-r--r--libkonq/tdefileivi.h20
11 files changed, 392 insertions, 4 deletions
diff --git a/konqueror/iconview/konq_iconview.cc b/konqueror/iconview/konq_iconview.cc
index a7bb5a812..1ac7b2eb5 100644
--- a/konqueror/iconview/konq_iconview.cc
+++ b/konqueror/iconview/konq_iconview.cc
@@ -40,6 +40,7 @@
#include <ktrader.h>
#include <tdelocale.h>
#include <kivdirectoryoverlay.h>
+#include <kivfreespaceoverlay.h>
#include <tdemessagebox.h>
#include <kstaticdeleter.h>
@@ -217,6 +218,9 @@ KonqKfmIconView::KonqKfmIconView( TQWidget *parentWidget, TQObject *parent, cons
m_paDirectoryOverlays = new TDEToggleAction( i18n( "&Folder Icons Reflect Contents" ), 0, this, TQT_SLOT( slotShowDirectoryOverlays() ),
actionCollection(), "show_directory_overlays" );
+ m_paFreeSpaceOverlays = new TDEToggleAction( i18n( "&Media Icons Reflect Free Space" ), 0, this, TQT_SLOT( slotShowFreeSpaceOverlays() ),
+ actionCollection(), "show_free_space_overlays" );
+
m_pamPreview = new TDEActionMenu( i18n( "&Preview" ), actionCollection(), "iconview_preview" );
m_paEnablePreviews = new TDEToggleAction( i18n("Enable Previews"), 0, actionCollection(), "iconview_preview_all" );
@@ -517,6 +521,27 @@ void KonqKfmIconView::slotShowDirectoryOverlays()
m_pIconView->updateContents();
}
+void KonqKfmIconView::slotShowFreeSpaceOverlays()
+{
+ bool show = !m_pProps->isShowingFreeSpaceOverlays();
+
+ m_pProps->setShowingFreeSpaceOverlays( show );
+
+ for ( TQIconViewItem *item = m_pIconView->firstItem(); item; item = item->nextItem() )
+ {
+ KFileIVI* kItem = static_cast<KFileIVI*>(item);
+ if ( !kItem->item()->isDir() ) continue;
+
+ if (show) {
+ showFreeSpaceOverlay(kItem);
+ } else {
+ kItem -> setShowFreeSpaceOverlay(false);
+ }
+ }
+
+ m_pIconView->updateContents();
+}
+
void KonqKfmIconView::slotSelect()
{
bool ok;
@@ -978,6 +1003,9 @@ void KonqKfmIconView::slotNewItems( const KFileItemList& entries )
if ( fileItem->isDir() && m_pProps->isShowingDirectoryOverlays() ) {
showDirectoryOverlay(item);
}
+ if ( fileItem->mimetype().startsWith("media/") && m_pProps->isShowingFreeSpaceOverlays() ) {
+ showFreeSpaceOverlay(item);
+ }
TQString key;
@@ -1074,6 +1102,25 @@ void KonqKfmIconView::showDirectoryOverlay(KFileIVI* item)
}
}
+void KonqKfmIconView::showFreeSpaceOverlay(KFileIVI* item)
+{
+ KFileItem* fileItem = item->item();
+
+ if ( TDEGlobalSettings::showFilePreview( fileItem->url() ) ) {
+ m_paOutstandingOverlays.append(item);
+ if (m_paOutstandingOverlays.count() == 1)
+ {
+ if (!m_paOutstandingOverlaysTimer)
+ {
+ m_paOutstandingOverlaysTimer = new TQTimer(this);
+ connect(m_paOutstandingOverlaysTimer, TQT_SIGNAL(timeout()),
+ TQT_SLOT(slotFreeSpaceOverlayStart()));
+ }
+ m_paOutstandingOverlaysTimer->start(20, true);
+ }
+ }
+}
+
void KonqKfmIconView::slotDirectoryOverlayStart()
{
do
@@ -1094,6 +1141,26 @@ void KonqKfmIconView::slotDirectoryOverlayStart()
} while (true);
}
+void KonqKfmIconView::slotFreeSpaceOverlayStart()
+{
+ do
+ {
+ KFileIVI* item = m_paOutstandingOverlays.first();
+ if (!item)
+ return; // Nothing to do
+
+ KIVFreeSpaceOverlay* overlay = item->setShowFreeSpaceOverlay( true );
+
+ if (overlay)
+ {
+ connect( overlay, TQT_SIGNAL( finished() ), this, TQT_SLOT( slotFreeSpaceOverlayFinished() ) );
+ overlay->start(); // Watch out, may emit finished() immediately!!
+ return; // Let it run....
+ }
+ m_paOutstandingOverlays.removeFirst();
+ } while (true);
+}
+
void KonqKfmIconView::slotDirectoryOverlayFinished()
{
m_paOutstandingOverlays.removeFirst();
@@ -1102,6 +1169,14 @@ void KonqKfmIconView::slotDirectoryOverlayFinished()
m_paOutstandingOverlaysTimer->start(0, true); // Don't call directly to prevent deep recursion.
}
+void KonqKfmIconView::slotFreeSpaceOverlayFinished()
+{
+ m_paOutstandingOverlays.removeFirst();
+
+ if (m_paOutstandingOverlays.count() > 0)
+ m_paOutstandingOverlaysTimer->start(0, true); // Don't call directly to prevent deep recursion.
+}
+
// see also KDesktop::slotRefreshItems
void KonqKfmIconView::slotRefreshItems( const KFileItemList& entries )
{
@@ -1302,6 +1377,7 @@ bool KonqKfmIconView::doOpenURL( const KURL & url )
{
m_paDotFiles->setChecked( m_pProps->isShowingDotFiles() );
m_paDirectoryOverlays->setChecked( m_pProps->isShowingDirectoryOverlays() );
+ m_paFreeSpaceOverlays->setChecked( m_pProps->isShowingFreeSpaceOverlays() );
m_paEnablePreviews->setChecked( m_pProps->isShowingPreview() );
for ( m_paPreviewPlugins.first(); m_paPreviewPlugins.current(); m_paPreviewPlugins.next() )
{
diff --git a/konqueror/iconview/konq_iconview.h b/konqueror/iconview/konq_iconview.h
index c05362b9d..d66cc4cc8 100644
--- a/konqueror/iconview/konq_iconview.h
+++ b/konqueror/iconview/konq_iconview.h
@@ -76,6 +76,7 @@ public:
public slots:
void slotPreview( bool toggle );
void slotShowDirectoryOverlays();
+ void slotShowFreeSpaceOverlays();
void slotShowDot();
void slotSelect();
void slotUnselect();
@@ -120,7 +121,9 @@ protected slots:
virtual void slotClear();
virtual void slotRedirection( const KURL & );
virtual void slotDirectoryOverlayStart();
+ virtual void slotFreeSpaceOverlayStart();
virtual void slotDirectoryOverlayFinished();
+ virtual void slotFreeSpaceOverlayFinished();
/**
* This is the 'real' finished slot, where we emit the completed() signal
@@ -196,6 +199,7 @@ protected:
TDEToggleAction *m_paDotFiles;
TDEToggleAction *m_paDirectoryOverlays;
+ TDEToggleAction *m_paFreeSpaceOverlays;
TDEToggleAction *m_paEnablePreviews;
TQPtrList<KFileIVI> m_paOutstandingOverlays;
TQTimer *m_paOutstandingOverlaysTimer;
@@ -226,6 +230,7 @@ protected:
private:
void showDirectoryOverlay(KFileIVI* item);
+ void showFreeSpaceOverlay(KFileIVI* item);
};
class IconViewBrowserExtension : public KonqDirPartBrowserExtension
diff --git a/konqueror/iconview/konq_iconview.rc b/konqueror/iconview/konq_iconview.rc
index 20551e0a7..4c0f95c99 100644
--- a/konqueror/iconview/konq_iconview.rc
+++ b/konqueror/iconview/konq_iconview.rc
@@ -36,6 +36,7 @@
<Action name="iconview_preview" />
<Action name="show_dot"/>
<Action name="show_directory_overlays"/>
+ <Action name="show_free_space_overlays"/>
<Separator/>
<Action name="bgsettings"/>
</Menu>
diff --git a/libkonq/CMakeLists.txt b/libkonq/CMakeLists.txt
index 5b960874e..7202bdfe8 100644
--- a/libkonq/CMakeLists.txt
+++ b/libkonq/CMakeLists.txt
@@ -23,6 +23,7 @@ include_directories(
${TQT_INCLUDE_DIRS}
${ARTS_INCLUDE_DIRS}
${TDE_INCLUDE_DIR}/arts/
+ ${CMAKE_BINARY_DIR}
)
link_directories(
@@ -39,8 +40,8 @@ install( FILES
konq_operations.h libkonq_export.h konq_dirpart.h
konq_propsview.h konq_events.h konq_undo.h
konq_historymgr.h konq_historycomm.h konq_pixmapprovider.h
- kivdirectoryoverlay.h konq_faviconmgr.h konq_xmlguiclient.h
- konqbookmarkmanager.h konq_filetip.h
+ kivdirectoryoverlay.h kivfreespaceoverlay.h konq_faviconmgr.h
+ konq_xmlguiclient.h konqbookmarkmanager.h konq_filetip.h
DESTINATION ${INCLUDE_INSTALL_DIR} )
@@ -58,8 +59,8 @@ tde_add_library( konq SHARED AUTOMOC
konq_iconviewwidget.cc konq_settings.cc konq_drag.cc konq_operations.cc
konq_dirpart.cc konq_propsview.cc konq_events.cc konq_bgnddlg.cc konq_undo.cc
konq_undo.skel konq_historymgr.cc konq_historycomm.cc konq_historycomm.skel
- konq_pixmapprovider.cc kivdirectoryoverlay.cc konq_faviconmgr.cc
- konq_faviconmgr.skel konq_filetip.cc
+ konq_pixmapprovider.cc kivdirectoryoverlay.cc kivfreespaceoverlay.cc
+ konq_faviconmgr.cc konq_faviconmgr.skel konq_filetip.cc
VERSION 4.2.0
LINK tdeparts-shared
DESTINATION ${LIB_INSTALL_DIR}
diff --git a/libkonq/Makefile.am b/libkonq/Makefile.am
index 327c97450..8d4cc1216 100644
--- a/libkonq/Makefile.am
+++ b/libkonq/Makefile.am
@@ -32,6 +32,7 @@ libkonq_la_SOURCES = konq_popupmenu.cc knewmenu.cc \
konq_historymgr.cc konq_historycomm.cc konq_historycomm.skel \
konq_pixmapprovider.cc \
kivdirectoryoverlay.cc \
+ kivfreespaceoverlay.cc \
konq_faviconmgr.cc konq_faviconmgr.skel konq_filetip.cc
directory_DATA = directory_bookmarkbar.desktop
@@ -50,6 +51,7 @@ include_HEADERS = konq_popupmenu.h knewmenu.h \
konq_undo.h konq_historymgr.h konq_historycomm.h \
konq_pixmapprovider.h \
kivdirectoryoverlay.h \
+ kivfreespaceoverlay.h \
konq_faviconmgr.h konq_xmlguiclient.h konqbookmarkmanager.h konq_filetip.h
diff --git a/libkonq/kivfreespaceoverlay.cc b/libkonq/kivfreespaceoverlay.cc
new file mode 100644
index 000000000..614c8529a
--- /dev/null
+++ b/libkonq/kivfreespaceoverlay.cc
@@ -0,0 +1,131 @@
+/* This file is part of the TDE libraries
+ Copyright (C) 2013 Timothy Pearson
+ Based on kivdirectoryoverlay.cc
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include <tqdict.h>
+#include <tqpixmap.h>
+#include <tqpainter.h>
+#include <tqbitmap.h>
+#include <tqimage.h>
+#include <tqfile.h>
+
+#include <tdefileivi.h>
+#include <tdefileitem.h>
+#include <tdeapplication.h>
+#include <kdirlister.h>
+#include <kstandarddirs.h>
+#include <kiconloader.h>
+#include <konq_settings.h>
+#include <tdelocale.h>
+#include <kdebug.h>
+
+#ifdef HAVE_STATVFS
+# include <sys/statvfs.h>
+#else
+# include <sys/mount.h>
+# define statvfs statfs
+# define f_frsize f_bsize
+#endif
+
+#include "kivfreespaceoverlay.h"
+
+KIVFreeSpaceOverlay::KIVFreeSpaceOverlay(KFileIVI* freespace)
+: m_lister(0)
+{
+ if (!m_lister)
+ {
+ m_lister = new KDirLister;
+ m_lister->setAutoErrorHandlingEnabled(false, 0);
+ connect(m_lister, TQT_SIGNAL(completed()), TQT_SLOT(slotCompleted()));
+ connect(m_lister, TQT_SIGNAL(newItems( const KFileItemList& )), TQT_SLOT(slotNewItems( const KFileItemList& )));
+ m_lister->setShowingDotFiles(false);
+ }
+ m_freespace = freespace;
+}
+
+KIVFreeSpaceOverlay::~KIVFreeSpaceOverlay()
+{
+ if (m_lister) m_lister->stop();
+ delete m_lister;
+}
+
+void KIVFreeSpaceOverlay::start()
+{
+ if ( m_freespace->item()->isReadable() ) {
+ m_lister->openURL(m_freespace->item()->url());
+ } else {
+ emit finished();
+ }
+}
+
+void KIVFreeSpaceOverlay::timerEvent(TQTimerEvent *)
+{
+ m_lister->stop();
+}
+
+void KIVFreeSpaceOverlay::slotCompleted()
+{
+ KFileItem* item = m_freespace->item();
+ if (item) {
+ bool isLocal = false;
+ KURL localURL = item->mostLocalURL(isLocal);
+ if (!isLocal) {
+ m_freespace->setOverlayProgressBar(-1);
+ }
+ else {
+ TQString localPath = localURL.path();
+ if (localPath != "") {
+ TDEIO::filesize_t m_total = 0;
+ TDEIO::filesize_t m_used = 0;
+ TDEIO::filesize_t m_free = 0;
+
+ struct statvfs vfs;
+ memset(&vfs, 0, sizeof(vfs));
+
+ if ( ::statvfs(TQFile::encodeName(localPath), &vfs) != -1 )
+ {
+ m_total = static_cast<TDEIO::filesize_t>(vfs.f_blocks) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
+ m_free = static_cast<TDEIO::filesize_t>(vfs.f_bavail) * static_cast<TDEIO::filesize_t>(vfs.f_frsize);
+ m_used = m_total - m_free;
+ m_freespace->setOverlayProgressBar((m_used/(m_total*1.0))*100.0);
+ }
+ else {
+ m_freespace->setOverlayProgressBar(-1);
+ }
+ }
+ else {
+ m_freespace->setOverlayProgressBar(-1);
+ }
+ }
+ }
+ else {
+ m_freespace->setOverlayProgressBar(-1);
+ }
+
+ emit finished();
+}
+
+void KIVFreeSpaceOverlay::slotNewItems( const KFileItemList& items )
+{
+ //
+}
+
+#include "kivfreespaceoverlay.moc"
diff --git a/libkonq/kivfreespaceoverlay.h b/libkonq/kivfreespaceoverlay.h
new file mode 100644
index 000000000..3b454e74b
--- /dev/null
+++ b/libkonq/kivfreespaceoverlay.h
@@ -0,0 +1,56 @@
+/* This file is part of the TDE libraries
+ Copyright (C) 2013 Timothy Pearson
+ Based on kivdirectoryoverlay.h
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KIVFREESPACEOVERLAY_H_
+#define _KIVFREESPACEOVERLAY_H_
+
+#include <tdefileitem.h>
+#include <libkonq_export.h>
+
+#include <tqdict.h>
+
+class KDirLister;
+class KFileIVI;
+
+class LIBKONQ_EXPORT KIVFreeSpaceOverlay : public TQObject
+{
+ Q_OBJECT
+
+public:
+ KIVFreeSpaceOverlay(KFileIVI* freespace);
+ virtual ~KIVFreeSpaceOverlay();
+ void start();
+
+signals:
+ void finished();
+
+protected:
+ virtual void timerEvent(TQTimerEvent *);
+
+private slots:
+ void slotCompleted();
+ void slotNewItems( const KFileItemList& items );
+
+private:
+ KDirLister* m_lister;
+ KFileIVI* m_freespace;
+};
+
+#endif
diff --git a/libkonq/konq_propsview.cc b/libkonq/konq_propsview.cc
index bc8aa4e9d..edaff588b 100644
--- a/libkonq/konq_propsview.cc
+++ b/libkonq/konq_propsview.cc
@@ -94,6 +94,7 @@ KonqPropsView::KonqPropsView( TDEInstance * instance, KonqPropsView * defaultPro
d->descending = config->readBoolEntry( "SortDescending", false );
m_bShowDot = config->readBoolEntry( "ShowDotFiles", false );
m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", false );
+ m_bShowFreeSpaceOverlays = config->readBoolEntry( "ShowFreeSpaceOverlays", false );
m_dontPreview = config->readListEntry( "DontPreview" );
m_dontPreview.remove("audio/"); //Use the separate setting.
@@ -222,6 +223,7 @@ bool KonqPropsView::enterDir( const KURL & dir )
m_bShowDot = config->readBoolEntry( "ShowDotFiles", m_bShowDot );
d->caseInsensitiveSort=config->readBoolEntry("CaseInsensitiveSort",d->caseInsensitiveSort);
m_bShowDirectoryOverlays = config->readBoolEntry( "ShowDirectoryOverlays", m_bShowDirectoryOverlays );
+ m_bShowFreeSpaceOverlays = config->readBoolEntry( "ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
if (config->hasKey( "DontPreview" ))
{
m_dontPreview = config->readListEntry( "DontPreview" );
@@ -393,6 +395,24 @@ void KonqPropsView::setShowingDirectoryOverlays( bool show )
}
}
+void KonqPropsView::setShowingFreeSpaceOverlays( bool show )
+{
+ kdDebug(1203) << "KonqPropsView::setShowingFreeSpaceOverlays " << show << endl;
+ m_bShowFreeSpaceOverlays = show;
+ if ( m_defaultProps && !m_bSaveViewPropertiesLocally )
+ {
+ kdDebug(1203) << "Saving in default properties" << endl;
+ m_defaultProps->setShowingFreeSpaceOverlays( show );
+ }
+ else if (currentConfig())
+ {
+ kdDebug(1203) << "Saving in current config" << endl;
+ TDEConfigGroupSaver cgs(currentConfig(), currentGroup());
+ currentConfig()->writeEntry( "ShowFreeSpaceOverlays", m_bShowFreeSpaceOverlays );
+ currentConfig()->sync();
+ }
+}
+
void KonqPropsView::setShowingPreview( const TQString &preview, bool show )
{
if ( m_dontPreview.contains( preview ) != show )
diff --git a/libkonq/konq_propsview.h b/libkonq/konq_propsview.h
index fb0383072..c2759693f 100644
--- a/libkonq/konq_propsview.h
+++ b/libkonq/konq_propsview.h
@@ -105,6 +105,9 @@ public:
void setShowingDirectoryOverlays( bool show );
bool isShowingDirectoryOverlays() const { return m_bShowDirectoryOverlays; }
+ void setShowingFreeSpaceOverlays( bool show );
+ bool isShowingFreeSpaceOverlays() const { return m_bShowFreeSpaceOverlays; }
+
void setShowingPreview( const TQString &preview, bool show );
void setShowingPreview( bool show );
bool isShowingPreview( const TQString &preview ) const { return ! m_dontPreview.contains(preview); }
@@ -143,6 +146,7 @@ private:
int m_iItemTextPos;
bool m_bShowDot;
bool m_bShowDirectoryOverlays;
+ bool m_bShowFreeSpaceOverlays;
TQStringList m_dontPreview;
TQColor m_textColor;
TQColor m_bgColor;
diff --git a/libkonq/tdefileivi.cc b/libkonq/tdefileivi.cc
index e91bf359b..bff31c890 100644
--- a/libkonq/tdefileivi.cc
+++ b/libkonq/tdefileivi.cc
@@ -19,6 +19,7 @@
#include "tdefileivi.h"
#include "kivdirectoryoverlay.h"
+#include "kivfreespaceoverlay.h"
#include "konq_iconviewwidget.h"
#include "konq_operations.h"
#include "konq_settings.h"
@@ -44,8 +45,10 @@ struct KFileIVI::Private
TQString m_animatedIcon; // Name of animation
bool m_animated; // Animation currently running ?
KIVDirectoryOverlay* m_directoryOverlay;
+ KIVFreeSpaceOverlay* m_freeSpaceOverlay;
TQPixmap m_overlay;
TQString m_overlayName;
+ int m_progress;
};
KFileIVI::KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size )
@@ -72,12 +75,15 @@ KFileIVI::KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size
else
setMouseOverAnimation( "unknown" );
}
+ d->m_progress = -1;
d->m_directoryOverlay = 0;
+ d->m_freeSpaceOverlay = 0;
}
KFileIVI::~KFileIVI()
{
delete d->m_directoryOverlay;
+ delete d->m_freeSpaceOverlay;
delete d;
}
@@ -138,6 +144,13 @@ void KFileIVI::setOverlay( const TQString& iconName )
refreshIcon(true);
}
+void KFileIVI::setOverlayProgressBar( const int progress )
+{
+ d->m_progress = progress;
+
+ refreshIcon(true);
+}
+
KIVDirectoryOverlay* KFileIVI::setShowDirectoryOverlay( bool show )
{
if ( !m_fileitem->isDir() || m_fileitem->iconName() != "folder" )
@@ -160,6 +173,28 @@ bool KFileIVI::showDirectoryOverlay( )
return (bool)d->m_directoryOverlay;
}
+KIVFreeSpaceOverlay* KFileIVI::setShowFreeSpaceOverlay( bool show )
+{
+ if ( !m_fileitem->mimetype().startsWith("media/") )
+ return 0;
+
+ if (show) {
+ if (!d->m_freeSpaceOverlay)
+ d->m_freeSpaceOverlay = new KIVFreeSpaceOverlay(this);
+ return d->m_freeSpaceOverlay;
+ } else {
+ delete d->m_freeSpaceOverlay;
+ d->m_freeSpaceOverlay = 0;
+ setOverlayProgressBar(-1);
+ return 0;
+ }
+}
+
+bool KFileIVI::showFreeSpaceOverlay( )
+{
+ return (bool)d->m_freeSpaceOverlay;
+}
+
void KFileIVI::setPixmapDirect( const TQPixmap& pixmap, bool recalc, bool redraw )
{
TQIconSet::Mode mode;
@@ -375,6 +410,7 @@ void KFileIVI::paintItem( TQPainter *p, const TQColorGroup &c )
TDEIconViewItem::paintItem( p, cg );
paintOverlay(p);
+ paintOverlayProgressBar(p);
}
@@ -386,6 +422,42 @@ void KFileIVI::paintOverlay( TQPainter *p ) const
}
}
+void KFileIVI::paintOverlayProgressBar( TQPainter *p ) const
+{
+ if (d->m_progress != -1) {
+// // Pie chart
+// TQRect rect = pixmapRect(true);
+// rect.setX(x() + rect.x());
+// rect.setY(y() + rect.y() + ((pixmapRect().height()*3)/4));
+// rect.setWidth(pixmapRect().width()/4);
+// rect.setHeight(pixmapRect().height()/4);
+//
+// p->save();
+//
+// p->setPen(TQPen::NoPen);
+// p->setBrush(TQt::red);
+// p->drawEllipse(rect);
+// p->setBrush(TQt::green);
+// p->drawPie(rect, 1440, (((100-d->m_progress)*5760)/100));
+
+ // Progress bar
+ TQRect rect = pixmapRect(true);
+ int verticalOffset = 0;
+ int usedBarWidth = ((d->m_progress*pixmapRect().width())/100);
+ int endPosition = x() + rect.x() + usedBarWidth;
+
+ p->save();
+
+ p->setPen(TQPen::NoPen);
+ p->setBrush(TQt::red);
+ p->drawRect(TQRect(x() + rect.x(), y() + rect.y() + (pixmapRect().height() - verticalOffset), usedBarWidth, 1));
+ p->setBrush(TQt::green);
+ p->drawRect(TQRect(endPosition, y() + rect.y() + (pixmapRect().height() - verticalOffset), pixmapRect().width() - usedBarWidth, 1));
+
+ p->restore();
+ }
+}
+
void KFileIVI::paintFontUpdate( TQPainter *p ) const
{
if ( m_fileitem->isLink() )
diff --git a/libkonq/tdefileivi.h b/libkonq/tdefileivi.h
index 9d940a023..243688d43 100644
--- a/libkonq/tdefileivi.h
+++ b/libkonq/tdefileivi.h
@@ -27,6 +27,7 @@
class KFileItem;
class KonqIconViewWidget;
class KIVDirectoryOverlay;
+class KIVFreeSpaceOverlay;
/**
* KFileIVI (short form of "Konq - File - IconViewItem")
@@ -146,6 +147,13 @@ public:
void setOverlay( const TQString & iconName);
/**
+ * Sets a progress bar to be shown on the right side of the icon.
+ * Currently used for disk space overlays.
+ * setOverlayProgressBar(-1) to remove progress bar.
+ */
+ void setOverlayProgressBar( const int progress);
+
+ /**
* Redetermines the icon (useful if KFileItem might return another icon).
* Does nothing with thumbnails
*/
@@ -191,6 +199,13 @@ public:
KIVDirectoryOverlay* setShowDirectoryOverlay( bool );
bool showDirectoryOverlay( );
+ /**
+ * Sets showing of free space overlays. Does nothing if this does
+ * not represent a media device.
+ */
+ KIVFreeSpaceOverlay* setShowFreeSpaceOverlay( bool );
+ bool showFreeSpaceOverlay( );
+
virtual int compare( TQIconViewItem *i ) const;
protected:
@@ -202,6 +217,11 @@ protected:
void paintOverlay( TQPainter *p ) const;
/**
+ * Contains the logic and code for painting the overlay progress bar.
+ */
+ void paintOverlayProgressBar( TQPainter *p ) const;
+
+ /**
* Updates the colorgroup.
*/
TQColorGroup updateColors(const TQColorGroup &c) const;