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())
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
;
45 PurpleAccount
*account
;
50 Request(PurpleAccount
*account_
, const char *remote_user_
, const char *id_
,
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
{
66 PurpleAccountRequestAuthorizationCb auth_cb
;
67 PurpleAccountRequestAuthorizationCb deny_cb
;
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
{
81 PendingRequestWindow(Accounts
&accounts_
, const Requests
&requests
);
82 virtual ~PendingRequestWindow() {}
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
);
93 class RequestDialog
: public CppConsUI::AbstractDialog
{
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
;
104 // the request represented by the dialog
105 const Request
*request
;
108 virtual void emitResponse(ResponseType response
);
111 CONSUI_DISABLE_COPY(RequestDialog
);
114 typedef std::map
<const Request
*, CppConsUI::TreeView::NodeReference
>
117 CppConsUI::TreeView
*treeview
;
118 RequestMap request_map
;
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
);
127 CONSUI_DISABLE_COPY(PendingRequestWindow
);
130 PurpleAccountUiOps centerim_account_ui_ops
;
132 PendingRequestWindow
*request_window
;
134 static Accounts
*my_instance
;
138 CONSUI_DISABLE_COPY(Accounts
);
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 : */