00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/recorder.h"
00023
00024 #include "gui/chat.h"
00025
00026 #include "gui/widgets/button.h"
00027 #include "gui/widgets/chattab.h"
00028 #include "gui/widgets/layout.h"
00029 #include "gui/widgets/windowcontainer.h"
00030
00031 #include "utils/stringutils.h"
00032
00033 #include <physfs.h>
00034
00035 Recorder::Recorder(ChatWindow *chat, const std::string &title,
00036 const std::string &buttonTxt) :
00037 Window(title)
00038 {
00039 setWindowName("Recorder");
00040 const int offsetX = 2 * getPadding() + 10;
00041 const int offsetY = getTitleBarHeight() + getPadding() + 10;
00042
00043 mChat = chat;
00044 Button *button = new Button(buttonTxt, "activate", this);
00045
00046
00047
00048 setDefaultSize(button->getWidth() + offsetX, button->getHeight() +
00049 offsetY, ImageRect::LOWER_LEFT, 0, 123);
00050
00051 place(0, 0, button);
00052
00053 Layout &layout = getLayout();
00054 layout.setRowHeight(0, Layout::AUTO_SET);
00055
00056 loadWindowState();
00057 }
00058
00059 Recorder::~Recorder()
00060 {
00061 }
00062
00063 void Recorder::record(const std::string &msg)
00064 {
00065 if (mStream.is_open())
00066 {
00067 mStream << msg << std::endl;
00068 }
00069 }
00070
00071 void Recorder::setRecordingFile(const std::string &msg)
00072 {
00073 std::string msgCopy = msg;
00074 trim(msgCopy);
00075
00076 if (msgCopy.empty())
00077 {
00078 if (mStream.is_open())
00079 {
00080 mStream.close();
00081 setVisible(false);
00082
00083
00084
00085
00086
00087 localChatTab->chatLog(_("Finishing recording."), BY_SERVER);
00088 }
00089 else
00090 {
00091 localChatTab->chatLog(_("Not currently recording."), BY_SERVER);
00092 }
00093 }
00094 else if (mStream.is_open())
00095 {
00096 localChatTab->chatLog(_("Already recording."), BY_SERVER);
00097 }
00098 else
00099 {
00100
00101
00102
00103
00104 localChatTab->chatLog(_("Starting to record..."), BY_SERVER);
00105 const std::string file =
00106 std::string(PHYSFS_getUserDir()) + "/.tmw/" + msgCopy;
00107
00108 mStream.open(file.c_str(), std::ios_base::trunc);
00109
00110 if (mStream.is_open())
00111 setVisible(true);
00112 else
00113 localChatTab->chatLog(_("Failed to start recording."), BY_SERVER);
00114 }
00115 }
00116
00117 void Recorder::action(const gcn::ActionEvent &event)
00118 {
00119 setRecordingFile("");
00120 }