Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何添加书签

From Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
翻译自: Add a Bookmark
hoolee
最后由 hamishwillee 在 30 May 2013 编辑


在S60第二版中增加书签

我们可以使用CFavouritesDb来增加书签

#include <FavouritesDb.h>
 
_LIT( KBookmarkDbPath, "c:\\system\\data\\" );
_LIT( KBookmarkDbFile, "Bookmarks1.db" );
 
CAddFavouritesDb* CAddFavouritesDb::NewL()
{
CAddFavouritesDb* favdb = new (ELeave) CAddFavouritesDb();
CleanupStack::PushL( favdb );
favdb->ConstructL( KBookmarkDbPath, KBookmarkDbFile );
CleanupStack::Pop();
return favdb;
}
   CAddFavouritesDb * addBookmrk = CAddFavouritesDb::NewL();
CleanupStack::PushL( addBookmrk );
User::LeaveIfError(addBookmrk->OpenL());
CFavouritesItem* bookmrkItem = CFavouritesItem::NewLC();
bookmrkItem->SetType( CFavouritesItem::EItem );
bookmrkItem->SetParentFolder(KFavouritesRootUid);//this should be added else will leave with -6 error code when add
bookmrkItem->SetNameL( _L("AddBookmark") );
bookmrkItem->SetUrlL( _L("http://www.developer.nokia.com/") );
addBookmrk->AddL(*bookmrkItem , ETrue);
addBookmrk->Close();
CleanupStack::PopAndDestroy( bookmrkItem );
CleanupStack::PopAndDestroy( addBookmrk );


这里需要在.mmp文件中增加favouritesengine.lib

 LIBRARY favouritesengine.lib

在S60第三版中增加书签

在S60第三版中,CAddFavouritesDb已经被RFavouritesDb类替换。

在S60 3.1版本中添加书签:

#include <favouritessession.h> 
#include <favouritesdb.h>
#include <favouritesitem.h>
 
// Link against: favouritesengine.lib
 
RFavouritesSession iSession;
User::LeaveIfError(iSession.Connect());
CleanupClosePushL(iSession);
 
RFavouritesDb db;
// KBrowserBookmarks is picked up from the header
User::LeaveIfError(db.Open(iSession, KBrowserBookmarks));
CleanupClosePushL(db);
 
CFavouritesItem* item = CFavouritesItem::NewLC();
item->SetNameL(_L("Google UK"));
item->SetParentFolder(KFavouritesRootUid);
item->SetType(CFavouritesItem::EItem);
item->SetUrlL(_L("http://www.google.co.uk/"));
 
User::LeaveIfError(db.Add(*item, ETrue));
 
CleanupStack::PopAndDestroy(3, &session); // db, item

等同于使用如下代码在S60 3.0版本浏览器中添加书签:

CFavouritesItem* item =  CFavouritesItem::NewLC();
item->SetNameL(_L("ossGoogle UK"));
item->SetParentFolder(KFavouritesRootUid);
item->SetType(CFavouritesItem::EItem);
item->SetUrlL(_L("osshttp://www.google.co.uk/"));

Links

How to use SQL

This page was last modified on 30 May 2013, at 04:37.
43 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×