1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
4 // This file is part of CenterIM.
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 ACCOUNTWINDOW_H
20 #define ACCOUNTWINDOW_H
22 #include <cppconsui/Button.h>
23 #include <cppconsui/CheckBox.h>
24 #include <cppconsui/ColorPicker.h>
25 #include <cppconsui/ComboBox.h>
26 #include <cppconsui/InputDialog.h>
27 #include <cppconsui/MessageDialog.h>
28 #include <cppconsui/SplitDialog.h>
29 #include <cppconsui/TreeView.h>
30 #include <libpurple/purple.h>
32 class AccountWindow
: public CppConsUI::SplitDialog
{
35 virtual ~AccountWindow() override
{}
38 virtual void onScreenResized() override
;
42 typedef std::list
<SplitOption
*> SplitWidgets
;
43 typedef std::vector
<CppConsUI::Widget
*> Widgets
;
46 CppConsUI::Button
*parent
;
47 CppConsUI::TreeView::NodeReference parent_reference
;
48 SplitWidgets split_widgets
;
50 typedef std::map
<PurpleAccount
*, AccountEntry
> AccountEntries
;
52 class BoolOption
: public CppConsUI::CheckBox
{
56 TYPE_REMEMBER_PASSWORD
,
60 BoolOption(PurpleAccount
*account
, PurpleAccountOption
*option
);
61 BoolOption(PurpleAccount
*account
, Type type
);
62 virtual ~BoolOption() override
{}
65 PurpleAccount
*account_
;
66 PurpleAccountOption
*option_
;
69 void onToggle(CppConsUI::CheckBox
&activator
, bool new_state
);
72 CONSUI_DISABLE_COPY(BoolOption
);
75 class StringOption
: public CppConsUI::Button
{
83 StringOption(PurpleAccount
*account
, PurpleAccountOption
*option
);
84 StringOption(PurpleAccount
*account
, Type type
);
85 virtual ~StringOption() override
{}
88 PurpleAccount
*account_
;
89 PurpleAccountOption
*option_
;
94 void onActivate(CppConsUI::Button
&activator
);
95 void responseHandler(CppConsUI::InputDialog
&activator
,
96 CppConsUI::AbstractDialog::ResponseType response
);
99 CONSUI_DISABLE_COPY(StringOption
);
102 class IntegerOption
: public CppConsUI::Button
{
104 IntegerOption(PurpleAccount
*account
, PurpleAccountOption
*option
);
105 virtual ~IntegerOption() override
{}
108 PurpleAccount
*account_
;
109 PurpleAccountOption
*option_
;
112 void onActivate(CppConsUI::Button
&activator
);
113 void responseHandler(CppConsUI::InputDialog
&activator
,
114 CppConsUI::AbstractDialog::ResponseType response
);
117 CONSUI_DISABLE_COPY(IntegerOption
);
120 class StringListOption
: public CppConsUI::ComboBox
{
122 StringListOption(PurpleAccount
*account
, PurpleAccountOption
*option
);
123 virtual ~StringListOption() override
{}
126 PurpleAccount
*account_
;
127 PurpleAccountOption
*option_
;
129 void onSelectionChanged(CppConsUI::ComboBox
&activator
, int new_entry
,
130 const char *title
, intptr_t data
);
133 CONSUI_DISABLE_COPY(StringListOption
);
136 class SplitOption
: public CppConsUI::Button
{
138 SplitOption(PurpleAccount
*account
, PurpleAccountUserSplit
*split
,
139 AccountEntry
*account_entry
);
140 virtual ~SplitOption() override
{}
143 PurpleAccount
*account_
;
144 PurpleAccountUserSplit
*split_
;
145 AccountEntry
*account_entry_
;
148 void onActivate(CppConsUI::Button
&activator
);
149 void responseHandler(CppConsUI::InputDialog
&activator
,
150 CppConsUI::AbstractDialog::ResponseType response
);
153 CONSUI_DISABLE_COPY(SplitOption
);
156 class ProtocolOption
: public CppConsUI::ComboBox
{
158 ProtocolOption(PurpleAccount
*account
, AccountWindow
&account_window
);
159 virtual ~ProtocolOption() override
{}
162 AccountWindow
*account_window_
;
163 PurpleAccount
*account_
;
165 void onProtocolChanged(CppConsUI::ComboBox
&activator
,
166 std::size_t new_entry
, const char *title
, intptr_t data
);
169 CONSUI_DISABLE_COPY(ProtocolOption
);
172 class ColorOption
: public CppConsUI::ColorPicker
{
174 ColorOption(PurpleAccount
*account
);
175 virtual ~ColorOption() override
{}
178 PurpleAccount
*account_
;
181 CppConsUI::ColorPicker
&activator
, int new_fg
, int new_bg
);
184 CONSUI_DISABLE_COPY(ColorOption
);
187 CppConsUI::TreeView
*treeview_
;
188 AccountEntries account_entries_
;
190 CONSUI_DISABLE_COPY(AccountWindow
);
192 void clearAccount(PurpleAccount
*account
, bool full
);
193 void populateAccount(PurpleAccount
*account
);
195 void addAccount(CppConsUI::Button
&activator
);
196 void dropAccount(CppConsUI::Button
&activator
, PurpleAccount
*account
);
197 void dropAccountResponseHandler(CppConsUI::MessageDialog
&activator
,
198 CppConsUI::AbstractDialog::ResponseType response
, PurpleAccount
*account
);
201 #endif // ACCOUNTWINDOW_H
203 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: