|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
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: |
|
19 * This class extends ToolbarSnippet class to hold the |
|
20 * windows view toolbar buttons |
|
21 * |
|
22 */ |
|
23 |
|
24 #include "BookmarksToolbarSnippet.h" |
|
25 #include "ToolbarChromeItem.h" |
|
26 #include "ViewStack.h" |
|
27 #include "GWebContentView.h" |
|
28 #include "BookmarksManager.h" |
|
29 #include <QDebug> |
|
30 |
|
31 namespace GVA { |
|
32 |
|
33 BookmarksToolbarSnippet::BookmarksToolbarSnippet(const QString& elementId, ChromeWidget * chrome, |
|
34 const QWebElement & element) |
|
35 : DualButtonToolbarSnippet(elementId, chrome, element), |
|
36 m_action1(0), m_action2(0) |
|
37 { |
|
38 } |
|
39 |
|
40 BookmarksToolbarSnippet::~BookmarksToolbarSnippet() |
|
41 { |
|
42 if(m_action1) |
|
43 delete m_action1; |
|
44 if(m_action2) |
|
45 delete m_action2; |
|
46 } |
|
47 |
|
48 BookmarksToolbarSnippet * BookmarksToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
49 { |
|
50 BookmarksToolbarSnippet * that = new BookmarksToolbarSnippet( elementId, chrome, element ); |
|
51 that->setChromeWidget( new ToolbarChromeItem( that ) ); |
|
52 return that; |
|
53 } |
|
54 |
|
55 void BookmarksToolbarSnippet::addChild(ChromeSnippet * child) { |
|
56 WebChromeContainerSnippet * s = dynamic_cast<WebChromeContainerSnippet* >(child); |
|
57 if (!s) { |
|
58 ToolbarActions_t* t = new ToolbarActions_t(); |
|
59 if (child->elementId() == "BookmarksBackButton" ) { |
|
60 t->actionId = BOOKMARKS_VIEW_ACTION_BACK; |
|
61 t->actionName = BOOKMARKS_TOOLBAR_BACK; |
|
62 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png"; |
|
63 t->disabledImg = ""; |
|
64 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png"; |
|
65 } |
|
66 else if (child->elementId() == "BookmarksAddButton" ) { |
|
67 t->actionId = BOOKMARKS_VIEW_ACTION_ADD; |
|
68 t->actionName = BOOKMARKS_TOOLBAR_ADD; |
|
69 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add.png"; |
|
70 t->disabledImg = ""; |
|
71 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_pressed.png"; |
|
72 } |
|
73 t->id = child->elementId(); |
|
74 m_actionInfo.append(t); |
|
75 } |
|
76 |
|
77 WebChromeContainerSnippet::addChild(child); |
|
78 } |
|
79 |
|
80 void BookmarksToolbarSnippet::setAction(ChromeSnippet * s) { |
|
81 ToolbarSnippet::setAction(s); |
|
82 |
|
83 ActionButtonSnippet * button = static_cast<ActionButtonSnippet*> (s); |
|
84 int index = getIndex(s); |
|
85 |
|
86 if (index != -1 ) { |
|
87 ToolbarActions_t * t = m_actionInfo.at(index); |
|
88 QAction * action = button->getDefaultAction(); |
|
89 if (t->actionId == BOOKMARKS_VIEW_ACTION_BACK ) { |
|
90 if( !action ) { |
|
91 action = new QAction(0); |
|
92 button->setDefaultAction(action); |
|
93 m_action1 = action; |
|
94 } |
|
95 connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton())); |
|
96 } |
|
97 else if (t->actionId == BOOKMARKS_VIEW_ACTION_ADD) { |
|
98 if( !action ) { |
|
99 action = new QAction(0); |
|
100 button->setDefaultAction(action); |
|
101 m_action2 = action; |
|
102 } |
|
103 connect(action, SIGNAL(triggered()), this, SIGNAL(addBookmarkSelected())); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 void BookmarksToolbarSnippet::handleBackButton() { |
|
109 GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView")); |
|
110 if(webView) { |
|
111 webView->showNormalPage(); |
|
112 webView->setGesturesEnabled(true); |
|
113 } |
|
114 |
|
115 ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_BOOKMARKS_VIEW ); |
|
116 } |
|
117 |
|
118 } // end of namespace GVA |
|
119 |
|
120 |