1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/* This file is part of the KDE Project
Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "remotedirnotify.h"
#include "../debug.h"
#include <klocale.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdesktopfile.h>
#include <kdirnotify.h>
#include <QtDBus/QtDBus>
RemoteDirNotify::RemoteDirNotify()
{
KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview");
const QString path = KGlobal::dirs()->saveLocation("remote_entries");
m_baseURL.setPath(path);
QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"),
QStringLiteral("FilesAdded"), this, SLOT(FilesAdded(QString)));
QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"),
QStringLiteral("FilesRemoved"), this, SLOT(FilesRemoved(QStringList)));
QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"),
QStringLiteral("FilesChanged"), this, SLOT(FilesChanged(QStringList)));
}
KUrl RemoteDirNotify::toRemoteURL(const KUrl &url)
{
qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::toRemoteURL(" << url << ")";
if ( m_baseURL.isParentOf(url) )
{
QString path = KUrl::relativePath(m_baseURL.path(),
url.path());
KUrl result("remote:/"+path);
result.cleanPath();
qCDebug(KIOREMOTE_LOG) << "result => " << result;
return result;
}
qCDebug(KIOREMOTE_LOG) << "result => KUrl()";
return KUrl();
}
KUrl::List RemoteDirNotify::toRemoteURLList(const KUrl::List &list)
{
KUrl::List new_list;
KUrl::List::const_iterator it = list.begin();
KUrl::List::const_iterator end = list.end();
for (; it!=end; ++it)
{
KUrl url = toRemoteURL(*it);
if (url.isValid())
{
new_list.append(url);
}
}
return new_list;
}
void RemoteDirNotify::FilesAdded(const QString &directory)
{
qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesAdded";
QUrl new_dir = toRemoteURL(directory);
if (new_dir.isValid())
{
org::kde::KDirNotify::emitFilesAdded(new_dir);
}
}
// This hack is required because of the way we manage .desktop files with
// Forwarding Slaves, their URL is out of the ioslave (most remote:/ files
// have a file:/ based UDS_URL so that they are executed correctly.
// Hence, FilesRemoved and FilesChanged does nothing... We're forced to use
// FilesAdded to re-list the modified directory.
inline void evil_hack(const KUrl::List &list)
{
KUrl::List notified;
KUrl::List::const_iterator it = list.begin();
KUrl::List::const_iterator end = list.end();
for (; it!=end; ++it)
{
QUrl url = (*it).upUrl();
if (!notified.contains(url))
{
org::kde::KDirNotify::emitFilesAdded(url);
notified.append(url);
}
}
}
void RemoteDirNotify::FilesRemoved(const QStringList &fileList)
{
qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesRemoved";
KUrl::List new_list = toRemoteURLList(fileList);
if (!new_list.isEmpty())
{
//KDirNotify_stub notifier("*", "*");
//notifier.FilesRemoved( new_list );
evil_hack(new_list);
}
}
void RemoteDirNotify::FilesChanged(const QStringList &fileList)
{
qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesChanged";
KUrl::List new_list = toRemoteURLList(fileList);
if (!new_list.isEmpty())
{
//KDirNotify_stub notifier("*", "*");
//notifier.FilesChanged( new_list );
evil_hack(new_list);
}
}
|