Commit 0c9abdaf authored by Anthony Fieroni's avatar Anthony Fieroni
Browse files

[filenamesearch] Add kded module to watch file changes



REVIEW: 129297
Signed-off-by: Anthony Fieroni's avatarAnthony Fieroni <bvbfan@abv.bg>
parent 2e48fc8f
add_library(kio_filenamesearch MODULE kio_filenamesearch.cpp)
target_link_libraries(kio_filenamesearch KF5::KIOCore)
target_link_libraries(kio_filenamesearch KF5::KIOCore KF5::DBusAddons)
set_target_properties(kio_filenamesearch PROPERTIES OUTPUT_NAME "filenamesearch")
install(TARGETS kio_filenamesearch DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kio)
install(FILES filenamesearch.protocol DESTINATION ${SERVICES_INSTALL_DIR})
add_subdirectory(kded)
set (KDED_FILENAMESEARCH_SRCS
filenamesearchmodule.cpp
)
add_library(filenamesearchmodule MODULE ${KDED_FILENAMESEARCH_SRCS})
kcoreaddons_desktop_to_json(filenamesearchmodule filenamesearchmodule.desktop)
target_link_libraries(filenamesearchmodule
KF5::DBusAddons
KF5::KIOCore
)
install(TARGETS filenamesearchmodule DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kded)
/*
* This file is part of the KDE KIO-extras Project
* Copyright (C) 2016 Anthony Fieroni <bvbfan@abv.bg>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "filenamesearchmodule.h"
#include <QDBusConnection>
#include <QUrl>
#include <KPluginFactory>
FileNameSearchModule::FileNameSearchModule(QObject* parent, const QVariantList&)
: KDEDModule(parent)
, m_dirNotify(QString(), QString(), QDBusConnection::sessionBus())
{
connect(&m_dirNotify, &OrgKdeKDirNotifyInterface::enteredDirectory,
this, &FileNameSearchModule::registerSearchUrl);
connect(&m_dirNotify, &OrgKdeKDirNotifyInterface::leftDirectory,
this, &FileNameSearchModule::unregisterSearchUrl);
connect(&m_dirNotify, &OrgKdeKDirNotifyInterface::FilesAdded,
this, &FileNameSearchModule::slotFilesAdded);
connect(&m_dirNotify, &OrgKdeKDirNotifyInterface::FilesChanged,
this, &FileNameSearchModule::slotFilesChanged);
connect(&m_dirNotify, &OrgKdeKDirNotifyInterface::FilesRemoved,
this, &FileNameSearchModule::slotFilesRemoved);
}
void FileNameSearchModule::registerSearchUrl(const QString &urlString)
{
if (urlString.startsWith(QStringLiteral("filenamesearch"))) {
m_searchUrls << QUrl(urlString);
}
}
void FileNameSearchModule::unregisterSearchUrl(const QString &urlString)
{
if (urlString.startsWith(QStringLiteral("filenamesearch"))) {
m_searchUrls.removeAll(QUrl(urlString));
}
}
void FileNameSearchModule::slotFilesAdded(const QString &urlString)
{
for (const QUrl &dirUrl : m_searchUrls) {
if (urlString.startsWith(dirUrl.path())) {
org::kde::KDirNotify::emitFilesAdded(dirUrl);
}
}
}
void FileNameSearchModule::slotFilesChanged(const QStringList &files)
{
QList<QUrl> fileList;
fileList.reserve(files.count());
for (const QUrl &dirUrl : m_searchUrls) {
for (const QString &file : files) {
if (file.startsWith(dirUrl.path())) {
QUrl url(file);
url.setScheme(QStringLiteral("filenamesearch"));
fileList << url;
}
}
}
if (!fileList.isEmpty()) {
org::kde::KDirNotify::emitFilesChanged(fileList);
}
}
void FileNameSearchModule::slotFilesRemoved(const QStringList &files)
{
QList<QUrl> fileList;
fileList.reserve(files.count());
for (const QUrl &dirUrl : m_searchUrls) {
for (const QString &file : files) {
if (file.startsWith(dirUrl.path())) {
QUrl url(file);
url.setScheme(QStringLiteral("filenamesearch"));
fileList << url;
}
}
}
if (!fileList.isEmpty()) {
org::kde::KDirNotify::emitFilesRemoved(fileList);
}
}
K_PLUGIN_FACTORY_WITH_JSON(Factory,
"filenamesearchmodule.json",
registerPlugin<FileNameSearchModule>();)
#include "filenamesearchmodule.moc"
[Desktop Entry]
Type=Service
Icon=edit-find
ServiceTypes=KDEDModule
X-KDE-ServiceTypes=KDEDModule
X-KDE-Library=filenamesearchmodule
X-KDE-FactoryName=filenamesearchmodule
X-KDE-DBus-ModuleName=filenamesearchmodule
X-KDE-Kded-load-on-demand=true
X-KDE-Kded-autoload=false
Name=Search Folder Updater
Name[ar]=محدّث مجلّدات البحث
Name[ast]=Anovador de carpetes de gueta
Name[bg]=Обновяване на търсените папки
Name[ca]=Actualitzador de les carpetes de cerca
Name[ca@valencia]=Actualitzador de les carpetes de cerca
Name[cs]=Nástroj pro aktualizaci složek pro vyhledávání
Name[da]=Opdatering af søgemappe
Name[de]=Suchordner-Aktualisierung
Name[el]=Εργαλείο ενημέρωσης φακέλου αναζήτησης
Name[en_GB]=Search Folder Updater
Name[es]=Actualizador de la carpeta de búsquedas
Name[et]=Otsingukataloogide uuendaja
Name[fi]=Hakukansion päivitin
Name[fr]=Mise à jour du dossier Recherche
Name[gd]=Inneal-ùrachaidh nam pasganan-luirg
Name[gl]=Actualizador do cartafol de busca
Name[hu]=Keresésfrissítő
Name[it]=Aggiornamento delle cartelle di ricerca
Name[ko]=검색 폴더 업데이트 도구
Name[nb]=Søkemappe-oppdatering
Name[nds]=Söökorner-Opfrischen
Name[nl]=Bijwerker van zoekmap
Name[nn]=Søkjemappe-oppdatering
Name[pl]=Uaktualnianie katalogu wyszukiwania
Name[pt]=Actualização das Pastas de Pesquisa
Name[pt_BR]=Atualização das pastas de pesquisa
Name[ro]=Actualizator pentru dosare de căutare
Name[ru]=Обновление папок поиска
Name[sk]=Aktualizátor priečinkov hľadania
Name[sl]=Posodobilnik iskalnih map
Name[sr]=Освеживач фасцикла претраге
Name[sr@ijekavian]=Освеживач фасцикла претраге
Name[sr@ijekavianlatin]=Osveživač fascikla pretrage
Name[sr@latin]=Osveživač fascikla pretrage
Name[sv]=Uppdateringsverktyg för sökkataloger
Name[tr]=Klasör Güncelleyici Araması
Name[uk]=Засіб оновлення тек пошуку
Name[x-test]=xxSearch Folder Updaterxx
Name[zh_CN]=搜索文件夹更新器
Name[zh_TW]=搜尋資料夾更新器
Comment=Allows automatic updates of Search Folders
Comment[ar]=يسمح بالتّحديثات الآليّة لمجلّدات البحث
Comment[ast]=Permite anovamientos automáticos de les carpetes de gueta
Comment[bg]=Автоматично обновяване на търсените папки
Comment[ca]=Permet l'actualització automàtica de les carpetes de cerca
Comment[ca@valencia]=Permet l'actualització automàtica de les carpetes de cerca
Comment[cs]=Umožňuje automatickou aktualizaci prohledávaných složek
Comment[da]=Tillad automatisk opdatering af søgemapper
Comment[de]=Ermöglicht die automatische Aktualisierung von Suchordnern
Comment[el]=Επιτρέπει την αυτόματη ενημέρωση των φακέλων αναζήτησης
Comment[en_GB]=Allows automatic updates of Search Folders
Comment[es]=Permite actualizaciones automáticas de las carpetas de búsqueda
Comment[et]=Võimaldab otsingukataloogide automaatset uuendamist
Comment[fi]=Mahdollistaa hakukansioiden automaattisen päivittämisen
Comment[fr]=Permet une mise à jour automatique des dossiers de recherche
Comment[gd]=Bheir e comas ùrachaidh fhèin-obrachail dhut airson nam pasganan-luirg
Comment[gl]=Permite actualizar automaticamente os cartafoles de busca.
Comment[hu]=Lehetővé teszi a keresési mappák automatikus frissítését
Comment[it]=Permette l'aggiornamento automatico delle cartelle di ricerca
Comment[ko]=검색 폴더 자동 업데이트 허용
Comment[nb]=Tillater automatisk oppdatering av søkemapper
Comment[nds]=Frischt Söökornern automaatsch op
Comment[nl]=Staat automatisch bijwerken van zoekmappen toe
Comment[nn]=Tillèt automatiske oppdateringar av søkjemapper
Comment[pl]=Umożliwia samoczynne uaktualnienia katalogów wyszukiwania
Comment[pt]=Permite as actualizações automáticas das Pastas de Pesquisa
Comment[pt_BR]=Permite as atualizações automáticas das pastas de pesquisa
Comment[ro]=Permite actualizarea automată a dosarelor de căutare
Comment[ru]=Автоматическое обновление результатов поиска файлов
Comment[sk]=Umožní automatické aktualizácie priečinkov hľadania
Comment[sl]=Omogoča samodejno posodabljanje iskalnih map
Comment[sr]=Омогућава аутоматско ажурирање фасцикла претраге
Comment[sr@ijekavian]=Омогућава аутоматско ажурирање фасцикла претраге
Comment[sr@ijekavianlatin]=Omogućava automatsko ažuriranje fascikla pretrage
Comment[sr@latin]=Omogućava automatsko ažuriranje fascikla pretrage
Comment[sv]=Tillåter automatisk uppdatering av sökkataloger
Comment[tr]=Arama klasörlerinin otomatik güncellenmesine izin verir
Comment[uk]=Надає змогу автоматично оновлювати теки пошуку
Comment[x-test]=xxAllows automatic updates of Search Foldersxx
Comment[zh_CN]=允许自动更新搜索文件夹
Comment[zh_TW]=允許自動更新搜尋資料夾
/*
* This file is part of the KDE KIO-extras Project
* Copyright (C) 2016 Anthony Fieroni <bvbfan@abv.bg>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef FILENAME_SEARCH_KDED_MODULE_H_
#define FILENAME_SEARCH_KDED_MODULE_H_
#include <KDEDModule>
#include <kdirnotify.h>
#include <QUrl>
class FileNameSearchModule : public KDEDModule
{
Q_OBJECT
public:
FileNameSearchModule(QObject *parent, const QVariantList&);
private Q_SLOTS:
void registerSearchUrl(const QString &urlString);
void unregisterSearchUrl(const QString &urlString);
void slotFilesAdded(const QString &urlString);
void slotFilesChanged(const QStringList &files);
void slotFilesRemoved(const QStringList &files);
private:
QList<QUrl> m_searchUrls;
org::kde::KDirNotify m_dirNotify;
};
#endif
......@@ -29,12 +29,15 @@
#include <QRegularExpression>
#include <QUrl>
#include <QUrlQuery>
#include <QtDBus/QDBusInterface>
Q_LOGGING_CATEGORY(KIO_FILENAMESEARCH, "kio_filenamesearch")
FileNameSearchProtocol::FileNameSearchProtocol(const QByteArray &pool, const QByteArray &app)
: SlaveBase("search", pool, app)
{
QDBusInterface kded(QStringLiteral("org.kde.kded5"), QStringLiteral("/kded"), QStringLiteral("org.kde.kded5"));
kded.call(QStringLiteral("loadModule"), QStringLiteral("filenamesearchmodule"));
}
FileNameSearchProtocol::~FileNameSearchProtocol()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment