File indexing completed on 2024-04-28 17:06:14

0001 /*
0002     SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 #ifndef KMOUNTMAN_H
0009 #define KMOUNTMAN_H
0010 
0011 // QtCore
0012 #include <QExplicitlySharedDataPointer>
0013 #include <QObject>
0014 #include <QPointer>
0015 #include <QString>
0016 #include <QUrl>
0017 // QtWidgets
0018 #include <QAction>
0019 #include <QWidget>
0020 
0021 #include <KIO/Global>
0022 #include <KIO/Job>
0023 #include <KIOCore/KMountPoint>
0024 
0025 #include <Solid/Device>
0026 #include <Solid/SolidNamespace>
0027 
0028 class KMountManGUI;
0029 class KToolBarPopupAction;
0030 
0031 class KMountMan : public QObject
0032 {
0033     Q_OBJECT
0034     friend class KMountManGUI;
0035 
0036 public:
0037     enum mntStatus { DOESNT_EXIST, NOT_MOUNTED, MOUNTED };
0038 
0039     inline bool operational()
0040     {
0041         return _operational;
0042     } // check this 1st
0043 
0044     void mount(const QString &mntPoint, bool blocking = true); // this is probably what you need for mount
0045     void unmount(const QString &mntPoint, bool blocking = true); // this is probably what you need for unmount
0046     mntStatus getStatus(const QString &mntPoint); // return the status of a mntPoint (if any)
0047     void eject(const QString &mntPoint);
0048     bool ejectable(QString path);
0049     bool removable(QString path);
0050     bool removable(Solid::Device d);
0051     bool invalidFilesystem(const QString &type);
0052     bool networkFilesystem(const QString &type);
0053     bool nonmountFilesystem(const QString &type, const QString &mntPoint);
0054     QAction *action()
0055     {
0056         return (QAction *)_action;
0057     }
0058 
0059     explicit KMountMan(QWidget *parent);
0060     ~KMountMan();
0061 
0062     // NOTE: this function needs some time (~50msec)
0063     QString findUdiForPath(const QString &path, const Solid::DeviceInterface::Type &expType = Solid::DeviceInterface::Unknown);
0064     QString pathForUdi(const QString &udi);
0065 
0066 public slots:
0067     void mainWindow(); // opens up the GUI
0068     void autoMount(const QString &path); // just call it before refreshing into a dir
0069     void delayedPerformAction(const QAction *action);
0070     void quickList();
0071     void slotTeardownRequested(const QString &udi);
0072 
0073 protected slots:
0074     void jobResult(KJob *job);
0075     void slotTeardownDone(Solid::ErrorType error, const QVariant &errorData, const QString &udi);
0076     void slotSetupDone(Solid::ErrorType error, const QVariant &errorData, const QString &udi);
0077     void deviceAdded(const QString &udi);
0078 
0079 protected:
0080     // used internally
0081     static QExplicitlySharedDataPointer<KMountPoint> findInListByMntPoint(KMountPoint::List &lst, QString value);
0082     void toggleMount(const QString &mntPoint);
0083     void emitRefreshPanel(const QUrl &url)
0084     {
0085         emit refreshPanel(url);
0086     }
0087 
0088 signals:
0089     void refreshPanel(const QUrl &);
0090 
0091 private:
0092     enum ActionType { Mount, Unmount };
0093 
0094     KToolBarPopupAction *_action;
0095     QAction *_manageAction;
0096 
0097     bool _operational; // if false, something went terribly wrong on startup
0098     bool waiting; // used to block krusader while waiting for (un)mount operation
0099     KMountManGUI *mountManGui;
0100     // the following is the FS type
0101     QStringList invalid_fs;
0102     QStringList nonmount_fs;
0103     QStringList network_fs;
0104     // the following is the FS name
0105     QStringList nonmount_fs_mntpoint;
0106     QPointer<QWidget> parentWindow;
0107 };
0108 
0109 #endif