本文整理汇总了C++中solid::Device类的典型用法代码示例。如果您正苦于以下问题:C++ Device类的具体用法?C++ Device怎么用?C++ Device使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canHandle
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;
}
示例2: main
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;
}
示例3: data
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();
}
示例4: start
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();
}
示例5:
/**
* @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" );
}
示例6: opticalParent
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;
}
示例7: hasRemovableParent
// 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;
}
示例8: lookup
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());
}
}
示例9: teardownAction
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);
}
示例10: checkUrl
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;
}
}
}
示例11: SolDevice
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);
}
}
示例12: sourceRequestEvent
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;
}
}
示例13: setDevice
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()));
}
示例14: deviceData
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();
}
示例15: deviceLessThan
bool deviceLessThan(const Solid::Device &a, const Solid::Device &b) {
return a.udi() < b.udi();
}