~ubuntu-branches/ubuntu/oneiric/polkit-qt-1/oneiric

« back to all changes in this revision

Viewing changes to .pc/kubuntu_01_fix_glib_ftbfs.diff/gui/polkitqt1-gui-actionbutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-11-07 01:18:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101107011828-qf5lzf950ih0l250
Tags: 0.98.1~git20101107-0ubuntu1
* New upstream snapshot:
  - Drop kubuntu_01_fix_glib_ftbfs.diff, accepted upstream
  - Bump build-depend versions on polkit to >= 0.98

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of the Polkit-qt project
3
 
 * Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
4
 
 * Copyright (C) 2009 Dario Freddi <drf@kde.org>
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Library General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2 of the License, or (at your option) any later version.
10
 
 *
11
 
 * This library is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
 
 * Library General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Library General Public License
17
 
 * along with this library; see the file COPYING.LIB. If not, write to
18
 
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 
 * Boston, MA 02110-1301, USA.
20
 
 */
21
 
 
22
 
#include "polkitqt1-gui-actionbutton.h"
23
 
 
24
 
#include "polkitqt1-gui-actionbutton_p.h"
25
 
 
26
 
namespace PolkitQt1
27
 
{
28
 
 
29
 
namespace Gui
30
 
{
31
 
 
32
 
ActionButton::ActionButton(QAbstractButton *button, const QString &actionId, QObject *parent)
33
 
        : Action(actionId, parent)
34
 
        , d_ptr(new ActionButtonPrivate(QList<QAbstractButton *>() << button))
35
 
{
36
 
    d_ptr->q_ptr = this;
37
 
 
38
 
    setButton(button);
39
 
    connect(this, SIGNAL(dataChanged()), SLOT(updateButton()));
40
 
}
41
 
 
42
 
ActionButton::ActionButton(ActionButtonPrivate &dd, const QString &actionId, QObject *parent)
43
 
        : Action(actionId, parent)
44
 
        , d_ptr(&dd)
45
 
{
46
 
    d_ptr->q_ptr = this;
47
 
 
48
 
    connect(this, SIGNAL(dataChanged()), SLOT(updateButton()));
49
 
}
50
 
 
51
 
ActionButton::~ActionButton()
52
 
{
53
 
    delete d_ptr;
54
 
}
55
 
 
56
 
void ActionButtonPrivate::updateButton()
57
 
{
58
 
    Q_Q(ActionButton);
59
 
 
60
 
    foreach(QAbstractButton *ent, buttons) {
61
 
        ent->setVisible(q->isVisible());
62
 
        ent->setEnabled(q->isEnabled());
63
 
        ent->setText(q->text());
64
 
        if (!q->toolTip().isNull()) {
65
 
            ent->setToolTip(q->toolTip());
66
 
        }
67
 
        if (!q->whatsThis().isNull()) {
68
 
            ent->setWhatsThis(q->whatsThis());
69
 
        }
70
 
        ent->setIcon(q->icon());
71
 
        // if the item cannot do the action anymore
72
 
        // lets revert to the initial state
73
 
        if (ent->isCheckable()) {
74
 
            ent->setChecked(q->isChecked());
75
 
        }
76
 
    }
77
 
}
78
 
 
79
 
bool ActionButton::activate()
80
 
{
81
 
    Q_D(ActionButton);
82
 
 
83
 
    bool tg = false;
84
 
    foreach(QAbstractButton *ent, d->buttons) {
85
 
        if (ent->isCheckable()) {
86
 
            // we set the the current Action state
87
 
            ent->setChecked(isChecked());
88
 
            // toggle the action cause we are not directly connected there..
89
 
            tg = true;
90
 
        }
91
 
    }
92
 
 
93
 
    if (tg) {
94
 
        toggle();
95
 
    }
96
 
 
97
 
    return Action::activate();
98
 
}
99
 
 
100
 
void ActionButton::setButton(QAbstractButton *button)
101
 
{
102
 
    Q_D(ActionButton);
103
 
 
104
 
    // First, let's clear the list
105
 
    foreach(QAbstractButton *ent, d->buttons) {
106
 
        d->removeButton(ent);
107
 
    }
108
 
 
109
 
    // And then add it
110
 
    d->addButton(button);
111
 
}
112
 
 
113
 
void ActionButtonPrivate::addButton(QAbstractButton *button)
114
 
{
115
 
    Q_Q(ActionButton);
116
 
 
117
 
    buttons.append(button);
118
 
    QObject::connect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool)));
119
 
    QObject::connect(q, SIGNAL(toggled(bool)), button, SLOT(toggle()));
120
 
    if (q->isCheckable()) {
121
 
        // the button should follow our first buttons
122
 
        button->setCheckable(true);
123
 
    } else if (button->isCheckable()) {
124
 
        // if we are not checkable BUT the button
125
 
        // is (eg a QCheckBox) we should set all buttons to
126
 
        // checkable.
127
 
        foreach(QAbstractButton *ent, buttons) {
128
 
            ent->setCheckable(true);
129
 
        }
130
 
        // set the checkable state of Action to store the initial state
131
 
        q->setCheckable(true);
132
 
    }
133
 
    // call this after m_activateOnCheck receives the value
134
 
    updateButton();
135
 
}
136
 
 
137
 
void ActionButtonPrivate::removeButton(QAbstractButton *button)
138
 
{
139
 
    Q_Q(ActionButton);
140
 
 
141
 
    if (buttons.contains(button)) {
142
 
        QObject::disconnect(button, SIGNAL(clicked(bool)), q, SLOT(streamClicked(bool)));
143
 
        QObject::disconnect(q, SIGNAL(toggled(bool)), button, SLOT(toggle()));
144
 
        buttons.removeOne(button);
145
 
    }
146
 
}
147
 
 
148
 
QAbstractButton *ActionButton::button() const
149
 
{
150
 
    Q_D(const ActionButton);
151
 
 
152
 
    return d->buttons.first();
153
 
}
154
 
 
155
 
void ActionButtonPrivate::streamClicked(bool c)
156
 
{
157
 
    Q_Q(ActionButton);
158
 
 
159
 
    emit q->clicked(qobject_cast<QAbstractButton *>(q->sender()), c);
160
 
}
161
 
 
162
 
}
163
 
 
164
 
}
165
 
 
166
 
#include "polkitqt1-gui-actionbutton.moc"