JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Inintial import
[now-playing-d.git] / now-playing-d.c
1 /* now-playing-d.c
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include <stdio.h>
19 #include <gtk/gtk.h>
20 #include "eggtrayicon.h"
21
22
23 char buf[1000];
24 char* playing[2] = {&buf[0], &buf[500]};
25 int playing_i = 0;
26
27
28 // this gets called regularly by gtk
29 static gboolean
30 ticker(GtkWidget *widget) {
31         FILE * fd;
32         int len;
33
34         if (widget->window == NULL) {
35                 return FALSE;
36         }
37
38         fd = fopen(TMP_FILE, "r");
39         if(fd == NULL) {
40                 return TRUE;
41         }
42         len = fread(playing[playing_i], 1, 499, fd);
43         fclose(fd);
44         playing[playing_i][len] = 0;
45
46         if(strcmp(playing[playing_i], playing[1 - playing_i])) {
47                 gtk_label_set_text(GTK_LABEL(widget), playing[playing_i]);
48         }
49
50         playing_i = 1 - playing_i;
51
52         // gtk_widget_queue_draw(widget);
53         return TRUE;
54 }
55
56
57 int
58 main(int argc, char *argv[]) {
59         GtkWidget *label;
60         EggTrayIcon *egg;
61
62         // initialize GTK
63         gtk_set_locale();
64         gtk_init(&argc, &argv);
65
66         // make the widget
67         label = gtk_label_new("initializing...");
68         egg = egg_tray_icon_new("what's this string do?");
69         // nest and display the widget
70         gtk_container_add(GTK_CONTAINER(egg), label);
71         gtk_widget_show_all(GTK_WIDGET(egg));
72
73         // initialize and start ticker
74         playing[0][0] = 0;
75         playing[1][0] = 0;
76         g_timeout_add(1000, (GSourceFunc) ticker, (gpointer) label);
77
78         gtk_main();
79 }