launcher/src/enginewrapper.cpp
changeset 17 4f2773374eff
child 23 c9bf25a20c9f
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     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 <xqconversions.h>
       
    19 #include <hbinputdialog.h>
       
    20 #include <bautils.h>
       
    21 #include <shareuidialog.h>
       
    22 #include <eikenv.h>
       
    23 #include <hbprogressdialog.h>
       
    24 #include <QDebug>
       
    25 
       
    26 #include "launchermainwindow.h"
       
    27 #include "notifications.h"
       
    28 #include "enginewrapper.h"
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 
       
    32 EngineWrapper::EngineWrapper(LauncherMainWindow* mainWindow)
       
    33 : mEngine(0), 
       
    34   mMainWindow(mainWindow),
       
    35   mProgressDialog(0),
       
    36   mWaitDialog(0)
       
    37 {
       
    38 }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 
       
    42 EngineWrapper::~EngineWrapper()
       
    43 {
       
    44     if (mEngine != NULL) {
       
    45         delete mEngine;
       
    46         mEngine = NULL;
       
    47     }
       
    48     if (mProgressDialog != NULL) {
       
    49         delete mProgressDialog;
       
    50         mProgressDialog = NULL;
       
    51     }
       
    52     if (mWaitDialog != NULL) {
       
    53         delete mWaitDialog;
       
    54         mWaitDialog = NULL;
       
    55     }
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 
       
    60 bool EngineWrapper::init()
       
    61 {
       
    62     
       
    63     // construct engine
       
    64     TRAPD(error, mEngine = CLauncherEngine::NewL(this));
       
    65     if (error != KErrNone) {
       
    66         return false;
       
    67     }
       
    68     
       
    69     return true;
       
    70    
       
    71 }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 
       
    75 bool EngineWrapper::listOfAllApps(QStringList &allAppsQStringList){
       
    76     
       
    77     // Get application CDesCArray list from engine
       
    78     CDesCArray* allAppsCDescArray = 0;
       
    79     TRAPD(error, allAppsCDescArray = mEngine->ListOfAllAppsL());
       
    80     if(error != KErrNone) {
       
    81         return false;
       
    82     }
       
    83         
       
    84     //convert CDesCArray to QStringList
       
    85     for (int i = 0; i < allAppsCDescArray->Count(); i++) {
       
    86         allAppsQStringList.append(QString::fromUtf16(
       
    87                 allAppsCDescArray->MdcaPoint(i).Ptr(),
       
    88                 allAppsCDescArray->MdcaPoint(i).Length()));
       
    89     }
       
    90     return true;
       
    91 }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 bool EngineWrapper::startAppLaunching(const QModelIndexList &qList, bool autoClose) 
       
    95 {
       
    96     
       
    97     // check if used has not selected any files
       
    98     if (qList.size() == 0) {
       
    99         Notifications::showErrorNote("Nothing selected");
       
   100         return false;
       
   101     }
       
   102 
       
   103     bool retval(true);
       
   104     CArrayFix<TInt>* pArrayFix = NULL;
       
   105     try{
       
   106         // Create CArrayFix for application numbers that are launched and Qlist into CArrayFix
       
   107         QT_TRAP_THROWING( pArrayFix = QModelIndexListToCArrayFixL(qList) );
       
   108         
       
   109         // Start launching applications
       
   110         QT_TRAP_THROWING(mEngine->StartAppLaunchingL(pArrayFix, autoClose ? ETrue : EFalse));
       
   111     }
       
   112     catch (const std::exception &e){
       
   113         qDebug() << "EngineWrapper::startAppLaunching - exception: " << e.what();
       
   114         retval = false;
       
   115     }
       
   116     
       
   117     if(pArrayFix)
       
   118         delete pArrayFix;
       
   119     
       
   120     return retval;
       
   121 }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 
       
   125 bool EngineWrapper::stopLaunching()
       
   126 {
       
   127     TRAPD(error, mEngine->StopLaunchingL());
       
   128     if (error != KErrNone) {
       
   129         return false;
       
   130     }
       
   131     else {
       
   132         return true;
       
   133     }
       
   134 }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 
       
   138 bool EngineWrapper::sendLog()
       
   139 {
       
   140     ShareUi dialog;
       
   141     QList<QVariant> fileList;
       
   142 
       
   143     if( mEngine->LogFileExists() )
       
   144         {
       
   145         const TDesC& logFilePath = mEngine->LogFilePath();
       
   146         fileList.append( QString::fromUtf16( logFilePath.Ptr(), logFilePath.Length() ) );
       
   147         }
       
   148     if( mEngine->BCLogFileExists() )
       
   149         {
       
   150         const TDesC& BCLogFilePath = mEngine->BCLogFilePath();
       
   151         fileList.append( QString::fromUtf16( BCLogFilePath.Ptr(), BCLogFilePath.Length() ) );
       
   152         }
       
   153     
       
   154     if( !fileList.empty()){
       
   155         dialog.init(fileList,true);   
       
   156         return true;
       
   157     }
       
   158     else{
       
   159         return false;
       
   160     }
       
   161     
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 
       
   166 bool EngineWrapper::deleteLog()
       
   167 {
       
   168     // if log file exists delete it.
       
   169     if (mEngine->LogFileExists()) {
       
   170         if (mEngine->DeleteLogFile() != KErrNone) {
       
   171             return false;
       
   172         }
       
   173     }
       
   174     
       
   175     //if BC log file exists, delete it.
       
   176     if (mEngine->BCLogFileExists()) {
       
   177         if (mEngine->DeleteBCLogFile() != KErrNone) {
       
   178             return false;
       
   179         }
       
   180     }
       
   181     
       
   182     return true;
       
   183 
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 
       
   188 bool EngineWrapper::sendListOfDlls()
       
   189 {
       
   190     const TDesC& systemDllsFilePath = mEngine->SystemDllsFilePath();
       
   191     
       
   192     if ( BaflUtils::FileExists( CEikonEnv::Static()->FsSession(), systemDllsFilePath) ){
       
   193         ShareUi dialog;
       
   194         QList<QVariant> fileList;
       
   195         fileList.append( QString::fromUtf16( systemDllsFilePath.Ptr(), systemDllsFilePath.Length() ) );
       
   196         dialog.init(fileList,true); 
       
   197         return true;
       
   198     }
       
   199     else{
       
   200         Notifications::showErrorNote("DLL list does not exist");
       
   201         return false;
       
   202     }
       
   203 }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 
       
   207 void EngineWrapper::doCompareDlls(HbAction* action)
       
   208     {
       
   209     HbInputDialog *dlg = static_cast<HbInputDialog*>(sender());
       
   210     if(action == dlg->primaryAction())
       
   211         {
       
   212         TFileName fileName( dlg->value().toString().utf16() );
       
   213         TRAPD(error,  mEngine->AnalyseDLLsL( fileName ) );
       
   214         if( error != KErrNone )
       
   215             { 
       
   216             HideWaitDialog();
       
   217             HideProgressBar();
       
   218             Notifications::showErrorNote( QString("Error in analyse: %1").arg( error ) );
       
   219             }
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 
       
   225 void EngineWrapper::compareDlls()
       
   226 {
       
   227     const TDesC& requiredDllsFileName = mEngine->RequiredDllsFilePath();
       
   228     QString fileName = QString::fromUtf16( requiredDllsFileName.Ptr(), requiredDllsFileName.Length() );
       
   229     HbInputDialog::getText( "Select input file for BC analysis:", this, SLOT(doCompareDlls(HbAction*)), fileName );
       
   230 }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 void EngineWrapper::ShowProgressBar(const TDesC& descText, TInt minimum, TInt maximum)
       
   234 {
       
   235     QString qStringText = XQConversions::s60DescToQString(descText);
       
   236    
       
   237     if(mProgressDialog){
       
   238         delete mProgressDialog;
       
   239         mProgressDialog = NULL;
       
   240     }
       
   241     mProgressDialog = new HbProgressDialog( HbProgressDialog::ProgressDialog );
       
   242     
       
   243     if( maximum > 0 )
       
   244         mProgressDialog->setRange(minimum, maximum);
       
   245     //iProgressDialog->setAutoClose(true);
       
   246     mProgressDialog->setText(qStringText);
       
   247     connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(CancelDllBCanalysis()));
       
   248     mProgressDialog->show();
       
   249 }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 void EngineWrapper::SetProgressBarValue(TInt value)
       
   253 {
       
   254     if (mProgressDialog && value > 0 ){
       
   255         mProgressDialog->setProgressValue(value);
       
   256     }
       
   257 }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 void EngineWrapper::HideProgressBar()
       
   261 {
       
   262     if (mProgressDialog != NULL) {
       
   263         disconnect(mProgressDialog, SIGNAL(cancelled), this, SLOT(CancelDllBCanalysis()));
       
   264         delete mProgressDialog;
       
   265         mProgressDialog = NULL;
       
   266     }
       
   267 }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 void EngineWrapper::CancelDllBCanalysis()
       
   271 {
       
   272     mEngine->CancelBCAnalysis();
       
   273 }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 void EngineWrapper::ShowWaitDialog(const TDesC& descText)
       
   277 {
       
   278     QString qStringText = XQConversions::s60DescToQString(descText);
       
   279    
       
   280     if(mWaitDialog){
       
   281         delete mWaitDialog;
       
   282         mWaitDialog = NULL;
       
   283     }
       
   284     mWaitDialog = Notifications::showWaitDialog(qStringText);
       
   285 }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 void EngineWrapper::HideWaitDialog()
       
   289 {
       
   290     if (mWaitDialog != NULL) {
       
   291         delete mWaitDialog;
       
   292         mWaitDialog = NULL;
       
   293     }
       
   294 }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 
       
   298 void EngineWrapper::setSkipHiddenAndEmbedOnly(bool skip)
       
   299 {
       
   300     if(skip) {
       
   301         mEngine->SetSkipHiddenAndEmbedOnly(ETrue);
       
   302     }
       
   303     else {
       
   304         mEngine->SetSkipHiddenAndEmbedOnly(EFalse);
       
   305     }
       
   306 }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 
       
   310 void EngineWrapper::ChangeFocusToOutputView()
       
   311 {
       
   312     mMainWindow->openOutputView();
       
   313 }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 
       
   317 void EngineWrapper::PrintText(const TDesC& descText)
       
   318 {
       
   319     
       
   320     // Convert the descriptor to QString
       
   321     QString qStringText = XQConversions::s60DescToQString(descText);
       
   322     mMainWindow->printText(qStringText);
       
   323 }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 
       
   327 CArrayFix<TInt>* EngineWrapper::QModelIndexListToCArrayFixL(const QModelIndexList& qlist)
       
   328 {
       
   329     CArrayFix<TInt>* pArrayFix = new (ELeave) CArrayFixFlat<TInt>( qlist.size() );
       
   330     CleanupStack::PushL(pArrayFix);
       
   331     for (int j = 0; j < qlist.size(); j++) {
       
   332         pArrayFix->AppendL(qlist.at(j).row());
       
   333     }
       
   334     CleanupStack::Pop(pArrayFix);
       
   335     return pArrayFix;
       
   336 }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 
       
   340 void EngineWrapper::ShowErrorMessage(const TDesC& descText)
       
   341 {
       
   342     QString qStringText = XQConversions::s60DescToQString(descText);
       
   343     Notifications::showErrorNote(qStringText);
       
   344 }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 
       
   348 void EngineWrapper::ShowInfoMessage(const TDesC& descText)
       
   349 {
       
   350     QString qStringText = XQConversions::s60DescToQString(descText);
       
   351     Notifications::showInformationNote(qStringText);
       
   352 }
       
   353 
       
   354 // End of File