QString DAttachedUdisks2Device::displayName() { static QMap<QString, const char*> i18nMap { {"data", "Data Disk"} }; QStorageInfo storage_info(mountPoint); bool hasLabelName = true; QString result; if (blockDevice()->isValid()) { QString devName = blockDevice()->idLabel(); if (devName.isEmpty()) { hasLabelName = false; devName = qApp->translate("DeepinStorage", "%1 Volume").arg(DiskControlItem::formatDiskSize(blockDevice()->size())); } // Deepin i10n Label text (_dde_text): if (devName.startsWith(ddeI18nSym)) { QString i18nKey = devName.mid(ddeI18nSym.size(), devName.size() - ddeI18nSym.size()); devName = qApp->translate("DeepinStorage", i18nMap.value(i18nKey, i18nKey.toUtf8().constData())); } result = devName; } if (storage_info.isValid()) { if (!hasLabelName) { qint64 bytesTotal = storage_info.bytesTotal(); result = qApp->translate("DeepinStorage", "%1 Volume").arg(DiskControlItem::formatDiskSize(bytesTotal)); } } return result; }
void DAttachedUdisks2Device::detach() { blockDevice()->unmount({}); QScopedPointer<DDiskDevice> diskDev(DDiskManager::createDiskDevice(blockDevice()->drive())); if (diskDev->optical()) { // is optical if (diskDev->ejectable()) { diskDev->eject({}); return; } } if (diskDev->removable()) { diskDev->eject({}); } if (diskDev->canPowerOff()) { diskDev->powerOff({}); } }
/** * checks one storage target path and creates a QuotaBlockDevice * * @param targetPath path to block device to check * @param targetNumID targetNumID of the storage target to check */ QuotaBlockDevice QuotaBlockDevice::getBlockDeviceOfTarget(std::string& targetPath, uint16_t targetNumID) { static std::string mountInformationPath("/proc/mounts"); std::string resMountPath; std::string resBlockDevicePath; QuotaBlockDeviceFsType resFsType = QuotaBlockDeviceFsType_UNKNOWN; struct mntent* mntData; FILE *mntFile = setmntent(mountInformationPath.c_str(), "r"); while ( (mntData = getmntent(mntFile) ) ) { std::string tmpMountPath(mntData->mnt_dir); // test all mounts, use the mount with the longest match and use the last match if multiple // mounts with the longest match exists if ( (targetPath.find(tmpMountPath) == 0) && (resMountPath.size() <= tmpMountPath.size() ) ) { resMountPath = mntData->mnt_dir; resBlockDevicePath = mntData->mnt_fsname; std::string type(mntData->mnt_type); if ( type.compare("xfs") == 0 ) resFsType = QuotaBlockDeviceFsType_XFS; else if ( type.find("ext") == 0 ) resFsType = QuotaBlockDeviceFsType_EXTX; else if ( type.compare("zfs") == 0 ) resFsType = QuotaBlockDeviceFsType_ZFS; else resFsType = QuotaBlockDeviceFsType_UNKNOWN; } } endmntent(mntFile); QuotaBlockDevice blockDevice(resMountPath, resBlockDevicePath, resFsType, targetPath); // check if the installed libzfs is compatible with implementation if(blockDevice.getFsType() == QuotaBlockDeviceFsType_ZFS) { if(!Program::getApp()->isDlOpenHandleLibZfsValid() ) QuotaTk::checkRequiredLibZfsFunctions(&blockDevice, targetNumID); } return blockDevice; }
QString DAttachedUdisks2Device::iconName() { QScopedPointer<DDiskDevice> diskDev(DDiskManager::createDiskDevice(blockDevice()->drive())); bool isDvd = diskDev->optical(); bool isRemovable = diskDev->removable(); QString iconName = QStringLiteral("drive-harddisk"); if (isRemovable) { iconName = QStringLiteral("drive-removable-media-usb"); } if (isDvd) { iconName = QStringLiteral("media-optical"); } return iconName; }
bool DAttachedUdisks2Device::detachable() { QScopedPointer<DDiskDevice> diskDev(DDiskManager::createDiskDevice(blockDevice()->drive())); return diskDev->removable(); }