Update AUTHORS file
[centerim5.git] / src / Accounts.h
blob0df73de91dfa03364b8df88647d6e2113de5b6f2
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 __ACCOUNTS_H__
23 #define __ACCOUNTS_H__
25 #include <cppconsui/SplitDialog.h>
26 #include <cppconsui/TreeView.h>
27 #include <libpurple/purple.h>
29 #define ACCOUNTS (Accounts::instance())
31 class Accounts {
32 public:
33 static Accounts *instance();
35 void restoreStatuses(bool offline);
37 void openPendingRequests();
39 // interface for Header
40 sigc::signal<void, Accounts &, size_t> signal_request_count_change;
42 protected:
43 private:
44 struct Request {
45 PurpleAccount *account;
46 char *remote_user;
47 char *id;
48 char *alias;
50 Request(PurpleAccount *account_, const char *remote_user_, const char *id_,
51 const char *alias_);
52 virtual ~Request();
54 private:
55 CONSUI_DISABLE_COPY(Request);
58 struct AddRequest : public Request {
59 AddRequest(PurpleAccount *account_, const char *remote_user_,
60 const char *id_, const char *alias_);
61 virtual ~AddRequest() {}
64 struct AuthRequest : public Request {
65 char *message;
66 PurpleAccountRequestAuthorizationCb auth_cb;
67 PurpleAccountRequestAuthorizationCb deny_cb;
68 void *data;
70 AuthRequest(PurpleAccount *account_, const char *remote_user_,
71 const char *id_, const char *alias_, const char *message_, bool on_list_,
72 PurpleAccountRequestAuthorizationCb auth_cb_,
73 PurpleAccountRequestAuthorizationCb deny_cb_, void *data_);
74 virtual ~AuthRequest();
77 typedef std::vector<Request *> Requests;
79 class PendingRequestWindow : public CppConsUI::SplitDialog {
80 public:
81 PendingRequestWindow(Accounts &accounts_, const Requests &requests);
82 virtual ~PendingRequestWindow() {}
84 // Window
85 virtual void onScreenResized();
87 /* Provide a way for the Accounts singleton to add or delete requests
88 * dynamically when these events occur. */
89 void appendRequest(const Request &request);
90 void removeRequest(const Request &request);
92 protected:
93 class RequestDialog : public CppConsUI::AbstractDialog {
94 public:
95 RequestDialog(
96 const Request &request_, const char *title, const char *text);
97 virtual ~RequestDialog() {}
99 const Request *getRequest() const { return request; }
101 sigc::signal<void, RequestDialog &, ResponseType> signal_response;
103 protected:
104 // the request represented by the dialog
105 const Request *request;
107 // AbstractDialog
108 virtual void emitResponse(ResponseType response);
110 private:
111 CONSUI_DISABLE_COPY(RequestDialog);
114 typedef std::map<const Request *, CppConsUI::TreeView::NodeReference>
115 RequestMap;
117 CppConsUI::TreeView *treeview;
118 RequestMap request_map;
119 Accounts *accounts;
120 RequestDialog *dialog;
122 void onActivate(CppConsUI::Button &activator, const Request &request);
123 void onAddResponse(RequestDialog &activator, ResponseType response);
124 void onAuthResponse(RequestDialog &activator, ResponseType response);
126 private:
127 CONSUI_DISABLE_COPY(PendingRequestWindow);
130 PurpleAccountUiOps centerim_account_ui_ops;
131 Requests requests;
132 PendingRequestWindow *request_window;
134 static Accounts *my_instance;
136 Accounts();
137 ~Accounts();
138 CONSUI_DISABLE_COPY(Accounts);
140 static void init();
141 static void finalize();
142 friend class CenterIM;
144 /* This method is called by PendingRequestWindow when an add or auth request
145 * should be closed. */
146 void closeRequest(const Request &request);
147 void onPendingRequestWindowClose(CppConsUI::Window &activator);
149 static void notify_added_(PurpleAccount *account, const char *remote_user,
150 const char *id, const char *alias, const char *message)
152 ACCOUNTS->notify_added(account, remote_user, id, alias, message);
154 static void status_changed_(PurpleAccount *account, PurpleStatus *status)
156 ACCOUNTS->status_changed(account, status);
158 static void request_add_(PurpleAccount *account, const char *remote_user,
159 const char *id, const char *alias, const char *message)
161 ACCOUNTS->request_add(account, remote_user, id, alias, message);
163 static void *request_authorize_(PurpleAccount *account,
164 const char *remote_user, const char *id, const char *alias,
165 const char *message, gboolean on_list,
166 PurpleAccountRequestAuthorizationCb authorize_cb,
167 PurpleAccountRequestAuthorizationCb deny_cb, void *user_data)
169 return ACCOUNTS->request_authorize(account, remote_user, id, alias, message,
170 on_list, authorize_cb, deny_cb, user_data);
172 static void close_account_request_(void *ui_handle)
174 ACCOUNTS->close_account_request(ui_handle);
177 void notify_added(PurpleAccount *account, const char *remote_user,
178 const char *id, const char *alias, const char *message);
179 void status_changed(PurpleAccount *account, PurpleStatus *status);
180 void request_add(PurpleAccount *account, const char *remote_user,
181 const char *id, const char *alias, const char *message);
182 void *request_authorize(PurpleAccount *account, const char *remote_user,
183 const char *id, const char *alias, const char *message, gboolean on_list,
184 PurpleAccountRequestAuthorizationCb authorize_cb,
185 PurpleAccountRequestAuthorizationCb deny_cb, void *user_data);
186 void close_account_request(void *ui_handle);
189 #endif // __ACCOUNTS_H__
191 /* vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab : */