source: titan/plugins/filemanager/filemanager.h @ 22419

Last change on this file since 22419 was 22419, checked in by obi, 11 years ago

fix

File size: 10.9 KB
Line 
1#ifndef FILEMANAGER_H
2#define FILEMANAGER_H
3
4void filemanagerrename(int aktfilelist, struct skin* filelist1, struct skin* filelistpath1, struct skin* filelist2, struct skin* filelistpath2)
5{
6        char* tmpstr = NULL, *file1 = NULL, *cmd = NULL;
7
8        if(filelistpath1 == NULL || filelistpath2 == NULL)
9                return;
10
11        if(filelist1 == NULL || filelist1->select == NULL)
12                return;
13
14        if(filelist2 == NULL || filelist2->select == NULL)
15                return;
16
17        if(aktfilelist == 0)
18                tmpstr = ostrcat(filelist1->select->text, NULL, 0, 0);
19        else
20                tmpstr = ostrcat(filelist2->select->text, NULL, 0, 0);
21               
22        char* search = textinput(_("Rename"), tmpstr);
23        free(tmpstr); tmpstr = NULL;
24
25        if(search != NULL)
26        {
27                if(aktfilelist == 0)
28                {
29                        file1 = createpath(filelistpath1->text, filelist1->select->text);
30                        tmpstr = createpath(filelistpath1->text, search);
31                }
32                else
33                {
34                        file1 = createpath(filelistpath2->text, filelist2->select->text);
35                        tmpstr = createpath(filelistpath2->text, search);
36                }
37
38                if(!file_exist(tmpstr))
39                {
40                        cmd = ostrcat(cmd, "mv -f \"", 1, 0);
41                        cmd = ostrcat(cmd, file1, 1, 0);
42                        cmd = ostrcat(cmd, "\" \"", 1, 0);
43                        cmd = ostrcat(cmd, tmpstr, 1, 0);
44                        cmd = ostrcat(cmd, "\"", 1, 0);
45                        printf("cmd: %s\n",cmd);
46                        system(cmd);
47                        free(cmd); cmd = NULL;
48                }
49
50                free(tmpstr); tmpstr = NULL;
51                free(search); search = NULL;
52        }
53}
54
55void filemanagercreatefolder(int aktfilelist, struct skin* filelist1, struct skin* filelistpath1, struct skin* filelist2, struct skin* filelistpath2)
56{
57        char* tmpstr = NULL;
58
59        if(filelistpath1 == NULL || filelistpath2 == NULL)
60                return;
61
62        if(filelist1 == NULL || filelist1->select == NULL)
63                return;
64
65        if(filelist2 == NULL || filelist2->select == NULL)
66                return;
67
68        char* search = textinputhist(_("Create Folder"), " ", "searchhist");
69        if(search != NULL)
70        {
71                if(aktfilelist == 0)
72                        tmpstr = createpath(filelistpath1->text, search);
73                else
74                        tmpstr = createpath(filelistpath2->text, search);
75
76                if(!file_exist(tmpstr))
77                        mkdir(tmpstr, 0777);
78
79        }
80
81        free(tmpstr); tmpstr = NULL;
82        free(search); search = NULL;
83}
84                       
85void filemanagermenu(int aktfilelist, struct skin* filelist1, struct skin* filelistpath1, struct skin* filelist2, struct skin* filelistpath2)
86{
87        struct menulist* mlist = NULL, *mbox = NULL;
88        char* skintitle = "Menu";
89
90        addmenulist(&mlist, "Rename", NULL, NULL, 0, 0);
91        addmenulist(&mlist, "Create Folder", NULL, NULL, 0, 0);
92
93        mbox = menulistbox(mlist, NULL, skintitle, NULL, NULL, 1, 0);
94        if(mbox != NULL)
95        {
96                if(ostrcmp(mbox->name, "Rename") == 0)
97                        filemanagerrename(aktfilelist, filelist1, filelistpath1, filelist2, filelistpath1);
98                else if(ostrcmp(mbox->name, "Create Folder") == 0)
99                        filemanagercreatefolder(aktfilelist, filelist1, filelistpath1, filelist2, filelistpath1);
100
101        }
102
103        freemenulist(mlist, 1); mlist = NULL;
104}
105
106void screenfilemanager()
107{
108        int rcret = 0, aktfilelist = 0, ret = 0;
109        long bgcol1 = 0, bgcol2 = 0;
110        struct skin* filemanager = getscreen("filemanager");
111        struct skin* filemanager1 = getscreen("filemanager1");
112        struct skin* filemanager2 = getscreen("filemanager2");
113        struct skin* filelistpath1 = getscreennode(filemanager1, "filelistpath");
114        struct skin* filelist1 = getscreennode(filemanager1, "filelist");
115        struct skin* filelistpath2 = getscreennode(filemanager2, "filelistpath");
116        struct skin* filelist2 = getscreennode(filemanager2, "filelist");
117        char* file1 = NULL, *cmd = NULL, *tmpstr = NULL;
118        struct skin* tmpfilelist = filelist1;
119
120        filelist1->aktline = 0;
121        filelist1->aktpage = 0;
122        changemask(filelist1, "*");
123        changeinput(filelist1, "/");
124        changetext(filelistpath1, filelist1->input);
125       
126        filelist2->aktline = 0;
127        filelist2->aktpage = 0;
128        changemask(filelist2, "*");
129        changeinput(filelist2, "/");
130        changetext(filelistpath2, filelist2->input);
131
132        delmarkedscreennodes(filemanager1, FILELISTDELMARK);
133        delmarkedscreennodes(filemanager2, FILELISTDELMARK);
134        createfilelist(filemanager1, filelist1, 0);
135        createfilelist(filemanager2, filelist2, 0);
136
137        bgcol1 = filelistpath1->bgcol;
138        bgcol2 = filelistpath2->bgcol;
139
140        filelistpath1->bgcol = convertcol("markcol");
141       
142        drawscreen(filemanager, 0, 1);
143        drawscreen(filemanager1, 0, 1);
144        drawscreen(filemanager2, 0, 0);
145        addscreenrc(filemanager1, filelist1);
146        delrc(getrcconfigint("rcff", NULL), filemanager1, filelist1);
147        delrc(getrcconfigint("rcfr", NULL), filemanager1, filelist1);
148
149        while(1)
150        {
151                if(aktfilelist == 0)
152                {
153                        rcret = waitrc(filemanager1, 0, 0);
154                        tmpfilelist = filelist1;
155                }
156                else
157                {
158                        rcret = waitrc(filemanager2, 0, 0);
159                        tmpfilelist = filelist2;
160                }
161               
162                if(rcret == getrcconfigint("rcexit", NULL)) break;
163
164                if(status.security == 1)
165                {
166                        if((rcret == getrcconfigint("rcgreen", NULL) || rcret == getrcconfigint("rcyellow", NULL)) && tmpfilelist->select != NULL && ostrcmp(tmpfilelist->select->text, "..") != 0) //copy - move
167                        {
168                                if(aktfilelist == 0)
169                                        file1 = createpath(filelistpath1->text, filelist1->select->text);
170                                else
171                                        file1 = createpath(filelistpath2->text, filelist2->select->text);
172
173                                if(file1 != NULL)
174                                {
175                                        if(rcret == getrcconfigint("rcgreen", NULL))
176                                        {
177                                                tmpstr = ostrcat(tmpstr, _("Realy copy this file/dir?"), 1, 0);
178                                                cmd = ostrcat(cmd, "cp -r ", 1, 0);
179                                        }
180                                        if(rcret == getrcconfigint("rcyellow", NULL))
181                                        {
182                                                tmpstr = ostrcat(tmpstr, _("Realy move this file/dir?"), 1, 0);
183                                                cmd = ostrcat(cmd, "mv ", 1, 0);
184                                        }
185                                       
186                                        tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
187                                        tmpstr = ostrcat(tmpstr, _("From"), 1, 0);
188                                        tmpstr = ostrcat(tmpstr, ": ", 1, 0);                           
189                                        tmpstr = ostrcat(tmpstr, file1, 1, 0);
190                                        tmpstr = ostrcat(tmpstr, "\n", 1, 0);
191                                        tmpstr = ostrcat(tmpstr, _("To"), 1, 0);
192                                        tmpstr = ostrcat(tmpstr, ": ", 1, 0);
193                                        if(aktfilelist == 0)
194                                                tmpstr = ostrcat(tmpstr, filelistpath2->text, 1, 0);
195                                        else
196                                                tmpstr = ostrcat(tmpstr, filelistpath1->text, 1, 0);
197                                        ret = textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 300, 0, 0);
198                                        free(tmpstr); tmpstr = NULL;
199                                       
200                                        cmd = ostrcat(cmd, "\"", 1, 0);
201                                        cmd = ostrcat(cmd, file1, 1, 0);
202                                        cmd = ostrcat(cmd, "\" \"", 1, 0);
203                                        if(aktfilelist == 0)
204                                                cmd = ostrcat(cmd, filelistpath2->text, 1, 0);
205                                        else
206                                                cmd = ostrcat(cmd, filelistpath1->text, 1, 0);
207                                        cmd = ostrcat(cmd, "\"", 1, 0);
208                                        if(ret == 1) system(cmd);
209                                        free(cmd); cmd = NULL;
210                                }
211                                free(file1); file1 = NULL;
212                               
213                                if(ret == 1)
214                                {
215                                        delmarkedscreennodes(filemanager1, FILELISTDELMARK);
216                                        delmarkedscreennodes(filemanager2, FILELISTDELMARK);
217                                        createfilelist(filemanager1, filelist1, 0);
218                                        createfilelist(filemanager2, filelist2, 0);
219                                }
220                                drawscreen(filemanager, 0, 1);
221                                drawscreen(filemanager1, 0, 1);
222                                drawscreen(filemanager2, 0, 0);
223                        }
224                       
225                        if(rcret == getrcconfigint("rcred", NULL) && tmpfilelist->select != NULL && ostrcmp(tmpfilelist->select->text, "..") != 0) //delete
226                        {
227                                if(aktfilelist == 0)
228                                        file1 = createpath(filelistpath1->text, filelist1->select->text);
229                                else
230                                        file1 = createpath(filelistpath2->text, filelist2->select->text);
231                                if(file1 != NULL)
232                                {
233                                        tmpstr = ostrcat(tmpstr, _("Realy delete this file/dir?"), 1, 0);
234                                        tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
235                                        tmpstr = ostrcat(tmpstr, file1, 1, 0);
236                                        ret = textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0);
237                                        free(tmpstr); tmpstr = NULL;
238                                       
239                                        cmd = ostrcat(cmd, "rm -rf ", 1, 0);
240                                        cmd = ostrcat(cmd, "\"", 1, 0);
241                                        cmd = ostrcat(cmd, file1, 1, 0);
242                                        cmd = ostrcat(cmd, "\"", 1, 0);
243                                        if(ret == 1) system(cmd);
244                                        free(cmd); cmd = NULL;                 
245                                }
246                                free(file1); file1 = NULL;
247                               
248                                if(ret == 1)
249                                {
250                                        delmarkedscreennodes(filemanager1, FILELISTDELMARK);
251                                        delmarkedscreennodes(filemanager2, FILELISTDELMARK);
252                                        createfilelist(filemanager1, filelist1, 0);
253                                        createfilelist(filemanager2, filelist2, 0);
254                                }
255                                drawscreen(filemanager, 0, 1);
256                                drawscreen(filemanager1, 0, 1);
257                                drawscreen(filemanager2, 0, 0);
258                        }
259                       
260                        if(rcret == getrcconfigint("rcblue", NULL) && tmpfilelist->select != NULL && ostrcmp(tmpfilelist->select->text, "..") != 0) //view
261                        {
262                                if(aktfilelist == 0)
263                                        file1 = createpath(filelistpath1->text, filelist1->select->text);
264                                else
265                                        file1 = createpath(filelistpath2->text, filelist2->select->text);
266
267                                if(cmpfilenameext(file1, ".txt") == 0 || cmpfilenameext(file1, ".sh") == 0 || cmpfilenameext(file1, ".cfg") == 0 || cmpfilenameext(file1, ".conf") == 0)
268                                {
269                                        tmpstr = readfiletomem(file1, 0);
270                                        if(tmpstr != NULL)
271                                        {
272                                                textbox(file1, tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 600, 0, 0);
273
274                                                drawscreen(filemanager, 0, 1);
275                                                drawscreen(filemanager1, 0, 1);
276                                                drawscreen(filemanager2, 0, 0);
277                                        }
278                                        free(tmpstr); tmpstr = NULL;
279                                }
280                                else
281                                {
282                                        textbox(_("Message"), _("Can't show this file!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0);
283
284                                        drawscreen(filemanager, 0, 1);
285                                        drawscreen(filemanager1, 0, 1);
286                                        drawscreen(filemanager2, 0, 0);
287                                }
288                                free(file1); file1 = NULL;
289                        }
290
291                        //menu
292                        if(rcret == getrcconfigint("rcmenu", NULL))
293                        {
294                                filemanagermenu(aktfilelist, filelist1, filelistpath1, filelist2, filelistpath2);
295
296                                delmarkedscreennodes(filemanager1, FILELISTDELMARK);
297                                delmarkedscreennodes(filemanager2, FILELISTDELMARK);
298                                createfilelist(filemanager1, filelist1, 0);
299                                createfilelist(filemanager2, filelist2, 0);
300                                       
301                                drawscreen(filemanager, 0, 1);
302                                drawscreen(filemanager1, 0, 1);
303                                drawscreen(filemanager2, 0, 0);
304                        }
305                }
306                else
307                        textbox(_("Message"), _("Registration needed, please contact Atemio !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0);
308               
309                if(rcret == getrcconfigint("rcff", NULL) || rcret == getrcconfigint("rcfr", NULL)) //change filelist
310                {
311                        if(aktfilelist == 0)
312                        {
313                                aktfilelist = 1;
314                                delownerrc(filemanager1);
315                                delownerrc(filemanager2);
316                                addscreenrc(filemanager2, filelist2);
317                                delrc(getrcconfigint("rcff", NULL), filemanager2, filelist2);
318                                delrc(getrcconfigint("rcfr", NULL), filemanager2, filelist2);
319                                filelistpath1->bgcol = 0;
320                                filelistpath2->bgcol = convertcol("markcol");
321                        }
322                        else
323                        {
324                                aktfilelist = 0;
325                                delownerrc(filemanager1);
326                                delownerrc(filemanager2);
327                                addscreenrc(filemanager1, filelist1);
328                                delrc(getrcconfigint("rcff", NULL), filemanager1, filelist1);
329                                delrc(getrcconfigint("rcfr", NULL), filemanager1, filelist1);
330                                filelistpath1->bgcol = convertcol("markcol");
331                                filelistpath2->bgcol = 0;
332                        }
333                        drawscreen(filemanager1, 0, 1);
334                        drawscreen(filemanager2, 0, 0);
335                }
336       
337        }
338       
339        delmarkedscreennodes(filemanager1, FILELISTDELMARK);
340        delmarkedscreennodes(filemanager2, FILELISTDELMARK);
341        filelistpath1->bgcol = bgcol1;
342        filelistpath2->bgcol = bgcol2;
343        delownerrc(filemanager1);
344        delownerrc(filemanager2);
345        clearscreen(filemanager);
346}
347
348#endif
Note: See TracBrowser for help on using the repository browser.