~ubuntu-branches/ubuntu/precise/plasma-widget-networkmanagement/precise

« back to all changes in this revision

Viewing changes to applet/activatablelistwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-08-24 15:34:36 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100824153436-9o7x461aj0xthuc3
Tags: 0.9~svn1167391-0ubuntu1
* New upstream snapshot
* Add kubuntu_04_no_tests.diff to not build tests, they fail

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "remoteactivatablelist.h"
38
38
#include "remoteinterfaceconnection.h"
39
39
#include "remotewirelessnetwork.h"
 
40
#include "remotegsminterfaceconnection.h"
40
41
#include "activatableitem.h"
41
42
 
42
43
// networkmanagement applet
43
44
#include "interfaceconnectionitem.h"
44
45
#include "wirelessnetworkitem.h"
45
46
#include "hiddenwirelessnetworkitem.h"
 
47
#include "gsminterfaceconnectionitem.h"
46
48
 
47
49
ActivatableListWidget::ActivatableListWidget(RemoteActivatableList* activatables, QGraphicsWidget* parent) : Plasma::ScrollWidget(parent),
48
50
    m_activatables(activatables),
93
95
 
94
96
void ActivatableListWidget::addInterface(Solid::Control::NetworkInterface* iface)
95
97
{
 
98
    kDebug() << "interface added";
96
99
    if (iface) {
97
100
        m_interfaces << iface->uni();
98
101
        m_showAllTypes = true;
107
110
    filter();
108
111
}
109
112
 
110
 
void ActivatableListWidget::setShowAllTypes(bool show)
 
113
void ActivatableListWidget::setShowAllTypes(bool show, bool refresh)
111
114
{
112
115
    m_showAllTypes = show;
113
 
    filter();
 
116
    if (show) {
 
117
        m_vpn = false;
 
118
    }
 
119
    if (refresh) {
 
120
        filter();
 
121
    }
114
122
}
115
123
 
116
124
void ActivatableListWidget::toggleVpn()
117
125
{
118
126
    kDebug() << "VPN toggled";
119
 
    m_vpn = !m_vpn;
 
127
    m_vpn = true;
120
128
    filter();
121
129
}
122
130
 
129
137
            return false;
130
138
        }
131
139
    }
132
 
    // Policy wether an activatable should be shown or not.
 
140
    // Policy whether an activatable should be shown or not.
133
141
    if (m_interfaces.count()) {
134
142
        // If interfaces are set, activatables for other interfaces are not shown
135
143
        if (m_interfaces.contains(activatable->deviceUni())) {
176
184
            ai = new HiddenWirelessNetworkItem(static_cast<RemoteInterfaceConnection*>(activatable), m_widget);
177
185
            break;
178
186
        }
 
187
#ifdef COMPILE_MODEM_MANAGER_SUPPORT
 
188
        case Knm::Activatable::GsmInterfaceConnection:
 
189
        { // Gsm (2G, 3G, etc)
 
190
            GsmInterfaceConnectionItem* gici = new GsmInterfaceConnectionItem(static_cast<RemoteGsmInterfaceConnection*>(activatable), m_widget);
 
191
            ai = gici;
 
192
            break;
 
193
        }
 
194
#endif
179
195
        default:
180
196
            break;
181
197
    }
184
200
    ai->setupItem();
185
201
    m_layout->addItem(ai);
186
202
    m_itemIndex[activatable] = ai;
 
203
    connect(ai, SIGNAL(disappearAnimationFinished()),
 
204
            this, SLOT(deleteItem()));
 
205
 
187
206
}
188
207
 
189
208
void ActivatableListWidget::listAppeared()
198
217
void ActivatableListWidget::deactivateConnection(const QString& deviceUni)
199
218
{
200
219
    foreach (ActivatableItem* item, m_itemIndex) {
 
220
        if (!item) { // the item might be gone here
 
221
            continue;
 
222
        }
201
223
        RemoteInterfaceConnection *conn = item->interfaceConnection();
202
224
        if (conn && conn->deviceUni() == deviceUni) {
203
225
            //kDebug() << "deactivating" << conn->connectionName();
229
251
        if (accept(act)) {
230
252
            createItem(act);
231
253
        } else {
232
 
            activatableRemoved(act);
 
254
            if (m_itemIndex.keys().contains(act)) {
 
255
                activatableRemoved(act);
 
256
            }
233
257
        }
234
258
    }
235
259
    m_layout->invalidate();
237
261
 
238
262
void ActivatableListWidget::activatableRemoved(RemoteActivatable * removed)
239
263
{
240
 
    m_layout->removeItem(m_itemIndex[removed]);
241
 
    delete m_itemIndex[removed];
242
 
    m_itemIndex.remove(removed);
 
264
    ActivatableItem *it = m_itemIndex[removed];
 
265
    if (!it) {
 
266
        return;
 
267
    }
 
268
    it->disappear();
 
269
}
 
270
 
 
271
void ActivatableListWidget::deleteItem()
 
272
{
 
273
    ActivatableItem* ai = dynamic_cast<ActivatableItem*>(sender());
 
274
    m_layout->removeItem(ai);
 
275
    m_itemIndex.remove(m_itemIndex.key(ai));
 
276
    delete ai;
243
277
}
244
278
 
245
279
// vim: sw=4 sts=4 et tw=100