UsbExample::UsbExample(QObject *parent) : QObject(parent) { QObject::connect(&m_usb_manager, SIGNAL(deviceInserted(QUsbDevice::IdList)), this, SLOT(onDevInserted(QUsbDevice::IdList))); QObject::connect(&m_usb_manager, SIGNAL(deviceRemoved(QUsbDevice::IdList)), this, SLOT(onDevRemoved(QUsbDevice::IdList))); m_usb_manager.setLogLevel(QUsbDevice::logDebug); qInfo("Starting..."); qInfo("Press CTRL+C to close."); }
MainWindow::MainWindow (Platform *platform, const char *cmddevice, const char *cmdfile, bool unsafe, bool maximized, QWidget *parent) : QWidget(parent) { pPlatform = platform; QDBusConnection dbusConnection = QDBusConnection::systemBus(); file = QString(); mMaximized = maximized; mUnsafe = unsafe; fileSize = new QLabel(" "); fileLabel = new QLabel(" "); // The "new" UI won't compile on 10.3 or SLE10, so fallback in that case to the older, uglier one #if (QT_VERSION >= 0x040400) useNewUI(); #else useOldUI(); #endif setWindowTitle(QString("SUSE Studio Imagewriter %1").arg(APP_VERSION)); reloadDeviceList(cmddevice); if (cmdfile != NULL) { if(QFile(cmdfile).exists()) { setFile(cmdfile); setSizeLabel(cmdfile); } } #ifdef USEHAL // Hook into DBUS insertion and removal notifications dbusConnection.connect("", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", "DeviceAdded", this, SLOT(deviceInserted(QDBusMessage))); dbusConnection.connect("", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", "DeviceRemoved", this, SLOT(deviceRemoved(QDBusMessage))); #else dbusConnection.connect("", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceAdded", this, SLOT(deviceInserted(QDBusMessage))); dbusConnection.connect("", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(deviceRemoved(QDBusMessage))); #endif if (!mMaximized) centerWindow(); }
void Storage::processRemovableUdevEvents(const QString& devtype, const QString& path, const QString& sysname, const QString& action) { qDebug() << Q_FUNC_INFO << ": devtype = " << devtype << ", path = " << path << ", sysname = " << sysname << ", action = " << action; if (devtype == "disk") // device { QMap<QString, StorageDevice*>::iterator it = _devices.find(path); if (action == "remove") { // QMap::find returns an iterator pointing to the item with key key in the map. // If the map contains no item with key key, the function returns end(). if ( it != _devices.end()) { // delete device emit deviceRemoved(it.value()); _devices.remove(it.key()); delete it.value(); } // else if devices is not into _devices, maybe because we lost the "add" action... if (usb_active) restartSharingOverUSB(); } else if (action == "add") { // QMap::find returns an iterator pointing to the item with key key in the map. // If the map contains no item with key key, the function returns end(). if ( it == _devices.end()) { // insert a new device // is a block device it = _devices.insert(path, createStorageDevice (path, sysname, StorageDevice::REMOVABLE)); } // add new device it.value()->setInserted(true); emit deviceInserted(it.value()); } else { qDebug() << Q_FUNC_INFO << ": Unknown device action " << action << ". Discarted device"; if ( it != _devices.end()) { _devices.remove(it.key()); delete it.value(); } } return; } if (devtype == "partition") { QMap<QString, StoragePartition*>::iterator it = _partitions.find(path); if (action == "add") { // QMap::find returns an iterator pointing to the item with key key in the map. // If the map contains no item with key key, the function returns end(). if (it == _partitions.end()) { it = _partitions.insert(path, createStoragePartition (StoragePartition::REMOVABLE, StoragePartition::FS_VFAT, path, sysname , "/mnt/sd")); } removablePartition = it.value(); mountStoragePartition(removablePartition); } else if (action == "remove") { // QMap::find returns an iterator pointing to the item with key key in the map. // If the map contains no item with key key, the function returns end(). if (it != _partitions.end()) { umountStoragePartition(it.value()); if (removablePartition == it.value()) { qDebug() << Q_FUNC_INFO << ": Cleaning removable partition"; removablePartition = NULL; } _partitions.remove(it.key()); it.value()->deleteLater(); } // else if partition is not into _partitions, maybe because we lost the "add" action... } else if (action == "change") { qDebug() << Q_FUNC_INFO << ": got a change action for a partition, emitting deviceChanged"; emit deviceChanged(sysname); // NOTE: We used to insert here too the removable partition, but that should be covered by the add } else { qDebug() << Q_FUNC_INFO << ": action " << action << " not supported for partitions. Discarted partition"; if (it != _partitions.end()) { _partitions.remove(it.key()); delete (it.value()); } } return; } }