Commit 4d048ad0 authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* Introducing an (useless for now) information bar

svn path=/branches/work/libarchive-based-ark/ark/; revision=689527
parent bed37e29
......@@ -7,11 +7,7 @@ ADD_DEFINITIONS(-D_LARGEFILE64_SOURCE)
set(arkpart_PART_SRCS
part.cpp
#filelistview.cpp
#arkutils.cpp
#arkwidget.cpp
#arkviewer.cpp
#extractiondialog.cpp
infopanel.cpp
archivemodel.cpp
)
......
......@@ -216,6 +216,17 @@ QModelIndex ArchiveModel::parent( const QModelIndex &index ) const
return QModelIndex();
}
ArchiveEntry ArchiveModel::entryForIndex( const QModelIndex &index )
{
if ( index.isValid() )
{
ArchiveNode *item = static_cast<ArchiveNode*>( index.internalPointer() );
Q_ASSERT( item );
return item->entry();
}
return ArchiveEntry();
}
int ArchiveModel::rowCount( const QModelIndex &parent ) const
{
if ( parent.column() <= 0 )
......
......@@ -46,6 +46,8 @@ class ArchiveModel: public QAbstractItemModel
void setArchive( Arch *archive );
ArchiveEntry entryForIndex( const QModelIndex &index );
signals:
void loadingStarted();
void loadingFinished();
......
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "infopanel.h"
#include "kerfuffle/arch.h"
#include <QLabel>
#include <QVBoxLayout>
#include <KLocale>
#include <KMimeType>
#include <KIconLoader>
InfoPanel::InfoPanel( QWidget *parent )
: QWidget( parent ), m_icon( new QLabel( this ) ), m_name( new QLabel( this ) ), m_mimetype( new QLabel( this ) )
{
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget( m_icon );
layout->addWidget( m_name );
layout->addWidget( m_mimetype );
layout->addStretch();
setLayout( layout );
setDefaultValues();
m_icon->setAlignment( Qt::AlignCenter );
m_name->setAlignment( Qt::AlignCenter );
m_mimetype->setAlignment( Qt::AlignCenter );
}
InfoPanel::~InfoPanel()
{
}
void InfoPanel::setDefaultValues()
{
KMimeType::Ptr defaultMime = KMimeType::defaultMimeTypePtr();
m_icon->setPixmap( KIconLoader::global()->loadMimeTypeIcon( defaultMime->iconName(), K3Icon::Desktop ) );
m_name->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( i18n( "No file selected" ) ) );
m_mimetype->setText( QString() );
}
void InfoPanel::setEntry( const ArchiveEntry& entry )
{
if ( entry.isEmpty() )
{
setDefaultValues();
}
else
{
KMimeType::Ptr mimeType = KMimeType::findByPath( entry[ FileName ].toString(), 0, true );
m_icon->setPixmap( KIconLoader::global()->loadMimeTypeIcon( mimeType->iconName(), K3Icon::Desktop ) );
QStringList nameParts = entry[ FileName ].toString().split( '/', QString::SkipEmptyParts );
QString name = ( nameParts.count() > 0 )? nameParts.last() : entry[ FileName ].toString();
m_name->setText( QString( "<font size=+1><b>%1</b></font>" ).arg( name ) );
m_mimetype->setText( mimeType->comment() );
}
}
#include "infopanel.moc"
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef INFOPANEL_H
#define INFOPANEL_H
#include <QWidget>
#include "kerfuffle/arch.h"
class QLabel;
class InfoPanel: public QWidget
{
Q_OBJECT
public:
InfoPanel( QWidget *parent = 0 );
~InfoPanel();
void setEntry( const ArchiveEntry& entry );
private:
void setDefaultValues();
QLabel *m_icon;
QLabel *m_name;
QLabel *m_mimetype;
};
#endif // INFOPANEL_H
......@@ -20,6 +20,7 @@
*/
#include "part.h"
#include "archivemodel.h"
#include "infopanel.h"
#include <KParts/GenericFactory>
#include <KApplication>
......@@ -27,25 +28,32 @@
#include <KDebug>
#include <KActionCollection>
#include <KIcon>
#include <KHBox>
#include <KDebug>
#include <QTreeView>
#include <QCursor>
#include <QAction>
#include <kdebug.h>
#include <QSplitter>
typedef KParts::GenericFactory<Part> Factory;
K_EXPORT_COMPONENT_FACTORY( libarkpartnew, Factory );
Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) ), m_view( new QTreeView( parentWidget ) )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) )
{
Q_UNUSED( args );
setComponentData( Factory::componentData() );
setXMLFile( "ark_part_new.rc" );
setWidget( m_view );
setupView();
QSplitter *mainWidget = new QSplitter( Qt::Horizontal, parentWidget );
setWidget( mainWidget );
m_view = new QTreeView( parentWidget );
m_infoPanel = new InfoPanel( parentWidget );
mainWidget->addWidget( m_view );
mainWidget->addWidget( m_infoPanel );
setupView();
setupActions();
connect( m_model, SIGNAL( loadingStarted() ),
......@@ -64,6 +72,8 @@ void Part::setupView()
m_view->setModel( m_model );
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( updateActions() ) );
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( selectionChanged() ) );
}
void Part::setupActions()
......@@ -83,6 +93,11 @@ void Part::updateActions()
m_previewAction->setEnabled( m_view->selectionModel()->currentIndex().isValid() );
}
void Part::selectionChanged()
{
m_infoPanel->setEntry( m_model->entryForIndex( m_view->selectionModel()->currentIndex() ) );
}
KAboutData* Part::createAboutData()
{
return new KAboutData( "ark", 0, ki18n( "ArkPart" ), "3.0" );
......
......@@ -25,6 +25,7 @@
#include "interface.h"
class ArchiveModel;
class InfoPanel;
class QTreeView;
class QAction;
class KAboutData;
......@@ -48,6 +49,7 @@ class Part: public KParts::ReadWritePart, public Interface
void slotLoadingFinished();
void slotPreview();
void updateActions();
void selectionChanged();
private:
void setupView();
......@@ -56,6 +58,7 @@ class Part: public KParts::ReadWritePart, public Interface
ArchiveModel *m_model;
QTreeView *m_view;
QAction *m_previewAction;
InfoPanel *m_infoPanel;
};
......
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