1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * |
5 * under the terms of "Eclipse Public License v1.0" |
5 * This program is free software: you can redistribute it and/or modify |
6 * which accompanies this distribution, and is available |
6 * it under the terms of the GNU Lesser General Public License as published by |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * the Free Software Foundation, version 2.1 of the License. |
8 * |
8 * |
9 * Initial Contributors: |
9 * This program is distributed in the hope that it will be useful, |
10 * Nokia Corporation - initial contribution. |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * Contributors: |
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
21 |
18 |
|
19 #include <QtGui> |
22 #include <QtGui> |
20 |
23 |
21 #include "mostvisitedpagestore.h" |
24 #include "mostvisitedpagestore.h" |
|
25 #include "bedrockprovisioning.h" |
22 |
26 |
23 const QString KMostVistedStoreFile = "mostvisitedpages.dat"; |
27 const QString KMostVistedStoreFile = "mostvisitedpages.dat"; |
24 const uint KMostVistedStoreVersion = 1; |
28 const uint KMostVistedStoreVersion = 1; |
25 const uint KMostVistedStoreLimit = 5; |
29 const uint KMostVistedStoreLimit = 5; |
26 |
30 |
105 #endif |
109 #endif |
106 |
110 |
107 readStore(); |
111 readStore(); |
108 } |
112 } |
109 |
113 |
|
114 |
|
115 void MostVisitedPageStore::clearMostVisitedPageStore() |
|
116 { |
|
117 for (int i = m_pageList.size() - 1; i >= 0; --i) |
|
118 delete m_pageList.takeAt(i); |
|
119 |
|
120 //deleting MVP file |
|
121 QFile file(m_mvpFile); |
|
122 file.remove(); |
|
123 |
|
124 //create default thumbnails |
|
125 initializeDefaultPageThumbnails(); |
|
126 } |
|
127 |
110 MostVisitedPageStore::~MostVisitedPageStore() |
128 MostVisitedPageStore::~MostVisitedPageStore() |
111 { |
129 { |
112 writeStore(); |
130 writeStore(); |
113 for (int i = 0; i < m_pageList.size(); ++i) |
131 for (int i = m_pageList.size() - 1; i >= 0; --i) |
114 delete m_pageList.takeAt(i); |
132 delete m_pageList.takeAt(i); |
115 } |
133 } |
116 |
134 |
117 void MostVisitedPageStore::pageAccessed(const QUrl& url, QImage* pageThumbnail, int pageRank) |
135 void MostVisitedPageStore::pageAccessed(const QUrl& url, QImage* pageThumbnail, int pageRank) |
118 { |
136 { |
153 //check if we have crossed the store limit and remove last item if so |
171 //check if we have crossed the store limit and remove last item if so |
154 if (m_pageList.size() > KMostVistedStoreLimit) { |
172 if (m_pageList.size() > KMostVistedStoreLimit) { |
155 delete m_pageList.takeLast(); |
173 delete m_pageList.takeLast(); |
156 } |
174 } |
157 } else if (pageThumbnail) { |
175 } else if (pageThumbnail) { |
158 // add thumbnail, delete if it has any old thumbnail |
176 // add thumbnail, delete if it has any old thumbnail |
159 |
177 |
160 // This check is specifically added to take into account of |
178 //This check is specifically added to take into account of |
161 // future code changes if thumbnail gets assigned somewhere else |
179 //future code changes if thumbnail gets assigned somewhere else |
162 if (m_pageList[found]->m_pageThumbnail) { |
180 if (m_pageList[found]->m_pageThumbnail) { |
163 delete m_pageList[found]->m_pageThumbnail; |
181 delete m_pageList[found]->m_pageThumbnail; |
164 } |
182 } |
165 |
183 |
166 m_pageList[found]->m_pageThumbnail = pageThumbnail; |
184 m_pageList[found]->m_pageThumbnail = pageThumbnail; |
167 } |
185 } |
168 |
186 |
169 m_needPersistWrite = true; |
187 m_needPersistWrite = true; |
170 writeStore(); |
188 writeStore(); |
171 } |
189 } |
230 m_pageList.append(mvPage); |
248 m_pageList.append(mvPage); |
231 } |
249 } |
232 } |
250 } |
233 file.close(); |
251 file.close(); |
234 } |
252 } |
235 |
253 |
236 if (!m_pageList.size()) { |
254 initializeDefaultPageThumbnails(); |
237 m_pageList.append(new MostVisitedPage(KDefaultPage1)); |
|
238 m_pageList.append(new MostVisitedPage(KDefaultPage2)); |
|
239 m_pageList.append(new MostVisitedPage(KDefaultPage3)); |
|
240 m_pageList.append(new MostVisitedPage(KDefaultPage4)); |
|
241 m_pageList.append(new MostVisitedPage(KDefaultPage5)); |
|
242 } |
|
243 } |
255 } |
244 |
256 |
245 void MostVisitedPageStore::writeStore() |
257 void MostVisitedPageStore::writeStore() |
246 { |
258 { |
247 //if only store is modified then save it. |
259 //if only store is modified then save it. |
248 if (!m_needPersistWrite) |
260 |
|
261 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveHistory"); |
|
262 |
|
263 if ((!m_needPersistWrite) || (!enabled)) |
249 return; |
264 return; |
250 |
265 |
251 // save url store |
266 // save url store |
252 // version |
267 // version |
253 // url, thumbnail, rank |
268 // url, thumbnail, rank |