示例#1
0
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();
}
示例#2
0
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;
}
示例#3
0
// 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;
}
示例#4
0
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());
    }
}
示例#5
0
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);
}
示例#6
0
    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();
    }