2012-03-27 22:24:38 +02:00
|
|
|
#include "config.h"
|
2010-07-30 23:10:34 +02:00
|
|
|
#include "ilister.h"
|
2010-08-01 16:13:27 +02:00
|
|
|
#include "imobiledeviceconnection.h"
|
2010-07-30 23:10:34 +02:00
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
iLister::iLister() {
|
|
|
|
}
|
|
|
|
|
|
|
|
iLister::~iLister() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void iLister::Init() {
|
|
|
|
idevice_event_subscribe(&EventCallback, reinterpret_cast<void*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void iLister::EventCallback(const idevice_event_t* event, void* context) {
|
|
|
|
iLister* me = reinterpret_cast<iLister*>(context);
|
|
|
|
|
2012-03-27 22:24:38 +02:00
|
|
|
#ifdef IMOBILEDEVICE_USES_UDIDS
|
|
|
|
const char* uuid = event->udid;
|
|
|
|
#else
|
2010-07-30 23:10:34 +02:00
|
|
|
const char* uuid = event->uuid;
|
2012-03-27 22:24:38 +02:00
|
|
|
#endif
|
2010-07-30 23:10:34 +02:00
|
|
|
|
|
|
|
switch (event->event) {
|
|
|
|
case IDEVICE_DEVICE_ADD:
|
|
|
|
me->DeviceAddedCallback(uuid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDEVICE_DEVICE_REMOVE:
|
|
|
|
me->DeviceRemovedCallback(uuid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void iLister::DeviceAddedCallback(const char* uuid) {
|
2010-08-01 13:29:04 +02:00
|
|
|
DeviceInfo info = ReadDeviceInfo(uuid);
|
2010-08-01 13:24:25 +02:00
|
|
|
QString id = UniqueId(uuid);
|
2010-08-01 13:29:04 +02:00
|
|
|
|
2010-09-13 19:08:10 +02:00
|
|
|
QString name = MakeFriendlyName(id);
|
|
|
|
if (info.product_type == "iPhone 3,1" || info.product_type.startsWith("iPad")) {
|
|
|
|
// iPhone 4 and iPad unsupported by libgpod as of 0.7.94.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-01 13:24:25 +02:00
|
|
|
{
|
|
|
|
QMutexLocker l(&mutex_);
|
2010-08-01 13:29:04 +02:00
|
|
|
devices_[id] = info;
|
2010-08-01 13:24:25 +02:00
|
|
|
}
|
2010-07-30 23:10:34 +02:00
|
|
|
|
|
|
|
emit DeviceAdded(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void iLister::DeviceRemovedCallback(const char* uuid) {
|
2010-08-01 13:24:25 +02:00
|
|
|
QString id = UniqueId(uuid);
|
|
|
|
{
|
|
|
|
QMutexLocker l(&mutex_);
|
|
|
|
if (!devices_.contains(id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
devices_.remove(id);
|
|
|
|
}
|
2010-07-30 23:10:34 +02:00
|
|
|
|
|
|
|
emit DeviceRemoved(id);
|
|
|
|
}
|
|
|
|
|
2010-08-01 13:24:25 +02:00
|
|
|
QString iLister::UniqueId(const char *uuid) {
|
|
|
|
return "ithing/" + QString::fromUtf8(uuid);
|
|
|
|
}
|
|
|
|
|
2010-07-30 23:10:34 +02:00
|
|
|
QStringList iLister::DeviceUniqueIDs() {
|
|
|
|
return devices_.keys();
|
|
|
|
}
|
|
|
|
|
2010-08-16 01:26:04 +02:00
|
|
|
QVariantList iLister::DeviceIcons(const QString& id) {
|
|
|
|
return QVariantList() << "ipodtouchicon";
|
2010-07-30 23:10:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString iLister::DeviceManufacturer(const QString& id) {
|
|
|
|
return "Apple";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString iLister::DeviceModel(const QString& id) {
|
2010-08-01 13:24:25 +02:00
|
|
|
return LockAndGetDeviceInfo(id, &DeviceInfo::product_type);
|
2010-07-30 23:10:34 +02:00
|
|
|
}
|
|
|
|
|
2010-07-31 00:08:47 +02:00
|
|
|
quint64 iLister::DeviceCapacity(const QString& id) {
|
2010-08-01 13:24:25 +02:00
|
|
|
return LockAndGetDeviceInfo(id, &DeviceInfo::total_bytes);
|
2010-07-31 00:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 iLister::DeviceFreeSpace(const QString& id) {
|
2010-08-01 13:24:25 +02:00
|
|
|
return LockAndGetDeviceInfo(id, &DeviceInfo::free_bytes);
|
2010-07-31 00:08:47 +02:00
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
|
2010-08-09 20:40:20 +02:00
|
|
|
QVariantMap iLister::DeviceHardwareInfo(const QString& id) {
|
|
|
|
QVariantMap ret;
|
2010-08-09 20:42:17 +02:00
|
|
|
ret[tr("Color")] = LockAndGetDeviceInfo(id, &DeviceInfo::colour);
|
2010-08-09 20:40:20 +02:00
|
|
|
ret["IMEI"] = LockAndGetDeviceInfo(id, &DeviceInfo::imei);
|
|
|
|
ret[tr("Password Protected")] = LockAndGetDeviceInfo(id, &DeviceInfo::password_protected);
|
|
|
|
ret[tr("Timezone")] = LockAndGetDeviceInfo(id, &DeviceInfo::timezone);
|
|
|
|
ret[tr("WiFi MAC Address")] = LockAndGetDeviceInfo(id, &DeviceInfo::wifi_mac);
|
|
|
|
ret[tr("Bluetooth MAC Address")] = LockAndGetDeviceInfo(id, &DeviceInfo::bt_mac);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
|
2010-07-30 23:10:34 +02:00
|
|
|
QString iLister::MakeFriendlyName(const QString& id) {
|
2010-08-09 20:40:20 +02:00
|
|
|
QString name = LockAndGetDeviceInfo(id, &DeviceInfo::name);
|
|
|
|
if (!name.isEmpty()) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2010-08-01 13:24:25 +02:00
|
|
|
QString model_id = LockAndGetDeviceInfo(id, &DeviceInfo::product_type);
|
|
|
|
|
2010-07-30 23:10:34 +02:00
|
|
|
if (model_id.startsWith("iPhone")) {
|
|
|
|
QString version = model_id.right(3);
|
|
|
|
QChar major = version[0];
|
|
|
|
QChar minor = version[2];
|
|
|
|
if (major == '1' && minor == '1') {
|
|
|
|
return "iPhone";
|
|
|
|
}
|
|
|
|
if (major == '1' && minor == '2') {
|
|
|
|
return "iPhone 3G";
|
|
|
|
}
|
|
|
|
if (major == '2' && minor == '1') {
|
|
|
|
return "iPhone 3GS";
|
|
|
|
}
|
|
|
|
if (major == '3' && minor == '1') {
|
|
|
|
return "iPhone 4";
|
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
} else if (model_id.startsWith("iPod")) {
|
|
|
|
return "iPod Touch";
|
|
|
|
} else if (model_id.startsWith("iPad")) {
|
|
|
|
return "iPad";
|
2010-07-30 23:10:34 +02:00
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
return model_id;
|
2010-07-30 23:10:34 +02:00
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
|
2010-08-01 13:55:01 +02:00
|
|
|
QList<QUrl> iLister::MakeDeviceUrls(const QString& id) {
|
|
|
|
QList<QUrl> ret;
|
|
|
|
|
|
|
|
QString uuid = LockAndGetDeviceInfo(id, &DeviceInfo::uuid);
|
|
|
|
if (uuid.isEmpty())
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret << QUrl("afc://" + uuid + "/");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-07-31 16:13:37 +02:00
|
|
|
|
2010-07-30 23:10:34 +02:00
|
|
|
void iLister::UnmountDevice(const QString& id) { }
|
2010-08-01 13:24:25 +02:00
|
|
|
|
2010-08-01 16:13:27 +02:00
|
|
|
iLister::DeviceInfo iLister::ReadDeviceInfo(const char* uuid) {
|
2010-08-01 13:24:25 +02:00
|
|
|
DeviceInfo ret;
|
|
|
|
|
2010-08-01 16:13:27 +02:00
|
|
|
iMobileDeviceConnection conn(uuid);
|
2010-08-01 13:24:25 +02:00
|
|
|
ret.uuid = uuid;
|
2010-08-09 20:40:20 +02:00
|
|
|
ret.product_type = conn.GetProperty("ProductType").toString();
|
|
|
|
ret.free_bytes = conn.GetProperty("AmountDataAvailable", "com.apple.disk_usage").toULongLong();
|
|
|
|
ret.total_bytes = conn.GetProperty("TotalDataCapacity", "com.apple.disk_usage").toULongLong();
|
|
|
|
ret.name = conn.GetProperty("DeviceName").toString();
|
|
|
|
|
|
|
|
ret.colour = conn.GetProperty("DeviceColor").toString();
|
|
|
|
ret.imei = conn.GetProperty("InternationalMobileEquipmentIdentity").toString();
|
|
|
|
ret.hardware = conn.GetProperty("HardwareModel").toString();
|
|
|
|
ret.password_protected = conn.GetProperty("PasswordProtected").toBool();
|
|
|
|
ret.os_version = conn.GetProperty("ProductVersion").toString();
|
|
|
|
ret.timezone = conn.GetProperty("TimeZone").toString();
|
|
|
|
ret.wifi_mac = conn.GetProperty("WiFiAddress").toString();
|
|
|
|
ret.bt_mac = conn.GetProperty("BluetoothAddress").toString();
|
2010-08-01 13:24:25 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-08-11 20:47:53 +02:00
|
|
|
|
|
|
|
void iLister::UpdateDeviceFreeSpace(const QString& id) {
|
|
|
|
{
|
|
|
|
QMutexLocker l(&mutex_);
|
|
|
|
if (!devices_.contains(id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
DeviceInfo& info = devices_[id];
|
|
|
|
iMobileDeviceConnection conn(info.uuid);
|
|
|
|
|
|
|
|
info.free_bytes = conn.GetProperty("AmountDataAvailable", "com.apple.disk_usage").toULongLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit DeviceChanged(id);
|
|
|
|
}
|