Use pkg-config to find ncursesw
[centerim5.git] / src / Accounts.h
blob409e6829c47904a4cec9b7a5a0a8b13540bde22b
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 ACCOUNTS_H
20 #define ACCOUNTS_H
22 #include <cppconsui/SplitDialog.h>
23 #include <cppconsui/TreeView.h>
24 #include <libpurple/purple.h>
26 #define ACCOUNTS (Accounts::instance())
28 class Accounts {
29 public:
30 static Accounts *instance();
32 void restoreStatuses(bool offline);
34 void openPendingRequests();
36 // Interface for Header.
37 sigc::signal<void, Accounts &, std::size_t> signal_request_count_change;
39 private:
40 struct Request {
41 PurpleAccount *account_;
42 char *remote_user_;
43 char *id_;
44 char *alias_;
46 Request(PurpleAccount *account, const char *remote_user, const char *id,
47 const char *alias);
48 virtual ~Request();
50 private:
51 CONSUI_DISABLE_COPY(Request);
54 struct AddRequest : public Request {
55 AddRequest(PurpleAccount *account, const char *remote_user, const char *id,
56 const char *alias);
57 virtual ~AddRequest() override {}
60 struct AuthRequest : public Request {
61 char *message_;
62 PurpleAccountRequestAuthorizationCb auth_cb_;
63 PurpleAccountRequestAuthorizationCb deny_cb_;
64 void *data_;
66 AuthRequest(PurpleAccount *account, const char *remote_user, const char *id,
67 const char *alias, const char *message, bool on_list,
68 PurpleAccountRequestAuthorizationCb auth_cb,
69 PurpleAccountRequestAuthorizationCb deny_cb, void *data);
70 virtual ~AuthRequest() override;
73 typedef std::vector<Request *> Requests;
75 class PendingRequestWindow : public CppConsUI::SplitDialog {
76 public:
77 PendingRequestWindow(Accounts &accounts, const Requests &requests);
78 virtual ~PendingRequestWindow() override {}
80 // Window
81 virtual void onScreenResized() override;
83 // Provide a way for the Accounts singleton to add or delete requests
84 // dynamically when these events occur.
85 void appendRequest(const Request &request);
86 void removeRequest(const Request &request);
88 protected:
89 class RequestDialog : public CppConsUI::AbstractDialog {
90 public:
91 RequestDialog(
92 const Request &request, const char *title, const char *text);
93 virtual ~RequestDialog() override {}
95 const Request *getRequest() const { return request_; }
97 sigc::signal<void, RequestDialog &, ResponseType> signal_response;
99 protected:
100 // The request represented by the dialog.
101 const Request *request_;
103 // AbstractDialog
104 virtual void emitResponse(ResponseType response) override;
106 private:
107 CONSUI_DISABLE_COPY(RequestDialog);
110 typedef std::map<const Request *, CppConsUI::TreeView::NodeReference>
111 RequestNodes;
113 CppConsUI::TreeView *treeview_;
114 RequestNodes request_nodes_;
115 Accounts *accounts_;
116 RequestDialog *dialog_;
118 void onActivate(CppConsUI::Button &activator, const Request &request);
119 void onAddResponse(RequestDialog &activator, ResponseType response);
120 void onAuthResponse(RequestDialog &activator, ResponseType response);
122 private:
123 CONSUI_DISABLE_COPY(PendingRequestWindow);
126 PurpleAccountUiOps centerim_account_ui_ops_;
127 Requests requests_;
128 PendingRequestWindow *request_window_;
130 static Accounts *my_instance_;
132 Accounts();
133 ~Accounts();
134 CONSUI_DISABLE_COPY(Accounts);
136 static void init();
137 static void finalize();
138 friend class CenterIM;
140 // This method is called by PendingRequestWindow when an add or auth request
141 // should be closed.
142 void closeRequest(const Request &request);
143 void onPendingRequestWindowClose(CppConsUI::Window &activator);
145 static void notify_added_(PurpleAccount *account, const char *remote_user,
146 const char *id, const char *alias, const char *message)
148 ACCOUNTS->notify_added(account, remote_user, id, alias, message);
150 static void status_changed_(PurpleAccount *account, PurpleStatus *status)
152 ACCOUNTS->status_changed(account, status);
154 static void request_add_(PurpleAccount *account, const char *remote_user,
155 const char *id, const char *alias, const char *message)
157 ACCOUNTS->request_add(account, remote_user, id, alias, message);
159 static void *request_authorize_(PurpleAccount *account,
160 const char *remote_user, const char *id, const char *alias,
161 const char *message, gboolean on_list,
162 PurpleAccountRequestAuthorizationCb auth_cb,
163 PurpleAccountRequestAuthorizationCb deny_cb, void *user_data)
165 return ACCOUNTS->request_authorize(account, remote_user, id, alias, message,
166 on_list, auth_cb, deny_cb, user_data);
168 static void close_account_request_(void *ui_handle)
170 ACCOUNTS->close_account_request(ui_handle);
173 void notify_added(PurpleAccount *account, const char *remote_user,
174 const char *id, const char *alias, const char *message);
175 void status_changed(PurpleAccount *account, PurpleStatus *status);
176 void request_add(PurpleAccount *account, const char *remote_user,
177 const char *id, const char *alias, const char *message);
178 void *request_authorize(PurpleAccount *account, const char *remote_user,
179 const char *id, const char *alias, const char *message, gboolean on_list,
180 PurpleAccountRequestAuthorizationCb auth_cb,
181 PurpleAccountRequestAuthorizationCb deny_cb, void *user_data);
182 void close_account_request(void *ui_handle);
185 #endif // ACCOUNTS_H
187 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: