|
1 /** |
|
2 This file is part of CWRT package ** |
|
3 |
|
4 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** |
|
5 |
|
6 This program is free software: you can redistribute it and/or modify |
|
7 it under the terms of the GNU (Lesser) General Public License as |
|
8 published by the Free Software Foundation, version 2.1 of the License. |
|
9 This program is distributed in the hope that it will be useful, but |
|
10 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 (Lesser) General Public License for more details. You should have |
|
13 received a copy of the GNU (Lesser) General Public License along |
|
14 with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 #include <QtCore/QDebug> |
|
20 #include <QString> |
|
21 #include "ContentAgent_p.h" |
|
22 #include "ContentAgent.h" |
|
23 #include "bookmarks.h" |
|
24 #include <browsercontentdll.h> |
|
25 |
|
26 |
|
27 namespace WRT { |
|
28 |
|
29 ContentAgentPrivate::ContentAgentPrivate(ContentAgent* mgr, QWidget* /*parent*/) : |
|
30 q(mgr), |
|
31 m_connectedToBookmarks(false), |
|
32 m_loadedBookmarks(false), |
|
33 m_loadedHistory(false), |
|
34 m_maxUrls(10) |
|
35 { |
|
36 QFileInfo dbFile("browserContent.db"); |
|
37 |
|
38 m_bookmarkSession=new BrowserContent("Bedrock"); |
|
39 if (m_bookmarkSession) { |
|
40 m_connectedToBookmarks = true; |
|
41 } else { |
|
42 qDebug() << "ContentAgentPrivate: Failed to connect to bookmarks"; |
|
43 } |
|
44 } |
|
45 |
|
46 ContentAgentPrivate::~ContentAgentPrivate() |
|
47 { |
|
48 delete m_bookmarkSession; |
|
49 } |
|
50 |
|
51 /*! |
|
52 * \class ContentAgent |
|
53 * |
|
54 * This class is responsible for managing bookmarks, This class could be used |
|
55 * mainly for displying bookmarks in UI. |
|
56 * |
|
57 */ |
|
58 |
|
59 /*! |
|
60 * Basic constructor |
|
61 * @param parent : parent widget (Defaulted to NULL ) if not specified |
|
62 */ |
|
63 ContentAgent::ContentAgent(QWidget *parent) : |
|
64 d(new ContentAgentPrivate(this, parent)) |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 ContentAgent::~ContentAgent() |
|
70 { |
|
71 delete d; |
|
72 } |
|
73 |
|
74 ContentAgent* ContentAgent::getSingleton() |
|
75 { |
|
76 static ContentAgent* singleton = 0; |
|
77 |
|
78 if(!singleton){ |
|
79 singleton = new ContentAgent(); |
|
80 singleton->setObjectName("ContentAgent"); |
|
81 } |
|
82 return singleton; |
|
83 } |
|
84 |
|
85 QString ContentAgent::getBookmarks() |
|
86 { |
|
87 QList<BookmarkLeaf*> nodes; |
|
88 nodes = d->m_bookmarkSession->fetchAllBookmarks(); |
|
89 QString bookmarkData = "["; |
|
90 for(int i=0;i<nodes.count();i++) { |
|
91 bookmarkData.append("{"); |
|
92 bookmarkData.append("\"title\": \""); |
|
93 bookmarkData.append(nodes[i]->getTitle()); |
|
94 bookmarkData.append("\", \"urlvalue\": \""); |
|
95 bookmarkData.append(nodes[i]->getUrl()); |
|
96 if(i != (nodes.count()-1)) |
|
97 bookmarkData.append("\"},"); |
|
98 else |
|
99 bookmarkData.append("\"}"); |
|
100 } |
|
101 bookmarkData.append("]"); |
|
102 |
|
103 return bookmarkData; |
|
104 } |
|
105 |
|
106 QMap<QString, QString> ContentAgent::getSuggestedBookmarks(QString atitle) |
|
107 { |
|
108 QList<BookmarkLeaf*> nodes; |
|
109 nodes = d->m_bookmarkSession->suggestBookMarks(atitle); |
|
110 QMap<QString, QString> map; |
|
111 for(int i=0;i<nodes.count();i++) { |
|
112 map.insert( nodes[i]->getTitle(), nodes[i]->getUrl() ); |
|
113 } |
|
114 return map; |
|
115 } |
|
116 |
|
117 QMap<QString, QString> ContentAgent::getSuggestedHistory(QString atitle) |
|
118 { |
|
119 QList<HistoryLeaf*> nodes; |
|
120 nodes = d->m_bookmarkSession->suggestHistory(atitle); |
|
121 QMap<QString, QString> map; |
|
122 for(int i=0;i<nodes.count();i++) { |
|
123 map.insert( nodes[i]->getTitle(), nodes[i]->getUrl() ); |
|
124 } |
|
125 return map; |
|
126 } |
|
127 |
|
128 QObjectList ContentAgent::getUISuggestion(QString suggest) |
|
129 { |
|
130 return (d->m_bookmarkSession->suggestContent(suggest)); |
|
131 } |
|
132 |
|
133 }//wrt |