ginebra2/RecentUrlToolbarSnippet.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 23 Jun 2010 17:59:43 +0300
changeset 5 0f2326c2a325
child 6 1c3b8676e58c
permissions -rw-r--r--
Revision: 201024 Kit: 2010125

/*
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 2.1 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not,
 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
 * Description:
 * This class extends ToolbarSnippet class to hold the
 * windows view toolbar buttons
 *
 */

#include "RecentUrlToolbarSnippet.h"
#include "ViewStack.h"
#include "GWebContentView.h"
#include "BookmarksManager.h"
#include <QDebug>

namespace GVA {

    RecentUrlToolbarSnippet::RecentUrlToolbarSnippet(const QString& elementId, ChromeWidget * chrome,
                                                     const QRectF& ownerArea, const QWebElement & element, QGraphicsWidget * widget)
        : DualButtonToolbarSnippet(elementId, chrome, ownerArea, element, widget),
          m_action1(0)
    {      
    }

    RecentUrlToolbarSnippet::~RecentUrlToolbarSnippet()
    {
        if(m_action1)
            delete m_action1;
    }

    void RecentUrlToolbarSnippet::addChild(ChromeSnippet * child) {
        WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
        if (!s) {
            ToolbarActions_t* t = new ToolbarActions_t();
            if (child->elementId() == "RecentBackButton" ) {
                t->actionId = RECENTURL_VIEW_ACTION_BACK;
                t->actionName = RECENTURL_TOOLBAR_BACK;
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
                t->disabledImg = "";
                t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
            }
            else if (child->elementId() == "RecentClearallButton" ) {
                t->actionId = RECENTURL_VIEW_ACTION_CLEARALL;
                t->actionName = RECENTURL_TOOLBAR_CLEARALL;
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall.png";
                t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_disabled.png";
                t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_pressed.png";
            }
            t->id = child->elementId();
            m_actionInfo.append(t);
        }

        WebChromeContainerSnippet::addChild(child);
    }

    void RecentUrlToolbarSnippet::setAction(ChromeSnippet * s) {
        ToolbarSnippet::setAction(s);

        ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
        int index = getIndex(s);

        if (index != -1 ) {
            ToolbarActions_t * t = m_actionInfo.at(index);
            QAction * action =  button->getDefaultAction();
            if (t->actionId == RECENTURL_VIEW_ACTION_BACK ) {
                if( !action ) {
                    action = new QAction(0);
                    button->setDefaultAction(action);
                    m_action1 = action;
                }
                connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
            }
            else if (t->actionId == RECENTURL_VIEW_ACTION_CLEARALL) {
                if( !action ) {
					// Action is created/handled/owned by BookmarksManager
                    QAction * a = WRT::BookmarksManager::getSingleton()->getActionClearHistory();
                    button->setDefaultAction(a);
                }
            }
        }
    }

    void RecentUrlToolbarSnippet::handleBackButton() {
        GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView"));
        if(webView)
            webView->showNormalPage();
        ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_RECENTURL_VIEW );
    }

} // end of namespace GVA