filebrowser/ui/src/enginewrapper.cpp
changeset 55 2d9cac8919d3
parent 53 819e59dfc032
child 56 392f7045e621
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
     1 /*
       
     2 * Copyright (c) 2010 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 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "enginewrapper.h"
       
    19 #include "engine.h"
       
    20 #include "FBFileUtils.h"
       
    21 #include "notifications.h"
       
    22 #include "fbfileview.h"
       
    23 #include "fbsearchview.h"
       
    24 #include "filebrowsersettings.h"
       
    25 //#include "fbsettingsview.h"
       
    26 
       
    27 #include <HbProgressDialog>
       
    28 
       
    29 #include <QString>
       
    30 #include <QFileInfo>
       
    31 #include <QModelIndex>
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 
       
    35 EngineWrapper::EngineWrapper()
       
    36     : mEngine(0),
       
    37     mFilesFound(),
       
    38     mSettings(0),
       
    39     mProgressDialog(0),
       
    40     mWaitDialog(0)
       
    41 {
       
    42 }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 
       
    46 EngineWrapper::~EngineWrapper()
       
    47 {
       
    48     if(mEngine != NULL) {
       
    49         TRAP_IGNORE(mEngine->DeActivateEngineL());
       
    50         delete mEngine;
       
    51     } 
       
    52     if (mProgressDialog)
       
    53         delete mProgressDialog;
       
    54 
       
    55     if (mWaitDialog)
       
    56         delete mWaitDialog;
       
    57 }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 
       
    61 bool EngineWrapper::init()
       
    62 {
       
    63     TRAPD(err, mEngine = CEngine::NewL(this));
       
    64     if (err != KErrNone) {
       
    65         return false;
       
    66     } else {
       
    67         TRAP_IGNORE(mEngine->ActivateEngineL());
       
    68         mSettings = FileBrowserSettings(&mEngine->Settings());
       
    69         return true;
       
    70     }
       
    71 }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Functions that are called from UI
       
    75 // ---------------------------------------------------------------------------
       
    76 bool EngineWrapper::searchFiles()
       
    77 {
       
    78     TRAPD(err, mEngine->SearchL() );
       
    79     if(err != KErrNone) {
       
    80         return false;
       
    81     }
       
    82     else {
       
    83         return true;
       
    84     }
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 SearchAttributes EngineWrapper::getFileSearchAttributes()
       
    89 {
       
    90     TSearchAttributes tAttributes = mEngine->GetSearchAttributes();
       
    91     SearchAttributes attributes;
       
    92 
       
    93     // Convert TSearchAttributes to SearchAttributes 
       
    94     attributes.mSearchDir  = QString((QChar*)tAttributes.iSearchDir.Ptr(),tAttributes.iSearchDir.Length());
       
    95     attributes.mWildCards  = QString((QChar*)tAttributes.iWildCards.Ptr(),tAttributes.iWildCards.Length()); 
       
    96     attributes.mTextInFile = QString((QChar*)tAttributes.iTextInFile.Ptr(),tAttributes.iTextInFile.Length()); 
       
    97     attributes.mMinSize    = tAttributes.iMinSize;
       
    98     attributes.mMaxSize    = tAttributes.iMaxSize;
       
    99     attributes.mRecurse    = tAttributes.iRecurse;
       
   100     attributes.mDefaultWildCard = tAttributes.iDefaultWildCard;
       
   101     
       
   102     // TTime to QDate
       
   103     TBuf<20> timeString;
       
   104     _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3");
       
   105     TRAP_IGNORE( tAttributes.iMinDate.FormatL(timeString, KDateString) );
       
   106     QString temp = QString::fromUtf16(timeString.Ptr(), timeString.Length());
       
   107     temp.replace(QChar('/'), QChar('-'));
       
   108     attributes.mMinDate = QDate::fromString(temp, "dd-MM-yyyy");
       
   109     
       
   110     
       
   111     TRAP_IGNORE( tAttributes.iMaxDate.FormatL(timeString, KDateString) );
       
   112     temp = QString::fromUtf16(timeString.Ptr(), timeString.Length());
       
   113     temp.replace(QChar('/'), QChar('-'));
       
   114     attributes.mMaxDate = QDate::fromString(temp, "dd-MM-yyyy");
       
   115     
       
   116     return attributes;
       
   117 
       
   118 }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 int EngineWrapper::setFileSearchAttributes(SearchAttributes attributes)
       
   122 {
       
   123     TSearchAttributes tAttributes;
       
   124     // Convert SearchAttributes to TSearchAttributes 
       
   125     
       
   126     //convert QString to TFilename:
       
   127     tAttributes.iSearchDir = TFileName(attributes.mSearchDir.utf16());
       
   128     tAttributes.iWildCards = TFileName(attributes.mWildCards.utf16());
       
   129     tAttributes.iTextInFile = TFileName(attributes.mTextInFile.utf16());
       
   130     
       
   131     tAttributes.iMinSize    = attributes.mMinSize;
       
   132     tAttributes.iMaxSize    = attributes.mMaxSize;    
       
   133     tAttributes.iRecurse    = attributes.mRecurse;
       
   134     tAttributes.iDefaultWildCard = attributes.mDefaultWildCard;
       
   135     
       
   136     // QDate to TTime for both min- and max Date
       
   137     QString temp = attributes.mMinDate.toString("yyyy-MM-dd");
       
   138     QStringList dateList = temp.split("-");
       
   139     int month = dateList[1].toInt() - 1;
       
   140     int day = dateList[2].toInt() - 1;
       
   141     temp = dateList[0];
       
   142     if (month == 0) {
       
   143         temp.append("00");
       
   144     }
       
   145     else {
       
   146         temp.append(QString::number(month));
       
   147     }
       
   148     if (day == 0) {
       
   149         temp.append("00");
       
   150     }
       
   151     else { 
       
   152         temp.append(QString::number(day));
       
   153     }
       
   154     temp.append(":");
       
   155         
       
   156     TBuf<24> dateString(temp.utf16());
       
   157     tAttributes.iMinDate.Set(dateString);
       
   158     
       
   159     temp = attributes.mMaxDate.toString("yyyy-MM-dd");
       
   160     dateList = temp.split("-");
       
   161     month = dateList[1].toInt() - 1;
       
   162     day = dateList[2].toInt() - 1;
       
   163     temp = dateList[0];
       
   164     if (month == 0) {
       
   165         temp.append("00");
       
   166     }
       
   167     else {
       
   168         temp.append(QString::number(month));
       
   169     }
       
   170     if (day == 0) {
       
   171         temp.append("00");
       
   172     }
       
   173     else { 
       
   174         temp.append(QString::number(day));
       
   175     }
       
   176     temp.append(":");
       
   177     dateString.Copy(temp.utf16());
       
   178     tAttributes.iMaxDate.Set(dateString);
       
   179     
       
   180     mEngine->ChangeAttributes(tAttributes);
       
   181     return KErrNone;
       
   182 }
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 SearchResults EngineWrapper::getSearchResults()
       
   187 {
       
   188     TSearchResults tResults = mEngine->SearchResults();
       
   189     SearchResults results;
       
   190     results.mNumberOfFoundFiles = tResults.iNumberOfFoundFiles;
       
   191     CFileEntryList* foundFilesResult = mEngine->FoundFiles();
       
   192     if (!mFilesFound.isEmpty()) {
       
   193         mFilesFound.clear();
       
   194         }
       
   195     // copy file names and convert them from TFileName format to QStringList items type
       
   196     for (int i = 0; i < foundFilesResult->Count(); i++) {
       
   197             mFilesFound.append(
       
   198                     QString((QChar*)foundFilesResult->At(i).iFullName.Ptr(), 
       
   199                     foundFilesResult->At(i).iFullName.Length()) 
       
   200                     );
       
   201         }
       
   202     results.mFoundFilesList = &mFilesFound;
       
   203     return results;
       
   204 }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 
       
   208 void EngineWrapper::saveSettings(bool aNotifyModules)
       
   209 {
       
   210     return mEngine->SaveSettingsL(aNotifyModules);;
       
   211 }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 
       
   215 bool EngineWrapper::isDriveListViewActive()
       
   216 {
       
   217     // TODO check return value
       
   218     if (mEngine->FileUtils() && mEngine->FileUtils()->IsDriveListViewActive()) {
       
   219         return true;
       
   220     } else {
       
   221         return false;
       
   222     }
       
   223 }
       
   224 
       
   225 bool EngineWrapper::isCurrentDriveReadOnly()
       
   226 {
       
   227     // TODO check return value
       
   228     if (mEngine->FileUtils() && mEngine->FileUtils()->IsCurrentDriveReadOnly()) {
       
   229         return true;
       
   230     } else {
       
   231         return false;
       
   232     }
       
   233 }
       
   234 
       
   235 bool EngineWrapper::isClipBoardListInUse()
       
   236 {
       
   237     if (mEngine->FileUtils() && mEngine->FileUtils()->ClipBoardList() && mEngine->FileUtils()->ClipBoardList()->Count() != 0)
       
   238         return true;
       
   239     else
       
   240         return false;
       
   241 }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 void EngineWrapper::startExecutingCommands(const QString &aCommandsExecutionMessage)
       
   245 {
       
   246     TPtrC commandsExecutionMessage(reinterpret_cast<const TText*>(aCommandsExecutionMessage.constData()));
       
   247     TRAPD(err, mEngine->FileUtils()->StartExecutingCommandsL(commandsExecutionMessage) );
       
   248     Q_UNUSED(err); //TODO
       
   249 }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 
       
   253 void EngineWrapper::refreshView()
       
   254 {
       
   255     if (mEngine->FileUtils()) {
       
   256         TRAPD(err, mEngine->FileUtils()->RefreshViewL() );
       
   257         Q_UNUSED(err); //TODO
       
   258     }
       
   259 }
       
   260 
       
   261 void EngineWrapper::moveUpOneLevel()
       
   262 {
       
   263     if (mEngine->FileUtils()) {
       
   264         TRAPD(err, mEngine->FileUtils()->MoveUpOneLevelL() );
       
   265         Q_UNUSED(err); //TODO
       
   266     }
       
   267 }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 
       
   271 void EngineWrapper::moveDownToDirectory(const QModelIndex& aIndex)
       
   272 {
       
   273     if (mEngine->FileUtils()) {
       
   274         TRAPD(err, mEngine->FileUtils()->MoveDownToDirectoryL(aIndex.row()) );
       
   275         Q_UNUSED(err); //TODO
       
   276     }
       
   277 }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 
       
   281 int EngineWrapper::clipboardCut(const QModelIndexList& aSelectionIndices)
       
   282 {
       
   283     TInt operations = 0;
       
   284     const CArrayFix<TInt> *selectionIndexes = convertSelectionList(aSelectionIndices);
       
   285     if (mEngine->FileUtils()) {
       
   286         TRAPD(err, operations = mEngine->FileUtils()->ClipboardCutL(selectionIndexes) );
       
   287         Q_UNUSED(err); //TODO
       
   288     }
       
   289     delete selectionIndexes;
       
   290     return operations;
       
   291 }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 int EngineWrapper::clipboardCopy(const QModelIndexList& aSelectionIndices)
       
   295 {
       
   296     TInt operations = 0;
       
   297     const CArrayFix<TInt> *selectionIndexes = convertSelectionList(aSelectionIndices);
       
   298 
       
   299     if (mEngine->FileUtils()) {
       
   300         TRAPD(err, operations = mEngine->FileUtils()->ClipboardCopyL(selectionIndexes));
       
   301         Q_UNUSED(err); //TODO
       
   302     }
       
   303     delete selectionIndexes;
       
   304     return operations;
       
   305 }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 
       
   309 void EngineWrapper::clipboardPaste(const OverwriteOptions &aOverwriteOptions)
       
   310 {
       
   311     TOverwriteOptions tOverwriteOptions = convertOverwriteOptions(aOverwriteOptions);
       
   312     if (mEngine->FileUtils()) {
       
   313         TRAPD(err, mEngine->FileUtils()->ClipboardPasteL(tOverwriteOptions));
       
   314         Q_UNUSED(err); //TODO
       
   315     }
       
   316 }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 
       
   320 void EngineWrapper::copyToFolder(const QString &aTargetDir, const OverwriteOptions &aOverwriteOptions, bool aMove)
       
   321 {
       
   322     TFileName targetDir = TFileName(aTargetDir.utf16());
       
   323     TOverwriteOptions tOverwriteOptions = convertOverwriteOptions(aOverwriteOptions);
       
   324 
       
   325 
       
   326     TRAPD(err, mEngine->FileUtils()->CopyToFolderL(targetDir, tOverwriteOptions, aMove ? ETrue : EFalse) );
       
   327     Q_UNUSED(err); //TODO
       
   328 }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 
       
   332 void EngineWrapper::createNewFile(const QString &aNewFileName)
       
   333 {
       
   334     TFileName fileName = TFileName(aNewFileName.utf16());
       
   335     TRAPD(err, mEngine->FileUtils()->NewFileL(fileName) );
       
   336     Q_UNUSED(err); //TODO
       
   337 }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 
       
   341 void EngineWrapper::createNewDirectory(const QString &aNewDirectoryName)
       
   342 {
       
   343     TFileName newDirectoryName = TFileName(aNewDirectoryName.utf16());
       
   344     TRAPD(err, mEngine->FileUtils()->NewDirectoryL(newDirectoryName) );
       
   345     Q_UNUSED(err); //TODO
       
   346 }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 
       
   350 void EngineWrapper::deleteItems(const QModelIndexList& aSelectionIndices)
       
   351 {
       
   352     setCurrentSelection(aSelectionIndices);
       
   353     TRAPD(err, mEngine->FileUtils()->DeleteL() );
       
   354     Q_UNUSED(err); //TODO
       
   355 }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 bool EngineWrapper::selectionHasDirs()
       
   359 {
       
   360     return mEngine->FileUtils()->SelectionHasDirs();
       
   361 }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 
       
   365 void EngineWrapper::rename(const QModelIndex& aIndex, const QString aNewName)
       
   366 {
       
   367     if (mEngine->FileUtils()) {
       
   368         const TFileName newName = TFileName(aNewName.utf16());
       
   369         TRAPD(err, mEngine->FileUtils()->RenameL(aIndex.row(), newName) );
       
   370         Q_UNUSED(err); //TODO
       
   371     }
       
   372 }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 
       
   376 void EngineWrapper::touch(bool aRecurse)
       
   377 {
       
   378     if (mEngine->FileUtils()) {
       
   379         TRAPD(err, mEngine->FileUtils()->TouchL(aRecurse) );
       
   380         Q_UNUSED(err); //TODO
       
   381     }
       
   382 }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 
       
   386 void EngineWrapper::properties(const QModelIndex &aCurrentItemIndex, QStringList &aPropertyList, QString &aTitleText)
       
   387 {
       
   388     if (mEngine->FileUtils()) {
       
   389 
       
   390         // create an array for the items
       
   391         CDesCArray* entryLines = new(ELeave) CDesCArrayFlat(16);
       
   392 //        CleanupStack::PushL(entryLines);
       
   393         TFileName titleText;
       
   394 
       
   395         TRAPD(err, mEngine->FileUtils()->PropertiesL(aCurrentItemIndex.row(), entryLines, titleText));
       
   396         Q_UNUSED(err); //TODO
       
   397 
       
   398         aTitleText = QString::fromUtf16(titleText.Ptr(), titleText.Length());
       
   399         QString textItem;
       
   400         for (TInt i = 0; i < entryLines->Count(); ++i) {
       
   401             textItem = QString::fromUtf16((*entryLines)[i].Ptr(), (*entryLines)[i].Length());
       
   402             aPropertyList.append(textItem);
       
   403         }
       
   404 //        CleanupStack::PopAndDestroy(); //entryLines
       
   405         delete entryLines;
       
   406     }
       
   407 }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 
       
   411 void EngineWrapper::setAttributes(quint32 &setAttributesMask, quint32 &clearAttributesMask, bool &recurse)
       
   412 {
       
   413     if (mEngine->FileUtils()) {
       
   414         TBool tRecurse = recurse ? ETrue : EFalse;
       
   415         TRAPD(err, mEngine->FileUtils()->SetAttributesL(setAttributesMask, clearAttributesMask, tRecurse));
       
   416         Q_UNUSED(err); //TODO
       
   417     }
       
   418 }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 
       
   422 bool EngineWrapper::openAppArc(QString fileName)
       
   423 {
       
   424 
       
   425     //convert QString to TFilename:
       
   426     fileName.replace("/", "\\");
       
   427     TFileName fileToOpen = TFileName(fileName.utf16());
       
   428 
       
   429     TRAPD(err, mEngine->OpenWithApparcL(fileToOpen) );
       
   430     if(err != KErrNone) {
       
   431         return false;
       
   432     } else {
       
   433         return true;
       
   434     }
       
   435 }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 
       
   439 bool EngineWrapper::openDocHandler(QString fileName, bool embeddedVal)
       
   440 {
       
   441     //convert QString to TFilename:
       
   442     fileName.replace("/", "\\");
       
   443     TFileName fileToOpen = TFileName(fileName.utf16());
       
   444 
       
   445     TRAPD(err, mEngine->OpenWithDocHandlerL(fileToOpen, embeddedVal) );
       
   446     if(err != KErrNone) {
       
   447         return false;
       
   448     } else {
       
   449         return true;
       
   450     }
       
   451 }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 
       
   455 int EngineWrapper::itemCount() const
       
   456 {
       
   457     if (mEngine->FileUtils()->IsDriveListViewActive()) {
       
   458         return mEngine->FileUtils()->DriveEntries()->Count();
       
   459     } else {
       
   460         return mEngine->FileUtils()->FileEntries()->Count();
       
   461     }
       
   462 }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 
       
   466 FbDriveEntry EngineWrapper::getDriveEntry(const QModelIndex& aIndex) const
       
   467 {
       
   468     TDriveEntry driveEntry;
       
   469     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0) {
       
   470         driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   471     }
       
   472     return FbDriveEntry(driveEntry);
       
   473 }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 
       
   477 FbFileEntry EngineWrapper::getFileEntry(const QModelIndex& aIndex) const
       
   478 {
       
   479     TFileEntry fileEntry;
       
   480     if (mEngine->FileUtils()->FileEntries()->Count() > aIndex.row() && aIndex.row() >= 0) {
       
   481         fileEntry = mEngine->FileUtils()->FileEntries()->At(aIndex.row());
       
   482     }
       
   483     return FbFileEntry(fileEntry);
       
   484 }
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 
       
   488 const CArrayFix<TInt> *EngineWrapper::convertSelectionList(const QModelIndexList &aSelectionIndices)
       
   489 {
       
   490     CArrayFixFlat<TInt>* selectionIndexes = 0;
       
   491     TRAPD(err, selectionIndexes = new(ELeave)CArrayFixFlat<TInt>(4));
       
   492     if (err != KErrNone) {
       
   493         return 0;
       
   494     }
       
   495 
       
   496     for (int i=0; i< aSelectionIndices.count(); ++i) {
       
   497         TRAPD(err, selectionIndexes->AppendL(aSelectionIndices.at(i).row()) );
       
   498         Q_UNUSED(err); //TODO
       
   499     }
       
   500     return selectionIndexes;
       
   501 }
       
   502 
       
   503 
       
   504 // ---------------------------------------------------------------------------
       
   505 
       
   506 void EngineWrapper::setCurrentSelection(const QModelIndexList &aSelectionIndices)
       
   507 {
       
   508     const CArrayFix<TInt> *selectionIndexes = convertSelectionList(aSelectionIndices);
       
   509     mEngine->FileUtils()->SetCurrentSelection(selectionIndexes);
       
   510     delete selectionIndexes;
       
   511 }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 
       
   515 bool EngineWrapper::isDestinationEntriesExists(const QModelIndexList &aSelectionIndices, QString aTargetDir)
       
   516 {
       
   517     TFileName targetDir = TFileName(aTargetDir.utf16());
       
   518     //setCurrentSelection(aSelectionIndices);
       
   519     Q_UNUSED(aSelectionIndices);
       
   520 
       
   521     TBool someEntryExists = mEngine->FileUtils()->IsDestinationEntriesExists(targetDir);
       
   522     return someEntryExists;
       
   523 }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 bool EngineWrapper::targetExists(const QModelIndex& aIndex, const QString aNewName)
       
   527 {
       
   528     const TFileName newName = TFileName(aNewName.utf16());
       
   529     return mEngine->FileUtils()->TargetExists(aIndex.row(), newName);
       
   530 }
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 
       
   534 QString EngineWrapper::currentPath() const
       
   535 {
       
   536     return QString::fromUtf16(mEngine->FileUtils()->CurrentPath().Ptr(),
       
   537                               mEngine->FileUtils()->CurrentPath().Length());
       
   538 }
       
   539 
       
   540 TOverwriteOptions EngineWrapper::convertOverwriteOptions(const OverwriteOptions &aOverwriteOptions)
       
   541 {
       
   542     TOverwriteOptions tOverwriteOptions;
       
   543     tOverwriteOptions.iDoFileOperations = aOverwriteOptions.doFileOperations;
       
   544     tOverwriteOptions.iQueryIndex = aOverwriteOptions.queryIndex;
       
   545     tOverwriteOptions.iPostFix = TFileName(aOverwriteOptions.postFix.utf16());
       
   546     tOverwriteOptions.iOverWriteFlags = aOverwriteOptions.overWriteFlags;
       
   547     return tOverwriteOptions;
       
   548 }
       
   549 
       
   550 bool EngineWrapper::hasDrivePassword(const QModelIndex &aIndex)
       
   551 {
       
   552     bool hasPassword = false;
       
   553     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   554     {
       
   555         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   556         hasPassword = driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttHasPassword;
       
   557     }
       
   558     return hasPassword;
       
   559 }
       
   560 
       
   561 bool EngineWrapper::isDriveRemovable(const QModelIndex &aIndex)
       
   562 {
       
   563     bool isRemovable = false;
       
   564     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   565     {
       
   566         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   567         isRemovable = driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable;
       
   568     }
       
   569     return isRemovable;
       
   570 }
       
   571 
       
   572 bool EngineWrapper::isDriveLocked(const QModelIndex &aIndex)
       
   573 {
       
   574     bool isRemovable = false;
       
   575     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   576     {
       
   577         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   578         isRemovable = driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked;
       
   579     }
       
   580     return isRemovable;
       
   581 }
       
   582 
       
   583 void EngineWrapper::GetDriveName(const QModelIndex &aIndex, QString &aDriveName)
       
   584 {
       
   585     TFileName driveName;
       
   586     mEngine->FileUtils()->GetDriveName(aIndex.row(), driveName);
       
   587     aDriveName = QString::fromUtf16(driveName.Ptr(), driveName.Length());
       
   588 }
       
   589 
       
   590 
       
   591 void EngineWrapper::GetDriveVolumeLabel(const QModelIndex &aIndex, QString &aVolumeLabel)
       
   592 {
       
   593     TFileName volumeLabel;
       
   594     mEngine->FileUtils()->GetDriveName(aIndex.row(), volumeLabel);
       
   595     aVolumeLabel = QString::fromUtf16(volumeLabel.Ptr(), volumeLabel.Length());
       
   596 }
       
   597 
       
   598 void EngineWrapper::DiskAdminSetDrivePassword(const QModelIndex &aIndex,
       
   599                                               const QString &aOldPassword,
       
   600                                               const QString &aNewPassword)
       
   601 {
       
   602     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   603     TFileName newPassword = TFileName(aNewPassword.utf16());
       
   604     TRAP_IGNORE(mEngine->FileUtils()->SetDrivePasswordL(aIndex.row(), oldPassword, newPassword));
       
   605 }
       
   606 
       
   607 void EngineWrapper::DiskAdminUnlockDrive(const QModelIndex &aIndex, const QString &aOldPassword)
       
   608 {
       
   609     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   610     TRAP_IGNORE(mEngine->FileUtils()->UnlockDriveL(aIndex.row(), oldPassword));
       
   611 }
       
   612 
       
   613 void EngineWrapper::DiskAdminClearDrivePassword(const QModelIndex &aIndex, const QString &aOldPassword)
       
   614 {
       
   615     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   616     TRAP_IGNORE(mEngine->FileUtils()->ClearDrivePasswordL(aIndex.row(), oldPassword));
       
   617 }
       
   618 
       
   619 void EngineWrapper::DiskAdminEraseDrivePassword(const QModelIndex &aIndex)
       
   620 {
       
   621     TRAP_IGNORE(mEngine->FileUtils()->EraseDrivePasswordL(aIndex.row()));
       
   622 }
       
   623 
       
   624 void EngineWrapper::DiskAdminFormatDrive(const QModelIndex &aIndex, bool aQuickFormat)
       
   625 {
       
   626     TRAP_IGNORE(mEngine->FileUtils()->FormatDriveL(aIndex.row(), aQuickFormat));
       
   627 }
       
   628 
       
   629 void EngineWrapper::DiskAdminQuickFormatDrive(const QModelIndex &aIndex, bool aQuickFormat)
       
   630 {
       
   631     TRAP_IGNORE(mEngine->FileUtils()->FormatDriveL(aIndex.row(), aQuickFormat));
       
   632 }
       
   633 
       
   634 void EngineWrapper::DiskAdminCheckDisk(const QModelIndex &aIndex)
       
   635 {
       
   636     TRAP_IGNORE(mEngine->FileUtils()->CheckDiskL(aIndex.row()));
       
   637 }
       
   638 
       
   639 void EngineWrapper::DiskAdminScanDrive(const QModelIndex &aIndex)
       
   640 {
       
   641     TRAP_IGNORE(mEngine->FileUtils()->ScanDriveL(aIndex.row()));
       
   642 }
       
   643 
       
   644 void EngineWrapper::DiskAdminSetDriveName(const QModelIndex &aIndex, const QString &aDriveName)
       
   645 {
       
   646     TFileName driveName = TFileName(aDriveName.utf16());
       
   647     TRAP_IGNORE(mEngine->FileUtils()->SetDriveNameL(aIndex.row(), driveName));
       
   648 }
       
   649 
       
   650 void EngineWrapper::DiskAdminSetDriveVolumeLabel(const QModelIndex &aIndex, const QString &aVolumeLabel)
       
   651 {
       
   652     TFileName volumeLabel = TFileName(aVolumeLabel.utf16());
       
   653     TRAP_IGNORE(mEngine->FileUtils()->SetDriveNameL(aIndex.row(), volumeLabel));
       
   654 }
       
   655 
       
   656 void EngineWrapper::DiskAdminEjectDrive(const QModelIndex &aIndex)
       
   657 {
       
   658     TRAP_IGNORE(mEngine->FileUtils()->EjectDriveL(aIndex.row()));
       
   659 }
       
   660 
       
   661 void EngineWrapper::DiskAdminDismountDrive(const QModelIndex &aIndex)
       
   662 {
       
   663     TRAP_IGNORE(mEngine->FileUtils()->DismountFileSystemL(aIndex.row()));
       
   664 }
       
   665 
       
   666 void EngineWrapper::DiskAdminEraseMBR(const QModelIndex &aIndex)
       
   667 {
       
   668     TRAP_IGNORE(mEngine->FileUtils()->EraseMBRL(aIndex.row()));
       
   669 }
       
   670 
       
   671 void EngineWrapper::DiskAdminPartitionDrive(const QModelIndex &aIndex, bool aEraseMBR, int aAmountOfPartitions)
       
   672 {
       
   673     TRAP_IGNORE(mEngine->FileUtils()->PartitionDriveL(aIndex.row(), aEraseMBR, aAmountOfPartitions));
       
   674 }
       
   675 
       
   676 void EngineWrapper::ToolsSetErrRd(bool aEnable)
       
   677 {
       
   678     TRAP_IGNORE(mEngine->FileUtils()->SetErrRdL(aEnable));
       
   679 }
       
   680 
       
   681 bool EngineWrapper::ErrRdFileExists()
       
   682 {
       
   683     return mEngine->FileUtils()->FileExists(KErrRdPath);
       
   684 }
       
   685 
       
   686 void EngineWrapper::ToolsErrorSimulateLeave(int aLeaveCode)
       
   687 {
       
   688     mEngine->FileUtils()->SimulateLeaveL(aLeaveCode);
       
   689 }
       
   690 
       
   691 void EngineWrapper::ToolsErrorSimulatePanic(QString aPanicCategory, int aPanicCode)
       
   692 {
       
   693     TBuf<128> panicCategory;
       
   694     panicCategory.Copy(aPanicCategory.utf16());
       
   695     mEngine->FileUtils()->SimulatePanicL(panicCategory, aPanicCode);
       
   696 }
       
   697 
       
   698 void EngineWrapper::ToolsErrorSimulateException(int aExceptionCode)
       
   699 {
       
   700     mEngine->FileUtils()->SimulateExceptionL(aExceptionCode);
       
   701 }
       
   702 
       
   703 quint32 EngineWrapper::getDebugMask()
       
   704 {
       
   705     return mEngine->FileUtils()->GetDebugMask();
       
   706 }
       
   707 
       
   708 void EngineWrapper::toolsSetDebugMask(quint32 aDbgMask)
       
   709 {
       
   710     mEngine->FileUtils()->SetDebugMaskL(aDbgMask);
       
   711 }
       
   712 
       
   713 void EngineWrapper::toolsWriteAllFiles()
       
   714 {
       
   715     mEngine->FileUtils()->WriteAllFilesL();
       
   716 }
       
   717 
       
   718 void EngineWrapper::showFileCheckSums(const QModelIndex &aIndex, TFileBrowserCmdFileChecksums checksumType)
       
   719 {
       
   720     mEngine->FileUtils()->ShowFileCheckSumsL(aIndex.row(), checksumType);
       
   721 }
       
   722 
       
   723 // ---------------------------------------------------------------------------
       
   724 // Functions that are called from engine
       
   725 // ---------------------------------------------------------------------------
       
   726 
       
   727 // ---------------------------------------------------------------------------
       
   728 
       
   729 void EngineWrapper::ShowErrorNote(const TDesC& aDescText, TBool aNoTimeout /*= EFalse*/)
       
   730 {
       
   731     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   732     Notifications::showErrorNote(qText, aNoTimeout);
       
   733 }
       
   734 
       
   735 // ---------------------------------------------------------------------------
       
   736 
       
   737 void EngineWrapper::ShowInformationNote(const TDesC &aDescText, const TDesC &aDescTitle)
       
   738 {
       
   739     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   740     QString qTitle = QString::fromUtf16(aDescTitle.Ptr(), aDescTitle.Length());
       
   741     Notifications::showInformationNote(qText, qTitle);
       
   742 }
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 
       
   746 void EngineWrapper::ShowConfirmationNote(const TDesC& aDescText, TBool aNoTimeout /*= EFalse*/)
       
   747 {
       
   748     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   749     Notifications::showConfirmationNote(qText, aNoTimeout);
       
   750 }
       
   751 
       
   752 void EngineWrapper::ShowProgressDialog(const TDesC& aDescText, TInt aMinimum, TInt aMaximum )
       
   753 {
       
   754     const QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   755     if (!mProgressDialog) {
       
   756         mProgressDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   757         QObject::connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   758     }
       
   759 
       
   760     mProgressDialog->setText(qText);
       
   761     mProgressDialog->setMinimum(aMinimum);
       
   762     mProgressDialog->setMaximum(aMaximum);
       
   763     mEngine->FileUtils()->SetAllowProcessing(true);
       
   764     mProgressDialog->show();
       
   765 }
       
   766 
       
   767 void EngineWrapper::CancelProgressDialog()
       
   768 {
       
   769     if (mProgressDialog) {
       
   770         QObject::disconnect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   771         mProgressDialog->cancel();
       
   772         QObject::connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   773     }
       
   774 }
       
   775 
       
   776 void EngineWrapper::SetProgressValue(TInt aValue)
       
   777 {
       
   778     if (mProgressDialog)
       
   779         mProgressDialog->setProgressValue(aValue);
       
   780 }
       
   781 
       
   782 void EngineWrapper::progressDialogCancelled()
       
   783 {
       
   784     mEngine->FileUtils()->DialogDismissedL();
       
   785 }
       
   786 
       
   787 void EngineWrapper::ShowWaitDialog(const TDesC& aDescText)
       
   788 {
       
   789     const QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   790     if (!mWaitDialog) {
       
   791         mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   792         QObject::connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitDialogCancelled()));
       
   793     }
       
   794 
       
   795     mWaitDialog->setText(qText);
       
   796     mEngine->FileUtils()->SetAllowProcessing(true);
       
   797     //mWaitDialog->setAttribute(Qt::WA_DeleteOnClose);
       
   798     mWaitDialog->show();
       
   799 }
       
   800 
       
   801 void EngineWrapper::CancelWaitDialog()
       
   802 {
       
   803     if (mWaitDialog)
       
   804         mWaitDialog->cancel();
       
   805 }
       
   806 
       
   807 void EngineWrapper::waitDialogCancelled()
       
   808 {
       
   809     mEngine->FileUtils()->SetAllowProcessing(false);
       
   810 }
       
   811 
       
   812 void EngineWrapper::ProcessEvents()
       
   813 {
       
   814     qApp->processEvents();
       
   815 }
       
   816 
       
   817 TBool EngineWrapper::ShowConfirmationQuery(const TDesC& aDescText)
       
   818 {
       
   819     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   820     return Notifications::showConfirmationQuery(qText);
       
   821 }
       
   822 
       
   823 void EngineWrapper::NotifyModelHasChanged()
       
   824 {
       
   825     emit fileSystemDataChanged();
       
   826 }
       
   827 
       
   828 // ---------------------------------------------------------------------------