Index: code/branches/chat/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.cc	(revision 6686)
+++ code/branches/chat/src/orxonox/ChatHistory.cc	(revision 6688)
@@ -27,37 +27,49 @@
  */
 
-#include <ChatHistory.h>
+#include "ChatHistory.h"
 
+#ifndef TEST
 namespace orxonox
 {
+#endif
   /* is this necessary? if yes uncomment please :P */
   //CreateFactory(ChatHistory);
 
   /* constructor */
+  #ifndef TEST
   ChatHistory(BaseObject* creator) : BaseObject(creator) 
+  #else
+  ChatHistory::ChatHistory()
+  #endif
   {
     /* register the object */
+    #ifndef TEST
     RegisterObject(ChatHistory);
+    #endif
+
+    this->hist_log_enabled = true;
 
     /* Read setting for logfiles */
-    if( true ) /* NOTE Make this a check for the logfile setting */
-      this->chat_hist_openlog();
+    if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
+    { this->chat_hist_openlog();
+
+      /* push starting line */
+      this->chat_hist_logline( "--- Logfile opened ---" );
+    }
 
     /* Read setting for maximum number of lines and set limit */
     this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
-
-    /* push starting line */
-    this->hist_buffer.push_front( "--- Logfile opened ---" )
   }
 
   /* destructor */
-  virtual ChatHistory::~ChatHistory()
+  ChatHistory::~ChatHistory()
   {
-    /* check if loggin is enabled */
-      /* y -> synchronize the logfile */
+    chat_hist_closelog();
+    
+    /* TODO clear list */
   }
 
   /* react to incoming chat */
-  virtual void ChatHistory::incomingChat(const std::string& message, 
+  void ChatHistory::incomingChat(const std::string& message, 
     unsigned int senderID)
   {
@@ -66,6 +78,7 @@
 
     /* format the message and senderID into a line */
-    std::string buf = "empty"; /* NOTE to be changed */
+    std::string buf = "" + senderID; /* NOTE to be changed */
 
+    /* TODO */
     /* --> a) look up the actual name of the sender */
     /* --> b) add sender name and string up with a separator
@@ -74,21 +87,27 @@
 
     /* add the line to the history */
-    this->chat_hist_addline( buf );
+    this->chat_hist_addline( buf + ": " + message );
 
     /* add the line to the log */
-    this->chat_hist_logline( buf );
+    this->chat_hist_logline( buf + ": " + message );
   } 
 
   /* Synchronize logfile onto the hard drive */ /* MARK MARK */
-  int ChatHistory::syncLog();
+  int ChatHistory::syncLog()
+  {
+    //if( this->hist_logfile )
+      //this->hist_logfile.sync();
+  }
 
   /* add a line to this history */
-  int ChatHistory::chat_hist_addline( const std::string& toadd );
+  int ChatHistory::chat_hist_addline( const std::string& toadd )
   {
+    /* crop history at the end if it's too large */
+    while( this->hist_buffer.size() > this->hist_maxlines+1 )
+      this->hist_buffer.pop_front();
+
     /* push to the front of the history */
-    this->hist_buffer.push_front( toadd );
+    this->hist_buffer.push_back( toadd );
 
-    /* crop history at the end if it's too large */
-    this->hist_buffer.resize( this->hist_maxlines );
   }
 
@@ -101,5 +120,5 @@
     /* output the line to the file if logging is enabled */
     if( this->hist_log_enabled )
-      this->hist_logfile << buf << std::endl;
+      this->hist_logfile << toadd << std::endl;
   }
 
@@ -111,5 +130,5 @@
      */
     this->hist_logfile.open( "/tmp/setsomepath.txt", 
-      fstream::out | fstream::app );
+      std::fstream::out | std::fstream::app );
 
     /* TODO check whether this works (not sure how you'd like it?) */
@@ -119,3 +138,28 @@
   }
 
+  /* close logfile */
+  void ChatHistory::chat_hist_closelog()
+  {
+    if( this->hist_logfile )
+    { this->chat_hist_logline( "--- Logfile closed ---" );
+      this->hist_logfile.close();
+    }
+  }
+
+  /* output history for debugging */
+  void ChatHistory::debug_printhist()
+  {
+    std::deque<std::string>::iterator it;
+
+    for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
+      ++it )
+      std::cout << *it << std::endl;
+
+    std::cout << "Size: " << hist_buffer.size() << std::endl;
+
+    
+  }
+
+#ifndef TEST
 }
+#endif
Index: code/branches/chat/src/orxonox/ChatHistory.h
===================================================================
--- code/branches/chat/src/orxonox/ChatHistory.h	(revision 6686)
+++ code/branches/chat/src/orxonox/ChatHistory.h	(revision 6688)
@@ -27,22 +27,43 @@
  */
 
-#include <list>
+#include <deque>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+#define TEST 0
+
+#ifndef TEST
 #include <core/BaseObject.h>
+#endif
 
 #ifndef _ChatHistory_H__
 #define _ChatHistory_H__
 
+
 /* Class to implement chat history */
+#ifndef TEST
 namespace orxonox
 {
+#endif
+
+  /* constructor */
+  #ifndef TEST
   class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener
+  #else
+  class ChatHistory 
+  #endif
   {
     public:
       /* constructors, destructors */
+      #ifndef TEST
       ChatHistory(BaseObject* creator);
+      #else
+      ChatHistory();
+      #endif
       virtual ~ChatHistory();
 
   
-    protected:
+    //protected:
       /** what to do with incoming chat 
        * 
@@ -58,9 +79,12 @@
        */
       int syncLog();
+
+      /** debug-print */
+      void debug_printhist();
       
     private:
       /* FIELDS */
       /** Vector to store the history in */
-      list<std::string> hist_buffer;
+      std::deque<std::string> hist_buffer;
 
       /** Maximum number of lines stored in this history */
@@ -74,5 +98,5 @@
 
       /** Output file stream for logfile */
-      ofstream hist_logfile;
+      std::ofstream hist_logfile;
 
 
@@ -99,6 +123,13 @@
        */
       int chat_hist_openlog();
-  }
+
+
+      /** close logfile */
+      void chat_hist_closelog();
+  };
+
+#ifndef TEST
 }
+#endif
 
 
