filemanager/src/filemanager/src/fmfindwidget.cpp
branchRCL_3
changeset 20 491b3ed49290
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
       
     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 * 
       
    15 * Description:
       
    16 *     The source file of the file find widget of file manager
       
    17 *
       
    18 */
       
    19 
       
    20 #include "fmfindwidget.h"
       
    21 #include "fmfindresultmodel.h"
       
    22 #include "fmviewmanager.h"
       
    23 #include "fmoperationservice.h"
       
    24 
       
    25 #include <QGraphicsLinearLayout>
       
    26 #include <QFileInfo>
       
    27 
       
    28 #include <hblistview.h>
       
    29 #include <hbsearchpanel.h>
       
    30 #include <hblabel.h>
       
    31 #include <hbwidget.h>
       
    32 
       
    33 FmFindWidget::FmFindWidget( QGraphicsItem *parent )
       
    34     : HbWidget( parent )
       
    35 {
       
    36     init();
       
    37 }
       
    38 
       
    39 FmFindWidget::~FmFindWidget()
       
    40 {
       
    41 }
       
    42 
       
    43 void FmFindWidget::itemActivated(const QModelIndex &index)
       
    44 {   
       
    45     FmOperationService *operationService = FmViewManager::viewManager()->operationService();
       
    46     if( !operationService ) {
       
    47         return;
       
    48     }
       
    49 
       
    50     QFileInfo fileInfo = mModel->fileInfo( index );
       
    51     if ( fileInfo.isFile() ) {
       
    52         operationService->syncLaunchFileOpen( fileInfo.filePath() );
       
    53     }else if( fileInfo.isDir() ) {
       
    54         emit activated( fileInfo.filePath() );
       
    55     }
       
    56 }
       
    57 
       
    58 void FmFindWidget::find( const QString &keyword, const QString &path )
       
    59 {
       
    60     mModel->setFindPath( path );
       
    61     
       
    62     QRegExp regExp( '*' + keyword + '*' );
       
    63     regExp.setPatternSyntax( QRegExp::Wildcard );
       
    64     regExp.setCaseSensitivity( Qt::CaseInsensitive );
       
    65     mModel->setPattern( regExp );
       
    66 
       
    67     mModel->find();
       
    68 }
       
    69 
       
    70 void FmFindWidget::stopFind()
       
    71 {
       
    72     mModel->stop();
       
    73 }
       
    74 
       
    75 void FmFindWidget::on_resultModel_finished()
       
    76 {
       
    77     emit finished();
       
    78 }
       
    79 
       
    80 void FmFindWidget::on_resultModel_modelCountChanged( int count )
       
    81 {
       
    82     if( count > 0 ) {
       
    83         activateContentWidget( ResultListView );
       
    84     } else {
       
    85         activateContentWidget( EmptyTipWidget );
       
    86     }
       
    87 }
       
    88 
       
    89 void FmFindWidget::activateContentWidget( ContentWidgetType contentWidgetType )
       
    90 {
       
    91     switch( contentWidgetType )
       
    92     {
       
    93     case EmptyTipWidget:
       
    94         {
       
    95         if( mLayout->count() > 0 ) {
       
    96             if( mLayout->itemAt( 0 ) == mListView ) {
       
    97                 mLayout->removeItem( mListView );
       
    98                 mLayout->addItem( mEmptyTipWidget );
       
    99             } 
       
   100         } else {
       
   101             mLayout->addItem( mEmptyTipWidget );
       
   102         }
       
   103         mListView->hide();
       
   104         mEmptyTipWidget->show();
       
   105         deActiveSearchPanel();
       
   106         emit setEmptyMenu( true );
       
   107         }
       
   108         break;
       
   109     case ResultListView:
       
   110         {
       
   111         if( mLayout->count() > 0 ) {
       
   112             if( mLayout->itemAt( 0 ) == mEmptyTipWidget ) {
       
   113                 mLayout->removeItem( mEmptyTipWidget );
       
   114                 mLayout->addItem( mListView );
       
   115             } 
       
   116         } else {
       
   117             mLayout->addItem( mListView );
       
   118         }
       
   119         mEmptyTipWidget->hide();
       
   120         mListView->show();
       
   121         activeSearchPanel();
       
   122         emit setEmptyMenu( false );
       
   123         }
       
   124         break;
       
   125     }
       
   126 }
       
   127 
       
   128 void FmFindWidget::init()
       
   129 {
       
   130     mLayout = new QGraphicsLinearLayout( this );
       
   131     mLayout->setOrientation( Qt::Vertical );
       
   132 
       
   133     mModel = new FmFindResultModel( this );
       
   134     mModel->setObjectName( "resultModel" );
       
   135 
       
   136     connect( mModel, SIGNAL(finished()), this, SLOT( on_resultModel_finished()) );
       
   137 
       
   138     connect( mModel, SIGNAL( modelCountChanged( int )),
       
   139         this, SLOT( on_resultModel_modelCountChanged( int )) );
       
   140     
       
   141     mListView = new HbListView( this );
       
   142     mListView->setModel( mModel );
       
   143 
       
   144     mEmptyTipWidget = new HbWidget( this );
       
   145     QGraphicsLinearLayout *emptyTipLayout = new QGraphicsLinearLayout( mEmptyTipWidget );
       
   146     HbLabel *emptyTipLable = new HbLabel( hbTrId( "No found files or folders" ), mEmptyTipWidget );
       
   147     emptyTipLayout->addItem( emptyTipLable );
       
   148  
       
   149     initSearchPanel();
       
   150     activateContentWidget( EmptyTipWidget );
       
   151     
       
   152     setLayout( mLayout );
       
   153 
       
   154     connect( mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
       
   155 }
       
   156 
       
   157 void FmFindWidget::initSearchPanel()
       
   158 {
       
   159     mSearchPanel = new HbSearchPanel( this );
       
   160     mSearchPanel->setObjectName( "searchPanel" );
       
   161 //    mSearchPanel->setSearchOptionsEnabled( true );
       
   162     mSearchPanel->setProgressive( false );
       
   163     mSearchPanel->hide();
       
   164     
       
   165     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
       
   166         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) );
       
   167     
       
   168     connect( mSearchPanel, SIGNAL( exitClicked() ),
       
   169         this, SLOT( on_searchPanel_exitClicked() ) );
       
   170 }
       
   171 
       
   172 void FmFindWidget::sortFiles( FmFindResultModel::SortFlag sortFlag )
       
   173 {
       
   174     mModel->sort( sortFlag );
       
   175 }
       
   176 
       
   177 void FmFindWidget::activeSearchPanel()
       
   178 {
       
   179     mLayout->addItem( mSearchPanel );
       
   180     mSearchPanel->show();
       
   181 }
       
   182 
       
   183 void FmFindWidget::on_searchPanel_criteriaChanged( const QString &criteria )
       
   184 {
       
   185     mFindTargetPath.clear();
       
   186     emit startSearch( mFindTargetPath, criteria );
       
   187 }
       
   188 
       
   189 void FmFindWidget::on_searchPanel_exitClicked()
       
   190 {
       
   191     mSearchPanel->hide();
       
   192     mLayout->removeItem( mSearchPanel );
       
   193 }
       
   194 
       
   195 void FmFindWidget::deActiveSearchPanel()
       
   196 {
       
   197     mSearchPanel->hide();
       
   198     mLayout->removeItem( mSearchPanel );
       
   199 
       
   200 }
       
   201 
       
   202 
       
   203