ginebra2/RecentUrlToolbarSnippet.cpp
author hgs
Tue, 29 Jun 2010 00:46:29 -0400
changeset 3 0954f5dd2cd0
child 12 afcd8e6d025b
permissions -rw-r--r--
201026
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 *
hgs
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
hgs
parents:
diff changeset
     6
 * it under the terms of the GNU Lesser General Public License as published by
hgs
parents:
diff changeset
     7
 * the Free Software Foundation, version 2.1 of the License.
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
hgs
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
hgs
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
hgs
parents:
diff changeset
    12
 * GNU Lesser General Public License for more details.
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * You should have received a copy of the GNU Lesser General Public License
hgs
parents:
diff changeset
    15
 * along with this program.  If not,
hgs
parents:
diff changeset
    16
 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
hgs
parents:
diff changeset
    17
 *
hgs
parents:
diff changeset
    18
 * Description:
hgs
parents:
diff changeset
    19
 * This class extends ToolbarSnippet class to hold the
hgs
parents:
diff changeset
    20
 * windows view toolbar buttons
hgs
parents:
diff changeset
    21
 *
hgs
parents:
diff changeset
    22
 */
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
#include "RecentUrlToolbarSnippet.h"
hgs
parents:
diff changeset
    25
#include "ToolbarChromeItem.h"
hgs
parents:
diff changeset
    26
#include "ViewStack.h"
hgs
parents:
diff changeset
    27
#include "GWebContentView.h"
hgs
parents:
diff changeset
    28
#include "BookmarksManager.h"
hgs
parents:
diff changeset
    29
#include <QDebug>
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
namespace GVA {
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
    RecentUrlToolbarSnippet::RecentUrlToolbarSnippet(const QString& elementId, ChromeWidget * chrome,
hgs
parents:
diff changeset
    34
                                                     const QWebElement & element)
hgs
parents:
diff changeset
    35
        : DualButtonToolbarSnippet(elementId, chrome, element),
hgs
parents:
diff changeset
    36
          m_action1(0)
hgs
parents:
diff changeset
    37
    {      
hgs
parents:
diff changeset
    38
    }
hgs
parents:
diff changeset
    39
hgs
parents:
diff changeset
    40
    RecentUrlToolbarSnippet::~RecentUrlToolbarSnippet()
hgs
parents:
diff changeset
    41
    {
hgs
parents:
diff changeset
    42
        if(m_action1)
hgs
parents:
diff changeset
    43
            delete m_action1;
hgs
parents:
diff changeset
    44
    }
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
    RecentUrlToolbarSnippet * RecentUrlToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
hgs
parents:
diff changeset
    47
    {
hgs
parents:
diff changeset
    48
        RecentUrlToolbarSnippet * that = new RecentUrlToolbarSnippet( elementId, chrome, element );
hgs
parents:
diff changeset
    49
        that->setChromeWidget( new ToolbarChromeItem( that ) );
hgs
parents:
diff changeset
    50
        return that;
hgs
parents:
diff changeset
    51
    }
hgs
parents:
diff changeset
    52
    
hgs
parents:
diff changeset
    53
    void RecentUrlToolbarSnippet::addChild(ChromeSnippet * child) {
hgs
parents:
diff changeset
    54
        WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
hgs
parents:
diff changeset
    55
        if (!s) {
hgs
parents:
diff changeset
    56
            ToolbarActions_t* t = new ToolbarActions_t();
hgs
parents:
diff changeset
    57
            if (child->elementId() == "RecentBackButton" ) {
hgs
parents:
diff changeset
    58
                t->actionId = RECENTURL_VIEW_ACTION_BACK;
hgs
parents:
diff changeset
    59
                t->actionName = RECENTURL_TOOLBAR_BACK;
hgs
parents:
diff changeset
    60
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
hgs
parents:
diff changeset
    61
                t->disabledImg = "";
hgs
parents:
diff changeset
    62
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
hgs
parents:
diff changeset
    63
            }
hgs
parents:
diff changeset
    64
            else if (child->elementId() == "RecentClearallButton" ) {
hgs
parents:
diff changeset
    65
                t->actionId = RECENTURL_VIEW_ACTION_CLEARALL;
hgs
parents:
diff changeset
    66
                t->actionName = RECENTURL_TOOLBAR_CLEARALL;
hgs
parents:
diff changeset
    67
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall.png";
hgs
parents:
diff changeset
    68
                t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_disabled.png";
hgs
parents:
diff changeset
    69
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_pressed.png";
hgs
parents:
diff changeset
    70
            }
hgs
parents:
diff changeset
    71
            t->id = child->elementId();
hgs
parents:
diff changeset
    72
            m_actionInfo.append(t);
hgs
parents:
diff changeset
    73
        }
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
        WebChromeContainerSnippet::addChild(child);
hgs
parents:
diff changeset
    76
    }
hgs
parents:
diff changeset
    77
hgs
parents:
diff changeset
    78
    void RecentUrlToolbarSnippet::setAction(ChromeSnippet * s) {
hgs
parents:
diff changeset
    79
        ToolbarSnippet::setAction(s);
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
        ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
hgs
parents:
diff changeset
    82
        int index = getIndex(s);
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
        if (index != -1 ) {
hgs
parents:
diff changeset
    85
            ToolbarActions_t * t = m_actionInfo.at(index);
hgs
parents:
diff changeset
    86
            QAction * action =  button->getDefaultAction();
hgs
parents:
diff changeset
    87
            if (t->actionId == RECENTURL_VIEW_ACTION_BACK ) {
hgs
parents:
diff changeset
    88
                if( !action ) {
hgs
parents:
diff changeset
    89
                    action = new QAction(0);
hgs
parents:
diff changeset
    90
                    button->setDefaultAction(action);
hgs
parents:
diff changeset
    91
                    m_action1 = action;
hgs
parents:
diff changeset
    92
                }
hgs
parents:
diff changeset
    93
                connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
hgs
parents:
diff changeset
    94
            }
hgs
parents:
diff changeset
    95
            else if (t->actionId == RECENTURL_VIEW_ACTION_CLEARALL) {
hgs
parents:
diff changeset
    96
                if( !action ) {
hgs
parents:
diff changeset
    97
					// Action is created/handled/owned by BookmarksManager
hgs
parents:
diff changeset
    98
                    QAction * a = WRT::BookmarksManager::getSingleton()->getActionClearHistory();
hgs
parents:
diff changeset
    99
                    button->setDefaultAction(a);
hgs
parents:
diff changeset
   100
                }
hgs
parents:
diff changeset
   101
            }
hgs
parents:
diff changeset
   102
        }
hgs
parents:
diff changeset
   103
    }
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
    void RecentUrlToolbarSnippet::handleBackButton() {
hgs
parents:
diff changeset
   106
        GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView"));
hgs
parents:
diff changeset
   107
        if(webView)
hgs
parents:
diff changeset
   108
            webView->showNormalPage();
hgs
parents:
diff changeset
   109
        ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_RECENTURL_VIEW );
hgs
parents:
diff changeset
   110
    }
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
} // end of namespace GVA
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114