]> gitweb.hamatoma.de Git - reqt/commitdiff
dayly work
authorhama <hama@siduction.net>
Wed, 4 Nov 2015 23:12:54 +0000 (00:12 +0100)
committerhama <hama@siduction.net>
Wed, 4 Nov 2015 23:12:54 +0000 (00:12 +0100)
base/ReFileUtils.cpp
base/ReFileUtils.hpp
cunit/cuReFileUtils.cpp
guiwidget/ReFileTable.cpp
guiwidget/ReFileTable.hpp
os/ReFileSystem.cpp
os/ReFileSystem.hpp

index dd93aec7c96d6382c724b27902d583bc154282ed..3e9aa57be067ca41d58c65e027e5b5ef505ebcf2 100644 (file)
@@ -441,6 +441,72 @@ QByteArray ReFileUtils::replaceExtension(const char* path, const char* ext) {
        }
        return rc;
 }
+
+/**
+ * Splits an URL into its parts.
+ *
+ * Examples:
+ * <pre>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"
+ * </pre>
+ *
+ * @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.
  *
index 1de0e252d65373f5e448f43fbdcd2e3b9516b708..dec87d80439dd279f3e55dd0711f50d11db5c5f8 100644 (file)
@@ -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);
index e58e839af94e4493f1626d5dd5f7a94fa900c20f..e321841f38d3218393d33cada44986a4662e259f 100644 (file)
@@ -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, &params);
+               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();
index 2fcd940f8a46f02580192532f090378f33c17f3c..1d699a0ff7fbd3c51d1666370beeefbd6d41962b 100644 (file)
@@ -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<Url> urls = mimeData->urls();
+               QList<Url>::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.
  *
index b634643a2f38806e817b905907bbc0a725fb8bb7..ce9942fc2dd9c64b07f6806eaa630e9152e27293 100644 (file)
@@ -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);
index 7638e6d89d377494a47d6b8a448ca1f1bc7dd0cb..5a58b7f382713977f8357acb0205b50d9babda31 100644 (file)
@@ -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             <code>NULL</code>: unknown filesystem<br>
+ *                             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.
  *
index 01f9795ca6bc7b4e402493456d7871f2e0e86ff9..946373e64b885773d75af532324cd09e9c16786a 100644 (file)
@@ -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;