[c5c522c] | 1 | #include <stdlib.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <string.h> |
---|
| 4 | #include <time.h> |
---|
| 5 | |
---|
| 6 | #include "../shared/debug.h" |
---|
| 7 | |
---|
| 8 | #include "drivers/lcd.h" |
---|
| 9 | |
---|
| 10 | #include "clients.h" |
---|
| 11 | #include "screen.h" |
---|
| 12 | #include "screenlist.h" |
---|
| 13 | #include "widget.h" |
---|
| 14 | |
---|
| 15 | #include "serverscreens.h" |
---|
| 16 | |
---|
| 17 | screen *server_screen; |
---|
| 18 | char *id = "ClientList"; |
---|
| 19 | char *name = "Client List"; |
---|
| 20 | |
---|
| 21 | char title[256] = "LCDproc Server"; |
---|
| 22 | char one[256] = ""; |
---|
| 23 | char two[256] = ""; |
---|
| 24 | char three[256] = ""; |
---|
| 25 | |
---|
| 26 | int server_screen_init() |
---|
| 27 | { |
---|
| 28 | widget *w; |
---|
| 29 | |
---|
| 30 | debug("server_screen_init\n"); |
---|
| 31 | |
---|
| 32 | server_screen = screen_create(); |
---|
| 33 | |
---|
| 34 | if(!server_screen) |
---|
| 35 | { |
---|
| 36 | fprintf(stderr, "server_screen_init: Error allocating screen\n"); |
---|
| 37 | return -1; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | server_screen->id = id; |
---|
| 41 | server_screen->name = name; |
---|
| 42 | server_screen->duration = 20; // 1 second, instead of 4... |
---|
| 43 | |
---|
| 44 | // TODO: Error-checking? |
---|
| 45 | widget_add(server_screen, "title", "title", NULL, 1); |
---|
| 46 | widget_add(server_screen, "one" , "string", NULL, 1); |
---|
| 47 | widget_add(server_screen, "two" , "string", NULL, 1); |
---|
| 48 | widget_add(server_screen, "three", "string", NULL, 1); |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | // Now, initialize all the widgets... |
---|
| 52 | w = widget_find(server_screen, "title"); |
---|
| 53 | if(w) |
---|
| 54 | { |
---|
| 55 | w->text = title; |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | fprintf(stderr, "server_screen_init: Can't find title\n"); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | w = widget_find(server_screen, "one"); |
---|
| 63 | if(w) |
---|
| 64 | { |
---|
| 65 | w->x = 1; |
---|
| 66 | w->y = 2; |
---|
| 67 | w->text = one; |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | fprintf(stderr, "server_screen_init: Can't find widget one\n"); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | w = widget_find(server_screen, "two"); |
---|
| 75 | if(w) |
---|
| 76 | { |
---|
| 77 | w->x = 1; |
---|
| 78 | w->y = 3; |
---|
| 79 | w->text = two; |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | fprintf(stderr, "server_screen_init: Can't find widget two\n"); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | w = widget_find(server_screen, "three"); |
---|
| 87 | if(w) |
---|
| 88 | { |
---|
| 89 | w->x = 1; |
---|
| 90 | w->y = 4; |
---|
| 91 | w->text = three; |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | fprintf(stderr, "server_screen_init: Can't find widget three\n"); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | // And enqueue the screen |
---|
| 101 | screenlist_add(server_screen); |
---|
| 102 | |
---|
| 103 | debug("server_screen_init done\n"); |
---|
| 104 | |
---|
| 105 | return 0; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | int update_server_screen(int timer) |
---|
| 110 | { |
---|
| 111 | client *c; |
---|
| 112 | int num_clients; |
---|
| 113 | screen *s; |
---|
| 114 | int num_screens; |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | // Draw a title... |
---|
| 118 | //strcpy(title, "LCDproc Server"); |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | // Now get info on the number of connected clients... |
---|
| 122 | num_clients=0; num_screens=0; |
---|
| 123 | LL_Rewind(clients); |
---|
| 124 | do { |
---|
| 125 | c = LL_Get(clients); |
---|
| 126 | if(c) |
---|
| 127 | { |
---|
| 128 | num_clients++; |
---|
| 129 | LL_Rewind(c->data->screenlist); |
---|
| 130 | do { |
---|
| 131 | s = LL_Get(c->data->screenlist); |
---|
| 132 | if(s) |
---|
| 133 | { |
---|
| 134 | num_screens++; |
---|
| 135 | } |
---|
| 136 | } while(LL_Next(c->data->screenlist) == 0); |
---|
| 137 | } |
---|
| 138 | } while(LL_Next(clients) == 0); |
---|
| 139 | |
---|
| 140 | if(lcd.hgt >= 3) |
---|
| 141 | { |
---|
| 142 | sprintf(one, "Clients: %i", num_clients); |
---|
| 143 | sprintf(two, "Screens: %i", num_screens); |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | if(lcd.wid >= 20) |
---|
| 148 | sprintf(one, "%i Client%s, %i Screen%s", |
---|
| 149 | num_clients, (num_clients==1)?"":"s", |
---|
| 150 | num_screens, (num_screens==1)?"":"s"); |
---|
| 151 | else // 16x2 size |
---|
| 152 | sprintf(one, "%i Cli%s, %i Scr%s", |
---|
| 153 | num_clients, (num_clients==1)?"":"s", |
---|
| 154 | num_screens, (num_screens==1)?"":"s"); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | return 0; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | int no_screen_screen(int timer) |
---|
| 161 | { |
---|
| 162 | |
---|
| 163 | lcd.clear(); |
---|
| 164 | |
---|
| 165 | lcd.string(1, 1, "Error: No screen!"); |
---|
| 166 | |
---|
| 167 | lcd.flush(); |
---|
| 168 | |
---|
| 169 | return 0; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | int goodbye_screen() |
---|
| 173 | { |
---|
| 174 | char |
---|
| 175 | *b20 = " ", |
---|
| 176 | *t20 = " Thanks for using ", |
---|
| 177 | #ifdef LINUX |
---|
| 178 | *l20 = " LCDproc and Linux! ", |
---|
| 179 | #else |
---|
| 180 | *l20 = " LCDproc! ", |
---|
| 181 | #endif |
---|
| 182 | *b16 = " ", |
---|
| 183 | *t16 = "Thanks for using", |
---|
| 184 | #ifdef LINUX |
---|
| 185 | *l16 = " LCDproc+Linux! ", |
---|
| 186 | #else |
---|
| 187 | *l16 = " LCDproc! ", |
---|
| 188 | #endif |
---|
| 189 | *nil = ""; |
---|
| 190 | |
---|
| 191 | lcd.clear(); |
---|
| 192 | |
---|
| 193 | if(lcd.hgt >= 4) |
---|
| 194 | { |
---|
| 195 | if(lcd.wid >= 20) |
---|
| 196 | { |
---|
| 197 | lcd.string(1, 1, b20); |
---|
| 198 | lcd.string(1, 2, t20); |
---|
| 199 | lcd.string(1, 3, l20); |
---|
| 200 | lcd.string(1, 4, b20); |
---|
| 201 | } |
---|
| 202 | else |
---|
| 203 | { |
---|
| 204 | lcd.string(1, 1, b16); |
---|
| 205 | lcd.string(1, 2, t16); |
---|
| 206 | lcd.string(1, 3, l16); |
---|
| 207 | lcd.string(1, 4, b16); |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | if(lcd.wid >= 20) |
---|
| 213 | { |
---|
| 214 | lcd.string(1, 1, t20); |
---|
| 215 | lcd.string(1, 2, l20); |
---|
| 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
| 219 | lcd.string(1, 1, t16); |
---|
| 220 | lcd.string(1, 2, l16); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | lcd.flush(); |
---|
| 225 | |
---|
| 226 | return 0; |
---|
| 227 | } |
---|
| 228 | |
---|