Files
lcdproc/server/serverscreens.c
T

228 lines
5.1 KiB
C
Raw Normal View History

/*
* serverscreens.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
*
*
* Implements the serverscreens
*
*/
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2001-11-29 14:09:13 +00:00
#include "shared/report.h"
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
#include "drivers.h"
1999-12-09 23:15:14 +00:00
#include "clients.h"
#include "screen.h"
#include "screenlist.h"
#include "widget.h"
#include "serverscreens.h"
screen *server_screen;
char *id = "ClientList";
char *name = "Client List";
char title[256] = "LCDproc Server";
char one[256] = "";
char two[256] = "";
1999-12-09 23:15:14 +00:00
char three[256] = "";
#define WidgetXPos(w,a) (w)->x = (a)
#define WidgetYPos(w,a) (w)->y = (a)
#define WidgetText(w,a) (w)->text = (a)
#define WidgetString(w,a,b,t) {WidgetXPos(w,a);WidgetYPos(w,b);WidgetText(w,t);}
int
server_screen_init ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
widget *w;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
debug (RPT_DEBUG, "server_screen_init");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
server_screen = screen_create ();
2000-04-03 22:13:57 +00:00
if (!server_screen) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: Error allocating screen");
2000-04-03 22:13:57 +00:00
return -1;
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
server_screen->id = id;
server_screen->name = name;
2001-12-30 00:15:25 +00:00
server_screen->duration = 8; /* 1 second, instead of 4...*/
if (widget_add (server_screen, "title", "title", NULL, 1) != 0) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
}
if (widget_add (server_screen, "one", "string", NULL, 1) != 0) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
}
if (widget_add (server_screen, "two", "string", NULL, 1) != 0) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
}
if (widget_add (server_screen, "three", "string", NULL, 1) != 0) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: internal error: could not add title widget");
}
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Now, initialize all the widgets...*/
if ((w = widget_find (server_screen, "title")) != NULL) {
WidgetText(w,title);
} else
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: Can't find title");
if ((w = widget_find (server_screen, "one")) != NULL)
WidgetString(w,1,2,one)
else
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: Can't find widget one");
if ((w = widget_find (server_screen, "two")) != NULL)
WidgetString(w,1,3,two)
else
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: Can't find widget two");
if ((w = widget_find (server_screen, "three")) != NULL)
WidgetString(w,1,4,three)
else
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "server_screen_init: Can't find widget three");
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* And enqueue the screen*/
2000-04-03 22:13:57 +00:00
screenlist_add (server_screen);
2001-11-29 14:09:13 +00:00
debug (RPT_DEBUG, "server_screen_init done");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
static int
screen_count (client *c) {
int n;
n = 0;
LL_Rewind (c->data->screenlist);
do {
if (LL_Get (c->data->screenlist) != NULL)
n++;
} while (LL_Next (c->data->screenlist) == 0);
return n;
}
int
update_server_screen (int timer)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
client *c;
int num_clients;
2001-12-30 00:15:25 +00:00
/*screen *s;*/
2000-04-03 22:13:57 +00:00
int num_screens;
2001-12-30 00:15:25 +00:00
/* Draw a title...*/
/*strcpy(title, "LCDproc Server");*/
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Now get info on the number of connected clients...*/
2000-04-03 22:13:57 +00:00
num_clients = 0;
num_screens = 0;
LL_Rewind (clients);
do {
c = LL_Get (clients);
if (c) {
num_clients++;
num_screens += screen_count(c);
2001-12-30 00:15:25 +00:00
/* LL_Rewind (c->data->screenlist); */
/* do { */
/* s = LL_Get (c->data->screenlist); */
/* if (s) { */
/* num_screens++; */
/* } */
/* } while (LL_Next (c->data->screenlist) == 0); */
2000-04-03 22:13:57 +00:00
}
} while (LL_Next (clients) == 0);
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Format strings for the appropriate size display... */
if (display_props->height >= 3) {
snprintf (one, sizeof(one), "Clients: %i", num_clients);
snprintf (two, sizeof(two), "Screens: %i", num_screens);
2000-04-03 22:13:57 +00:00
} else {
2001-12-30 00:15:25 +00:00
if (display_props->width >= 20)
snprintf (one, sizeof(one), "%i Client%s, %i Screen%s", num_clients,
(num_clients == 1) ? "" : "s", num_screens,
(num_screens == 1) ? "" : "s");
2001-12-30 00:15:25 +00:00
else /* 16x2 size*/
snprintf (one, sizeof(one), "%i Cli%s, %i Scr%s", num_clients,
(num_clients == 1) ? "" : "s", num_screens,
(num_screens == 1) ? "" : "s");
2000-04-03 22:13:57 +00:00
}
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
int
no_screen_screen (int timer)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
drivers_clear ();
drivers_string (1, 1, "Error: No screen!");
drivers_flush ();
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
int
goodbye_screen ()
1999-12-09 23:15:14 +00:00
{
char *b20 = " ";
char *t20 = " Thanks for using ";
1999-12-09 23:15:14 +00:00
#ifdef LINUX
char *l20 = " LCDproc and Linux! ";
1999-12-09 23:15:14 +00:00
#else
char *l20 = " LCDproc! ";
1999-12-09 23:15:14 +00:00
#endif
char *b16 = " ";
char *t16 = "Thanks for using";
1999-12-09 23:15:14 +00:00
#ifdef LINUX
char *l16 = " LCDproc+Linux! ";
1999-12-09 23:15:14 +00:00
#else
char *l16 = " LCDproc! ";
1999-12-09 23:15:14 +00:00
#endif
2001-12-30 00:15:25 +00:00
drivers_clear ();
2001-12-30 00:15:25 +00:00
if (display_props->height >= 4) {
if (display_props->width >= 20) {
drivers_string (1, 1, b20);
drivers_string (1, 2, t20);
drivers_string (1, 3, l20);
drivers_string (1, 4, b20);
2000-04-03 22:13:57 +00:00
} else {
2001-12-30 00:15:25 +00:00
drivers_string (1, 1, b16);
drivers_string (1, 2, t16);
drivers_string (1, 3, l16);
drivers_string (1, 4, b16);
2000-04-03 22:13:57 +00:00
}
} else {
2001-12-30 00:15:25 +00:00
if (display_props->width >= 20) {
drivers_string (1, 1, t20);
drivers_string (1, 2, l20);
2000-04-03 22:13:57 +00:00
} else {
2001-12-30 00:15:25 +00:00
drivers_string (1, 1, t16);
drivers_string (1, 2, l16);
2000-04-03 22:13:57 +00:00
}
}
2001-12-30 00:15:25 +00:00
drivers_flush ();
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}