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

ark

infopanel.cpp

Go to the documentation of this file.
00001 /*
00002  * ark -- archiver for the KDE project
00003  *
00004  * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 #include "infopanel.h"
00022 #include "kerfuffle/archive.h"
00023 
00024 #include <QLabel>
00025 #include <QVBoxLayout>
00026 #include <QFileInfo>
00027 
00028 #include <KLocale>
00029 #include <KMimeType>
00030 #include <KIconLoader>
00031 #include <KIO/NetAccess>
00032 
00033 using namespace Kerfuffle;
00034 
00035 static QPixmap EnormousMimeIcon( const QString& mimeName )
00036 {
00037     return KIconLoader::global()->loadMimeTypeIcon( mimeName, KIconLoader::Desktop, KIconLoader::SizeEnormous );
00038 }
00039 
00040 InfoPanel::InfoPanel( ArchiveModel *model, QWidget *parent )
00041     : QFrame( parent ), m_model( model )
00042 {
00043     setupUi( this );
00044     setDefaultValues();
00045     iconLabel->setFixedHeight( KIconLoader::SizeEnormous );
00046     iconLabel->setMinimumWidth( KIconLoader::SizeEnormous );
00047     setMaximumWidth( 2 * KIconLoader::SizeEnormous );
00048 }
00049 
00050 InfoPanel::~InfoPanel()
00051 {
00052 }
00053 
00054 void InfoPanel::setDefaultValues()
00055 {
00056     iconLabel->setPixmap( KIconLoader::global()->loadIcon( "utilities-file-archiver", KIconLoader::Desktop, KIconLoader::SizeEnormous ) );
00057     if ( !m_model->archive() )
00058     {
00059         fileName->setText( QString( "<center><font size=+1><b>%1</b></font></center>" ).arg( i18n( "No archive loaded" ) ) );
00060         additionalInfo->setText( QString() );
00061     }
00062     else
00063     {
00064         QFileInfo archiveInfo( m_model->archive()->fileName() );
00065         fileName->setText( QString( "<center><font size=+1><b>%1</b></font></center>" ).arg( archiveInfo.fileName() ) );
00066         additionalInfo->setText( QString() );
00067     }
00068     hideMetaData();
00069     hideActions();
00070 }
00071 
00072 void InfoPanel::setIndex( const QModelIndex& index )
00073 {
00074     if ( !index.isValid() )
00075     {
00076         setDefaultValues();
00077     }
00078     else
00079     {
00080         const ArchiveEntry& entry = m_model->entryForIndex( index );
00081 
00082         KMimeType::Ptr mimeType;
00083 
00084         if ( entry[ IsDirectory ].toBool() )
00085         {
00086             mimeType = KMimeType::mimeType( "inode/directory" );
00087         }
00088         else
00089         {
00090             mimeType = KMimeType::findByPath( entry[ FileName ].toString(), 0, true );
00091         }
00092 
00093         iconLabel->setPixmap( EnormousMimeIcon( mimeType->iconName() ) );
00094         if ( entry[ IsDirectory ].toBool() )
00095         {
00096             additionalInfo->setText( i18np( "One item", "%1 items", m_model->childCount( index ) ) );
00097         }
00098         else if ( entry.contains( Link ) )
00099         {
00100             additionalInfo->setText( i18n( "Symbolic Link" ) );
00101         }
00102         else
00103         {
00104             additionalInfo->setText( KIO::convertSize( entry[ Size ].toULongLong() ) );
00105         }
00106 
00107         QStringList nameParts = entry[ FileName ].toString().split( '/', QString::SkipEmptyParts );
00108         QString name = ( nameParts.count() > 0 )? nameParts.last() : entry[ FileName ].toString();
00109         fileName->setText( QString( "<center><font size=+1><b>%1</b></font></center>" ).arg( name ) );
00110 
00111         metadataLabel->setText( metadataTextFor( index ) );
00112         showMetaData();
00113     }
00114 }
00115 
00116 void InfoPanel::setIndexes( const QModelIndexList &list )
00117 {
00118     if ( list.size() == 0 )
00119     {
00120         setIndex( QModelIndex() );
00121     }
00122     else if ( list.size() == 1 )
00123     {
00124         setIndex( list[ 0 ] );
00125     }
00126     else
00127     {
00128         // TODO: set the icon
00129         fileName->setText( QString( "<center><font size=+1><b>%1</b></font></center>" ).arg( i18np( "One file selected", "%1 files selected", list.size() ) ) );
00130         quint64 totalSize = 0;
00131         foreach( const QModelIndex& index, list )
00132         {
00133             const ArchiveEntry& entry = m_model->entryForIndex( index );
00134             totalSize += entry[ Size ].toULongLong();
00135         }
00136         additionalInfo->setText( KIO::convertSize( totalSize ) );
00137         hideMetaData();
00138     }
00139 }
00140 
00141 void InfoPanel::showMetaData()
00142 {
00143     firstSeparator->show();
00144     metadataLabel->show();
00145 }
00146 
00147 void InfoPanel::hideMetaData()
00148 {
00149     firstSeparator->hide();
00150     metadataLabel->hide();
00151 }
00152 
00153 void InfoPanel::showActions()
00154 {
00155     secondSeparator->show();
00156     actionsLabel->show();
00157 }
00158 
00159 void InfoPanel::hideActions()
00160 {
00161     secondSeparator->hide();
00162     actionsLabel->hide();
00163 }
00164 
00165 QString InfoPanel::metadataTextFor( const QModelIndex &index )
00166 {
00167     const ArchiveEntry& entry = m_model->entryForIndex( index );
00168     QString text;
00169 
00170     KMimeType::Ptr mimeType;
00171 
00172     if ( entry[ IsDirectory ].toBool() )
00173     {
00174         mimeType = KMimeType::mimeType( "inode/directory" );
00175     }
00176     else
00177     {
00178         mimeType = KMimeType::findByPath( entry[ FileName ].toString(), 0, true );
00179     }
00180 
00181     text += i18n( "<b>Type:</b> %1<br/>",  mimeType->comment() );
00182 
00183     if ( entry.contains( Owner ) )
00184     {
00185         text += i18n( "<b>Owner:</b> %1<br/>", entry[ Owner ].toString() );
00186     }
00187 
00188     if ( entry.contains( Group ) )
00189     {
00190         text += i18n( "<b>Group:</b> %1<br/>", entry[ Group ].toString() );
00191     }
00192 
00193     if ( entry.contains( Link ) )
00194     {
00195         text += i18n( "<b>Target:</b> %1<br/>", entry[ Link ].toString() );
00196     }
00197 
00198     if ( entry.contains( IsPasswordProtected ) && entry[ IsPasswordProtected ].toBool() )
00199     {
00200         text += i18n( "<b>Password protected:</b> Yes<br/>");
00201     }
00202 
00203     return text;
00204 }
00205 
00206 #include "infopanel.moc"

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal