Improve error reporting from the curses wrapper
[centerim5.git] / src / Conversation.h
blob4553d3d7e909f70e43bc3aa800d394df6b12bfbe
1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 //
4 // This file is part of CenterIM.
5 //
6 // CenterIM is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // CenterIM is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CONVERSATION_H
20 #define CONVERSATION_H
22 #include "Log.h"
23 #include "ConversationRoomList.h"
25 #include <cppconsui/AbstractLine.h>
26 #include <cppconsui/VerticalLine.h>
27 #include <cppconsui/TextEdit.h>
28 #include <cppconsui/TextView.h>
29 #include <cppconsui/Window.h>
30 #include <libpurple/purple.h>
32 class Conversation : public CppConsUI::Window {
33 public:
34 Conversation(PurpleConversation *conv);
35 virtual ~Conversation();
37 // InputProcessor
38 virtual bool processInput(const TermKeyKey &key);
40 // Widget
41 virtual void moveResize(int newx, int newy, int neww, int newh);
42 virtual bool restoreFocus();
43 virtual void ungrabFocus();
45 // Window
46 virtual void show();
47 virtual void close();
48 virtual void onScreenResized();
50 void write(const char *name, const char *alias, const char *message,
51 PurpleMessageFlags flags, time_t mtime);
53 PurpleConversation *getPurpleConversation() const { return conv_; };
55 ConversationRoomList *getRoomList() const { return room_list_; };
57 protected:
58 class ConversationLine : public CppConsUI::AbstractLine {
59 public:
60 ConversationLine(const char *text);
61 virtual ~ConversationLine();
63 // Widget
64 virtual int draw(CppConsUI::Curses::ViewPort area, CppConsUI::Error &error);
66 protected:
67 char *text_;
68 size_t text_width_;
70 private:
71 CONSUI_DISABLE_COPY(ConversationLine);
74 CppConsUI::TextView *view_;
75 CppConsUI::TextEdit *input_;
76 ConversationLine *line_;
78 PurpleConversation *conv_;
80 char *filename_;
81 GIOChannel *logfile_;
83 size_t input_text_length_;
85 // Only PURPLE_CONV_TYPE_CHAT have a room list.
86 ConversationRoomList *room_list_;
87 CppConsUI::VerticalLine *room_list_line_;
89 char *stripHTML(const char *str) const;
90 void destroyPurpleConversation(PurpleConversation *conv);
91 void buildLogFilename();
92 char *extractTime(time_t sent_time, time_t show_time) const;
93 void loadHistory();
94 bool processCommand(const char *raw, const char *html);
95 void onInputTextChange(CppConsUI::TextEdit &activator);
97 void actionSend();
99 private:
100 Conversation();
101 CONSUI_DISABLE_COPY(Conversation);
103 void declareBindables();
106 #endif // CONVERSATION_H
108 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: