File indexing completed on 2024-04-28 17:06:05
0001 /* 0002 SPDX-FileCopyrightText: 2006 Csaba Karai <cskarai@freemail.hu> 0003 SPDX-FileCopyrightText: 2006-2022 Krusader Krew <https://krusader.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef MEDIABUTTON_H 0009 #define MEDIABUTTON_H 0010 0011 // QtCore 0012 #include <QEvent> 0013 #include <QList> 0014 #include <QMap> 0015 #include <QTimer> 0016 #include <QUrl> 0017 // QtWidgets 0018 #include <QMenu> 0019 #include <QToolButton> 0020 #include <QWidget> 0021 0022 #include <Solid/Device> 0023 #include <Solid/SolidNamespace> 0024 0025 class QMenu; 0026 0027 class MediaButton : public QToolButton 0028 { 0029 Q_OBJECT 0030 public: 0031 explicit MediaButton(QWidget *parent = nullptr); 0032 ~MediaButton() override; 0033 0034 public slots: 0035 void slotAboutToShow(); 0036 void slotAboutToHide(); 0037 void slotPopupActivated(QAction *); 0038 void slotAccessibilityChanged(bool, const QString &); 0039 void slotDeviceAdded(const QString &); 0040 void slotDeviceRemoved(const QString &); 0041 void showMenu(); 0042 void slotCheckMounts(); 0043 void updateIcon(const QString &mountPoint); 0044 0045 signals: 0046 void openUrl(const QUrl &); 0047 void newTab(const QUrl &); 0048 void aboutToShow(); 0049 0050 protected: 0051 bool eventFilter(QObject *o, QEvent *e) override; 0052 bool getNameAndIcon(Solid::Device &, QString &, QIcon &); 0053 0054 private: 0055 void createMediaList(); 0056 void toggleMount(const QString &udi); 0057 void getStatus(const QString &udi, bool &mounted, QString *mountPointOut = nullptr, bool *ejectableOut = nullptr); 0058 void mount(const QString &, bool open = false, bool newtab = false); 0059 void umount(const QString &); 0060 void eject(QString); 0061 void rightClickMenu(const QString &udi, QPoint pos); 0062 0063 QList<Solid::Device> storageDevices; 0064 0065 private slots: 0066 void slotSetupDone(Solid::ErrorType error, const QVariant &errorData, const QString &udi); 0067 0068 private: 0069 static QString remotePrefix; 0070 0071 QMenu *popupMenu; 0072 QMenu *rightMenu; 0073 QString udiToOpen; 0074 bool openInNewTab; 0075 QMap<QString, QString> udiNameMap; 0076 QTimer mountCheckerTimer; 0077 QString currentMountPoint; // for performance optimization 0078 }; 0079 0080 #endif /* MEDIABUTTON_H */