generic: adjust to KDirWatch changes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-21 00:26:44 +02:00
parent ea611115c4
commit 5ca5e4ea2d
19 changed files with 62 additions and 197 deletions

View file

@ -148,15 +148,11 @@ KateFileTemplates::KateFileTemplates( QObject* parent, const QList<QVariant> &du
const QStringList dirs = KGlobal::dirs()->findDirs("data", "kate/plugins/katefiletemplates/templates");
for ( QStringList::const_iterator it = dirs.begin(); it != dirs.end(); ++it )
{
m_dw->addDir( *it, KDirWatch::WatchFiles );
m_dw->addDir( *it );
}
connect( m_dw, SIGNAL(dirty(QString)),
this, SLOT(updateTemplateDirs(QString)) );
connect( m_dw, SIGNAL(created(QString)),
this, SLOT(updateTemplateDirs(QString)) );
connect( m_dw, SIGNAL(deleted(QString)),
this, SLOT(updateTemplateDirs(QString)) );
// m_templates.setAutoDelete( true );
updateTemplateDirs();

View file

@ -198,7 +198,7 @@ void PluginView::slotModifiedOnDisc( KTextEditor::Document* document, bool modif
case KTextEditor::ModificationInterface::OnDiskCreated:
tabbar->setTabIcon( tabID, KIconLoader::global()
->loadIcon( "document-save", KIconLoader::Small, 16 ) );
break;
break;
case KTextEditor::ModificationInterface::OnDiskDeleted:
tabbar->setTabIcon( tabID, KIconLoader::global()
->loadIcon( "dialog-warning", KIconLoader::Small, 16 ) );

View file

@ -183,12 +183,6 @@ KateDocument::KateDocument ( bool bSingleViewMode, bool bBrowserView,
connect( KateGlobal::self()->dirWatch(), SIGNAL(dirty(QString)),
this, SLOT(slotModOnHdDirty(QString)) );
connect( KateGlobal::self()->dirWatch(), SIGNAL(created(QString)),
this, SLOT(slotModOnHdCreated(QString)) );
connect( KateGlobal::self()->dirWatch(), SIGNAL(deleted(QString)),
this, SLOT(slotModOnHdDeleted(QString)) );
/**
* load handling
* this is needed to ensure we signal the user if a file ist still loading
@ -4363,36 +4357,6 @@ void KateDocument::slotModOnHdDirty (const QString &path)
}
}
void KateDocument::slotModOnHdCreated (const QString &path)
{
if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskCreated))
{
m_modOnHd = true;
m_modOnHdReason = OnDiskCreated;
// reenable dialog if not running atm
if (m_isasking == -1)
m_isasking = false;
emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
}
}
void KateDocument::slotModOnHdDeleted (const QString &path)
{
if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskDeleted))
{
m_modOnHd = true;
m_modOnHdReason = OnDiskDeleted;
// reenable dialog if not running atm
if (m_isasking == -1)
m_isasking = false;
emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
}
}
const QByteArray &KateDocument::digest () const
{
return m_buffer->digest();
@ -4427,13 +4391,10 @@ QString KateDocument::reasonedMOHString() const
{
case OnDiskModified:
return i18n("The file '%1' was modified by another program.", str );
break;
case OnDiskCreated:
return i18n("The file '%1' was created by another program.", str );
break;
case OnDiskDeleted:
return i18n("The file '%1' was deleted by another program.", str );
break;
default:
return QString();
}

View file

@ -904,8 +904,6 @@ Q_SIGNALS:
private Q_SLOTS:
void slotModOnHdDirty (const QString &path);
void slotModOnHdCreated (const QString &path);
void slotModOnHdDeleted (const QString &path);
private:
/**

View file

@ -100,14 +100,11 @@ KfindDlg::KfindDlg(const KUrl & url, QWidget *parent)
KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData(), true);
setButtonMenu( Help, helpMenu->menu() );
dirwatch=NULL;
}
KfindDlg::~KfindDlg()
{
stopSearch();
delete dirwatch;
}
void KfindDlg::finishAndClose()
@ -144,33 +141,6 @@ void KfindDlg::startSearch()
enableButton(User2, true); // Enable "Stop"
enableButton(User1, false); // Disable "Save As..."
delete dirwatch;
dirwatch=new KDirWatch();
connect(dirwatch, SIGNAL(created(QString)), this, SLOT(slotNewItems(QString)));
connect(dirwatch, SIGNAL(deleted(QString)), this, SLOT(slotDeleteItem(QString)));
dirwatch->addDir(query->url().path(), KDirWatch::WatchFiles);
#if 0
// waba: Watching for updates is disabled for now because even with FAM it causes too
// much problems. See BR68220, BR77854, BR77846, BR79512 and BR85802
// There are 3 problems:
// 1) addDir() keeps looping on recursive symlinks
// 2) addDir() scans all subdirectories, so it basically does the same as the process that
// is started by KQuery but in-process, undoing the advantages of using a separate find process
// A solution could be to let KQuery emit all the directories it has searched in.
// Either way, putting dirwatchers on a whole file system is probably just too much.
// 3) FAM has a tendency to deadlock with so many files (See BR77854) This has hopefully
// been fixed in KDirWatch, but that has not yet been confirmed.
//Getting a list of all subdirs
if(tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM))
{
const QStringList subdirs=getAllSubdirs(query->url().path());
for(QStringList::const_iterator it = subdirs.constBegin(); it != subdirs.constEnd(); ++it)
dirwatch->addDir(*it,true);
}
#endif
win->beginSearch(query->url());
tabWidget->beginSearch();
@ -258,32 +228,6 @@ void KfindDlg::about ()
dlg.exec ();
}
void KfindDlg::slotDeleteItem(const QString& file)
{
kDebug()<<QString("Will remove one item: %1").arg(file);
KUrl url;
url.setPath( file );
win->removeItem( url );
QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg( str );
}
void KfindDlg::slotNewItems( const QString& file )
{
kDebug()<<QString("Will add this item") << file;
if( file.indexOf(query->url().path(KUrl::AddTrailingSlash))==0 )
{
KUrl url;
url.setPath ( file );
if ( !win->isInserted( url ) )
query->slotListEntries( QStringList() << file );
}
}
QStringList KfindDlg::getAllSubdirs(QDir d)
{
QStringList dirs;

View file

@ -21,7 +21,6 @@
#include <kdialog.h>
#include <kdirlister.h>
#include <kdirwatch.h>
#include <QString>
#include <QDir>
@ -58,8 +57,6 @@ public Q_SLOTS:
void slotResult(int);
// void slotSearchDone();
void about ();
void slotDeleteItem(const QString&);
void slotNewItems( const QString& );
void finishAndClose();
@ -74,7 +71,6 @@ private:
bool isResultReported;
KQuery *query;
KStatusBar *mStatusBar;
KDirWatch *dirwatch;
};
#endif

View file

@ -44,7 +44,7 @@ Workspace::Workspace( QWidget* parent)
KAcceleratorManager::setNoAccel(this);
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
setDocumentMode(true);
connect(&mDirWatch, SIGNAL(deleted(QString)), this, SLOT(removeWorkSheet(QString)));
connect(&mDirWatch, SIGNAL(dirty(QString)), this, SLOT(maybeRemoveWorkSheet(QString)));
}
Workspace::~Workspace()
@ -143,20 +143,26 @@ void Workspace::newWorkSheet()
insertTab(-1, sheet, dlg.sheetTitle() );
mSheetList.append( sheet );
setCurrentIndex(indexOf( sheet ));
connect( sheet, SIGNAL(titleChanged(QWidget*)),
SLOT(updateSheetTitle(QWidget*)));
connect( sheet, SIGNAL(titleChanged(QWidget*)), SLOT(updateSheetTitle(QWidget*)));
}
}
void Workspace::contextMenu (int index, const QPoint &point) {
// KMenu pm;
void Workspace::contextMenu (int index, const QPoint &point)
{
// KMenu pm;
Q_UNUSED(index);
Q_UNUSED(point);
// QAction *new_worksheet = pm.addAction( Toplevel->actionCollection()->action("new_worksheet") );
// QAction *action = pm.exec( point );
// QAction *new_worksheet = pm.addAction( Toplevel->actionCollection()->action("new_worksheet") );
// QAction *action = pm.exec( point );
}
void Workspace::maybeRemoveWorkSheet( const QString &fileName )
{
if (!QFile::exists(fileName)) {
removeWorkSheet(fileName);
}
}
void Workspace::updateSheetTitle( QWidget* wdg )
{
if ( wdg )
@ -239,7 +245,7 @@ void Workspace::exportWorkSheet( WorkSheet *sheet )
QString fileName;
do {
fileName = KFileDialog::getSaveFileName( QString(tabText(indexOf( currentWidget() ))+ ".sgrd"),
QLatin1String("*.sgrd"), this, i18n("Export Tab") );
QLatin1String("*.sgrd"), this, i18n("Export Tab") );
if ( fileName.isEmpty() )
return;

View file

@ -22,12 +22,12 @@
#ifndef KSG_WORKSPACE_H
#define KSG_WORKSPACE_H
#include <QString>
#include <KTabWidget>
#include <kdirwatch.h>
class KConfig;
class KUrl;
#include <QString>
class WorkSheet;
class Workspace : public KTabWidget
@ -67,6 +67,7 @@ class Workspace : public KTabWidget
private Q_SLOTS:
virtual void contextMenu (int, const QPoint &);
void maybeRemoveWorkSheet( const QString &fileName );
Q_SIGNALS:
void setCaption( const QString &text);

View file

@ -128,8 +128,6 @@ TaskManager::TaskManager()
d->watcher = new KDirWatch(this);
d->watcher->addFile(KGlobal::dirs()->locateLocal("config", "klaunchrc"));
connect(d->watcher, SIGNAL(dirty(QString)), this, SLOT(configureStartup()));
connect(d->watcher, SIGNAL(created(QString)), this, SLOT(configureStartup()));
connect(d->watcher, SIGNAL(deleted(QString)), this, SLOT(configureStartup()));
configureStartup();
}

View file

@ -155,7 +155,7 @@ void IconApplet::setUrl(const KUrl& url, bool fromConfigDialog)
if (m_url.isLocalFile()) {
m_watcher = new KDirWatch;
m_watcher->addFile(m_url.toLocalFile());
connect(m_watcher, SIGNAL(deleted(QString)), this, SLOT(delayedDestroy()));
connect(m_watcher, SIGNAL(dirty(QString)), this, SLOT(delayedDestroy()));
QFileInfo fi(m_url.toLocalFile());
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, m_url.toLocalFile());

View file

@ -163,9 +163,8 @@ RecentlyUsedModel::RecentlyUsedModel(QObject *parent, RecentType recenttype, int
// listen for changes to the list of recent documents
KDirWatch *recentDocWatch = new KDirWatch(this);
recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory(), KDirWatch::WatchFiles);
connect(recentDocWatch, SIGNAL(created(QString)), this, SLOT(recentDocumentAdded(QString)));
connect(recentDocWatch, SIGNAL(deleted(QString)), this, SLOT(recentDocumentRemoved(QString)));
recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory());
connect(recentDocWatch, SIGNAL(dirty(QString)), this, SLOT(recentDocumentDirty(QString)));
}
}
@ -219,15 +218,20 @@ DisplayOrder RecentlyUsedModel::nameDisplayOrder() const
return d->displayOrder;
}
void RecentlyUsedModel::recentDocumentAdded(const QString& path)
void RecentlyUsedModel::recentDocumentDirty(const QString& path)
{
kDebug() << "Recent document added" << path;
d->addRecentDocument(path, false);
}
void RecentlyUsedModel::recentDocumentRemoved(const QString& path)
{
kDebug() << "Recent document removed" << path;
d->removeExistingItem(path);
kDebug() << "Recent document dirty" << path;
d->itemsByPath.clear();
clear();
if (d->recenttype != DocumentsOnly) {
d->loadRecentApplications();
}
if (d->recenttype != ApplicationsOnly) {
d->loadRecentDocuments();
}
}
void RecentlyUsedModel::recentApplicationAdded(KService::Ptr service, int)

View file

@ -61,8 +61,7 @@ public Q_SLOTS:
void clearRecentDocumentsAndApplications();
private Q_SLOTS:
void recentDocumentAdded(const QString& path);
void recentDocumentRemoved(const QString& path);
void recentDocumentDirty(const QString& path);
void recentApplicationAdded(KService::Ptr, int startCount);
void recentApplicationRemoved(KService::Ptr);
void recentApplicationsCleared();

View file

@ -36,12 +36,10 @@ FileBrowserEngine::FileBrowserEngine(QObject* parent, const QVariantList& args)
Q_UNUSED(args)
m_dirWatch = new KDirWatch(this);
connect(m_dirWatch, SIGNAL(created(
const QString &)), this, SLOT(dirCreated(QString)));
connect(m_dirWatch, SIGNAL(deleted(
const QString &)), this, SLOT(dirDeleted(QString)));
connect(m_dirWatch, SIGNAL(dirty(
const QString &)), this, SLOT(dirDirty(QString)));
connect(
m_dirWatch, SIGNAL(dirty(QString)),
this, SLOT(updateData(QString))
);
}
FileBrowserEngine::~FileBrowserEngine()
@ -59,29 +57,12 @@ bool FileBrowserEngine::sourceRequestEvent(const QString &path)
kDebug() << "source requested() called: "<< path;
m_dirWatch->addDir(path);
setData(path, "type", QVariant("unknown"));
updateData (path, INIT);
updateData(path);
return true;
}
void FileBrowserEngine::dirDirty(const QString &path)
void FileBrowserEngine::updateData(const QString &path)
{
updateData(path, DIRTY);
}
void FileBrowserEngine::dirCreated(const QString &path)
{
updateData(path, CREATED);
}
void FileBrowserEngine::dirDeleted(const QString &path)
{
updateData(path, DELETED);
}
void FileBrowserEngine::updateData(const QString &path, EventType event)
{
Q_UNUSED(event)
ObjectType type = NOTHING;
if (QDir(path).exists()) {
type = DIRECTORY;

View file

@ -40,16 +40,13 @@ protected:
void init();
protected slots:
void dirDirty (const QString &path);
void dirCreated(const QString &path);
void dirDeleted(const QString &path);
void dirDirty(const QString &path);
private:
enum EventType {INIT, DIRTY, CREATED, DELETED};
enum ObjectType {NOTHING, FILE, DIRECTORY};
enum ObjectType { NOTHING, FILE, DIRECTORY };
KDirWatch * m_dirWatch;
void updateData(const QString &path, EventType event);
void updateData(const QString &path);
void clearData(const QString &path);
//QMap < QString, QStringList > m_regiteredListeners;

View file

@ -47,7 +47,7 @@ HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& args)
{
QStringList folders = KGlobal::dirs()->findDirs("data", "solid/actions/");
foreach (const QString &folder, folders) {
m_dirWatch->addDir(folder, KDirWatch::WatchFiles);
m_dirWatch->addDir(folder);
}
connect(m_dirWatch, SIGNAL(dirty(QString)), this, SLOT(updatePredicates(QString)));
}

View file

@ -39,9 +39,7 @@ RecentDocuments::RecentDocuments(QObject *parent, const QVariantList& args)
loadRecentDocuments();
// listen for changes to the list of recent documents
KDirWatch *recentDocWatch = new KDirWatch(this);
recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory(), KDirWatch::WatchFiles);
connect(recentDocWatch,SIGNAL(created(QString)),this,SLOT(loadRecentDocuments()));
connect(recentDocWatch,SIGNAL(deleted(QString)),this,SLOT(loadRecentDocuments()));
recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory());
connect(recentDocWatch,SIGNAL(dirty(QString)),this,SLOT(loadRecentDocuments()));
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Looks for documents recently used with names matching :q:.")));
}

View file

@ -46,7 +46,7 @@ BackgroundListModel::BackgroundListModel(Image *listener, QObject *parent)
m_size(0,0),
m_resizeMethod(Plasma::Wallpaper::ScaledResize)
{
connect(&m_dirwatch, SIGNAL(deleted(QString)), this, SLOT(removeBackground(QString)));
connect(&m_dirwatch, SIGNAL(dirty(QString)), this, SLOT(reload()));
m_previewUnavailablePix.fill(Qt::transparent);
//m_previewUnavailablePix = KIcon("unknown").pixmap(m_previewUnavailablePix.size());
}
@ -56,20 +56,6 @@ BackgroundListModel::~BackgroundListModel()
qDeleteAll(m_packages);
}
void BackgroundListModel::removeBackground(const QString &path)
{
QModelIndex index;
while ((index = indexOf(path)).isValid()) {
beginRemoveRows(QModelIndex(), index.row(), index.row());
Plasma::Package *package = m_packages.at(index.row());
m_packages.removeAt(index.row());
m_sizeCache.remove(package);
m_previews.remove(package);
delete package;
endRemoveRows();
}
}
void BackgroundListModel::reload()
{
reload(QStringList());
@ -96,6 +82,12 @@ void BackgroundListModel::reload(const QStringList &selected)
const QStringList dirs = KGlobal::dirs()->findDirs("wallpaper", "");
kDebug() << "going looking in" << dirs;
// add wallpaper dirs to dirwatch (recursively)
foreach (const QString &dir, dirs) {
m_dirwatch.addDir(dir);
}
BackgroundFinder *finder = new BackgroundFinder(m_structureParent.data(), dirs);
connect(finder, SIGNAL(backgroundsFound(QStringList)), this, SLOT(processPaths(QStringList)));
finder->start();
@ -120,13 +112,6 @@ void BackgroundListModel::processPaths(const QStringList &paths)
}
}
// add new files to dirwatch
foreach (Plasma::Package *b, newPackages) {
if (!m_dirwatch.contains(b->path())) {
m_dirwatch.addFile(b->path());
}
}
if (!newPackages.isEmpty()) {
const int start = rowCount();
beginInsertRows(QModelIndex(), start, start + newPackages.size());
@ -195,8 +180,7 @@ QSize BackgroundListModel::bestSize(Plasma::Package *package) const
QSize size(-1, -1);
m_sizeCache.insert(package, size);
ImageSizeFinder *finder = new ImageSizeFinder(image, const_cast<BackgroundListModel *>(this));
connect(finder, SIGNAL(sizeFound(QString,QSize)), this,
SLOT(sizeFound(QString,QSize)));
connect(finder, SIGNAL(sizeFound(QString,QSize)), this, SLOT(sizeFound(QString,QSize)));
finder->start();
return size;
}

View file

@ -56,7 +56,6 @@ public:
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Plasma::Package *package(int index) const;
void reload();
void reload(const QStringList &selected);
void addBackground(const QString &path);
QModelIndex indexOf(const QString &path) const;
@ -66,7 +65,7 @@ public:
void setResizeMethod(Plasma::Wallpaper::ResizeMethod resizeMethod);
protected Q_SLOTS:
void removeBackground(const QString &path);
void reload();
void showPreview(const KFileItem &item, const QPixmap &preview);
void previewFailed(const KFileItem &item);
void sizeFound(const QString &path, const QSize &s);

View file

@ -399,9 +399,12 @@ void Image::updateDirWatch(const QStringList &newDirs)
if (!m_dirWatch) {
m_dirWatch = new KDirWatch(this);
connect(m_dirWatch, SIGNAL(created(QString)), SLOT(pathCreated(QString)));
connect(m_dirWatch, SIGNAL(dirty(QString)), SLOT(pathDirty(QString)));
#warning FIXME: update the whole list on dirty() signal
#if 0
connect(m_dirWatch, SIGNAL(created(QString)), SLOT(pathCreated(QString)));
connect(m_dirWatch, SIGNAL(deleted(QString)), SLOT(pathDeleted(QString)));
#endif
}
foreach (const QString &oldDir, m_dirs) {
@ -412,7 +415,7 @@ void Image::updateDirWatch(const QStringList &newDirs)
foreach (const QString &newDir, newDirs) {
if (!m_dirWatch->contains(newDir)) {
m_dirWatch->addDir(newDir, KDirWatch::WatchSubDirs | KDirWatch::WatchFiles);
m_dirWatch->addDir(newDir);
}
}