2022-04-25 10:23:20 +08:00
|
|
|
#ifndef MOUNTDISKLISTENER_H
|
|
|
|
#define MOUNTDISKLISTENER_H
|
|
|
|
|
|
|
|
#include "dir-watcher-adaptor.h"
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QStorageInfo>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusObjectPath>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusReply>
|
|
|
|
|
|
|
|
#undef slots
|
|
|
|
#undef signals
|
|
|
|
#undef emit
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <gio/gunixmounts.h>
|
|
|
|
|
|
|
|
class DirWatcher : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_CLASSINFO("D-Bus Interface","org.ukui.search.fileindex")
|
|
|
|
|
|
|
|
public:
|
|
|
|
static DirWatcher *getDirWatcher();
|
|
|
|
static void mountAddCallback(GVolumeMonitor *monitor, GMount *gmount, DirWatcher *pThis);
|
|
|
|
static void mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, DirWatcher *pThis);
|
|
|
|
|
|
|
|
void appendBlackListItemOfIndex(const QString &path);
|
|
|
|
void appendBlackListItemOfIndex(const QStringList &pathList);
|
|
|
|
void removeBlackListItemOfIndex(const QString &path);
|
|
|
|
void removeBlackListItemOfIndex(const QStringList &pathList);
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
|
|
|
|
void initDbusService();
|
|
|
|
|
|
|
|
QStringList currentIndexableDir();
|
|
|
|
QStringList currentBlackListOfIndex();
|
|
|
|
|
|
|
|
QStringList currentSearchableDir();
|
|
|
|
QStringList searchableDirForSearchApplication();
|
|
|
|
QStringList blackListOfDir(const QString &dirPath);
|
|
|
|
|
2022-12-07 14:04:21 +08:00
|
|
|
/**
|
|
|
|
* @brief DirWatcher::appendIndexableListItem
|
|
|
|
* add a item to indexable dirs
|
|
|
|
* @param path: the path to be added to the index dirs list
|
|
|
|
* @return int: the result code
|
|
|
|
* 1: successful
|
|
|
|
* -1: path or its parent dir has been added
|
|
|
|
* -2: path is or under blacklist
|
|
|
|
* -3: path is in repeat mounted devices and another path which is in the same device has been indexed
|
|
|
|
* -4: another path which is in the same device has been indexed
|
|
|
|
* -5: path is not exists
|
|
|
|
*/
|
|
|
|
Q_SCRIPTABLE int appendIndexableListItem(const QString &path);
|
|
|
|
Q_SCRIPTABLE bool removeIndexableListItem(const QString &path);
|
2022-04-25 10:23:20 +08:00
|
|
|
|
2023-04-06 10:39:10 +08:00
|
|
|
//新接口
|
|
|
|
int appendSearchDir(const QString &path);
|
|
|
|
void removeSearchDir(const QString &path);
|
|
|
|
|
|
|
|
QStringList currentSearchDirs();
|
|
|
|
QStringList currentBlackList();
|
|
|
|
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
private:
|
|
|
|
DirWatcher(QObject *parent = nullptr);
|
|
|
|
~DirWatcher();
|
|
|
|
void initData();
|
|
|
|
void initDiskWatcher();
|
2022-12-07 14:04:21 +08:00
|
|
|
void updateIndexableDirs();
|
2022-04-25 10:23:20 +08:00
|
|
|
|
|
|
|
void handleDisk();
|
|
|
|
|
2022-12-07 14:04:21 +08:00
|
|
|
bool handleIndexItemAppend(const QString &path, QStringList &blackList);
|
|
|
|
bool handleIndexItemRemove(const QString &path);
|
2022-04-25 10:23:20 +08:00
|
|
|
|
|
|
|
static QMutex s_mutex;
|
|
|
|
|
|
|
|
DirWatcherAdaptor *m_adaptor = nullptr;
|
|
|
|
|
|
|
|
GVolumeMonitor *m_volumeMonitor = nullptr;
|
|
|
|
quint64 m_mountAddHandle;
|
|
|
|
quint64 m_mountRemoveHandle;
|
|
|
|
|
|
|
|
QSettings *m_qSettings = nullptr;
|
|
|
|
QStringList m_blackListOfIndex;
|
|
|
|
QStringList m_indexableDirList;
|
|
|
|
|
|
|
|
QStringList m_searchableDirList;
|
|
|
|
QStringList m_searchableListForApplication;
|
|
|
|
QStringList m_autoMountList;
|
|
|
|
QMultiMap<QString, QString> m_infoOfSubvolume;
|
|
|
|
QMap<QString, QStringList> m_currentMountedDeviceInfo;
|
|
|
|
QMap<QString, QStringList> m_repeatedlyMountedDeviceInfo;
|
|
|
|
|
2022-05-12 17:19:04 +08:00
|
|
|
QStringList m_currentUDiskDeviceList;
|
2022-04-25 10:23:20 +08:00
|
|
|
QString m_removedUDiskDevice;
|
|
|
|
QMap<QString, QStringList> m_currentUDiskDeviceInfo;
|
2022-06-23 10:21:22 +08:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void handleAddedUDiskDevice(QDBusMessage msg);
|
|
|
|
void handleRemovedUDiskDevice(QDBusMessage msg);
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void udiskRemoved();
|
|
|
|
void appendIndexItem(const QString&, const QStringList&);
|
|
|
|
void removeIndexItem(const QString&);
|
2022-12-27 09:41:32 +08:00
|
|
|
void indexDirsChanged();
|
2022-04-25 10:23:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOUNTDISKLISTENER_H
|
|
|
|
|