From 9fac7af37460c6a73a7debac1ba82b094a8f066c Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Fri, 2 Feb 2001 04:49:20 +0000 Subject: Replaced lot of ugly char * by string. Fixed bug in plpftp's filename-completion, which was introduced yesterday. Added a class PlpUID for dealing with application-UIDs Added UID->mimetype mapping in kioslave. --- kde2/kioslave/kio_plp.cpp | 143 ++++++++++++++++++++++++++++++++++++++-------- kde2/kioslave/kio_plp.h | 77 +++++++++++++------------ 2 files changed, 159 insertions(+), 61 deletions(-) (limited to 'kde2/kioslave') diff --git a/kde2/kioslave/kio_plp.cpp b/kde2/kioslave/kio_plp.cpp index 587ef98..4e7dbf0 100644 --- a/kde2/kioslave/kio_plp.cpp +++ b/kde2/kioslave/kio_plp.cpp @@ -25,6 +25,7 @@ #include "kio_plp.h" +#include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include @@ -99,6 +101,10 @@ removeFirstPart(const QString& path, QString &removed) { PLPProtocol::PLPProtocol (const QCString &pool, const QCString &app) :SlaveBase("psion", pool, app), plpRfsv(0), plpRfsvSocket(0) { + + kdDebug(PLP_DEBUGAREA) << "PLPProtocol::PLPProtocol(" << pool << "," + << app << ")" << endl; + currentHost = ""; struct servent *se = getservbyname("psion", "tcp"); endservent(); @@ -106,7 +112,45 @@ PLPProtocol::PLPProtocol (const QCString &pool, const QCString &app) currentPort = ntohs(se->s_port); else currentPort = DPORT; - kdDebug(PLP_DEBUGAREA) << "PLP::PLP: -" << pool << "-" << endl; + + typedef QMap UIDMap; + KConfig *cfg = new KConfig("kioslaverc"); + + UIDMap uids = cfg->entryMap("Psion/UIDmapping"); + if (uids.isEmpty()) { + cfg->setGroup("Psion/UIDmapping"); + // Builtin application types. + cfg->writeEntry("uid-10000037-1000006D-1000007F", + "application/x-psion-word"); + cfg->writeEntry("uid-10000037-1000006D-10000088", + "application/x-psion-sheet"); + cfg->writeEntry("uid-10000037-1000006D-1000006d", + "application/x-psion-record"); + cfg->writeEntry("uid-10000037-1000006D-1000007d", + "application/x-psion-sketch"); + cfg->writeEntry("uid-10000037-1000006D-10000085", + "application/x-psion-opl"); + cfg->writeEntry("uid-10000050-1000006D-10000084", + "application/x-psion-agenda"); + cfg->writeEntry("uid-10000050-1000006D-10000086", + "application/x-psion-data"); + cfg->sync(); + uids = cfg->entryMap("Psion/UIDmapping"); + } + for (UIDMap::Iterator uit = uids.begin(); uit != uids.end(); ++uit) { + long u1, u2, u3; + + sscanf(uit.key().data(), "uid-%08X-%08X-%08X", &u1, &u2, &u3); + puids.insert(PlpUID(u1, u2, u3), uit.data()); + } +#if 0 + cout << "uids:" << endl; + for (UidMap::Iterator it = puids.begin(); it != puids.end(); it++) { + cout << "UID: " << hex << setw(8) << setfill('0') << it.key().uid[0] + << it.key().uid[1] << it.key().uid[2] << dec << "->" << + it.data() << endl; + } +#endif } PLPProtocol::~PLPProtocol() { @@ -135,9 +179,9 @@ isDrive(const QString& path) { for (QStringList::Iterator it = drives.begin(); it != drives.end(); it++) { QString cmp = "/" + *it; if (cmp == tmp) - return TRUE; + return true; } - return FALSE; + return false; } bool PLPProtocol:: @@ -220,6 +264,19 @@ checkConnection() { return (plpRfsv == 0); } +QString PLPProtocol:: +uid2mime(PlpDirent &e) { + QString tmp; + PlpUID u = e.getUID(); + UidMap::Iterator it = puids.find(u); + + if (it != puids.end()) + tmp = it.data(); + else + tmp.sprintf("application/x-psion-uid-%08X-%08X-%08X", u[0], u[1], u[2]); + return tmp; +} + void PLPProtocol:: listDir(const KURL& _url) { KURL url(_url); @@ -268,6 +325,7 @@ listDir(const KURL& _url) { UDSEntry entry; for (int i = 0; i < files.size(); i++) { UDSAtom atom; + PlpDirent e = files[i]; long attr = e.getAttr(); @@ -276,9 +334,13 @@ listDir(const KURL& _url) { atom.m_str = e.getName(); entry.append(atom); - if (rom) - attr |= rfsv::PSI_A_RDONLY; - completeUDSEntry(entry, attr, e.getSize(), e.getPsiTime().getTime()); + if ((attr & rfsv::PSI_A_DIR) == 0) { + atom.m_uds = KIO::UDS_MIME_TYPE; + atom.m_str = uid2mime(e); + entry.append(atom); + } + + completeUDSEntry(entry, e, rom); listEntry(entry, false); } listEntry(entry, true); // ready @@ -306,20 +368,17 @@ createVirtualDirEntry(UDSEntry & entry, bool rdonly) { bool PLPProtocol:: emitTotalSize(QString &name) { - long attr; - long size; - bool err; - PsiTime time; + PlpDirent e; - Enum res = plpRfsv->fgeteattr(name, attr, size, time); + Enum res = plpRfsv->fgeteattr(name, e); if (checkForError(res)) return true; - totalSize(size); + totalSize(e.getSize()); return false; } void PLPProtocol:: -stat( const KURL & url) { +stat(const KURL & url) { QString path(QFile::encodeName(url.path())); UDSEntry entry; UDSAtom atom; @@ -351,33 +410,67 @@ stat( const KURL & url) { return; } - long attr, size; - PsiTime time; - Enum res = plpRfsv->fgeteattr(path, attr, size, time); + PlpDirent e; + + Enum res = plpRfsv->fgeteattr(path, e); if (checkForError(res)) return; - if (rom) - attr |= rfsv::PSI_A_RDONLY; atom.m_uds = KIO::UDS_NAME; atom.m_str = fileName; entry.append(atom); - completeUDSEntry(entry, attr, size, time.getTime()); + completeUDSEntry(entry, e, rom); statEntry(entry); finished(); } void PLPProtocol:: -completeUDSEntry(UDSEntry& entry, const long attr, const long size, const time_t date) { +mimetype(const KURL & url) { + QString path(QFile::encodeName(url.path())); + UDSEntry entry; UDSAtom atom; + if (checkConnection()) + return; + + kdDebug(PLP_DEBUGAREA) << "mimetype(" << path << ")" << endl; + stripTrailingSlash(path); + + if (isRoot(path) || isDrive(path)) { + mimeType("inode/directory"); + finished(); + return; + } + convertName(path); + + if (path.isEmpty()) { + error(ERR_DOES_NOT_EXIST, path); + return; + } + + PlpDirent e; + Enum res = plpRfsv->fgeteattr(path, e); + if (checkForError(res)) + return; + mimeType(uid2mime(e)); + finished(); +} + +void PLPProtocol:: +completeUDSEntry(UDSEntry& entry, PlpDirent &e, bool rom) { + UDSAtom atom; + long attr = e.getAttr(); + + if (rom) + attr |= rfsv::PSI_A_RDONLY; + atom.m_uds = KIO::UDS_SIZE; - atom.m_long = size; + atom.m_long = e.getSize(); entry.append(atom); atom.m_uds = KIO::UDS_MODIFICATION_TIME; - atom.m_long = date; + atom.m_long = e.getPsiTime().getTime(); entry.append(atom); atom.m_uds = KIO::UDS_ACCESS; @@ -392,7 +485,7 @@ completeUDSEntry(UDSEntry& entry, const long attr, const long size, const time_t atom.m_long = (attr & rfsv::PSI_A_DIR) ? S_IFDIR : S_IFREG; entry.append(atom); -#if 0 +#if 1 KIO::UDSEntry::ConstIterator it = entry.begin(); for( ; it != entry.end(); it++ ) { switch ((*it).m_uds) { @@ -504,9 +597,9 @@ checkForError(Enum res) { error(ERR_UNKNOWN, text); break; } - return TRUE; + return true; } - return FALSE; + return false; } void PLPProtocol:: diff --git a/kde2/kioslave/kio_plp.h b/kde2/kioslave/kio_plp.h index 0112801..49176f0 100644 --- a/kde2/kioslave/kio_plp.h +++ b/kde2/kioslave/kio_plp.h @@ -28,50 +28,55 @@ #include #include +typedef QMap UidMap; + class PLPProtocol : public KIO::SlaveBase { - public: - PLPProtocol (const QCString &pool, const QCString &app ); - virtual ~PLPProtocol(); - - virtual void openConnection(); - virtual void closeConnection(); +public: + PLPProtocol (const QCString &pool, const QCString &app); + virtual ~PLPProtocol(); + + virtual void openConnection(); + virtual void closeConnection(); - virtual void setHost( const QString& host, int port, const QString& user, const QString& pass ); + virtual void setHost(const QString& host, int port, const QString&, const QString&); - virtual void put( const KURL& url, int _mode,bool _overwrite, bool _resume ); - virtual void get( const KURL& url ); - virtual void listDir( const KURL& url); - virtual void stat( const KURL & url); - virtual void mkdir( const KURL& url, int permissions ); - virtual void del( const KURL& url, bool isfile); - virtual void chmod(const KURL& url, int permissions ); - virtual void rename(const KURL &src, const KURL &dest, bool overwrite); - virtual void copy( const KURL& src, const KURL &dest, int mode, bool overwrite ); + virtual void put(const KURL& url, int _mode,bool _overwrite, bool _resume); + virtual void get(const KURL& url); + virtual void listDir(const KURL& url); + virtual void stat(const KURL & url); + virtual void mimetype(const KURL & url); + virtual void mkdir(const KURL& url, int permissions); + virtual void del(const KURL& url, bool isfile); + virtual void chmod(const KURL& url, int permissions); + virtual void rename(const KURL &src, const KURL &dest, bool overwrite); + virtual void copy(const KURL& src, const KURL &dest, int mode, bool overwrite ); - void calcprogress(long total); - private: - bool checkConnection(); + void calcprogress(long total); +private: + bool checkConnection(); - char driveChar(const QString& path); + char driveChar(const QString& path); - void createVirtualDirEntry(KIO::UDSEntry & entry, bool rdonly); - void completeUDSEntry(KIO::UDSEntry& entry, const long attr, const long size, const time_t date); - bool checkForError(Enum res); - bool isRomDrive(const QString& path); - bool isDrive(const QString& path); - bool isRoot(const QString& path); - void convertName(QString &path); - bool emitTotalSize(QString &name); + void createVirtualDirEntry(KIO::UDSEntry & entry, bool rdonly); + void completeUDSEntry(KIO::UDSEntry& entry, PlpDirent &e, bool rom); + bool checkForError(Enum res); + bool isRomDrive(const QString& path); + bool isDrive(const QString& path); + bool isRoot(const QString& path); + void convertName(QString &path); + bool emitTotalSize(QString &name); + QString uid2mime(PlpDirent &e); - rfsv *plpRfsv; - ppsocket *plpRfsvSocket; - QStringList drives; - QMap drivechars; - QString currentHost; - int currentPort; - time_t t_last; - time_t t_start; + rfsv *plpRfsv; + ppsocket *plpRfsvSocket; + QStringList drives; + QMap drivechars; + UidMap puids; + QString currentHost; + int currentPort; + time_t t_last; + time_t t_start; }; #endif -- cgit v1.2.3