}
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.
*
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);
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();
}
}
+/**
+ * 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.
*
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);
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.
*
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__
ReFileMetaData& target, bool force = false);
virtual ErrorCode write(const QString& target, int64_t offset,
const QByteArray& buffer);
-
protected:
QString m_basePath;
QDir m_dir;