filemanager/src/filemanager/src/fmfindwidget.cpp
changeset 46 d58987eac7e8
parent 16 ada7962b4308
equal deleted inserted replaced
37:15bc28c9dd51 46:d58987eac7e8
    27 
    27 
    28 #include <hblistview.h>
    28 #include <hblistview.h>
    29 #include <hbsearchpanel.h>
    29 #include <hbsearchpanel.h>
    30 #include <hblabel.h>
    30 #include <hblabel.h>
    31 #include <hbwidget.h>
    31 #include <hbwidget.h>
       
    32 #include <hbstackedwidget.h>
    32 
    33 
    33 FmFindWidget::FmFindWidget( QGraphicsItem *parent )
    34 FmFindWidget::FmFindWidget( QGraphicsItem *parent )
    34     : HbWidget( parent )
    35     : HbWidget( parent )
    35 {
    36 {
       
    37     FM_LOG("FmFindWidget::FmFindWidget()");
    36     init();
    38     init();
    37 }
    39 }
    38 
    40 
    39 FmFindWidget::~FmFindWidget()
    41 FmFindWidget::~FmFindWidget()
    40 {
    42 {
       
    43     FM_LOG("FmFindWidget::~FmFindWidget() START");
       
    44     delete mModel;
       
    45     FM_LOG("FmFindWidget::~FmFindWidget() END");
    41 }
    46 }
    42 
    47 
    43 void FmFindWidget::itemActivated(const QModelIndex &index)
    48 void FmFindWidget::itemActivated(const QModelIndex &index)
    44 {   
    49 {   
    45     FmOperationService *operationService = FmViewManager::viewManager()->operationService();
    50     FmOperationService *operationService = FmViewManager::viewManager()->operationService();
    53     }else if( fileInfo.isDir() ) {
    58     }else if( fileInfo.isDir() ) {
    54         emit activated( fileInfo.filePath() );
    59         emit activated( fileInfo.filePath() );
    55     }
    60     }
    56 }
    61 }
    57 
    62 
    58 void FmFindWidget::find( const QString &keyword, const QString &path )
    63 void FmFindWidget::find( const QString &keyword, const QStringList &pathList )
    59 {
    64 {
    60     mModel->setFindPath( path );
    65     mPathList = pathList;
    61     
    66     // find will auto-start after receive criteria change event.
    62     QRegExp regExp( '*' + keyword + '*' );
    67     mSearchPanel->setCriteria( keyword );
    63     regExp.setPatternSyntax( QRegExp::Wildcard );
       
    64     regExp.setCaseSensitivity( Qt::CaseInsensitive );
       
    65     mModel->setPattern( regExp );
       
    66 
       
    67     mModel->find();
       
    68 }
    68 }
    69 
    69 
    70 void FmFindWidget::stopFind()
    70 void FmFindWidget::stopFind()
    71 {
    71 {
    72     mModel->stop();
    72     mModel->stopFind();
    73 }
       
    74 
       
    75 void FmFindWidget::on_resultModel_finished()
       
    76 {
       
    77     emit finished();
       
    78     //Since layout problem is found, refresh it
       
    79     on_resultModel_refresh();  
       
    80 }
    73 }
    81 
    74 
    82 void FmFindWidget::on_resultModel_modelCountChanged( int count )
    75 void FmFindWidget::on_resultModel_modelCountChanged( int count )
    83 {
    76 {
    84     if( count > 0 ) {
    77     if( count > 0 ) {
    85         activateContentWidget( ResultListView );
    78         mContentWidget->setCurrentWidget( mListView );
    86     } else {
    79     } else {
    87         activateContentWidget( EmptyTipWidget );
    80         mContentWidget->setCurrentWidget( mEmptyTipWidget );
    88     }
    81     }
    89 }
    82 }
    90 
    83 
    91 void FmFindWidget::activateContentWidget( ContentWidgetType contentWidgetType )
    84 void FmFindWidget::on_resultModel_findStarted()
    92 {
    85 {
    93     switch( contentWidgetType )
    86     emit setEmptyMenu( true );
    94     {
    87 }
    95     case EmptyTipWidget:
    88 
    96         {
    89 void FmFindWidget::on_resultModel_findFinished()
    97         if( mLayout->count() > 0 ) {
    90 {
    98             if( mLayout->itemAt( 0 ) == mListView ) {
    91     emit setEmptyMenu( false );
    99                 mLayout->removeItem( mListView );
       
   100                 mLayout->addItem( mEmptyTipWidget );
       
   101             } 
       
   102         } else {
       
   103             mLayout->addItem( mEmptyTipWidget );
       
   104         }
       
   105         mListView->hide();
       
   106         mEmptyTipWidget->show();
       
   107         deActiveSearchPanel();
       
   108         emit setEmptyMenu( true );
       
   109         }
       
   110         break;
       
   111     case ResultListView:
       
   112         {
       
   113         if( mLayout->count() > 0 ) {
       
   114             if( mLayout->itemAt( 0 ) == mEmptyTipWidget ) {
       
   115                 mLayout->removeItem( mEmptyTipWidget );
       
   116                 mLayout->addItem( mListView );
       
   117             } 
       
   118         } else {
       
   119             mLayout->addItem( mListView );
       
   120         }
       
   121         mEmptyTipWidget->hide();
       
   122         mListView->show();
       
   123         activeSearchPanel();
       
   124         emit setEmptyMenu( false );
       
   125         }
       
   126         break;
       
   127     }
       
   128 }
    92 }
   129 
    93 
   130 void FmFindWidget::init()
    94 void FmFindWidget::init()
   131 {
    95 {
   132     mLayout = new QGraphicsLinearLayout( this );
    96     mLayout = new QGraphicsLinearLayout( this );
   133     mLayout->setOrientation( Qt::Vertical );
    97     mLayout->setOrientation( Qt::Vertical );
       
    98  
       
    99     mContentWidget = new HbStackedWidget( this );
       
   100     mLayout->addItem( mContentWidget );
       
   101     initSearchPanel();
       
   102     mLayout->addItem( mSearchPanel );
       
   103     setLayout( mLayout );
   134 
   104 
   135     mModel = new FmFindResultModel( this );
   105     mModel = new FmFindResultModel( this );
   136     mModel->setObjectName( "resultModel" );
   106     mModel->setObjectName( "resultModel" );
   137 
   107 
   138     connect( mModel, SIGNAL(finished()), this, SLOT( on_resultModel_finished()) );
   108     connect( mModel, SIGNAL( modelCountChanged( int )),
       
   109         this, SLOT( on_resultModel_modelCountChanged( int )), Qt::QueuedConnection );
   139 
   110 
   140     connect( mModel, SIGNAL( modelCountChanged( int )),
   111     connect( mModel, SIGNAL( findStarteded()),
   141         this, SLOT( on_resultModel_modelCountChanged( int )) );
   112         this, SLOT( on_resultModel_findStarted()) );
       
   113 
       
   114     connect( mModel, SIGNAL( findFinished()),
       
   115         this, SLOT( on_resultModel_findFinished()) );
   142     
   116     
   143     connect( mModel, SIGNAL( refresh()),
       
   144         this, SLOT( on_resultModel_refresh()) );
       
   145 
       
   146     mListView = new HbListView( this );
   117     mListView = new HbListView( this );
   147     mListView->setModel( mModel );
   118     mListView->setModel( mModel );
   148 
   119 
   149     mEmptyTipWidget = new HbWidget( this );
   120     mEmptyTipWidget = new HbWidget( this );
   150     QGraphicsLinearLayout *emptyTipLayout = new QGraphicsLinearLayout( mEmptyTipWidget );
   121     QGraphicsLinearLayout *emptyTipLayout = new QGraphicsLinearLayout( mEmptyTipWidget );
   151     HbLabel *emptyTipLable = new HbLabel( hbTrId( "No found files or folders" ), mEmptyTipWidget );
   122     HbLabel *emptyTipLable = new HbLabel( hbTrId( "No found files or folders" ), mEmptyTipWidget );
   152     emptyTipLayout->addItem( emptyTipLable );
   123     emptyTipLayout->addItem( emptyTipLable );
       
   124     emptyTipLayout->setAlignment( emptyTipLable, Qt::AlignCenter );
       
   125     emptyTipLable->setAlignment( Qt::AlignCenter );
   153  
   126  
   154     initSearchPanel();
   127     mContentWidget->addWidget( mListView );
   155     activateContentWidget( EmptyTipWidget );
   128     mContentWidget->addWidget( mEmptyTipWidget );
   156     
   129     
   157     setLayout( mLayout );
   130     mContentWidget->setCurrentWidget( mEmptyTipWidget );
   158 
       
   159     connect( mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
   131     connect( mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
   160 }
   132 }
   161 
   133 
   162 void FmFindWidget::initSearchPanel()
   134 void FmFindWidget::initSearchPanel()
   163 {
   135 {
   164     mSearchPanel = new HbSearchPanel( this );
   136     mSearchPanel = new HbSearchPanel( this );
   165     mSearchPanel->setObjectName( "searchPanel" );
   137     mSearchPanel->setObjectName( "searchPanel" );
   166 //    mSearchPanel->setSearchOptionsEnabled( true );
   138     mSearchPanel->setSearchOptionsEnabled( false );
   167     mSearchPanel->setProgressive( false );
   139     mSearchPanel->setProgressive( true );
   168     mSearchPanel->hide();
       
   169     
   140     
   170     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
   141     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
   171         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) );
   142         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ), Qt::QueuedConnection  );
   172     
   143     
   173     connect( mSearchPanel, SIGNAL( exitClicked() ),
   144     connect( mSearchPanel, SIGNAL( exitClicked() ),
   174         this, SLOT( on_searchPanel_exitClicked() ) );
   145         this, SLOT( on_searchPanel_exitClicked() ), Qt::QueuedConnection );
   175 }
   146 }
   176 
   147 
   177 void FmFindWidget::sortFiles( FmFindResultModel::SortFlag sortFlag )
   148 void FmFindWidget::sortFiles( FmFindResultModel::SortFlag sortFlag )
   178 {
   149 {
   179     mModel->sort( sortFlag );
   150     mModel->sort( sortFlag );
   180 }
   151 }
   181 
   152 
   182 void FmFindWidget::activeSearchPanel()
       
   183 {
       
   184     mLayout->addItem( mSearchPanel );
       
   185     mSearchPanel->show();
       
   186 }
       
   187 
       
   188 void FmFindWidget::on_searchPanel_criteriaChanged( const QString &criteria )
   153 void FmFindWidget::on_searchPanel_criteriaChanged( const QString &criteria )
   189 {
   154 {
   190     mFindTargetPath.clear();
   155     QRegExp regExp;
   191     emit startSearch( mFindTargetPath, criteria );
   156     if( !criteria.isEmpty() ) {
       
   157         regExp.setPattern( '*' + criteria + '*' );
       
   158     }
       
   159     // if criteria is empty, then keep regExp empty. find thread will return empty result.
       
   160     
       
   161     regExp.setPatternSyntax( QRegExp::Wildcard );
       
   162     regExp.setCaseSensitivity( Qt::CaseInsensitive );
       
   163 
       
   164     mModel->find( regExp, mPathList );
   192 }
   165 }
   193 
   166 
   194 void FmFindWidget::on_searchPanel_exitClicked()
   167 void FmFindWidget::on_searchPanel_exitClicked()
   195 {
   168 {
   196     mSearchPanel->hide();
   169     FmViewManager::viewManager()->popViewAndShow();
   197     mLayout->removeItem( mSearchPanel );
       
   198 }
       
   199 
       
   200 void FmFindWidget::deActiveSearchPanel()
       
   201 {
       
   202     mSearchPanel->hide();
       
   203     mLayout->removeItem( mSearchPanel );
       
   204 
       
   205 }
       
   206 
       
   207 void FmFindWidget::on_resultModel_refresh()
       
   208 {
       
   209     mListView->setModel( 0 );
       
   210     mListView->setModel( mModel );  
       
   211 }
   170 }
   212 
   171 
   213 
   172 
   214 
   173