From b6901a420cffbaf16890cbff4c25a8e3a433d419 Mon Sep 17 00:00:00 2001 From: baijunjie Date: Tue, 27 Dec 2022 09:41:32 +0800 Subject: [PATCH] Add the refresh of search dirs' ui in ukcc plugin when the udisk is unplugged. --- search-ukcc-plugin/search.cpp | 15 +++++++++++++++ search-ukcc-plugin/search.h | 3 +++ .../dirwatcher/dir-watcher.cpp | 17 ++++++++++++----- .../dirwatcher/dir-watcher.h | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/search-ukcc-plugin/search.cpp b/search-ukcc-plugin/search.cpp index e39e2a6..a5e093c 100644 --- a/search-ukcc-plugin/search.cpp +++ b/search-ukcc-plugin/search.cpp @@ -19,6 +19,10 @@ Search::Search() QDBusConnection::sessionBus(), this); + if (m_interface->isValid()) { + connect(m_interface, SIGNAL(indexDirsChanged()), this, SLOT(refreshSearchDirsUi())); + } + m_setSearchDirInterface = new QDBusInterface("com.ukui.search.fileindex.service", "/org/ukui/search/fileindex", "org.ukui.search.fileindex", @@ -386,6 +390,17 @@ void Search::initUi() m_mainLyt->setContentsMargins(0, 0, 0, 0); } +void Search::refreshSearchDirsUi() +{ + qWarning() << "==========refreshUi!!!!"; + while (m_searchDirLyt->count() - 1) { + QWidget *widget = m_searchDirLyt->itemAt(m_searchDirLyt->count() - 1)->widget(); + m_searchDirLyt->removeWidget(widget); + widget->deleteLater(); + } + initSearchDirs(); +} + void Search::initFileDialog() { //添加黑名单对话框 diff --git a/search-ukcc-plugin/search.h b/search-ukcc-plugin/search.h index 5f362f4..bc54ede 100644 --- a/search-ukcc-plugin/search.h +++ b/search-ukcc-plugin/search.h @@ -62,6 +62,9 @@ public: QIcon icon() const Q_DECL_OVERRIDE; bool isEnable() const Q_DECL_OVERRIDE; +public Q_SLOTS: + void refreshSearchDirsUi(); + private: QWidget * m_pluginWidget = nullptr; QString m_plugin_name = ""; diff --git a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp index 01a6755..206a367 100644 --- a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp +++ b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp @@ -66,15 +66,21 @@ void DirWatcher::updateIndexableDirs() m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList(); m_qSettings->endGroup(); QStringList indexableDirs = m_indexableDirList; + bool changed(false); for (const QString& dir : m_indexableDirList) { if (!QFileInfo(dir).isDir()) { indexableDirs.removeAll(dir); + changed = true; } } - m_qSettings->beginGroup(INDEXABLE_DIR_VALUE); - m_qSettings->setValue(INDEXABLE_DIR_VALUE, indexableDirs); - m_qSettings->endGroup(); - m_indexableDirList = indexableDirs; + + if (changed) { + m_qSettings->beginGroup(INDEXABLE_DIR_VALUE); + m_qSettings->setValue(INDEXABLE_DIR_VALUE, indexableDirs); + m_qSettings->endGroup(); + m_indexableDirList = indexableDirs; + Q_EMIT this->indexDirsChanged(); + } } QStringList DirWatcher::currentBlackListOfIndex() @@ -249,8 +255,9 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di qDebug() << "Mount Removed"; pThis->handleDisk(); QMutexLocker locker(&s_mutex); - //处理u盘设备(由于udisk2信号连不上,不生效) + //处理u盘设备 if (pThis->m_removedUDiskDevice != NULL) { + pThis->updateIndexableDirs();//更新索引名单,排除失效目录 pThis->m_currentUDiskDeviceInfo.remove(pThis->m_removedUDiskDevice); qDebug() << "m_currentUDiskDeviceInfo(after remove):" << pThis->m_currentUDiskDeviceInfo; pThis->m_removedUDiskDevice = ""; diff --git a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.h b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.h index d702c23..2e12f09 100644 --- a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.h +++ b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.h @@ -106,6 +106,7 @@ Q_SIGNALS: void udiskRemoved(); void appendIndexItem(const QString&, const QStringList&); void removeIndexItem(const QString&); + void indexDirsChanged(); }; #endif // MOUNTDISKLISTENER_H