source: titan/titan/textinputhist.h @ 26495

Last change on this file since 26495 was 25633, checked in by obi, 10 years ago

fix suche

File size: 6.3 KB
Line 
1#ifndef TEXTINPUTHIST_H
2#define TEXTINPUTHIST_H
3
4void removehistory(char* text, char* histname)
5{
6        int count = 0, i = 0;
7        char* tmpstr = NULL, *tmpstr1 = NULL;
8        struct splitstr* ret = NULL;
9
10        if(histname == NULL || text == NULL || strlen(text) == 0) return;
11
12        tmpstr = readfiletomem(getconfig(histname, NULL), 0);
13       
14        ret = strsplit(tmpstr, "\n", &count);
15
16        if(ret != NULL)
17        {
18                for(i = 0; i < count; i++)
19                {
20                        if(ostrstr(ret[i].part, text) == NULL)
21                        {
22                                tmpstr1 = ostrcat(tmpstr1, ret[i].part, 1, 0);
23                                tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
24                        }
25                }
26        }
27
28        if(tmpstr1 != NULL && strlen(tmpstr1) > 0)
29                tmpstr1[strlen(tmpstr1) - 1] = '\0';
30
31        if(tmpstr1 == NULL)
32                writesys(getconfig(histname, NULL), "", 0);
33        else
34                writesys(getconfig(histname, NULL), tmpstr1, 0);
35
36        free(ret); ret = NULL;
37        free(tmpstr); tmpstr = NULL;
38        free(tmpstr1); tmpstr1 = NULL;
39}
40
41void savehistory(char* text, char* histname)
42{
43        int count = 0, i = 0;
44        char* tmpstr = NULL, *tmpstr1 = NULL;
45        struct splitstr* ret = NULL;
46
47        if(histname == NULL || text == NULL || strlen(text) == 0) return;
48
49        tmpstr1 = ostrcat(tmpstr1, text, 1, 0);
50        tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
51
52        tmpstr = readfiletomem(getconfig(histname, NULL), 0);
53       
54        ret = strsplit(tmpstr, "\n", &count);
55
56        if(ret != NULL)
57        {
58                for(i = 0; i < count; i++)
59                {
60                        if(ostrstr(ret[i].part, text) == NULL)
61                        {
62                                tmpstr1 = ostrcat(tmpstr1, ret[i].part, 1, 0);
63                                tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
64                        }
65                }
66        }
67
68        if(tmpstr1 != NULL && strlen(tmpstr1) > 0)
69                tmpstr1[strlen(tmpstr1) - 1] = '\0';
70
71        writesys(getconfig(histname, NULL), tmpstr1, 0);
72
73        free(ret); ret = NULL;
74        free(tmpstr); tmpstr = NULL;
75        free(tmpstr1); tmpstr1 = NULL;
76}
77
78void readhistory(struct skin* textinputhist, struct skin* listbox, char* histname)
79{
80        int count = 0, i = 0;
81        char* tmpstr = NULL;
82        struct skin* tmp = NULL;
83        struct splitstr* ret = NULL;
84
85        if(histname == NULL) return;
86
87        listbox->aktline = 1;
88        listbox->aktpage = -1;
89
90        tmpstr = readfiletomem(getconfig(histname, NULL), 0);
91        ret = strsplit(tmpstr, "\n", &count);
92
93        if(ret != NULL)
94        {
95                for(i = 0; i < count; i++)
96                {
97                        tmp = addlistbox(textinputhist, listbox, tmp, 1);
98                        if(tmp != NULL)
99                        {
100                                changetext(tmp, ret[i].part);
101                                changename(tmp, ret[i].part);
102                        }
103                }
104        }
105
106        free(ret); ret = NULL;
107        free(tmpstr); tmpstr = NULL;
108}
109
110char* textinputhist(char* title, char* text, char* histname)
111{
112        int rcret = -1, fromthread = 0, height = 0;
113        struct skin* textinputhist = getscreen("textinputhist");
114        struct skin* listbox = getscreennode(textinputhist, "listbox");
115        struct skin* input = getscreennode(textinputhist, "input");
116        struct skin* framebuffer = getscreen("framebuffer");
117        char* ret = NULL, *bg = NULL, *tmpstr = NULL;
118
119        if(pthread_self() != status.mainthread)
120        fromthread = 1;
121
122        changetitle(textinputhist, _(title));
123        height = textinputhist->height;
124        if(title != NULL)
125                textinputhist->height += textinputhist->fontsize + 6 + (textinputhist->bordersize * 2);
126
127        if(text != NULL)
128                tmpstr = ostrcat(tmpstr, text, 1, 0);
129
130        changeinput(input, tmpstr);
131        readhistory(textinputhist, listbox, histname);
132
133        if(fromthread == 1)
134        {
135                delrc(getrcconfigint("rcvolup", NULL), NULL, NULL);
136                delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL);
137                delrc(getrcconfigint("rcmute", NULL), NULL, NULL);
138                m_lock(&status.drawingmutex, 0);
139                m_lock(&status.rcmutex, 10);
140                setnodeattr(textinputhist, framebuffer, 2);
141                status.rcowner = textinputhist;
142                bg = savescreen(textinputhist);
143                drawscreen(textinputhist, 0, 2);
144        }
145        else
146                drawscreen(textinputhist, 0, 0);
147
148        addrc(getrcconfigint("rcup", NULL), listboxup, textinputhist, listbox);
149        addrc(getrcconfigint("rcdown", NULL), listboxdown, textinputhist, listbox);
150        addscreenrc(textinputhist, input);
151
152        while(1)
153        {
154                rcret = waitrc(textinputhist, 0, 0);
155                if(rcret == getrcconfigint("rcexit", NULL)) break;
156               
157                if(rcret == getrcconfigint("rcok", NULL) && tmpstr != NULL && listbox->select != NULL && (input->input == NULL || ostrcmp(input->input, " ") == 0))
158                {
159                        changeinput(input, listbox->select->name);
160
161                        if(fromthread == 1)
162                                drawscreen(textinputhist, 0, 2);
163                        else
164                                drawscreen(textinputhist, 0, 0);
165                       
166                        ret = ostrcat(listbox->select->name, NULL, 0, 0);
167                        strstrip(ret);
168                        savehistory(ret, histname);
169                        break;
170                }
171                else if(rcret == getrcconfigint("rcok", NULL) && input->input != NULL)
172                {
173                        ret = ostrcat(input->input, NULL, 0, 0);
174                        strstrip(ret);
175                        savehistory(ret, histname);
176                        break;
177                }
178               
179                if(rcret == getrcconfigint("rcyellow", NULL) && listbox->select != NULL)
180                {
181                        changeinput(input, listbox->select->name);
182                        if(fromthread == 1)
183                                drawscreen(textinputhist, 0, 2);
184                        else
185                                drawscreen(textinputhist, 0, 0);
186                       
187                        writerc(getrcconfigint("rctext", NULL));
188                }
189
190                if(rcret == getrcconfigint("rcred", NULL))
191                {
192                        free(tmpstr), tmpstr = NULL;
193                        tmpstr = ostrcat(tmpstr, NULL, 1, 0);
194                        changeinput(input, tmpstr);
195                        if(fromthread == 1)
196                                drawscreen(textinputhist, 0, 2);
197                        else
198                                drawscreen(textinputhist, 0, 0);
199                }
200
201                if(rcret == getrcconfigint("rcgreen", NULL) && listbox->select != NULL)
202                {
203                        ret = ostrcat(listbox->select->name, NULL, 0, 0);
204                        removehistory(ret, histname);
205                        free(ret); ret = NULL;
206                        listbox->aktline = 1;
207                        listbox->aktpage = -1;
208                        delmarkedscreennodes(textinputhist, 1);
209                        readhistory(textinputhist, listbox, histname);
210                        if(fromthread == 1)
211                                drawscreen(textinputhist, 0, 2);
212                        else
213                                drawscreen(textinputhist, 0, 0);
214                }
215        }
216
217        free(tmpstr), tmpstr = NULL;
218        delownerrc(textinputhist);
219        delrc(getrcconfigint("rcup", NULL), textinputhist, listbox);
220        delrc(getrcconfigint("rcdown", NULL), textinputhist, listbox);
221
222        if(fromthread == 1)
223        {
224                clearscreennolock(textinputhist);
225                restorescreen(bg, textinputhist);
226                blitfb(0);
227                sleep(1);
228                status.rcowner = NULL;
229                m_unlock(&status.rcmutex, 3);
230                m_unlock(&status.drawingmutex, 0);
231                addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL);
232                addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL);
233                addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL);
234        }
235        else
236        {
237                clearscreen(textinputhist);
238                drawscreen(skin, 0, 0);
239        }
240
241        textinputhist->height = height;
242        delmarkedscreennodes(textinputhist, 1);
243        return ret;
244}
245
246#endif
Note: See TracBrowser for help on using the repository browser.