bool SmbDeviceHandlerFactory::canHandle( const Solid::Device &device ) const { const Solid::NetworkShare *share = device.as<Solid::NetworkShare>(); if( !share ) { debug() << __PRETTY_FUNCTION__ << device.udi() << "has no NetworkShare interface"; return false; } if( share->type() != Solid::NetworkShare::Cifs ) { debug() << __PRETTY_FUNCTION__ << device.udi() << "has type" << share->type() << "but smbfs/cifs type is" << Solid::NetworkShare::Cifs; return false; } const Solid::StorageAccess *access = device.as<Solid::StorageAccess>(); if( !access ) { debug() << __PRETTY_FUNCTION__ << device.udi() << "has no StorageAccess interface"; return false; } if( !access->isAccessible() || access->filePath().isEmpty() ) { debug() << __PRETTY_FUNCTION__ << device.udi() << "is not accessible" << "or has empty mount-point"; return false; } return true; }
int main(int argc, char **argv) { QCoreApplication app(argc, argv); KComponentData data("tutorial5"); //get a Network Device QList<Solid::Device> netlist = Solid::Device::listFromType(Solid::DeviceInterface::NetworkInterface, QString()); //check to see if no network devices were found if(netlist.empty()) { kDebug() << "No network devices found!"; return 0; } Solid::Device device = netlist[0]; Solid::NetworkInterface *netdev = device.as<Solid::NetworkInterface>(); //keep the program from crashing in the event that there's a bug in solid if(!netdev) { kDebug() << "Device could not be converted. There is a bug."; return 0; } kDebug() << "The iface of " << device.udi() << " is " << netdev->ifaceName(); return 0; }
QVariant SoundCardModel::data(const QModelIndex &index, int role) const { // Sanity check if (!index.isValid()) return QVariant(); // Check if role is supported if (role != Qt::DisplayRole && role != Qt::DecorationRole) return QVariant(); Solid::Device device = m_list.at(index.row()); Solid::AudioInterface *audio = device.as<Solid::AudioInterface>(); if (audio->deviceType() == Solid::AudioInterface::AudioOutput) { qDebug() << device.udi() << device.product() << device.parentUdi(); switch (role) { case Qt::DisplayRole: return audio->name(); case Qt::DecorationRole: switch (audio->soundcardType()) { case Solid::AudioInterface::Headset: return QIcon::fromTheme("audio-headset"); default: return QIcon::fromTheme("audio-card"); } } } return QVariant(); }
void SolidDeviceJob::start() { Solid::Device device (m_dest); QString operation = operationName(); if (operation == QLatin1String("mount")) { if (device.is<Solid::StorageAccess>()) { Solid::StorageAccess *access = device.as<Solid::StorageAccess>(); if (access && !access->isAccessible()) { access->setup(); } } } else if (operation == QLatin1String("unmount")) { if (device.is<Solid::OpticalDisc>()) { Solid::OpticalDrive *drive = device.as<Solid::OpticalDrive>(); if (!drive) { drive = device.parent().as<Solid::OpticalDrive>(); } if (drive) { drive->eject(); } } else if (device.is<Solid::StorageAccess>()) { Solid::StorageAccess *access = device.as<Solid::StorageAccess>(); if (access && access->isAccessible()) { access->teardown(); } } } emitResult(); }
/** * @brief Return true if device is identified as iPod-compatible using product and vendor. * * @param device Solid device to identify * @return true if the device is iPod-like, false if it cannot be proved. **/ static bool deviceIsRootIpodDevice( const Solid::Device &device ) { if( !device.vendor().contains( "Apple", Qt::CaseInsensitive ) ) return false; return device.product().startsWith( "iPod" ) || device.product().startsWith( "iPhone" ) || device.product().startsWith( "iPad" ); }
Solid::Device MenuDiskItem::opticalParent() const { Solid::Device it = mDevice; //search for parent drive for ( ; !it.udi().isEmpty(); it = it.parent()) { if (it.is<Solid::OpticalDrive>()) break; } return it; }
// Paulo: I'm not sure what this is for static bool hasRemovableParent(Solid::Device device) { // qDebug() << "acess:" << device.udi(); for ( ; !device.udi().isEmpty(); device = device.parent()) { Solid::StorageDrive* drive = device.as<Solid::StorageDrive>(); if (drive && drive->isRemovable()) { // qDebug() << "removable parent drive:" << device.udi(); return true; } } return false; }
AudioCdDevice::AudioCdDevice(MusicModel *m, Solid::Device &dev) : Device(m, dev, false, true) #ifdef CDDB_FOUND , cddb(0) #endif #ifdef MUSICBRAINZ5_FOUND , mb(0) #endif , year(0) , disc(0) , time(0xFFFFFFFF) , lookupInProcess(false) , autoPlay(false) { icn=Icon("media-optical"); drive=dev.parent().as<Solid::OpticalDrive>(); Solid::Block *block=dev.as<Solid::Block>(); if (block) { device=block->device(); } else { // With UDisks2 we cannot get block from device :-( QStringList parts=dev.udi().split("/", QString::SkipEmptyParts); if (!parts.isEmpty()) { parts=parts.last().split(":"); if (!parts.isEmpty()) { device="/dev/"+parts.first(); } } } if (!device.isEmpty()) { static bool registeredTypes=false; if (!registeredTypes) { qRegisterMetaType<CdAlbum >("CdAlbum"); qRegisterMetaType<QList<CdAlbum> >("QList<CdAlbum>"); registeredTypes=true; } devPath=Song::constCddaProtocol+device+QChar('/'); #if defined CDDB_FOUND && defined MUSICBRAINZ5_FOUND connectService(Settings::self()->useCddb()); #else connectService(true); #endif detailsString=i18n("Reading disc"); setStatusMessage(detailsString); lookupInProcess=true; connect(Covers::self(), SIGNAL(cover(const Song &, const QImage &, const QString &)), this, SLOT(setCover(const Song &, const QImage &, const QString &))); emit lookup(Settings::self()->cdAuto()); } }
QAction* PlacesItemModel::teardownAction(int index) const { const PlacesItem* item = placesItem(index); if (!item) { return 0; } Solid::Device device = item->device(); const bool providesTearDown = device.is<Solid::StorageAccess>() && device.as<Solid::StorageAccess>()->isAccessible(); if (!providesTearDown) { return 0; } Solid::StorageDrive* drive = device.as<Solid::StorageDrive>(); if (!drive) { drive = device.parent().as<Solid::StorageDrive>(); } bool hotPluggable = false; bool removable = false; if (drive) { hotPluggable = drive->isHotpluggable(); removable = drive->isRemovable(); } QString iconName; QString text; const QString label = item->text(); if (device.is<Solid::OpticalDisc>()) { text = i18nc("@item", "Release '%1'", label); } else if (removable || hotPluggable) { text = i18nc("@item", "Safely Remove '%1'", label); iconName = QStringLiteral("media-eject"); } else { text = i18nc("@item", "Unmount '%1'", label); iconName = QStringLiteral("media-eject"); } if (iconName.isEmpty()) { return new QAction(text, 0); } return new QAction(QIcon::fromTheme(iconName), text, 0); }
int MTPSlave::checkUrl ( const KUrl& url, bool redirect ) { kDebug ( KIO_MTP ) << url; if ( url.path().startsWith ( QLatin1String ( "udi=" ) ) && redirect ) { QString udi = url.path( KUrl::RemoveTrailingSlash ).remove ( 0, 4 ); kDebug ( KIO_MTP ) << "udi = " << udi; Solid::Device device ( udi ); if ( !device.isValid() ) { return 2; } Solid::GenericInterface *iface = device.as<Solid::GenericInterface>(); QMap<QString, QVariant> properties = iface->allProperties(); int busnum = properties.value ( QLatin1String ( "BUSNUM" ) ).toInt(); int devnum = properties.value ( QLatin1String ( "DEVNUM" ) ).toInt(); kDebug ( KIO_MTP ) << "UDI reports BUS/DEV:" << busnum << "/" << devnum; QMap<QString, LIBMTP_raw_device_t*> devices = getRawDevices(); foreach ( const QString &deviceName, devices.keys() ) { LIBMTP_raw_device_t* rawDevice = devices.value ( deviceName ); int currentBusNum = rawDevice->bus_location; int currentDevNum = rawDevice->devnum; kDebug ( KIO_MTP ) << "LIBMTP has BUS/DEV:"<< currentBusNum << "/" << currentDevNum; if ( currentBusNum == busnum && currentDevNum == devnum ) { KUrl newUrl; newUrl.setProtocol ( QLatin1String ( "mtp" ) ); newUrl.setPath ( QLatin1Char ( '/' ) + deviceName ); redirection ( newUrl ); return 1; } } }
SolStorageDevice::SolStorageDevice(QTreeWidgetItem *parent, const Solid::Device &device, const storageChildren &c) : SolDevice(parent, device) { deviceTypeHolder = Solid::DeviceInterface::StorageDrive; setDefaultDeviceText(); if(c == CREATECHILDREN) { createDeviceChildren<SolVolumeDevice>(this,device.udi(),Solid::DeviceInterface::StorageVolume); } }
bool SolidDeviceEngine::sourceRequestEvent(const QString &name) { if (name.startsWith('/')) { Solid::Device device = Solid::Device(name); if (device.isValid()) { if (m_devicemap.contains(name) ) { return true; } else { m_devicemap[name] = device; return populateDeviceData(name); } } } else { Solid::Predicate predicate = Solid::Predicate::fromString(name); if (predicate.isValid() && !m_predicatemap.contains(name)) { foreach (const Solid::Device &device, Solid::Device::listFromQuery(predicate)) { m_predicatemap[name] << device.udi(); } setData(name, m_predicatemap[name]); return true; } }
void DeviceActionsDialog::setDevice(const Solid::Device &device) { m_device = device; QString label = device.vendor(); if (!label.isEmpty()) label+=' '; label+= device.product(); setWindowTitle(label); m_view.iconLabel->setPixmap(KIcon(device.icon()).pixmap(64)); m_view.descriptionLabel->setText(device.vendor()+' '+device.product()); setWindowIcon(KIcon(device.icon())); }
QVariant FilePlacesItem::deviceData(int role) const { Solid::Device d = device(); if (!d.isValid()) return QVariant(); switch (role) { case Qt::DecorationRole: return QIcon::fromTheme(d.icon()); case Qt::DisplayRole: return d.description(); case VFilePlacesModel::UrlRole: if (m_access) return QUrl::fromLocalFile(m_access->filePath()); else if (m_disc && (m_disc->availableContent() && Solid::OpticalDisc::Audio) != 0) { QString device = d.as<Solid::Block>()->device(); return QUrl(QString("audiocd:///?device=%1").arg(device)); } case VFilePlacesModel::FixedDeviceRole: { Solid::StorageDrive *drive = 0; Solid::Device parentDevice = d; while (parentDevice.isValid() && !drive) { drive = parentDevice.as<Solid::StorageDrive>(); parentDevice = parentDevice.parent(); } if (drive) return !drive->isHotpluggable() && !drive->isRemovable(); return true; } break; default: break; } return QVariant(); }
bool deviceLessThan(const Solid::Device &a, const Solid::Device &b) { return a.udi() < b.udi(); }
//---------------------------------------- //--- Primary playback control methods --- //---------------------------------------- void Playlist::playItemAt(int row, Model model) { bool isQueue = (model == QueueModel); MediaItem nextMediaItem = isQueue ? m_queue->mediaItemAt(row) : m_currentPlaylist->mediaItemAt(row); if (!isQueue) { nextMediaItem.playlistIndex = row; } nextMediaItem.nowPlaying = true; //Update Queue Model if (!m_shuffle) { //Just build a new queue from the row of the item in the playlist buildQueueFrom(nextMediaItem.playlistIndex); } else { int rowInQueue = isQueue ? row : m_queue->rowOfUrl(nextMediaItem.url); //Add currently playing item to history if (rowInQueue > 0 && m_nowPlaying->rowCount() > 0) { if (m_nowPlaying->mediaItemAt(0).type == "Audio" || m_nowPlaying->mediaItemAt(0).type == "Video") { int nowPlayingIndex = m_nowPlaying->mediaItemAt(0).playlistIndex; m_playlistIndicesHistory.append(nowPlayingIndex); m_playlistUrlHistory.append(m_nowPlaying->mediaItemAt(0).url); if (m_queue->rowCount() > 1) { m_queue->removeMediaItemAt(0); rowInQueue--; } } } //Remove requested item from history bool inHistory = (m_playlistIndicesHistory.indexOf(nextMediaItem.playlistIndex) != -1); if ( inHistory ) { //remove from history int idx = m_playlistIndicesHistory.indexOf(row); m_playlistIndicesHistory.removeAt(idx); m_playlistUrlHistory.removeAt(idx); } //Place requested item at front of queue QList<MediaItem> queueMediaList = m_queue->mediaList(); if ( rowInQueue > 0 ) { //in queue, but not at first place, so move it queueMediaList.move(rowInQueue, 0); } else if (rowInQueue < 0) { //not in queue, so add it at first place queueMediaList.insert(0, nextMediaItem); if (queueMediaList.count() > m_queueDepth) { queueMediaList.removeLast(); } } //else it is already at first place in the queue m_queue->clearMediaListData(); m_queue->loadMediaList(queueMediaList, true); //Fill out queue shuffle(); } //Play media Item m_mediaObject->clearQueue(); m_currentStream.clear(); QString subType; if (nextMediaItem.type == "Audio") { subType = nextMediaItem.fields["audioType"].toString(); } else if(nextMediaItem.type == "Video") { subType = nextMediaItem.fields["videoType"].toString(); } m_currentUrl = nextMediaItem.url; bool isDiscTitle = Utilities::isDisc( nextMediaItem.url ); if (isDiscTitle) { Solid::Device device = Solid::Device( Utilities::deviceUdiFromUrl(nextMediaItem.url) ); if (!device.isValid()) { stop(); return; } const Solid::Block* block = device.as<const Solid::Block>(); Phonon::DiscType discType = (subType == "CD Track") ? Phonon::Cd : Phonon::Dvd; Phonon::MediaSource src = Phonon::MediaSource(discType, block->device()); int title = nextMediaItem.fields["trackNumber"].toInt(); if (m_mediaObject->currentSource().discType() != src.discType() || m_mediaObject->currentSource().deviceName() != src.deviceName()) { m_mediaObject->setCurrentSource(src); } if (title != -1) { m_mediaController->setCurrentTitle(title); m_mediaController->setAutoplayTitles(true); } m_mediaObject->play(); } else if (subType == "Audio Stream") { m_currentStream = nextMediaItem.url; m_streamListUrls.clear(); if (Utilities::isPls(nextMediaItem.url) || Utilities::isM3u(nextMediaItem.url)) { QList<MediaItem> streamList = Utilities::mediaListFromSavedList(nextMediaItem); for (int i = 0; i < streamList.count(); i++) { m_streamListUrls << streamList.at(i).url; if (i == 0) { m_currentUrl = streamList.at(i).url; } else { m_mediaObject->enqueue(Phonon::MediaSource(QUrl::fromPercentEncoding(streamList.at(i).url.toUtf8()))); } } } else { m_streamListUrls << nextMediaItem.url; } m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromPercentEncoding(m_currentUrl.toUtf8()))); m_mediaObject->play(); } else { m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(m_currentUrl.toUtf8()))); m_mediaObject->play(); } m_state = Playlist::Playing; }