--- a/filemanager/src/filemanager/src/fmviewmanager.cpp Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/filemanager/src/fmviewmanager.cpp Tue Aug 24 10:24:14 2010 +0800
@@ -28,17 +28,21 @@
#include "fmoperationservice.h"
#include "fmoperationbase.h"
#include "fmdrivewatcher.h"
+#include "fmdialog.h"
+#include "fmdlgutils.h"
#include <hbview.h>
-#include <hbmessagebox.h>
+#include <hbmainwindow.h>
+#include <hbapplication.h>
+#include <hbactivitymanager.h>
#include <QFileSystemWatcher>
#include <QFileInfo>
-#include <hbdialog.h>
+#include <QPixmap>
FmViewManager *FmViewManager::mViewManager = 0;
-FmDlgCloseUnit::FmDlgCloseUnit( HbDialog *dialog ) : mDialog( dialog )
+FmDlgCloseUnit::FmDlgCloseUnit( FmDialog *dialog ) : mDialog( dialog )
{
}
FmDlgCloseUnit::~FmDlgCloseUnit()
@@ -64,20 +68,14 @@
return mAssociatedDrives;
}
-HbDialog *FmDlgCloseUnit::dialog()
+FmDialog *FmDlgCloseUnit::dialog()
{
return mDialog;
}
-FmViewManager::FmViewManager( FmMainWindow* mainWindow )
+FmViewManager::FmViewManager( FmMainWindow* mainWindow ) : mOperationService( 0 )
{
mMainWindow = mainWindow;
- mOperationService = new FmOperationService( this );
- mOperationService->setObjectName( "operationService" );
-
- mFsWatcher = new QFileSystemWatcher( this );
- mFsWatcher->setObjectName( "fsWatcher" );
-
mDriveWatcher = new FmDriveWatcher( this );
mDriveWatcher->setObjectName( "driveWatcher" );
mDriveWatcher->startWatch();
@@ -87,7 +85,6 @@
FmViewManager::~FmViewManager(void)
{
-
FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() );
while( view ) {
mMainWindow->removeView( view );
@@ -97,8 +94,6 @@
delete mOperationService;
mOperationService = 0;
- delete mFsWatcher;
- mFsWatcher = 0;
mDriveWatcher->cancelWatch();
delete mDriveWatcher;
@@ -127,6 +122,10 @@
FmOperationService *FmViewManager::operationService()
{
+ if ( !mOperationService ) {
+ mOperationService = new FmOperationService( this );
+ mOperationService->setObjectName( "operationService" );
+ }
return mOperationService;
}
@@ -134,7 +133,10 @@
{
FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() );
view->setNavigationAction( 0 );
-
+ // grap the screen when only the drive view is in view stack.
+ if( viewCount() == 1 ) {
+ mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect());
+ }
mMainWindow->removeView( view );
delete view;
@@ -144,16 +146,32 @@
}
}
-void FmViewManager::on_operationService_refreshModel( FmOperationBase *operationBase, const QString &path )
+void FmViewManager::on_operationService_driveSpaceChanged( FmOperationBase *operationBase )
{
Q_UNUSED( operationBase );
- emit refreshModel( path );
+ // request drive view to refresh
+ emit driveSpaceChanged();
+}
+
+void FmViewManager::on_operationService_notifyFinish( FmOperationBase *operationBase )
+{
+ if( !operationBase ){
+ Q_ASSERT_X( false, "FmViewManager",
+ "NULL is not accepted in on_operationService_notifyFinish()" );
+ return;
+ }
+
+ if( operationBase->operationType() == FmOperationService::EOperationTypeBackup )
+ {
+ // after finish backup, we need refresh backup date in backup view.
+ emit refreshBackupDate();
+ }
}
int FmViewManager::viewCount()
{
- return mMainWindow->viewCount();
+ return mMainWindow->views().count();
}
@@ -163,9 +181,23 @@
mMainWindow->addView( driverView );
mMainWindow->setCurrentView( driverView );
+ HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
+ bool ok = activityManager->removeActivity("FMMemoryStoragesList");
- connect( this, SIGNAL( refreshModel( QString ) ),
- driverView, SLOT( refreshModel( QString ) ) );
+ connect( this, SIGNAL( driveSpaceChanged() ),
+ driverView, SLOT( refreshDrive() ) );
+ // Refresh drive view when gaining foreground
+ // ( switch back to filemanager from home screen or any other applications )
+ connect( mMainWindow, SIGNAL( revealed() ),
+ driverView, SLOT( refreshDrive() ) );
+
+ // use Qt::QueuedConnection because synchronous refresh is not work well while
+ // connected with another OTG device which have more than one external drive in it.
+ // File server only give driveChanged event once, but two drive is inserted.
+ // Synchronous refresh will miss another drive.
+ // So use Qt::QueuedConnection to performance asynchronous refresh.
+ connect( this, SIGNAL( driveChanged() ),
+ driverView, SLOT( refreshDrive() ), Qt::QueuedConnection );
}
void FmViewManager::createFileView( const QString &path,
@@ -175,15 +207,14 @@
QString absolutePath = fileInfo.absoluteFilePath();
QString checkedPath = FmUtils::checkDriveToFolderFilter( absolutePath );
- FmDriverInfo::DriveState driveState = FmUtils::queryDriverInfo( path ).driveState();
- if( driveState & FmDriverInfo::EDriveAvailable ) {
- if( !FmUtils::isPathAccessabel( checkedPath ) ) {
+ if( FmUtils::isDriveAvailable( path ) ) {
+ if( FmErrNone != FmUtils::isPathAccessabel( checkedPath ) ) {
checkedPath.clear();
}
}
if( checkedPath.isEmpty() ) {
- HbMessageBox::information( QString( hbTrId("Path: %1 is unavailable!").arg( path )) );
+ FmDlgUtils::information( QString( hbTrId("Path: %1 is unavailable!").arg( path )) );
return;
}
@@ -198,8 +229,8 @@
mMainWindow->addView( fileView );
mMainWindow->setCurrentView( fileView );
- connect( this, SIGNAL( refreshModel( const QString& ) ), //emit when need refresh models
- fileView, SLOT( refreshModel( const QString& ) ) );
+ connect( this, SIGNAL( driveChanged() ), //emit when drive changed.
+ fileView, SLOT( on_driveChanged() ) );
connect( fileView, SIGNAL( popViewAndShow() ), //emit when fileView need delete itself and pop&show view from stack.
this, SLOT( popViewAndShow() ), Qt::QueuedConnection );
@@ -229,7 +260,10 @@
mMainWindow->addView( backupView );
mMainWindow->setCurrentView( backupView );
-
+ connect( this, SIGNAL( driveChanged() ), //emit when need refresh model
+ backupView, SLOT( refreshModel() ) );
+ connect( this, SIGNAL( refreshBackupDate() ), //emit when need refresh backup date
+ backupView, SLOT( refreshBackupDate() ) );
}
void FmViewManager::createRestoreView()
@@ -238,6 +272,7 @@
mMainWindow->addView( restoreView );
mMainWindow->setCurrentView( restoreView );
+ connect( this, SIGNAL( driveChanged() ), restoreView, SLOT( refreshRestoreView() ) );
}
@@ -247,6 +282,7 @@
mMainWindow->addView( deleteBackupView );
mMainWindow->setCurrentView( deleteBackupView );
+ connect( this, SIGNAL( driveChanged() ), deleteBackupView, SLOT( refreshDeleteBackupView() ) );
}
@@ -254,33 +290,12 @@
return mMainWindow->orientation();
}
-void FmViewManager::on_fsWatcher_fileChanged(const QString &path)
-{
- emit refreshModel( path );
-}
-void FmViewManager::on_fsWatcher_directoryChanged(const QString &path)
-{
- emit refreshModel( path );
-}
-void FmViewManager::addWatchPath( const QString &path )
-{
- mFsWatcher->addPath( path );
-}
-void FmViewManager::removeWatchPath( const QString &path )
-{
- if( !mViewManager || !mFsWatcher ) {
- return;
- }
- mFsWatcher->removePath( path );
-}
-
-
void FmViewManager::on_driveWatcher_driveAddedOrChanged()
{
- FmLogger::log( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged start" ) );
- emit refreshModel( QString("") );
+ FM_LOG( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged start" ) );
+ emit driveChanged();
checkDlgCloseUnit();
- FmLogger::log( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged end" ) );
+ FM_LOG( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged end" ) );
}
@@ -292,10 +307,39 @@
for( int i = 0; i < drives.length(); i++ ) {
QString drive( drives[i] + QString( ":/" ) );
if( !FmUtils::isDriveAvailable( drive ) ) {
- FmLogger::log( " close Dialog start " );
+ FM_LOG( " close Dialog start " );
unit->dialog()->close();
- FmLogger::log( " close Dialog end " );
+ FM_LOG( " close Dialog end " );
}
}
}
}
+
+void FmViewManager::saveActivity()
+{
+ //grap the screen when current view is drive view.
+ FmDriverView *driveView = qobject_cast<FmDriverView *>(mMainWindow->currentView());
+ if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) {
+ mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect());
+ }
+ QVariantHash metadata;
+ metadata.insert("screenshot", mScreenShot);
+ HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
+ // add the activity to the activity manager
+ bool ok = activityManager->addActivity("FMMemoryStoragesList", QVariant(), metadata);
+ if ( !ok )
+ {
+ qFatal("Add failed" );
+ }
+
+}
+
+void FmViewManager::onAboutToChangeView(HbView * oldView, HbView *newView)
+{
+ Q_UNUSED(newView);
+ //grap the screen when oldView is drive view.
+ FmDriverView *driveView = qobject_cast<FmDriverView *>(oldView);
+ if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) {
+ mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect());
+ }
+}