<table><tr><td style="">marcingu added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D28745">View Revision</a></tr></table><br /><div><div><p>Ok, so far I have implemented <tt style="background: #ebebeb; font-size: 13px;">Solid::Device::storageAccessFromPath</tt> by talking all StorageAccess devices, going though all of them and and returning proper one.<br />
code:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">Solid::Device Solid::Device::storageAccessFromPath(const QString &path)
{
    // TODO check if symlinks are in the path
    QFileInfo fileInfo = QFileInfo(path);
    if (!fileInfo.exists()) {
        //TODO error handling
    }
    QSet<QString> checked; //To avoid weird infinete loops
    checked.insert(fileInfo.path());
    while (fileInfo.isSymLink()) {
        fileInfo = QFileInfo(fileInfo.symLinkTarget());
        if (checked.contains(fileInfo.path())) {
            //TODO error handling
        }
        checked.insert(fileInfo.path());
    }
    QDir dir = fileInfo.dir();
    QString canonPath = dir.canonicalPath();
    QList<Device> list = Solid::Device::listFromType(DeviceInterface::Type::StorageAccess);
    Device match;
    int match_length = 0;
    for (Device device: list) {
        StorageAccess *storageAccess = device.as<StorageAccess>();
        if (canonPath.startsWith(storageAccess->filePath()) && storageAccess->filePath().size() > match_length) {
            match_length = storageAccess->filePath().size();
            match = device;
        }
    }
    return match;
}</pre></div>

<p>and in the thumbnail.cpp:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">Solid::Device device = Solid::Device::storageAccessFromPath(filePath);
if (device.is<Solid::StorageVolume>()) {
    allowCache = device.as<Solid::StorageVolume>()->usage() != Solid::StorageVolume::UsageType::Encrypted;
}</pre></div>

<p>It works, but it might be better to hold tree structure with all StorageAcces devices where position on tree would be determined by mountpoint of device, which would allow us to go straight to the desired StorageAccess without checking all of them.<br />
On the other hand, to do that we would have to slice path into parts and compare those parts with nodes on the tree and also create special structure for that. I'm not sure which approach is better.</p>

<p>Another problem with storing StorageAccess tree is that I looked at DeviceManager classes and it might be too difficult for me, as I don't know Solid well.</p>

<p>Which should it be and do we go about it?</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R320 KIO Extras</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D28745">https://phabricator.kde.org/D28745</a></div></div><br /><div><strong>To: </strong>marcingu, ivan, broulik, Dolphin, ngraham, meven, bruns<br /><strong>Cc: </strong>thiago, bruns, meven, ngraham, kde-frameworks-devel, kfm-devel, waitquietly, azyx, nikolaik, pberestov, iasensio, aprcela, fprice, LeGast00n, cblack, fbampaloukas, alexde, Codezela, feverfew, michaelh, spoorun, navarromorales, firef, andrebarros, emmanuelp, rdieter, mikesomov<br /></div>