File indexing completed on 2024-04-14 03:49:47

0001 /*
0002     This file is part of the KDE Baloo project.
0003     SPDX-FileCopyrightText: 2011 Sebastian Trueg <trueg@kde.org>
0004     SPDX-FileCopyrightText: 2014 Vishesh Handa <vhanda@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef STORAGE_DEVICES_H
0010 #define STORAGE_DEVICES_H
0011 
0012 #include <QObject>
0013 #include <QHash>
0014 
0015 #include <Solid/Device>
0016 
0017 namespace Baloo
0018 {
0019 
0020 /**
0021  * The removable media cache
0022  * media that are supported by Baloo.
0023  */
0024 class StorageDevices : public QObject
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     explicit StorageDevices(QObject* parent = nullptr);
0030     ~StorageDevices();
0031 
0032     class Entry
0033     {
0034     public:
0035         Entry();
0036         explicit Entry(const Solid::Device& device);
0037 
0038         Solid::Device device() const {
0039             return m_device;
0040         }
0041 
0042         bool isMounted() const;
0043         QString mountPath() const;
0044 
0045         /**
0046          * Returns true if Baloo should be indexing this
0047          * Currently we only index permanently mounted media
0048          */
0049         bool isUsable() const;
0050 
0051         QString udi() const {
0052             return m_device.udi();
0053         }
0054     private:
0055         Solid::Device m_device;
0056     };
0057 
0058     QList<Entry> allMedia() const;
0059     bool isEmpty() const;
0060 
0061 Q_SIGNALS:
0062     void deviceAdded(const Baloo::StorageDevices::Entry* entry);
0063     void deviceRemoved(const Baloo::StorageDevices::Entry* entry);
0064     void deviceAccessibilityChanged(const Baloo::StorageDevices::Entry* entry);
0065 
0066 private Q_SLOTS:
0067     void slotSolidDeviceAdded(const QString& udi);
0068     void slotSolidDeviceRemoved(const QString& udi);
0069     void slotAccessibilityChanged(bool accessible, const QString& udi);
0070 
0071 private:
0072     void initCacheEntries();
0073 
0074     Entry* createCacheEntry(const Solid::Device& dev);
0075 
0076     /// maps Solid UDI to Entry
0077     QHash<QString, Entry> m_metadataCache;
0078 };
0079 
0080 } // namespace Baloo
0081 
0082 Q_DECLARE_TYPEINFO(Baloo::StorageDevices::Entry, Q_RELOCATABLE_TYPE);
0083 
0084 #endif // STORAGE_DEVICES_H