From: hama Date: Wed, 4 Nov 2015 23:12:54 +0000 (+0100) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=58c4b3d2c173fbd0a0765490e3cd0584e312de80;p=reqt dayly work --- diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index dd93aec..3e9aa57 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -441,6 +441,72 @@ QByteArray ReFileUtils::replaceExtension(const char* path, const char* ext) { } return rc; } + +/** + * Splits an URL into its parts. + * + * Examples: + *
url: "file:///path/name.ext"
+ * protocol: "file:" host: "//" path: "/path/" node: "name.ext" param: ""
+ *
+ * url: "http://b2.de/xy/index.htm?id=1"
+ * protocol: "http:" host: "//b2.de" path: "/xy/" node: "index.htm" param: "?id=1"
+ * 
+ * + * @param url the URL to split + * @param protocol OUT: NULL or the protocol + * @param host OUT: NULL or the host part + * @param path OUT: NULL or the path without the last node + * @param node OUT: NULL or the last node of the path + */ +void ReFileUtils::splitUrl(const QString& url, QString* protocol, QString* host, + QString* path, QString* node, QString* params){ + if (protocol != NULL) + *protocol = ReQStringUtils::m_empty; + if (host != NULL) + *host = ReQStringUtils::m_empty; + if (path != NULL) + *path = ReQStringUtils::m_empty; + if (params != NULL) + *params = ReQStringUtils::m_empty; + int ix = url.indexOf(':'); + if (ix < 0){ + ix = 0; + } else { + ix++; + if (protocol != NULL) + *protocol = url.mid(0, ix); + } + int start = ix; + if (url.length() >= start + 2 && url.at(start) == '/' && url.at(start + 1) == '/'){ + ix = url.indexOf("/", start + 2); + if (ix < 0) + ix = 2; + if (host != NULL) + *host = url.mid(start, ix); + start = ix; + } + ix = url.lastIndexOf(OS_SEPARATOR); + if (ix < 0) + ix = url.lastIndexOf(OS_2nd_SEPARATOR); + if (ix >= 0){ + ix++; + if (path != NULL) + *path = url.mid(start, ix); + start = ix; + } + ix = url.indexOf('?', start); + if (ix < 0){ + if (node != NULL) + *node = url.mid(start); + } else { + if (node != NULL) + *node = url.mid(start, ix); + if (params != NULL) + *params = url.mid(ix); + } +} + /** * Sets the filetimes. * diff --git a/base/ReFileUtils.hpp b/base/ReFileUtils.hpp index 1de0e25..dec87d8 100644 --- a/base/ReFileUtils.hpp +++ b/base/ReFileUtils.hpp @@ -47,6 +47,8 @@ public: static int seek(FILE* file, int64_t offset, int whence); static bool setTimes(const char* filename, const QDateTime& modified, const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL); + static void splitUrl(const QString& url, QString* protocol, QString* host, + QString* path, QString* node, QString* params = NULL); static int64_t tell(FILE* file); static QByteArray tempDir(const char* node, const char* parent = NULL, bool withSeparator = true); diff --git a/cunit/cuReFileUtils.cpp b/cunit/cuReFileUtils.cpp index e58e839..e321841 100644 --- a/cunit/cuReFileUtils.cpp +++ b/cunit/cuReFileUtils.cpp @@ -296,8 +296,36 @@ public: checkReplaceExt("/abc.1/def.123", "/abc.1/def.xyz", ".123", __LINE__); checkReplaceExt("/abc.1/def.123", "/abc.1/def", ".123", __LINE__); } + void checkUrl(const char* url, const char* expProto, char* expHost, + const char* expPath, const char* expNode, const char* expParams){ + QString protocol, host, path, node, params; + ReFileUtils::splitUrl(QString(url), &protocol, &host, &path, &node, ¶ms); + checkEqu(expProto, protocol); + checkEqu(expHost, host); + checkEqu(expPath, path); + checkEqu(expNode, node); + checkEqu(expParams, params); + } + void testSplitUrl(){ + checkUrl("file:///abc/def.x", "file:", "//", "/abc", "def.x", ""); + checkUrl("file:/abc/def.x", "file:", "", "/abc", "def.x", ""); + checkUrl("///abc/def.x", "", "//", "/abc", "def.x", ""); + checkUrl("/abc/def.x", "", "", "/abc", "def.x", ""); + checkUrl("/def.x", "", "", "/", "def.x", ""); + checkUrl("def.x", "", "", "", "def.x", ""); + + checkUrl("http://b2.de/public/index.htm?id=1", "http:", "//b2.de", "/public/", + "index.htm", "?id=1"); + checkUrl("http://b2.de/index.htm?id=1", "http:", "//b2.de", "/", + "index.htm", "?id=1"); + checkUrl("http:index.htm?id=1", "http:", "", "", + "index.htm", "?id=1"); + checkUrl("http:index.htm", "http:", "", "", + "index.htm", ""); + } virtual void run() { + testSplitUrl(); testParentOf(); testCleanPath(); testReplaceExtension(); diff --git a/guiwidget/ReFileTable.cpp b/guiwidget/ReFileTable.cpp index 2fcd940..1d699a0 100644 --- a/guiwidget/ReFileTable.cpp +++ b/guiwidget/ReFileTable.cpp @@ -157,6 +157,36 @@ void ReFileTable::fileDragging(){ } } +/** + * Copies the selected files into the clipboard. + * + * @param currentRow the row where the context menu is called + */ +void ReFileTable::copyFromClipboard(int currentRow){ + QClipboard *clipboard = QApplication::clipboard(); + const QMimeData *mimeData = clipboard->mimeData(); + ReFileSystem* source = NULL; + if (! mimeData->hasUrls()) + say(LOG_INFO, tr("No files in clipboard")); + else { + QList urls = mimeData->urls(); + QList::const_iterator it; + QString path, node; + for (it = urls.cbegin(); it != urls.cend(); ++it){ + QString url = it->url(); + if (source == NULL){ + if ( (source = ReFileSystem::buildFromUrl(url)) == NULL){ + say(LOG_ERROR, tr("unknown filesystem: %1").arg(url)); + break; + } + } + ReFileUtils::splitUrl2(NULL, &path, &node); + fileSystem->copy() + + } + } +} + /** * Copies the selected files into the clipboard. * diff --git a/guiwidget/ReFileTable.hpp b/guiwidget/ReFileTable.hpp index b634643..ce9942f 100644 --- a/guiwidget/ReFileTable.hpp +++ b/guiwidget/ReFileTable.hpp @@ -40,6 +40,7 @@ public slots: protected: QString buildAbsPath(int row, bool withNode = false, bool uriFormat = false); QString cellAsText(int row, int col); + void copyFromClipboard(int currentRow); void copyToClipboard(int currentRow = -1, const QString& full = ReQStringUtils::m_empty); void openEntry(int row); diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 7638e6d..5a58b7f 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -66,6 +66,25 @@ int ReFileSystem::blocksize() const { return m_blocksize; } +/** + * Returns a filesystem given by an URL. + * + * @param url the url with infos about a filesystem + * @return NULL: unknown filesystem
+ * otherwise: the filesystem described in the URL + */ +ReFileSystem* ReFileSystem::buildFromUrl(const QString& url) +{ + ReFileSystem* rc = NULL; + if (url.startsWith("file:")){ +#if defined __linux__ + rc = new ReLocalFileSystem("/", ReLogger::globalLogger()); +#elif defined __WIN32__ +#error "missing evaluating drive" +#endif + } +} + /** * Copy a file from a source filesystem to the current directory of the instance. * diff --git a/os/ReFileSystem.hpp b/os/ReFileSystem.hpp index 01f9795..946373e 100644 --- a/os/ReFileSystem.hpp +++ b/os/ReFileSystem.hpp @@ -160,8 +160,8 @@ public: void setOsPermissions(const ReOSPermissions& osPermissions); void setWriteable(bool writeable); bool writeable() const; - - +public: + static ReFileSystem* buildFromUrl(const QString& url); protected: QString m_name; #ifdef __linux__ @@ -199,7 +199,6 @@ public: ReFileMetaData& target, bool force = false); virtual ErrorCode write(const QString& target, int64_t offset, const QByteArray& buffer); - protected: QString m_basePath; QDir m_dir;