summaryrefslogtreecommitdiffstats
path: root/kioslave/remote
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/remote
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kioslave/remote')
-rw-r--r--kioslave/remote/Makefile.am32
-rw-r--r--kioslave/remote/dummy.cpp1
-rw-r--r--kioslave/remote/kdedmodule/Makefile.am13
-rw-r--r--kioslave/remote/kdedmodule/remotedirnotify.cpp143
-rw-r--r--kioslave/remote/kdedmodule/remotedirnotify.desktop64
-rw-r--r--kioslave/remote/kdedmodule/remotedirnotify.h43
-rw-r--r--kioslave/remote/kdedmodule/remotedirnotifymodule.cpp37
-rw-r--r--kioslave/remote/kdedmodule/remotedirnotifymodule.h36
-rw-r--r--kioslave/remote/kio_remote.cpp234
-rw-r--r--kioslave/remote/kio_remote.h45
-rw-r--r--kioslave/remote/remote.protocol17
-rw-r--r--kioslave/remote/remoteimpl.cpp298
-rw-r--r--kioslave/remote/remoteimpl.h54
-rw-r--r--kioslave/remote/testremote.cpp69
-rw-r--r--kioslave/remote/testremote.h34
15 files changed, 1120 insertions, 0 deletions
diff --git a/kioslave/remote/Makefile.am b/kioslave/remote/Makefile.am
new file mode 100644
index 000000000..073bfd12e
--- /dev/null
+++ b/kioslave/remote/Makefile.am
@@ -0,0 +1,32 @@
+SUBDIRS= . kdedmodule
+# wizard
+
+INCLUDES = $(all_includes)
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = kio_remote.la
+
+kio_remote_la_SOURCES = dummy.cpp
+kio_remote_la_LIBADD = libkioremote.la $(LIB_KIO)
+kio_remote_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined
+
+dummy.cpp:
+ echo > dummy.cpp
+
+kde_services_DATA = remote.protocol
+
+noinst_LTLIBRARIES = libkioremote.la
+libkioremote_la_SOURCES = kio_remote.cpp remoteimpl.cpp
+
+check_PROGRAMS = testremote
+testremote_SOURCES = testremote.cpp
+testremote_LDADD = libkioremote.la $(LIB_KIO)
+testremote_LDFLAGS = $(all_libraries)
+
+## TODO in unsermake: TESTS = testremote
+check: testremote
+ ./testremote
+
+messages:
+ $(XGETTEXT) `find . -name "*.cc" -o -name "*.cpp" -o -name "*.h"` -o $(podir)/kio_remote.pot
+
diff --git a/kioslave/remote/dummy.cpp b/kioslave/remote/dummy.cpp
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/kioslave/remote/dummy.cpp
@@ -0,0 +1 @@
+
diff --git a/kioslave/remote/kdedmodule/Makefile.am b/kioslave/remote/kdedmodule/Makefile.am
new file mode 100644
index 000000000..61f4d2261
--- /dev/null
+++ b/kioslave/remote/kdedmodule/Makefile.am
@@ -0,0 +1,13 @@
+kde_module_LTLIBRARIES = kded_remotedirnotify.la
+
+METASOURCES = AUTO
+INCLUDES = $(all_includes)
+
+kded_remotedirnotify_la_SOURCES = remotedirnotify.cpp remotedirnotify.skel remotedirnotifymodule.cpp remotedirnotifymodule.skel
+kded_remotedirnotify_la_LDFLAGS = $(all_libraries) -module -avoid-version
+kded_remotedirnotify_la_LIBADD = $(LIB_KSYCOCA)
+
+
+servicesdir = $(kde_servicesdir)/kded
+services_DATA = remotedirnotify.desktop
+
diff --git a/kioslave/remote/kdedmodule/remotedirnotify.cpp b/kioslave/remote/kdedmodule/remotedirnotify.cpp
new file mode 100644
index 000000000..88933e29a
--- /dev/null
+++ b/kioslave/remote/kdedmodule/remotedirnotify.cpp
@@ -0,0 +1,143 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 Kvin 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 <kdebug.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <kdesktopfile.h>
+
+#include <kdirnotify_stub.h>
+
+#include <qdir.h>
+
+RemoteDirNotify::RemoteDirNotify()
+{
+ KGlobal::dirs()->addResourceType("remote_entries",
+ KStandardDirs::kde_default("data") + "remoteview");
+
+ QString path = KGlobal::dirs()->saveLocation("remote_entries");
+ m_baseURL.setPath(path);
+}
+
+KURL RemoteDirNotify::toRemoteURL(const KURL &url)
+{
+ kdDebug(1220) << "RemoteDirNotify::toRemoteURL(" << url << ")" << endl;
+ if ( m_baseURL.isParentOf(url) )
+ {
+ QString path = KURL::relativePath(m_baseURL.path(),
+ url.path());
+ KURL result("remote:/"+path);
+ result.cleanPath();
+ kdDebug(1220) << "result => " << result << endl;
+ return result;
+ }
+
+ kdDebug(1220) << "result => KURL()" << endl;
+ 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;
+}
+
+ASYNC RemoteDirNotify::FilesAdded(const KURL &directory)
+{
+ kdDebug(1220) << "RemoteDirNotify::FilesAdded" << endl;
+
+ KURL new_dir = toRemoteURL(directory);
+
+ if (new_dir.isValid())
+ {
+ KDirNotify_stub notifier("*", "*");
+ notifier.FilesAdded( 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)
+{
+ KDirNotify_stub notifier("*", "*");
+
+ KURL::List notified;
+
+ KURL::List::const_iterator it = list.begin();
+ KURL::List::const_iterator end = list.end();
+
+ for (; it!=end; ++it)
+ {
+ KURL url = (*it).upURL();
+
+ if (!notified.contains(url))
+ {
+ notifier.FilesAdded(url);
+ notified.append(url);
+ }
+ }
+}
+
+
+ASYNC RemoteDirNotify::FilesRemoved(const KURL::List &fileList)
+{
+ kdDebug(1220) << "RemoteDirNotify::FilesRemoved" << endl;
+
+ KURL::List new_list = toRemoteURLList(fileList);
+
+ if (!new_list.isEmpty())
+ {
+ //KDirNotify_stub notifier("*", "*");
+ //notifier.FilesRemoved( new_list );
+ evil_hack(new_list);
+ }
+}
+
+ASYNC RemoteDirNotify::FilesChanged(const KURL::List &fileList)
+{
+ kdDebug(1220) << "RemoteDirNotify::FilesChanged" << endl;
+
+ KURL::List new_list = toRemoteURLList(fileList);
+
+ if (!new_list.isEmpty())
+ {
+ //KDirNotify_stub notifier("*", "*");
+ //notifier.FilesChanged( new_list );
+ evil_hack(new_list);
+ }
+}
diff --git a/kioslave/remote/kdedmodule/remotedirnotify.desktop b/kioslave/remote/kdedmodule/remotedirnotify.desktop
new file mode 100644
index 000000000..cbae89366
--- /dev/null
+++ b/kioslave/remote/kdedmodule/remotedirnotify.desktop
@@ -0,0 +1,64 @@
+[Desktop Entry]
+Type=Service
+Name=KDED Remote Base URL Notifier
+Name[af]=KDED afgeleë URL inkennissteller
+Name[be]=Праверка зменаў аддаленых файлаў KDED
+Name[bs]=KDED udaljeno obavještenje o baznom URLu
+Name[ca]=Notificador d'URL de base remota KDED
+Name[cs]=Démon upozorňování na vzdálená URL
+Name[csb]=Dôwanié wiédzë ò daleczich URL-ach dlô KDED
+Name[da]=KDED Ekstern basis-URL påmindelser
+Name[de]=Überwachung für Dateien auf Fremdrechnern
+Name[el]=Ειδοποιητής KDED για απομακρυσμένη URL
+Name[eo]=KDED Fora Bazo URL Atentigilo
+Name[es]=Notificador de URL remota KDED
+Name[et]=KDED mujalasuva URL-i teadustaja
+Name[eu]=KDED urruneko URL oinarriaren iragarlea
+Name[fa]=اخطاردهندۀ نشانی وب پایه دور KDED
+Name[fi]=KDED:in etäverkko-osoitteen ilmaisin
+Name[fr]=Notificateur d'URL distante KDED
+Name[fy]=KDED ekstern basis-URL-adres melding
+Name[gl]=KDED Notificador de Base de URL Remota
+Name[hi]=केडीईडी रिमोट आधारित यूआरएल नोटिफ़ायर
+Name[hr]=KDED URL obavještavanje udaljene baze
+Name[hu]=Távoli alapcím-értesítő
+Name[is]=KDED fjarlægur grunnslóðartilkynnari
+Name[it]=Notifica KDED Remote Base URL
+Name[ja]=KDED リモート ベース URL 通知
+Name[kk]=Желідегі дискідегі өзгеріс туралы қулақтандыру
+Name[ko]=KDED 원격 기반 URL 알리미
+Name[lt]=KDED nutolusio pagrindinio URL priminiklis
+Name[lv]=KDED attālinātā URL bāzes atgādinātājs
+Name[ms]=Pemberitahu URL Pangkalan Jauh KDED
+Name[nb]=KDED-påminner for eksterne nettadresser
+Name[nds]=KDED-Narichten för feern Basis-URLs
+Name[ne]=KDED रिमोटमा आधारित यूआरएल सूचक
+Name[nl]=KDED extern basis-URL-adres notificatie
+Name[nn]=KDED-påminnar for eksterne nettadressar
+Name[pa]=KDED ਰਿਮੋਟ ਅਧਾਰਿਤ URL ਸੂਚਨਾ
+Name[pl]=Powiadamianie o zdalnych URL-ach dla KDED
+Name[pt]=Notificador de URLs de Base Remotos do KDED
+Name[pt_BR]=Serviço de Notificação da URL Remota
+Name[ro]=Notificare KDED pentru URL distant de bază
+Name[ru]=Проверка изменения сетевых файлов
+Name[rw]=Mumenyekanisha wa URL KDED Yakure Shingiro
+Name[sk]=KDED notifikátor vzdialenej URL
+Name[sl]=Obvestilnik KDED oddaljenega osnovnega URL-ja
+Name[sr]=Обавештавач о удаљеном базном URL-у, KDED
+Name[sr@Latn]=Obaveštavač o udaljenom baznom URL-u, KDED
+Name[sv]=KDED-meddelande om fjärrbaswebbadresser
+Name[ta]=KDED தொலைதூரம் சார்ந்த வலைமனை குறிப்பான்
+Name[th]=ตัวแจ้งเตือน Remote Base URL KDED
+Name[tr]=KDED Uzak Tabanlı URL Hatırlatıcı
+Name[tt]=Çittäge URL Üzgärelü Beldergeçe
+Name[uk]=Сповіщувач про віддалену основну адресу (URL) для KDED
+Name[vi]=Trình thông báo URL trên mạng KDED
+Name[wa]=Notifiaedje KDED d' URL di båze å lon
+Name[zh_CN]=KDED 远程基 URL 通知器
+Name[zh_TW]=KDED 遠端基礎 URL 通知程式
+ServiceTypes=KDEDModule
+X-KDE-ModuleType=Library
+X-KDE-Library=remotedirnotify
+X-KDE-FactoryName=remotedirnotify
+X-KDE-Kded-load-on-demand=true
+X-KDE-Kded-autoload=true
diff --git a/kioslave/remote/kdedmodule/remotedirnotify.h b/kioslave/remote/kdedmodule/remotedirnotify.h
new file mode 100644
index 000000000..110d53a9d
--- /dev/null
+++ b/kioslave/remote/kdedmodule/remotedirnotify.h
@@ -0,0 +1,43 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 Kvin 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.
+*/
+
+#ifndef REMOTEDIRNOTIFY_H
+#define REMOTEDIRNOTIFY_H
+
+#include <kurl.h>
+#include <kdirnotify.h>
+
+class RemoteDirNotify : public KDirNotify
+{
+K_DCOP
+
+public:
+ RemoteDirNotify();
+
+k_dcop:
+ virtual ASYNC FilesAdded (const KURL &directory);
+ virtual ASYNC FilesRemoved (const KURL::List &fileList);
+ virtual ASYNC FilesChanged (const KURL::List &fileList);
+
+private:
+ KURL toRemoteURL(const KURL &url);
+ KURL::List toRemoteURLList(const KURL::List &list);
+ KURL m_baseURL;
+};
+
+#endif
diff --git a/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp
new file mode 100644
index 000000000..5877ac299
--- /dev/null
+++ b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp
@@ -0,0 +1,37 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 Kvin 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 "remotedirnotifymodule.h"
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+RemoteDirNotifyModule::RemoteDirNotifyModule(const QCString &obj)
+ : KDEDModule(obj)
+{
+}
+
+extern "C" {
+ KDE_EXPORT KDEDModule *create_remotedirnotify(const QCString &obj)
+ {
+ KGlobal::locale()->insertCatalogue("kio_remote");
+ return new RemoteDirNotifyModule(obj);
+ }
+}
+
diff --git a/kioslave/remote/kdedmodule/remotedirnotifymodule.h b/kioslave/remote/kdedmodule/remotedirnotifymodule.h
new file mode 100644
index 000000000..4ce8c2c7d
--- /dev/null
+++ b/kioslave/remote/kdedmodule/remotedirnotifymodule.h
@@ -0,0 +1,36 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 Kvin 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.
+*/
+
+#ifndef REMOTEDIRNOTIFYMODULE_H
+#define REMOTEDIRNOTIFYMODULE_H
+
+#include <kdedmodule.h>
+
+#include "remotedirnotify.h"
+
+class RemoteDirNotifyModule : public KDEDModule
+{
+K_DCOP
+
+public:
+ RemoteDirNotifyModule(const QCString &obj);
+private:
+ RemoteDirNotify notifier;
+};
+
+#endif
diff --git a/kioslave/remote/kio_remote.cpp b/kioslave/remote/kio_remote.cpp
new file mode 100644
index 000000000..1200f943c
--- /dev/null
+++ b/kioslave/remote/kio_remote.cpp
@@ -0,0 +1,234 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kevin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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 <stdlib.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <dcopclient.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+
+
+#include "kio_remote.h"
+
+static const KCmdLineOptions options[] =
+{
+ { "+protocol", I18N_NOOP( "Protocol name" ), 0 },
+ { "+pool", I18N_NOOP( "Socket name" ), 0 },
+ { "+app", I18N_NOOP( "Socket name" ), 0 },
+ KCmdLineLastOption
+};
+
+extern "C" {
+ int KDE_EXPORT kdemain( int argc, char **argv )
+ {
+ // KApplication is necessary to use other ioslaves
+ putenv(strdup("SESSION_MANAGER="));
+ KCmdLineArgs::init(argc, argv, "kio_remote", 0, 0, 0, 0);
+ KCmdLineArgs::addCmdLineOptions( options );
+ KApplication app( false, false );
+ // We want to be anonymous even if we use DCOP
+ app.dcopClient()->attach();
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ RemoteProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
+ slave.dispatchLoop();
+ return 0;
+ }
+}
+
+
+RemoteProtocol::RemoteProtocol(const QCString &protocol,
+ const QCString &pool, const QCString &app)
+ : SlaveBase(protocol, pool, app)
+{
+}
+
+RemoteProtocol::~RemoteProtocol()
+{
+}
+
+void RemoteProtocol::listDir(const KURL &url)
+{
+ kdDebug(1220) << "RemoteProtocol::listDir: " << url << endl;
+
+ if ( url.path().length() <= 1 )
+ {
+ listRoot();
+ return;
+ }
+
+ int second_slash_idx = url.path().find( '/', 1 );
+ QString root_dirname = url.path().mid( 1, second_slash_idx-1 );
+
+ KURL target = m_impl.findBaseURL( root_dirname );
+ kdDebug(1220) << "possible redirection target : " << target << endl;
+ if( target.isValid() )
+ {
+ target.addPath( url.path().remove(0, second_slash_idx) );
+ redirection(target);
+ finished();
+ return;
+ }
+
+ error(KIO::ERR_MALFORMED_URL, url.prettyURL());
+}
+
+void RemoteProtocol::listRoot()
+{
+ KIO::UDSEntry entry;
+
+ KIO::UDSEntryList remote_entries;
+ m_impl.listRoot(remote_entries);
+
+ totalSize(remote_entries.count()+2);
+
+ m_impl.createTopLevelEntry(entry);
+ listEntry(entry, false);
+
+ m_impl.createWizardEntry(entry);
+ listEntry(entry, false);
+
+ KIO::UDSEntryListIterator it = remote_entries.begin();
+ KIO::UDSEntryListIterator end = remote_entries.end();
+
+ for(; it!=end; ++it)
+ {
+ listEntry(*it, false);
+ }
+
+ entry.clear();
+ listEntry(entry, true);
+
+ finished();
+}
+
+void RemoteProtocol::stat(const KURL &url)
+{
+ kdDebug(1220) << "RemoteProtocol::stat: " << url << endl;
+
+ QString path = url.path();
+ if ( path.isEmpty() || path == "/" )
+ {
+ // The root is "virtual" - it's not a single physical directory
+ KIO::UDSEntry entry;
+ m_impl.createTopLevelEntry( entry );
+ statEntry( entry );
+ finished();
+ return;
+ }
+
+ if (m_impl.isWizardURL(url))
+ {
+ KIO::UDSEntry entry;
+ if (m_impl.createWizardEntry(entry))
+ {
+ statEntry(entry);
+ finished();
+ }
+ else
+ {
+ error(KIO::ERR_DOES_NOT_EXIST, url.prettyURL());
+ }
+ return;
+ }
+
+ int second_slash_idx = url.path().find( '/', 1 );
+ QString root_dirname = url.path().mid( 1, second_slash_idx-1 );
+
+ if ( second_slash_idx==-1 || ( (int)url.path().length() )==second_slash_idx+1 )
+ {
+ KIO::UDSEntry entry;
+ if (m_impl.statNetworkFolder(entry, root_dirname))
+ {
+ statEntry(entry);
+ finished();
+ return;
+ }
+ }
+ else
+ {
+ KURL target = m_impl.findBaseURL( root_dirname );
+ kdDebug( 1220 ) << "possible redirection target : " << target << endl;
+ if ( target.isValid() )
+ {
+ target.addPath( url.path().remove( 0, second_slash_idx ) );
+ redirection( target );
+ finished();
+ return;
+ }
+ }
+
+ error(KIO::ERR_MALFORMED_URL, url.prettyURL());
+}
+
+void RemoteProtocol::del(const KURL &url, bool /*isFile*/)
+{
+ kdDebug(1220) << "RemoteProtocol::del: " << url << endl;
+
+ if (!m_impl.isWizardURL(url)
+ && m_impl.deleteNetworkFolder(url.fileName()))
+ {
+ finished();
+ return;
+ }
+
+ error(KIO::ERR_CANNOT_DELETE, url.prettyURL());
+}
+
+void RemoteProtocol::get(const KURL &url)
+{
+ kdDebug(1220) << "RemoteProtocol::get: " << url << endl;
+
+ QString file = m_impl.findDesktopFile( url.fileName() );
+ kdDebug(1220) << "desktop file : " << file << endl;
+
+ if (!file.isEmpty())
+ {
+ KURL desktop;
+ desktop.setPath(file);
+
+ redirection(desktop);
+ finished();
+ return;
+ }
+
+ error(KIO::ERR_MALFORMED_URL, url.prettyURL());
+}
+
+void RemoteProtocol::rename(const KURL &src, const KURL &dest,
+ bool overwrite)
+{
+ if (src.protocol()!="remote" || dest.protocol()!="remote"
+ || m_impl.isWizardURL(src) || m_impl.isWizardURL(dest))
+ {
+ error(KIO::ERR_UNSUPPORTED_ACTION, src.prettyURL());
+ return;
+ }
+
+ if (m_impl.renameFolders(src.fileName(), dest.fileName(), overwrite))
+ {
+ finished();
+ return;
+ }
+
+ error(KIO::ERR_CANNOT_RENAME, src.prettyURL());
+}
diff --git a/kioslave/remote/kio_remote.h b/kioslave/remote/kio_remote.h
new file mode 100644
index 000000000..7d3b0366e
--- /dev/null
+++ b/kioslave/remote/kio_remote.h
@@ -0,0 +1,45 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kevin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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.
+*/
+
+#ifndef KIO_REMOTE_H
+#define KIO_REMOTE_H
+
+#include <kio/slavebase.h>
+#include "remoteimpl.h"
+
+class RemoteProtocol : public KIO::SlaveBase
+{
+public:
+ RemoteProtocol(const QCString &protocol, const QCString &pool,
+ const QCString &app);
+ virtual ~RemoteProtocol();
+
+ virtual void listDir(const KURL &url);
+ virtual void stat(const KURL &url);
+ virtual void del(const KURL &url, bool isFile);
+ virtual void get(const KURL &url);
+ virtual void rename(const KURL &src, const KURL &dest, bool overwrite);
+
+private:
+ void listRoot();
+
+ RemoteImpl m_impl;
+};
+
+#endif
diff --git a/kioslave/remote/remote.protocol b/kioslave/remote/remote.protocol
new file mode 100644
index 000000000..6554be442
--- /dev/null
+++ b/kioslave/remote/remote.protocol
@@ -0,0 +1,17 @@
+[Protocol]
+exec=kio_remote
+protocol=remote
+input=none
+output=filesystem
+listing=Name,Type,Size,Date,AccessDate,Access,Owner,Group,Link
+reading=true
+writing=false
+makedir=false
+deleting=true
+linking=true
+moving=true
+Icon=network
+maxInstances=4
+#TODO DocPath=kioslave/file.html
+Class=:local
+deleteRecursive=true
diff --git a/kioslave/remote/remoteimpl.cpp b/kioslave/remote/remoteimpl.cpp
new file mode 100644
index 000000000..139cbfd2a
--- /dev/null
+++ b/kioslave/remote/remoteimpl.cpp
@@ -0,0 +1,298 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kevin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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 "remoteimpl.h"
+
+#include <kdebug.h>
+#include <kglobalsettings.h>
+#include <kstandarddirs.h>
+#include <kdesktopfile.h>
+#include <kservice.h>
+#include <klocale.h>
+
+#include <qdir.h>
+#include <qfile.h>
+
+#include <sys/stat.h>
+
+#define WIZARD_URL "remote:/x-wizard_service.desktop"
+#define WIZARD_SERVICE "knetattach"
+
+RemoteImpl::RemoteImpl()
+{
+ KGlobal::dirs()->addResourceType("remote_entries",
+ KStandardDirs::kde_default("data") + "remoteview");
+
+ QString path = KGlobal::dirs()->saveLocation("remote_entries");
+
+ QDir dir = path;
+ if (!dir.exists())
+ {
+ dir.cdUp();
+ dir.mkdir("remoteview");
+ }
+}
+
+void RemoteImpl::listRoot(QValueList<KIO::UDSEntry> &list) const
+{
+ kdDebug(1220) << "RemoteImpl::listRoot" << endl;
+
+ QStringList names_found;
+ QStringList dirList = KGlobal::dirs()->resourceDirs("remote_entries");
+
+ QStringList::ConstIterator dirpath = dirList.begin();
+ QStringList::ConstIterator end = dirList.end();
+ for(; dirpath!=end; ++dirpath)
+ {
+ QDir dir = *dirpath;
+ if (!dir.exists()) continue;
+
+ QStringList filenames
+ = dir.entryList( QDir::Files | QDir::Readable );
+
+
+ KIO::UDSEntry entry;
+
+ QStringList::ConstIterator name = filenames.begin();
+ QStringList::ConstIterator endf = filenames.end();
+
+ for(; name!=endf; ++name)
+ {
+ if (!names_found.contains(*name))
+ {
+ entry.clear();
+ createEntry(entry, *dirpath, *name);
+ list.append(entry);
+ names_found.append(*name);
+ }
+ }
+ }
+}
+
+bool RemoteImpl::findDirectory(const QString &filename, QString &directory) const
+{
+ kdDebug(1220) << "RemoteImpl::findDirectory" << endl;
+
+ QStringList dirList = KGlobal::dirs()->resourceDirs("remote_entries");
+
+ QStringList::ConstIterator dirpath = dirList.begin();
+ QStringList::ConstIterator end = dirList.end();
+ for(; dirpath!=end; ++dirpath)
+ {
+ QDir dir = *dirpath;
+ if (!dir.exists()) continue;
+
+ QStringList filenames
+ = dir.entryList( QDir::Files | QDir::Readable );
+
+
+ KIO::UDSEntry entry;
+
+ QStringList::ConstIterator name = filenames.begin();
+ QStringList::ConstIterator endf = filenames.end();
+
+ for(; name!=endf; ++name)
+ {
+ if (*name==filename)
+ {
+ directory = *dirpath;
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+QString RemoteImpl::findDesktopFile(const QString &filename) const
+{
+ kdDebug(1220) << "RemoteImpl::findDesktopFile" << endl;
+
+ QString directory;
+ if (findDirectory(filename+".desktop", directory))
+ {
+ return directory+filename+".desktop";
+ }
+
+ return QString::null;
+}
+
+KURL RemoteImpl::findBaseURL(const QString &filename) const
+{
+ kdDebug(1220) << "RemoteImpl::findBaseURL" << endl;
+
+ QString file = findDesktopFile(filename);
+ if (!file.isEmpty())
+ {
+ KDesktopFile desktop(file, true);
+ return desktop.readURL();
+ }
+
+ return KURL();
+}
+
+
+static void addAtom(KIO::UDSEntry &entry, unsigned int ID, long l,
+ const QString &s = QString::null)
+{
+ KIO::UDSAtom atom;
+ atom.m_uds = ID;
+ atom.m_long = l;
+ atom.m_str = s;
+ entry.append(atom);
+}
+
+
+void RemoteImpl::createTopLevelEntry(KIO::UDSEntry &entry) const
+{
+ entry.clear();
+ addAtom(entry, KIO::UDS_NAME, 0, ".");
+ addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
+ addAtom(entry, KIO::UDS_ACCESS, 0555);
+ addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");
+ addAtom(entry, KIO::UDS_ICON_NAME, 0, "network");
+}
+
+static KURL findWizardRealURL()
+{
+ KURL url;
+ KService::Ptr service = KService::serviceByDesktopName(WIZARD_SERVICE);
+
+ if (service && service->isValid())
+ {
+ url.setPath( locate("apps",
+ service->desktopEntryPath())
+ );
+ }
+
+ return url;
+}
+
+bool RemoteImpl::createWizardEntry(KIO::UDSEntry &entry) const
+{
+ entry.clear();
+
+ KURL url = findWizardRealURL();
+
+ if (!url.isValid())
+ {
+ return false;
+ }
+
+ addAtom(entry, KIO::UDS_NAME, 0, i18n("Add a Network Folder"));
+ addAtom(entry, KIO::UDS_FILE_TYPE, S_IFREG);
+ addAtom(entry, KIO::UDS_URL, 0, WIZARD_URL);
+ addAtom(entry, KIO::UDS_LOCAL_PATH, 0, url.path());
+ addAtom(entry, KIO::UDS_ACCESS, 0500);
+ addAtom(entry, KIO::UDS_MIME_TYPE, 0, "application/x-desktop");
+ addAtom(entry, KIO::UDS_ICON_NAME, 0, "wizard");
+
+ return true;
+}
+
+bool RemoteImpl::isWizardURL(const KURL &url) const
+{
+ return url==KURL(WIZARD_URL);
+}
+
+
+void RemoteImpl::createEntry(KIO::UDSEntry &entry,
+ const QString &directory,
+ const QString &file) const
+{
+ kdDebug(1220) << "RemoteImpl::createEntry" << endl;
+
+ KDesktopFile desktop(directory+file, true);
+
+ kdDebug(1220) << "path = " << directory << file << endl;
+
+ entry.clear();
+
+ QString new_filename = file;
+ new_filename.truncate( file.length()-8);
+
+ addAtom(entry, KIO::UDS_NAME, 0, desktop.readName());
+ addAtom(entry, KIO::UDS_URL, 0, "remote:/"+new_filename);
+
+ addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR);
+ addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory");
+
+ QString icon = desktop.readIcon();
+
+ addAtom(entry, KIO::UDS_ICON_NAME, 0, icon);
+ addAtom(entry, KIO::UDS_LINK_DEST, 0, desktop.readURL());
+}
+
+bool RemoteImpl::statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const
+{
+ kdDebug(1220) << "RemoteImpl::statNetworkFolder: " << filename << endl;
+
+ QString directory;
+ if (findDirectory(filename+".desktop", directory))
+ {
+ createEntry(entry, directory, filename+".desktop");
+ return true;
+ }
+
+ return false;
+}
+
+bool RemoteImpl::deleteNetworkFolder(const QString &filename) const
+{
+ kdDebug(1220) << "RemoteImpl::deleteNetworkFolder: " << filename << endl;
+
+ QString directory;
+ if (findDirectory(filename+".desktop", directory))
+ {
+ kdDebug(1220) << "Removing " << directory << filename << ".desktop" << endl;
+ return QFile::remove(directory+filename+".desktop");
+ }
+
+ return false;
+}
+
+bool RemoteImpl::renameFolders(const QString &src, const QString &dest,
+ bool overwrite) const
+{
+ kdDebug(1220) << "RemoteImpl::renameFolders: "
+ << src << ", " << dest << endl;
+
+ QString directory;
+ if (findDirectory(src+".desktop", directory))
+ {
+ if (!overwrite && QFile::exists(directory+dest+".desktop"))
+ {
+ return false;
+ }
+
+ kdDebug(1220) << "Renaming " << directory << src << ".desktop"<< endl;
+ QDir dir(directory);
+ bool res = dir.rename(src+".desktop", dest+".desktop");
+ if (res)
+ {
+ KDesktopFile desktop(directory+dest+".desktop");
+ desktop.writeEntry("Name", dest);
+ }
+ return res;
+ }
+
+ return false;
+}
+
+
diff --git a/kioslave/remote/remoteimpl.h b/kioslave/remote/remoteimpl.h
new file mode 100644
index 000000000..ba7390bf4
--- /dev/null
+++ b/kioslave/remote/remoteimpl.h
@@ -0,0 +1,54 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kevin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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.
+*/
+
+#ifndef REMOTEIMPL_H
+#define REMOTEIMPL_H
+
+#include <kio/global.h>
+#include <kio/job.h>
+#include <kurl.h>
+
+#include <qstring.h>
+
+class RemoteImpl
+{
+public:
+ RemoteImpl();
+
+ void createTopLevelEntry(KIO::UDSEntry &entry) const;
+ bool createWizardEntry(KIO::UDSEntry &entry) const;
+ bool isWizardURL(const KURL &url) const;
+ bool statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const;
+
+ void listRoot(QValueList<KIO::UDSEntry> &list) const;
+
+ KURL findBaseURL(const QString &filename) const;
+ QString findDesktopFile(const QString &filename) const;
+
+ bool deleteNetworkFolder(const QString &filename) const;
+ bool renameFolders(const QString &src, const QString &dest,
+ bool overwrite) const;
+
+private:
+ bool findDirectory(const QString &filename, QString &directory) const;
+ void createEntry(KIO::UDSEntry& entry, const QString &directory,
+ const QString &file) const;
+};
+
+#endif
diff --git a/kioslave/remote/testremote.cpp b/kioslave/remote/testremote.cpp
new file mode 100644
index 000000000..a3e979023
--- /dev/null
+++ b/kioslave/remote/testremote.cpp
@@ -0,0 +1,69 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kvin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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 "kio_remote.h"
+#include "testremote.h"
+
+#include <config.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kcmdlineargs.h>
+
+#include <stdlib.h>
+
+static bool check(const QString& txt, QString a, QString b)
+{
+ if (a.isEmpty())
+ a = QString::null;
+ if (b.isEmpty())
+ b = QString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ KApplication::disableAutoDcopRegistration();
+ KCmdLineArgs::init(argc,argv,"testremote", 0, 0, 0, 0);
+ KApplication app;
+
+ TestRemote test;
+ test.setup();
+ test.runAll();
+ kdDebug() << "All tests OK." << endl;
+ return 0; // success. The exit(1) in check() is what happens in case of failure.
+}
+
+void TestRemote::setup()
+{
+
+}
+
+void TestRemote::runAll()
+{
+
+}
+
diff --git a/kioslave/remote/testremote.h b/kioslave/remote/testremote.h
new file mode 100644
index 000000000..ba51a8602
--- /dev/null
+++ b/kioslave/remote/testremote.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE project
+ Copyright (c) 2004 Kvin 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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.
+*/
+
+#ifndef TESTREMOTE_H
+#define TESTREMOTE_H
+
+class TestRemote
+{
+public:
+ TestRemote() {}
+ void setup();
+ void runAll();
+
+ // tests
+
+};
+
+#endif