[mcrux] r163 committed - Adding Copy function

0 views
Skip to first unread message

mc...@googlecode.com

unread,
Nov 29, 2009, 3:01:16 AM11/29/09
to mcru...@googlegroups.com
Revision: 163
Author: mital.d.vora
Date: Sun Nov 29 00:00:53 2009
Log: Adding Copy function


http://code.google.com/p/mcrux/source/detail?r=163

Added:
/trunk/src/plugins/FileSystem/FileProps.cpp
/trunk/src/plugins/FileSystem/FileProps.h
Modified:
/trunk/src/lib/plugin/MCruxPluginManager.cpp
/trunk/src/plugins/FileSystem/FileSystemQtModule.cpp
/trunk/src/plugins/FileSystem/FileSystemQtModule.h
/trunk/src/plugins/FileSystem/FileUtils.cpp
/trunk/src/src.pro

=======================================
--- /dev/null
+++ /trunk/src/plugins/FileSystem/FileProps.cpp Sun Nov 29 00:00:53 2009
@@ -0,0 +1,58 @@
+/**
+* copyright (C) 2009 Mital Vora. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* 3. Neither the name of MCrux nor the names of its contributors may be
+* used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* @author: Mital Vora.
+**/
+
+#include "FileProps.h"
+
+static int myTypeID = qRegisterMetaType<FileProps*>();
+
+FileProps::FileProps(const FileInfo * _info)
+ : MQtModule(),
+ info(_info)
+{
+ this->setObjectName("fileSystem");
+ setProperties();
+}
+
+FileProps::FileProps(const FileProps & props)
+ : MQtModule(),
+ info(props.info)
+{
+ this->setObjectName("fileSystem");
+ setProperties();
+}
+
+
+FileProps::~FileProps()
+{
+}
+
+
+void FileProps::setProperties()
+{
+ string fileType = (info->fileType == FILETYPE_FILE) ? "file" : "dir";
+ double fileSize = info->fileSize;
+ double lastModifiedTime = info->lastModifiedTime;
+ double permissionMode = info->permissionMode;
+
+ setProperty("type", QVariant(QString(fileType.c_str())));
+ setProperty("size", QVariant(fileSize));
+ setProperty("last_modified_time", QVariant(lastModifiedTime));
+ setProperty("permission_mode", QVariant(permissionMode));
+}
+
=======================================
--- /dev/null
+++ /trunk/src/plugins/FileSystem/FileProps.h Sun Nov 29 00:00:53 2009
@@ -0,0 +1,53 @@
+/**
+ * copyright (C) 2009 Mital Vora. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of MCrux nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * @author: Mital Vora.
+ **/
+
+#ifndef _FILEPROPS_H_
+#define _FILEPROPS_H_
+
+#include <iostream>
+
+using namespace std;
+
+#include <QtGui/QtGui>
+
+#include <mcrux/qt/MQtModule.h>
+
+#include "FileUtils.h"
+
+class FileProps
+: public MQtModule
+{
+ Q_OBJECT
+
+public:
+
+ FileProps(const FileInfo * _info);
+ FileProps(const FileProps & props);
+ virtual ~FileProps();
+
+private:
+ const FileInfo * info;
+
+ void setProperties();
+};
+
+
+Q_DECLARE_METATYPE(FileProps*)
+
+#endif // _FILEPROPS_H_
=======================================
--- /trunk/src/lib/plugin/MCruxPluginManager.cpp Sat Nov 28 04:16:50 2009
+++ /trunk/src/lib/plugin/MCruxPluginManager.cpp Sun Nov 29 00:00:53 2009
@@ -133,14 +133,16 @@
bool MCruxPluginManager::injectPlugins(QWebView * webView)
{
MQtModule * mcrux = new MQtModule("mcrux");
-// FileSystemQtModule * fs = new FileSystemQtModule();
// QVariant v = (*fs);
-
- QVariant v = qVariantFromValue(new FileSystemQtModule());
- mcrux->setProperty("fileSystem", v);
+ //QVariant v = qVariantFromValue(new FileSystemQtModule());
+ // mcrux->setProperty("fileSystem", v);
+
QVariant v1(1);// = new Integer(1);
mcrux->setProperty("inte", v1);

webView->page()->mainFrame()->addToJavaScriptWindowObject(mcrux->objectName(),
mcrux);
+
+ FileSystemQtModule * fs = new FileSystemQtModule();
+
webView->page()->mainFrame()->addToJavaScriptWindowObject(fs->objectName(),
fs);
return true;
}

=======================================
--- /trunk/src/plugins/FileSystem/FileSystemQtModule.cpp Sat Nov 28
04:16:50 2009
+++ /trunk/src/plugins/FileSystem/FileSystemQtModule.cpp Sun Nov 29
00:00:53 2009
@@ -18,6 +18,7 @@
**/

#include "FileSystemQtModule.h"
+#include "FileUtils.h"

static int myTypeID = qRegisterMetaType<FileSystemQtModule*>();

@@ -29,3 +30,47 @@
FileSystemQtModule::~FileSystemQtModule()
{
}
+
+QString FileSystemQtModule::readFile(const QString &filePath)
+{
+ qDebug() << "FileSystemQtModule::readFile: " << filePath;
+ std::string filedata;
+ if (FileUtils::ReadFile(filePath.toStdString(), filedata))
+ {
+ return QString(filedata.c_str());
+ }
+ // TODO: throw exception
+ return QString("");
+}
+
+// bool readDirectory(const string& dirName, vector<string>& files);
+/*QList<QString> FileSystemQtModule::readDirectory(const QString& dirName)
+{
+ QList<QString> files;
+ vector<string> stdFiles;
+ if (FileUtils::readDirectory(dirName.toStdString(), stdFiles))
+ {
+ for(vector<string>::const_iterator
+ oIter = stdFiles.begin();
+ oIter != stdFiles.end();
+ oIter++)
+ {
+ files.push_back(QString(oIter->c_str()));
+ }
+ return files;
+ }
+ // TODO: throw Exception
+ return files;
+}
+
+QScriptValue FileSystemQtModule::getFileInfo(const QString& fileName)
+{
+ FileInfo * info = FileUtils::getFileInfo(fileName.toStdString());
+ FileProps prop(info);
+ return NULL;
+}
+ */
+bool FileSystemQtModule::copy(const QString& sourceFileName, const
QString& destFileName)
+{
+ return FileUtils::Copy(sourceFileName.toStdString(),
destFileName.toStdString());
+}
=======================================
--- /trunk/src/plugins/FileSystem/FileSystemQtModule.h Sat Nov 28 04:16:50
2009
+++ /trunk/src/plugins/FileSystem/FileSystemQtModule.h Sun Nov 29 00:00:53
2009
@@ -1,48 +1,46 @@
/**
-* copyright (C) 2009 Mital Vora. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* 3. Neither the name of MCrux nor the names of its contributors may be
-* used to endorse or promote products derived from this software
-* without specific prior written permission.
-*
-* @author: Mital Vora.
-**/
+ * copyright (C) 2009 Mital Vora. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of MCrux nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * @author: Mital Vora.
+ **/

#ifndef _FILESYSTEMQTMODULE_H_
#define _FILESYSTEMQTMODULE_H_

-#include <iostream>
-
-using namespace std;
-
-#include <QtGui/QtGui>
-
-#include <mcrux/qt/MQtModule.h>
+#include <QList>
+
+#include "FileProps.h"
+

class FileSystemQtModule
- : public MQtModule
+: public MQtModule
{
Q_OBJECT
+
public slots:

- QString *readFile(const QString &filePath)
- {
- qDebug() << "Param: " << filePath;
- return NULL;
- }
+ QString readFile(const QString &filePath);
+ bool copy(const QString& sourceFileName, const QString& destFileName);
+// QList<QString> readDirectory(const QString& dirName);
+// FileProps getFileInfo(const QString& fileName);
+
public:

- FileSystemQtModule();
- virtual ~FileSystemQtModule();
+ FileSystemQtModule();
+ virtual ~FileSystemQtModule();
};


=======================================
--- /trunk/src/plugins/FileSystem/FileUtils.cpp Sat Nov 28 04:16:50 2009
+++ /trunk/src/plugins/FileSystem/FileUtils.cpp Sun Nov 29 00:00:53 2009
@@ -17,19 +17,24 @@
* @author: Mital Vora.
**/

+#ifdef WIN32
#include "StdAfx.h"

-#include "FileUtils.h"
#include <io.h>
-#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "dirent.h"
#include <errno.h>
-
+#else // for linux
+
+#include <dirent.h>
+#endif
+
+#include <fcntl.h>
#include <fstream>

+#include "FileUtils.h"

bool FileUtils::readDirectory(const string& dirName, vector<string>& files)
{
@@ -55,16 +60,11 @@

FileInfo * FileUtils::getFileInfo(const string& fileName)
{
- if (_access(fileName.c_str(), 0) != 0)
- {
- return NULL;
- }
+ FileInfo * info = new FileInfo();

struct stat status;
stat(fileName.c_str(), &status);

- FileInfo * info = new FileInfo();
-
info->fileType = FILETYPE_FILE;
info->fileSize = status.st_size;
info->lastModifiedTime = status.st_mtime;
@@ -74,13 +74,14 @@
{
info->fileType = FILETYPE_DIRECTORY;
}
-
return info;
}


bool FileUtils::Copy(const string& sourceFileName, const string&
destFileName)
{
+
+ std::cout << "copy: "<< sourceFileName.c_str() << " to " <<
destFileName.c_str() << std::endl;
bool bRet = false;
char *buffer = NULL;

@@ -137,6 +138,7 @@
}
catch (...)
{
+ std::cout << "caught exception" << std::endl;
if (NULL != buffer)
{
delete [] buffer;
=======================================
--- /trunk/src/src.pro Sat Nov 28 04:16:50 2009
+++ /trunk/src/src.pro Sun Nov 29 00:00:53 2009
@@ -30,7 +30,9 @@
lib/window/MCruxWindowManager.h \
lib/plugin/MCruxPluginManager.h

-HEADERS += plugins/FileSystem/FileSystemQtModule.h
+HEADERS += plugins/FileSystem/FileSystemQtModule.h \
+ plugins/FileSystem/FileProps.h \
+ plugins/FileSystem/FileUtils.h

SOURCES += bin/mcrux_linux.cpp \
lib/MCrux.cpp \
@@ -44,4 +46,6 @@
lib/qt/MQtModule.cpp \
lib/plugin/MCruxPluginManager.cpp

-SOURCES += plugins/FileSystem/FileSystemQtModule.cpp
+SOURCES += plugins/FileSystem/FileSystemQtModule.cpp \
+ plugins/FileSystem/FileProps.cpp \
+ plugins/FileSystem/FileUtils.cpp
Reply all
Reply to author
Forward
0 new messages