webengine/osswebengine/WebKit/s60/misc/WebIconDatabase.cpp
changeset 0 dd21522fd290
child 27 6297cdf66332
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "config.h"
       
    19 #include "WebIconDatabase.h"
       
    20 
       
    21 #include "IconDatabase.h"
       
    22 #include "MaskedBitmap.h"
       
    23 #include "Image.h"
       
    24 #include "PlatformString.h"
       
    25 #include "KURL.h"
       
    26 #include "IntRect.h"
       
    27 #include <GULICON.H>
       
    28 #include <FBS.H>
       
    29 #include "WebKitUtilsSqlite.h"
       
    30 
       
    31 using namespace WebCore;
       
    32 
       
    33 _LIT(KDBFile, "c:\\private\\%08x\\");
       
    34 
       
    35 WebIconDatabase::WebIconDatabase()
       
    36 {
       
    37 }
       
    38 
       
    39 WebIconDatabase::~WebIconDatabase()
       
    40 {
       
    41     iconDatabase()->close();
       
    42     sqlite3SymbianLibFinalize();
       
    43 }
       
    44 
       
    45 void WebIconDatabase::openSharedDatabase()
       
    46 {
       
    47     if (!iconDatabase()->isOpen()) {
       
    48         sqlite3SymbianLibInit();
       
    49         // tot fixme: get process path from some utilities
       
    50         iconDatabase()->setEnabled(true);
       
    51 	    RProcess myProcess;	
       
    52 	    TBuf <256>dirName;    
       
    53         dirName.Format(KDBFile, myProcess.Identity());
       
    54         String s(dirName.Ptr(), dirName.Length());
       
    55         iconDatabase()->open(s);
       
    56     }
       
    57 }
       
    58 
       
    59 CGulIcon* WebIconDatabase::iconForPageURL(const TDesC8& url)
       
    60 {
       
    61     // make sure url has a trailing /
       
    62     KURL _url(url);
       
    63     iconDatabase()->retainIconForPageURL(String(_url));
       
    64     Image* image = iconDatabase()->iconForPageURL(String(_url), IntSize(TSize(16, 16)));
       
    65     if (image) {
       
    66         CMaskedBitmap* maskedBitmap = image->getMaskedBitmap();
       
    67         if (!maskedBitmap)
       
    68             return NULL;
       
    69         CGulIcon* icon = NULL;
       
    70         CFbsBitmap* bitmap = new CFbsBitmap();
       
    71         CFbsBitmap* mask = new CFbsBitmap();
       
    72 
       
    73         if (bitmap && mask) {
       
    74             int err( BitmapUtil::CopyBitmap(maskedBitmap->Bitmap(), *bitmap));
       
    75             int errMask( BitmapUtil::CopyBitmap(maskedBitmap->Mask(), *mask));
       
    76             if (err == KErrNone && errMask == KErrNone) {
       
    77                 TRAP_IGNORE(icon = CGulIcon::NewL());
       
    78                 if (icon) {
       
    79                     icon->SetBitmap( bitmap );
       
    80                     icon->SetMask( mask );
       
    81                 }
       
    82             }
       
    83         }
       
    84         return icon;
       
    85     }
       
    86     return NULL;
       
    87 }
       
    88 
       
    89 void WebIconDatabase::retainIconForURL(const TDesC8& url)
       
    90 {   
       
    91     iconDatabase()->retainIconForPageURL(String(url));
       
    92 }
       
    93 
       
    94 void WebIconDatabase::releaseIconForURL(const TDesC8& url)
       
    95 {   
       
    96     iconDatabase()->releaseIconForPageURL(String(url));
       
    97 }
       
    98 
       
    99