diff options
Diffstat (limited to 'src/ui/accounts.c')
-rw-r--r-- | src/ui/accounts.c | 71 |
1 files changed, 10 insertions, 61 deletions
diff --git a/src/ui/accounts.c b/src/ui/accounts.c index 4936c82..380506d 100644 --- a/src/ui/accounts.c +++ b/src/ui/accounts.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "accounts.h" | 25 | #include "accounts.h" |
26 | 26 | ||
27 | #include "list_input.h" | ||
27 | #include "../application.h" | 28 | #include "../application.h" |
28 | #include "../util.h" | 29 | #include "../util.h" |
29 | 30 | ||
@@ -33,14 +34,7 @@ _accounts_iterate(void *cls, | |||
33 | struct GNUNET_CHAT_Account *account) | 34 | struct GNUNET_CHAT_Account *account) |
34 | { | 35 | { |
35 | UI_ACCOUNTS_Handle *accounts = cls; | 36 | UI_ACCOUNTS_Handle *accounts = cls; |
36 | 37 | list_input_select(accounts, 1, account); | |
37 | const bool selected = (accounts->line_selected == accounts->line_index); | ||
38 | |||
39 | accounts->line_index++; | ||
40 | |||
41 | if (selected) | ||
42 | accounts->selected = account; | ||
43 | |||
44 | return GNUNET_YES; | 38 | return GNUNET_YES; |
45 | } | 39 | } |
46 | 40 | ||
@@ -55,66 +49,34 @@ accounts_event(UI_ACCOUNTS_Handle *accounts, | |||
55 | return; | 49 | return; |
56 | } | 50 | } |
57 | 51 | ||
58 | accounts->line_index = 0; | 52 | list_input_reset(accounts); |
59 | accounts->selected = NULL; | ||
60 | 53 | ||
61 | int count = GNUNET_CHAT_iterate_accounts( | 54 | GNUNET_CHAT_iterate_accounts( |
62 | app->chat.handle, | 55 | app->chat.handle, |
63 | &_accounts_iterate, | 56 | &_accounts_iterate, |
64 | accounts | 57 | accounts |
65 | ) + 1; | 58 | ); |
59 | |||
60 | list_input_select(accounts, 1, NULL); | ||
66 | 61 | ||
67 | switch (key) | 62 | switch (key) |
68 | { | 63 | { |
69 | case 27: | 64 | case 27: |
70 | case KEY_EXIT: | 65 | case KEY_EXIT: |
71 | { | ||
72 | app->chat.quit = TRUE; | 66 | app->chat.quit = TRUE; |
73 | break; | 67 | break; |
74 | } | ||
75 | case KEY_UP: | ||
76 | { | ||
77 | accounts->line_selected--; | ||
78 | break; | ||
79 | } | ||
80 | case KEY_DOWN: | ||
81 | { | ||
82 | accounts->line_selected++; | ||
83 | break; | ||
84 | } | ||
85 | case '\n': | 68 | case '\n': |
86 | case KEY_ENTER: | 69 | case KEY_ENTER: |
87 | { | ||
88 | if (accounts->selected) | 70 | if (accounts->selected) |
89 | GNUNET_CHAT_connect(app->chat.handle, accounts->selected); | 71 | GNUNET_CHAT_connect(app->chat.handle, accounts->selected); |
90 | else | 72 | else |
91 | accounts->create_dialog.window = &(accounts->window); | 73 | accounts->create_dialog.window = &(accounts->window); |
92 | break; | 74 | break; |
93 | } | ||
94 | default: | 75 | default: |
95 | break; | 76 | break; |
96 | } | 77 | } |
97 | 78 | ||
98 | if (accounts->line_selected < 0) | 79 | list_input_event(accounts, key); |
99 | accounts->line_selected = 0; | ||
100 | else if (accounts->line_selected >= count) | ||
101 | accounts->line_selected = count - 1; | ||
102 | |||
103 | if (!(accounts->window)) | ||
104 | return; | ||
105 | |||
106 | const int height = getmaxy(accounts->window); | ||
107 | const int y = accounts->line_selected - accounts->line_offset; | ||
108 | |||
109 | if (y < 0) | ||
110 | accounts->line_offset += y; | ||
111 | else if (y + 1 >= height) | ||
112 | accounts->line_offset += y + 1 - height; | ||
113 | |||
114 | if (accounts->line_offset < 0) | ||
115 | accounts->line_offset = 0; | ||
116 | else if (accounts->line_offset >= count) | ||
117 | accounts->line_offset = count - 1; | ||
118 | } | 80 | } |
119 | 81 | ||
120 | static int | 82 | static int |
@@ -122,18 +84,7 @@ _accounts_print_entry(UI_ACCOUNTS_Handle *accounts, | |||
122 | char type, | 84 | char type, |
123 | const char *text) | 85 | const char *text) |
124 | { | 86 | { |
125 | const bool selected = (accounts->line_selected == accounts->line_index); | 87 | list_input_print_gnunet(accounts, 1); |
126 | const int y = accounts->line_index - accounts->line_offset; | ||
127 | |||
128 | accounts->line_index++; | ||
129 | |||
130 | if (y < 0) | ||
131 | return GNUNET_YES; | ||
132 | |||
133 | const int height = getmaxy(accounts->window); | ||
134 | |||
135 | if (y >= height) | ||
136 | return GNUNET_NO; | ||
137 | 88 | ||
138 | const int attrs_select = A_BOLD; | 89 | const int attrs_select = A_BOLD; |
139 | 90 | ||
@@ -153,9 +104,7 @@ _accounts_iterate_print(void *cls, | |||
153 | struct GNUNET_CHAT_Account *account) | 104 | struct GNUNET_CHAT_Account *account) |
154 | { | 105 | { |
155 | UI_ACCOUNTS_Handle *accounts = cls; | 106 | UI_ACCOUNTS_Handle *accounts = cls; |
156 | |||
157 | const char *name = GNUNET_CHAT_account_get_name(account); | 107 | const char *name = GNUNET_CHAT_account_get_name(account); |
158 | |||
159 | return _accounts_print_entry(accounts, 'x', name); | 108 | return _accounts_print_entry(accounts, 'x', name); |
160 | } | 109 | } |
161 | 110 | ||
@@ -172,7 +121,7 @@ accounts_print(UI_ACCOUNTS_Handle *accounts, | |||
172 | if (!(accounts->window)) | 121 | if (!(accounts->window)) |
173 | return; | 122 | return; |
174 | 123 | ||
175 | accounts->line_index = 0; | 124 | list_input_reset(accounts); |
176 | werase(accounts->window); | 125 | werase(accounts->window); |
177 | 126 | ||
178 | GNUNET_CHAT_iterate_accounts( | 127 | GNUNET_CHAT_iterate_accounts( |