aboutsummaryrefslogtreecommitdiff
path: root/src/ui/accounts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/accounts.c')
-rw-r--r--src/ui/accounts.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
index e933d5d..c3cdb85 100644
--- a/src/ui/accounts.c
+++ b/src/ui/accounts.c
@@ -49,6 +49,12 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
49 MESSENGER_Application *app, 49 MESSENGER_Application *app,
50 int key) 50 int key)
51{ 51{
52 if (accounts->create.window)
53 {
54 account_create_event(&(accounts->create), app, key);
55 return;
56 }
57
52 accounts->line_index = 0; 58 accounts->line_index = 0;
53 accounts->selected = NULL; 59 accounts->selected = NULL;
54 60
@@ -56,7 +62,7 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
56 app->chat.handle, 62 app->chat.handle,
57 &_accounts_iterate, 63 &_accounts_iterate,
58 accounts 64 accounts
59 ); 65 ) + 1;
60 66
61 switch (key) 67 switch (key)
62 { 68 {
@@ -81,7 +87,8 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
81 { 87 {
82 if (accounts->selected) 88 if (accounts->selected)
83 GNUNET_CHAT_connect(app->chat.handle, accounts->selected); 89 GNUNET_CHAT_connect(app->chat.handle, accounts->selected);
84 90 else
91 accounts->create.window = accounts->window;
85 break; 92 break;
86 } 93 }
87 default: 94 default:
@@ -110,13 +117,11 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
110 accounts->line_offset = count - 1; 117 accounts->line_offset = count - 1;
111} 118}
112 119
113int 120static int
114_accounts_iterate_print(void *cls, 121_accounts_print_entry(UI_ACCOUNTS_Handle *accounts,
115 UNUSED const struct GNUNET_CHAT_Handle *handle, 122 char type,
116 struct GNUNET_CHAT_Account *account) 123 const char *text)
117{ 124{
118 UI_ACCOUNTS_Handle *accounts = cls;
119
120 const bool selected = (accounts->line_selected == accounts->line_index); 125 const bool selected = (accounts->line_selected == accounts->line_index);
121 const int y = accounts->line_index - accounts->line_offset; 126 const int y = accounts->line_index - accounts->line_offset;
122 127
@@ -130,24 +135,40 @@ _accounts_iterate_print(void *cls,
130 if (y >= height) 135 if (y >= height)
131 return GNUNET_NO; 136 return GNUNET_NO;
132 137
133 const char *name = GNUNET_CHAT_account_get_name(account);
134
135 const int attrs_select = A_BOLD; 138 const int attrs_select = A_BOLD;
136 139
137 if (selected) wattron(accounts->window, attrs_select); 140 if (selected) wattron(accounts->window, attrs_select);
138 141
139 wmove(accounts->window, y, 0); 142 wmove(accounts->window, y, 0);
140 wprintw(accounts->window, "%s", name); 143 wprintw(accounts->window, "[%c] %s", selected? type : ' ', text);
141 144
142 if (selected) wattroff(accounts->window, attrs_select); 145 if (selected) wattroff(accounts->window, attrs_select);
143 146
144 return GNUNET_YES; 147 return GNUNET_YES;
145} 148}
146 149
150int
151_accounts_iterate_print(void *cls,
152 UNUSED const struct GNUNET_CHAT_Handle *handle,
153 struct GNUNET_CHAT_Account *account)
154{
155 UI_ACCOUNTS_Handle *accounts = cls;
156
157 const char *name = GNUNET_CHAT_account_get_name(account);
158
159 return _accounts_print_entry(accounts, 'x', name);
160}
161
147void 162void
148accounts_print(UI_ACCOUNTS_Handle *accounts, 163accounts_print(UI_ACCOUNTS_Handle *accounts,
149 MESSENGER_Application *app) 164 MESSENGER_Application *app)
150{ 165{
166 if (accounts->create.window)
167 {
168 account_create_print(&(accounts->create), app);
169 return;
170 }
171
151 if (!(accounts->window)) 172 if (!(accounts->window))
152 return; 173 return;
153 174
@@ -159,4 +180,6 @@ accounts_print(UI_ACCOUNTS_Handle *accounts,
159 &_accounts_iterate_print, 180 &_accounts_iterate_print,
160 accounts 181 accounts
161 ); 182 );
183
184 _accounts_print_entry(accounts, '+', "Add account");
162} 185}