Update list of wide characters
[centerim5.git] / src / CenterIM.h
blobb0cc3b1ae1694d5c7ba861e106961de14bd89c9a
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 CenterIM. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CENTERIM_H
20 #define CENTERIM_H
22 #include <cppconsui/CoreManager.h>
23 #include <cppconsui/CppConsUI.h>
24 #include <libpurple/purple.h>
25 #include <vector>
27 #define CONF_PREFIX "/centerim5"
28 #define CONF_PLUGINS_PREF CONF_PREFIX "/plugins"
29 #define CONF_PLUGINS_SAVE_PREF CONF_PLUGINS_PREF "/loaded"
31 #define CENTERIM (CenterIM::instance())
33 class CenterIM : public CppConsUI::InputProcessor {
34 public:
35 enum ScreenArea {
36 BUDDY_LIST_AREA,
37 CHAT_AREA,
38 FOOTER_AREA,
39 HEADER_AREA,
40 LOG_AREA,
41 WHOLE_AREA,
42 AREAS_NUM
45 // Color schemes. Keep synchronized with scheme_names.
46 enum Scheme {
47 SCHEME_BEGIN = 1,
48 SCHEME_ACCOUNTSTATUSMENU = SCHEME_BEGIN,
49 SCHEME_BUDDYLIST,
50 SCHEME_BUDDYLISTBUDDY,
51 SCHEME_BUDDYLISTBUDDY_AWAY,
52 SCHEME_BUDDYLISTBUDDY_NA,
53 SCHEME_BUDDYLISTBUDDY_OFFLINE,
54 SCHEME_BUDDYLISTBUDDY_ONLINE,
55 SCHEME_BUDDYLISTCHAT,
56 SCHEME_BUDDYLISTCONTACT,
57 SCHEME_BUDDYLISTCONTACT_AWAY,
58 SCHEME_BUDDYLISTCONTACT_NA,
59 SCHEME_BUDDYLISTCONTACT_OFFLINE,
60 SCHEME_BUDDYLISTCONTACT_ONLINE,
61 SCHEME_BUDDYLISTGROUP,
62 SCHEME_CONVERSATION,
63 SCHEME_CONVERSATION_ACTIVE,
64 SCHEME_CONVERSATION_NEW,
65 SCHEME_FOOTER,
66 SCHEME_GENERALMENU,
67 SCHEME_GENERALWINDOW,
68 SCHEME_HEADER,
69 SCHEME_HEADER_REQUEST,
70 SCHEME_LOG,
72 SCHEME_END,
75 static CenterIM *instance();
77 // InputProcessor
78 virtual bool processInput(const TermKeyKey &key) override;
80 void quit();
82 // Returns a position and size of a selected area.
83 CppConsUI::Rect getScreenArea(ScreenArea area);
84 CppConsUI::Rect getScreenAreaCentered(ScreenArea area);
86 static const char *const version_;
88 bool loadColorSchemeConfig();
89 bool loadKeyConfig();
91 bool isEnabledExpandedConversationMode() const { return convs_expanded_; }
93 sigc::connection timeoutConnect(const sigc::slot<bool> &slot,
94 unsigned interval, int priority = G_PRIORITY_DEFAULT);
95 sigc::connection timeoutOnceConnect(const sigc::slot<void> &slot,
96 unsigned interval, int priority = G_PRIORITY_DEFAULT);
98 private:
99 struct IOClosurePurple {
100 PurpleInputFunction function;
101 guint result;
102 gpointer data;
104 IOClosurePurple() : function(nullptr), result(0), data(nullptr) {}
107 GMainLoop *mainloop_;
108 bool mainloop_error_exit_;
109 CppConsUI::CoreManager *mngr_;
110 // Flag indicating if the conversation full-screen mode is activated.
111 bool convs_expanded_;
112 // Flag indicating if idle reporting is based on keyboard presses.
113 bool idle_reporting_on_keyboard_;
115 guint stdin_timeout_id_;
116 int resize_pipe_[2];
117 volatile bool resize_pending_;
118 const char *sigwinch_write_error_;
119 std::size_t sigwinch_write_error_size_;
121 PurpleCoreUiOps centerim_core_ui_ops_;
122 PurpleDebugUiOps logbuf_debug_ui_ops_;
123 PurpleEventLoopUiOps centerim_glib_eventloops_;
125 CppConsUI::Rect areas_[AREAS_NUM];
127 static const char *color_names_[];
128 static const char *scheme_names_[];
130 static CenterIM *my_instance_;
132 CenterIM();
133 virtual ~CenterIM() {}
134 CONSUI_DISABLE_COPY(CenterIM);
136 static int run(int argc, char *argv[]);
137 friend int main(int argc, char *argv[]);
139 int runAll(int argc, char *argv[]);
140 void printUsage(FILE *out, const char *prg_name);
141 void printVersion(FILE *out);
142 int initializePurple(const char *config_path);
143 void finalizePurple();
144 void initializePreferences();
146 int initializeScreenResizing();
147 void finalizeScreenResizing();
149 // Recalculates area sizes to fit into current screen size.
150 void onScreenResized();
152 void onTopWindowChanged();
154 // PurpleEventLoopUiOps callbacks.
155 // Adds IO watch to glib main loop context.
156 static guint input_add_purple(int fd, PurpleInputCondition condition,
157 PurpleInputFunction function, gpointer data);
159 // Helper functions for input_add_purple().
160 // Processes IO input to purple callback.
161 static gboolean io_input_purple(
162 GIOChannel *source, GIOCondition condition, gpointer data);
163 // Destroyes libpurple IO input callback internal data.
164 static void io_destroy_purple(gpointer data);
166 static gboolean stdin_bytes_available_(
167 GIOChannel * /*source*/, GIOCondition /*condition*/, gpointer data)
169 return reinterpret_cast<CenterIM *>(data)->stdin_bytes_available();
171 gboolean stdin_bytes_available();
172 static gboolean stdin_timeout_(gpointer data)
174 return reinterpret_cast<CenterIM *>(data)->stdin_timeout();
176 gboolean stdin_timeout();
178 static gboolean resize_bytes_available_(
179 GIOChannel * /*source*/, GIOCondition /*condition*/, gpointer data)
181 return reinterpret_cast<CenterIM *>(data)->resize_bytes_available();
183 gboolean resize_bytes_available();
185 // Draws everything.
186 static gboolean draw_(gpointer data)
188 return reinterpret_cast<CenterIM *>(data)->draw();
190 gboolean draw();
192 static void sigwinch_handler_(int signum)
194 CENTERIM->sigwinch_handler(signum);
196 void sigwinch_handler(int signum);
198 // CppConsUI callbacks.
199 // Registers a redraw request.
200 void redraw_cppconsui();
201 // Logs a debug message produced by CppConsUI.
202 void log_debug_cppconsui(const char *message);
204 // PurpleCoreUiOps callbacks.
205 // Returns information about CenterIM such as name, website etc.
206 static GHashTable *get_ui_info();
208 // PurpleDebugUiOps callbacks.
209 static void purple_print(
210 PurpleDebugLevel level, const char *category, const char *arg_s);
211 static gboolean purple_is_enabled(
212 PurpleDebugLevel level, const char *category);
214 // Called when the CONF_PREFIX/dimensions preferences change their values.
215 static void dimensions_change_(
216 const char *name, PurplePrefType type, gconstpointer val, gpointer data)
218 reinterpret_cast<CenterIM *>(data)->dimensions_change(name, type, val);
220 void dimensions_change(
221 const char *name, PurplePrefType type, gconstpointer val);
223 // Called when the /libpurple/away/idle_reporting preference changes its
224 // value.
225 static void idle_reporting_change_(
226 const char *name, PurplePrefType type, gconstpointer val, gpointer data)
228 reinterpret_cast<CenterIM *>(data)->idle_reporting_change(name, type, val);
230 void idle_reporting_change(
231 const char *name, PurplePrefType type, gconstpointer val);
233 // Config handling.
234 void loadDefaultColorSchemeConfig();
235 bool saveColorSchemeConfig();
236 const char *schemeToString(int scheme);
237 int stringToScheme(const char *str);
238 char *colorToString(int color);
239 bool stringToColor(const char *str, int *color);
240 char *colorAttributesToString(int attrs);
241 bool stringToColorAttributes(const char *str, int *attrs);
242 void loadDefaultKeyConfig();
243 bool saveKeyConfig();
245 void actionFocusBuddyList();
246 void actionFocusActiveConversation();
247 void actionOpenAccountStatusMenu();
248 void actionOpenGeneralMenu();
249 void actionBuddyListToggleOffline();
250 void actionFocusPrevConversation();
251 void actionFocusNextConversation();
252 void actionFocusConversation(int i);
253 void actionExpandConversation();
255 void declareBindables();
258 #endif // CENTERIM_H
260 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: