1 /*****************************************************************************
2  * Copyright (C) 2000 Shie Erlich <krusader@users.sourceforge.net>           *
3  * Copyright (C) 2000 Rafi Yanai <krusader@users.sourceforge.net>            *
4  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
5  *                                                                           *
6  * This file is part of Krusader [https://krusader.org].                     *
7  *                                                                           *
8  * Krusader is free software: you can redistribute it and/or modify          *
9  * it under the terms of the GNU General Public License as published by      *
10  * the Free Software Foundation, either version 2 of the License, or         *
11  * (at your option) any later version.                                       *
12  *                                                                           *
13  * Krusader is distributed in the hope that it will be useful,               *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
16  * GNU General Public License for more details.                              *
17  *                                                                           *
18  * You should have received a copy of the GNU General Public License         *
19  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
20  *****************************************************************************/
21 #ifndef KMOUNTMAN_H
22 #define KMOUNTMAN_H
23 
24 // QtCore
25 #include <QExplicitlySharedDataPointer>
26 #include <QObject>
27 #include <QString>
28 #include <QPointer>
29 #include <QUrl>
30 // QtWidgets
31 #include <QWidget>
32 #include <QAction>
33 
34 #include <KIO/Job>
35 #include <KIO/Global>
36 #include <KIOCore/KMountPoint>
37 
38 #include <Solid/Device>
39 #include <Solid/SolidNamespace>
40 
41 class KMountManGUI;
42 class KToolBarPopupAction;
43 
44 class KMountMan : public QObject
45 {
46     Q_OBJECT
47     friend class KMountManGUI;
48 
49 public:
50     enum mntStatus {DOESNT_EXIST, NOT_MOUNTED, MOUNTED};
51 
operational()52     inline bool operational() {
53         return _operational;
54     } // check this 1st
55 
56     void mount(QString mntPoint, bool blocking = true); // this is probably what you need for mount
57     void unmount(QString mntPoint, bool blocking = true); // this is probably what you need for unmount
58     mntStatus getStatus(QString mntPoint);    // return the status of a mntPoint (if any)
59     void eject(QString mntPoint);
60     bool ejectable(QString path);
61     bool removable(QString path);
62     bool removable(Solid::Device d);
63     QString convertSize(KIO::filesize_t size);
64     bool invalidFilesystem(QString type);
65     bool networkFilesystem(QString type);
66     bool nonmountFilesystem(QString type, QString mntPoint);
action()67     QAction *action() {
68         return (QAction *) _action;
69     }
70 
71     explicit KMountMan(QWidget *parent);
72     ~KMountMan();
73 
74     // NOTE: this function needs some time (~50msec)
75     QString findUdiForPath(QString path, const Solid::DeviceInterface::Type &expType = Solid::DeviceInterface::Unknown);
76     QString pathForUdi(QString udi);
77 
78 public slots:
79     void mainWindow();                        // opens up the GUI
80     void autoMount(QString path);             // just call it before refreshing into a dir
81     void delayedPerformAction(const QAction *action);
82     void quickList();
83 
84 protected slots:
85     void jobResult(KJob *job);
86     void slotTeardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
87     void slotSetupDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
88 
89 protected:
90     // used internally
91     static QExplicitlySharedDataPointer<KMountPoint> findInListByMntPoint(KMountPoint::List &lst, QString value);
92     void toggleMount(QString mntPoint);
emitRefreshPanel(const QUrl & url)93     void emitRefreshPanel(const QUrl &url) {
94         emit refreshPanel(url);
95     }
96 
97 signals:
98     void refreshPanel(const QUrl &);
99 
100 private:
101     enum ActionType { Mount, Unmount };
102 
103     KToolBarPopupAction *_action;
104     QAction *_manageAction;
105 
106     bool _operational;   // if false, something went terribly wrong on startup
107     bool waiting; // used to block krusader while waiting for (un)mount operation
108     KMountManGUI *mountManGui;
109     // the following is the FS type
110     QStringList invalid_fs;
111     QStringList nonmount_fs;
112     QStringList network_fs;
113     // the following is the FS name
114     QStringList nonmount_fs_mntpoint;
115     QPointer<QWidget> parentWindow;
116 };
117 
118 #endif
119