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

Last change on this file since 24454 was 24454, checked in by nit, 10 years ago

[titan] add test rename in filelistmanager before move with progressbar for speed up

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