Update AUTHORS file
[centerim5.git] / src / CenterIM.h
blobcfb86eecce2bc396980742305ab7b74217a0e3f1
1 /*
2 * Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
3 * Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
5 * This file is part of CenterIM.
7 * CenterIM is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * CenterIM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef __CENTERIM_H__
23 #define __CENTERIM_H__
25 #ifdef __GNUC__
26 #define _attribute(x) __attribute__(x)
27 #else
28 #define _attribute(x)
29 #endif
31 #include <cppconsui/CoreManager.h>
32 #include <cppconsui/CppConsUI.h>
33 #include <libpurple/purple.h>
34 #include <vector>
36 #define CONF_PREFIX "/centerim5"
37 #define CONF_PLUGINS_PREF CONF_PREFIX "/plugins"
38 #define CONF_PLUGINS_SAVE_PREF CONF_PLUGINS_PREF "/loaded"
40 #define CENTERIM (CenterIM::instance())
42 class CenterIM : public CppConsUI::InputProcessor {
43 public:
44 enum ScreenArea {
45 BUDDY_LIST_AREA,
46 CHAT_AREA,
47 FOOTER_AREA,
48 HEADER_AREA,
49 LOG_AREA,
50 WHOLE_AREA,
51 AREAS_NUM
54 static CenterIM *instance();
56 // InputProcessor
57 virtual bool processInput(const TermKeyKey &key);
59 void quit();
61 // returns a position and size of a selected area
62 CppConsUI::Rect getScreenArea(ScreenArea area);
63 CppConsUI::Rect getScreenAreaCentered(ScreenArea area);
65 static const char *const version;
67 bool loadColorSchemeConfig();
68 bool loadKeyConfig();
70 bool isEnabledExpandedConversationMode() const { return convs_expanded; }
72 sigc::connection timeoutConnect(const sigc::slot<bool> &slot,
73 unsigned interval, int priority = G_PRIORITY_DEFAULT);
74 sigc::connection timeoutOnceConnect(const sigc::slot<void> &slot,
75 unsigned interval, int priority = G_PRIORITY_DEFAULT);
77 protected:
78 private:
79 struct IOClosurePurple {
80 PurpleInputFunction function;
81 guint result;
82 gpointer data;
84 IOClosurePurple() : function(NULL), result(0), data(NULL) {}
87 struct IOClosureCppConsUI {
88 CppConsUI::InputFunction function;
89 guint result;
90 gpointer data;
92 IOClosureCppConsUI() : function(NULL), result(0), data(NULL) {}
95 struct SourceClosureCppConsUI {
96 CppConsUI::SourceFunction function;
97 void *data;
99 SourceClosureCppConsUI() : function(NULL), data(NULL) {}
102 GMainLoop *mainloop;
103 CppConsUI::CoreManager *mngr;
104 sigc::connection resize_conn;
105 sigc::connection top_window_change_conn;
106 // flag indicating if the conversation full-screen mode is activated
107 bool convs_expanded;
108 // flag indicating if idle reporting is based on keyboard presses
109 bool idle_reporting_on_keyboard;
111 PurpleCoreUiOps centerim_core_ui_ops;
112 PurpleDebugUiOps logbuf_debug_ui_ops;
113 PurpleEventLoopUiOps centerim_glib_eventloops;
115 CppConsUI::Rect areas[AREAS_NUM];
117 static const char *named_colors[];
119 static CenterIM *my_instance;
121 CenterIM();
122 virtual ~CenterIM() {}
123 CONSUI_DISABLE_COPY(CenterIM);
125 static int run(int argc, char *argv[]);
126 friend int main(int argc, char *argv[]);
128 int runAll(int argc, char *argv[]);
129 void printUsage(FILE *out, const char *prg_name);
130 void printVersion(FILE *out);
131 int purpleInit(const char *config_path);
132 void purpleFinalize();
133 void prefsInit();
135 // recalculates area sizes to fit into current screen size
136 void onScreenResized();
138 void onTopWindowChanged();
140 // PurpleEventLoopUiOps callbacks
141 // adds IO watch to glib main loop context
142 static guint input_add_purple(int fd, PurpleInputCondition condition,
143 PurpleInputFunction function, gpointer data);
145 // helper functions for input_add_purple()
146 // process IO input to purple callback
147 static gboolean io_input_purple(
148 GIOChannel *source, GIOCondition condition, gpointer data);
149 // destroyes libpurple IO input callback internal data
150 static void io_destroy_purple(gpointer data);
152 // CppConsUI callbacks
153 // adds IO watch to glib main loop context
154 static unsigned input_add_cppconsui(int fd,
155 CppConsUI::InputCondition condition, CppConsUI::InputFunction function,
156 void *data);
158 // helper functions for input_add_cppconsui()
159 // process IO input to CppConsUI callback
160 static gboolean io_input_cppconsui(
161 GIOChannel *source, GIOCondition condition, gpointer data);
162 // destroyes CppConsUI IO input callback internal data
163 static void io_destroy_cppconsui(gpointer data);
165 static unsigned timeout_add_cppconsui(
166 unsigned interval, CppConsUI::SourceFunction function, void *data);
167 static gboolean timeout_function_cppconsui(gpointer data);
168 static void timeout_destroy_cppconsui(gpointer data);
169 static bool timeout_remove_cppconsui(unsigned handle);
170 static bool input_remove_cppconsui(unsigned handle);
172 // log an error produced by CppConsUI
173 static void log_error_cppconsui(const char *message);
175 // PurpleCoreUiOps callbacks
176 // returns information about CenterIM such as name, website etc.
177 static GHashTable *get_ui_info();
179 // PurpleDebugUiOps callbacks
180 static void purple_print(
181 PurpleDebugLevel level, const char *category, const char *arg_s);
182 static gboolean purple_is_enabled(
183 PurpleDebugLevel level, const char *category);
185 // called when CONF_PREFIX/dimensions prefs are changed
186 static void dimensions_change_(
187 const char *name, PurplePrefType type, gconstpointer val, gpointer data)
189 reinterpret_cast<CenterIM *>(data)->dimensions_change(name, type, val);
191 void dimensions_change(
192 const char *name, PurplePrefType type, gconstpointer val);
194 // called when /libpurple/away/idle_reporting pref is changed
195 static void idle_reporting_change_(
196 const char *name, PurplePrefType type, gconstpointer val, gpointer data)
198 reinterpret_cast<CenterIM *>(data)->idle_reporting_change(name, type, val);
200 void idle_reporting_change(
201 const char *name, PurplePrefType type, gconstpointer val);
203 // config handling
204 void loadDefaultColorSchemeConfig();
205 bool saveColorSchemeConfig();
206 char *colorToString(int color);
207 bool stringToColor(const char *str, int *color);
208 char *colorAttributesToString(int attrs);
209 bool stringToColorAttributes(const char *str, int *attrs);
210 void loadDefaultKeyConfig();
211 bool saveKeyConfig();
213 void actionFocusBuddyList();
214 void actionFocusActiveConversation();
215 void actionOpenAccountStatusMenu();
216 void actionOpenGeneralMenu();
217 void actionBuddyListToggleOffline();
218 void actionFocusPrevConversation();
219 void actionFocusNextConversation();
220 void actionFocusConversation(int i);
221 void actionExpandConversation();
223 void declareBindables();
226 #endif // __CENTERIM_H__
228 /* vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab : */