Add the refresh of search dirs' ui in ukcc plugin when the udisk is unplugged.

This commit is contained in:
baijunjie 2022-12-27 09:41:32 +08:00 committed by baijunjie
parent 020f869a29
commit 29c6440e23
4 changed files with 31 additions and 5 deletions

View File

@ -19,6 +19,10 @@ Search::Search()
QDBusConnection::sessionBus(), QDBusConnection::sessionBus(),
this); this);
if (m_interface->isValid()) {
connect(m_interface, SIGNAL(indexDirsChanged()), this, SLOT(refreshSearchDirsUi()));
}
m_setSearchDirInterface = new QDBusInterface("com.ukui.search.fileindex.service", m_setSearchDirInterface = new QDBusInterface("com.ukui.search.fileindex.service",
"/org/ukui/search/fileindex", "/org/ukui/search/fileindex",
"org.ukui.search.fileindex", "org.ukui.search.fileindex",
@ -386,6 +390,17 @@ void Search::initUi()
m_mainLyt->setContentsMargins(0, 0, 0, 0); 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() void Search::initFileDialog()
{ {
//添加黑名单对话框 //添加黑名单对话框

View File

@ -62,6 +62,9 @@ public:
QIcon icon() const Q_DECL_OVERRIDE; QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE; bool isEnable() const Q_DECL_OVERRIDE;
public Q_SLOTS:
void refreshSearchDirsUi();
private: private:
QWidget * m_pluginWidget = nullptr; QWidget * m_pluginWidget = nullptr;
QString m_plugin_name = ""; QString m_plugin_name = "";

View File

@ -66,15 +66,21 @@ void DirWatcher::updateIndexableDirs()
m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList(); m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList();
m_qSettings->endGroup(); m_qSettings->endGroup();
QStringList indexableDirs = m_indexableDirList; QStringList indexableDirs = m_indexableDirList;
bool changed(false);
for (const QString& dir : m_indexableDirList) { for (const QString& dir : m_indexableDirList) {
if (!QFileInfo(dir).isDir()) { if (!QFileInfo(dir).isDir()) {
indexableDirs.removeAll(dir); indexableDirs.removeAll(dir);
changed = true;
} }
} }
if (changed) {
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE); m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
m_qSettings->setValue(INDEXABLE_DIR_VALUE, indexableDirs); m_qSettings->setValue(INDEXABLE_DIR_VALUE, indexableDirs);
m_qSettings->endGroup(); m_qSettings->endGroup();
m_indexableDirList = indexableDirs; m_indexableDirList = indexableDirs;
Q_EMIT this->indexDirsChanged();
}
} }
QStringList DirWatcher::currentBlackListOfIndex() QStringList DirWatcher::currentBlackListOfIndex()
@ -249,8 +255,9 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di
qDebug() << "Mount Removed"; qDebug() << "Mount Removed";
pThis->handleDisk(); pThis->handleDisk();
QMutexLocker locker(&s_mutex); QMutexLocker locker(&s_mutex);
//处理u盘设备(由于udisk2信号连不上不生效 //处理u盘设备
if (pThis->m_removedUDiskDevice != NULL) { if (pThis->m_removedUDiskDevice != NULL) {
pThis->updateIndexableDirs();//更新索引名单,排除失效目录
pThis->m_currentUDiskDeviceInfo.remove(pThis->m_removedUDiskDevice); pThis->m_currentUDiskDeviceInfo.remove(pThis->m_removedUDiskDevice);
qDebug() << "m_currentUDiskDeviceInfo(after remove):" << pThis->m_currentUDiskDeviceInfo; qDebug() << "m_currentUDiskDeviceInfo(after remove):" << pThis->m_currentUDiskDeviceInfo;
pThis->m_removedUDiskDevice = ""; pThis->m_removedUDiskDevice = "";

View File

@ -106,6 +106,7 @@ Q_SIGNALS:
void udiskRemoved(); void udiskRemoved();
void appendIndexItem(const QString&, const QStringList&); void appendIndexItem(const QString&, const QStringList&);
void removeIndexItem(const QString&); void removeIndexItem(const QString&);
void indexDirsChanged();
}; };
#endif // MOUNTDISKLISTENER_H #endif // MOUNTDISKLISTENER_H