diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/home | |
download | tdebase-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/home')
-rw-r--r-- | kioslave/home/Makefile.am | 32 | ||||
-rw-r--r-- | kioslave/home/dummy.cpp | 1 | ||||
-rw-r--r-- | kioslave/home/home.protocol | 19 | ||||
-rw-r--r-- | kioslave/home/homeimpl.cpp | 228 | ||||
-rw-r--r-- | kioslave/home/homeimpl.h | 57 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/Makefile.am | 13 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/homedirnotify.cpp | 185 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/homedirnotify.desktop | 60 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/homedirnotify.h | 48 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/homedirnotifymodule.cpp | 37 | ||||
-rw-r--r-- | kioslave/home/kdedmodule/homedirnotifymodule.h | 36 | ||||
-rw-r--r-- | kioslave/home/kio_home.cpp | 186 | ||||
-rw-r--r-- | kioslave/home/kio_home.h | 44 | ||||
-rw-r--r-- | kioslave/home/testhome.cpp | 69 | ||||
-rw-r--r-- | kioslave/home/testhome.h | 34 |
15 files changed, 1049 insertions, 0 deletions
diff --git a/kioslave/home/Makefile.am b/kioslave/home/Makefile.am new file mode 100644 index 000000000..be10e5bcc --- /dev/null +++ b/kioslave/home/Makefile.am @@ -0,0 +1,32 @@ +SUBDIRS= . kdedmodule +# wizard + +INCLUDES = $(all_includes) +METASOURCES = AUTO + +kde_module_LTLIBRARIES = kio_home.la + +kio_home_la_SOURCES = dummy.cpp +kio_home_la_LIBADD = libkiohome.la $(LIB_KIO) +kio_home_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined + +dummy.cpp: + echo > dummy.cpp + +kde_services_DATA = home.protocol + +noinst_LTLIBRARIES = libkiohome.la +libkiohome_la_SOURCES = kio_home.cpp homeimpl.cpp + +check_PROGRAMS = testhome +testhome_SOURCES = testhome.cpp +testhome_LDADD = libkiohome.la $(LIB_KIO) +testhome_LDFLAGS = $(all_libraries) + +## TODO in unsermake: TESTS = testhome +check: testhome + ./testhome + +messages: + $(XGETTEXT) `find . -name "*.cc" -o -name "*.cpp" -o -name "*.h"` -o $(podir)/kio_home.pot + diff --git a/kioslave/home/dummy.cpp b/kioslave/home/dummy.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/kioslave/home/dummy.cpp @@ -0,0 +1 @@ + diff --git a/kioslave/home/home.protocol b/kioslave/home/home.protocol new file mode 100644 index 000000000..59f6cba5d --- /dev/null +++ b/kioslave/home/home.protocol @@ -0,0 +1,19 @@ +[Protocol] +exec=kio_home +protocol=home +input=none +output=filesystem +listing=Name,Type,Size,Date,AccessDate,Access,Owner,Group,Link +reading=true +writing=true +makedir=true +deleting=true +linking=true +moving=true +Icon=folder_home +maxInstances=4 +#TODO DocPath=kioslave/file.html +Class=:local +Parent=system:/ +deleteRecursive=true +fileNameUsedForCopying=Name diff --git a/kioslave/home/homeimpl.cpp b/kioslave/home/homeimpl.cpp new file mode 100644 index 000000000..7e86173ba --- /dev/null +++ b/kioslave/home/homeimpl.cpp @@ -0,0 +1,228 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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 "homeimpl.h" + +#include <kdebug.h> +#include <qapplication.h> +#include <qeventloop.h> + +#include <sys/stat.h> + +#define MINIMUM_UID 500 + +HomeImpl::HomeImpl() +{ + KUser user; + m_effectiveUid = user.uid(); +} + +bool HomeImpl::parseURL(const KURL &url, QString &name, QString &path) const +{ + QString url_path = url.path(); + + int i = url_path.find('/', 1); + if (i > 0) + { + name = url_path.mid(1, i-1); + path = url_path.mid(i+1); + } + else + { + name = url_path.mid(1); + path = QString::null; + } + + return name != QString::null; +} + +bool HomeImpl::realURL(const QString &name, const QString &path, KURL &url) +{ + KUser user(name); + + if ( user.isValid() ) + { + KURL res; + res.setPath( user.homeDir() ); + res.addPath(path); + url = res; + return true; + } + + return false; +} + + +bool HomeImpl::listHomes(QValueList<KIO::UDSEntry> &list) +{ + kdDebug() << "HomeImpl::listHomes" << endl; + + KUser current_user; + QValueList<KUserGroup> groups = current_user.groups(); + QValueList<int> uid_list; + + QValueList<KUserGroup>::iterator groups_it = groups.begin(); + QValueList<KUserGroup>::iterator groups_end = groups.end(); + + for(; groups_it!=groups_end; ++groups_it) + { + QValueList<KUser> users = (*groups_it).users(); + + QValueList<KUser>::iterator it = users.begin(); + QValueList<KUser>::iterator users_end = users.end(); + + for(; it!=users_end; ++it) + { + if ((*it).uid()>=MINIMUM_UID + && !uid_list.contains( (*it).uid() ) ) + { + uid_list.append( (*it).uid() ); + KIO::UDSEntry entry; + createHomeEntry(entry, *it); + list.append(entry); + } + } + } + + return true; +} + +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 HomeImpl::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, "kfm_home"); + addAtom(entry, KIO::UDS_USER, 0, "root"); + addAtom(entry, KIO::UDS_GROUP, 0, "root"); +} + +void HomeImpl::createHomeEntry(KIO::UDSEntry &entry, + const KUser &user) +{ + kdDebug() << "HomeImpl::createHomeEntry" << endl; + + entry.clear(); + + QString full_name = user.loginName(); + + if (!user.fullName().isEmpty()) + { + full_name = user.fullName()+" ("+user.loginName()+")"; + } + + full_name = KIO::encodeFileName( full_name ); + + addAtom(entry, KIO::UDS_NAME, 0, full_name); + addAtom(entry, KIO::UDS_URL, 0, "home:/"+user.loginName()); + + addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR); + addAtom(entry, KIO::UDS_MIME_TYPE, 0, "inode/directory"); + + QString icon_name = "folder_home2"; + + if (user.uid()==m_effectiveUid) + { + icon_name = "folder_home"; + } + + addAtom(entry, KIO::UDS_ICON_NAME, 0, icon_name); + + KURL url; + url.setPath(user.homeDir()); + entry += extractUrlInfos(url); +} + +bool HomeImpl::statHome(const QString &name, KIO::UDSEntry &entry) +{ + kdDebug() << "HomeImpl::statHome: " << name << endl; + + KUser user(name); + + if (user.isValid()) + { + createHomeEntry(entry, user); + return true; + } + + return false; +} + +void HomeImpl::slotStatResult(KIO::Job *job) +{ + if ( job->error() == 0) + { + KIO::StatJob *stat_job = static_cast<KIO::StatJob *>(job); + m_entryBuffer = stat_job->statResult(); + } + + qApp->eventLoop()->exitLoop(); +} + +KIO::UDSEntry HomeImpl::extractUrlInfos(const KURL &url) +{ + m_entryBuffer.clear(); + + KIO::StatJob *job = KIO::stat(url, false); + connect( job, SIGNAL( result(KIO::Job *) ), + this, SLOT( slotStatResult(KIO::Job *) ) ); + qApp->eventLoop()->enterLoop(); + + KIO::UDSEntry::iterator it = m_entryBuffer.begin(); + KIO::UDSEntry::iterator end = m_entryBuffer.end(); + + KIO::UDSEntry infos; + + for(; it!=end; ++it) + { + switch( (*it).m_uds ) + { + case KIO::UDS_ACCESS: + case KIO::UDS_USER: + case KIO::UDS_GROUP: + case KIO::UDS_CREATION_TIME: + case KIO::UDS_MODIFICATION_TIME: + case KIO::UDS_ACCESS_TIME: + infos.append(*it); + break; + default: + break; + } + } + + addAtom(infos, KIO::UDS_LOCAL_PATH, 0, url.path()); + + return infos; +} + +#include "homeimpl.moc" + diff --git a/kioslave/home/homeimpl.h b/kioslave/home/homeimpl.h new file mode 100644 index 000000000..8c4ace279 --- /dev/null +++ b/kioslave/home/homeimpl.h @@ -0,0 +1,57 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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 HOMEIMPL_H +#define HOMEIMPL_H + +#include <kio/global.h> +#include <kio/job.h> +#include <kurl.h> +#include <kuser.h> + +#include <qstring.h> + +class HomeImpl : public QObject +{ +Q_OBJECT + +public: + HomeImpl(); + bool parseURL(const KURL &url, QString &name, QString &path) const; + bool realURL(const QString &name, const QString &path, KURL &url); + + bool statHome(const QString &name, KIO::UDSEntry &entry); + bool listHomes(QValueList<KIO::UDSEntry> &list); + + void createTopLevelEntry(KIO::UDSEntry &entry) const; + +private slots: + void slotStatResult(KIO::Job *job); + +private: + void createHomeEntry(KIO::UDSEntry& entry, const KUser &user); + + KIO::UDSEntry extractUrlInfos(const KURL &url); + KIO::UDSEntry m_entryBuffer; + + + long m_effectiveUid; +}; + +#endif diff --git a/kioslave/home/kdedmodule/Makefile.am b/kioslave/home/kdedmodule/Makefile.am new file mode 100644 index 000000000..3d7a54f9b --- /dev/null +++ b/kioslave/home/kdedmodule/Makefile.am @@ -0,0 +1,13 @@ +kde_module_LTLIBRARIES = kded_homedirnotify.la + +METASOURCES = AUTO +INCLUDES = $(all_includes) + +kded_homedirnotify_la_SOURCES = homedirnotify.cpp homedirnotify.skel homedirnotifymodule.cpp homedirnotifymodule.skel +kded_homedirnotify_la_LDFLAGS = $(all_libraries) -module -avoid-version +kded_homedirnotify_la_LIBADD = $(LIB_KSYCOCA) + + +servicesdir = $(kde_servicesdir)/kded +services_DATA = homedirnotify.desktop + diff --git a/kioslave/home/kdedmodule/homedirnotify.cpp b/kioslave/home/kdedmodule/homedirnotify.cpp new file mode 100644 index 000000000..e4eab44bb --- /dev/null +++ b/kioslave/home/kdedmodule/homedirnotify.cpp @@ -0,0 +1,185 @@ +/* This file is part of the KDE Project + Copyright (c) 2005 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 "homedirnotify.h" + +#include <kdebug.h> +#include <kuser.h> + +#include <kdirnotify_stub.h> + +#define MINIMUM_UID 500 + +HomeDirNotify::HomeDirNotify() +: mInited( false ) +{ +} + +void HomeDirNotify::init() +{ + if( mInited ) + return; + mInited = true; + + KUser current_user; + QValueList<KUserGroup> groups = current_user.groups(); + QValueList<int> uid_list; + + QValueList<KUserGroup>::iterator groups_it = groups.begin(); + QValueList<KUserGroup>::iterator groups_end = groups.end(); + + for(; groups_it!=groups_end; ++groups_it) + { + QValueList<KUser> users = (*groups_it).users(); + + QValueList<KUser>::iterator it = users.begin(); + QValueList<KUser>::iterator users_end = users.end(); + + for(; it!=users_end; ++it) + { + if ((*it).uid()>=MINIMUM_UID + && !uid_list.contains( (*it).uid() ) ) + { + uid_list.append( (*it).uid() ); + + QString name = (*it).loginName(); + KURL url; + url.setPath( (*it).homeDir() ); + + m_homeFoldersMap[name] = url; + } + } + } +} + +KURL HomeDirNotify::toHomeURL(const KURL &url) +{ + kdDebug() << "HomeDirNotify::toHomeURL(" << url << ")" << endl; + + init(); + QMap<QString,KURL>::iterator it = m_homeFoldersMap.begin(); + QMap<QString,KURL>::iterator end = m_homeFoldersMap.end(); + + for (; it!=end; ++it) + { + QString name = it.key(); + KURL base = it.data(); + + if ( base.isParentOf(url) ) + { + QString path = KURL::relativePath(base.path(), + url.path()); + KURL result("home:/"+name+"/"+path); + result.cleanPath(); + kdDebug() << "result => " << result << endl; + return result; + } + } + + kdDebug() << "result => KURL()" << endl; + return KURL(); +} + +KURL::List HomeDirNotify::toHomeURLList(const KURL::List &list) +{ + init(); + KURL::List new_list; + + KURL::List::const_iterator it = list.begin(); + KURL::List::const_iterator end = list.end(); + + for (; it!=end; ++it) + { + KURL url = toHomeURL(*it); + + if (url.isValid()) + { + new_list.append(url); + } + } + + return new_list; +} + +ASYNC HomeDirNotify::FilesAdded(const KURL &directory) +{ + kdDebug() << "HomeDirNotify::FilesAdded" << endl; + + KURL new_dir = toHomeURL(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 (some home:/ 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 HomeDirNotify::FilesRemoved(const KURL::List &fileList) +{ + kdDebug() << "HomeDirNotify::FilesRemoved" << endl; + + KURL::List new_list = toHomeURLList(fileList); + + if (!new_list.isEmpty()) + { + //KDirNotify_stub notifier("*", "*"); + //notifier.FilesRemoved( new_list ); + evil_hack(new_list); + } +} + +ASYNC HomeDirNotify::FilesChanged(const KURL::List &fileList) +{ + kdDebug() << "HomeDirNotify::FilesChanged" << endl; + + KURL::List new_list = toHomeURLList(fileList); + + if (!new_list.isEmpty()) + { + //KDirNotify_stub notifier("*", "*"); + //notifier.FilesChanged( new_list ); + evil_hack(new_list); + } +} diff --git a/kioslave/home/kdedmodule/homedirnotify.desktop b/kioslave/home/kdedmodule/homedirnotify.desktop new file mode 100644 index 000000000..c931748d1 --- /dev/null +++ b/kioslave/home/kdedmodule/homedirnotify.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=KDED Home Base URL Notifier +Name[af]=KDED tuis URL inkennissteller +Name[be]=Праверка зменаў мясцовых файлаў KDED +Name[bs]=KDED lokalno obavještenje o baznom URLu +Name[ca]=Notificador KDED de l'URL d'inici +Name[cs]=Démon upozorňování na domovské URL +Name[csb]=Dôwanié wiédzë o URL-ach domôcegò katalogù dlô KDED +Name[da]=KDED Hjemmebasis-URL påmindelser +Name[de]=Überwachung für persönliche Ordner +Name[el]=KDED ειδοποιητής URL αρχικής βάσης +Name[eo]=KDED Hejmo Bazo URL Avertilo +Name[es]=Notificador de URL de KDED +Name[et]=KDED kodu baas-URLi teadustaja +Name[eu]=KDED hasierako URL oinarriaren iragarlea +Name[fa]=اخطاردهندۀ نشانی وب پایۀ آغازۀ KDED +Name[fi]=KDED:in etä-verkko-osoitteen ilmaisin +Name[fr]=Notification de l'URL de base KDED +Name[fy]=KDED Thúsbasis-URL-adres notifikaasje +Name[gl]=Notificador de URL base de KDED +Name[hr]=KDED URL obavještavanje domaće baze +Name[hu]=Értesítő a KDE saját URL-hez +Name[is]=KDED grunnslóðar tilkynnari +Name[it]=Notifica KDED Home Base URL +Name[ja]=KDED ホームベース URL Nofitier +Name[ka]=KDED ძირითადი თავფურცლის URL შემტყობინებელი +Name[kk]=KDED Home Base URL құлақтандыру +Name[km]=KDED Remote Base URL Notifier +Name[ko]=KDED 원격 기반 URL 알리미 +Name[lt]=KDED pagrindinio namų URL priminiklis +Name[nb]=KDED-påminner for eksterne nettadresser +Name[nds]=KDED-Narichten för Tohuusorner-URLs +Name[ne]=KDED गृह आधारित यूआरएल सूचक +Name[nl]=KDED Thuisbasis-URL-adres notificatie +Name[nn]=KDED-varsel for heimebase +Name[pa]=KDED ਮੁੱਖ ਅਧਾਰ URL ਸੂਚਕ +Name[pl]=Powiadamianie o URL-ach katalogu domowego dla KDED +Name[pt]=Notificador de URLs de Base Remotos do KDED +Name[pt_BR]=Serviço de Notificação da URL do KDED +Name[ro]=Notificare KDED pentru URL acasă +Name[ru]=Уведомление о смене базового адреса KDED +Name[sk]=KDED notifikátor domovskej URL +Name[sl]=Obvestilnik KDED domačega osnovnega URL-ja +Name[sr]=Обавештавач о домаћем базном URL-у, KDED +Name[sr@Latn]=Obaveštavač o domaćem baznom URL-u, KDED +Name[sv]=KDED-meddelande om hembaswebbadresser +Name[th]=ตัวแจ้งเตือน Home Base URL KDED +Name[tr]=KDED Yerel Tabanlı URL Hatırlatıcı +Name[uk]=Сповіщувач домашньої базової адреси URL KDED +Name[vi]=Trình thông báo URL trong máy KDED +Name[wa]=Notifieu di l' URL di båze del måjhon KDED +Name[zh_CN]=KDED 主页基 URL 通知器 +Name[zh_TW]=KDED 家用基礎 URL 通知程式 +ServiceTypes=KDEDModule +X-KDE-ModuleType=Library +X-KDE-Library=homedirnotify +X-KDE-FactoryName=homedirnotify +X-KDE-Kded-load-on-demand=true +X-KDE-Kded-autoload=true diff --git a/kioslave/home/kdedmodule/homedirnotify.h b/kioslave/home/kdedmodule/homedirnotify.h new file mode 100644 index 000000000..14655a1cd --- /dev/null +++ b/kioslave/home/kdedmodule/homedirnotify.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE Project + Copyright (c) 2005 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 HOMEDIRNOTIFY_H +#define HOMEDIRNOTIFY_H + +#include <kurl.h> +#include <kdirnotify.h> + +#include <qmap.h> + +class HomeDirNotify : public KDirNotify +{ +K_DCOP + +public: + HomeDirNotify(); + +k_dcop: + virtual ASYNC FilesAdded (const KURL &directory); + virtual ASYNC FilesRemoved (const KURL::List &fileList); + virtual ASYNC FilesChanged (const KURL::List &fileList); + +private: + void init(); + KURL toHomeURL(const KURL &url); + KURL::List toHomeURLList(const KURL::List &list); + + QMap<QString,KURL> m_homeFoldersMap; + bool mInited; +}; + +#endif diff --git a/kioslave/home/kdedmodule/homedirnotifymodule.cpp b/kioslave/home/kdedmodule/homedirnotifymodule.cpp new file mode 100644 index 000000000..1b91ccc31 --- /dev/null +++ b/kioslave/home/kdedmodule/homedirnotifymodule.cpp @@ -0,0 +1,37 @@ +/* This file is part of the KDE Project + Copyright (c) 2005 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 "homedirnotifymodule.h" + +#include <kdebug.h> +#include <klocale.h> +#include <kglobal.h> + +HomeDirNotifyModule::HomeDirNotifyModule(const QCString &obj) + : KDEDModule(obj) +{ +} + +extern "C" { + KDE_EXPORT KDEDModule *create_homedirnotify(const QCString &obj) + { + KGlobal::locale()->insertCatalogue("kio_home"); + return new HomeDirNotifyModule(obj); + } +} + diff --git a/kioslave/home/kdedmodule/homedirnotifymodule.h b/kioslave/home/kdedmodule/homedirnotifymodule.h new file mode 100644 index 000000000..159670fb6 --- /dev/null +++ b/kioslave/home/kdedmodule/homedirnotifymodule.h @@ -0,0 +1,36 @@ +/* This file is part of the KDE Project + Copyright (c) 2005 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 HOMEDIRNOTIFYMODULE_H +#define HOMEDIRNOTIFYMODULE_H + +#include <kdedmodule.h> + +#include "homedirnotify.h" + +class HomeDirNotifyModule : public KDEDModule +{ +K_DCOP + +public: + HomeDirNotifyModule(const QCString &obj); +private: + HomeDirNotify notifier; +}; + +#endif diff --git a/kioslave/home/kio_home.cpp b/kioslave/home/kio_home.cpp new file mode 100644 index 000000000..36a3161d8 --- /dev/null +++ b/kioslave/home/kio_home.cpp @@ -0,0 +1,186 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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_home.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_home", 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(); + HomeProtocol slave( args->arg(0), args->arg(1), args->arg(2) ); + slave.dispatchLoop(); + return 0; + } +} + + +HomeProtocol::HomeProtocol(const QCString &protocol, + const QCString &pool, const QCString &app) + : ForwardingSlaveBase(protocol, pool, app) +{ +} + +HomeProtocol::~HomeProtocol() +{ +} + +bool HomeProtocol::rewriteURL(const KURL &url, KURL &newUrl) +{ + QString name, path; + + if ( !m_impl.parseURL(url, name, path) ) + { + error(KIO::ERR_MALFORMED_URL, url.prettyURL()); + return false; + } + + + if ( !m_impl.realURL(name, path, newUrl) ) + { + error(KIO::ERR_MALFORMED_URL, url.prettyURL()); + return false; + } + + return true; +} + + +void HomeProtocol::listDir(const KURL &url) +{ + kdDebug() << "HomeProtocol::listDir: " << url << endl; + + if ( url.path().length() <= 1 ) + { + listRoot(); + return; + } + + QString name, path; + bool ok = m_impl.parseURL(url, name, path); + + if ( !ok ) + { + error(KIO::ERR_MALFORMED_URL, url.prettyURL()); + return; + } + + ForwardingSlaveBase::listDir(url); +} + +void HomeProtocol::listRoot() +{ + KIO::UDSEntry entry; + + KIO::UDSEntryList home_entries; + bool ok = m_impl.listHomes(home_entries); + + if (!ok) // can't happen + { + error(KIO::ERR_UNKNOWN, ""); + return; + } + + totalSize(home_entries.count()+1); + + m_impl.createTopLevelEntry(entry); + listEntry(entry, false); + + KIO::UDSEntryListIterator it = home_entries.begin(); + KIO::UDSEntryListIterator end = home_entries.end(); + + for(; it!=end; ++it) + { + listEntry(*it, false); + } + + entry.clear(); + listEntry(entry, true); + + finished(); +} + +void HomeProtocol::stat(const KURL &url) +{ + kdDebug() << "HomeProtocol::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; + } + + QString name; + bool ok = m_impl.parseURL(url, name, path); + + if ( !ok ) + { + error(KIO::ERR_MALFORMED_URL, url.prettyURL()); + return; + } + + if( path.isEmpty() ) + { + KIO::UDSEntry entry; + + if ( m_impl.statHome(name, entry) ) + { + statEntry(entry); + finished(); + } + else + { + error(KIO::ERR_DOES_NOT_EXIST, url.prettyURL()); + } + } + else + { + ForwardingSlaveBase::stat(url); + } +} diff --git a/kioslave/home/kio_home.h b/kioslave/home/kio_home.h new file mode 100644 index 000000000..1d5e237ea --- /dev/null +++ b/kioslave/home/kio_home.h @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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_HOME_H +#define KIO_HOME_H + +#include <kio/forwardingslavebase.h> +#include "homeimpl.h" + +class HomeProtocol : public KIO::ForwardingSlaveBase +{ +public: + HomeProtocol(const QCString &protocol, const QCString &pool, + const QCString &app); + virtual ~HomeProtocol(); + + virtual bool rewriteURL(const KURL &url, KURL &newUrl); + + virtual void listDir(const KURL &url); + virtual void stat(const KURL &url); + +private: + void listRoot(); + + HomeImpl m_impl; +}; + +#endif diff --git a/kioslave/home/testhome.cpp b/kioslave/home/testhome.cpp new file mode 100644 index 000000000..e9d64ec68 --- /dev/null +++ b/kioslave/home/testhome.cpp @@ -0,0 +1,69 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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_home.h" +#include "testhome.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,"testhome", 0, 0, 0, 0); + KApplication app; + + TestHome 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 TestHome::setup() +{ + +} + +void TestHome::runAll() +{ + +} + diff --git a/kioslave/home/testhome.h b/kioslave/home/testhome.h new file mode 100644 index 000000000..dd8b257e3 --- /dev/null +++ b/kioslave/home/testhome.h @@ -0,0 +1,34 @@ +/* This file is part of the KDE project + Copyright (c) 2005 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 TESTHOME_H +#define TESTHOME_H + +class TestHome +{ +public: + TestHome() {} + void setup(); + void runAll(); + + // tests + +}; + +#endif |