ginebra2/WindowToolbarSnippet.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 06 Jul 2010 14:03:49 +0300
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 15 73c48011b8c7
permissions -rw-r--r--
Revision: 201026 Kit: 2010127
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
 *
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
 * it under the terms of the GNU Lesser General Public License as published by
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
 * the Free Software Foundation, version 2.1 of the License.
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
 *
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
 * GNU Lesser General Public License for more details.
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
 *
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU Lesser General Public License
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 * along with this program.  If not,
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
 *
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
 * Description:
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
 * This class extends ToolbarSnippet class to hold the
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
 * windows view toolbar buttons
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
 *
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
 */
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include "WindowToolbarSnippet.h"
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    25
#include "ToolbarChromeItem.h"
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include "ViewStack.h"
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <QDebug>
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
namespace GVA {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
    WindowToolbarSnippet::WindowToolbarSnippet(const QString& elementId, ChromeWidget * chrome,
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    32
                                               const QWebElement & element)
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    33
        : DualButtonToolbarSnippet(elementId, chrome, element)
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
    {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
        m_type = TOOLBAR_WINDOWS_VIEW;
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
    WindowToolbarSnippet::~WindowToolbarSnippet()
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
    }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    42
    WindowToolbarSnippet * WindowToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    43
    {
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    44
        WindowToolbarSnippet * that = new WindowToolbarSnippet(elementId, chrome, element);
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    45
        that->setChromeWidget(new ToolbarChromeItem(that));
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    46
        return that;
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    47
    }
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    48
    
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    void WindowToolbarSnippet::addChild(ChromeSnippet * child) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
        WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
        if (!s) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
            ToolbarActions_t* t = new ToolbarActions_t();
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
            if (child->elementId() == "WinBackButton" ) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
                t->actionId = WINDOW_VIEW_ACTION_BACK;
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
                t->actionName = WINDOW_TOOLBAR_BACK;
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    57
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
                t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_disabled.png";
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    59
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
            }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
            else if (child->elementId() == "WinAddWindow" ) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
                t->actionId = WINDOW_VIEW_ACTION_ADD;
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
                t->actionName = WINDOW_TOOLBAR_ADD;
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    65
                t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add.png";
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
                t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_disabled.png";
6
1c3b8676e58c Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 5
diff changeset
    67
                t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_pressed.png";
5
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
            }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
            t->id = child->elementId();
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
            m_actionInfo.append(t);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
        }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
        WebChromeContainerSnippet::addChild(child);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
    void WindowToolbarSnippet::setAction(ChromeSnippet * s) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
        //qDebug() << "setAction: " << s->elementId();
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
        ToolbarSnippet::setAction(s);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
        ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
        int index = getIndex(s);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
        if (index != -1 ) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
            ToolbarActions_t * t = m_actionInfo.at(index);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
            if (t->actionId == WINDOW_VIEW_ACTION_BACK ) {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
                QAction * action =  button->getDefaultAction();
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
                connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
            }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
        }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
    }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
    void WindowToolbarSnippet::handleBackButton() {
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
        ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_WINDOWS_VIEW);
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
    }
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
} // end of namespace GVA
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
0f2326c2a325 Revision: 201024
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103