searchui/stateproviders/searchstateprovider/src/searchprogressivestate.cpp
changeset 5 3bc31ad99ee7
parent 3 6832643895f7
child 7 51d10d255e92
--- a/searchui/stateproviders/searchstateprovider/src/searchprogressivestate.cpp	Fri May 14 15:53:17 2010 +0300
+++ b/searchui/stateproviders/searchstateprovider/src/searchprogressivestate.cpp	Thu May 27 12:52:35 2010 +0300
@@ -42,7 +42,7 @@
 #include <fbs.h>
 #include <AknInternalIconUtils.h>
 #include <AknIconUtils.h> 
-#include <apgcli.h>
+#include <apaidpartner.h>
 #include <qpluginloader.h>
 #include <eventviewerplugininterface.h>
 #include <noteseditor.h>
@@ -51,6 +51,8 @@
 #include <apgcli.h>
 #include <AknTaskList.h>
 #include <apacmdln.h>
+#include <xqconversions.h>
+#include <apparc.h>
 const char *SEARCHSTATEPROVIDER_DOCML = ":/xml/searchstateprovider.docml";
 const char *TOC_VIEW = "tocView";
 const char *TUT_SEARCHPANEL_WIDGET = "searchPanel";
@@ -120,6 +122,10 @@
     if (mSearchPanel)
         {
         mSearchPanel->setSearchOptionsEnabled(true);
+        
+        mSearchPanel->setPlaceholderText("Search device");
+
+        mSearchPanel->setCancelEnabled(false);
         }
 
     constructHandlers();
@@ -138,20 +144,20 @@
     //Icon creation in array
     RArray<TUid> appUid;
     appUid.Append(TUid::Uid(0x20022EF9));//contact
-    appUid.Append(TUid::Uid(0x10207C62));//media(audio)
-    appUid.Append(TUid::Uid(0x200211FE));//video not assigned 
+    appUid.Append(TUid::Uid(0x10207C62));//audio
+    appUid.Append(TUid::Uid(0x200211FE));//video 
     appUid.Append(TUid::Uid(0x20000A14));//image 
     appUid.Append(TUid::Uid(0x2001FE79));//msg
-    appUid.Append(TUid::Uid(0x20022F35));//email not assigned 
+    appUid.Append(TUid::Uid(0x200255BA));//email 
     appUid.Append(TUid::Uid(0x10005901));//calender
     appUid.Append(TUid::Uid(0x20029F80));//notes
     //appUid.Append(TUid::Uid(0x20022F35));//application
-    appUid.Append(TUid::Uid(0x20022F35));//bookmark not assigned
+    appUid.Append(TUid::Uid(0x10008D39));//bookmark
     appUid.Append(TUid::Uid(0x2002BCC0));//files
 
     for (int i = 0; i < appUid.Count(); i++)
         {
-        mIconArray.append(getAppIconFromAppId(appUid[i]));
+        TRAP_IGNORE(mIconArray.append(getAppIconFromAppIdL(appUid[i])));
         }
 #ifdef OST_TRACE_COMPILER_IN_USE 
     //start() the timers to avoid worrying abt having to start()/restart() later
@@ -311,16 +317,8 @@
                 SLOT(startNewSearch(QString)));
         connect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
                 SLOT(setSettings()));
-        connect(mSearchPanel, SIGNAL(exitClicked()), this,
-                SLOT(cancelSearch()));
         }
-    if (mModel)
-        {
-        connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
-                SLOT(getrowsInserted()));
-        connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
-                SLOT(getrowsRemoved()));
-        }
+
     }
 // ---------------------------------------------------------------------------
 // SearchProgressiveState::deActivateSignals
@@ -347,15 +345,6 @@
                 SLOT(startNewSearch(QString)));
         disconnect(mSearchPanel, SIGNAL(searchOptionsClicked()), this,
                 SLOT(setSettings()));
-        disconnect(mSearchPanel, SIGNAL(exitClicked()), this,
-                SLOT(cancelSearch()));
-        }
-    if (mModel)
-        {
-        disconnect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this,
-                SLOT(getrowsInserted()));
-        disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
-                SLOT(getrowsRemoved()));
         }
     }
 // ---------------------------------------------------------------------------
@@ -397,18 +386,6 @@
     QStringList liststr;
     QString secondrow = aDoc->excerpt();
     QString firstrow;
-    //-------------- html tag creation-------------------
-   /* QString htmlTagPre = QString("<u>");
-    QString htmlTagPost = QString("</u>");
-    int insertpt = secondrow.indexOf(mOriginalString, 0, Qt::CaseInsensitive);
-    if (insertpt >= 0)
-        {
-        secondrow.insert(insertpt, htmlTagPre);
-
-        secondrow.insert(insertpt + mOriginalString.length()
-                + htmlTagPre.length(), htmlTagPost);
-        }
-*/    //--------------------Html Tag Creation completed------------
     QStandardItem* listitem = new QStandardItem();
 
     if (aDoc->baseAppClass().contains("contact"))
@@ -504,6 +481,7 @@
         {
         firstrow.append(filterDoc(aDoc, "Subject"));
         liststr << firstrow << secondrow;
+        listitem->setData(mIconArray.at(5), Qt::DecorationRole);
         }
     else if (aDoc->baseAppClass().contains("calendar"))
         {
@@ -531,8 +509,8 @@
         firstrow.append(filterDoc(aDoc, "Name"));
         liststr << firstrow;
         bool ok;
-        listitem->setData(getAppIconFromAppId(TUid::Uid(aDoc->docId().toInt(
-                &ok, 16))), Qt::DecorationRole);
+        TRAP_IGNORE(listitem->setData(getAppIconFromAppIdL(TUid::Uid(aDoc->docId().toInt(
+                                                &ok, 16))), Qt::DecorationRole));
         }
     else if (aDoc->baseAppClass().contains("bookmark"))
         {
@@ -542,6 +520,7 @@
             firstrow = "UnKnown";
             }
         liststr << firstrow << secondrow;
+        listitem->setData(mIconArray.at(8), Qt::DecorationRole);
         }
     else if (aDoc->baseAppClass().contains("file"))
         {
@@ -555,20 +534,7 @@
     listitem->setData(aDoc->docId(), Qt::UserRole);
     listitem->setData(aDoc->baseAppClass(), Qt::UserRole + 1);
     mModel->appendRow(listitem);
-    delete aDoc;
-    }
-// ---------------------------------------------------------------------------
-// SearchProgressiveState::getSettingCategory
-// ---------------------------------------------------------------------------
-void SearchProgressiveState::getSettingCategory(int item, bool avalue)
-    {
-    mSelectedCategory.insert(item, avalue);
-    }
-// ---------------------------------------------------------------------------
-// SearchProgressiveState::getrowsInserted
-// ---------------------------------------------------------------------------
-void SearchProgressiveState::getrowsInserted()
-    {
+
     mResultparser++;
     if (mResultparser < mResultcount)
         {
@@ -580,30 +546,14 @@
         PERF_CAT_GETDOC_ACCUMULATOR_ENDLOG
         searchOnCategory(mSearchString);
         }
+    delete aDoc;
     }
 // ---------------------------------------------------------------------------
-// SearchProgressiveState::getrowsRemoved
+// SearchProgressiveState::getSettingCategory
 // ---------------------------------------------------------------------------
-void SearchProgressiveState::getrowsRemoved()
+void SearchProgressiveState::getSettingCategory(int item, bool avalue)
     {
-    if (mModel->rowCount() != 0)
-        {
-        mModel->removeRow(0);
-        }
-    else
-        {
-        mListView->reset();
-        if (mOriginalString.length())
-            {
-            mDatabasecount = 0;
-            /*mSearchString = "$prefix(\"";
-            mSearchString += mOriginalString;
-            mSearchString += "\")";*/
-            mSearchString = mOriginalString;
-            mSearchString.append('*');
-            searchOnCategory(mSearchString);
-            }
-        }
+    mSelectedCategory.insert(item, avalue);
     }
 // ---------------------------------------------------------------------------
 // SearchProgressiveState::openResultitem
@@ -611,6 +561,8 @@
 void SearchProgressiveState::openResultitem(QModelIndex index)
     {
     QStandardItem* item = mModel->itemFromIndex(index);
+    if (item == NULL)
+        return;
     QList<QVariant> args;
     bool t;
     mRequest = NULL;
@@ -775,7 +727,7 @@
     {
     if (mModel)
         {
-        mModel->removeRows(0, mModel->rowCount());
+        mModel->clear();
         }
     }
 // ---------------------------------------------------------------------------
@@ -840,6 +792,11 @@
             {
             PERF_CAT_API_TIME_RESTART
             mSearchHandler->searchAsync(aKeyword, "_aggregate");
+            
+            }
+        else
+            {
+            searchOnCategory(mSearchString);
             }
         }
     else if (mDatabasecount >= mTemplist.count())
@@ -868,7 +825,7 @@
         {
         clear();
         }
-    else if (mOriginalString.length())
+    if (mOriginalString.length())
         {
         mDatabasecount = 0;
         mLinkindex = 0;
@@ -997,84 +954,108 @@
         }
     }
 // ---------------------------------------------------------------------------
-// SearchProgressiveState::cancelSearch
-// ---------------------------------------------------------------------------
-void SearchProgressiveState::cancelSearch()
-    {
-    for (int i = 0; i < mSearchHandlerList.count(); i++)
-        {
-        mSearchHandlerList.at(i)->cancelLastSearch();
-        }
-    }
-// ---------------------------------------------------------------------------
 // SearchProgressiveState::getAppIconFromAppId
 // ---------------------------------------------------------------------------
-HbIcon SearchProgressiveState::getAppIconFromAppId(TUid auid)
+HbIcon SearchProgressiveState::getAppIconFromAppIdL(TUid auid)
     {
     HbIcon icon;
-    CAknIcon* aknIcon = NULL;
-    CFbsBitmap* bitmap = NULL;
-    CFbsBitmap* mask = NULL;
-    QPixmap pixmap;
-    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
-    if (skin)
+    RApaLsSession apaLsSession;
+    CleanupClosePushL(apaLsSession);
+    User::LeaveIfError(apaLsSession.Connect());
+    CApaAppServiceInfoArray* skinArray(NULL);
+    TRAPD( err, skinArray = apaLsSession.GetAppServiceOpaqueDataLC(auid, TUid::Uid(0x2002DCF3));
+            if (err == KErrNone && skinArray )
+                {
+                TArray<TApaAppServiceInfo> tmpArray( skinArray->Array() );
+                if ( tmpArray.Count() )
+                    {
+                    TPtrC8 opaque(tmpArray[0].OpaqueData());
+                    const TPtrC16 iconName((TText16*) opaque.Ptr(),(opaque.Length()+1)>>1);
+                    icon = HbIcon( XQConversions:: s60DescToQString( iconName ) );
+                    }
+                }
+            CleanupStack::PopAndDestroy(skinArray);
+    );
+    if (icon.isNull() || !(icon.size().isValid()))
         {
-        TRAPD( err,
-                    {
-                    AknsUtils::CreateAppIconLC( skin, auid,
-                            EAknsAppIconTypeList, bitmap, mask );
-                    CleanupStack::Pop(2); //for trap
-                    }
-        );
-        if (err == KErrNone)
+        TSize iconSize(mListViewIconSize.width(), mListViewIconSize.height());
+        CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
+        TInt err = apaLsSession.GetAppIcon(auid, iconSize, *apaMaskedBitmap);
+        TInt iconsCount(0);
+        apaLsSession.NumberOfOwnDefinedIcons(auid, iconsCount);
+        QPixmap pixmap;
+        if ((err == KErrNone) && (iconsCount > 0))
             {
-            TRAPD( err1,
-                        {aknIcon = CAknIcon::NewL();
-                        aknIcon->SetBitmap(bitmap);
-                        aknIcon->SetMask(mask);});
-            if (err1 == KErrNone)
-                {
-                }
-            }
-        }
-    if (aknIcon)
-        {
-        //need to disable compression to properly convert the bitmap
-        AknIconUtils::DisableCompression(aknIcon->Bitmap());
-        AknIconUtils::SetSize(aknIcon->Bitmap(), TSize(mListViewIconSize.width(),
-                mListViewIconSize.height()),
-                EAspectRatioPreservedAndUnusedSpaceRemoved);
-        if (aknIcon->Bitmap()->Header().iCompression == ENoBitmapCompression)
-            {
-            pixmap = fromSymbianCFbsBitmap(aknIcon->Bitmap());
-            QPixmap mask = fromSymbianCFbsBitmap(aknIcon->Mask());
-            pixmap.setAlphaChannel(mask);
+            fromBitmapAndMaskToPixmapL(apaMaskedBitmap,
+                    apaMaskedBitmap->Mask(), pixmap);
+            pixmap = pixmap.scaled(mListViewIconSize,
+                    Qt::KeepAspectRatioByExpanding);
+            icon = HbIcon(QIcon(pixmap));
             }
         else
             {
-            CFbsBitmap *temp(NULL);
-            TRAPD( err,
-                        {temp = copyBitmapLC(aknIcon->Bitmap());
-                        pixmap = fromSymbianCFbsBitmap(temp);
-                        CleanupStack::PopAndDestroy();});
-            if (err == KErrNone)
+            HBufC* fileNameFromApparc;
+            TInt err2 = apaLsSession.GetAppIcon(auid, fileNameFromApparc);
+            CleanupStack::PushL(fileNameFromApparc);
+            if (err2 == KErrNone)
                 {
-                TRAPD( err1,
-                            {temp = copyBitmapLC(aknIcon->Mask());
-                            QPixmap mask = fromSymbianCFbsBitmap(temp);
-                            CleanupStack::PopAndDestroy();
-                            pixmap.setAlphaChannel(mask);});
-                if (err1 == KErrNone)
+                QString fileName = XQConversions::s60DescToQString(
+                        fileNameFromApparc->Des());
+                if (fileName.contains(QString(".mif")))
                     {
+                    TPtr ptr(fileNameFromApparc->Des());
+                    GetPixmapByFilenameL(ptr, mListViewIconSize, pixmap);
+                    pixmap = pixmap.scaled(mListViewIconSize,
+                            Qt::KeepAspectRatioByExpanding);
+                    icon = HbIcon(QIcon(pixmap));
                     }
                 }
+            CleanupStack::Pop(fileNameFromApparc);
             }
-        pixmap = pixmap.scaled(mListViewIconSize, Qt::KeepAspectRatioByExpanding);
-        icon = HbIcon(QIcon(pixmap));
+        CleanupStack::PopAndDestroy(apaMaskedBitmap);
         }
+    CleanupStack::PopAndDestroy(&apaLsSession);
+    
+    if (icon.isNull() || !(icon.size().isValid())) 
+            icon = HbIcon("qtg_large_application");
     return icon;
     }
 // ---------------------------------------------------------------------------
+// SearchProgressiveState::GetPixmapByFilenameL
+// ---------------------------------------------------------------------------
+void SearchProgressiveState::GetPixmapByFilenameL(TDesC& fileName,
+        const QSize &size, QPixmap& pixmap)
+    {
+    CFbsBitmap *bitamp(0);
+    CFbsBitmap *mask(0);
+
+    if (AknIconUtils::IsMifFile(fileName))
+        {
+        // SVG icon
+        // SVG always has only one icon
+        TInt bitmapIndex = 0;
+        TInt maskIndex = 1;
+        AknIconUtils::ValidateLogicalAppIconId(fileName, bitmapIndex,
+                maskIndex);
+
+        AknIconUtils::CreateIconLC(bitamp, mask, fileName, bitmapIndex,
+                maskIndex);
+        }
+
+    AknIconUtils::DisableCompression(bitamp);
+    AknIconUtils::SetSize(bitamp, TSize(size.width(), size.height()),
+            EAspectRatioPreservedAndUnusedSpaceRemoved);
+
+    AknIconUtils::DisableCompression(mask);
+    AknIconUtils::SetSize(mask, TSize(size.width(), size.height()),
+            EAspectRatioPreservedAndUnusedSpaceRemoved);
+
+    fromBitmapAndMaskToPixmapL(bitamp, mask, pixmap);
+
+    // bitmap and icon, AknsUtils::CreateIconLC doesn't specify the order
+    CleanupStack::Pop(2);
+    }
+// ---------------------------------------------------------------------------
 // SearchProgressiveState::TDisplayMode2Format
 // ---------------------------------------------------------------------------
 QImage::Format SearchProgressiveState::TDisplayMode2Format(TDisplayMode mode)
@@ -1147,6 +1128,31 @@
     return bmp;
     }
 // ---------------------------------------------------------------------------
+// SearchProgressiveState::fromBitmapAndMaskToPixmapL
+// ---------------------------------------------------------------------------
+void SearchProgressiveState::fromBitmapAndMaskToPixmapL(
+        CFbsBitmap* fbsBitmap, CFbsBitmap* fbsMask, QPixmap& pixmap)
+    {
+    if (fbsBitmap->Header().iCompression == ENoBitmapCompression)
+        {
+        pixmap = fromSymbianCFbsBitmap(fbsBitmap);
+        QPixmap mask = fromSymbianCFbsBitmap(fbsMask);
+        pixmap.setAlphaChannel(mask);
+        }
+    else
+        { // we need special handling for icons in 9.2 (NGA)
+        // let's hope that in future it will be in QT code
+        CFbsBitmap *temp(NULL);
+        temp = copyBitmapLC(fbsBitmap);
+        pixmap = fromSymbianCFbsBitmap(temp);
+        CleanupStack::PopAndDestroy();
+        temp = copyBitmapLC(fbsMask);
+        QPixmap mask = fromSymbianCFbsBitmap(temp);
+        CleanupStack::PopAndDestroy();
+        pixmap.setAlphaChannel(mask);
+        }
+    }
+// ---------------------------------------------------------------------------
 // SearchProgressiveState::filterDoc
 // ---------------------------------------------------------------------------
 QString SearchProgressiveState::filterDoc(const QCPixDocument* aDoc,