ginebra2/BookmarksToolbarSnippet.cpp
author hgs
Fri, 06 Aug 2010 17:23:08 -0400
changeset 9 b39122337a00
parent 3 0954f5dd2cd0
child 12 afcd8e6d025b
permissions -rw-r--r--
201031
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 "BookmarksToolbarSnippet.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
    BookmarksToolbarSnippet::BookmarksToolbarSnippet(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), m_action2(0)
hgs
parents:
diff changeset
    37
    {      
hgs
parents:
diff changeset
    38
    }
hgs
parents:
diff changeset
    39
hgs
parents:
diff changeset
    40
    BookmarksToolbarSnippet::~BookmarksToolbarSnippet()
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
        if(m_action2)
hgs
parents:
diff changeset
    45
            delete m_action2;
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
    
hgs
parents:
diff changeset
    48
    BookmarksToolbarSnippet * BookmarksToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
hgs
parents:
diff changeset
    49
    {
hgs
parents:
diff changeset
    50
        BookmarksToolbarSnippet * that = new BookmarksToolbarSnippet( elementId, chrome, element );
hgs
parents:
diff changeset
    51
        that->setChromeWidget( new ToolbarChromeItem( that ) );
hgs
parents:
diff changeset
    52
        return that;
hgs
parents:
diff changeset
    53
    }
hgs
parents:
diff changeset
    54
    
hgs
parents:
diff changeset
    55
    void BookmarksToolbarSnippet::addChild(ChromeSnippet * child) {
hgs
parents:
diff changeset
    56
        WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
hgs
parents:
diff changeset
    57
        if (!s) {
hgs
parents:
diff changeset
    58
            ToolbarActions_t* t = new ToolbarActions_t();
hgs
parents:
diff changeset
    59
            if (child->elementId() == "BookmarksBackButton" ) {
hgs
parents:
diff changeset
    60
                t->actionId = BOOKMARKS_VIEW_ACTION_BACK;
hgs
parents:
diff changeset
    61
                t->actionName = BOOKMARKS_TOOLBAR_BACK;
hgs
parents:
diff changeset
    62
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
hgs
parents:
diff changeset
    63
                t->disabledImg = "";
hgs
parents:
diff changeset
    64
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
hgs
parents:
diff changeset
    65
            }
hgs
parents:
diff changeset
    66
            else if (child->elementId() == "BookmarksAddButton" ) {
hgs
parents:
diff changeset
    67
                t->actionId = BOOKMARKS_VIEW_ACTION_ADD;
hgs
parents:
diff changeset
    68
                t->actionName = BOOKMARKS_TOOLBAR_ADD;
hgs
parents:
diff changeset
    69
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add.png";
hgs
parents:
diff changeset
    70
                t->disabledImg = "";
hgs
parents:
diff changeset
    71
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_pressed.png";
hgs
parents:
diff changeset
    72
            }
hgs
parents:
diff changeset
    73
            t->id = child->elementId();
hgs
parents:
diff changeset
    74
            m_actionInfo.append(t);
hgs
parents:
diff changeset
    75
        }
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
        WebChromeContainerSnippet::addChild(child);
hgs
parents:
diff changeset
    78
    }
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
    void BookmarksToolbarSnippet::setAction(ChromeSnippet * s) {
hgs
parents:
diff changeset
    81
        ToolbarSnippet::setAction(s);
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
        ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
hgs
parents:
diff changeset
    84
        int index = getIndex(s);
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
        if (index != -1 ) {
hgs
parents:
diff changeset
    87
            ToolbarActions_t * t = m_actionInfo.at(index);
hgs
parents:
diff changeset
    88
            QAction * action =  button->getDefaultAction();
hgs
parents:
diff changeset
    89
            if (t->actionId == BOOKMARKS_VIEW_ACTION_BACK ) {
hgs
parents:
diff changeset
    90
                if( !action ) {
hgs
parents:
diff changeset
    91
                    action = new QAction(0);
hgs
parents:
diff changeset
    92
                    button->setDefaultAction(action);
hgs
parents:
diff changeset
    93
                    m_action1 = action;
hgs
parents:
diff changeset
    94
                }
hgs
parents:
diff changeset
    95
                connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
hgs
parents:
diff changeset
    96
            }
hgs
parents:
diff changeset
    97
            else if (t->actionId == BOOKMARKS_VIEW_ACTION_ADD) {
hgs
parents:
diff changeset
    98
                if( !action ) {
hgs
parents:
diff changeset
    99
                    action = new QAction(0);
hgs
parents:
diff changeset
   100
                    button->setDefaultAction(action);
hgs
parents:
diff changeset
   101
                    m_action2 = action;
hgs
parents:
diff changeset
   102
                }
hgs
parents:
diff changeset
   103
                connect(action, SIGNAL(triggered()), this, SIGNAL(addBookmarkSelected()));
hgs
parents:
diff changeset
   104
            }
hgs
parents:
diff changeset
   105
        }
hgs
parents:
diff changeset
   106
    }
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
    void BookmarksToolbarSnippet::handleBackButton() {
hgs
parents:
diff changeset
   109
        GWebContentView* webView = static_cast<GWebContentView*> (chrome()->getView("WebView"));
hgs
parents:
diff changeset
   110
        if(webView) {
hgs
parents:
diff changeset
   111
            webView->showNormalPage();
hgs
parents:
diff changeset
   112
            webView->setGesturesEnabled(true);
hgs
parents:
diff changeset
   113
        }
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
        ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_BOOKMARKS_VIEW );
hgs
parents:
diff changeset
   116
    }
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
} // end of namespace GVA
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120