mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 09:20:13 +00:00
The filenamesearch ioslave has been moved to kio-extras, remove it from Dolphin.
See commit 05689c462745edbaeebcfc63d456877746805451 in kio-extras
This commit is contained in:
parent
bfdc5a44d2
commit
3c74d908de
|
@ -310,17 +310,6 @@ install(TARGETS kcm_dolphinnavigation DESTINATION ${PLUGIN_INSTALL_DIR} )
|
|||
install(TARGETS kcm_dolphinservices DESTINATION ${PLUGIN_INSTALL_DIR} )
|
||||
install(TARGETS kcm_dolphingeneral DESTINATION ${PLUGIN_INSTALL_DIR} )
|
||||
|
||||
#########################################
|
||||
|
||||
set(kio_search_PART_SRCS
|
||||
search/filenamesearchprotocol.cpp)
|
||||
|
||||
add_library(kio_filenamesearch MODULE ${kio_search_PART_SRCS})
|
||||
|
||||
target_link_libraries(kio_filenamesearch KF5::KDELibs4Support)
|
||||
|
||||
install(TARGETS kio_filenamesearch DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
|
||||
########### install files ###############
|
||||
|
||||
install( PROGRAMS org.kde.dolphin.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
|
||||
|
@ -333,7 +322,6 @@ install( FILES settings/dolphin_directoryviewpropertysettings.kcfg
|
|||
DESTINATION ${KCFG_INSTALL_DIR} )
|
||||
install( FILES dolphinui.rc DESTINATION ${CMAKE_INSTALL_KXMLGUI5DIR}/dolphin )
|
||||
install( FILES dolphin.appdata.xml DESTINATION ${SHARE_INSTALL_PREFIX}/appdata )
|
||||
install( FILES search/filenamesearch.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
|
||||
install( FILES settings/kcm/kcmdolphinviewmodes.desktop DESTINATION
|
||||
${SERVICES_INSTALL_DIR} )
|
||||
install( FILES settings/kcm/kcmdolphinnavigation.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
[Protocol]
|
||||
exec=kio_filenamesearch
|
||||
protocol=filenamesearch
|
||||
input=none
|
||||
output=filesystem
|
||||
reading=true
|
||||
writing=false
|
||||
deleting=true
|
||||
linking=false
|
||||
makedir=false
|
||||
moving=false
|
||||
listing=Name,Type,Size,Date,AccessDate,Access,Owner,Group,Link
|
||||
source=false
|
||||
Icon=edit-find
|
||||
Class=:local
|
||||
determineMimetypeFromExtension=false
|
||||
maxInstances=10
|
|
@ -1,192 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include "filenamesearchprotocol.h"
|
||||
|
||||
#include <KComponentData>
|
||||
#include <KDirLister>
|
||||
#include <KFileItem>
|
||||
#include <KIO/NetAccess>
|
||||
#include <KIO/Job>
|
||||
#include <KUrl>
|
||||
#include <kdemacros.h>
|
||||
#include <ktemporaryfile.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QEventLoop>
|
||||
#include <QRegExp>
|
||||
|
||||
FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &pool, const QByteArray &app ) :
|
||||
SlaveBase("search", pool, app),
|
||||
m_checkContent(false),
|
||||
m_regExp(0),
|
||||
m_iteratedDirs()
|
||||
{
|
||||
}
|
||||
|
||||
FileNameSearchProtocol::~FileNameSearchProtocol()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void FileNameSearchProtocol::listDir(const QUrl& url)
|
||||
{
|
||||
cleanup();
|
||||
|
||||
const QString search = url.queryItemValue("search");
|
||||
if (!search.isEmpty()) {
|
||||
m_regExp = new QRegExp(search, Qt::CaseInsensitive, QRegExp::Wildcard);
|
||||
}
|
||||
|
||||
m_checkContent = false;
|
||||
const QString checkContent = url.queryItemValue("checkContent");
|
||||
if (checkContent == QLatin1String("yes")) {
|
||||
m_checkContent = true;
|
||||
}
|
||||
|
||||
const QString urlString = url.queryItemValue("url");
|
||||
searchDirectory(KUrl(urlString));
|
||||
|
||||
cleanup();
|
||||
finished();
|
||||
}
|
||||
|
||||
void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
||||
{
|
||||
if (directory.path() == QLatin1String("/proc")) {
|
||||
// Don't try to iterate the /proc directory of Linux
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all items of the directory
|
||||
KDirLister *dirLister = new KDirLister();
|
||||
dirLister->setDelayedMimeTypes(false);
|
||||
dirLister->setAutoErrorHandlingEnabled(false, 0);
|
||||
dirLister->openUrl(directory);
|
||||
|
||||
QEventLoop eventLoop;
|
||||
QObject::connect(dirLister, static_cast<void(KDirLister::*)()>(&KDirLister::canceled), &eventLoop, &QEventLoop::quit);
|
||||
QObject::connect(dirLister, static_cast<void(KDirLister::*)()>(&KDirLister::completed), &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.exec();
|
||||
|
||||
// Visualize all items that match the search pattern
|
||||
QList<KUrl> pendingDirs;
|
||||
const KFileItemList items = dirLister->items();
|
||||
foreach (const KFileItem& item, items) {
|
||||
bool addItem = false;
|
||||
if (!m_regExp || item.name().contains(*m_regExp)) {
|
||||
addItem = true;
|
||||
} else if (m_checkContent && item.determineMimeType().inherits(QLatin1String("text/plain"))) {
|
||||
addItem = contentContainsPattern(item.url());
|
||||
}
|
||||
|
||||
if (addItem) {
|
||||
KIO::UDSEntry entry = item.entry();
|
||||
entry.insert(KIO::UDSEntry::UDS_URL, item.url().url() );
|
||||
listEntry(entry,false);
|
||||
}
|
||||
|
||||
if (item.isDir()) {
|
||||
if (item.isLink()) {
|
||||
// Assure that no endless searching is done in directories that
|
||||
// have already been iterated.
|
||||
const KUrl linkDest(item.url(), item.linkDest());
|
||||
if (!m_iteratedDirs.contains(linkDest.path())) {
|
||||
pendingDirs.append(linkDest);
|
||||
}
|
||||
} else {
|
||||
pendingDirs.append(item.url());
|
||||
}
|
||||
}
|
||||
}
|
||||
listEntry(KIO::UDSEntry(), true);
|
||||
|
||||
m_iteratedDirs.insert(directory.path());
|
||||
|
||||
delete dirLister;
|
||||
dirLister = 0;
|
||||
|
||||
// Recursively iterate all sub directories
|
||||
foreach (const KUrl& pendingDir, pendingDirs) {
|
||||
searchDirectory(pendingDir);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileNameSearchProtocol::contentContainsPattern(const KUrl& fileName) const
|
||||
{
|
||||
Q_ASSERT(m_regExp);
|
||||
|
||||
QString path;
|
||||
KTemporaryFile tempFile;
|
||||
|
||||
if (fileName.isLocalFile()) {
|
||||
path = fileName.path();
|
||||
} else if (tempFile.open()) {
|
||||
KIO::Job* getJob = KIO::file_copy(fileName,
|
||||
tempFile.fileName(),
|
||||
-1,
|
||||
KIO::Overwrite | KIO::HideProgressInfo);
|
||||
if (!KIO::NetAccess::synchronousRun(getJob, 0)) {
|
||||
// The non-local file could not be downloaded
|
||||
return false;
|
||||
}
|
||||
path = tempFile.fileName();
|
||||
} else {
|
||||
// No temporary file could be created for downloading non-local files
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
const QString line = in.readLine();
|
||||
if (line.contains(*m_regExp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileNameSearchProtocol::cleanup()
|
||||
{
|
||||
delete m_regExp;
|
||||
m_regExp = 0;
|
||||
m_iteratedDirs.clear();
|
||||
}
|
||||
|
||||
extern "C" int KDE_EXPORT kdemain( int argc, char **argv )
|
||||
{
|
||||
KComponentData instance("kio_search");
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Usage: kio_filenamesearch protocol domain-socket1 domain-socket2\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
FileNameSearchProtocol slave(argv[2], argv[3]);
|
||||
slave.dispatchLoop();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef FILENAMESEARCHPROTOCOL_H
|
||||
#define FILENAMESEARCHPROTOCOL_H
|
||||
|
||||
#include <kio/slavebase.h>
|
||||
|
||||
class KUrl;
|
||||
class QRegExp;
|
||||
|
||||
/**
|
||||
* @brief Lists files where the filename matches do a given query.
|
||||
*
|
||||
* The query is defined as part of the "search" query item of the URL.
|
||||
* The directory where the searching is started is defined in the "url" query
|
||||
* item. If the query item "checkContent" is set to "yes", all files with
|
||||
* a text MIME type will be checked for the content.
|
||||
*/
|
||||
class FileNameSearchProtocol : public KIO::SlaveBase {
|
||||
public:
|
||||
FileNameSearchProtocol(const QByteArray& pool, const QByteArray& app);
|
||||
virtual ~FileNameSearchProtocol();
|
||||
|
||||
virtual void listDir(const QUrl& url) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void searchDirectory(const KUrl& directory);
|
||||
|
||||
/**
|
||||
* @return True, if the pattern m_searchPattern is part of
|
||||
* the file \a fileName.
|
||||
*/
|
||||
bool contentContainsPattern(const KUrl& fileName) const;
|
||||
|
||||
void cleanup();
|
||||
|
||||
bool m_checkContent;
|
||||
QRegExp* m_regExp;
|
||||
QSet<QString> m_iteratedDirs;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue