Index: branches/qt_gui/src/lib/util/file.cc
===================================================================
--- branches/qt_gui/src/lib/util/file.cc	(revision 7615)
+++ branches/qt_gui/src/lib/util/file.cc	(revision 7616)
@@ -18,4 +18,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <stdio.h>
+
+#include <iostream>
+#include <fstream>
 
 #ifdef __unix__
@@ -27,125 +31,186 @@
 #endif
 
-
-
-File::File()
+#include <cassert>
+
+
+File::File(const std::string& fileName)
+{
+  this->_name = fileName;
+  File::homeDirCheck(this->_name);
+  this->init();
+}
+
+File::File(const File& file)
+{
+  this->_name = file._name;
+}
+
+File::~File()
+{
+  if (this->_status)
+    delete this->_status;
+  if (this->_handle)
+    assert(0);
+}
+
+/**
+ * @brief initializes the File
+ *
+ * Stats the File, looks if it exists and sets the hadle to 0
+ */
+void File::init()
+{
+  this->_handle = 0;
+
+  this->_status = new struct stat;
+  if (stat(this->_name.c_str(), this->_status))
+  {
+    delete this->_status;
+    this->_status = NULL;
+  }
+}
+
+bool File::open(OpenMode mode)
 {
 #warning implement
 }
 
-File::File(const std::string& fileName)
+bool File::close()
 {
 #warning implement
 }
 
-File::File(const File& file)
-{
-#warning implement
-}
-
-File::~File()
-{
-#warning implement
-}
-
-bool File::open(OpenMode mode)
-{
-#warning implement
-}
-
-bool File::close()
-{
-#warning implement
-}
-
 int File::handle()
 {
-#warning implement
+  return this->_handle;
 }
 
 bool File::exists()
 {
-#warning implement
+  return (this->_status != NULL);
 }
 
 bool File::isLink()
 {
-#warning implement
+#ifndef __WIN32__
+  return (this->_status != NULL && this->_status->st_mode & (S_IFLNK));
+#else
+  return false;
+#endif
 }
 // only on UNIX
+
 bool File::isFile()
 {
-#warning implement
-}
-
+  return (this->_status != NULL && this->_status->st_mode & (S_IFREG));
+}
+
+/**
+ * @brief Checks if it is a Directory
+ * @param directoryName the Directory to check for
+ * @returns true if it is a directory/symlink false otherwise
+ */
 bool File::isDirectory()
 {
-  std::string tmpDirName = this->_name;
-  struct stat status;
-
   // checking for the termination of the string given. If there is a "/" at the end cut it away
-  if (this->_name[this->_name.size()-1] == '/' ||
-      this->_name[this->_name.size()-1] == '\\')
-  {
-    tmpDirName.erase(tmpDirName.size()-1);
-  }
-
-  if(!stat(tmpDirName.c_str(), &status))
-  {
-    if (status.st_mode & (S_IFDIR
-#ifndef __WIN32__
-        | S_IFLNK
-#endif
-                         ))
-    {
-      return true;
-    }
-    else
-      return false;
-  }
-  else
+  //if (this->_name[this->_name.size()-1] == '/' ||
+  //    this->_name[this->_name.size()-1] == '\\')
+  //{
+  //  tmpDirName.erase(tmpDirName.size()-1);
+  //}
+  return (this->_status != NULL && this->_status->st_mode & (S_IFDIR));
+}
+
+
+/// FIXME NEXT THREE FUNCTIONS
+bool File::isReadeable()
+{
+#ifndef __WIN32__
+  return (this->_status != NULL && this->_status->st_mode & (S_IRUSR));
+#else
+  return (this->_status != NULL);
+#endif
+}
+
+bool File::isWriteable()
+{
+#ifndef __WIN32__
+  return (this->_status != NULL && this->_status->st_mode & (S_IWUSR));
+#else
+  return (this->_status != NULL);
+#endif
+}
+bool File::isExecutable()
+{
+#ifndef __WIN32__
+  return (this->_status != NULL && this->_status->st_mode & (S_IXUSR));
+#else
+  return (this->_status != NULL);
+#endif
+}
+
+
+bool File::copy(const File& destination)
+{
+  char ch;
+  std::ifstream iFile(this->_name.c_str());
+  std::ofstream oFile(destination.name().c_str());
+  while (iFile.get(ch))
+  {
+    oFile.put(ch);
+  }
+}
+
+bool File::rename(const File& destination)
+{
+  if (!std::rename(this->_name.c_str(), destination.name().c_str()))
+  {
+    this->close();
+    delete this->_status;
+    this->_status = NULL;
+    this->_name = destination.name();
+    this->init();
+
+    return true;
+  }
+  return false;
+}
+
+bool File::touch()
+{
+  FILE* stream;
+  if( (stream = fopen (this->_name.c_str(), "w")) == NULL)
+  {
+    std::cout << "could not touch '" << this->_name << "' for writing\n";
     return false;
-}
-
-bool File::isReadeable()
-{
-
-#warning implement
-}
-
-bool File::isWriteable()
-{
-#warning implement
-}
-bool File::isExecutable()
-{
-#warning implement
-}
-
-
-bool File::copy(const File& destination)
-{
-#warning implement
-}
-bool File::rename(const File& destination)
-{
-#warning implement
-}
-bool File::touch()
-{
-#warning implement
-}
+  }
+  fclose(stream);
+  return true;
+}
+
 bool File::remove()
 {
-#warning implement
+  unlink(this->_name.c_str());
+  delete this->_status;
+  this->_status = NULL;
+  /// FIXME HANDLE
 }
 
 void File::relToAbs(std::string& fileName)
 {
-#warning implement
-}
+  if (fileName.empty())
+    return ;
+  if (fileName[0] !=  '/')
+  {
+    if (fileName[0] == '.' && fileName[1] != '.')
+      fileName.erase(0);
+    fileName = File::cwd() + fileName;
+  }
+}
+
 void File::absToRel(std::string& fileName)
 {
-#warning implement
+  if (fileName.find(cwd()) == 0)
+    fileName.replace(0, File::cwd().size(), ".");
 }
 
@@ -173,4 +238,17 @@
 
 
+void File::homeDirCheck(std::string& fileName)
+{
+  if (fileName.size() < 2 || fileName[0] != '~' || fileName[1] != '/')
+    return;
+  std::string homeDir;
+#ifdef __WIN32__
+    homeDir = getenv("USERPROFILE");
+#else
+    homeDir = getenv("HOME");
+#endif
+    fileName = homeDir + fileName.substr(1);
+}
+
 
 #include "file.h"
