Commit 66e19815 authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* Show item count for folders on the info bar

svn path=/branches/work/libarchive-based-ark/ark/; revision=690385
parent 0f2dcadc
......@@ -248,6 +248,21 @@ ArchiveEntry ArchiveModel::entryForIndex( const QModelIndex &index )
return ArchiveEntry();
}
int ArchiveModel::childCount( const QModelIndex &index )
{
if ( index.isValid() )
{
ArchiveNode *item = static_cast<ArchiveNode*>( index.internalPointer() );
Q_ASSERT( item );
if ( item->isDir() )
{
return static_cast<ArchiveDirNode*>( item )->entries().count();
}
return 0;
}
return -1;
}
int ArchiveModel::rowCount( const QModelIndex &parent ) const
{
if ( parent.column() <= 0 )
......
......@@ -50,6 +50,7 @@ class ArchiveModel: public QAbstractItemModel
Kerfuffle::Archive *archive() const { return m_archive; }
ArchiveEntry entryForIndex( const QModelIndex &index );
int childCount( const QModelIndex &index );
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths = false );
......
......@@ -31,8 +31,13 @@
using namespace Kerfuffle;
InfoPanel::InfoPanel( QWidget *parent )
: QFrame( parent )
static QPixmap EnormousMimeIcon( const QString& mimeName )
{
return KIconLoader::global()->loadMimeTypeIcon( mimeName, K3Icon::Desktop, K3Icon::SizeEnormous );
}
InfoPanel::InfoPanel( ArchiveModel *model, QWidget *parent )
: QFrame( parent ), m_model( model )
{
setupUi( this );
setDefaultValues();
......@@ -47,29 +52,46 @@ InfoPanel::~InfoPanel()
void InfoPanel::setDefaultValues()
{
KMimeType::Ptr defaultMime = KMimeType::defaultMimeTypePtr();
iconLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon( defaultMime->iconName(), K3Icon::Desktop, K3Icon::SizeEnormous ) );
fileName->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( i18n( "No file selected" ) ) );
additionalInfo->setText( QString() );
iconLabel->setPixmap( KIconLoader::global()->loadIcon( "ark", K3Icon::Desktop, K3Icon::SizeEnormous ) );
if ( !m_model->archive() )
{
fileName->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( i18n( "No archive loaded" ) ) );
additionalInfo->setText( QString() );
}
else
{
fileName->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( i18n( "No file selected" ) ) );
additionalInfo->setText( QString() );
}
hideMetaData();
hideActions();
}
void InfoPanel::setEntry( const Kerfuffle::ArchiveEntry& entry )
void InfoPanel::setIndex( const QModelIndex& index )
{
if ( entry.isEmpty() )
if ( !index.isValid() )
{
setDefaultValues();
}
else
{
KMimeType::Ptr mimeType = KMimeType::findByPath( entry[ FileName ].toString(), 0, true );
iconLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon( mimeType->iconName(), K3Icon::Desktop, K3Icon::SizeEnormous ) );
const ArchiveEntry& entry = m_model->entryForIndex( index );
if ( entry[ IsDirectory ].toBool() )
{
iconLabel->setPixmap( EnormousMimeIcon( KMimeType::mimeType( "inode/directory" )->iconName() ) );
additionalInfo->setText( i18np( "One item", "%1 items", m_model->childCount( index ) ) );
}
else
{
KMimeType::Ptr mimeType = KMimeType::findByPath( entry[ FileName ].toString(), 0, true );
iconLabel->setPixmap( EnormousMimeIcon( mimeType->iconName() ) );
additionalInfo->setText( mimeType->comment() );
}
QStringList nameParts = entry[ FileName ].toString().split( '/', QString::SkipEmptyParts );
QString name = ( nameParts.count() > 0 )? nameParts.last() : entry[ FileName ].toString();
fileName->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( name ) );
additionalInfo->setText( mimeType->comment() );
metadataLabel->setText( metadataTextFor( entry ) );
showMetaData();
......
......@@ -23,6 +23,7 @@
#include <QFrame>
#include "kerfuffle/archive.h"
#include "archivemodel.h"
#include "ui_infopanel.h"
class QLabel;
......@@ -31,10 +32,10 @@ class InfoPanel: public QFrame, Ui::InformationPanel
{
Q_OBJECT
public:
InfoPanel( QWidget *parent = 0 );
InfoPanel( ArchiveModel *model, QWidget *parent = 0 );
~InfoPanel();
void setEntry( const Kerfuffle::ArchiveEntry& entry );
void setIndex( const QModelIndex & );
private:
void setDefaultValues();
......@@ -46,6 +47,8 @@ class InfoPanel: public QFrame, Ui::InformationPanel
void hideActions();
QString metadataTextFor( const Kerfuffle::ArchiveEntry& entry );
ArchiveModel *m_model;
};
#endif // INFOPANEL_H
......@@ -53,7 +53,7 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
QSplitter *mainWidget = new QSplitter( Qt::Horizontal, parentWidget );
setWidget( mainWidget );
m_view = new QTreeView( parentWidget );
m_infoPanel = new InfoPanel( parentWidget );
m_infoPanel = new InfoPanel( m_model, parentWidget );
mainWidget->addWidget( m_view );
mainWidget->addWidget( m_infoPanel );
......@@ -119,7 +119,7 @@ void Part::updateActions()
void Part::selectionChanged()
{
m_infoPanel->setEntry( m_model->entryForIndex( m_view->selectionModel()->currentIndex() ) );
m_infoPanel->setIndex( m_view->selectionModel()->currentIndex() );
}
KAboutData* Part::createAboutData()
......@@ -131,7 +131,7 @@ bool Part::openFile()
{
Kerfuffle::Archive *archive = Kerfuffle::factory( localFilePath() );
m_model->setArchive( archive );
m_infoPanel->setEntry( ArchiveEntry() );
m_infoPanel->setIndex( QModelIndex() );
updateActions();
return ( archive != 0 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment