about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-22 00:30:42 +0000
committerJames Booth <boothj5@gmail.com>2015-11-22 00:30:42 +0000
commit7a324abcd632a30b603586a1eef80eee4140e91a (patch)
treefec65f35e08fa060609fc4e113e662b265412d57 /src/ui
parent5c08bea8d075714182ca898fcb68d5ad15605f0d (diff)
downloadprofani-tty-7a324abcd632a30b603586a1eef80eee4140e91a.tar.gz
Option to show presence information on single line in roster
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/rosterwin.c120
-rw-r--r--src/ui/window.c13
-rw-r--r--src/ui/window.h1
3 files changed, 92 insertions, 42 deletions
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index cc31ef55..f3a10257 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -65,41 +65,66 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr
     if (by_presence) {
         if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
             wattron(layout->subwin, theme_attrs(colour));
-            GString *msg = g_string_new(" ");
-            while (current_indent > 0) {
-                g_string_append(msg, " ");
-                current_indent--;
+            if (presence_indent == -1) {
+                GString *msg = g_string_new("");
+                g_string_append_printf(msg, ": \"%s\"", status);
+                win_print_nowrap(layout->subwin, msg->str, FALSE);
+                g_string_free(msg, TRUE);
+                wattroff(layout->subwin, theme_attrs(colour));
+            } else {
+                GString *msg = g_string_new(" ");
+                while (current_indent > 0) {
+                    g_string_append(msg, " ");
+                    current_indent--;
+                }
+                g_string_append_printf(msg, "\"%s\"", status);
+                win_newline_lazy(layout->subwin);
+                win_print_nowrap(layout->subwin, msg->str, FALSE);
+                g_string_free(msg, TRUE);
+                wattroff(layout->subwin, theme_attrs(colour));
             }
-            g_string_append_printf(msg, "\"%s\"", status);
-            win_print_nowrap(layout->subwin, msg->str, TRUE);
-            g_string_free(msg, TRUE);
-            wattroff(layout->subwin, theme_attrs(colour));
         }
 
     // show both presence and status when not grouped by presence
     } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || (status && prefs_get_boolean(PREF_ROSTER_STATUS))) {
         wattron(layout->subwin, theme_attrs(colour));
-        GString *msg = g_string_new(" ");
-        while (current_indent > 0) {
-            g_string_append(msg, " ");
-            current_indent--;
-        }
-        if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
-            g_string_append(msg, presence);
-            if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
-                g_string_append_printf(msg, " \"%s\"", status);
+        if (presence_indent == -1) {
+            GString *msg = g_string_new("");
+            if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
+                g_string_append_printf(msg, ": %s", presence);
+                if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
+                    g_string_append_printf(msg, " \"%s\"", status);
+                }
+            } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
+                g_string_append_printf(msg, ": \"%s\"", status);
+            }
+            win_print_nowrap(layout->subwin, msg->str, FALSE);
+            g_string_free(msg, TRUE);
+            wattroff(layout->subwin, theme_attrs(colour));
+        } else {
+            GString *msg = g_string_new(" ");
+            while (current_indent > 0) {
+                g_string_append(msg, " ");
+                current_indent--;
+            }
+            if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
+                g_string_append(msg, presence);
+                if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
+                    g_string_append_printf(msg, " \"%s\"", status);
+                }
+            } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
+                g_string_append_printf(msg, "\"%s\"", status);
             }
-        } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
-            g_string_append_printf(msg, "\"%s\"", status);
+            win_newline_lazy(layout->subwin);
+            win_print_nowrap(layout->subwin, msg->str, FALSE);
+            g_string_free(msg, TRUE);
+            wattroff(layout->subwin, theme_attrs(colour));
         }
-        win_print_nowrap(layout->subwin, msg->str, TRUE);
-        g_string_free(msg, TRUE);
-        wattroff(layout->subwin, theme_attrs(colour));
     }
 }
 
 static void
-_rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_indent)
+_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent)
 {
     GList *resources = p_contact_get_available_resources(contact);
     if (resources) {
@@ -125,7 +150,8 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact, int current_inden
             if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
                 g_string_append_printf(msg, " [%d]", resource->priority);
             }
-            win_print_nowrap(layout->subwin, msg->str, TRUE);
+            win_newline_lazy(layout->subwin);
+            win_print_nowrap(layout->subwin, msg->str, FALSE);
             g_string_free(msg, TRUE);
             wattroff(layout->subwin, theme_attrs(resource_presence_colour));
 
@@ -170,24 +196,28 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
         g_string_append_printf(msg, "%c", ch);
     }
     g_string_append(msg, name);
-    win_print_nowrap(layout->subwin, msg->str, TRUE);
+    win_newline_lazy(layout->subwin);
+    win_print_nowrap(layout->subwin, msg->str, FALSE);
     g_string_free(msg, TRUE);
     wattroff(layout->subwin, theme_attrs(presence_colour));
 
     if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
-        _rosterwin_resource(layout, contact, current_indent);
+        _rosterwin_resources(layout, contact, current_indent);
     } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
         _rosterwin_presence(layout, presence_colour, presence, status, current_indent);
     }
 }
 
 static void
-_rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const presence, char *title)
+_rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const presence, char *title, gboolean newline)
 {
     GSList *contacts = roster_get_contacts_by_presence(presence);
 
     // if this group has contacts, or if we want to show empty groups
     if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
+        if (newline) {
+            win_newline_lazy(layout->subwin);
+        }
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
         GString *title_str = g_string_new(" ");
         char ch = prefs_get_roster_header_char();
@@ -198,7 +228,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
         if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
             g_string_append_printf(title_str, " (%d)", g_slist_length(contacts));
         }
-        win_print_nowrap(layout->subwin, title_str->str, TRUE);
+        win_print_nowrap(layout->subwin, title_str->str, FALSE);
         g_string_free(title_str, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
     }
@@ -215,7 +245,7 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
 }
 
 static void
-_rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
+_rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newline)
 {
     GSList *contacts = NULL;
 
@@ -229,6 +259,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
     prefs_free_string(order);
 
     if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
+        if (newline) {
+            win_newline_lazy(layout->subwin);
+        }
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
         GString *title = g_string_new(" ");
         char ch = prefs_get_roster_header_char();
@@ -239,7 +272,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
         if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
             g_string_append_printf(title, " (%d)", g_slist_length(contacts));
         }
-        win_print_nowrap(layout->subwin, title->str, TRUE);
+        win_print_nowrap(layout->subwin, title->str, FALSE);
         g_string_free(title, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
 
@@ -254,7 +287,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
 }
 
 static void
-_rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
+_rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline)
 {
     GSList *contacts = NULL;
 
@@ -268,6 +301,9 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
     prefs_free_string(order);
 
     if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
+        if (newline) {
+            win_newline_lazy(layout->subwin);
+        }
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
         GString *title = g_string_new(" ");
         char ch = prefs_get_roster_header_char();
@@ -279,7 +315,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
         if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
             g_string_append_printf(title, " (%d)", g_slist_length(contacts));
         }
-        win_print_nowrap(layout->subwin, title->str, TRUE);
+        win_print_nowrap(layout->subwin, title->str, FALSE);
         g_string_free(title, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
 
@@ -307,24 +343,26 @@ rosterwin_roster(void)
     char *by = prefs_get_string(PREF_ROSTER_BY);
     if (g_strcmp0(by, "presence") == 0) {
         werase(layout->subwin);
-        _rosterwin_contacts_by_presence(layout, "chat", "Available for chat");
-        _rosterwin_contacts_by_presence(layout, "online", "Online");
-        _rosterwin_contacts_by_presence(layout, "away", "Away");
-        _rosterwin_contacts_by_presence(layout, "xa", "Extended Away");
-        _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb");
+        _rosterwin_contacts_by_presence(layout, "chat", "Available for chat", FALSE);
+        _rosterwin_contacts_by_presence(layout, "online", "Online", TRUE);
+        _rosterwin_contacts_by_presence(layout, "away", "Away", TRUE);
+        _rosterwin_contacts_by_presence(layout, "xa", "Extended Away", TRUE);
+        _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb", TRUE);
         if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
-            _rosterwin_contacts_by_presence(layout, "offline", "Offline");
+            _rosterwin_contacts_by_presence(layout, "offline", "Offline", TRUE);
         }
     } else if (g_strcmp0(by, "group") == 0) {
         werase(layout->subwin);
+        gboolean newline = FALSE;
         GSList *groups = roster_get_groups();
         GSList *curr_group = groups;
         while (curr_group) {
-            _rosterwin_contacts_by_group(layout, curr_group->data);
+            _rosterwin_contacts_by_group(layout, curr_group->data, newline);
+            newline = TRUE;
             curr_group = g_slist_next(curr_group);
         }
         g_slist_free_full(groups, free);
-        _rosterwin_contacts_by_no_group(layout);
+        _rosterwin_contacts_by_no_group(layout, newline);
     } else {
         GSList *contacts = NULL;
 
@@ -349,7 +387,7 @@ rosterwin_roster(void)
         if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
             g_string_append_printf(title, " (%d)", g_slist_length(contacts));
         }
-        win_print_nowrap(layout->subwin, title->str, TRUE);
+        win_print_nowrap(layout->subwin, title->str, FALSE);
         g_string_free(title, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
 
diff --git a/src/ui/window.c b/src/ui/window.c
index 3ca9b927..c40e3547 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1269,11 +1269,22 @@ void
 win_print_nowrap(WINDOW *win, char *msg, gboolean newline)
 {
     int maxx = getmaxx(win);
+    int curx = getcurx(win);
     int cury = getcury(win);
 
-    waddnstr(win, msg, maxx);
+    waddnstr(win, msg, maxx - curx);
 
     if (newline) {
         wmove(win, cury+1, 0);
     }
 }
+
+void
+win_newline_lazy(WINDOW *win)
+{
+    int curx = getcurx(win);
+    if (curx > 0) {
+        int cury = getcury(win);
+        wmove(win, cury+1, 0);
+    }
+}
diff --git a/src/ui/window.h b/src/ui/window.h
index 24d71ad6..0a01b37f 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -68,6 +68,7 @@ void win_redraw(ProfWin *window);
 int win_roster_cols(void);
 int win_occpuants_cols(void);
 void win_print_nowrap(WINDOW *win, char *msg, gboolean newline);
+void win_newline_lazy(WINDOW *win);
 void win_mark_received(ProfWin *window, const char *const id);
 
 gboolean win_has_active_subwin(ProfWin *window);
id='n18' href='#n18'>18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341