diff options
Diffstat (limited to 'src/ui/chats.c')
-rw-r--r-- | src/ui/chats.c | 88 |
1 files changed, 15 insertions, 73 deletions
diff --git a/src/ui/chats.c b/src/ui/chats.c index 1a25927..5517541 100644 --- a/src/ui/chats.c +++ b/src/ui/chats.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "chats.h" | 25 | #include "chats.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 @@ _chats_iterate_group(void *cls, | |||
33 | struct GNUNET_CHAT_Group *group) | 34 | struct GNUNET_CHAT_Group *group) |
34 | { | 35 | { |
35 | UI_CHATS_Handle *chats = cls; | 36 | UI_CHATS_Handle *chats = cls; |
36 | 37 | list_input_select(chats, 1, GNUNET_CHAT_group_get_context(group)); | |
37 | const bool selected = (chats->line_selected == chats->line_index); | ||
38 | |||
39 | chats->line_index++; | ||
40 | |||
41 | if (selected) | ||
42 | chats->selected = GNUNET_CHAT_group_get_context(group); | ||
43 | |||
44 | return GNUNET_YES; | 38 | return GNUNET_YES; |
45 | } | 39 | } |
46 | 40 | ||
@@ -50,14 +44,7 @@ _chats_iterate_contact(void *cls, | |||
50 | struct GNUNET_CHAT_Contact *contact) | 44 | struct GNUNET_CHAT_Contact *contact) |
51 | { | 45 | { |
52 | UI_CHATS_Handle *chats = cls; | 46 | UI_CHATS_Handle *chats = cls; |
53 | 47 | list_input_select(chats, 1, GNUNET_CHAT_contact_get_context(contact)); | |
54 | const bool selected = (chats->line_selected == chats->line_index); | ||
55 | |||
56 | chats->line_index++; | ||
57 | |||
58 | if (selected) | ||
59 | chats->selected = GNUNET_CHAT_contact_get_context(contact); | ||
60 | |||
61 | return GNUNET_YES; | 48 | return GNUNET_YES; |
62 | } | 49 | } |
63 | 50 | ||
@@ -87,44 +74,34 @@ chats_event(UI_CHATS_Handle *chats, | |||
87 | return; | 74 | return; |
88 | } | 75 | } |
89 | 76 | ||
90 | chats->line_index = 0; | 77 | list_input_reset(chats); |
91 | chats->selected = NULL; | ||
92 | 78 | ||
93 | int count = 3; | 79 | GNUNET_CHAT_iterate_groups( |
94 | |||
95 | count += GNUNET_CHAT_iterate_groups( | ||
96 | app->chat.handle, | 80 | app->chat.handle, |
97 | &_chats_iterate_group, | 81 | &_chats_iterate_group, |
98 | chats | 82 | chats |
99 | ); | 83 | ); |
100 | 84 | ||
101 | count += GNUNET_CHAT_iterate_contacts( | 85 | GNUNET_CHAT_iterate_contacts( |
102 | app->chat.handle, | 86 | app->chat.handle, |
103 | &_chats_iterate_contact, | 87 | &_chats_iterate_contact, |
104 | chats | 88 | chats |
105 | ); | 89 | ); |
106 | 90 | ||
91 | list_input_select(chats, 1, NULL); | ||
92 | list_input_select(chats, 1, NULL); | ||
93 | list_input_select(chats, 1, NULL); | ||
94 | |||
95 | const int count = chats->line_index; | ||
96 | |||
107 | switch (key) | 97 | switch (key) |
108 | { | 98 | { |
109 | case 27: | 99 | case 27: |
110 | case KEY_EXIT: | 100 | case KEY_EXIT: |
111 | { | ||
112 | GNUNET_CHAT_disconnect(app->chat.handle); | 101 | GNUNET_CHAT_disconnect(app->chat.handle); |
113 | break; | 102 | break; |
114 | } | ||
115 | case KEY_UP: | ||
116 | { | ||
117 | chats->line_selected--; | ||
118 | break; | ||
119 | } | ||
120 | case KEY_DOWN: | ||
121 | { | ||
122 | chats->line_selected++; | ||
123 | break; | ||
124 | } | ||
125 | case '\n': | 103 | case '\n': |
126 | case KEY_ENTER: | 104 | case KEY_ENTER: |
127 | { | ||
128 | if (chats->selected) | 105 | if (chats->selected) |
129 | { | 106 | { |
130 | GNUNET_CHAT_context_request(chats->selected); | 107 | GNUNET_CHAT_context_request(chats->selected); |
@@ -150,31 +127,11 @@ chats_event(UI_CHATS_Handle *chats, | |||
150 | else if (chats->line_selected == count - 1) | 127 | else if (chats->line_selected == count - 1) |
151 | chats->enter_dialog.window = &(chats->window); | 128 | chats->enter_dialog.window = &(chats->window); |
152 | break; | 129 | break; |
153 | } | ||
154 | default: | 130 | default: |
155 | break; | 131 | break; |
156 | } | 132 | } |
157 | 133 | ||
158 | if (chats->line_selected < 0) | 134 | list_input_event(chats, key); |
159 | chats->line_selected = 0; | ||
160 | else if (chats->line_selected >= count) | ||
161 | chats->line_selected = count - 1; | ||
162 | |||
163 | if (!(chats->window)) | ||
164 | return; | ||
165 | |||
166 | const int height = getmaxy(chats->window); | ||
167 | const int y = chats->line_selected - chats->line_offset; | ||
168 | |||
169 | if (y < 0) | ||
170 | chats->line_offset += y; | ||
171 | else if (y + 1 >= height) | ||
172 | chats->line_offset += y + 1 - height; | ||
173 | |||
174 | if (chats->line_offset < 0) | ||
175 | chats->line_offset = 0; | ||
176 | else if (chats->line_offset >= count) | ||
177 | chats->line_offset = count - 1; | ||
178 | } | 135 | } |
179 | 136 | ||
180 | static int | 137 | static int |
@@ -183,18 +140,7 @@ _chats_print_entry(UI_CHATS_Handle *chats, | |||
183 | char chat_type, | 140 | char chat_type, |
184 | const char *text) | 141 | const char *text) |
185 | { | 142 | { |
186 | const bool selected = (chats->line_selected == chats->line_index); | 143 | list_input_print_gnunet(chats, 1); |
187 | const int y = chats->line_index - chats->line_offset; | ||
188 | |||
189 | chats->line_index++; | ||
190 | |||
191 | if (y < 0) | ||
192 | return GNUNET_YES; | ||
193 | |||
194 | const int height = getmaxy(chats->window); | ||
195 | |||
196 | if (y >= height) | ||
197 | return GNUNET_NO; | ||
198 | 144 | ||
199 | const int attrs_select = A_BOLD; | 145 | const int attrs_select = A_BOLD; |
200 | 146 | ||
@@ -218,9 +164,7 @@ _chats_iterate_print_group(void *cls, | |||
218 | struct GNUNET_CHAT_Group *group) | 164 | struct GNUNET_CHAT_Group *group) |
219 | { | 165 | { |
220 | UI_CHATS_Handle *chats = cls; | 166 | UI_CHATS_Handle *chats = cls; |
221 | |||
222 | const char *name = GNUNET_CHAT_group_get_name(group); | 167 | const char *name = GNUNET_CHAT_group_get_name(group); |
223 | |||
224 | return _chats_print_entry(chats, 'x', 'G', name); | 168 | return _chats_print_entry(chats, 'x', 'G', name); |
225 | } | 169 | } |
226 | 170 | ||
@@ -230,9 +174,7 @@ _chats_iterate_print_contact(void *cls, | |||
230 | struct GNUNET_CHAT_Contact *contact) | 174 | struct GNUNET_CHAT_Contact *contact) |
231 | { | 175 | { |
232 | UI_CHATS_Handle *chats = cls; | 176 | UI_CHATS_Handle *chats = cls; |
233 | |||
234 | const char *name = GNUNET_CHAT_contact_get_name(contact); | 177 | const char *name = GNUNET_CHAT_contact_get_name(contact); |
235 | |||
236 | return _chats_print_entry(chats, 'x', 'C', name); | 178 | return _chats_print_entry(chats, 'x', 'C', name); |
237 | } | 179 | } |
238 | 180 | ||
@@ -254,7 +196,7 @@ chats_print(UI_CHATS_Handle *chats, | |||
254 | if (!(chats->window)) | 196 | if (!(chats->window)) |
255 | return; | 197 | return; |
256 | 198 | ||
257 | chats->line_index = 0; | 199 | list_input_reset(chats); |
258 | werase(chats->window); | 200 | werase(chats->window); |
259 | 201 | ||
260 | GNUNET_CHAT_iterate_groups( | 202 | GNUNET_CHAT_iterate_groups( |