searchui/stateproviders/searchstateprovider/src/searchprogressivestate.cpp
changeset 3 6832643895f7
parent 2 208a4ba3894c
child 5 3bc31ad99ee7
equal deleted inserted replaced
2:208a4ba3894c 3:6832643895f7
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description:  Implementation of the progressive search state.
    14  * Description:  Implementation of the progressive search state.
    15  *
    15  *
    16  */
    16  */
    17 
       
    18 #include "searchprogressivestate.h"
    17 #include "searchprogressivestate.h"
    19 #include "indevicehandler.h"
    18 #include "indevicehandler.h"
    20 #include <qcpixdocument.h>
    19 #include <qcpixdocument.h>
    21 #include <qcpixdocumentfield.h>
    20 #include <qcpixdocumentfield.h>
    22 #include <hbmainwindow.h>
    21 #include <hbmainwindow.h>
    42 #include <qbitmap.h>
    41 #include <qbitmap.h>
    43 #include <fbs.h>
    42 #include <fbs.h>
    44 #include <AknInternalIconUtils.h>
    43 #include <AknInternalIconUtils.h>
    45 #include <AknIconUtils.h> 
    44 #include <AknIconUtils.h> 
    46 #include <apgcli.h>
    45 #include <apgcli.h>
    47 
    46 #include <qpluginloader.h>
       
    47 #include <eventviewerplugininterface.h>
       
    48 #include <noteseditor.h>
       
    49 #include <w32std.h>
       
    50 #include <apgtask.h>
       
    51 #include <apgcli.h>
       
    52 #include <AknTaskList.h>
       
    53 #include <apacmdln.h>
    48 const char *SEARCHSTATEPROVIDER_DOCML = ":/xml/searchstateprovider.docml";
    54 const char *SEARCHSTATEPROVIDER_DOCML = ":/xml/searchstateprovider.docml";
    49 const char *TOC_VIEW = "tocView";
    55 const char *TOC_VIEW = "tocView";
    50 const char *TUT_SEARCHPANEL_WIDGET = "searchPanel";
    56 const char *TUT_SEARCHPANEL_WIDGET = "searchPanel";
    51 const char *TUT_LIST_VIEW = "listView";
    57 const char *TUT_LIST_VIEW = "listView";
    52 const QSize defaultIconSize(30, 30);
       
    53 const int totalcategories = 10;
    58 const int totalcategories = 10;
    54 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    55 // SearchProgressiveState::SearchProgressiveState
    60 // SearchProgressiveState::SearchProgressiveState
    56 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    57 //
       
    58 SearchProgressiveState::SearchProgressiveState(QState *parent) :
    62 SearchProgressiveState::SearchProgressiveState(QState *parent) :
    59     QState(parent), mMainWindow(NULL), mView(NULL), mListView(NULL),
    63     QState(parent), mMainWindow(NULL), mView(NULL), mListView(NULL),
    60             mDocumentLoader(NULL), mModel(NULL), mSearchHandler(NULL),
    64             mDocumentLoader(NULL), mModel(NULL), mSearchHandler(NULL),
    61             mAiwMgr(0), mRequest(0)
    65             notesEditor(0), mAiwMgr(0), mRequest(0)
    62     {
    66     {
    63 
    67 
    64     mMainWindow = hbInstance->allMainWindows().at(0);
    68     mMainWindow = hbInstance->allMainWindows().at(0);
    65     mModel = new QStandardItemModel(this);
    69     mModel = new QStandardItemModel(this);
    66 
    70 
    67    
       
    68     mAiwMgr = new XQApplicationManager;
    71     mAiwMgr = new XQApplicationManager;
    69 
    72 
    70     mDocumentLoader = new HbDocumentLoader();
    73     mDocumentLoader = new HbDocumentLoader();
    71     bool ok = false;
    74     bool ok = false;
    72     mDocumentLoader->load(SEARCHSTATEPROVIDER_DOCML, &ok);
    75     mDocumentLoader->load(SEARCHSTATEPROVIDER_DOCML, &ok);
    94 
    97 
    95         HbListViewItem *prototypeListView = qobject_cast<HbListViewItem *> (
    98         HbListViewItem *prototypeListView = qobject_cast<HbListViewItem *> (
    96                 prototype);
    99                 prototype);
    97         if (prototypeListView)
   100         if (prototypeListView)
    98             {
   101             {
       
   102             HbStyle style;
       
   103             qreal x;
       
   104             style.parameter("hb-param-graphic-size-primary-large", x);
       
   105             QSizeF size(x, x);
       
   106             mListViewIconSize = size.toSize();
    99             prototypeListView->setTextFormat(Qt::RichText);
   107             prototypeListView->setTextFormat(Qt::RichText);
   100 
       
   101             }
   108             }
   102         mListView->setModel(mModel, prototype);
   109         mListView->setModel(mModel, prototype);
   103 
   110 
   104         HbAbstractItemView::ItemAnimations noCreationAndRemovalAnimations =
   111         HbAbstractItemView::ItemAnimations noCreationAndRemovalAnimations =
   105                 HbAbstractItemView::All;
   112                 HbAbstractItemView::All;
   106         noCreationAndRemovalAnimations ^= HbAbstractItemView::Appear;
   113         noCreationAndRemovalAnimations ^= HbAbstractItemView::Appear;
   107         noCreationAndRemovalAnimations ^= HbAbstractItemView::Disappear;
   114         noCreationAndRemovalAnimations ^= HbAbstractItemView::Disappear;
   108 
       
   109         mListView->setEnabledAnimations(noCreationAndRemovalAnimations);
   115         mListView->setEnabledAnimations(noCreationAndRemovalAnimations);
   110         }
   116         }
   111     
       
   112 
   117 
   113     mSearchPanel = qobject_cast<HbSearchPanel *> (
   118     mSearchPanel = qobject_cast<HbSearchPanel *> (
   114             mDocumentLoader->findWidget(TUT_SEARCHPANEL_WIDGET));
   119             mDocumentLoader->findWidget(TUT_SEARCHPANEL_WIDGET));
   115     if (mSearchPanel)
   120     if (mSearchPanel)
   116         {
   121         {
   146 
   151 
   147     for (int i = 0; i < appUid.Count(); i++)
   152     for (int i = 0; i < appUid.Count(); i++)
   148         {
   153         {
   149         mIconArray.append(getAppIconFromAppId(appUid[i]));
   154         mIconArray.append(getAppIconFromAppId(appUid[i]));
   150         }
   155         }
   151 
       
   152 #ifdef OST_TRACE_COMPILER_IN_USE 
   156 #ifdef OST_TRACE_COMPILER_IN_USE 
   153     //start() the timers to avoid worrying abt having to start()/restart() later
   157     //start() the timers to avoid worrying abt having to start()/restart() later
   154     m_categorySearchApiTime.start();
   158     m_categorySearchApiTime.start();
   155     m_categorySearchUiTime.start();
   159     m_categorySearchUiTime.start();
   156     m_totalSearchUiTime.start();
   160     m_totalSearchUiTime.start();
   159 #endif
   163 #endif
   160     }
   164     }
   161 // ---------------------------------------------------------------------------
   165 // ---------------------------------------------------------------------------
   162 // SearchProgressiveState::~SearchProgressiveState
   166 // SearchProgressiveState::~SearchProgressiveState
   163 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
   164 //
       
   165 SearchProgressiveState::~SearchProgressiveState()
   168 SearchProgressiveState::~SearchProgressiveState()
   166     {
   169     {
   167     if (mAiwMgr)
   170     if (mAiwMgr)
   168         {
   171         {
   169         delete mAiwMgr;
   172         delete mAiwMgr;
   170         }
   173         }
   171    
       
   172     if (mModel)
   174     if (mModel)
   173         {
   175         {
   174         delete mModel;
   176         delete mModel;
   175         }
   177         }
   176     if (mDocumentLoader)
   178     if (mDocumentLoader)
   177         {
   179         {
   178         delete mDocumentLoader;
   180         delete mDocumentLoader;
   179         }
   181         }
   180 
       
   181     for (int i = 0; i < mSearchHandlerList.count(); i++)
   182     for (int i = 0; i < mSearchHandlerList.count(); i++)
   182         {
   183         {
   183         delete mSearchHandlerList.at(i);
   184         delete mSearchHandlerList.at(i);
   184         }
   185         }
   185 
   186     if(notesEditor)
   186     }
   187         {
   187 
   188         delete notesEditor;
       
   189         }
       
   190     }
   188 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   189 // SearchProgressiveState::constructHandlers
   192 // SearchProgressiveState::constructHandlers
   190 // ---------------------------------------------------------------------------
   193 // ---------------------------------------------------------------------------
   191 //
       
   192 void SearchProgressiveState::constructHandlers()
   194 void SearchProgressiveState::constructHandlers()
   193     {
   195     {
   194     InDeviceHandler* handler = NULL;
   196     InDeviceHandler* handler = NULL;
   195     for (int i = 0; i < totalcategories; i++)
   197     for (int i = 0; i < totalcategories; i++)
   196         {
   198         {
   249                 }
   251                 }
   250             }
   252             }
   251         mSearchHandlerList.append(handler);
   253         mSearchHandlerList.append(handler);
   252         }
   254         }
   253     }
   255     }
   254 
       
   255 // ---------------------------------------------------------------------------
   256 // ---------------------------------------------------------------------------
   256 // SearchProgressiveState::onEntry
   257 // SearchProgressiveState::onEntry
   257 // ---------------------------------------------------------------------------
   258 // ---------------------------------------------------------------------------
   258 //
       
   259 void SearchProgressiveState::onEntry(QEvent *event)
   259 void SearchProgressiveState::onEntry(QEvent *event)
   260     {
   260     {
   261     //  WMS_LOG << "::onEntry";
   261     //  WMS_LOG << "::onEntry";
   262     QState::onEntry(event);
   262     QState::onEntry(event);
   263 
       
   264     activateSignals();
   263     activateSignals();
   265 
   264 
   266     // If this is not the current view, we're getting back from plugin view  
   265     // If this is not the current view, we're getting back from plugin view  
   267     if (mMainWindow)
   266     if (mMainWindow)
   268         {
   267         {
   280     setSelectedCategories();
   279     setSelectedCategories();
   281     }
   280     }
   282 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   283 // SearchProgressiveState::onExit
   282 // SearchProgressiveState::onExit
   284 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   285 //
       
   286 void SearchProgressiveState::onExit(QEvent *event)
   284 void SearchProgressiveState::onExit(QEvent *event)
   287     {
   285     {
   288     QState::onExit(event);
   286     QState::onExit(event);
   289     deActivateSignals();
   287     deActivateSignals();
   290     }
   288     }
   291 
       
   292 // ---------------------------------------------------------------------------
   289 // ---------------------------------------------------------------------------
   293 // SearchProgressiveState::activateSignals
   290 // SearchProgressiveState::activateSignals
   294 // ---------------------------------------------------------------------------
   291 // ---------------------------------------------------------------------------
   295 //
       
   296 void SearchProgressiveState::activateSignals()
   292 void SearchProgressiveState::activateSignals()
   297     {
   293     {
   298     for (int i = 0; i < mSearchHandlerList.count(); i++)
   294     for (int i = 0; i < mSearchHandlerList.count(); i++)
   299         {
   295         {
   300         connect(mSearchHandlerList.at(i),
   296         connect(mSearchHandlerList.at(i),
   311         }
   307         }
   312     if (mSearchPanel)
   308     if (mSearchPanel)
   313         {
   309         {
   314         connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this,
   310         connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this,
   315                 SLOT(startNewSearch(QString)));
   311                 SLOT(startNewSearch(QString)));
   316 
       
   317         connect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
   312         connect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
   318                 SLOT(setSettings()));
   313                 SLOT(setSettings()));
   319 
       
   320         connect(mSearchPanel, SIGNAL(exitClicked()), this,
   314         connect(mSearchPanel, SIGNAL(exitClicked()), this,
   321                 SLOT(cancelSearch()));
   315                 SLOT(cancelSearch()));
   322         }
   316         }
   323     if (mModel)
   317     if (mModel)
   324         {
   318         {
   325         connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
   319         connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
   326                 SLOT(getrowsInserted()));
   320                 SLOT(getrowsInserted()));
   327 
       
   328         connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
   321         connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
   329                 SLOT(getrowsRemoved()));
   322                 SLOT(getrowsRemoved()));
   330         }
   323         }
   331     }
   324     }
   332 // ---------------------------------------------------------------------------
   325 // ---------------------------------------------------------------------------
   333 // SearchProgressiveState::deActivateSignals
   326 // SearchProgressiveState::deActivateSignals
   334 // ---------------------------------------------------------------------------
   327 // ---------------------------------------------------------------------------
   335 //
       
   336 void SearchProgressiveState::deActivateSignals()
   328 void SearchProgressiveState::deActivateSignals()
   337     {
   329     {
   338     for (int i = 0; i < mSearchHandlerList.count(); i++)
   330     for (int i = 0; i < mSearchHandlerList.count(); i++)
   339         {
   331         {
   340         disconnect(mSearchHandlerList.at(i),
   332         disconnect(mSearchHandlerList.at(i),
   351         }
   343         }
   352     if (mSearchPanel)
   344     if (mSearchPanel)
   353         {
   345         {
   354         disconnect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this,
   346         disconnect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this,
   355                 SLOT(startNewSearch(QString)));
   347                 SLOT(startNewSearch(QString)));
   356 
       
   357         disconnect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
   348         disconnect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
   358                 SLOT(setSettings()));
   349                 SLOT(setSettings()));
   359 
       
   360         disconnect(mSearchPanel, SIGNAL(exitClicked()), this,
   350         disconnect(mSearchPanel, SIGNAL(exitClicked()), this,
   361                 SLOT(cancelSearch()));
   351                 SLOT(cancelSearch()));
   362         }
   352         }
   363     if (mModel)
   353     if (mModel)
   364         {
   354         {
   365         disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
   355         disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
   366                 SLOT(getrowsInserted()));
   356                 SLOT(getrowsInserted()));
   367 
       
   368         disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
   357         disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
   369                 SLOT(getrowsRemoved()));
   358                 SLOT(getrowsRemoved()));
   370         }
   359         }
   371     }
   360     }
   372 // ---------------------------------------------------------------------------
   361 // ---------------------------------------------------------------------------
   373 // SearchProgressiveState::onAsyncSearchComplete
   362 // SearchProgressiveState::onAsyncSearchComplete
   374 // ---------------------------------------------------------------------------
   363 // ---------------------------------------------------------------------------
   375 //
       
   376 void SearchProgressiveState::onAsyncSearchComplete(int aError,
   364 void SearchProgressiveState::onAsyncSearchComplete(int aError,
   377         int aResultCount)
   365         int aResultCount)
   378     {
   366     {
   379     PERF_CAT_API_ENDLOG
   367     PERF_CAT_API_ENDLOG
   380     PERF_CAT_HITS_ENDLOG
   368     PERF_CAT_HITS_ENDLOG
   381 
       
   382     if (aError != 0)
   369     if (aError != 0)
   383         {
   370         {
   384         //some error print logs
   371         //some error print logs
   385         searchOnCategory(mSearchString);
   372         searchOnCategory(mSearchString);
   386         return;
   373         return;
   399         }
   386         }
   400     }
   387     }
   401 // ---------------------------------------------------------------------------
   388 // ---------------------------------------------------------------------------
   402 // SearchProgressiveState::onGetDocumentComplete
   389 // SearchProgressiveState::onGetDocumentComplete
   403 // ---------------------------------------------------------------------------
   390 // ---------------------------------------------------------------------------
   404 //
       
   405 void SearchProgressiveState::onGetDocumentComplete(int aError,
   391 void SearchProgressiveState::onGetDocumentComplete(int aError,
   406         QCPixDocument* aDoc)
   392         QCPixDocument* aDoc)
   407     {
   393     {
   408     PERF_CAT_GETDOC_TIME_ACCUMULATE
   394     PERF_CAT_GETDOC_TIME_ACCUMULATE
   409     if (aDoc == NULL || aError != 0)
   395     if (aDoc == NULL || aError != 0)
   410         return;
   396         return;
   411     QStringList liststr;
   397     QStringList liststr;
   412     QString secondrow = aDoc->excerpt();
   398     QString secondrow = aDoc->excerpt();
   413     QString firstrow;
   399     QString firstrow;
   414 
       
   415     //-------------- html tag creation-------------------
   400     //-------------- html tag creation-------------------
   416     QString htmlTagPre = QString("<u>");
   401    /* QString htmlTagPre = QString("<u>");
   417     QString htmlTagPost = QString("</u>");
   402     QString htmlTagPost = QString("</u>");
   418     int insertpt = secondrow.indexOf(mOriginalString, 0, Qt::CaseInsensitive);
   403     int insertpt = secondrow.indexOf(mOriginalString, 0, Qt::CaseInsensitive);
   419     if (insertpt >= 0)
   404     if (insertpt >= 0)
   420         {
   405         {
   421         secondrow.insert(insertpt, htmlTagPre);
   406         secondrow.insert(insertpt, htmlTagPre);
   422 
   407 
   423         secondrow.insert(insertpt + mOriginalString.length()
   408         secondrow.insert(insertpt + mOriginalString.length()
   424                 + htmlTagPre.length(), htmlTagPost);
   409                 + htmlTagPre.length(), htmlTagPost);
   425         }
   410         }
   426     //--------------------Html Tag Creation completed------------
   411 */    //--------------------Html Tag Creation completed------------
   427     QStandardItem* listitem = new QStandardItem();
   412     QStandardItem* listitem = new QStandardItem();
   428 
   413 
   429     if (aDoc->baseAppClass().contains("contact"))
   414     if (aDoc->baseAppClass().contains("contact"))
   430         {
   415         {
   431         QString givename;
   416         QStringList docsList = filterDoc(aDoc, "GivenName", "FamilyName");
   432         QString familyname;
   417         if (docsList.value(0, "").length())
   433         bool bgivenname = false;
   418             {
   434         bool bfamilyname = false;
   419             firstrow.append(docsList.at(0));
   435         for (int i = 0; i < aDoc->fieldCount(); i++)
   420             }
   436             {
   421         if (docsList.value(1, "").length())
   437             if (!bgivenname && aDoc->field(i).name().contains("GivenName"))
       
   438                 {
       
   439                 givename.append(aDoc->field(i).value());
       
   440                 bgivenname = true;
       
   441                 }
       
   442             if (!bfamilyname && aDoc->field(i).name().contains("FamilyName"))
       
   443                 {
       
   444                 familyname.append(aDoc->field(i).value());
       
   445                 bfamilyname = true;
       
   446                 }
       
   447             if (bgivenname && bfamilyname)
       
   448                 break;
       
   449             }
       
   450         if (givename.length())
       
   451             {
       
   452             firstrow.append(givename);
       
   453             }
       
   454         if (familyname.length())
       
   455             {
   422             {
   456             if (firstrow.length())
   423             if (firstrow.length())
   457                 firstrow.append(" ");
   424                 firstrow.append(" ");
   458             firstrow.append(familyname);
   425             firstrow.append(docsList.at(1));
   459             }
   426             }
   460         if (firstrow.length() == 0)
   427         if (firstrow.length() == 0)
   461             {
   428             {
   462             firstrow = hbTrId("txt_phob_list_unknown");
   429             firstrow = hbTrId("txt_phob_dblist_unnamed");
   463             }
   430             }
   464         liststr << firstrow << secondrow;
   431         liststr << firstrow << secondrow;
   465         listitem->setData(mIconArray.at(0), Qt::DecorationRole);
   432         listitem->setData(mIconArray.at(0), Qt::DecorationRole);
   466         }
   433         }
   467     else if (aDoc->baseAppClass().contains("audio"))
   434     else if (aDoc->baseAppClass().contains("audio"))
   468         {
   435         {
   469         firstrow.append(filterDoc(aDoc, "Title"));
   436         QStringList audioList = filterDoc(aDoc, "Title", "MediaId");
       
   437         if (audioList.value(0, "").length())
       
   438             {
       
   439             firstrow.append(audioList.at(0));
       
   440             }
   470         if (firstrow.length() == 0)
   441         if (firstrow.length() == 0)
   471             {
   442             {
   472             firstrow = hbTrId("txt_mus_dblist_val_unknown4");
   443             firstrow = hbTrId("txt_mus_dblist_val_unknown4");
   473             }
   444             }
   474         liststr << firstrow << secondrow;
   445         liststr << firstrow << secondrow;
   475         listitem->setData(mIconArray.at(1), Qt::DecorationRole);
   446         listitem->setData(mIconArray.at(1), Qt::DecorationRole);
       
   447         if (audioList.value(1, "").length())
       
   448             {
       
   449             listitem->setData(audioList.at(1), Qt::UserRole + 2);
       
   450             }
   476         }
   451         }
   477     else if (aDoc->baseAppClass().contains("video"))
   452     else if (aDoc->baseAppClass().contains("video"))
   478         {
   453         {
   479         firstrow.append(filterDoc(aDoc, "Title"));
   454         QStringList videoList = filterDoc(aDoc, "Title", "MediaId","Name");
   480         if (firstrow.length() == 0)
   455         if (videoList.value(0, "").length())
   481             {
   456             {
   482             firstrow.append(filterDoc(aDoc, "Name"));
   457             firstrow.append(videoList.at(0));
       
   458             }
       
   459         if (firstrow.length() == 0 && videoList.value(2, "").length())
       
   460             {
       
   461             firstrow.append(videoList.at(2));
   483             }
   462             }
   484         liststr << firstrow << secondrow;
   463         liststr << firstrow << secondrow;
   485         listitem->setData(mIconArray.at(2), Qt::DecorationRole);
   464         listitem->setData(mIconArray.at(2), Qt::DecorationRole);
       
   465         if (videoList.value(1, "").length())
       
   466             {
       
   467             listitem->setData(videoList.at(1), Qt::UserRole + 2);
       
   468             }
   486         }
   469         }
   487     else if (aDoc->baseAppClass().contains("image"))
   470     else if (aDoc->baseAppClass().contains("image"))
   488         {
   471         {
   489         firstrow.append(filterDoc(aDoc, "Name"));
   472         QStringList imageList = filterDoc(aDoc, "Name", "MediaId");
       
   473         if (imageList.value(0, "").length())
       
   474             {
       
   475             firstrow.append(imageList.at(0));
       
   476             }
   490         liststr << firstrow << secondrow;
   477         liststr << firstrow << secondrow;
   491         listitem->setData(mIconArray.at(3), Qt::DecorationRole);
   478         listitem->setData(mIconArray.at(3), Qt::DecorationRole);
       
   479         if (imageList.value(1, "").length())
       
   480             {
       
   481             listitem->setData(imageList.at(1), Qt::UserRole + 2);
       
   482             }
   492         }
   483         }
   493     else if (aDoc->baseAppClass().contains("msg"))
   484     else if (aDoc->baseAppClass().contains("msg"))
   494         {
   485         {
   495         QString subject;
   486         QStringList msgList = filterDoc(aDoc, "Subject", "Body");
   496         QString body;
   487         if (msgList.value(0, "").length())
   497         bool bsubject = false;
   488             {
   498         bool bbody = false;
   489             firstrow.append(msgList.at(0));
   499         for (int i = 0; i < aDoc->fieldCount(); i++)
       
   500             {
       
   501             if (!bsubject && aDoc->field(i).name().contains("Subject"))
       
   502                 {
       
   503                 subject.append(aDoc->field(i).value());
       
   504                 bsubject = true;
       
   505                 }
       
   506             if (!bbody && aDoc->field(i).name().contains("Body"))
       
   507                 {
       
   508                 body.append(aDoc->field(i).value());
       
   509                 bbody = true;
       
   510                 }
       
   511             if (bsubject && bbody)
       
   512                 break;
       
   513             }
       
   514         if (subject.length())
       
   515             {
       
   516             firstrow.append(subject);
       
   517             }
   490             }
   518         else
   491         else
   519             {
   492             {
   520             firstrow.append(body);
   493             if (msgList.value(1, "").length())
       
   494                 firstrow.append(msgList.at(1));
   521             }
   495             }
   522         if (firstrow.length() == 0)
   496         if (firstrow.length() == 0)
   523             {
   497             {
   524             firstrow = " ";// space if subject and body are missing
   498             firstrow = " ";// space if subject and body are missing
   525             }
   499             }
   531         firstrow.append(filterDoc(aDoc, "Subject"));
   505         firstrow.append(filterDoc(aDoc, "Subject"));
   532         liststr << firstrow << secondrow;
   506         liststr << firstrow << secondrow;
   533         }
   507         }
   534     else if (aDoc->baseAppClass().contains("calendar"))
   508     else if (aDoc->baseAppClass().contains("calendar"))
   535         {
   509         {
   536         firstrow.append(filterDoc(aDoc, "Description"));
   510         firstrow.append(filterDoc(aDoc, "Summary"));
   537         if (firstrow.length() == 0)
   511         if (firstrow.length() == 0)
   538             {
   512             {
   539             firstrow = hbTrId("txt_calendar_preview_unnamed");
   513             firstrow = hbTrId("txt_calendar_preview_unnamed");
   540             }
   514             }
   541 
   515 
   548         if (firstrow.length() == 0)
   522         if (firstrow.length() == 0)
   549             {
   523             {
   550             firstrow = hbTrId("txt_notes_dblist_unnamed");
   524             firstrow = hbTrId("txt_notes_dblist_unnamed");
   551             }
   525             }
   552         liststr << firstrow << secondrow;
   526         liststr << firstrow << secondrow;
       
   527         listitem->setData(mIconArray.at(7), Qt::DecorationRole);
   553         }
   528         }
   554     else if (aDoc->baseAppClass().contains("applications"))
   529     else if (aDoc->baseAppClass().contains("applications"))
   555         {
   530         {
   556         liststr << secondrow;
   531         firstrow.append(filterDoc(aDoc, "Name"));
       
   532         liststr << firstrow;
   557         bool ok;
   533         bool ok;
   558         listitem->setData(getAppIconFromAppId(TUid::Uid(aDoc->docId().toInt(
   534         listitem->setData(getAppIconFromAppId(TUid::Uid(aDoc->docId().toInt(
   559                 &ok, 16))), Qt::DecorationRole);
   535                 &ok, 16))), Qt::DecorationRole);
   560         }
   536         }
   561     else if (aDoc->baseAppClass().contains("bookmark"))
   537     else if (aDoc->baseAppClass().contains("bookmark"))
   567             }
   543             }
   568         liststr << firstrow << secondrow;
   544         liststr << firstrow << secondrow;
   569         }
   545         }
   570     else if (aDoc->baseAppClass().contains("file"))
   546     else if (aDoc->baseAppClass().contains("file"))
   571         {
   547         {
   572         firstrow.append(filterDoc(aDoc, "BaseName"));
   548         firstrow.append(filterDoc(aDoc, "Name"));
   573         if (firstrow.length() == 0)
   549         if (firstrow.length() == 0)
   574             firstrow = aDoc->baseAppClass();
   550             firstrow = aDoc->baseAppClass();
   575         liststr << firstrow << secondrow;
   551         liststr << firstrow << secondrow;
   576         listitem->setData(mIconArray.at(9), Qt::DecorationRole);
   552         listitem->setData(mIconArray.at(9), Qt::DecorationRole);
   577         }
   553         }
   578 
       
   579     listitem->setData(liststr, Qt::DisplayRole);
   554     listitem->setData(liststr, Qt::DisplayRole);
   580     listitem->setData(aDoc->docId(), Qt::UserRole);
   555     listitem->setData(aDoc->docId(), Qt::UserRole);
   581     listitem->setData(aDoc->baseAppClass(), Qt::UserRole + 1);
   556     listitem->setData(aDoc->baseAppClass(), Qt::UserRole + 1);
   582 
       
   583     mModel->appendRow(listitem);
   557     mModel->appendRow(listitem);
   584 
       
   585     delete aDoc;
   558     delete aDoc;
   586     }
   559     }
   587 // ---------------------------------------------------------------------------
   560 // ---------------------------------------------------------------------------
   588 // SearchProgressiveState::getSettingCategory
   561 // SearchProgressiveState::getSettingCategory
   589 // ---------------------------------------------------------------------------
   562 // ---------------------------------------------------------------------------
   590 //
       
   591 void SearchProgressiveState::getSettingCategory(int item, bool avalue)
   563 void SearchProgressiveState::getSettingCategory(int item, bool avalue)
   592     {
   564     {
   593     mSelectedCategory.insert(item, avalue);
   565     mSelectedCategory.insert(item, avalue);
   594     }
   566     }
   595 // ---------------------------------------------------------------------------
   567 // ---------------------------------------------------------------------------
   596 // SearchProgressiveState::getrowsInserted
   568 // SearchProgressiveState::getrowsInserted
   597 // ---------------------------------------------------------------------------
   569 // ---------------------------------------------------------------------------
   598 //
       
   599 void SearchProgressiveState::getrowsInserted()
   570 void SearchProgressiveState::getrowsInserted()
   600     {
   571     {
   601     mResultparser++;
   572     mResultparser++;
   602     if (mResultparser < mResultcount)
   573     if (mResultparser < mResultcount)
   603         {
   574         {
   611         }
   582         }
   612     }
   583     }
   613 // ---------------------------------------------------------------------------
   584 // ---------------------------------------------------------------------------
   614 // SearchProgressiveState::getrowsRemoved
   585 // SearchProgressiveState::getrowsRemoved
   615 // ---------------------------------------------------------------------------
   586 // ---------------------------------------------------------------------------
   616 //
       
   617 void SearchProgressiveState::getrowsRemoved()
   587 void SearchProgressiveState::getrowsRemoved()
   618     {
   588     {
   619     if (mModel->rowCount() != 0)
   589     if (mModel->rowCount() != 0)
   620         {
   590         {
   621         mModel->removeRow(0);
   591         mModel->removeRow(0);
   624         {
   594         {
   625         mListView->reset();
   595         mListView->reset();
   626         if (mOriginalString.length())
   596         if (mOriginalString.length())
   627             {
   597             {
   628             mDatabasecount = 0;
   598             mDatabasecount = 0;
       
   599             /*mSearchString = "$prefix(\"";
       
   600             mSearchString += mOriginalString;
       
   601             mSearchString += "\")";*/
   629             mSearchString = mOriginalString;
   602             mSearchString = mOriginalString;
   630             mSearchString.append('*');
   603             mSearchString.append('*');
   631             searchOnCategory(mSearchString);
   604             searchOnCategory(mSearchString);
   632             }
   605             }
   633         }
   606         }
   634     }
   607     }
   635 // ---------------------------------------------------------------------------
   608 // ---------------------------------------------------------------------------
   636 // SearchProgressiveState::openResultitem
   609 // SearchProgressiveState::openResultitem
   637 // ---------------------------------------------------------------------------
   610 // ---------------------------------------------------------------------------
   638 //
       
   639 void SearchProgressiveState::openResultitem(QModelIndex index)
   611 void SearchProgressiveState::openResultitem(QModelIndex index)
   640     {
   612     {
   641     QStandardItem* item = mModel->itemFromIndex(index);
   613     QStandardItem* item = mModel->itemFromIndex(index);
   642     QString baseclass = item->data(Qt::UserRole + 1).toString();
   614     QList<QVariant> args;
   643 
       
   644     QVariant retValue;
       
   645     bool t;
   615     bool t;
   646     if (baseclass.contains("contact"))
   616     mRequest = NULL;
   647         {
   617     if (item->data(Qt::UserRole + 1).toString().contains("contact"))
   648 
   618         {
   649         mRequest = mAiwMgr->create("com.nokia.services.phonebookservices",
   619         mRequest = mAiwMgr->create("com.nokia.services.phonebookservices",
   650                 "Fetch", "open(int)", false);
   620                 "Fetch", "open(int)", false);
       
   621 
       
   622         int uid = (item->data(Qt::UserRole)).toInt(&t);
       
   623         args << uid;
       
   624         }
       
   625     else if (item->data(Qt::UserRole + 1).toString().contains("bookmark"))
       
   626         {
       
   627 
       
   628         }
       
   629     else if (item->data(Qt::UserRole + 1).toString().contains("calendar"))
       
   630         {
       
   631         QDir pluginDir = QDir(QString("z:/resource/qt/plugins/calendar"));
       
   632         QPluginLoader *calAgandaViewerPluginLoader = new QPluginLoader(
       
   633                 pluginDir.absoluteFilePath(QString(
       
   634                         "agendaeventviewerplugin.qtplugin")));
       
   635 
       
   636         calAgandaViewerPluginInstance = qobject_cast<
       
   637                 EventViewerPluginInterface *> (
       
   638                 calAgandaViewerPluginLoader->instance());
       
   639 
       
   640         connect(calAgandaViewerPluginInstance, SIGNAL(viewingCompleted()),
       
   641                 this, SLOT(_viewingCompleted()));
       
   642 
       
   643         calAgandaViewerPluginInstance->viewEvent(
       
   644                 item->data(Qt::UserRole).toInt(),
       
   645                 EventViewerPluginInterface::ActionEditDelete, NULL);
       
   646         }
       
   647     else if (item->data(Qt::UserRole + 1).toString().contains("applications"))
       
   648         {
       
   649         TRAPD(err,
       
   650                     {LaunchApplicationL(TUid::Uid((item->data(Qt::UserRole)).toString().toInt(&t, 16)));})
       
   651         if (err == KErrNone)
       
   652             {
       
   653             }
       
   654         }
       
   655     else if (item->data(Qt::UserRole + 1).toString().contains("file"))
       
   656         {
       
   657         }
       
   658     else if (item->data(Qt::UserRole + 1).toString().contains("video"))
       
   659         {
       
   660         mRequest = mAiwMgr->create("com.nokia.videos", "IVideoView",
       
   661                 "playMedia(QString)", false);
       
   662 
       
   663         QString uid = getDrivefromMediaId(
       
   664                 item->data(Qt::UserRole + 2).toString());
       
   665         uid.append(':');
       
   666         uid.append(item->data(Qt::UserRole).toString());
       
   667         args << uid;
       
   668         }
       
   669     else if (item->data(Qt::UserRole + 1).toString().contains("audio"))
       
   670         {
       
   671         QString uid = getDrivefromMediaId(
       
   672                 item->data(Qt::UserRole + 2).toString());
       
   673         uid.append(':');
       
   674         uid.append(item->data(Qt::UserRole).toString());
       
   675         mRequest = mAiwMgr->create("musicplayer",
       
   676                 "com.nokia.symbian.IFileView", "view(QString)", false);
       
   677         args << uid;
       
   678         }
       
   679     else if (item->data(Qt::UserRole + 1).toString().contains("image"))
       
   680         {
       
   681         QString uid = getDrivefromMediaId(
       
   682                 item->data(Qt::UserRole + 2).toString());
       
   683         uid.append(':');
       
   684         uid.append(item->data(Qt::UserRole).toString());
       
   685         mRequest = mAiwMgr->create("com.nokia.services.media",
       
   686                 "com.nokia.symbian.IFileView", "view(QString)", false);
       
   687         args << uid;
       
   688         }
       
   689     else if (item->data(Qt::UserRole + 1).toString().contains("notes"))
       
   690         {
       
   691         if (!notesEditor)
       
   692             {
       
   693             notesEditor = new NotesEditor(this);
       
   694             }
       
   695         notesEditor->edit(item->data(Qt::UserRole).toInt());
       
   696         }
       
   697     else if (item->data(Qt::UserRole + 1).toString().contains("msg"))
       
   698         {
       
   699         mRequest = mAiwMgr->create("com.nokia.services.hbserviceprovider",
       
   700                 "conversationview", "view(int)", false);
       
   701 
       
   702         int uid = (item->data(Qt::UserRole)).toInt(&t);
       
   703         args << uid;
       
   704         }
       
   705     if (mRequest)
       
   706         {
   651         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this,
   707         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this,
   652                 SLOT(handleOk(const QVariant&)));
   708                 SLOT(handleOk(const QVariant&)));
   653         // Connect error handling signal or apply lastError function instead.
       
   654         connect(mRequest, SIGNAL(requestError(int,const QString&)), this,
   709         connect(mRequest, SIGNAL(requestError(int,const QString&)), this,
   655                 SLOT(handleError(int,const QString&)));
   710                 SLOT(handleError(int,const QString&)));// Connect error handling signal or apply lastError function instead.
   656 
       
   657         if (!mRequest)
       
   658             {
       
   659             qDebug() << "AIW-ERROR: NULL request";
       
   660             return;
       
   661             }
       
   662 
       
   663         int uid = (item->data(Qt::UserRole)).toInt(&t);
       
   664         QList<QVariant> args;
       
   665         args << uid;
       
   666         mRequest->setArguments(args);
   711         mRequest->setArguments(args);
   667         // Make the request
   712         if (!mRequest->send())// Make the request
   668         if (!mRequest->send())
       
   669             {
   713             {
   670             qDebug() << "AIW-ERROR: Send failed" << mRequest->lastError();
   714             qDebug() << "AIW-ERROR: Send failed" << mRequest->lastError();
   671             }
   715             }
   672         delete mRequest;
   716         disconnect(mRequest, SIGNAL(requestOk(const QVariant&)), this,
   673 
       
   674         }
       
   675     else if (baseclass.contains("msg"))
       
   676         {
       
   677         int uid = (item->data(Qt::UserRole)).toInt(&t);
       
   678 
       
   679         mRequest = mAiwMgr->create("com.nokia.services.hbserviceprovider",
       
   680                 "conversationview", "view(qint64)", false);
       
   681         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this,
       
   682                 SLOT(handleOk(const QVariant&)));
   717                 SLOT(handleOk(const QVariant&)));
   683         // Connect error handling signal or apply lastError function instead.
   718         disconnect(mRequest, SIGNAL(requestError(int,const QString&)), this,
   684         connect(mRequest, SIGNAL(requestError(int,const QString&)), this,
   719                 SLOT(handleError(int,const QString&)));// Connect error handling signal or apply lastError function instead.
   685                 SLOT(handleError(int,const QString&)));
   720         mRequest->deleteLater();
   686 
   721         }
   687         if (!mRequest)
   722     else
   688             {
   723         {
   689             qDebug() << "AIW-ERROR: NULL request";
   724         qDebug() << "AIW-ERROR: NULL request";
   690             return;
   725         return;
   691             }
   726         }
   692 
       
   693         QList<QVariant> args;
       
   694         args << uid;
       
   695         retValue = mRequest->send();
       
   696         delete mRequest;
       
   697         }
       
   698     else if (baseclass.contains("video"))
       
   699         {
       
   700         QString uid = item->data(Qt::UserRole).toString();
       
   701         mRequest = mAiwMgr->create("com.nokia.videos", "IVideoView",
       
   702                 "playMedia(QString)", false);
       
   703         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this,
       
   704                 SLOT(handleOk(const QVariant&)));
       
   705         // Connect error handling signal or apply lastError function instead.
       
   706         connect(mRequest, SIGNAL(requestError(int,const QString&)), this,
       
   707                 SLOT(handleError(int,const QString&)));
       
   708 
       
   709         QList<QVariant> args;
       
   710         args << uid;
       
   711         retValue = mRequest->send();
       
   712         delete mRequest;
       
   713         }
       
   714 
       
   715     }
   727     }
   716 // ---------------------------------------------------------------------------
   728 // ---------------------------------------------------------------------------
   717 // SearchProgressiveState::handleOk
   729 // SearchProgressiveState::handleOk
   718 // ---------------------------------------------------------------------------
   730 // ---------------------------------------------------------------------------
   719 //
   731 void SearchProgressiveState::handleOk(const QVariant& var)
   720 void SearchProgressiveState::handleOk(const QVariant& /*var*/)
   732     {
   721     {
   733     Q_UNUSED(var);
   722 
       
   723     }
   734     }
   724 // ---------------------------------------------------------------------------
   735 // ---------------------------------------------------------------------------
   725 // SearchProgressiveState::handleError
   736 // SearchProgressiveState::handleError
   726 // ---------------------------------------------------------------------------
   737 // ---------------------------------------------------------------------------
   727 //
   738 void SearchProgressiveState::handleError(int ret, const QString& var)
   728 void SearchProgressiveState::handleError(int /*ret*/, const QString& /*var*/)
   739     {
   729     {
   740     Q_UNUSED(ret);
   730 
   741     Q_UNUSED(var);
   731     }
   742     }
   732 // ---------------------------------------------------------------------------
   743 // ---------------------------------------------------------------------------
   733 // SearchProgressiveState::createSuggestionLink
   744 // SearchProgressiveState::createSuggestionLink
   734 // ---------------------------------------------------------------------------
   745 // ---------------------------------------------------------------------------
   735 //
       
   736 void SearchProgressiveState::createSuggestionLink(bool aFlag)
   746 void SearchProgressiveState::createSuggestionLink(bool aFlag)
   737     {
   747     {
   738     QStandardItem* listitem = new QStandardItem();    
   748     QStandardItem* listitem = new QStandardItem();   
   739     QString htmlKeyword = QString("<u>%1</u>").arg(mOriginalString);
       
   740     if (!aFlag)
   749     if (!aFlag)
   741         {
   750         {
   742         QString linkString = QString(hbTrId(
   751         QString linkString = QString(hbTrId("txt_search_list_search_for_1").arg(mOriginalString));
   743                 "txt_search_list_search_for_1_on_2").arg(htmlKeyword));
       
   744         mLinkindex = mModel->rowCount();
   752         mLinkindex = mModel->rowCount();
   745         listitem->setData(linkString, Qt::DisplayRole);
   753         listitem->setData(linkString, Qt::DisplayRole);
   746  
       
   747         mModel->appendRow(listitem);
   754         mModel->appendRow(listitem);
   748         }
   755         }
   749 
       
   750     }
   756     }
   751 // ---------------------------------------------------------------------------
   757 // ---------------------------------------------------------------------------
   752 // SearchProgressiveState::noResultsFound
   758 // SearchProgressiveState::noResultsFound
   753 // ---------------------------------------------------------------------------
   759 // ---------------------------------------------------------------------------
   754 //
       
   755 void SearchProgressiveState::noResultsFound(QString aKeyword)
   760 void SearchProgressiveState::noResultsFound(QString aKeyword)
   756     {
   761     {
   757     if (aKeyword.length())
   762     if (aKeyword.length())
   758         {
   763         {
   759         QStandardItem* listitem = new QStandardItem();
   764         QStandardItem* listitem = new QStandardItem();
   760         QString noResultMsg = QString("<align=\"center\">" + hbTrId(
   765         QString noResultMsg = QString("<align=\"center\">" + hbTrId(
   761                 "txt_search_results_no_match_found"));
   766                 "txt_search_list_no_match_found"));
   762         listitem->setData(noResultMsg, Qt::DisplayRole);
   767         listitem->setData(noResultMsg, Qt::DisplayRole);
   763         mModel->appendRow(listitem);
   768         mModel->appendRow(listitem);
   764         }
   769         }
   765 
       
   766     }
   770     }
   767 // ---------------------------------------------------------------------------
   771 // ---------------------------------------------------------------------------
   768 // SearchProgressiveState::clear
   772 // SearchProgressiveState::clear
   769 // ---------------------------------------------------------------------------
   773 // ---------------------------------------------------------------------------
   770 //
       
   771 void SearchProgressiveState::clear()
   774 void SearchProgressiveState::clear()
   772     {
   775     {
   773     if (mModel)
   776     if (mModel)
   774         {
   777         {
   775         mModel->removeRows(0, mModel->rowCount());      
   778         mModel->removeRows(0, mModel->rowCount());
   776         }
   779         }
   777     }
   780     }
   778 // ---------------------------------------------------------------------------
   781 // ---------------------------------------------------------------------------
   779 // SearchProgressiveState::searchOnCategory
   782 // SearchProgressiveState::searchOnCategory
   780 // ---------------------------------------------------------------------------
   783 // ---------------------------------------------------------------------------
   781 //
       
   782 void SearchProgressiveState::searchOnCategory(const QString aKeyword)
   784 void SearchProgressiveState::searchOnCategory(const QString aKeyword)
   783     {
   785     {
   784 #ifdef OST_TRACE_COMPILER_IN_USE
   786 #ifdef OST_TRACE_COMPILER_IN_USE
   785     if( mDatabasecount != 0 ){//Search just started.
   787     if( mDatabasecount != 0 )
       
   788         {//Search just started.
   786         PERF_CAT_UI_ENDLOG
   789         PERF_CAT_UI_ENDLOG
   787     }
   790         }
   788     PERF_CAT_UI_TIME_RESTART
   791     PERF_CAT_UI_TIME_RESTART
   789 #endif
   792 #endif
   790     mResultparser = 0;
   793     mResultparser = 0;
   791     mResultcount = 0;
   794     mResultcount = 0;
   792     if (mDatabasecount < mTemplist.count())
   795     if (mDatabasecount < mTemplist.count())
   793         {
   796         {
   794         QString str = mTemplist.at(mDatabasecount);
   797         if (mTemplist.at(mDatabasecount).contains("selectall"))
   795         if (str.contains("selectall"))
   798             {
   796             {
   799             mSearchHandler = mSearchHandlerList.at(0);
   797             // mSearchHandler = mSearchHandlerList.at(0);
   800             }
   798             }
   801         else if (mTemplist.at(mDatabasecount).contains("contact"))
   799         else if (str.contains("contact"))
       
   800             {
   802             {
   801             mSearchHandler = mSearchHandlerList.at(1);
   803             mSearchHandler = mSearchHandlerList.at(1);
   802             }
   804             }
   803         else if (str.contains("media"))
   805         else if (mTemplist.at(mDatabasecount).contains("media"))
   804             {
   806             {
   805             mSearchHandler = mSearchHandlerList.at(2);
   807             mSearchHandler = mSearchHandlerList.at(2);
   806             }
   808             }
   807         else if (str.contains("msg"))
   809         else if (mTemplist.at(mDatabasecount).contains("msg"))
   808             {
   810             {
   809             mSearchHandler = mSearchHandlerList.at(3);
   811             mSearchHandler = mSearchHandlerList.at(3);
   810             }
   812             }
   811         else if (str.contains("email"))
   813         else if (mTemplist.at(mDatabasecount).contains("email"))
   812             {
   814             {
   813             mSearchHandler = mSearchHandlerList.at(4);
   815             mSearchHandler = mSearchHandlerList.at(4);
   814             }
   816             }
   815         else if (str.contains("calendar"))
   817         else if (mTemplist.at(mDatabasecount).contains("calendar"))
   816             {
   818             {
   817             mSearchHandler = mSearchHandlerList.at(5);
   819             mSearchHandler = mSearchHandlerList.at(5);
   818             }
   820             }
   819         else if (str.contains("notes"))
   821         else if (mTemplist.at(mDatabasecount).contains("notes"))
   820             {
   822             {
   821             mSearchHandler = mSearchHandlerList.at(6);
   823             mSearchHandler = mSearchHandlerList.at(6);
   822             }
   824             }
   823         else if (str.contains("applications"))
   825         else if (mTemplist.at(mDatabasecount).contains("applications"))
   824             {
   826             {
   825             mSearchHandler = mSearchHandlerList.at(7);
   827             mSearchHandler = mSearchHandlerList.at(7);
   826             }
   828             }
   827         else if (str.contains("file"))
   829         else if (mTemplist.at(mDatabasecount).contains("file"))
   828             {
   830             {
   829             mSearchHandler = mSearchHandlerList.at(8);
   831             mSearchHandler = mSearchHandlerList.at(8);
   830             }
   832             }
   831         else if (str.contains("bookmark"))
   833         else if (mTemplist.at(mDatabasecount).contains("bookmark"))
   832             {
   834             {
   833             mSearchHandler = mSearchHandlerList.at(9);
   835             mSearchHandler = mSearchHandlerList.at(9);
   834             }
   836             }
   835         // mSearchHandler->setCategory(mTemplist.at(mDatabasecount));
   837         // mSearchHandler->setCategory(mTemplist.at(mDatabasecount));
   836         mDatabasecount++;
   838         mDatabasecount++;
   841             }
   843             }
   842         }
   844         }
   843     else if (mDatabasecount >= mTemplist.count())
   845     else if (mDatabasecount >= mTemplist.count())
   844         {
   846         {
   845         PERF_TOTAL_UI_ENDLOG
   847         PERF_TOTAL_UI_ENDLOG
   846         if (mListView->indexCount() == 0 && aKeyword.length() != 0)
   848         if (mModel->rowCount() == 0 && aKeyword.length() != 0)
   847             {
   849             {
   848             noResultsFound(mOriginalString);
   850             noResultsFound(mOriginalString);
   849             createSuggestionLink(0);
   851             createSuggestionLink(0);
   850             }
   852             }
   851         return;
   853         return;
   852         }
   854         }
   853 
       
   854     }
   855     }
   855 // ---------------------------------------------------------------------------
   856 // ---------------------------------------------------------------------------
   856 // SearchProgressiveState::startNewSearch
   857 // SearchProgressiveState::startNewSearch
   857 // ---------------------------------------------------------------------------
   858 // ---------------------------------------------------------------------------
   858 //
       
   859 void SearchProgressiveState::startNewSearch(const QString &aKeyword)
   859 void SearchProgressiveState::startNewSearch(const QString &aKeyword)
   860     {
   860     {
   861     PERF_CAT_TOTAL_TIME_RESTART
   861     PERF_CAT_TOTAL_TIME_RESTART
   862 
       
   863     mOriginalString = aKeyword.trimmed();
   862     mOriginalString = aKeyword.trimmed();
   864     for (int i = 0; i < mSearchHandlerList.count(); i++)
   863     for (int i = 0; i < mSearchHandlerList.count(); i++)
   865         {
   864         {
   866         mSearchHandlerList.at(i)->cancelLastSearch();
   865         mSearchHandlerList.at(i)->cancelLastSearch();
   867         }
   866         }
   871         }
   870         }
   872     else if (mOriginalString.length())
   871     else if (mOriginalString.length())
   873         {
   872         {
   874         mDatabasecount = 0;
   873         mDatabasecount = 0;
   875         mLinkindex = 0;
   874         mLinkindex = 0;
       
   875         //Prefix query
       
   876         /*mSearchString = "$prefix(\"";
       
   877         mSearchString += mOriginalString;
       
   878         mSearchString += "\")";*/
   876         mSearchString = mOriginalString;
   879         mSearchString = mOriginalString;
   877         mSearchString.append('*');
   880         mSearchString.append('*');
   878         searchOnCategory(mSearchString);
   881         searchOnCategory(mSearchString);
   879         }
   882         }
   880     }
   883     }
   881 // ---------------------------------------------------------------------------
   884 // ---------------------------------------------------------------------------
   882 // SearchProgressiveState::setSettings
   885 // SearchProgressiveState::setSettings
   883 // ---------------------------------------------------------------------------
   886 // ---------------------------------------------------------------------------
   884 //
       
   885 void SearchProgressiveState::setSettings()
   887 void SearchProgressiveState::setSettings()
   886     {
   888     {
   887     mTempSelectedCategory = mSelectedCategory;
   889     mTempSelectedCategory = mSelectedCategory;
   888     emit settingsState();
   890     emit settingsState();
   889     }
   891     }
   890 // ---------------------------------------------------------------------------
   892 // ---------------------------------------------------------------------------
   891 // SearchProgressiveState::_customizeGoButton
   893 // SearchProgressiveState::_customizeGoButton
   892 // ---------------------------------------------------------------------------
   894 // ---------------------------------------------------------------------------
   893 //
       
   894 void SearchProgressiveState::_customizeGoButton(bool avalue)
   895 void SearchProgressiveState::_customizeGoButton(bool avalue)
   895     {
   896     {
   896     if (mSearchPanel)
   897     if (mSearchPanel)
   897         {
   898         {
   898         if (avalue)
   899         if (avalue)
   906         }
   907         }
   907     }
   908     }
   908 // ---------------------------------------------------------------------------
   909 // ---------------------------------------------------------------------------
   909 // SearchProgressiveState::settingsaction
   910 // SearchProgressiveState::settingsaction
   910 // ---------------------------------------------------------------------------
   911 // ---------------------------------------------------------------------------
   911 //
       
   912 void SearchProgressiveState::settingsaction(bool avalue)
   912 void SearchProgressiveState::settingsaction(bool avalue)
   913     {
   913     {
   914     if (avalue)
   914     if (avalue)
   915         {
   915         {
   916         QMapIterator<int, bool> i(mTempSelectedCategory);
   916         QMapIterator<int, bool> i(mTempSelectedCategory);
   917         QMapIterator<int, bool> j(mSelectedCategory);
   917         QMapIterator<int, bool> j(mSelectedCategory);
   918         while (i.hasNext())
   918         while (i.hasNext())
   919             {
   919             {
   920             i.next();
   920             i.next();
   921             j.next();
   921             j.next();
   922             if (i.value() == j.value())
   922             if (i.value() != j.value())
   923                 {
       
   924 
       
   925                 }
       
   926             else
       
   927                 {
   923                 {
   928                 startNewSearch(mOriginalString);
   924                 startNewSearch(mOriginalString);
   929                 break;
   925                 break;
   930                 }
   926                 }
   931             }
   927             }
   932         }
   928         }
   933     }
   929     }
   934 // ---------------------------------------------------------------------------
   930 // ---------------------------------------------------------------------------
   935 // SearchProgressiveState::setSelectedCategories
   931 // SearchProgressiveState::setSelectedCategories
   936 // ---------------------------------------------------------------------------
   932 // ---------------------------------------------------------------------------
   937 //
       
   938 void SearchProgressiveState::setSelectedCategories()
   933 void SearchProgressiveState::setSelectedCategories()
   939     {
   934     {
   940     mTemplist.clear();
   935     mTemplist.clear();
   941     QMapIterator<int, bool> i(mSelectedCategory);
   936     QMapIterator<int, bool> i(mSelectedCategory);
       
   937     bool isrootsearch = false;
   942     while (i.hasNext())
   938     while (i.hasNext())
   943         {
   939         {
   944         i.next();
   940         i.next();
   945         if (i.value())
   941         if (i.value())
   946             {
   942             {
   947             switch (i.key())
   943             switch (i.key())
   948                 {
   944                 {
   949                 case 0:
   945                 case 0:
   950                     {
   946                     {
   951                     //mTemplist.append("selectall");
   947                     isrootsearch = true;
       
   948                     // mTemplist.append("selectall");
   952                     break;
   949                     break;
   953                     }
   950                     }
   954                 case 1: //Contacts
   951                 case 1: //Contacts
   955                     {
   952                     {
   956                     mTemplist.append("contact");
   953                     mTemplist.append("contact");
   989                     break;
   986                     break;
   990                     }
   987                     }
   991                 }
   988                 }
   992             }
   989             }
   993         }
   990         }
       
   991     if (mTemplist.count() == 8)
       
   992         isrootsearch = true;
       
   993     if (isrootsearch)
       
   994         {
       
   995         mTemplist.clear();
       
   996         mTemplist.append("selectall");
       
   997         }
   994     }
   998     }
   995 // ---------------------------------------------------------------------------
   999 // ---------------------------------------------------------------------------
   996 // SearchProgressiveState::cancelSearch
  1000 // SearchProgressiveState::cancelSearch
   997 // ---------------------------------------------------------------------------
  1001 // ---------------------------------------------------------------------------
   998 //
       
   999 void SearchProgressiveState::cancelSearch()
  1002 void SearchProgressiveState::cancelSearch()
  1000     {
  1003     {
  1001     for (int i = 0; i < mSearchHandlerList.count(); i++)
  1004     for (int i = 0; i < mSearchHandlerList.count(); i++)
  1002         {
  1005         {
  1003         mSearchHandlerList.at(i)->cancelLastSearch();
  1006         mSearchHandlerList.at(i)->cancelLastSearch();
  1004         }
  1007         }
  1005     }
  1008     }
  1006 // ---------------------------------------------------------------------------
  1009 // ---------------------------------------------------------------------------
  1007 // SearchProgressiveState::getAppIconFromAppId
  1010 // SearchProgressiveState::getAppIconFromAppId
  1008 // ---------------------------------------------------------------------------
  1011 // ---------------------------------------------------------------------------
  1009 //
       
  1010 HbIcon SearchProgressiveState::getAppIconFromAppId(TUid auid)
  1012 HbIcon SearchProgressiveState::getAppIconFromAppId(TUid auid)
  1011     {
  1013     {
  1012     HbIcon icon;
  1014     HbIcon icon;
  1013     CAknIcon* aknIcon = NULL;
  1015     CAknIcon* aknIcon = NULL;
  1014     CFbsBitmap* bitmap = NULL;
  1016     CFbsBitmap* bitmap = NULL;
  1015     CFbsBitmap* mask = NULL;
  1017     CFbsBitmap* mask = NULL;
  1016     QPixmap pixmap;
  1018     QPixmap pixmap;
  1017 
       
  1018     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1019     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1019     if (skin)
  1020     if (skin)
  1020         {
  1021         {
  1021         TRAPD( err,
  1022         TRAPD( err,
  1022                     {
  1023                     {
  1031                         {aknIcon = CAknIcon::NewL();
  1032                         {aknIcon = CAknIcon::NewL();
  1032                         aknIcon->SetBitmap(bitmap);
  1033                         aknIcon->SetBitmap(bitmap);
  1033                         aknIcon->SetMask(mask);});
  1034                         aknIcon->SetMask(mask);});
  1034             if (err1 == KErrNone)
  1035             if (err1 == KErrNone)
  1035                 {
  1036                 {
  1036 
       
  1037                 }
  1037                 }
  1038             }
  1038             }
  1039         }
  1039         }
  1040     if (aknIcon)
  1040     if (aknIcon)
  1041         {       
  1041         {
  1042         //need to disable compression to properly convert the bitmap
  1042         //need to disable compression to properly convert the bitmap
  1043         AknIconUtils::DisableCompression(aknIcon->Bitmap());
  1043         AknIconUtils::DisableCompression(aknIcon->Bitmap());
  1044 
  1044         AknIconUtils::SetSize(aknIcon->Bitmap(), TSize(mListViewIconSize.width(),
  1045         AknIconUtils::SetSize(aknIcon->Bitmap(), TSize(
  1045                 mListViewIconSize.height()),
  1046                 defaultIconSize.width(), defaultIconSize.height()),
       
  1047                 EAspectRatioPreservedAndUnusedSpaceRemoved);
  1046                 EAspectRatioPreservedAndUnusedSpaceRemoved);
  1048         if (aknIcon->Bitmap()->Header().iCompression == ENoBitmapCompression)
  1047         if (aknIcon->Bitmap()->Header().iCompression == ENoBitmapCompression)
  1049             {
  1048             {
  1050             pixmap = fromSymbianCFbsBitmap(aknIcon->Bitmap());
  1049             pixmap = fromSymbianCFbsBitmap(aknIcon->Bitmap());
  1051             QPixmap mask = fromSymbianCFbsBitmap(aknIcon->Mask());
  1050             QPixmap mask = fromSymbianCFbsBitmap(aknIcon->Mask());
  1065                             QPixmap mask = fromSymbianCFbsBitmap(temp);
  1064                             QPixmap mask = fromSymbianCFbsBitmap(temp);
  1066                             CleanupStack::PopAndDestroy();
  1065                             CleanupStack::PopAndDestroy();
  1067                             pixmap.setAlphaChannel(mask);});
  1066                             pixmap.setAlphaChannel(mask);});
  1068                 if (err1 == KErrNone)
  1067                 if (err1 == KErrNone)
  1069                     {
  1068                     {
  1070 
       
  1071                     }
  1069                     }
  1072                 }
  1070                 }
  1073 
  1071             }
  1074             }
  1072         pixmap = pixmap.scaled(mListViewIconSize, Qt::KeepAspectRatioByExpanding);
  1075 
       
  1076         pixmap = pixmap.scaled(defaultIconSize,
       
  1077                 Qt::KeepAspectRatioByExpanding);
       
  1078         icon = HbIcon(QIcon(pixmap));
  1073         icon = HbIcon(QIcon(pixmap));
  1079         }
  1074         }
  1080     return icon;
  1075     return icon;
  1081     }
  1076     }
  1082 // ---------------------------------------------------------------------------
  1077 // ---------------------------------------------------------------------------
  1083 // SearchProgressiveState::TDisplayMode2Format
  1078 // SearchProgressiveState::TDisplayMode2Format
  1084 // ---------------------------------------------------------------------------
  1079 // ---------------------------------------------------------------------------
  1085 //
       
  1086 QImage::Format SearchProgressiveState::TDisplayMode2Format(TDisplayMode mode)
  1080 QImage::Format SearchProgressiveState::TDisplayMode2Format(TDisplayMode mode)
  1087     {
  1081     {
  1088     QImage::Format format;
  1082     QImage::Format format;
  1089     switch (mode)
  1083     switch (mode)
  1090         {
  1084         {
  1120     return format;
  1114     return format;
  1121     }
  1115     }
  1122 // ---------------------------------------------------------------------------
  1116 // ---------------------------------------------------------------------------
  1123 // SearchProgressiveState::fromSymbianCFbsBitmap
  1117 // SearchProgressiveState::fromSymbianCFbsBitmap
  1124 // ---------------------------------------------------------------------------
  1118 // ---------------------------------------------------------------------------
  1125 //
       
  1126 QPixmap SearchProgressiveState::fromSymbianCFbsBitmap(CFbsBitmap *aBitmap)
  1119 QPixmap SearchProgressiveState::fromSymbianCFbsBitmap(CFbsBitmap *aBitmap)
  1127     {
  1120     {
  1128     aBitmap->BeginDataAccess();
  1121     aBitmap->BeginDataAccess();
  1129     uchar *data = (uchar *) aBitmap->DataAddress();
  1122     uchar *data = (uchar *) aBitmap->DataAddress();
  1130     TSize size = aBitmap->SizeInPixels();
  1123     TSize size = aBitmap->SizeInPixels();
  1131     TDisplayMode displayMode = aBitmap->DisplayMode();
  1124     TDisplayMode displayMode = aBitmap->DisplayMode();
  1132 
       
  1133     // QImage format must match to bitmap format
       
  1134     QImage image(data, size.iWidth, size.iHeight, TDisplayMode2Format(
  1125     QImage image(data, size.iWidth, size.iHeight, TDisplayMode2Format(
  1135             displayMode));
  1126             displayMode));// QImage format must match to bitmap format
  1136     aBitmap->EndDataAccess();
  1127     aBitmap->EndDataAccess();
  1137 
       
  1138     // No data copying happens because image format matches native OpenVG format.
  1128     // No data copying happens because image format matches native OpenVG format.
  1139     // So QPixmap actually points to CFbsBitmap data.
  1129     // So QPixmap actually points to CFbsBitmap data.
  1140     return QPixmap::fromImage(image);
  1130     return QPixmap::fromImage(image);
  1141     }
  1131     }
  1142 // ---------------------------------------------------------------------------
  1132 // ---------------------------------------------------------------------------
  1143 // SearchProgressiveState::copyBitmapLC
  1133 // SearchProgressiveState::copyBitmapLC
  1144 // ---------------------------------------------------------------------------
  1134 // ---------------------------------------------------------------------------
  1145 //
       
  1146 CFbsBitmap *SearchProgressiveState::copyBitmapLC(CFbsBitmap *input)
  1135 CFbsBitmap *SearchProgressiveState::copyBitmapLC(CFbsBitmap *input)
  1147     {
  1136     {
  1148     CFbsBitmap *bmp = new (ELeave) CFbsBitmap();
  1137     CFbsBitmap *bmp = new (ELeave) CFbsBitmap();
  1149     CleanupStack::PushL(bmp);
  1138     CleanupStack::PushL(bmp);
  1150     bmp->Create(input->SizeInPixels(), input->DisplayMode());
  1139     bmp->Create(input->SizeInPixels(), input->DisplayMode());
  1158     return bmp;
  1147     return bmp;
  1159     }
  1148     }
  1160 // ---------------------------------------------------------------------------
  1149 // ---------------------------------------------------------------------------
  1161 // SearchProgressiveState::filterDoc
  1150 // SearchProgressiveState::filterDoc
  1162 // ---------------------------------------------------------------------------
  1151 // ---------------------------------------------------------------------------
  1163 //
       
  1164 QString SearchProgressiveState::filterDoc(const QCPixDocument* aDoc,
  1152 QString SearchProgressiveState::filterDoc(const QCPixDocument* aDoc,
  1165         const QString& filter)
  1153         const QString& filter)
  1166     {
  1154     {
  1167     for (int i = 0; i < aDoc->fieldCount(); i++)
  1155     for (int i = 0; i < aDoc->fieldCount(); i++)
  1168         {
  1156         {
  1171             return aDoc->field(i).value();
  1159             return aDoc->field(i).value();
  1172             }
  1160             }
  1173         }
  1161         }
  1174     return NULL;
  1162     return NULL;
  1175     }
  1163     }
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // SearchProgressiveState::filterDoc
       
  1166 // ---------------------------------------------------------------------------
       
  1167 QStringList SearchProgressiveState::filterDoc(const QCPixDocument* aDoc,
       
  1168         const QString& filter1, const QString& filter2,
       
  1169         const QString& filter3)
       
  1170     {
       
  1171     QStringList docList;
       
  1172     docList.append(QString());
       
  1173     docList.append(QString());
       
  1174     docList.append(QString());
       
  1175     bool bfilter1 = false;
       
  1176     bool bfilter2 = false;
       
  1177     bool bfilter3 = false;
       
  1178     if (!filter3.length())
       
  1179         {
       
  1180         bfilter3 = true;
       
  1181         }
       
  1182     for (int i = 0; i < aDoc->fieldCount(); i++)
       
  1183         {
       
  1184         if (!bfilter1 && aDoc->field(i).name().contains(filter1))
       
  1185             {
       
  1186             docList.replace(0, aDoc->field(i).value());
       
  1187             bfilter1 = true;
       
  1188             }
       
  1189         if (!bfilter2 && aDoc->field(i).name().contains(filter2))
       
  1190             {
       
  1191             docList.replace(1, aDoc->field(i).value());
       
  1192             bfilter2 = true;
       
  1193             }
       
  1194         if (!bfilter3 && aDoc->field(i).name().contains(filter3))
       
  1195             {
       
  1196             docList.replace(2, aDoc->field(i).value());
       
  1197             bfilter3 = true;
       
  1198             }
       
  1199         if (bfilter1 && bfilter2 && bfilter3)
       
  1200             break;
       
  1201         }
       
  1202     return docList;
       
  1203     }
       
  1204 // ---------------------------------------------------------------------------
       
  1205 // SearchProgressiveState::getDrivefromMediaId
       
  1206 // ---------------------------------------------------------------------------
       
  1207 QString SearchProgressiveState::getDrivefromMediaId(QString aMediaId)
       
  1208     {
       
  1209     TBuf<15> mediaIdBuf(aMediaId.utf16());
       
  1210     if (KErrNone == iFs.Connect())
       
  1211         {
       
  1212         TUint mediaNum;
       
  1213         TVolumeInfo vmInfo;
       
  1214         TChar driveLetter;
       
  1215         TLex lex(mediaIdBuf);
       
  1216         lex.Val(mediaNum);
       
  1217         TDriveNumber drive = TDriveNumber(KErrNotSupported);
       
  1218 
       
  1219         for (TInt i = 0; i <= EDriveZ; i++)
       
  1220             {
       
  1221             TInt err = iFs.Volume(vmInfo, i);// Volume() returns KErrNotReady if no volume present.       
       
  1222             if (err != KErrNotReady)// In this case, check next drive number
       
  1223                 {
       
  1224                 if (vmInfo.iUniqueID == mediaNum)
       
  1225                     {
       
  1226                     drive = TDriveNumber(i);//Is the drive
       
  1227                     if (KErrNone == iFs.DriveToChar(drive, driveLetter))
       
  1228                         {
       
  1229                         mediaIdBuf.Zero();
       
  1230                         mediaIdBuf.Append(driveLetter);
       
  1231                         mediaIdBuf.LowerCase();
       
  1232                         }
       
  1233                     break;
       
  1234                     }
       
  1235                 }
       
  1236             }
       
  1237         iFs.Close();
       
  1238         }
       
  1239     return QString::fromUtf16(mediaIdBuf.Ptr(), mediaIdBuf.Length());
       
  1240     }
       
  1241 // ---------------------------------------------------------------------------
       
  1242 // SearchProgressiveState::LaunchApplicationL
       
  1243 // ---------------------------------------------------------------------------
       
  1244 void SearchProgressiveState::LaunchApplicationL(const TUid aUid)
       
  1245     {
       
  1246     RWsSession wsSession;
       
  1247     User::LeaveIfError(wsSession.Connect());
       
  1248     CleanupClosePushL<RWsSession> (wsSession);
       
  1249     CAknTaskList *taskList = CAknTaskList::NewL(wsSession);
       
  1250     TApaTask task = taskList->FindRootApp(aUid);
       
  1251     delete taskList;
       
  1252     if (task.Exists())
       
  1253         {
       
  1254         task.BringToForeground();
       
  1255         }
       
  1256     else
       
  1257         {
       
  1258         TApaAppInfo appInfo;
       
  1259         TApaAppCapabilityBuf capabilityBuf;
       
  1260         RApaLsSession appArcSession;
       
  1261         User::LeaveIfError(appArcSession.Connect());
       
  1262         CleanupClosePushL<RApaLsSession> (appArcSession);
       
  1263         User::LeaveIfError(appArcSession.GetAppInfo(appInfo, aUid));
       
  1264         User::LeaveIfError(
       
  1265                 appArcSession.GetAppCapability(capabilityBuf, aUid));
       
  1266         TApaAppCapability &caps = capabilityBuf();
       
  1267         TFileName appName = appInfo.iFullName;
       
  1268         CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
       
  1269         cmdLine->SetExecutableNameL(appName);
       
  1270         if (caps.iLaunchInBackground)
       
  1271             {
       
  1272             cmdLine->SetCommandL(EApaCommandBackground);
       
  1273             }
       
  1274         else
       
  1275             {
       
  1276             cmdLine->SetCommandL(EApaCommandRun);
       
  1277             }
       
  1278         //cmdLine->SetTailEndL(aParam);
       
  1279         User::LeaveIfError(appArcSession.StartApp(*cmdLine));
       
  1280         CleanupStack::PopAndDestroy(cmdLine);
       
  1281         CleanupStack::PopAndDestroy(&appArcSession);
       
  1282         }
       
  1283     CleanupStack::PopAndDestroy(&wsSession);
       
  1284     }
       
  1285 // ---------------------------------------------------------------------------
       
  1286 // SearchProgressiveState::_viewingCompleted
       
  1287 // ---------------------------------------------------------------------------
       
  1288 void SearchProgressiveState::_viewingCompleted()
       
  1289     {
       
  1290     if (calAgandaViewerPluginInstance)
       
  1291         calAgandaViewerPluginInstance->deleteLater();
       
  1292     }