add more spacing
[personal-kdebase.git] / runtime / kioslave / remote / kdedmodule / remotedirnotify.cpp
blob99f962a01c04b6a0f040fcb6227ed88bd0d93ba5
1 /* This file is part of the KDE Project
2 Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "remotedirnotify.h"
21 #include <kdebug.h>
22 #include <klocale.h>
23 #include <kglobal.h>
24 #include <kstandarddirs.h>
25 #include <kdesktopfile.h>
26 #include <kdirnotify.h>
28 #include <QtDBus/QtDBus>
29 #include <QDir>
31 RemoteDirNotify::RemoteDirNotify()
33 KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview");
35 QString path = KGlobal::dirs()->saveLocation("remote_entries");
36 m_baseURL.setPath(path);
38 QDBusConnection::sessionBus().connect(QString(), QString(), "org.kde.KDirNotify",
39 "FilesAdded", this, SLOT(FilesAdded(QString))); QDBusConnection::sessionBus().connect(QString(), QString(), "org.kde.KDirNotify",
40 "FilesRemoved", this, SLOT(FilesRemoved(QStringList))); QDBusConnection::sessionBus().connect(QString(), QString(), "org.kde.KDirNotify",
41 "FilesChanged", this, SLOT(FilesChanged(QStringList)));
44 KUrl RemoteDirNotify::toRemoteURL(const KUrl &url)
46 kDebug(1220) << "RemoteDirNotify::toRemoteURL(" << url << ")";
47 if ( m_baseURL.isParentOf(url) )
49 QString path = KUrl::relativePath(m_baseURL.path(),
50 url.path());
51 KUrl result("remote:/"+path);
52 result.cleanPath();
53 kDebug(1220) << "result => " << result;
54 return result;
57 kDebug(1220) << "result => KUrl()";
58 return KUrl();
61 KUrl::List RemoteDirNotify::toRemoteURLList(const KUrl::List &list)
63 KUrl::List new_list;
65 KUrl::List::const_iterator it = list.begin();
66 KUrl::List::const_iterator end = list.end();
68 for (; it!=end; ++it)
70 KUrl url = toRemoteURL(*it);
72 if (url.isValid())
74 new_list.append(url);
78 return new_list;
81 void RemoteDirNotify::FilesAdded(const QString &directory)
83 kDebug(1220) << "RemoteDirNotify::FilesAdded";
85 KUrl new_dir = toRemoteURL(directory);
87 if (new_dir.isValid())
89 org::kde::KDirNotify::emitFilesAdded( new_dir.url() );
93 // This hack is required because of the way we manage .desktop files with
94 // Forwarding Slaves, their URL is out of the ioslave (most remote:/ files
95 // have a file:/ based UDS_URL so that they are executed correctly.
96 // Hence, FilesRemoved and FilesChanged does nothing... We're forced to use
97 // FilesAdded to re-list the modified directory.
98 inline void evil_hack(const KUrl::List &list)
100 KUrl::List notified;
102 KUrl::List::const_iterator it = list.begin();
103 KUrl::List::const_iterator end = list.end();
105 for (; it!=end; ++it)
107 KUrl url = (*it).upUrl();
109 if (!notified.contains(url))
111 org::kde::KDirNotify::emitFilesAdded(url.url());
112 notified.append(url);
118 void RemoteDirNotify::FilesRemoved(const QStringList &fileList)
120 kDebug(1220) << "RemoteDirNotify::FilesRemoved";
122 KUrl::List new_list = toRemoteURLList(fileList);
124 if (!new_list.isEmpty())
126 //KDirNotify_stub notifier("*", "*");
127 //notifier.FilesRemoved( new_list );
128 evil_hack(new_list);
132 void RemoteDirNotify::FilesChanged(const QStringList &fileList)
134 kDebug(1220) << "RemoteDirNotify::FilesChanged";
136 KUrl::List new_list = toRemoteURLList(fileList);
138 if (!new_list.isEmpty())
140 //KDirNotify_stub notifier("*", "*");
141 //notifier.FilesChanged( new_list );
142 evil_hack(new_list);
146 #include "remotedirnotify.moc"