utilityapps/filebrowser/ui/src/enginewrapper.cpp
changeset 55 2d9cac8919d3
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     if (err == KErrNone) {
       
   337         Notifications::showConfirmationNote(QString("New file created"));
       
   338     } else if (err == KErrAlreadyExists) {
       
   339         Notifications::showInformationNote(QString("File already exists"));
       
   340     } else {
       
   341         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   342     }
       
   343     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   344 }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 
       
   348 void EngineWrapper::createNewDirectory(const QString &aNewDirectoryName)
       
   349 {
       
   350     TFileName newDirectoryName = TFileName(aNewDirectoryName.utf16());
       
   351     TRAPD(err, mEngine->FileUtils()->NewDirectoryL(newDirectoryName) );
       
   352     if (err == KErrNone) {
       
   353         Notifications::showConfirmationNote(QString("New directory created"));
       
   354     } else if (err == KErrAlreadyExists) {
       
   355         Notifications::showInformationNote(QString("Directory already exists"));
       
   356     } else {
       
   357         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   358     }
       
   359     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   360 }
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 
       
   364 void EngineWrapper::deleteItems(const QModelIndexList& aSelectionIndices)
       
   365 {
       
   366     setCurrentSelection(aSelectionIndices);
       
   367     TRAPD(err, mEngine->FileUtils()->DeleteL() );
       
   368     Q_UNUSED(err); //TODO
       
   369 }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 bool EngineWrapper::selectionHasDirs()
       
   373 {
       
   374     return mEngine->FileUtils()->SelectionHasDirs();
       
   375 }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 
       
   379 void EngineWrapper::rename(const QModelIndex& aIndex, const QString aNewName)
       
   380 {
       
   381     if (mEngine->FileUtils()) {
       
   382         const TFileName newName = TFileName(aNewName.utf16());
       
   383         TRAPD(err, mEngine->FileUtils()->RenameL(aIndex.row(), newName) );
       
   384         Q_UNUSED(err); //TODO
       
   385     }
       
   386 }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 
       
   390 void EngineWrapper::touch(bool aRecurse)
       
   391 {
       
   392     if (mEngine->FileUtils()) {
       
   393         TRAPD(err, mEngine->FileUtils()->TouchL(aRecurse) );
       
   394         Q_UNUSED(err); //TODO
       
   395     }
       
   396 }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 
       
   400 int EngineWrapper::getFilesCount(const QString &aDriveRoot)
       
   401 {
       
   402     int count = 0;
       
   403     const TFileName driveRoot = TFileName(aDriveRoot.utf16());
       
   404     if (mEngine->FileUtils()) {
       
   405         TRAPD(err, count = mEngine->FileUtils()->GetFilesCount(driveRoot));
       
   406         Q_UNUSED(err); //TODO
       
   407     }
       
   408     return count;
       
   409 }
       
   410 
       
   411 int EngineWrapper::getFilesCountAndSize(const QString &aDriveRoot, qint64 &aSize)
       
   412 {
       
   413     int count = 0;
       
   414     TInt64 size = 0;
       
   415     const TFileName driveRoot = TFileName(aDriveRoot.utf16());
       
   416     if (mEngine->FileUtils()) {
       
   417         TRAPD(err, count = mEngine->FileUtils()->GetFilesCountAndSize(driveRoot, size));
       
   418         aSize = size;
       
   419         Q_UNUSED(err); //TODO
       
   420     }
       
   421     return count;
       
   422 }
       
   423 
       
   424 int EngineWrapper::getEntriesCount(const QString &aDriveRoot)
       
   425 {
       
   426     int count = -1;
       
   427     const TFileName driveRoot = TFileName(aDriveRoot.utf16());
       
   428     if (mEngine->FileUtils()) {
       
   429         TRAPD(err, count = mEngine->FileUtils()->GetEntriesCount(driveRoot));
       
   430         Q_UNUSED(err); //TODO
       
   431     }
       
   432     return count;
       
   433 }
       
   434 
       
   435 QString EngineWrapper::getMimeType(const QString &aFullPath)
       
   436 {
       
   437     QString qMimeType;
       
   438     if (mEngine->FileUtils()) {
       
   439         const TFileName fullPath = TFileName(aFullPath.utf16());
       
   440         TFileName mimeType = mEngine->FileUtils()->GetMimeType(fullPath);
       
   441         qMimeType = QString::fromUtf16(mimeType.Ptr(), mimeType.Length());
       
   442     }
       
   443     return qMimeType;
       
   444 }
       
   445 
       
   446 QString EngineWrapper::getOpenWith(const QString &aFullPath)
       
   447 {
       
   448     QString qOpenWith;
       
   449     if (mEngine->FileUtils()) {
       
   450         const TFileName fullPath = TFileName(aFullPath.utf16());
       
   451         TFileName openWith = mEngine->FileUtils()->GetOpenWith(fullPath);
       
   452         qOpenWith = QString::fromUtf16(openWith.Ptr(), openWith.Length());
       
   453     }
       
   454     return qOpenWith;
       
   455 }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 
       
   459 void EngineWrapper::setAttributes(quint32 &setAttributesMask, quint32 &clearAttributesMask, bool &recurse)
       
   460 {
       
   461     if (mEngine->FileUtils()) {
       
   462         TBool tRecurse = recurse ? ETrue : EFalse;
       
   463         TRAPD(err, mEngine->FileUtils()->SetAttributesL(setAttributesMask, clearAttributesMask, tRecurse));
       
   464         Q_UNUSED(err); //TODO
       
   465     }
       
   466 }
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 
       
   470 bool EngineWrapper::openAppArc(QString fileName)
       
   471 {
       
   472 
       
   473     //convert QString to TFilename:
       
   474     fileName.replace("/", "\\");
       
   475     TFileName fileToOpen = TFileName(fileName.utf16());
       
   476 
       
   477     TRAPD(err, mEngine->OpenWithApparcL(fileToOpen) );
       
   478     if(err != KErrNone) {
       
   479         return false;
       
   480     } else {
       
   481         return true;
       
   482     }
       
   483 }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 
       
   487 bool EngineWrapper::openDocHandler(QString fileName, bool embeddedVal)
       
   488 {
       
   489     //convert QString to TFilename:
       
   490     fileName.replace("/", "\\");
       
   491     TFileName fileToOpen = TFileName(fileName.utf16());
       
   492 
       
   493     TRAPD(err, mEngine->OpenWithDocHandlerL(fileToOpen, embeddedVal) );
       
   494     if(err != KErrNone) {
       
   495         return false;
       
   496     } else {
       
   497         return true;
       
   498     }
       
   499 }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 
       
   503 int EngineWrapper::itemCount() const
       
   504 {
       
   505     if (mEngine->FileUtils()->IsDriveListViewActive()) {
       
   506         return mEngine->FileUtils()->DriveEntries()->Count();
       
   507     } else {
       
   508         return mEngine->FileUtils()->FileEntries()->Count();
       
   509     }
       
   510 }
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 
       
   514 FbDriveEntry EngineWrapper::getDriveEntry(const QModelIndex& aIndex) const
       
   515 {
       
   516     TDriveEntry driveEntry;
       
   517     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0) {
       
   518         driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   519     }
       
   520     return FbDriveEntry(driveEntry);
       
   521 }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 
       
   525 FbFileEntry EngineWrapper::getFileEntry(const QModelIndex& aIndex) const
       
   526 {
       
   527     TFileEntry fileEntry;
       
   528     if (mEngine->FileUtils()->FileEntries()->Count() > aIndex.row() && aIndex.row() >= 0) {
       
   529         fileEntry = mEngine->FileUtils()->FileEntries()->At(aIndex.row());
       
   530     }
       
   531     return FbFileEntry(fileEntry);
       
   532 }
       
   533 
       
   534 // ---------------------------------------------------------------------------
       
   535 
       
   536 const CArrayFix<TInt> *EngineWrapper::convertSelectionList(const QModelIndexList &aSelectionIndices)
       
   537 {
       
   538     CArrayFixFlat<TInt>* selectionIndexes = 0;
       
   539     TRAPD(err, selectionIndexes = new(ELeave)CArrayFixFlat<TInt>(4));
       
   540     if (err != KErrNone) {
       
   541         return 0;
       
   542     }
       
   543 
       
   544     for (int i=0; i< aSelectionIndices.count(); ++i) {
       
   545         TRAPD(err, selectionIndexes->AppendL(aSelectionIndices.at(i).row()) );
       
   546         Q_UNUSED(err); //TODO
       
   547     }
       
   548     return selectionIndexes;
       
   549 }
       
   550 
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 
       
   554 void EngineWrapper::setCurrentSelection(const QModelIndexList &aSelectionIndices)
       
   555 {
       
   556     const CArrayFix<TInt> *selectionIndexes = convertSelectionList(aSelectionIndices);
       
   557     mEngine->FileUtils()->SetCurrentSelection(selectionIndexes);
       
   558     delete selectionIndexes;
       
   559 }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 
       
   563 bool EngineWrapper::isDestinationEntriesExists(const QModelIndexList &aSelectionIndices, QString aTargetDir)
       
   564 {
       
   565     TFileName targetDir = TFileName(aTargetDir.utf16());
       
   566     //setCurrentSelection(aSelectionIndices);
       
   567     Q_UNUSED(aSelectionIndices);
       
   568 
       
   569     TBool someEntryExists = mEngine->FileUtils()->IsDestinationEntriesExists(targetDir);
       
   570     return someEntryExists;
       
   571 }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 bool EngineWrapper::targetExists(const QModelIndex& aIndex, const QString aNewName)
       
   575 {
       
   576     const TFileName newName = TFileName(aNewName.utf16());
       
   577     return mEngine->FileUtils()->TargetExists(aIndex.row(), newName);
       
   578 }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 
       
   582 QString EngineWrapper::currentPath() const
       
   583 {
       
   584     return QString::fromUtf16(mEngine->FileUtils()->CurrentPath().Ptr(),
       
   585                               mEngine->FileUtils()->CurrentPath().Length());
       
   586 }
       
   587 
       
   588 TOverwriteOptions EngineWrapper::convertOverwriteOptions(const OverwriteOptions &aOverwriteOptions)
       
   589 {
       
   590     TOverwriteOptions tOverwriteOptions;
       
   591     tOverwriteOptions.iDoFileOperations = aOverwriteOptions.doFileOperations;
       
   592     tOverwriteOptions.iQueryIndex = aOverwriteOptions.queryIndex;
       
   593     tOverwriteOptions.iPostFix = TFileName(aOverwriteOptions.postFix.utf16());
       
   594     tOverwriteOptions.iOverWriteFlags = aOverwriteOptions.overWriteFlags;
       
   595     return tOverwriteOptions;
       
   596 }
       
   597 
       
   598 bool EngineWrapper::hasDrivePassword(const QModelIndex &aIndex)
       
   599 {
       
   600     bool hasPassword = false;
       
   601     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   602     {
       
   603         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   604         hasPassword = driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttHasPassword;
       
   605     }
       
   606     return hasPassword;
       
   607 }
       
   608 
       
   609 bool EngineWrapper::isDriveRemovable(const QModelIndex &aIndex)
       
   610 {
       
   611     bool isRemovable = false;
       
   612     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   613     {
       
   614         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   615         isRemovable = driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable;
       
   616     }
       
   617     return isRemovable;
       
   618 }
       
   619 
       
   620 bool EngineWrapper::isDriveLocked(const QModelIndex &aIndex)
       
   621 {
       
   622     bool isRemovable = false;
       
   623     if (mEngine->FileUtils()->DriveEntries()->Count() > aIndex.row() && aIndex.row() >= 0)
       
   624     {
       
   625         TDriveEntry driveEntry = mEngine->FileUtils()->DriveEntries()->At(aIndex.row());
       
   626         isRemovable = driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked;
       
   627     }
       
   628     return isRemovable;
       
   629 }
       
   630 
       
   631 void EngineWrapper::GetDriveName(const QModelIndex &aIndex, QString &aDriveName)
       
   632 {
       
   633     TFileName driveName;
       
   634     mEngine->FileUtils()->GetDriveName(aIndex.row(), driveName);
       
   635     aDriveName = QString::fromUtf16(driveName.Ptr(), driveName.Length());
       
   636 }
       
   637 
       
   638 
       
   639 void EngineWrapper::GetDriveVolumeLabel(const QModelIndex &aIndex, QString &aVolumeLabel)
       
   640 {
       
   641     TFileName volumeLabel;
       
   642     mEngine->FileUtils()->GetDriveName(aIndex.row(), volumeLabel);
       
   643     aVolumeLabel = QString::fromUtf16(volumeLabel.Ptr(), volumeLabel.Length());
       
   644 }
       
   645 
       
   646 /**
       
   647   * Wrapper function for SetDrivePasswordL
       
   648   */
       
   649 void EngineWrapper::DiskAdminSetDrivePassword(const QModelIndex &aIndex,
       
   650                                               const QString &aOldPassword,
       
   651                                               const QString &aNewPassword)
       
   652 {
       
   653     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   654     TFileName newPassword = TFileName(aNewPassword.utf16());
       
   655 
       
   656     TRAPD(err, mEngine->FileUtils()->SetDrivePasswordL(aIndex.row(), oldPassword, newPassword));
       
   657 
       
   658     if (err == KErrNone) {
       
   659         Notifications::showInformationNote(QString("Password set"));
       
   660     } else if (err == KErrNotSupported) {
       
   661         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   662     } else {
       
   663         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   664     }
       
   665     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   666 }
       
   667 
       
   668 /**
       
   669   * Wrapper function for UnlockDriveL
       
   670   */
       
   671 void EngineWrapper::DiskAdminUnlockDrive(const QModelIndex &aIndex, const QString &aOldPassword)
       
   672 {
       
   673     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   674 
       
   675     TRAPD(err, mEngine->FileUtils()->UnlockDriveL(aIndex.row(), oldPassword));
       
   676 
       
   677     if (err == KErrNone) {
       
   678         Notifications::showInformationNote(QString("Drive unlocked"));
       
   679     } else if (err == KErrNotSupported) {
       
   680         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   681     } else {
       
   682         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   683     }
       
   684 
       
   685     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   686 }
       
   687 
       
   688 /**
       
   689   * Wrapper function for ClearDrivePasswordL
       
   690   */
       
   691 void EngineWrapper::DiskAdminClearDrivePassword(const QModelIndex &aIndex, const QString &aOldPassword)
       
   692 {
       
   693     TFileName oldPassword = TFileName(aOldPassword.utf16());
       
   694     TRAPD(err, mEngine->FileUtils()->ClearDrivePasswordL(aIndex.row(), oldPassword));
       
   695 
       
   696     if (err == KErrNone) {
       
   697         Notifications::showInformationNote(QString("Password cleared"));
       
   698     } else if (err == KErrNotSupported) {
       
   699         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   700     } else {
       
   701         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   702     }
       
   703 
       
   704     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   705 }
       
   706 
       
   707 /**
       
   708   * Wrapper function for ClearDrivePasswordL
       
   709   */
       
   710 void EngineWrapper::DiskAdminEraseDrivePassword(const QModelIndex &aIndex)
       
   711 {
       
   712     TRAPD(err, mEngine->FileUtils()->EraseDrivePasswordL(aIndex.row()));
       
   713 
       
   714     if (err == KErrNone) {
       
   715         Notifications::showInformationNote(QString("Password erased"));
       
   716     } else if (err == KErrNotSupported) {
       
   717         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   718     } else {
       
   719         Notifications::showErrorNote(QString("Cannot erase, you may have to format the drive first"));
       
   720     }
       
   721 
       
   722     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   723 }
       
   724 
       
   725 void EngineWrapper::DiskAdminFormatDrive(const QModelIndex &aIndex, bool aQuickFormat)
       
   726 {
       
   727     TRAP_IGNORE(mEngine->FileUtils()->FormatDriveL(aIndex.row(), aQuickFormat));
       
   728 }
       
   729 
       
   730 void EngineWrapper::DiskAdminQuickFormatDrive(const QModelIndex &aIndex, bool aQuickFormat)
       
   731 {
       
   732     TRAP_IGNORE(mEngine->FileUtils()->FormatDriveL(aIndex.row(), aQuickFormat));
       
   733 }
       
   734 
       
   735 void EngineWrapper::DiskAdminCheckDisk(const QModelIndex &aIndex)
       
   736 {
       
   737     TRAP_IGNORE(mEngine->FileUtils()->CheckDiskL(aIndex.row()));
       
   738 }
       
   739 
       
   740 /**
       
   741   * Wrapper function for ScanDriveL
       
   742   */
       
   743 void EngineWrapper::DiskAdminScanDrive(const QModelIndex &aIndex)
       
   744 {
       
   745     TRAPD(err, mEngine->FileUtils()->ScanDriveL(aIndex.row()));
       
   746 
       
   747     if (err == KErrNone) {
       
   748         Notifications::showConfirmationNote(QString("Run succesfully"));
       
   749     } else if (err == KErrNotSupported) {
       
   750         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   751     } else {
       
   752         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   753     }
       
   754 
       
   755     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   756 }
       
   757 
       
   758 /**
       
   759   * Wrapper function for SetDriveNameL
       
   760   */
       
   761 void EngineWrapper::DiskAdminSetDriveName(const QModelIndex &aIndex, const QString &aDriveName)
       
   762 {
       
   763     TFileName driveName = TFileName(aDriveName.utf16());
       
   764     TRAPD(err, mEngine->FileUtils()->SetDriveNameL(aIndex.row(), driveName));
       
   765 
       
   766     if (err == KErrNone) {
       
   767         Notifications::showConfirmationNote(QString("Name changed"));
       
   768     } else if (err == KErrNotSupported) {
       
   769         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   770     } else {
       
   771         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   772     }
       
   773 
       
   774     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   775 }
       
   776 
       
   777 /**
       
   778   * Wrapper function for SetDriveVolumeLabelL
       
   779   */
       
   780 void EngineWrapper::DiskAdminSetDriveVolumeLabel(const QModelIndex &aIndex, const QString &aVolumeLabel)
       
   781 {
       
   782     TFileName volumeLabel = TFileName(aVolumeLabel.utf16());
       
   783     TRAPD(err, mEngine->FileUtils()->SetDriveVolumeLabelL(aIndex.row(), volumeLabel));
       
   784 
       
   785     if (err == KErrNone) {
       
   786         Notifications::showConfirmationNote(QString("Volume label changed"));
       
   787     } else if (err == KErrNotSupported) {
       
   788         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   789     } else {
       
   790         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   791     }
       
   792 
       
   793     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   794 }
       
   795 
       
   796 /**
       
   797   * Wrapper function for EjectDriveL
       
   798   */
       
   799 void EngineWrapper::DiskAdminEjectDrive(const QModelIndex &aIndex)
       
   800 {
       
   801     TRAPD(err, mEngine->FileUtils()->EjectDriveL(aIndex.row()));
       
   802 
       
   803     if (err == KErrNone) {
       
   804         Notifications::showConfirmationNote(QString("Ejected succesfully"));
       
   805     } else if (err == KErrNotSupported) {
       
   806         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   807     } else {
       
   808         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   809     }
       
   810 
       
   811     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   812 }
       
   813 
       
   814 /**
       
   815   * Wrapper function for DismountFileSystemL
       
   816   */
       
   817 void EngineWrapper::DiskAdminDismountDrive(const QModelIndex &aIndex)
       
   818 {
       
   819     TRAPD(err, mEngine->FileUtils()->DismountFileSystemL(aIndex.row()));
       
   820 
       
   821     if (err == KErrNone) {
       
   822         Notifications::showConfirmationNote(QString("Dismounted succesfully"));
       
   823     } else if (err == KErrNotSupported) {
       
   824         Notifications::showErrorNote(QString("Not supported for this drive"));
       
   825     } else {
       
   826         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   827     }
       
   828 
       
   829     TRAP_IGNORE(mEngine->FileUtils()->RefreshViewL());
       
   830 }
       
   831 
       
   832 /**
       
   833   * Wrapper function for EraseMBRL
       
   834   */
       
   835 void EngineWrapper::DiskAdminEraseMBR(const QModelIndex &aIndex)
       
   836 {
       
   837     TRAP_IGNORE(mEngine->FileUtils()->EraseMBRL(aIndex.row()));
       
   838 }
       
   839 
       
   840 /**
       
   841   * Wrapper function for PartitionDriveL
       
   842   */
       
   843 void EngineWrapper::DiskAdminPartitionDrive(const QModelIndex &aIndex, bool aEraseMBR, int aAmountOfPartitions)
       
   844 {
       
   845     TRAP_IGNORE(mEngine->FileUtils()->PartitionDriveL(aIndex.row(), aEraseMBR, aAmountOfPartitions));
       
   846 }
       
   847 
       
   848 void EngineWrapper::ToolsSetErrRd(bool aEnable)
       
   849 {
       
   850     TRAP_IGNORE(mEngine->FileUtils()->SetErrRdL(aEnable));
       
   851 }
       
   852 
       
   853 bool EngineWrapper::ErrRdFileExists()
       
   854 {
       
   855     return mEngine->FileUtils()->FileExists(KErrRdPath);
       
   856 }
       
   857 
       
   858 void EngineWrapper::ToolsErrorSimulateLeave(int aLeaveCode)
       
   859 {
       
   860     mEngine->FileUtils()->SimulateLeaveL(aLeaveCode);
       
   861 }
       
   862 
       
   863 void EngineWrapper::ToolsErrorSimulatePanic(QString aPanicCategory, int aPanicCode)
       
   864 {
       
   865     TBuf<128> panicCategory;
       
   866     panicCategory.Copy(aPanicCategory.utf16());
       
   867     mEngine->FileUtils()->SimulatePanicL(panicCategory, aPanicCode);
       
   868 }
       
   869 
       
   870 void EngineWrapper::ToolsErrorSimulateException(int aExceptionCode)
       
   871 {
       
   872     mEngine->FileUtils()->SimulateExceptionL(aExceptionCode);
       
   873 }
       
   874 
       
   875 quint32 EngineWrapper::getDebugMask()
       
   876 {
       
   877     return mEngine->FileUtils()->GetDebugMask();
       
   878 }
       
   879 
       
   880 void EngineWrapper::toolsSetDebugMask(quint32 aDbgMask)
       
   881 {
       
   882     mEngine->FileUtils()->SetDebugMaskL(aDbgMask);
       
   883 }
       
   884 
       
   885 void EngineWrapper::toolsWriteAllFiles()
       
   886 {
       
   887     mEngine->FileUtils()->WriteAllFilesL();
       
   888 }
       
   889 
       
   890 void EngineWrapper::showFileCheckSums(const QModelIndex &aIndex, TFileBrowserCmdFileChecksums checksumType)
       
   891 {
       
   892     TRAPD(err, mEngine->FileUtils()->ShowFileCheckSumsL(aIndex.row(), checksumType));
       
   893 
       
   894     if (err != KErrNone) {
       
   895         ShowErrorNote(mEngine->FileUtils()->ResolveErrorMessage(err));
       
   896     }
       
   897 }
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // Functions that are called from engine
       
   901 // ---------------------------------------------------------------------------
       
   902 
       
   903 // ---------------------------------------------------------------------------
       
   904 
       
   905 void EngineWrapper::ShowErrorNote(const TDesC& aDescText, TBool aNoTimeout /*= EFalse*/)
       
   906 {
       
   907     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   908     Notifications::showErrorNote(qText, aNoTimeout);
       
   909 }
       
   910 
       
   911 // ---------------------------------------------------------------------------
       
   912 
       
   913 void EngineWrapper::ShowInformationNote(const TDesC &aDescText, const TDesC &aDescTitle)
       
   914 {
       
   915     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   916     QString qTitle = QString::fromUtf16(aDescTitle.Ptr(), aDescTitle.Length());
       
   917     Notifications::showInformationNote(qText, qTitle);
       
   918 }
       
   919 
       
   920 // ---------------------------------------------------------------------------
       
   921 
       
   922 void EngineWrapper::ShowConfirmationNote(const TDesC& aDescText, TBool aNoTimeout /*= EFalse*/)
       
   923 {
       
   924     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   925     Notifications::showConfirmationNote(qText, aNoTimeout);
       
   926 }
       
   927 
       
   928 void EngineWrapper::ShowProgressDialog(const TDesC& aDescText, TInt aMinimum, TInt aMaximum )
       
   929 {
       
   930     const QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   931     if (!mProgressDialog) {
       
   932         mProgressDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   933         QObject::connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   934     }
       
   935 
       
   936     mProgressDialog->setText(qText);
       
   937     mProgressDialog->setMinimum(aMinimum);
       
   938     mProgressDialog->setMaximum(aMaximum);
       
   939     mEngine->FileUtils()->SetAllowProcessing(true);
       
   940     mProgressDialog->show();
       
   941 }
       
   942 
       
   943 void EngineWrapper::CancelProgressDialog()
       
   944 {
       
   945     if (mProgressDialog) {
       
   946         QObject::disconnect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   947         mProgressDialog->cancel();
       
   948         QObject::connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(progressDialogCancelled()));
       
   949     }
       
   950 }
       
   951 
       
   952 void EngineWrapper::SetProgressValue(TInt aValue)
       
   953 {
       
   954     if (mProgressDialog)
       
   955         mProgressDialog->setProgressValue(aValue);
       
   956 }
       
   957 
       
   958 void EngineWrapper::progressDialogCancelled()
       
   959 {
       
   960     mEngine->FileUtils()->DialogDismissedL();
       
   961 }
       
   962 
       
   963 void EngineWrapper::ShowWaitDialog(const TDesC& aDescText)
       
   964 {
       
   965     const QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   966     if (!mWaitDialog) {
       
   967         mWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   968         QObject::connect(mWaitDialog, SIGNAL(cancelled()), this, SLOT(waitDialogCancelled()));
       
   969     }
       
   970 
       
   971     mWaitDialog->setText(qText);
       
   972     mEngine->FileUtils()->SetAllowProcessing(true);
       
   973     //mWaitDialog->setAttribute(Qt::WA_DeleteOnClose);
       
   974     mWaitDialog->show();
       
   975 }
       
   976 
       
   977 void EngineWrapper::CancelWaitDialog()
       
   978 {
       
   979     if (mWaitDialog)
       
   980         mWaitDialog->cancel();
       
   981 }
       
   982 
       
   983 void EngineWrapper::waitDialogCancelled()
       
   984 {
       
   985     mEngine->FileUtils()->SetAllowProcessing(false);
       
   986 }
       
   987 
       
   988 void EngineWrapper::ProcessEvents()
       
   989 {
       
   990     qApp->processEvents();
       
   991 }
       
   992 
       
   993 TBool EngineWrapper::ShowConfirmationQuery(const TDesC& aDescText)
       
   994 {
       
   995     QString qText = QString::fromUtf16(aDescText.Ptr(), aDescText.Length());
       
   996     return Notifications::showConfirmationQuery(qText);
       
   997 }
       
   998 
       
   999 void EngineWrapper::NotifyModelHasChanged()
       
  1000 {
       
  1001     emit fileSystemDataChanged();
       
  1002 }
       
  1003 
       
  1004 // ---------------------------------------------------------------------------