filemanager/src/filemanager/src/listviewitems.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
equal deleted inserted replaced
16:ada7962b4308 37:15bc28c9dd51
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *     Zhiqiang Yang <zhiqiang.yang@nokia.com>
       
    14 *     Steven Yao <steven.yao@nokia.com>
       
    15 * 
       
    16 * Description:
       
    17 *     The source file of the disk list view item
       
    18 *
       
    19 */
       
    20 #include "listviewitems.h"
       
    21 #include "fmutils.h"
       
    22 
       
    23 #include <QFileIconProvider>
       
    24 #include <QGraphicsLinearLayout>
       
    25 
       
    26 #include <hblabel.h>
       
    27 #include <hbcheckbox.h>
       
    28 #include <hbpushbutton.h>
       
    29 #include <hbabstractitemview.h>
       
    30 
       
    31 DiskListViewItem::DiskListViewItem( QGraphicsItem *parent )
       
    32     : HbListViewItem( parent ),
       
    33       mIconLabel( 0 ),
       
    34       mDiskNameLabel( 0 ),
       
    35       mSizeLabel( 0 ),
       
    36       mFreeLabel( 0 ),
       
    37       mCheckBox( 0 )
       
    38 
       
    39 {
       
    40     init();
       
    41 }
       
    42 
       
    43 DiskListViewItem::~DiskListViewItem()
       
    44 {
       
    45 }
       
    46 
       
    47 void DiskListViewItem::polish(HbStyleParameters& params)
       
    48 {
       
    49     Q_UNUSED(params);
       
    50 }
       
    51 
       
    52 bool DiskListViewItem::canSetModelIndex( const QModelIndex &index ) const
       
    53 {
       
    54     Q_UNUSED( index );
       
    55 	return true;
       
    56 }
       
    57 
       
    58 
       
    59 HbAbstractViewItem *DiskListViewItem::createItem()
       
    60 {
       
    61 	return new DiskListViewItem( parentItem() );
       
    62 }
       
    63 
       
    64 void DiskListViewItem::updateChildItems()
       
    65 {
       
    66 	QVariant variant = modelIndex().data( Qt::DecorationRole );
       
    67 	QIcon icon = qvariant_cast<QIcon>( variant );
       
    68     if( icon.isNull() ) {
       
    69         QFileIconProvider fileIconProvider;
       
    70         icon = fileIconProvider.icon( QFileIconProvider::Drive );
       
    71     }
       
    72     QString displayString = modelIndex().data( Qt::DisplayRole ).toString();
       
    73 	QString diskName = modelIndex().data( Qt::UserRole ).toString();
       
    74 
       
    75     diskName = FmUtils::fillPathWithSplash( diskName );
       
    76 
       
    77 	mIconLabel->setIcon( HbIcon( icon ) );
       
    78 	
       
    79 	FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
       
    80 
       
    81     mDiskNameLabel->setPlainText( displayString );
       
    82     mSizeLabel->setPlainText( hbTrId ( "Size: " ) + FmUtils::formatStorageSize( driverInfo.size() ) );
       
    83     mFreeLabel->setPlainText( hbTrId ( "Free: " ) + FmUtils::formatStorageSize( driverInfo.freeSize() ) );
       
    84 
       
    85 //    mCheckBox->setCheckState( checkState() );
       
    86 }
       
    87 
       
    88 void DiskListViewItem::setCheckedState( int state )
       
    89 {
       
    90 	HbAbstractViewItem::setCheckState( static_cast<Qt::CheckState>(state) );
       
    91 }
       
    92 
       
    93 void DiskListViewItem::init()
       
    94 {
       
    95 	QGraphicsLinearLayout *hLayout = new QGraphicsLinearLayout();
       
    96 	hLayout->setOrientation( Qt::Horizontal );
       
    97 
       
    98 	mIconLabel = new HbLabel();
       
    99 	mIconLabel->setMinimumWidth(32);
       
   100 	hLayout->addItem( mIconLabel );
       
   101 	hLayout->setAlignment( mIconLabel, Qt::AlignTop );
       
   102 	hLayout->setStretchFactor( mIconLabel, 1 );
       
   103 
       
   104 	QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout();
       
   105 	vLayout->setOrientation( Qt::Vertical );
       
   106 
       
   107 	mDiskNameLabel = new HbLabel();
       
   108 	mDiskNameLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) );
       
   109 	vLayout->addItem( mDiskNameLabel );
       
   110 	vLayout->setAlignment( mDiskNameLabel, Qt::AlignLeft );
       
   111 
       
   112 	mSizeLabel = new HbLabel();
       
   113 	mSizeLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
       
   114 	vLayout->addItem( mSizeLabel );
       
   115 	vLayout->setAlignment( mSizeLabel, Qt::AlignLeft );
       
   116 
       
   117 	mFreeLabel = new HbLabel();
       
   118 	mFreeLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
       
   119 	vLayout->addItem( mFreeLabel );
       
   120 	vLayout->setAlignment( mFreeLabel, Qt::AlignLeft );
       
   121 
       
   122 	HbWidget *labelsWidget = new HbWidget();
       
   123 	labelsWidget->setLayout(vLayout);
       
   124 
       
   125 	hLayout->addItem( labelsWidget );
       
   126 	hLayout->setStretchFactor( labelsWidget, 5 );
       
   127 
       
   128 	setLayout( hLayout );
       
   129 }
       
   130 
       
   131 //file list item, not used.
       
   132 /*
       
   133 FileListViewItem::FileListViewItem( QGraphicsItem *parent )
       
   134     : HbListViewItem( parent ),
       
   135       mIconLabel( 0 ),
       
   136       mNameLabel( 0 ),
       
   137       mCheckBox( 0 )
       
   138 {
       
   139     init();
       
   140 }
       
   141 
       
   142 FileListViewItem::~FileListViewItem()
       
   143 {
       
   144 }
       
   145 
       
   146 void FileListViewItem::polish(HbStyleParameters& params)
       
   147 {
       
   148     Q_UNUSED(params);
       
   149 }
       
   150 
       
   151 bool FileListViewItem::canSetModelIndex( const QModelIndex &index ) const
       
   152 {
       
   153     Q_UNUSED( index );
       
   154     return true;
       
   155 
       
   156 //  do not used
       
   157 //	const QFileSystemModel *model = dynamic_cast<const QFileSystemModel *>(index.model());
       
   158 //	QFileInfo info = model->fileInfo( index );
       
   159 //	QString path = info.path();
       
   160 
       
   161 //	return (path.right(1) != ":");
       
   162    
       
   163 }
       
   164 
       
   165 
       
   166 HbAbstractViewItem *FileListViewItem::createItem()
       
   167 {
       
   168 	return new FileListViewItem( parentItem() );
       
   169 }
       
   170 
       
   171 void FileListViewItem::updateChildItems()
       
   172 {
       
   173 	QVariant variant = modelIndex().data( Qt::DecorationRole );
       
   174 	QIcon icon = qvariant_cast<QIcon>( variant );
       
   175 	QString diskName = modelIndex().data( Qt::DisplayRole ).toString();
       
   176 
       
   177     QString debugString = "updateChindItems: diskName = " + diskName;
       
   178     FmLogger::log(debugString);
       
   179 	mIconLabel->setIcon( HbIcon( icon ) );
       
   180 	mNameLabel->setPlainText( diskName );
       
   181     mCheckBox->setCheckState( checkState() );
       
   182 }
       
   183 
       
   184 void FileListViewItem::setCheckedState( int state )
       
   185 {
       
   186 	HbAbstractViewItem::setCheckState( static_cast<Qt::CheckState>(state) );
       
   187 }
       
   188 
       
   189 void FileListViewItem::init()
       
   190 {
       
   191 	QGraphicsLinearLayout *hLayout = new QGraphicsLinearLayout();
       
   192 	hLayout->setOrientation( Qt::Horizontal );
       
   193 
       
   194 	mIconLabel = new HbLabel();
       
   195 	mIconLabel->setMinimumWidth(32);
       
   196 	hLayout->addItem( mIconLabel );
       
   197 	hLayout->setAlignment( mIconLabel, Qt::AlignTop );
       
   198 	hLayout->setStretchFactor( mIconLabel, 1 );
       
   199 
       
   200 	mNameLabel = new HbLabel();
       
   201 	mNameLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) );
       
   202 	mNameLabel->setAlignment( Qt::AlignVCenter );
       
   203 	hLayout->addItem( mNameLabel );
       
   204 	hLayout->setAlignment( mNameLabel, Qt::AlignLeft );
       
   205 	hLayout->setStretchFactor( mNameLabel, 20 );
       
   206 
       
   207     mCheckBox = new HbCheckBox( this );
       
   208 	connect( mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setCheckedState(int)) );
       
   209     hLayout->addItem( mCheckBox );
       
   210     hLayout->setAlignment( mCheckBox, Qt::AlignLeft );
       
   211 
       
   212 	setLayout( hLayout );
       
   213 }
       
   214 */