~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to core/smb4ksolidinterface.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    smb4ksolidinterface  -  This class provides an interface to KDE's
 
3
    Solid framework.
 
4
                             -------------------
 
5
    begin                : So Sep 14 2008
 
6
    copyright            : (C) 2008 by Alexander Reinholdt
 
7
    email                : dustpuppy@users.berlios.de
 
8
 ***************************************************************************/
 
9
 
 
10
/***************************************************************************
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 *   This program is distributed in the hope that it will be useful, but   *
 
17
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
18
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
19
 *   General Public License for more details.                              *
 
20
 *                                                                         *
 
21
 *   You should have received a copy of the GNU General Public License     *
 
22
 *   along with this program; if not, write to the                         *
 
23
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
 
24
 *   MA  02111-1307 USA                                                    *
 
25
 ***************************************************************************/
 
26
 
 
27
// KDE includes
 
28
#include <kglobal.h>
 
29
#include <kdebug.h>
 
30
#include <klocale.h>
 
31
#include <solid/deviceinterface.h>
 
32
#include <solid/devicenotifier.h>
 
33
#include <solid/device.h>
 
34
#include <solid/acadapter.h>
 
35
#include <solid/battery.h>
 
36
#include <solid/powermanagement.h>
 
37
 
 
38
// application specific includes
 
39
#include <smb4ksolidinterface.h>
 
40
 
 
41
class Smb4KSolidInterfacePrivate
 
42
{
 
43
  public:
 
44
    Smb4KSolidInterface instance;
 
45
};
 
46
 
 
47
K_GLOBAL_STATIC( Smb4KSolidInterfacePrivate, priv );
 
48
 
 
49
 
 
50
Smb4KSolidInterface::Smb4KSolidInterface()
 
51
: QObject(),
 
52
  m_button_pressed( UnknownButton ),
 
53
  m_network_status( Unknown )
 
54
{
 
55
  init();
 
56
}
 
57
 
 
58
 
 
59
Smb4KSolidInterface::~Smb4KSolidInterface()
 
60
{
 
61
}
 
62
 
 
63
 
 
64
Smb4KSolidInterface *Smb4KSolidInterface::self()
 
65
{
 
66
  return &priv->instance;
 
67
}
 
68
 
 
69
 
 
70
void Smb4KSolidInterface::init()
 
71
{
 
72
  // Connect to device notifier.
 
73
  connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceAdded( const QString & ) ),
 
74
           this,                              SLOT( slotDeviceAdded( const QString & ) ) );
 
75
 
 
76
  connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceRemoved( const QString & ) ),
 
77
           this,                              SLOT( slotDeviceRemoved( const QString & ) ) );
 
78
 
 
79
  // Get the buttons
 
80
  QList<Solid::Device> list_btn = Solid::Device::listFromType( Solid::DeviceInterface::Button, QString() );
 
81
 
 
82
  foreach ( const Solid::Device &device_btn, list_btn )
 
83
  {
 
84
    if ( device_btn.isValid() )
 
85
    {
 
86
      const Solid::Button *button = device_btn.as<Solid::Button>();
 
87
      connect( button, SIGNAL( pressed( Solid::Button::ButtonType, const QString & ) ),
 
88
               this,   SLOT( slotButtonPressed( Solid::Button::ButtonType, const QString & ) ) );
 
89
 
 
90
      continue;
 
91
    }
 
92
    else
 
93
    {
 
94
      continue;
 
95
    }
 
96
  }
 
97
 
 
98
  // FIXME: Check for hibernation, etc. as well as for the system waking
 
99
  // up again.
 
100
 
 
101
  // Get the AC adapter(s)
 
102
  QList<Solid::Device> list_ac = Solid::Device::listFromType( Solid::DeviceInterface::AcAdapter, QString() );
 
103
 
 
104
  foreach ( const Solid::Device &device_ac, list_ac )
 
105
  {
 
106
    if ( device_ac.isValid() )
 
107
    {
 
108
      const Solid::AcAdapter *acadapter = device_ac.as<Solid::AcAdapter>();
 
109
      connect( acadapter, SIGNAL( plugStateChanged( bool, const QString & ) ),
 
110
               this,     SLOT( slotAcPlugStateChanged( bool, const QString & ) ) );
 
111
 
 
112
      // FIXME: Check the current state.
 
113
 
 
114
      continue;
 
115
    }
 
116
    else
 
117
    {
 
118
      continue;
 
119
    }
 
120
  }
 
121
 
 
122
  // Get the primary batteries
 
123
  QList<Solid::Device> list_bat = Solid::Device::listFromType( Solid::DeviceInterface::Battery, QString() );
 
124
 
 
125
  foreach ( const Solid::Device &device_bat, list_bat )
 
126
  {
 
127
    if ( device_bat.isValid() )
 
128
    {
 
129
      const Solid::Battery *battery = device_bat.as<Solid::Battery>();
 
130
 
 
131
      switch ( battery->type() )
 
132
      {
 
133
        case Solid::Battery::PrimaryBattery:
 
134
        {
 
135
          connect( battery, SIGNAL( chargeStateChanged( int, const QString & ) ),
 
136
                   this,    SLOT( slotBatteryChargeStateChanged( int, const QString & ) ) );
 
137
 
 
138
          connect( battery, SIGNAL( chargePercentChanged( int, const QString & ) ),
 
139
                   this,    SLOT( slotBatteryChargePercentChanged( int, const QString & ) ) );
 
140
 
 
141
          // FIXME: Check charge state and value
 
142
 
 
143
          break;
 
144
        }
 
145
        default:
 
146
        {
 
147
          break;
 
148
        }
 
149
      }
 
150
 
 
151
      continue;
 
152
    }
 
153
    else
 
154
    {
 
155
      continue;
 
156
    }
 
157
  }
 
158
 
 
159
  // Check network status and connect to the notifier
 
160
  slotNetworkStatusChanged( Solid::Networking::status() );
 
161
 
 
162
  connect( Solid::Networking::notifier(), SIGNAL( statusChanged( Solid::Networking::Status ) ),
 
163
           this,                          SLOT( slotNetworkStatusChanged( Solid::Networking::Status ) ) );
 
164
}
 
165
 
 
166
 
 
167
/////////////////////////////////////////////////////////////////////////////
 
168
// SLOT IMPLEMENTATIONS
 
169
/////////////////////////////////////////////////////////////////////////////
 
170
 
 
171
void Smb4KSolidInterface::slotDeviceAdded( const QString &udi )
 
172
{
 
173
  // Work around the fact that there is no signal that tells
 
174
  // us when the computer woke up. Check the UDIs in the map
 
175
  // and emit the wokeUp()
 
176
  if ( m_button_pressed != UnknownButton &&
 
177
       m_removed_devices[udi] == m_button_pressed )
 
178
  {
 
179
    m_removed_devices.remove( udi );
 
180
 
 
181
    if ( m_removed_devices.isEmpty() )
 
182
    {
 
183
      // Work around: Computer woke up.
 
184
      m_button_pressed = UnknownButton;
 
185
      emit wokeUp();
 
186
    }
 
187
    else
 
188
    {
 
189
      // Do nothing
 
190
    }
 
191
  }
 
192
}
 
193
 
 
194
 
 
195
void Smb4KSolidInterface::slotDeviceRemoved( const QString &udi )
 
196
{
 
197
  // Work around the fact that there is no signal that tells us,
 
198
  // that the computer has been woken up. Store the removed device(s)
 
199
  // and the pressed button to figure out later (in slotDeviceAdded())
 
200
  // if the computer became active again.
 
201
  if ( m_button_pressed != UnknownButton )
 
202
  {
 
203
    m_removed_devices.insert( udi, m_button_pressed );
 
204
  }
 
205
  else
 
206
  {
 
207
    // Do nothing
 
208
  }
 
209
}
 
210
 
 
211
 
 
212
void Smb4KSolidInterface::slotButtonPressed( Solid::Button::ButtonType type, const QString &udi )
 
213
{
 
214
  switch ( type )
 
215
  {
 
216
    case Solid::Button::LidButton:
 
217
    {
 
218
      m_button_pressed = LidButton;
 
219
      break;
 
220
    }
 
221
    case Solid::Button::SleepButton:
 
222
    {
 
223
      m_button_pressed = SleepButton;
 
224
      break;
 
225
    }
 
226
    case Solid::Button::PowerButton:
 
227
    {
 
228
      m_button_pressed = PowerButton;
 
229
      break;
 
230
    }
 
231
    default:
 
232
    {
 
233
      m_button_pressed = UnknownButton;
 
234
      break;
 
235
    }
 
236
  }
 
237
 
 
238
  emit buttonPressed( m_button_pressed );
 
239
}
 
240
 
 
241
 
 
242
void Smb4KSolidInterface::slotAcPlugStateChanged( bool state, const QString &udi )
 
243
{
 
244
  if ( state )
 
245
  {
 
246
    kDebug() << "AC adapter plugged ..." << endl;
 
247
  }
 
248
  else
 
249
  {
 
250
    kDebug() << "AC adapter unplugged ..." << endl;
 
251
  }
 
252
}
 
253
 
 
254
 
 
255
void Smb4KSolidInterface::slotBatteryChargeStateChanged( int state, const QString &udi )
 
256
{
 
257
  switch ( state )
 
258
  {
 
259
    case Solid::Battery::Discharging:
 
260
    {
 
261
      kDebug() << "Battery is discharging ..." << endl;
 
262
      break;
 
263
    }
 
264
    case Solid::Battery::Charging:
 
265
    {
 
266
      kDebug() << "Battery is charging ..." << endl;
 
267
      break;
 
268
    }
 
269
    default:
 
270
    {
 
271
      kDebug() << "Unknown battery state ..." << endl;
 
272
      break;
 
273
    }
 
274
  }
 
275
}
 
276
 
 
277
 
 
278
void Smb4KSolidInterface::slotBatteryChargePercentChanged( int value, const QString &udi )
 
279
{
 
280
  kDebug() << "Battery charge percent value: " << value << endl;
 
281
}
 
282
 
 
283
 
 
284
void Smb4KSolidInterface::slotNetworkStatusChanged( Solid::Networking::Status status )
 
285
{
 
286
  switch ( status )
 
287
  {
 
288
    case Solid::Networking::Connecting:
 
289
    {
 
290
      m_network_status = Connecting;
 
291
      break;
 
292
    }
 
293
    case Solid::Networking::Connected:
 
294
    {
 
295
      m_network_status = Connected;
 
296
      break;
 
297
    }
 
298
    case Solid::Networking::Disconnecting:
 
299
    {
 
300
      m_network_status = Disconnecting;
 
301
      break;
 
302
    }
 
303
    case Solid::Networking::Unconnected:
 
304
    {
 
305
      m_network_status = Disconnected;
 
306
      break;
 
307
    }
 
308
    case Solid::Networking::Unknown:
 
309
    default:
 
310
    {
 
311
      m_network_status = Unknown;
 
312
      break;
 
313
    }
 
314
  }
 
315
 
 
316
  emit networkStatusChanged( m_network_status );
 
317
}
 
318
 
 
319
#include "smb4ksolidinterface.moc"