ginebra2/RecentUrlToolbarSnippet.cpp
changeset 5 0f2326c2a325
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
       
     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 "RecentUrlToolbarSnippet.h"
       
    25 #include "ViewStack.h"
       
    26 #include "GWebContentView.h"
       
    27 #include "BookmarksManager.h"
       
    28 #include <QDebug>
       
    29 
       
    30 namespace GVA {
       
    31 
       
    32     RecentUrlToolbarSnippet::RecentUrlToolbarSnippet(const QString& elementId, ChromeWidget * chrome,
       
    33                                                      const QRectF& ownerArea, const QWebElement & element, QGraphicsWidget * widget)
       
    34         : DualButtonToolbarSnippet(elementId, chrome, ownerArea, element, widget),
       
    35           m_action1(0)
       
    36     {      
       
    37     }
       
    38 
       
    39     RecentUrlToolbarSnippet::~RecentUrlToolbarSnippet()
       
    40     {
       
    41         if(m_action1)
       
    42             delete m_action1;
       
    43     }
       
    44 
       
    45     void RecentUrlToolbarSnippet::addChild(ChromeSnippet * child) {
       
    46         WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
       
    47         if (!s) {
       
    48             ToolbarActions_t* t = new ToolbarActions_t();
       
    49             if (child->elementId() == "RecentBackButton" ) {
       
    50                 t->actionId = RECENTURL_VIEW_ACTION_BACK;
       
    51                 t->actionName = RECENTURL_TOOLBAR_BACK;
       
    52                 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
       
    53                 t->disabledImg = "";
       
    54                 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
       
    55             }
       
    56             else if (child->elementId() == "RecentClearallButton" ) {
       
    57                 t->actionId = RECENTURL_VIEW_ACTION_CLEARALL;
       
    58                 t->actionName = RECENTURL_TOOLBAR_CLEARALL;
       
    59                 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall.png";
       
    60                 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_disabled.png";
       
    61                 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_clearall_pressed.png";
       
    62             }
       
    63             t->id = child->elementId();
       
    64             m_actionInfo.append(t);
       
    65         }
       
    66 
       
    67         WebChromeContainerSnippet::addChild(child);
       
    68     }
       
    69 
       
    70     void RecentUrlToolbarSnippet::setAction(ChromeSnippet * s) {
       
    71         ToolbarSnippet::setAction(s);
       
    72 
       
    73         ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
       
    74         int index = getIndex(s);
       
    75 
       
    76         if (index != -1 ) {
       
    77             ToolbarActions_t * t = m_actionInfo.at(index);
       
    78             QAction * action =  button->getDefaultAction();
       
    79             if (t->actionId == RECENTURL_VIEW_ACTION_BACK ) {
       
    80                 if( !action ) {
       
    81                     action = new QAction(0);
       
    82                     button->setDefaultAction(action);
       
    83                     m_action1 = action;
       
    84                 }
       
    85                 connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
       
    86             }
       
    87             else if (t->actionId == RECENTURL_VIEW_ACTION_CLEARALL) {
       
    88                 if( !action ) {
       
    89 					// Action is created/handled/owned by BookmarksManager
       
    90                     QAction * a = WRT::BookmarksManager::getSingleton()->getActionClearHistory();
       
    91                     button->setDefaultAction(a);
       
    92                 }
       
    93             }
       
    94         }
       
    95     }
       
    96 
       
    97     void RecentUrlToolbarSnippet::handleBackButton() {
       
    98         GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView"));
       
    99         if(webView)
       
   100             webView->showNormalPage();
       
   101         ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_RECENTURL_VIEW );
       
   102     }
       
   103 
       
   104 } // end of namespace GVA
       
   105 
       
   106