|
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 "SettingsToolbarSnippet.h" |
|
25 #include "ToolbarChromeItem.h" |
|
26 #include "ViewStack.h" |
|
27 #include "GWebContentView.h" |
|
28 #include "webpagecontroller.h" |
|
29 #include <QDebug> |
|
30 |
|
31 namespace GVA { |
|
32 |
|
33 SettingsToolbarSnippet::SettingsToolbarSnippet(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 SettingsToolbarSnippet::~SettingsToolbarSnippet() |
|
41 { |
|
42 if(m_action1) |
|
43 delete m_action1; |
|
44 if(m_action2) |
|
45 delete m_action2; |
|
46 } |
|
47 |
|
48 SettingsToolbarSnippet * SettingsToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
49 { |
|
50 SettingsToolbarSnippet * that = new SettingsToolbarSnippet( elementId, chrome, element ); |
|
51 that->setChromeWidget( new ToolbarChromeItem( that ) ); |
|
52 return that; |
|
53 } |
|
54 |
|
55 void SettingsToolbarSnippet::addChild(ChromeSnippet * child) { |
|
56 WebChromeContainerSnippet * s = dynamic_cast<WebChromeContainerSnippet* >(child); |
|
57 if (!s) { |
|
58 ToolbarActions_t* t = new ToolbarActions_t(); |
|
59 if (child->elementId() == "SettingsBackButton" ) { |
|
60 t->actionId = SETTINGS_VIEW_ACTION_BACK; |
|
61 t->actionName = SETTINGS_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() == "SettingsFeedbackButton" ) { |
|
67 t->actionId = SETTINGS_VIEW_ACTION_FEEDBACK; |
|
68 t->actionName = SETTINGS_TOOLBAR_FEEDBACK; |
|
69 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_feedback.png"; |
|
70 t->disabledImg = ""; |
|
71 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_feedback_pressed.png"; |
|
72 } |
|
73 t->id = child->elementId(); |
|
74 m_actionInfo.append(t); |
|
75 } |
|
76 |
|
77 WebChromeContainerSnippet::addChild(child); |
|
78 } |
|
79 |
|
80 void SettingsToolbarSnippet::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 == SETTINGS_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 == SETTINGS_VIEW_ACTION_FEEDBACK) { |
|
98 if( !action ) { |
|
99 action = new QAction(0); |
|
100 button->setDefaultAction(action); |
|
101 m_action2 = action; |
|
102 } |
|
103 connect(action, SIGNAL(triggered()), this, SLOT(handleFeedbackButton())); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 void SettingsToolbarSnippet::handleBackButton() { |
|
109 GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView")); |
|
110 if(webView) { |
|
111 // Reloading here because otherwise the settings won't collapse when leaving and |
|
112 // re-entering the view. This fixes BR-3525. If there's a better way to do this in |
|
113 // the future this can be removed. |
|
114 webView->reload(); |
|
115 webView->showNormalPage(); |
|
116 webView->setGesturesEnabled(true); |
|
117 } |
|
118 |
|
119 ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_SETTINGS_VIEW ); |
|
120 } |
|
121 |
|
122 void SettingsToolbarSnippet::handleFeedbackButton() { |
|
123 QString mailTo = "oss-browser.errors@nokia.com"; |
|
124 QString feedbackBody = "Enter your feedback here:"; |
|
125 WebPageController::getSingleton()->feedbackMail(mailTo, feedbackBody); |
|
126 } |
|
127 |
|
128 |
|
129 } // end of namespace GVA |
|
130 |
|
131 |