~ubuntu-branches/ubuntu/precise/networkmanagement/precise

« back to all changes in this revision

Viewing changes to applet/activatableitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-10-23 14:00:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20111023140013-e38hdzybcg6zndrk
Tags: 0.9~svngit.nm09.20111023.ff842e-0ubuntu1
* New upstream snapshot.
* Drop all patches, merged upstream.
* Add kubuntu_add_subdirectory_po.diff to build the translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include <KIcon>
31
31
#include <KNotification>
 
32
#include <KGlobalSettings>
32
33
 
33
34
#include <Plasma/Animation>
34
35
#include <Plasma/Animator>
39
40
 
40
41
K_GLOBAL_STATIC_WITH_ARGS(KComponentData, s_networkManagementComponentData, ("networkmanagement", "networkmanagement", KComponentData::SkipMainComponentRegistration))
41
42
static const int m_iconSize = 48;
 
43
int rowHeight = qMax(28, QFontMetrics(KGlobalSettings::generalFont()).height()+10);
 
44
int maxConnectionNameWidth = QFontMetrics(KGlobalSettings::generalFont()).width("12345678901234567890123");
42
45
 
43
46
ActivatableItem::ActivatableItem(RemoteActivatable *remote, QGraphicsItem * parent) : Plasma::IconWidget(parent),
44
47
    m_activatable(remote),
45
48
    m_hasDefaultRoute(false),
46
49
    m_deleting(false),
47
 
    rowHeight(28), // TODO: try not to use hard coded value.
48
 
    spacing(4)
 
50
    spacing(4),
 
51
    m_connectButton(0)
49
52
{
50
53
    setDrawBackground(true);
51
54
    setTextBackgroundColor(QColor(Qt::transparent));
54
57
    if (remoteconnection) {
55
58
        connect(remoteconnection, SIGNAL(hasDefaultRouteChanged(bool)),
56
59
                SLOT(handleHasDefaultRouteChanged(bool)));
57
 
        connect(remoteconnection, SIGNAL(activationStateChanged(Knm::InterfaceConnection::ActivationState)),
58
 
                SLOT(activationStateChanged(Knm::InterfaceConnection::ActivationState)));
 
60
        connect(remoteconnection, SIGNAL(activationStateChanged(Knm::InterfaceConnection::ActivationState, Knm::InterfaceConnection::ActivationState)),
 
61
                SLOT(activationStateChanged(Knm::InterfaceConnection::ActivationState, Knm::InterfaceConnection::ActivationState)));
59
62
    }
60
63
 
61
64
    // Fade in when this widget appears
92
95
void ActivatableItem::emitClicked()
93
96
{
94
97
    if (m_activatable) {
95
 
        m_activatable->activate();
 
98
        RemoteInterfaceConnection * remote = interfaceConnection();
 
99
        if (remote && (remote->activationState() == Knm::InterfaceConnection::Activating ||
 
100
                       remote->activationState() == Knm::InterfaceConnection::Activated)) {
 
101
            emit showInterfaceDetails(remote->deviceUni());
 
102
        } else {
 
103
            m_activatable->activate();
 
104
        }
 
105
        emit clicked(this);
96
106
    }
97
 
    emit clicked(this);
98
107
 
99
108
    if (!Solid::Control::NetworkManagerNm09::isNetworkingEnabled()) {
100
109
        KNotification::event(Event::NetworkingDisabled, i18nc("@info:status Notification when the networking subsystem (NetworkManager, etc) is disabled", "Networking system disabled"), QPixmap(), 0, KNotification::CloseOnTimeout, *s_networkManagementComponentData)->sendEvent();
121
130
{
122
131
    Plasma::IconWidget::paint(painter, option, widget);
123
132
    if (m_hasDefaultRoute) {
 
133
        // TODO: this draws the pixmap behind the connection icon. This is the same
 
134
        // problem described in a comment in networkmanager.cpp:NetworkManagerApplet::paintInterface.
124
135
        painter->drawPixmap(QRect(4,4,12,12), KIcon("network-defaultroute").pixmap(QSize(16,16)));
125
136
    }
126
137
}
127
138
 
128
 
void ActivatableItem::activationStateChanged(Knm::InterfaceConnection::ActivationState state)
 
139
void ActivatableItem::activationStateChanged(Knm::InterfaceConnection::ActivationState oldState, Knm::InterfaceConnection::ActivationState newState)
129
140
{
 
141
    Q_UNUSED(oldState);
 
142
    m_state = newState;
 
143
 
 
144
    if (!m_connectButton) {
 
145
        return;
 
146
    }
 
147
 
130
148
    // Update the view of the connection, manipulate font based on activation state.
131
 
    kDebug() << state;
132
 
    QFont f = font();
133
 
    switch (state) {
 
149
    kDebug() << newState;
 
150
    QFont f = m_connectButton->font();
 
151
    switch (newState) {
134
152
        //Knm::InterfaceConnectihon::ActivationState
135
153
        case Knm::InterfaceConnection::Activated:
136
154
            kDebug() << "activated";
147
165
            f.setBold(false);
148
166
            f.setItalic(true);
149
167
    }
150
 
    setFont(f);
 
168
    m_connectButton->setFont(f);
151
169
}
152
170
 
153
171
void ActivatableItem::hoverEnter()