diff options
author | Timothy Pearson <[email protected]> | 2013-04-13 22:41:07 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-04-13 22:41:07 -0500 |
commit | 9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67 (patch) | |
tree | 93678c9bd7fd986e44911b920bc066c591274dae /libkonq | |
parent | 3df12cd87674fdfbc2afa21584e1f3e558fa873b (diff) | |
download | tdebase-9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67.tar.gz tdebase-9e4aad6b3bc3c1b4781a3c1cef6968640d4f6e67.zip |
Add initial media device free space overlay to Konqueror icon view
Diffstat (limited to 'libkonq')
-rw-r--r-- | libkonq/CMakeLists.txt | 9 | ||||
-rw-r--r-- | libkonq/Makefile.am | 2 | ||||
-rw-r--r-- | libkonq/kivfreespaceoverlay.cc | 131 | ||||
-rw-r--r-- | libkonq/kivfreespaceoverlay.h | 56 | ||||
-rw-r--r-- | libkonq/konq_propsview.cc | 20 | ||||
-rw-r--r-- | libkonq/konq_propsview.h | 4 | ||||
-rw-r--r-- | libkonq/tdefileivi.cc | 72 | ||||
-rw-r--r-- | libkonq/tdefileivi.h | 20 |
8 files changed, 310 insertions, 4 deletions
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; |