added function kill to conky
[livewp] / applet / src / livewp-conky.c
1 /*vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 of
12  * the License, or (at your option) any later version.
13  * 
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-conky.h"
26 void create_config(gboolean sleep){
27     FILE    *file_in;
28     FILE    *file_out;
29     gchar buffer[2048];
30
31     file_in = fopen("/etc/conky/conky.conf","r");
32     file_out = fopen("/tmp/conky.conf","w");
33     if (file_in && file_out){
34         while (!feof(file_in)) {
35             memset(buffer, 0, sizeof(buffer));
36             fgets(buffer, sizeof(buffer) - 1, file_in);
37             if (!strcmp(buffer, "own_window yes\n")){
38                 fputs("own_window no\n", file_out);
39                 continue;
40             }
41             if (!strcmp(buffer, "$alignc $nodename - $sysname $kernel on $machine ${color yellow}Uptime:$color $uptime\n")){
42                 fputs("$alignr $nodename\n$alignr $sysname $kernel on $machine\n", file_out);
43                 fputs("$alignr ${color yellow}Uptime:$color $uptime\n", file_out);
44                 continue;
45             }
46             if (!strcmp(buffer, "gap_y 60\n")){
47                 fputs("gap_y 0\n", file_out);
48                 continue;
49             }
50             if (!strcmp(buffer, "gap_x 20\n")){
51                 fputs("gap_x 5\n", file_out);
52                 continue;
53             }
54             if (!strcmp(buffer, "update_interval 3.0\n") && sleep){
55                 fputs("update_interval 20.0\n", file_out);
56                 continue;
57             }
58             if (!strcmp(buffer, "${color #24ff00} ${top name 4}    ${top pid 4} ${top cpu 4} ${top mem 4}")){
59                 fputs(buffer, file_out);
60                 fputs("\n${color #20ff00} ${top name 5}    ${top pid 5} ${top cpu 5} ${top mem 5}\n", file_out);
61                 fputs("${color #16ff00} ${top name 6}    ${top pid 6} ${top cpu 6} ${top mem 6}\n", file_out);
62                 continue;
63             }
64     
65             fputs(buffer, file_out);
66         }
67         fclose(file_out);
68         fclose(file_in);
69     }
70
71 }
72 void 
73 init_scene_Conky(AWallpaperPlugin *desktop_plugin){
74     create_config(False);
75     init_scene_External(desktop_plugin);
76 }
77 void
78 conky_visible(AWallpaperPlugin *desktop_plugin){
79     if (desktop_plugin->priv->visible)
80         create_config(FALSE);
81     else
82         create_config(TRUE);
83     kill (desktop_plugin->priv->podpid, SIGHUP);
84 }