~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/devices/wmdmlister.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "wmdmlister.h"
21
21
#include "wmdmthread.h"
 
22
#include "core/logging.h"
22
23
#include "core/utilities.h"
23
24
 
24
25
#include <objbase.h>
54
55
}
55
56
 
56
57
void WmdmLister::Init() {
 
58
  qLog(Debug) << "Starting";
 
59
 
57
60
  thread_.reset(new WmdmThread);
58
61
  if (!thread_->manager())
59
62
    return;
60
63
 
61
64
  // Register for notifications
 
65
  qLog(Debug) << "Obtaining CP container";
62
66
  IConnectionPointContainer* cp_container = NULL;
63
67
  thread_->manager()->QueryInterface(IID_IConnectionPointContainer, (void**)&cp_container);
64
68
 
 
69
  qLog(Debug) << "Obtaining CP";
65
70
  IConnectionPoint* cp = NULL;
66
71
  cp_container->FindConnectionPoint(IID_IWMDMNotification, &cp);
67
72
 
 
73
  qLog(Debug) << "Registering for notifications";
68
74
  cp->Advise(this, &notification_cookie_);
69
75
 
70
76
  cp->Release();
71
77
  cp_container->Release();
72
78
 
73
79
  // Fetch the initial list of devices
 
80
  qLog(Debug) << "Fetching device list";
74
81
  IWMDMEnumDevice* device_it = NULL;
75
82
  if (thread_->manager()->EnumDevices2(&device_it)) {
76
 
    qWarning() << "Error querying WMDM devices";
 
83
    qLog(Warning) << "Error querying WMDM devices";
77
84
    return;
78
85
  }
79
86
 
86
93
    if (device_it->Next(1, &device, &fetched) || fetched != 1)
87
94
      break;
88
95
 
 
96
    qLog(Debug) << "Querying device";
89
97
    if (device->QueryInterface(IID_IWMDMDevice2, (void**)&device2)) {
90
 
      qWarning() << "Error getting IWMDMDevice2 from device";
 
98
      qLog(Warning) << "Error getting IWMDMDevice2 from device";
91
99
      device->Release();
92
100
      continue;
93
101
    }
102
110
  device_it->Release();
103
111
 
104
112
  // Update the internal cache
 
113
  qLog(Debug) << "Updating device cache";
105
114
  {
106
115
    QMutexLocker l(&mutex_);
107
116
    devices_ = devices;
111
120
  foreach (const QString& id, devices.keys()) {
112
121
    emit DeviceAdded(id);
113
122
  }
 
123
 
 
124
  qLog(Debug) << "Startup complete";
114
125
}
115
126
 
116
127
void WmdmLister::ReallyShutdown() {
141
152
}
142
153
 
143
154
WmdmLister::DeviceInfo WmdmLister::ReadDeviceInfo(IWMDMDevice2* device) {
 
155
  qLog(Debug) << "Reading device info";
 
156
 
144
157
  DeviceInfo ret;
145
158
  ret.device_ = device;
146
159
 
156
169
  device->GetCanonicalName(buf, max_size);
157
170
  ret.canonical_name_ = QString::fromWCharArray(buf).toLower();
158
171
 
 
172
  qLog(Debug) << "Read device strings:" << ret.name_ << ret.manufacturer_ << ret.canonical_name_;
 
173
 
159
174
  // Upgrade to a device3
160
175
  IWMDMDevice3* device3 = NULL;
161
176
  device->QueryInterface(IID_IWMDMDevice3, (void**)&device3);
193
208
 
194
209
    if (storage_it->Next(1, &storage, &storage_fetched) == S_OK) {
195
210
      if (storage->QueryInterface(IID_IWMDMStorage2, (void**)&ret.storage_)) {
196
 
        qWarning() << "Error getting IWMDMStorage2 from storage";
 
211
        qLog(Warning) << "Error getting IWMDMStorage2 from storage";
197
212
      } else {
198
213
        // Get free space information
199
214
        UpdateFreeSpace(&ret);
212
227
}
213
228
 
214
229
void WmdmLister::GuessDriveLetter(DeviceInfo* info) {
215
 
  qDebug() << "Guessing drive letter for" << info->name_;
 
230
  qLog(Debug) << "Guessing drive letter for" << info->name_;
216
231
 
217
232
  // Windows XP puts the drive letter in brackets at the end of the name
218
233
  QRegExp drive_letter("\\(([A-Z]:)\\)$");
219
234
  if (drive_letter.indexIn(info->name_) != -1) {
220
 
    qDebug() << "Looks like an XP drive" << drive_letter.cap(1);
 
235
    qLog(Debug) << "Looks like an XP drive" << drive_letter.cap(1);
221
236
    CheckDriveLetter(info, drive_letter.cap(1));
222
237
    return;
223
238
  }
225
240
  // Windows 7 sometimes has the drive letter as the whole name
226
241
  drive_letter = QRegExp("^([A-Z]:)\\\\$");
227
242
  if (drive_letter.indexIn(info->name_) != -1) {
228
 
    qDebug() << "Looks like a win7 drive" << drive_letter.cap(1);
 
243
    qLog(Debug) << "Looks like a win7 drive" << drive_letter.cap(1);
229
244
    CheckDriveLetter(info, drive_letter.cap(1));
230
245
    return;
231
246
  }
260
275
 
261
276
        if (!GetVolumeInformationW(volume_path, name, MAX_PATH,
262
277
            &serial, NULL, NULL, type, MAX_PATH)) {
263
 
          qWarning() << "Error getting volume information for" <<
 
278
          qLog(Warning) << "Error getting volume information for" <<
264
279
              QString::fromWCharArray(volume_path);
265
280
        } else {
266
281
          if (name.ToString() == info->name_ && name.characters() != 0) {
267
282
            // We found it!
268
 
            qDebug() << "Looks like a win7 drive name" << QString::fromWCharArray(volume_path);
 
283
            qLog(Debug) << "Looks like a win7 drive name" << QString::fromWCharArray(volume_path);
269
284
            if (CheckDriveLetter(info, QString::fromWCharArray(volume_path))) {
270
285
              info->device_name_ = QString::fromWCharArray(device_name);
271
286
              info->volume_name_ = QString::fromWCharArray(volume_name);
297
312
      NULL, // flags
298
313
      type, MAX_PATH // fat or ntfs
299
314
      )) {
300
 
    qWarning() << "Error getting volume information for" << drive;
 
315
    qLog(Warning) << "Error getting volume information for" << drive;
301
316
    return false;
302
317
  } else {
303
 
    qDebug() << "Validated drive letter" << drive;
 
318
    qLog(Debug) << "Validated drive letter" << drive;
304
319
    info->mount_point_ = path.ToString();
305
320
    info->fs_name_ = name.ToString();
306
321
    info->fs_type_ = type.ToString();
421
436
}
422
437
 
423
438
HRESULT WmdmLister::WMDMMessage(DWORD message_type, LPCWSTR name) {
 
439
  qLog(Debug) << "WMDM message" << message_type << name;
 
440
 
424
441
  QString canonical_name = QString::fromWCharArray(name).toLower();
425
442
 
426
443
  switch (message_type) {
436
453
 
437
454
  IWMDMDevice* device = NULL;
438
455
  if (thread_->manager()->GetDeviceFromCanonicalName(name, &device)) {
439
 
    qWarning() << "Error in GetDeviceFromCanonicalName for" << canonical_name;
 
456
    qLog(Warning) << "Error in GetDeviceFromCanonicalName for" << canonical_name;
440
457
    return;
441
458
  }
442
459
 
443
460
  IWMDMDevice2* device2 = NULL;
444
461
  if (device->QueryInterface(IID_IWMDMDevice2, (void**) &device2)) {
445
 
    qWarning() << "Error getting IWMDMDevice2 from device";
 
462
    qLog(Warning) << "Error getting IWMDMDevice2 from device";
446
463
    device->Release();
447
464
    return;
448
465
  }