Changeset View
Changeset View
Standalone View
Standalone View
src/solid/devices/backends/mounts/mountsstorageaccess.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by David Hallas <david@davidhallas.dk> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #include "mountsstorageaccess.h" | ||||
21 | #include "mounts.h" | ||||
22 | #include <QDebug> | ||||
23 | #include <QProcess> | ||||
24 | | ||||
25 | using namespace Solid::Backends::Mounts; | ||||
26 | | ||||
27 | MountsStorageAccess::MountsStorageAccess(QObject *parent, QString udi) : | ||||
28 | QObject(parent), | ||||
29 | m_udi(udi) | ||||
30 | { | ||||
31 | } | ||||
32 | | ||||
33 | MountsStorageAccess::~MountsStorageAccess() | ||||
34 | { | ||||
35 | } | ||||
36 | | ||||
37 | bool MountsStorageAccess::isAccessible() const | ||||
38 | { | ||||
39 | return true; | ||||
40 | } | ||||
41 | | ||||
42 | QString MountsStorageAccess::filePath() const | ||||
43 | { | ||||
44 | const FuseMount *fuseMount = Mounts::fuseMountFromUdi(m_udi); | ||||
45 | if (!fuseMount) { | ||||
46 | return QString(); | ||||
47 | } | ||||
48 | return fuseMount->mountPoint; | ||||
49 | } | ||||
50 | | ||||
51 | bool MountsStorageAccess::isIgnored() const | ||||
52 | { | ||||
53 | return false; | ||||
54 | } | ||||
55 | | ||||
56 | bool MountsStorageAccess::setup() | ||||
57 | { | ||||
58 | return true; | ||||
59 | } | ||||
60 | | ||||
61 | bool MountsStorageAccess::teardown() | ||||
62 | { | ||||
63 | QProcess *process = new QProcess(); | ||||
64 | connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | ||||
65 | [this, process](int exitCode, QProcess::ExitStatus exitStatus) { | ||||
66 | process->deleteLater(); | ||||
67 | emit this->teardownDone(Solid::ErrorType::NoError, QVariant(), this->m_udi); | ||||
68 | }); | ||||
69 | QStringList arguments; | ||||
70 | arguments << "-u" << Mounts::fuseMountFromUdi(m_udi)->mountPoint; | ||||
71 | process->start("/usr/bin/fusermount", arguments); | ||||
72 | if (process->waitForStarted()) { | ||||
73 | return true; | ||||
74 | } | ||||
75 | delete process; | ||||
76 | return false; | ||||
77 | } |