1 | #ifndef TEXTINPUTHIST_H |
---|
2 | #define TEXTINPUTHIST_H |
---|
3 | |
---|
4 | void 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 | |
---|
41 | void 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 | |
---|
78 | void 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 | |
---|
110 | char* 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 | if(title == NULL) title = ostrcat(_("Input field"), NULL, 0, 0); |
---|
123 | |
---|
124 | changetitle(textinputhist, _(title)); |
---|
125 | |
---|
126 | height = textinputhist->height; |
---|
127 | if(title != NULL) |
---|
128 | textinputhist->height += textinputhist->fontsize + 6 + (textinputhist->bordersize * 2); |
---|
129 | |
---|
130 | if(text != NULL) |
---|
131 | tmpstr = ostrcat(tmpstr, text, 1, 0); |
---|
132 | |
---|
133 | changeinput(input, tmpstr); |
---|
134 | readhistory(textinputhist, listbox, histname); |
---|
135 | |
---|
136 | if(fromthread == 1) |
---|
137 | { |
---|
138 | delrc(getrcconfigint("rcvolup", NULL), NULL, NULL); |
---|
139 | delrc(getrcconfigint("rcvoldown", NULL), NULL, NULL); |
---|
140 | delrc(getrcconfigint("rcmute", NULL), NULL, NULL); |
---|
141 | m_lock(&status.drawingmutex, 0); |
---|
142 | m_lock(&status.rcmutex, 10); |
---|
143 | setnodeattr(textinputhist, framebuffer, 2); |
---|
144 | status.rcowner = textinputhist; |
---|
145 | bg = savescreen(textinputhist); |
---|
146 | drawscreen(textinputhist, 0, 2); |
---|
147 | } |
---|
148 | else |
---|
149 | drawscreen(textinputhist, 0, 0); |
---|
150 | |
---|
151 | addrc(getrcconfigint("rcup", NULL), listboxup, textinputhist, listbox); |
---|
152 | addrc(getrcconfigint("rcdown", NULL), listboxdown, textinputhist, listbox); |
---|
153 | addscreenrc(textinputhist, input); |
---|
154 | |
---|
155 | while(1) |
---|
156 | { |
---|
157 | rcret = waitrc(textinputhist, 0, 0); |
---|
158 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
159 | |
---|
160 | if(rcret == getrcconfigint("rcok", NULL) && tmpstr != NULL && listbox->select != NULL && (input->input == NULL || ostrcmp(input->input, " ") == 0)) |
---|
161 | { |
---|
162 | changeinput(input, listbox->select->name); |
---|
163 | |
---|
164 | if(fromthread == 1) |
---|
165 | drawscreen(textinputhist, 0, 2); |
---|
166 | else |
---|
167 | drawscreen(textinputhist, 0, 0); |
---|
168 | |
---|
169 | ret = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
170 | strstrip(ret); |
---|
171 | savehistory(ret, histname); |
---|
172 | break; |
---|
173 | } |
---|
174 | else if(rcret == getrcconfigint("rcok", NULL) && input->input != NULL) |
---|
175 | { |
---|
176 | ret = ostrcat(input->input, NULL, 0, 0); |
---|
177 | strstrip(ret); |
---|
178 | savehistory(ret, histname); |
---|
179 | break; |
---|
180 | } |
---|
181 | |
---|
182 | if(rcret == getrcconfigint("rcyellow", NULL) && listbox->select != NULL) |
---|
183 | { |
---|
184 | changeinput(input, listbox->select->name); |
---|
185 | if(fromthread == 1) |
---|
186 | drawscreen(textinputhist, 0, 2); |
---|
187 | else |
---|
188 | drawscreen(textinputhist, 0, 0); |
---|
189 | |
---|
190 | writerc(getrcconfigint("rctext", NULL)); |
---|
191 | } |
---|
192 | |
---|
193 | if(rcret == getrcconfigint("rcred", NULL)) |
---|
194 | { |
---|
195 | free(tmpstr), tmpstr = NULL; |
---|
196 | tmpstr = ostrcat(tmpstr, NULL, 1, 0); |
---|
197 | changeinput(input, tmpstr); |
---|
198 | if(fromthread == 1) |
---|
199 | drawscreen(textinputhist, 0, 2); |
---|
200 | else |
---|
201 | drawscreen(textinputhist, 0, 0); |
---|
202 | } |
---|
203 | |
---|
204 | if(rcret == getrcconfigint("rcgreen", NULL) && listbox->select != NULL) |
---|
205 | { |
---|
206 | ret = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
207 | removehistory(ret, histname); |
---|
208 | free(ret); ret = NULL; |
---|
209 | listbox->aktline = 1; |
---|
210 | listbox->aktpage = -1; |
---|
211 | delmarkedscreennodes(textinputhist, 1); |
---|
212 | readhistory(textinputhist, listbox, histname); |
---|
213 | if(fromthread == 1) |
---|
214 | drawscreen(textinputhist, 0, 2); |
---|
215 | else |
---|
216 | drawscreen(textinputhist, 0, 0); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | free(tmpstr), tmpstr = NULL; |
---|
221 | delownerrc(textinputhist); |
---|
222 | delrc(getrcconfigint("rcup", NULL), textinputhist, listbox); |
---|
223 | delrc(getrcconfigint("rcdown", NULL), textinputhist, listbox); |
---|
224 | |
---|
225 | if(fromthread == 1) |
---|
226 | { |
---|
227 | clearscreennolock(textinputhist); |
---|
228 | restorescreen(bg, textinputhist); |
---|
229 | blitfb(0); |
---|
230 | sleep(1); |
---|
231 | status.rcowner = NULL; |
---|
232 | m_unlock(&status.rcmutex, 3); |
---|
233 | m_unlock(&status.drawingmutex, 0); |
---|
234 | addrc(getrcconfigint("rcvolup", NULL), screenvolumeup, NULL, NULL); |
---|
235 | addrc(getrcconfigint("rcvoldown", NULL), screenvolumedown, NULL, NULL); |
---|
236 | addrc(getrcconfigint("rcmute", NULL), screenmute, NULL, NULL); |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | clearscreen(textinputhist); |
---|
241 | drawscreen(skin, 0, 0); |
---|
242 | } |
---|
243 | |
---|
244 | textinputhist->height = height; |
---|
245 | delmarkedscreennodes(textinputhist, 1); |
---|
246 | return ret; |
---|
247 | } |
---|
248 | |
---|
249 | #endif |
---|