~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kicker/kicker/ui/removebutton_mnu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 2001 Matthias Elter <elter@kde.org>
 
4
 
 
5
Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
of this software and associated documentation files (the "Software"), to deal
 
7
in the Software without restriction, including without limitation the rights
 
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the Software is
 
10
furnished to do so, subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
******************************************************************/
 
23
 
 
24
#include <QRegExp>
 
25
#include <Qt3Support/q3tl.h>
 
26
 
 
27
#include <QList>
 
28
#include <QMenu>
 
29
#include <kiconloader.h>
 
30
#include <klocale.h>
 
31
#include <kglobal.h>
 
32
#include <kdebug.h>
 
33
 
 
34
#include "panelbutton.h"
 
35
#include "pluginmanager.h"
 
36
#include "containerarea.h"
 
37
#include "container_button.h"
 
38
 
 
39
#include "panelmenuiteminfo.h"
 
40
#include "removebutton_mnu.h"
 
41
#include "removebutton_mnu.moc"
 
42
 
 
43
PanelRemoveButtonMenu::PanelRemoveButtonMenu( ContainerArea* cArea,
 
44
                                              QWidget *parent )
 
45
    : QMenu( parent ), containerArea( cArea )
 
46
{
 
47
    connect(this, SIGNAL(activated(int)), SLOT(slotExec(int)));
 
48
    connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
 
49
}
 
50
 
 
51
void PanelRemoveButtonMenu::addToContainers(const QString& type)
 
52
{
 
53
    BaseContainer::List list = containerArea->containers(type);
 
54
    for (BaseContainer::Iterator it = list.begin();
 
55
         it != list.end();
 
56
         ++it)
 
57
    {
 
58
        if ((*it)->isImmutable())
 
59
        {
 
60
            continue;
 
61
        }
 
62
        containers.append(*it);
 
63
    }
 
64
}
 
65
 
 
66
void PanelRemoveButtonMenu::slotAboutToShow()
 
67
{
 
68
    clear();
 
69
    containers.clear();
 
70
 
 
71
    addToContainers("URLButton");
 
72
    addToContainers("ServiceButton");
 
73
    addToContainers("ServiceMenuButton");
 
74
    addToContainers("ExecButton");
 
75
 
 
76
    int id = 0;
 
77
    PanelMenuItemInfo::List items;
 
78
    for (BaseContainer::Iterator it = containers.begin(); it != containers.end(); ++it)
 
79
    {
 
80
        items.append(PanelMenuItemInfo((*it)->icon(), (*it)->visibleName(), id));
 
81
        id++;
 
82
    }
 
83
 
 
84
    qHeapSort(items);
 
85
 
 
86
    for (PanelMenuItemInfo::List::iterator it = items.begin();
 
87
         it != items.end();
 
88
         ++it)
 
89
    {
 
90
        (*it).plug(this);
 
91
    }
 
92
 
 
93
    if (containers.count() > 1)
 
94
    {
 
95
        addSeparator();
 
96
        insertItem(i18n("All"), this, SLOT(slotRemoveAll()), 0, id);
 
97
    }
 
98
}
 
99
 
 
100
void PanelRemoveButtonMenu::slotExec( int id )
 
101
{
 
102
    if (containers.at(id) != containers.back())
 
103
    {
 
104
        containerArea->removeContainer(containers.at(id));
 
105
    }
 
106
}
 
107
 
 
108
PanelRemoveButtonMenu::~PanelRemoveButtonMenu()
 
109
{
 
110
}
 
111
 
 
112
void PanelRemoveButtonMenu::slotRemoveAll()
 
113
{
 
114
    containerArea->removeContainers(containers);
 
115
}