source: titan/plugins/satipclient/satipclient.h @ 45420

Last change on this file since 45420 was 45420, checked in by obi, 3 years ago

update satipclient and fix last pos if not press ok/exit

File size: 6.0 KB
Line 
1#ifndef SATIPCLIENT_H
2#define SATIPCLIENT_H
3
4void screensatipclient()
5{
6        int rcret = -1, ret = 0, i = 0, j = 0, count1 = 0, count2 = 0;
7        struct skin* satipclient = getscreen("satipclientsettings");
8        struct skin* listbox = getscreennode(satipclient, "listbox");
9        char* tmpstr = NULL,*tmpstr1 = NULL, *tmpstr2 = NULL, *satipclientstop = NULL, *satipclientstart = NULL, *satipclientscan = NULL, *satipclientrun = NULL, *satipclientconfig = NULL, *cmd = NULL;
10        char* name = NULL, *text = NULL, *type = NULL, *ip = NULL, *showname = NULL, *desc = NULL, *vtunerconf = NULL;
11       
12        struct skin* tmp = NULL;
13        struct skin* node = NULL;
14
15        satipclientstop = ostrcat("/etc/init.d/satipclient stop", NULL, 0, 0);
16        satipclientstart = ostrcat("/etc/init.d/satipclient start", NULL, 0, 0);
17        satipclientscan = createpluginpath("/satipclient/files/scan.py", 0);
18        satipclientrun = createpluginpath("/satipclient/files/run.sh", 0);
19        satipclientconfig = ostrcat("cp /mnt/network/vtuner.conf /etc", NULL, 0, 0);
20
21        addscreenrc(satipclient, listbox);
22        listbox->aktline = 1;
23        listbox->aktpage = 1;
24
25        vtunerconf = ostrcat("/mnt/network/vtuner.conf", NULL, 0, 0);
26
27        struct clist *myconfig[LISTHASHSIZE] = {NULL};
28        readconfig(vtunerconf, myconfig);
29
30        cmd = ostrcat("cat ", vtunerconf, 0, 0);
31        cmd = ostrcat(cmd, " | cut -d'=' -f2", 1, 0);
32
33        struct splitstr* ret1 = NULL;
34        tmpstr1 = string_newline(command(cmd));
35
36        ret1 = strsplit(tmpstr1, "\n", &count1);
37        if(ret1 != NULL && count1 > 0)
38        {       
39                for(i = 0; i < count1; i++)
40                {
41                        printf("round i-count1 (%d/%d)\n", i, count1);
42                        count2 = 0;
43                        tmpstr2 = string_newline(command(cmd));
44                        struct splitstr* ret2 = NULL;
45
46                        node = addlistbox(satipclient, listbox, node, 1);
47                        if(node != NULL)
48                        {
49                                node->type = CHOICEBOX;
50                                text = ostrcat(_("VTUNER"), " (", 0, 0);
51                                text = ostrcat(text, oitoa(i), 1, 1);
52                                text = ostrcat(text, ")", 1, 0);
53                                name = ostrcat(oitoa(i), NULL, 1, 0);
54                                changetext(node, text);
55                                changename(node, name);
56
57                                ret2 = strsplit(tmpstr2, "\n", &count2);
58                                if(ret2 != NULL && count2 > 0)
59                                {
60                                        for(j = 0; j < count2; j++)
61                                        {
62                                                desc = oregex(".*desc:(.*),ipaddr:.*", ret2[j].part);
63                                                if(desc != NULL)
64                                                {
65                                                        showname = ostrcat(showname, desc, 1, 0);
66                                                        showname = ostrcat(showname, " (", 1, 0);
67                                                        ip = oregex(".*,ipaddr:(.*),tuner_type:.*", ret2[j].part);
68                                                        showname = ostrcat(showname, ip, 1, 0);
69                                                        showname = ostrcat(showname, ") ", 1, 0);
70                                                        type = oregex(".*,tuner_type:(.*),uuid:.*", ret2[j].part);
71                                                        showname = ostrcat(showname, type, 1, 0);
72                                                }
73                                                else
74                                                {
75                                                        showname = ostrcat(showname, _("is not used"), 1, 0);
76                                                }
77
78                                                addchoicebox(node, ret2[j].part, showname);
79                                                printf("addchoicebox: showname=%s entry=%s\n", showname, ret2[j].part);
80
81                                                free(type), type = NULL;
82                                                free(ip), ip = NULL;
83                                                free(desc), desc = NULL;
84                                                free(showname), showname = NULL;
85                                        }
86                                }
87                                free(ret2), ret2 = NULL;
88                                setchoiceboxselection(node, getlist(myconfig, node->name, NULL));
89                                free(text), text = NULL;
90                                free(name), name = NULL;
91                        }
92                }
93        }
94        free(ret1), ret1 = NULL;
95        free(cmd), cmd = NULL;
96
97        drawscreen(satipclient, 0, 0);
98        tmp = listbox->select;
99
100        while(1)
101        {
102                addscreenrc(satipclient, tmp);
103                rcret = waitrc(satipclient, 0, 0);
104                tmp = listbox->select;
105
106                if(listbox->select != NULL)
107                        addlist(myconfig, listbox->select->name, listbox->select->ret);
108
109                if(rcret == getrcconfigint("rcexit", NULL)) break;
110                if(rcret == getrcconfigint("rcok", NULL))
111                {
112                        writelist(myconfig, vtunerconf);
113
114                        debug(10, "cmd: %s", satipclientconfig);
115                        system(satipclientconfig);
116
117                        debug(10, "cmd: %s", satipclientstop);
118                        system(satipclientstop);
119                        debug(10, "cmd: %s", satipclientstart);
120                        ret = system(satipclientstart);
121                        if(ret == 0)
122                                textbox(_("Message"), _("SAT-IP Client started and config saved"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 5, 0);
123                        else
124                                textbox(_("Message"), _("SAT-IP Client not started,\nPlease check your config."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
125                        drawscreen(satipclient, 0, 0);                 
126
127                        break;
128                }
129                else if(rcret == getrcconfigint("rcred", NULL))
130                {
131                        debug(10, "cmd: %s", satipclientstop);
132                        system(satipclientstop);
133                        textbox(_("Message"), _("SAT-IP Client now stopped"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 5, 0);
134                        drawscreen(satipclient, 0, 0);
135                }
136                else if(rcret == getrcconfigint("rcgreen", NULL))
137                {
138                        writelist(myconfig, vtunerconf);
139
140                        debug(10, "cmd: %s", satipclientconfig);
141                        system(satipclientconfig);
142
143                        debug(10, "cmd: %s", satipclientstop);
144                        system(satipclientstop);
145
146                        debug(10, "cmd: %s", satipclientstart);
147                        ret = system(satipclientstart);
148                        if(ret == 0)
149                                textbox(_("Message"), _("SAT-IP Client started."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 5, 0);
150                        else
151                                textbox(_("Message"), _("SAT-IP Client not started,\nPlease check your config."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
152                        drawscreen(satipclient, 0, 0);
153                }
154                else if(rcret == getrcconfigint("rcyellow", NULL))
155                {
156                        cmd = ostrcat(satipclientrun, " ", 0, 0);
157                        cmd = ostrcat(cmd, satipclientscan, 1, 0);
158                        debug(10, "cmd: %s", cmd);
159                       
160                        tmpstr = command(cmd);
161                        free(cmd), cmd = NULL;
162                        debug(10, "tmpstr: %s", tmpstr);
163
164                        textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 900, 500, 0, 0);
165                        free(tmpstr), tmpstr = NULL;
166                        drawscreen(satipclient, 0, 0);
167                }
168                else if(rcret == getrcconfigint("rcblue", NULL))
169                {
170                        screentunerconfig();
171                        writeallconfig(1);
172                        drawscreen(satipclient, 0, 0);
173                }
174        }
175
176        free(vtunerconf), vtunerconf = NULL;
177        free(satipclientstart), satipclientstart = NULL;
178        free(satipclientstop), satipclientstop = NULL;
179        free(satipclientscan), satipclientscan = NULL;
180        free(satipclientconfig), satipclientconfig = NULL;
181
182        delownconfigtmpall();
183        delmarkedscreennodes(satipclient, 1);
184        delownerrc(satipclient);
185        clearscreen(satipclient);
186}
187
188#endif
Note: See TracBrowser for help on using the repository browser.