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