1 /* wconfig.cc
2  * This file belongs to Worker, a file manager for UN*X/X11.
3  * Copyright (C) 2001-2021 Ralf Hoffmann.
4  * You can contact me at: ralf@boomerangsworld.de
5  *   or http://www.boomerangsworld.de/worker
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #include "wconfig.h"
23 #include "worker.h"
24 #include "filereq.h"
25 #include "fontreq.h"
26 #include <string>
27 #include "pdatei.h"
28 #include "configheader.h"
29 #include "aguix/acontainer.h"
30 #include "aguix/acontainerbb.h"
31 #include "aguix/kartei.h"
32 #include "condparser.h"
33 #include "ownop.h"
34 #include "aguix/slider.h"
35 #include "panel.hh"
36 #include "wconfig_lang.hh"
37 #include "wconfig_palette.hh"
38 #include "wconfig_font.hh"
39 #include "wconfig_start.hh"
40 #include "wconfig_mouse.hh"
41 #include "wconfig_clock.hh"
42 #include "wconfig_lister.hh"
43 #include "wconfig_listview.hh"
44 #include "wconfig_time.hh"
45 #include "wconfig_color.hh"
46 #include "wconfig_hotkey.hh"
47 #include "wconfig_filetype.hh"
48 #include "wconfig_path.hh"
49 #include "wconfig_button.hh"
50 #include "wconfig_dcd.hh"
51 #include "wconfig_pathjump_allow.hh"
52 #include "wconfig_colorconf.hh"
53 #include "wconfig_buttongrpconf.hh"
54 #include "wconfig_cachesize.hh"
55 #include "wconfig_ownerconf.hh"
56 #include "wconfig_termconf.hh"
57 #include "wconfig_dirsizeconf.hh"
58 #include "wconfig_layout.hh"
59 #include "wconfig_imexport.hh"
60 #include "wconfig_mainui.hh"
61 #include "wconfig_expertui.hh"
62 #include "wconfig_bookmarkcolor.hh"
63 #include "wconfig_directory_presets.hh"
64 #include "wc_color.hh"
65 #include "wcdoubleshortkey.hh"
66 #include "wcpath.hh"
67 #include "wcfiletype.hh"
68 #include "wchotkey.hh"
69 #include "wcbutton.hh"
70 #include "workerversion.h"
71 #include "wconfig_generalconf.hh"
72 #include <set>
73 #include <algorithm>
74 #include "magic_db.hh"
75 #include "wconfig_volman.hh"
76 #include "workerinitialsettings.hh"
77 #include "nwc_path.hh"
78 #include "worker_locale.h"
79 #include "aguix/button.h"
80 #include "aguix/bevelbox.h"
81 #include "aguix/solidbutton.h"
82 #include "aguix/fieldlistview.h"
83 #include "aguix/stringgadget.h"
84 #include "aguix/choosebutton.h"
85 #include "aguix/cyclebutton.h"
86 #include "simplelist.hh"
87 #include "datei.h"
88 #include "flattypelist.hh"
89 #include "fileentry.hh"
90 #include "aguix/utf8.hh"
91 #include "stringmatcher_flexiblematch.hh"
92 #include "worker_commands.h"
93 #include "flagreplacer.hh"
94 
95 #define DEFAULT_TIME_STRING "%H:%M:%S"
96 #define DEFAULT_DATE_STRING "%d %b %Y"
97 
98 static const char * predefined_dates[] = { "%d %b %Y",
99                                            "%m/%d/%y",
100                                            "%d.%m.%Y" };
101 static const char * predefined_times[] = { "%H:%M:%S",
102                                            "%H:%M" };
103 
104 WConfig *wconfig;
105 WConfig *lconfig;
106 
107 bool WConfig::always_keep_old_key = false;
108 
109 /*
110  * configures the filetypes
111  *
112  * args:
113  *   bool allowRemoveUnique
114  *     when true allow to remove the unique types (dir, notyet,...)
115  *     mainly used for export
116  *
117  * returnvalues:
118  *   bool:  true when okay was choosen
119  *          false otherwise
120  */
changeTypes(bool allowRemoveUnique)121 bool WConfig::changeTypes( bool allowRemoveUnique )
122 {
123   WConfig *twconfig = duplicate();
124   AGUIX *aguix = worker->getAGUIX();
125   std::string s1;
126   WCFiletype *cutft;
127 
128   AWindow *win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 6 ), AWindow::AWINDOW_DIALOG );
129   win->create();
130 
131   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 2 ), true );
132   ac1->setMinSpace( 5 );
133   ac1->setMaxSpace( 5 );
134 
135   FiletypePanel *ftp = new FiletypePanel( *win, *this );
136   ftp->create();
137   ftp->show();
138   ftp->setAllowRemoveUnique( true );
139   int w = ftp->getWidth();
140   int h = ftp->getHeight();
141 
142   ac1->add( ftp, 0, 0, AContainer::CO_MIN );
143   ac1->setMinWidth( w, 0, 0 );
144   ac1->setMinHeight( h, 0, 0 );
145   win->contMaximize( false );
146 
147   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 1 );
148   ac1_2->setMinSpace( 5 );
149   ac1_2->setMaxSpace( -1 );
150   ac1_2->setBorderWidth( 0 );
151   Button *okb = (Button*)ac1_2->add( new Button( aguix,
152                                                  0,
153                                                  0,
154                                                  catalog.getLocale( 11 ),
155                                                  0 ),
156                                      0, 0, AContainer::CO_INCW );
157   Button *cancelb = (Button*)ac1_2->add( new Button( aguix,
158                                                      0,
159                                                      0,
160                                                      catalog.getLocale( 8 ),
161                                                      0 ),
162                                          1, 0, AContainer::CO_INCW );
163   win->setDoTabCycling( true );
164   win->contMaximize( true );
165   win->show();
166 
167   AGMessage *msg;
168   while ( ( msg = aguix->GetMessage( NULL ) ) != NULL ) aguix->ReplyMessage( msg );
169   int ende = 0;
170 
171   cutft = NULL;
172 
173   while ( ende == 0 ) {
174     msg = aguix->WaitMessage( win );
175     if ( msg != NULL ) {
176       if ( msg->type == AG_CLOSEWINDOW ) {
177         if ( msg->closewindow.window == win->getWindow() ) ende = -1;
178       } else if ( msg->type == AG_BUTTONCLICKED ) {
179         if ( msg->button.button == okb ) ende = 1;
180         else if ( msg->button.button == cancelb ) ende = -1;
181       }
182       aguix->ReplyMessage( msg );
183     }
184   }
185   ftp->saveValues();
186   if ( ende == -1 ) {
187     // Wiederherstellen
188     setFiletypes( twconfig->getFiletypes() );
189     setDontCheckDirs( twconfig->getDontCheckDirs() );
190     setDontCheckVirtual( twconfig->getDontCheckVirtual() );
191   }
192   delete win;
193   delete twconfig;
194   if ( cutft != NULL ) delete cutft;
195   return ( ende == -1 ) ? false : true;
196 }
197 
changeHotkeys()198 bool WConfig::changeHotkeys()
199 {
200   WConfig *twconfig=duplicate();
201   AGUIX *aguix=worker->getAGUIX();
202 
203   AWindow *win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 91 ), AWindow::AWINDOW_DIALOG );
204   win->create();
205 
206   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 2 ), true );
207   ac1->setMinSpace( 5 );
208   ac1->setMaxSpace( 5 );
209 
210   HotkeyPanel *hp = new HotkeyPanel( *win, *this );
211   hp->create();
212   hp->show();
213   int w = hp->getWidth();
214   int h = hp->getHeight();
215 
216   ac1->add( hp, 0, 0, AContainer::CO_MIN );
217   ac1->setMinWidth( w, 0, 0 );
218   ac1->setMinHeight( h, 0, 0 );
219   win->contMaximize( false );
220 
221   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 1 );
222   ac1_2->setMinSpace( 5 );
223   ac1_2->setMaxSpace( -1 );
224   ac1_2->setBorderWidth( 0 );
225   Button *okb = (Button*)ac1_2->add( new Button( aguix,
226                                                  0,
227                                                  0,
228                                                  catalog.getLocale( 11 ),
229                                                  0 ),
230                                      0, 0, AContainer::CO_INCW );
231   Button *cancelb = (Button*)ac1_2->add( new Button( aguix,
232                                                      0,
233                                                      0,
234                                                      catalog.getLocale( 8 ),
235                                                      0 ),
236                                          1, 0, AContainer::CO_INCW );
237   win->setDoTabCycling( true );
238   win->contMaximize( true );
239   win->show();
240 
241   AGMessage *msg;
242   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
243   int ende=0;
244   while(ende==0) {
245     msg=aguix->WaitMessage(win);
246     if(msg!=NULL) {
247       if(msg->type==AG_CLOSEWINDOW) {
248         if(msg->closewindow.window==win->getWindow()) ende=-1;
249       } else if(msg->type==AG_BUTTONCLICKED) {
250         if(msg->button.button==okb) ende=1;
251         else if(msg->button.button==cancelb) ende=-1;
252       }
253       aguix->ReplyMessage(msg);
254     }
255   }
256   hp->saveValues();
257   if(ende==-1) {
258     // Wiederherstellen
259     setHotkeys(twconfig->getHotkeys());
260     // also restore buttons and paths (for the case the user entered a shortkey from one of this
261     setButtons(twconfig->getButtons());
262     setPaths(twconfig->getPaths());
263   }
264   delete win;
265   delete twconfig;
266   return (ende==-1)?false:true;
267 }
268 
changeButtons()269 bool WConfig::changeButtons()
270 {
271   WConfig *twconfig=duplicate();
272   AGUIX *aguix=worker->getAGUIX();
273 
274   AWindow *win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 4 ), AWindow::AWINDOW_DIALOG );
275   win->create();
276 
277   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 2 ), true );
278   ac1->setMinSpace( 5 );
279   ac1->setMaxSpace( 5 );
280 
281   ButtonPanel *bp = new ButtonPanel( *win, *this );
282   bp->create();
283   bp->show();
284   int w = bp->getWidth();
285   int h = bp->getHeight();
286 
287   ac1->add( bp, 0, 0, AContainer::CO_MIN );
288   ac1->setMinWidth( w, 0, 0 );
289   ac1->setMinHeight( h, 0, 0 );
290   win->contMaximize( false );
291 
292   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 1 );
293   ac1_2->setMinSpace( 5 );
294   ac1_2->setMaxSpace( -1 );
295   ac1_2->setBorderWidth( 0 );
296   Button *okb = (Button*)ac1_2->add( new Button( aguix,
297                                                  0,
298                                                  0,
299                                                  catalog.getLocale( 11 ),
300                                                  0 ),
301                                      0, 0, AContainer::CO_INCW );
302   Button *cancelb = (Button*)ac1_2->add( new Button( aguix,
303                                                      0,
304                                                      0,
305                                                      catalog.getLocale( 8 ),
306                                                      0 ),
307                                          1, 0, AContainer::CO_INCW );
308   win->setDoTabCycling( true );
309   win->contMaximize( true );
310   win->show();
311   AGMessage *msg;
312   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
313   int ende=0;
314   while(ende==0) {
315     msg=aguix->WaitMessage(win);
316     if(msg!=NULL) {
317       if(msg->type==AG_CLOSEWINDOW) {
318         if(msg->closewindow.window==win->getWindow()) ende=-1;
319       } else if(msg->type==AG_BUTTONCLICKED) {
320         if(msg->button.button==okb) ende=1;
321         else if(msg->button.button==cancelb) ende=-1;
322       }
323       aguix->ReplyMessage(msg);
324     }
325   }
326   bp->saveValues();
327   if(ende==-1) {
328     // Wiederherstellen
329     setButtons(twconfig->getButtons());
330     // also restore paths and hotkeys (for the case the user entered a shortkey from one of this
331     setPaths(twconfig->getPaths());
332     setHotkeys(twconfig->getHotkeys());
333   } else cleanUpButtons();
334   delete win;
335   delete twconfig;
336   return (ende==-1)?false:true;
337 }
338 
palette()339 int WConfig::palette()
340 {
341   return palette(-1);
342 }
343 
palette(int startcol)344 int WConfig::palette(int startcol)
345 {
346   AGUIX *aguix=worker->getAGUIX();
347   int w,h;
348   w=5+256+10+5;
349   h=5+256+10+5+aguix->getCharHeight()+4+5;
350   AWindow *win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 45 ), AWindow::AWINDOW_DIALOG );
351   win->create();
352   int sx = (int)sqrt( (double)( colors->size() ) );
353   if((sx*sx)<colors->size()) sx++;
354   int th=256/sx;
355   for(int i=0;i<colors->size();i++) {
356     win->add(new Button(aguix,
357                         10+(i%sx)*th,
358                         10+(i/sx)*th,
359                         th,
360                         th,
361                         "",
362                         0,
363                         i,
364                         i+1));
365   }
366   ((BevelBox*)win->add(new BevelBox(aguix,
367                                     5,
368                                     5,
369                                     256+10,
370                                     256+10,
371                                     1)))->toBack();
372   int t1 = aguix->getTextWidth( catalog.getLocale( 11 ) ) + 10;
373   int t2 = aguix->getTextWidth( catalog.getLocale( 8 ) ) + 10;
374   Button *okb=(Button*)win->add(new Button(aguix,
375                                            5,
376                                            256+20,
377                                            t1,
378                                            catalog.getLocale(11),
379                                            0));
380   Button *cancelb=(Button*)win->add(new Button(aguix,
381                                                w-5-t2,
382                                                256+20,
383                                                t2,
384                                                catalog.getLocale(8),
385                                                0));
386   SolidButton *editcolsb=(SolidButton*)win->add(new SolidButton(aguix,
387                                                 5+t1+5,
388                                                 256+20,
389                                                 w-5-5-10-t1-t2,
390                                                 "",
391                                                 0,
392                                                 (startcol>=0)?startcol:0,
393                                                 false));
394   win->setDoTabCycling( true );
395   win->resize(w,h);
396   win->setMaxSize(w,h);
397   win->setMinSize(w,h);
398   win->show();
399   AGMessage *msg;
400   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
401   int ende=0,selcol=(startcol>=0)?startcol:-1;
402   while(ende==0) {
403     msg=aguix->WaitMessage(win);
404     if(msg!=NULL) {
405       if(msg->type==AG_CLOSEWINDOW) {
406         if(msg->closewindow.window==win->getWindow()) ende=-1;
407       } else if(msg->type==AG_BUTTONCLICKED) {
408         if(msg->button.button==okb) ende=1;
409         else if(msg->button.button==cancelb) ende=-1;
410         else if(msg->button.button->getData()>0) {
411           // ein Eintrag wurde ausgewaehlt
412           selcol=msg->button.button->getData()-1;
413           editcolsb->setBG(selcol);
414         }
415       } else if ( msg->type == AG_KEYPRESSED ) {
416           if ( win->isParent( msg->key.window, false ) == true ) {
417               switch ( msg->key.key ) {
418                   case XK_Escape:
419                       ende = -1;
420                       break;
421               }
422           }
423       }
424       aguix->ReplyMessage(msg);
425     }
426   }
427   delete win;
428   return (ende==-1)?-1:selcol;
429 }
430 
applyColorList(List * cols)431 void WConfig::applyColorList(List *cols)
432 {
433     AGUIX *aguix = worker->getAGUIX();
434 
435     aguix->freeColors();
436 
437     int id = cols->initEnum();
438     WC_Color *tc1 = (WC_Color*)cols->getFirstElement();
439     while ( tc1 != NULL ) {
440         if ( aguix->AddColor( tc1->getRed(), tc1->getGreen(), tc1->getBlue() ).getColor() < 0 ) {
441             fprintf( stderr, "Worker: Can't allocate color %d,%d,%d!\n", tc1->getRed(), tc1->getGreen(), tc1->getBlue() );
442         }
443         tc1 = (WC_Color*)cols->getNextElement();
444     }
445     cols->closeEnum( id );
446 }
447 
setLang(const char * nlang)448 void WConfig::setLang( const char *nlang )
449 {
450   if(lang!=NULL) _freesafe(lang);
451   if(nlang==NULL) lang=dupstring("builtin");
452   else lang=dupstring(nlang);
453 }
454 
setTerminalBin(const char * ntb)455 void WConfig::setTerminalBin(const char *ntb)
456 {
457   if(isCorrectTerminalBin(ntb)==true) {
458     if(terminalbin!=NULL) _freesafe(terminalbin);
459     if(ntb==NULL) terminalbin=dupstring(TERMINAL_BIN);
460     else terminalbin=dupstring(ntb);
461   }
462 }
463 
setRows(unsigned int nrows)464 void WConfig::setRows(unsigned int nrows)
465 {
466   if((nrows<1)||(nrows>10)) return;
467   rows=nrows;
468   cleanUpPaths();
469   cleanUpButtons();
470 }
471 
setColumns(unsigned int ncols)472 void WConfig::setColumns(unsigned int ncols)
473 {
474   if((ncols<1)||(ncols>20)) return;
475   columns=ncols;
476   cleanUpPaths();
477   cleanUpButtons();
478 }
479 
setCacheSize(unsigned int ncs)480 void WConfig::setCacheSize(unsigned int ncs)
481 {
482   if(ncs<1) return;
483   cachesize=ncs;
484 }
485 
setHBarTop(int index2,bool val)486 void WConfig::setHBarTop(int index2,bool val)
487 {
488   if((index2<0)||(index2>1)) return;
489   hbar_top[index2]=val;
490 }
491 
setVBarLeft(int index2,bool val)492 void WConfig::setVBarLeft(int index2,bool val)
493 {
494   if((index2<0)||(index2>1)) return;
495   vbar_left[index2]=val;
496 }
497 
setHBarHeight(int index2,unsigned int nh)498 void WConfig::setHBarHeight(int index2,unsigned int nh)
499 {
500   if((index2<0)||(index2>1)) return;
501   if(nh<5) return;
502   hbar_height[index2]=nh;
503 }
504 
setVBarWidth(int index2,unsigned int nw)505 void WConfig::setVBarWidth(int index2,unsigned int nw)
506 {
507   if((index2<0)||(index2>1)) return;
508   if(nw<5) return;
509   vbar_width[index2]=nw;
510 }
511 
setVisCols(int side,const std::vector<WorkerTypes::listcol_t> * nv)512 void WConfig::setVisCols( int side, const std::vector<WorkerTypes::listcol_t> *nv )
513 {
514   if ( ( side < 0 ) || ( side > 1 ) ) return;
515   if ( nv == NULL ) return;
516 
517   viscols[side] = *nv;
518 }
519 
getLang()520 char *WConfig::getLang()
521 {
522   return lang;
523 }
524 
getTerminalBin()525 char *WConfig::getTerminalBin()
526 {
527   return terminalbin;
528 }
529 
getRows()530 unsigned int WConfig::getRows()
531 {
532   return rows;
533 }
534 
getColumns()535 unsigned int WConfig::getColumns()
536 {
537   return columns;
538 }
539 
getCacheSize()540 unsigned int WConfig::getCacheSize()
541 {
542   return cachesize;
543 }
544 
getHBarTop(int index2)545 bool WConfig::getHBarTop(int index2)
546 {
547   if((index2<0)||(index2>1)) return false;
548   return hbar_top[index2];
549 }
550 
getVBarLeft(int index2)551 bool WConfig::getVBarLeft(int index2)
552 {
553   if((index2<0)||(index2>1)) return false;
554   return vbar_left[index2];
555 }
556 
getHBarHeight(int index2)557 unsigned int WConfig::getHBarHeight(int index2)
558 {
559   if((index2<0)||(index2>1)) return 10;
560   return hbar_height[index2];
561 }
562 
getVBarWidth(int index2)563 unsigned int WConfig::getVBarWidth(int index2)
564 {
565   if((index2<0)||(index2>1)) return 10;
566   return vbar_width[index2];
567 }
568 
getVisCols(int side) const569 const std::vector<WorkerTypes::listcol_t> *WConfig::getVisCols( int side ) const
570 {
571   return &( viscols[ ( side == 1 ) ? 1 : 0 ] );
572 }
573 
clearVisCols(int side)574 void WConfig::clearVisCols( int side )
575 {
576   if ( ( side < 0 ) || ( side > 1 ) ) return;
577 
578   viscols[side].clear();
579 }
580 
addListCol(int side,WorkerTypes::listcol_t nv)581 void WConfig::addListCol( int side, WorkerTypes::listcol_t nv )
582 {
583   unsigned int ui;
584   bool found = false;
585 
586   if ( ( side < 0 ) || ( side > 1 ) ) return;
587 
588   for ( ui = 0; ui < viscols[side].size(); ui++ ) {
589     if ( viscols[side][ui] == nv ) {
590       found = true;
591       break;
592     }
593   }
594   if ( found == false ) {
595     viscols[side].push_back( nv );
596   }
597 }
598 
setStartDir(int index2,const char * ndir)599 void WConfig::setStartDir(int index2,const char *ndir)
600 {
601   if((index2<0)||(index2>1)) return;
602   if(dir[index2]!=NULL) _freesafe(dir[index2]);
603   if(ndir==NULL) dir[index2]=dupstring("");
604   else dir[index2]=dupstring(ndir);
605 }
606 
getStartDir(int index2)607 char *WConfig::getStartDir(int index2)
608 {
609   if((index2<0)||(index2>1)) return NULL;
610   return dir[index2];
611 }
612 
setFont(int index2,const char * nfont)613 void WConfig::setFont(int index2,const char *nfont)
614 {
615   if ( index2 < 0 || index2 > 5 ) return;
616 
617   std::string font;
618 
619   if ( nfont != NULL ) font = nfont;
620 
621   // now set the corresponding entry in font_names
622   font_type_t f_id = FONT_X11_GLOBAL;
623   switch ( index2 ) {
624       case 1:
625 #ifdef HAVE_XFT
626           f_id = FONT_XFT_BUTTONS;
627 #else
628           f_id = FONT_X11_BUTTONS;
629 #endif
630           break;
631       case 2:
632 #ifdef HAVE_XFT
633           f_id = FONT_XFT_LEFT;
634 #else
635           f_id = FONT_X11_LEFT;
636 #endif
637           break;
638       case 3:
639 #ifdef HAVE_XFT
640           f_id = FONT_XFT_RIGHT;
641 #else
642           f_id = FONT_X11_RIGHT;
643 #endif
644           break;
645       case 4:
646 #ifdef HAVE_XFT
647           f_id = FONT_XFT_TEXTVIEW;
648 #else
649           f_id = FONT_X11_TEXTVIEW;
650 #endif
651           break;
652       case 5:
653 #ifdef HAVE_XFT
654           f_id = FONT_XFT_STATEBAR;
655 #else
656           f_id = FONT_X11_STATEBAR;
657 #endif
658           break;
659       default:
660 #ifdef HAVE_XFT
661           f_id = FONT_XFT_GLOBAL;
662 #else
663           f_id = FONT_X11_GLOBAL;
664 #endif
665           break;
666   }
667   setFontName( f_id, font );
668 }
669 
getFont(int index2)670 std::string WConfig::getFont( int index2 )
671 {
672     if ( index2 < 0 || index2 > 5 ) return NULL;
673 
674     font_type_t f_id = FONT_X11_GLOBAL;
675     switch ( index2 ) {
676         case 1:
677 #ifdef HAVE_XFT
678             f_id = FONT_XFT_BUTTONS;
679 #else
680             f_id = FONT_X11_BUTTONS;
681 #endif
682             break;
683         case 2:
684 #ifdef HAVE_XFT
685             f_id = FONT_XFT_LEFT;
686 #else
687             f_id = FONT_X11_LEFT;
688 #endif
689             break;
690         case 3:
691 #ifdef HAVE_XFT
692             f_id = FONT_XFT_RIGHT;
693 #else
694             f_id = FONT_X11_RIGHT;
695 #endif
696             break;
697         case 4:
698 #ifdef HAVE_XFT
699             f_id = FONT_XFT_TEXTVIEW;
700 #else
701             f_id = FONT_X11_TEXTVIEW;
702 #endif
703             break;
704         case 5:
705 #ifdef HAVE_XFT
706             f_id = FONT_XFT_STATEBAR;
707 #else
708             f_id = FONT_X11_STATEBAR;
709 #endif
710             break;
711         default:
712 #ifdef HAVE_XFT
713             f_id = FONT_XFT_GLOBAL;
714 #else
715             f_id = FONT_X11_GLOBAL;
716 #endif
717             break;
718     }
719     return getFontName( f_id );
720 }
721 
setPaths(List * npaths)722 void WConfig::setPaths(List *npaths)
723 {
724   WCPath *tp;
725   int id=paths->initEnum();
726   tp=(WCPath*)paths->getFirstElement(id);
727   while(tp!=NULL) {
728     delete tp;
729     tp=(WCPath*)paths->getNextElement(id);
730   }
731   paths->closeEnum(id);
732   paths->removeAllElements();
733   id=npaths->initEnum();
734   tp=(WCPath*)npaths->getFirstElement(id);
735   while(tp!=NULL) {
736     paths->addElement(tp->duplicate());
737     tp=(WCPath*)npaths->getNextElement(id);
738   }
739   npaths->closeEnum(id);
740   cleanUpPaths();
741 }
742 
getPaths()743 List *WConfig::getPaths()
744 {
745   return paths;
746 }
747 
setFiletypes(List * nfts)748 void WConfig::setFiletypes(List *nfts)
749 {
750   WCFiletype *tft;
751   int id=filetypes->initEnum();
752   tft=(WCFiletype*)filetypes->getFirstElement(id);
753   while(tft!=NULL) {
754     delete tft;
755     tft=(WCFiletype*)filetypes->getNextElement(id);
756   }
757   filetypes->closeEnum(id);
758   filetypes->removeAllElements();
759   id=nfts->initEnum();
760   tft=(WCFiletype*)nfts->getFirstElement(id);
761   while(tft!=NULL) {
762     filetypes->addElement(tft->duplicate());
763     tft=(WCFiletype*)nfts->getNextElement(id);
764   }
765   nfts->closeEnum(id);
766 
767   /* clear special type pointers for fast lookup
768    * I could do initFixTypes
769    * but this is not so good for importing because
770    * there would be always the fixtypes
771    * this method should just take the list and not more
772    * all this initFixType-stuff is for worker and not needed
773    * in configuration
774    * but (TODO) it's better code when this pointers are always
775    * correct */
776   notyettype = NULL;
777   unknowntype = NULL;
778   dirtype = NULL;
779   voidtype = NULL;
780 }
781 
getFiletypes()782 List *WConfig::getFiletypes()
783 {
784   return filetypes;
785 }
786 
setHotkeys(List * nhks)787 void WConfig::setHotkeys(List *nhks)
788 {
789   WCHotkey *thk;
790   int id=hotkeys->initEnum();
791   thk=(WCHotkey*)hotkeys->getFirstElement(id);
792   while(thk!=NULL) {
793     delete thk;
794     thk=(WCHotkey*)hotkeys->getNextElement(id);
795   }
796   hotkeys->closeEnum(id);
797   hotkeys->removeAllElements();
798   id=nhks->initEnum();
799   thk=(WCHotkey*)nhks->getFirstElement(id);
800   while(thk!=NULL) {
801     hotkeys->addElement(thk->duplicate());
802     thk=(WCHotkey*)nhks->getNextElement(id);
803   }
804   nhks->closeEnum(id);
805 }
806 
getHotkeys()807 List *WConfig::getHotkeys()
808 {
809   return hotkeys;
810 }
811 
setButtons(List * nbs)812 void WConfig::setButtons(List *nbs)
813 {
814   WCButton *tb;
815   int id=buttons->initEnum();
816   tb=(WCButton*)buttons->getFirstElement(id);
817   while(tb!=NULL) {
818     delete tb;
819     tb=(WCButton*)buttons->getNextElement(id);
820   }
821   buttons->closeEnum(id);
822   buttons->removeAllElements();
823   id=nbs->initEnum();
824   tb=(WCButton*)nbs->getFirstElement(id);
825   while(tb!=NULL) {
826     buttons->addElement(tb->duplicate());
827     tb=(WCButton*)nbs->getNextElement(id);
828   }
829   nbs->closeEnum(id);
830   cleanUpButtons();
831 }
832 
getButtons()833 List *WConfig::getButtons()
834 {
835   return buttons;
836 }
837 
cleanUpPaths()838 void WConfig::cleanUpPaths()
839 {
840   int id=paths->initEnum();
841   WCPath *tp=(WCPath*)paths->getLastElement(id);
842   while(tp!=NULL) {
843     // Alle leeren am Ende entfernen
844     if(tp->getCheck()==false) {
845       delete tp;
846       paths->removeLastElement();
847     } else break;
848     tp=(WCPath*)paths->getLastElement(id);
849   }
850   // Und nun noch auf Bankgroesse auffuellen
851   paths->closeEnum(id);
852   while((((paths->size())%rows)!=0)||(paths->size()==0)) {
853     paths->addElement(new WCPath());
854   }
855 }
856 
cleanUpButtons()857 void WConfig::cleanUpButtons()
858 {
859   int banksize=rows*columns*2;
860   int id=buttons->initEnum();
861   WCButton *tb=(WCButton*)buttons->getLastElement(id);
862   while(tb!=NULL) {
863     // Alle leeren am Ende entfernen
864     if(tb->getCheck()==false) {
865       delete tb;
866       buttons->removeLastElement();
867     } else break;
868     tb=(WCButton*)buttons->getLastElement(id);
869   }
870   // Und nun noch auf Bankgroesse auffuellen
871   buttons->closeEnum(id);
872   while((((buttons->size())%banksize)!=0)||(buttons->size()==0)) {
873     buttons->addElement(new WCButton());
874   }
875 }
876 
WConfig(Worker * tworker)877 WConfig::WConfig(Worker *tworker)
878 {
879   unsigned int i;
880   this->worker=tworker;
881   lang=dupstring("");
882   terminalbin=dupstring(TERMINAL_BIN);
883   rows=1;
884   columns=1;
885   cachesize=10;
886   colors=new List();
887   colors->addElement(new WC_Color(160,160,160));
888   colors->addElement(new WC_Color(0,0,0));
889   colors->addElement(new WC_Color(255,255,255));
890   colors->addElement(new WC_Color(0,85,187));
891   colors->addElement(new WC_Color(204,34,0));
892   colors->addElement(new WC_Color(50,180,20));
893   colors->addElement(new WC_Color(119,0,119));
894   colors->addElement(new WC_Color(238,170,68));
895   hbar_top[0]=false;
896   hbar_top[1]=false;
897   vbar_left[0]=false;
898   vbar_left[1]=true;
899   hbar_height[0]=10;
900   hbar_height[1]=10;
901   vbar_width[0]=10;
902   vbar_width[1]=10;
903   for ( i = 0; i < 2; i++ ) {
904     viscols[i].push_back( WorkerTypes::LISTCOL_PERM );
905     viscols[i].push_back( WorkerTypes::LISTCOL_SIZE );
906     viscols[i].push_back( WorkerTypes::LISTCOL_NAME );
907     viscols[i].push_back( WorkerTypes::LISTCOL_TYPE );
908   }
909   showHeader[0] = true;
910   showHeader[1] = true;
911   dir[0]=dupstring("");
912   dir[1]=dupstring("");
913 
914   m_path_entry_on_top[0] = false;
915   m_path_entry_on_top[1] = false;
916 
917   setFontName( FONT_X11_GLOBAL, "fixed" );
918   setFontName( FONT_X11_BUTTONS, "fixed" );
919   setFontName( FONT_X11_LEFT, "fixed" );
920   setFontName( FONT_X11_RIGHT, "fixed" );
921   setFontName( FONT_X11_TEXTVIEW, "fixed" );
922   setFontName( FONT_X11_STATEBAR, "fixed" );
923   setFontName( FONT_XFT_GLOBAL, "Sans-10" );
924   setFontName( FONT_XFT_BUTTONS, "Sans-10" );
925   setFontName( FONT_XFT_LEFT, "Sans-10" );
926   setFontName( FONT_XFT_RIGHT, "Sans-10" );
927   setFontName( FONT_XFT_TEXTVIEW, "Sans-10" );
928   setFontName( FONT_XFT_STATEBAR, "Sans-10" );
929 
930   paths=new List();
931   for(i=0;i<rows;i++) {
932     paths->addElement(new WCPath());
933   }
934   filetypes=new List();
935   hotkeys=new List();
936   buttons=new List();
937   for(i=0;i<(rows*columns);i++) {
938     buttons->addElement(new WCButton());
939     buttons->addElement(new WCButton());
940   }
941   notyettype=NULL;
942   dirtype=NULL;
943   voidtype = NULL;
944   unknowntype = NULL;
945   initFixTypes();
946   ownerstringtype=0;
947 
948   clockbar_mode=CLOCKBAR_MODE_TIMERAM;
949   clockbar_updatetime=1;
950   clockbar_command=dupstring("");
951   m_clockbar_hints = true;
952 
953   dontcheckdirs=new List();
954   dontcheckvirtual = true;
955 
956   showStringForDirSize=false;
957   stringForDirSize=dupstring("<DIR>");
958   stringForDirSizeLen=strlen(stringForDirSize);
959 
960   setDateFormat( 0 );
961   date_formatstring = dupstring( "" );
962   setDateFormatString( NULL );
963   setDateSubst( true );
964 
965   setTimeFormat( 0 );
966   time_formatstring = dupstring( "" );
967   setTimeFormatString( NULL );
968 
969   setDateBeforeTime( false );
970 
971   m_layout_conf.setButtonVert( false );
972   m_layout_conf.setListViewVert( false );
973   m_layout_conf.setListViewWeight( 5 );
974   m_layout_conf.setWeightRelToActive( false );
975 
976   mouseConf.select_button = 1;
977   mouseConf.activate_button = 2;
978   mouseConf.scroll_button = 3;
979   mouseConf.context_button = 3;
980   mouseConf.activate_mod = 0;
981   mouseConf.scroll_mod = ShiftMask;
982   mouseConf.context_mod = 0;
983   mouseConf.select_method = MOUSECONF_NORMAL_MODE;
984 
985   setDefaultConfig();
986 
987   configureButtonSize[0] = -1;
988   configureButtonSize[1] = -1;
989   changeTypesSize[0] = -1;
990   changeTypesSize[1] = -1;
991   changeHotkeysSize[0] = -1;
992   changeHotkeysSize[1] = -1;
993   configureFiletypeSize[0] = -1;
994   configureFiletypeSize[1] = -1;
995   configureHotkeySize[0] = -1;
996   configureHotkeySize[1] = -1;
997   lastRequestCommand = NULL;
998 
999   currentConfigTime = 0;
1000 
1001   always_keep_old_key = false;
1002 
1003   m_save_worker_state_on_exit = true;
1004 
1005   m_vm_settings.request_action = true;
1006   m_vm_settings.preferred_udisks_version = 1;
1007 
1008   m_use_string_compare_mode = StringComparator::STRING_COMPARE_VERSION;
1009 
1010   m_apply_window_dialog_type = true;
1011 
1012   m_use_extended_regex = false;
1013 
1014   m_pathjump_store_files_always = false;
1015 
1016   m_loaded_major_version = 0;
1017   m_loaded_minor_version = 0;
1018   m_loaded_patch_version = 0;
1019 
1020   m_restore_tabs_mode = RESTORE_TABS_NEVER;
1021   m_store_tabs_mode = STORE_TABS_NEVER;
1022 
1023   m_terminal_returns_early = false;
1024 }
1025 
~WConfig()1026 WConfig::~WConfig()
1027 {
1028   if(lang!=NULL) _freesafe(lang);
1029   if(terminalbin!=NULL) _freesafe(terminalbin);
1030   int id=colors->initEnum();
1031   WC_Color *tcol=(WC_Color*)colors->getFirstElement(id);
1032   while(tcol!=NULL) {
1033     delete tcol;
1034     tcol=(WC_Color*)colors->getNextElement(id);
1035   }
1036   colors->closeEnum(id);
1037   delete colors;
1038   if(dir[0]!=NULL) _freesafe(dir[0]);
1039   if(dir[1]!=NULL) _freesafe(dir[1]);
1040   id=paths->initEnum();
1041   WCPath *tp=(WCPath*)paths->getFirstElement(id);
1042   while(tp!=NULL) {
1043     delete tp;
1044     tp=(WCPath*)paths->getNextElement(id);
1045   }
1046   paths->closeEnum(id);
1047   delete paths;
1048   id=filetypes->initEnum();
1049   WCFiletype *tft=(WCFiletype*)filetypes->getFirstElement(id);
1050   while(tft!=NULL) {
1051     delete tft;
1052     tft=(WCFiletype*)filetypes->getNextElement(id);
1053   }
1054   filetypes->closeEnum(id);
1055   delete filetypes;
1056   id=hotkeys->initEnum();
1057   WCHotkey *thk=(WCHotkey*)hotkeys->getFirstElement(id);
1058   while(thk!=NULL) {
1059     delete thk;
1060     thk=(WCHotkey*)hotkeys->getNextElement(id);
1061   }
1062   hotkeys->closeEnum(id);
1063   delete hotkeys;
1064   id=buttons->initEnum();
1065   WCButton *tb=(WCButton*)buttons->getFirstElement(id);
1066   while(tb!=NULL) {
1067     delete tb;
1068     tb=(WCButton*)buttons->getNextElement(id);
1069   }
1070   buttons->closeEnum(id);
1071   delete buttons;
1072 
1073   _freesafe(clockbar_command);
1074   id=dontcheckdirs->initEnum();
1075   char *tstr=(char*)dontcheckdirs->getFirstElement(id);
1076   while(tstr!=NULL) {
1077     _freesafe(tstr);
1078     tstr=(char*)dontcheckdirs->getNextElement(id);
1079   }
1080   dontcheckdirs->closeEnum(id);
1081   delete dontcheckdirs;
1082   _freesafe(stringForDirSize);
1083 
1084   _freesafe( date_formatstring );
1085   _freesafe( time_formatstring );
1086   if ( lastRequestCommand != NULL ) _freesafe( lastRequestCommand );
1087 }
1088 
duplicate()1089 WConfig *WConfig::duplicate()
1090 {
1091   WConfig *twc=new WConfig(worker);
1092   twc->setLang(lang);
1093   twc->setTerminalBin(terminalbin);
1094   twc->setRows(rows);
1095   twc->setColumns(columns);
1096   twc->setCacheSize(cachesize);
1097   twc->setHBarTop(0,hbar_top[0]);
1098   twc->setHBarTop(1,hbar_top[1]);
1099   twc->setVBarLeft(0,vbar_left[0]);
1100   twc->setVBarLeft(1,vbar_left[1]);
1101   twc->setHBarHeight(0,hbar_height[0]);
1102   twc->setHBarHeight(1,hbar_height[1]);
1103   twc->setVBarWidth(0,vbar_width[0]);
1104   twc->setVBarWidth(1,vbar_width[1]);
1105   twc->setVisCols( 0, &viscols[0] );
1106   twc->setVisCols( 1, &viscols[1] );
1107   twc->setStartDir(0,dir[0]);
1108   twc->setStartDir(1,dir[1]);
1109   twc->setFontNames( m_font_names );
1110   twc->setPaths(paths);
1111   twc->setFiletypes(filetypes);
1112   twc->setHotkeys(hotkeys);
1113   twc->setButtons(buttons);
1114   twc->setColors(colors);
1115   twc->setOwnerstringtype(ownerstringtype);
1116   twc->setClockbarMode(clockbar_mode);
1117   twc->setClockbarUpdatetime(clockbar_updatetime);
1118   twc->setClockbarCommand(clockbar_command);
1119   twc->setClockbarHints( m_clockbar_hints );
1120   twc->setDontCheckDirs(dontcheckdirs);
1121   twc->setDontCheckVirtual( dontcheckvirtual );
1122   twc->setShowStringForDirSize(showStringForDirSize);
1123   twc->setStringForDirSize(stringForDirSize);
1124 
1125   twc->setDateFormat( date_format );
1126   twc->setDateFormatString( date_formatstring );
1127   twc->setDateSubst( date_subst );
1128   twc->setTimeFormat( time_format );
1129   twc->setTimeFormatString( time_formatstring );
1130   twc->setDateBeforeTime( date_before_time );
1131 
1132   twc->setShowHeader( 0, showHeader[0] );
1133   twc->setShowHeader( 1, showHeader[1] );
1134 
1135   twc->setPathEntryOnTop( 0, getPathEntryOnTop( 0 ) );
1136   twc->setPathEntryOnTop( 1, getPathEntryOnTop( 1 ) );
1137 
1138   twc->setLayoutOrders( getLayoutOrders() );
1139   twc->setLayoutButtonVert( getLayoutButtonVert() );
1140   twc->setLayoutListviewVert( getLayoutListviewVert() );
1141   twc->setLayoutListViewWeight( getLayoutListViewWeight() );
1142   twc->setLayoutWeightRelToActive( getLayoutWeightRelToActive() );
1143 
1144   twc->setMouseSelectButton( getMouseSelectButton() );
1145   twc->setMouseActivateButton( getMouseActivateButton() );
1146   twc->setMouseScrollButton( getMouseScrollButton() );
1147   twc->setMouseContextButton( getMouseContextButton() );
1148   twc->setMouseActivateMod( getMouseActivateMod() );
1149   twc->setMouseScrollMod( getMouseScrollMod() );
1150   twc->setMouseContextMod( getMouseContextMod() );
1151   twc->setMouseSelectMethod( getMouseSelectMethod() );
1152 
1153   twc->setColorDefs( getColorDefs() );
1154 
1155   twc->setSaveWorkerStateOnExit( getSaveWorkerStateOnExit() );
1156 
1157   twc->setVMMountCommand( getVMMountCommand() );
1158   twc->setVMUnmountCommand( getVMUnmountCommand() );
1159   twc->setVMFStabFile( getVMFStabFile() );
1160   twc->setVMMtabFile( getVMMtabFile() );
1161   twc->setVMPartitionFile( getVMPartitionFile() );
1162   twc->setVMRequestAction( getVMRequestAction() );
1163   twc->setVMEjectCommand( getVMEjectCommand() );
1164   twc->setVMCloseTrayCommand( getVMCloseTrayCommand() );
1165   twc->setVMPreferredUdisksVersion( getVMPreferredUdisksVersion() );
1166 
1167   twc->setUseStringCompareMode( getUseStringCompareMode() );
1168   twc->setApplyWindowDialogType( getApplyWindowDialogType() );
1169   twc->setUseExtendedRegEx( getUseExtendedRegEx() );
1170 
1171   twc->setPathJumpAllowDirs( m_pathjump_allow_dirs );
1172   twc->setPathJumpStoreFilesAlways( getPathJumpStoreFilesAlways() );
1173 
1174   twc->setFaceDB( getFaceDB() );
1175 
1176   twc->setRestoreTabsMode( getRestoreTabsMode() );
1177   twc->setStoreTabsMode( getStoreTabsMode() );
1178 
1179   twc->setTerminalReturnsEarly( getTerminalReturnsEarly() );
1180 
1181   twc->setDirectoryPresets( getDirectoryPresets() );
1182 
1183   twc->setInitialCommand( m_initial_command );
1184 
1185   twc->setDisableBGCheckPrefix( getDisableBGCheckPrefix() );
1186 
1187   return twc;
1188 }
1189 
setColors(List * ncolors)1190 void WConfig::setColors(List *ncolors)
1191 {
1192   WC_Color *tc;
1193   int id=colors->initEnum();
1194   tc=(WC_Color*)colors->getFirstElement(id);
1195   while(tc!=NULL) {
1196     delete tc;
1197     tc=(WC_Color*)colors->getNextElement(id);
1198   }
1199   colors->closeEnum(id);
1200   colors->removeAllElements();
1201   id=ncolors->initEnum();
1202   tc=(WC_Color*)ncolors->getFirstElement(id);
1203   while(tc!=NULL) {
1204     colors->addElement(tc->duplicate());
1205     tc=(WC_Color*)ncolors->getNextElement(id);
1206   }
1207   ncolors->closeEnum(id);
1208 }
1209 
getColors()1210 List *WConfig::getColors()
1211 {
1212   return colors;
1213 }
1214 
resetColors()1215 void WConfig::resetColors()
1216 {
1217   WC_Color *tc;
1218   int id = colors->initEnum();
1219 
1220   tc = (WC_Color*)colors->getFirstElement( id );
1221   while ( tc != NULL ) {
1222     delete tc;
1223     tc = (WC_Color*)colors->getNextElement( id );
1224   }
1225   colors->closeEnum( id );
1226   colors->removeAllElements();
1227   colors->addElement( new WC_Color( 160, 160, 160 ) );
1228   colors->addElement( new WC_Color( 0, 0, 0 ) );
1229   colors->addElement( new WC_Color( 255, 255, 255 ) );
1230   colors->addElement( new WC_Color( 0, 85, 187 ) );
1231   colors->addElement( new WC_Color( 204, 34, 0 ) );
1232   colors->addElement( new WC_Color( 50, 180, 20 ) );
1233   colors->addElement( new WC_Color( 119, 0, 119 ) );
1234   colors->addElement( new WC_Color( 238, 170, 68 ) );
1235 }
1236 
setColor(int nr,int red,int green,int blue)1237 void WConfig::setColor( int nr, int red, int green, int blue )
1238 {
1239   WC_Color *tc;
1240 
1241   if ( ( nr < 0 ) || ( nr > 255 ) ) return;
1242   while ( colors->size() < ( nr + 1 ) ) colors->addElement( new WC_Color() );
1243   tc = (WC_Color*)colors->getElementAt( nr );
1244   if ( tc != NULL ) {
1245     tc->setRed( red );
1246     tc->setGreen( green );
1247     tc->setBlue( blue );
1248   }
1249 }
1250 
configurePathIndex(int index)1251 bool WConfig::configurePathIndex( int index )
1252 {
1253   if ( index < 0 ||
1254        index >= paths->size() ) return false;
1255   return configurePath( (WCPath*)paths->getElementAt( index ) );
1256 }
1257 
configurePath(WCPath * p1)1258 bool WConfig::configurePath(WCPath *p1)
1259 {
1260   WCPath *p1_bak = p1->duplicate();
1261   WCPath *p1_bak2 = p1->duplicate();
1262   AGUIX *aguix=worker->getAGUIX();
1263   int tw,w,h,ty,tx;
1264   int t1,t2;
1265   WCDoubleShortkey *dk;
1266   List *dkeys;
1267   int id, row, erg;
1268   AWindow *win;
1269   char *tstr;
1270   Requester *req = new Requester( aguix );
1271   std::string str1;
1272   bool acceptkey;
1273 
1274   w=10;
1275   h=10;
1276   win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 82 ), AWindow::AWINDOW_DIALOG );
1277   win->create();
1278   ty=5;
1279   Text *tt1=(Text*)win->add(new Text(aguix,5,ty,catalog.getLocale(83)));
1280   StringGadget *sg1=(StringGadget*)win->add(new StringGadget(aguix,5+tt1->getWidth()+5,
1281                                                              ty,100,p1->getName(),0));
1282   w=sg1->getX()+sg1->getWidth()+5;
1283   ty+=sg1->getHeight()+5;
1284 
1285   t1 = aguix->getTextWidth( "Test" ) + 10;
1286   SolidButton *sb1=(SolidButton*)win->add(new SolidButton(aguix,5,ty,t1,"Test",
1287                                                           p1->getFG(),p1->getBG(),false));
1288   tx=sb1->getX()+sb1->getWidth()+5;
1289   t1 = aguix->getTextWidth( catalog.getLocale( 32 ) ) + 10;
1290   Button *b1=(Button*)win->add(new Button(aguix,tx,ty,t1,catalog.getLocale(32),0));
1291   tx+=b1->getWidth()+5;
1292   t1 = aguix->getTextWidth( catalog.getLocale( 33 ) ) + 10;
1293   Button *b2=(Button*)win->add(new Button(aguix,tx,ty,t1,catalog.getLocale(33),0));
1294   tw=tx+b2->getWidth()+5;
1295   if(tw>w) w=tw;
1296   ty+=b2->getHeight()+5;
1297   t1 = aguix->getTextWidth( catalog.getLocale( 61 ) ) + 10;
1298   t2 = aguix->getTextWidth( catalog.getLocale( 62 ) ) + 10;
1299   tw=(t1>t2)?t1:t2;
1300 
1301   tt1 = (Text*)win->add( new Text( aguix, 5, ty, catalog.getLocale( 449 ) ) );
1302   ty += tt1->getHeight() + 5;
1303   FieldListView *sklv = (FieldListView*)win->add( new FieldListView( aguix,
1304                                                                      5,
1305                                                                      ty,
1306                                                                      100,
1307                                                                      6 * aguix->getCharHeight(),
1308                                                                      0 ) );
1309   sklv->setNrOfFields( 3 );
1310   sklv->setFieldWidth( 1, 1 );
1311   sklv->setHBarState( 2 );
1312   sklv->setVBarState( 2 );
1313 
1314   dkeys = p1_bak2->getDoubleKeys();
1315   id = dkeys->initEnum();
1316   dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
1317   while ( dk != NULL ) {
1318     row = sklv->addRow();
1319     sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1320     tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
1321     if ( tstr != NULL ) {
1322       sklv->setText( row, 0, tstr );
1323       _freesafe( tstr );
1324     } else {
1325       sklv->setText( row, 0, "???" );
1326     }
1327     if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
1328       tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
1329       if ( tstr != NULL ) {
1330         sklv->setText( row, 2, tstr );
1331         _freesafe( tstr );
1332       } else {
1333         sklv->setText( row, 2, "???" );
1334       }
1335     }
1336     dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
1337   }
1338   dkeys->closeEnum( id );
1339   sklv->redraw();
1340 
1341   tw = sklv->getWidth() + 10;
1342   if ( tw > w ) w = tw;
1343   ty += sklv->getHeight();
1344 
1345   GUIElement *skbs[2];
1346   skbs[0] = (Button*)win->add( new Button( aguix, 5, ty, catalog.getLocale( 450 ), 0 ) );
1347   skbs[1] = (Button*)win->add( new Button( aguix, 5, ty, catalog.getLocale( 451 ), 0 ) );
1348 
1349   ty += skbs[0]->getHeight() + 5;
1350 
1351   tt1=(Text*)win->add(new Text(aguix,5,ty,catalog.getLocale(84)));
1352   StringGadget *sg2=(StringGadget*)win->add(new StringGadget(aguix,5+tt1->getWidth()+5,ty,100,
1353                                                              p1->getPath(),0));
1354   tw=sg2->getX()+sg2->getWidth()+5;
1355   if(tw>w) w=tw;
1356   ty+=sg2->getHeight()+5;
1357 
1358   t1 = aguix->getTextWidth( catalog.getLocale( 11 ) ) + 10;
1359   t2 = aguix->getTextWidth( catalog.getLocale( 8 ) ) + 10;
1360   tw=5+t1+5+t2+5;
1361   if(tw>w) w=tw;
1362   Button *okb=(Button*)win->add(new Button(aguix,
1363                                              5,
1364                                              ty,
1365                                              t1,
1366                                              catalog.getLocale(11),
1367                                              0));
1368   Button *cancelb=(Button*)win->add(new Button(aguix,
1369                                                  w-5-t2,
1370                                                  ty,
1371                                                  t2,
1372                                                  catalog.getLocale(8),
1373                                                  0));
1374   h=okb->getY()+okb->getHeight()+5;
1375 
1376   t1 = AGUIX::scaleElementsW( w, 5, 0, 0, false, true, skbs, NULL, 2 );
1377   if ( t1 > w ) {
1378     w = t1;
1379   }
1380   sklv->resize( w - 2 * 5, sklv->getHeight() );
1381   cancelb->move( w - 5 - cancelb->getWidth(), cancelb->getY() );
1382 
1383   win->setDoTabCycling( true );
1384   win->resize(w,h);
1385   win->setMaxSize(w,h);
1386   win->setMinSize(w,h);
1387   sg1->resize(w-5-sg1->getX(),sg1->getHeight());
1388   sg2->resize(w-5-sg2->getX(),sg2->getHeight());
1389   win->show();
1390   AGMessage *msg;
1391   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
1392   int ende=0;
1393 
1394   p1->setDoubleKeys( NULL );  // clear list to avoid conflicts
1395 
1396   while(ende==0) {
1397     msg=aguix->WaitMessage(win);
1398     if(msg!=NULL) {
1399       if(msg->type==AG_CLOSEWINDOW) {
1400         if(msg->closewindow.window==win->getWindow()) ende=-1;
1401       } else if(msg->type==AG_BUTTONCLICKED) {
1402         if(msg->button.button==okb) ende=1;
1403         else if(msg->button.button==cancelb) ende=-1;
1404         else if(msg->button.button==b1) {
1405           int col=palette(sb1->getFG());
1406           if(col>=0) sb1->setFG(col);
1407         } else if(msg->button.button==b2) {
1408           int col=palette(sb1->getBG());
1409           if(col>=0) sb1->setBG(col);
1410         } else if ( msg->button.button == skbs[0] ) {
1411           // add shortkey
1412           // 1.Ask for normal or double shortkey
1413           str1 = catalog.getLocale( 453 );
1414           str1 += "|";
1415           str1 += catalog.getLocale( 454 );
1416           erg = req->request( catalog.getLocale( 123 ),
1417                               catalog.getLocale( 452 ),
1418                               str1.c_str() );
1419           if ( erg == 1 ) {
1420             // double
1421             getDoubleShortkey( true, NULL, NULL, p1, &dk );
1422           } else {
1423             // normal
1424             getDoubleShortkey( false, NULL, NULL, p1, &dk );
1425           }
1426           if ( dk != NULL ) {
1427             // if getDoubleShortkey returns a key then
1428             // it's not used or the user want it to be used here
1429             // so add it and after okay remove all other conflicts
1430             acceptkey = false;
1431             if ( p1_bak2->conflictKey( dk ) == true ) {
1432               // conflicts with current list
1433               // inform the user but do not use it
1434               req->request( catalog.getLocale( 347 ),
1435                             catalog.getLocale( 457 ),
1436                             catalog.getLocale( 11 ) );
1437             } else {
1438               // doesn't conflict with current list
1439               acceptkey = true;
1440             }
1441             if ( acceptkey == true ) {
1442               dkeys->addElement( dk );
1443               row = sklv->addRow();
1444               sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1445               tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
1446               if ( tstr != NULL ) {
1447                 sklv->setText( row, 0, tstr );
1448                 _freesafe( tstr );
1449               } else {
1450                 sklv->setText( row, 0, "???" );
1451               }
1452               if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
1453                 tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
1454                 if ( tstr != NULL ) {
1455                   sklv->setText( row, 2, tstr );
1456                   _freesafe( tstr );
1457                 } else {
1458                   sklv->setText( row, 2, "???" );
1459                 }
1460               }
1461             } else {
1462               delete dk;
1463             }
1464             sklv->redraw();
1465           }
1466         } else if ( msg->button.button == skbs[1] ) {
1467           // delete shortkey
1468           row = sklv->getActiveRow();
1469           if ( sklv->isValidRow( row ) == true ) {
1470             dkeys->removeElementAt( row );
1471             sklv->deleteRow( row );
1472             sklv->redraw();
1473           }
1474         }
1475       } else if ( msg->type == AG_KEYPRESSED ) {
1476           if ( win->isParent( msg->key.window, false ) == true ) {
1477               switch ( msg->key.key ) {
1478                   case XK_Escape:
1479                       ende = -1;
1480                       break;
1481               }
1482           }
1483       }
1484       aguix->ReplyMessage(msg);
1485     }
1486   }
1487   if(ende==1) {
1488     // Ubernehmen
1489     p1->setName(sg1->getText());
1490     p1->setPath(sg2->getText());
1491 
1492     WCButton *twcb;
1493     WCHotkey *twch;
1494     WCPath *twcp;
1495 
1496     // search for existing shortkey and remove it
1497     id = dkeys->initEnum();
1498     dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
1499     while ( dk != NULL ) {
1500       if ( findDoubleShortkey( dk, getButtons(), getPaths(), getHotkeys(), &twcb, &twcp, &twch ) != 0 ) {
1501         if ( twcb != NULL ) {
1502           twcb->removeKey( dk );
1503         } else if ( ( twcp != NULL ) && ( twcp != p1 ) ) {
1504           twcp->removeKey( dk );
1505         } else if ( twch != NULL ) {
1506           twch->removeKey( dk );
1507         }
1508       }
1509       dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
1510     }
1511     dkeys->closeEnum( id );
1512     p1->setCheck(true);
1513     p1->setFG(sb1->getFG());
1514     p1->setBG(sb1->getBG());
1515     p1->setDoubleKeys( dkeys );
1516   } else {
1517     p1->setDoubleKeys( p1_bak->getDoubleKeys() );
1518   }
1519   delete p1_bak;
1520   delete p1_bak2;
1521   delete win;
1522   delete req;
1523   return (ende==-1)?false:true;
1524 }
1525 
configureHotkeyIndex(int index)1526 bool WConfig::configureHotkeyIndex( int index )
1527 {
1528   if ( index < 0 ||
1529        index >= hotkeys->size() ) return false;
1530   return configureHotkey( (WCHotkey*)hotkeys->getElementAt( index ) );
1531 }
1532 
configureHotkey(WCHotkey * h1)1533 bool WConfig::configureHotkey(WCHotkey *h1)
1534 {
1535   WCHotkey *h1_bak=h1->duplicate();
1536   WCHotkey *h1_bak2=h1->duplicate();
1537   AGUIX *aguix=worker->getAGUIX();
1538   WCDoubleShortkey *dk;
1539   List *dkeys;
1540   int id, row, erg;
1541   AWindow *win;
1542   char *tstr;
1543   Requester *req = new Requester( aguix );
1544   std::string str1;
1545   bool acceptkey;
1546   int lastrow;
1547   struct timeval tv1, tv2;
1548   int w, h;
1549 
1550   win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 91 ), AWindow::AWINDOW_NORMAL );
1551   win->create();
1552 
1553   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 6 ), true );
1554   ac1->setMinSpace( 5 );
1555   ac1->setMaxSpace( 5 );
1556 
1557   AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 0 );
1558   ac1_1->setMinSpace( 5 );
1559   ac1_1->setMaxSpace( 5 );
1560   ac1_1->setBorderWidth( 0 );
1561 
1562   ac1_1->add( new Text( aguix, 0, 0, catalog.getLocale( 92 ) ), 0, 0, AContainer::CO_FIX );
1563   StringGadget *sg1 = (StringGadget*)ac1_1->add( new StringGadget( aguix, 0, 0, 100, h1->getName(), 0 ), 1, 0, AContainer::CO_INCW );
1564 
1565   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 449 ) ), 0, 1, AContainer::CO_INCWNR );
1566 
1567   AContainer *ac1_2 = ac1->add( new AContainer( win, 1, 2 ), 0, 2 );
1568   ac1_2->setMinSpace( 0 );
1569   ac1_2->setMaxSpace( 0 );
1570   ac1_2->setBorderWidth( 0 );
1571 
1572   FieldListView *sklv = (FieldListView*)ac1_2->add( new FieldListView( aguix,
1573 								       0,
1574 								       0,
1575 								       100,
1576 								       6 * aguix->getCharHeight(),
1577 								       0 ), 0, 0, AContainer::CO_MIN );
1578   sklv->setNrOfFields( 3 );
1579   sklv->setFieldWidth( 1, 1 );
1580   sklv->setHBarState( 2 );
1581   sklv->setVBarState( 2 );
1582 
1583   dkeys = h1_bak2->getDoubleKeys();
1584   id = dkeys->initEnum();
1585   dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
1586   while ( dk != NULL ) {
1587     row = sklv->addRow();
1588     sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1589     tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
1590     if ( tstr != NULL ) {
1591       sklv->setText( row, 0, tstr );
1592       _freesafe( tstr );
1593     } else {
1594       sklv->setText( row, 0, "???" );
1595     }
1596     if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
1597       tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
1598       if ( tstr != NULL ) {
1599         sklv->setText( row, 2, tstr );
1600         _freesafe( tstr );
1601       } else {
1602         sklv->setText( row, 2, "???" );
1603       }
1604     }
1605     dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
1606   }
1607   dkeys->closeEnum( id );
1608   sklv->redraw();
1609 
1610   AContainer *ac1_2_1 = ac1_2->add( new AContainer( win, 2, 1 ), 0, 1 );
1611   ac1_2_1->setMinSpace( 0 );
1612   ac1_2_1->setMaxSpace( 0 );
1613   ac1_2_1->setBorderWidth( 0 );
1614 
1615   GUIElement *skbs[2];
1616   skbs[0] = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 450 ), 0 ), 0, 0, AContainer::CO_INCW );
1617   skbs[1] = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 451 ), 0 ), 1, 0, AContainer::CO_INCW );
1618 
1619   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 245 ) ), 0, 3, AContainer::CO_INCWNR );
1620 
1621   AContainer *ac1_3 = ac1->add( new AContainer( win, 2, 1 ), 0, 4 );
1622   ac1_3->setMinSpace( 0 );
1623   ac1_3->setMaxSpace( 0 );
1624   ac1_3->setBorderWidth( 0 );
1625 
1626   AContainer *ac1_3_1 = ac1_3->add( new AContainer( win, 1, 5 ), 0, 0 );
1627   ac1_3_1->setMinSpace( 0 );
1628   ac1_3_1->setMaxSpace( 0 );
1629   ac1_3_1->setBorderWidth( 0 );
1630 
1631   Button *b2 = (Button*)ac1_3_1->add( new Button( aguix, 0, 0, catalog.getLocale( 246 ), 0 ), 0, 0, AContainer::CO_INCH );
1632   Button *b3 = (Button*)ac1_3_1->add( new Button( aguix, 0, 0, catalog.getLocale( 247 ), 0 ), 0, 1, AContainer::CO_INCH );
1633   Button *b4 = (Button*)ac1_3_1->add( new Button( aguix, 0, 0, catalog.getLocale( 248 ), "button-special1-fg", "button-special1-bg", 0 ), 0, 2, AContainer::CO_INCH );
1634   Button *b5 = (Button*)ac1_3_1->add( new Button( aguix, 0, 0, catalog.getLocale( 236 ), 0 ), 0, 3, AContainer::CO_INCH );
1635   Button *b6 = (Button*)ac1_3_1->add( new Button( aguix, 0, 0, catalog.getLocale( 237 ), 0 ), 0, 4, AContainer::CO_INCH );
1636 
1637   FieldListView *lv = (FieldListView*)ac1_3->add( new FieldListView( aguix,
1638 								     0,
1639 								     0,
1640 								     20 * aguix->getTextWidth( "M" ),
1641 								     100,
1642 								     0 ), 1, 0, AContainer::CO_MIN );
1643   lv->setHBarState(2);
1644   lv->setVBarState(2);
1645   lv->setAcceptFocus( true );
1646   lv->setDisplayFocus( true );
1647   command_list_t coms=h1->getComs();
1648   for ( auto &fpr : coms ) {
1649       row = lv->addRow();
1650       lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1651       lv->setText( row, 0, fpr->getDescription() );
1652   }
1653   lv->redraw();
1654 
1655   AContainer *ac1_4 = ac1->add( new AContainer( win, 2, 1 ), 0, 5 );
1656   ac1_4->setMinSpace( 5 );
1657   ac1_4->setMaxSpace( -1 );
1658   ac1_4->setBorderWidth( 0 );
1659   Button *okb =(Button*)ac1_4->add( new Button( aguix,
1660                                                 0,
1661                                                 0,
1662                                                 catalog.getLocale( 11 ),
1663                                                 0 ), 0, 0, AContainer::CO_FIX );
1664   Button *cancelb = (Button*)ac1_4->add( new Button( aguix,
1665 						     0,
1666 						     0,
1667 						     catalog.getLocale( 8 ),
1668 						     0 ), 1, 0, AContainer::CO_FIX );
1669 
1670 
1671   win->setDoTabCycling( true );
1672   win->contMaximize( true );
1673 
1674   w = win->getWidth();
1675   h = win->getHeight();
1676   if ( ( configureHotkeySize[0] >= w ) && ( configureHotkeySize[1] >= h ) ) {
1677     win->resize( configureHotkeySize[0], configureHotkeySize[1] );
1678   }
1679 
1680   win->show();
1681   AGMessage *msg;
1682   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
1683   int ende=0;
1684 
1685   h1->setDoubleKeys( NULL );  // clear list to avoid conflicts
1686 
1687   lastrow = -1;
1688   timerclear( &tv1 );
1689   while(ende==0) {
1690     msg=aguix->WaitMessage(win);
1691     if(msg!=NULL) {
1692       if(msg->type==AG_CLOSEWINDOW) {
1693         if(msg->closewindow.window==win->getWindow()) ende=-1;
1694       } else if(msg->type==AG_BUTTONCLICKED) {
1695         if(msg->button.button==okb) ende=1;
1696         else if(msg->button.button==cancelb) ende=-1;
1697         else if(msg->button.button==b2) {
1698             bool dontConfigure = false;
1699             auto fpr=requestCommand( dontConfigure );
1700             if ( fpr ) {
1701                 coms.push_back( fpr );
1702                 if ( ! dontConfigure ) fpr->configureWhenAvail();
1703                 row = lv->addRow();
1704                 lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1705                 lv->setText( row, 0, fpr->getDescription() );
1706                 lv->setActiveRow( row );
1707                 lv->showActive();
1708                 lv->redraw();
1709             }
1710         } else if(msg->button.button==b3) {
1711           row = lv->getActiveRow();
1712           if ( lv->isValidRow( row ) == true ) {
1713               auto it = coms.begin();
1714               std::advance( it, row );
1715               coms.erase( it );
1716               lv->deleteRow( row );
1717               if ( lv->isValidRow( row ) == true )
1718                   lv->setActiveRow( row );
1719               else
1720                   lv->setActiveRow( row - 1 );
1721               lv->showActive();
1722               lv->redraw();
1723           }
1724         } else if(msg->button.button==b4) {
1725           row = lv->getActiveRow();
1726           if ( lv->isValidRow( row ) == true ) {
1727               auto fpr = coms.at( row );
1728               fpr->configure();
1729               lv->setText( row, 0, fpr->getDescription() );
1730               lv->redraw();
1731           }
1732         } else if(msg->button.button==b5) {
1733           row = lv->getActiveRow();
1734           if ( lv->isValidRow( row ) == true ) {
1735             if ( row > 0 ) {
1736                 auto fpr = coms.at( row );
1737                 coms.at( row ) = coms.at( row - 1 );
1738                 coms.at( row - 1 ) = fpr;
1739                 lv->swapRows( row, row - 1 );
1740                 lv->showActive();
1741                 lv->redraw();
1742             }
1743           }
1744         } else if(msg->button.button==b6) {
1745           row = lv->getActiveRow();
1746           if ( lv->isValidRow( row ) == true ) {
1747             if ( row < ( lv->getElements() - 1 ) ) {
1748                 auto fpr = coms.at( row );
1749                 coms.at( row ) = coms.at( row + 1 );
1750                 coms.at( row + 1 ) = fpr;
1751                 lv->swapRows( row, row + 1 );
1752                 lv->showActive();
1753                 lv->redraw();
1754             }
1755           }
1756         } else if ( msg->button.button == skbs[0] ) {
1757           // add shortkey
1758           // 1.Ask for normal or double shortkey
1759           str1 = catalog.getLocale( 453 );
1760           str1 += "|";
1761           str1 += catalog.getLocale( 454 );
1762           erg = req->request( catalog.getLocale( 123 ),
1763                               catalog.getLocale( 452 ),
1764                               str1.c_str() );
1765           if ( erg == 1 ) {
1766             // double
1767             getDoubleShortkey( true, NULL, h1, NULL, &dk );
1768           } else {
1769             // normal
1770             getDoubleShortkey( false, NULL, h1, NULL, &dk );
1771           }
1772           if ( dk != NULL ) {
1773             // if getDoubleShortkey returns a key then
1774             // it's not used or the user want it to be used here
1775             // so add it and after okay remove all other conflicts
1776             acceptkey = false;
1777             if ( h1_bak2->conflictKey( dk ) == true ) {
1778               // conflicts with current list
1779               // inform the user but do not use it
1780               req->request( catalog.getLocale( 347 ),
1781                             catalog.getLocale( 457 ),
1782                             catalog.getLocale( 11 ) );
1783             } else {
1784               // doesn't conflict with current list
1785               acceptkey = true;
1786             }
1787             if ( acceptkey == true ) {
1788               dkeys->addElement( dk );
1789               row = sklv->addRow();
1790               sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1791               tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
1792               if ( tstr != NULL ) {
1793                 sklv->setText( row, 0, tstr );
1794                 _freesafe( tstr );
1795               } else {
1796                 sklv->setText( row, 0, "???" );
1797               }
1798               if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
1799                 tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
1800                 if ( tstr != NULL ) {
1801                   sklv->setText( row, 2, tstr );
1802                   _freesafe( tstr );
1803                 } else {
1804                   sklv->setText( row, 2, "???" );
1805                 }
1806               }
1807             } else {
1808               delete dk;
1809             }
1810             sklv->redraw();
1811           }
1812         } else if ( msg->button.button == skbs[1] ) {
1813           // delete shortkey
1814           row = sklv->getActiveRow();
1815           if ( sklv->isValidRow( row ) == true ) {
1816             dkeys->removeElementAt( row );
1817             sklv->deleteRow( row );
1818             sklv->redraw();
1819           }
1820         }
1821       } else if ( msg->type == AG_FIELDLV_ONESELECT ) {
1822         if ( ( msg->fieldlv.lv == lv ) && ( msg->fieldlv.mouse == true ) ) {
1823           gettimeofday( &tv2, NULL );
1824           if ( lastrow < 0 ) {
1825             lastrow = msg->fieldlv.row;
1826             tv1 = tv2;
1827           } else {
1828             if  ( ( msg->fieldlv.row == lastrow ) &&
1829                   ( aguix->isDoubleClick( &tv2, &tv1 ) == true ) ) {
1830               if ( lv->isValidRow( lastrow ) == true ) {
1831                   auto fpr = coms.at( lastrow );
1832                   fpr->configure();
1833                   lv->setText( lastrow, 0, fpr->getDescription() );
1834                   lv->redraw();
1835               }
1836               lastrow = -1;
1837             } else {
1838               lastrow = msg->fieldlv.row;
1839               tv1 = tv2;
1840             }
1841           }
1842         }
1843       } else if ( msg->type == AG_FIELDLV_MULTISELECT ) {
1844         lastrow = -1;
1845       } else if ( msg->type == AG_KEYPRESSED ) {
1846           if ( win->isParent( msg->key.window, false ) == true ) {
1847               switch ( msg->key.key ) {
1848                   case XK_Escape:
1849                       ende = -1;
1850                       break;
1851               }
1852           }
1853       }
1854       aguix->ReplyMessage(msg);
1855     }
1856   }
1857   if(ende==1) {
1858     // Ubernehmen
1859     h1->setName(sg1->getText());
1860     h1->setComs( coms );
1861 
1862     WCButton *twcb;
1863     WCHotkey *twch;
1864     WCPath *twcp;
1865 
1866     // search for existing shortkey and remove it
1867     id = dkeys->initEnum();
1868     dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
1869     while ( dk != NULL ) {
1870       if ( findDoubleShortkey( dk, getButtons(), getPaths(), getHotkeys(), &twcb, &twcp, &twch ) != 0 ) {
1871         if ( twcb != NULL ) {
1872           twcb->removeKey( dk );
1873         } else if ( twcp != NULL ) {
1874           twcp->removeKey( dk );
1875         } else if ( ( twch != NULL ) && ( twch != h1 ) ) {
1876           twch->removeKey( dk );
1877         }
1878       }
1879       dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
1880     }
1881     dkeys->closeEnum( id );
1882     h1->setDoubleKeys( dkeys );
1883   } else {
1884     h1->setComs(h1_bak->getComs());
1885     h1->setDoubleKeys( h1_bak->getDoubleKeys() );
1886   }
1887   delete h1_bak;
1888   delete h1_bak2;
1889   configureHotkeySize[0] = win->getWidth();
1890   configureHotkeySize[1] = win->getHeight();
1891   delete win;
1892   delete req;
1893 
1894   return (ende==-1)?false:true;
1895 }
1896 
1897 class requestCommand_str {
1898 public:
1899     std::string str;
1900     int id;
1901     std::string internalName;
1902     std::string category;
1903     bool hidden;
1904     int row;
1905     bool eval_command = false;
1906     std::string description;
1907 
requestCommand_str()1908     requestCommand_str() : id( 0 ),
1909                            hidden( false ),
1910                            row ( - 1 )
1911     {
1912     }
1913 
getVisibleText() const1914     std::string getVisibleText() const
1915     {
1916         if ( ! description.empty() ) {
1917             std::string t = description;
1918 
1919             t += " (";
1920 
1921             if ( eval_command ) {
1922                 t += catalog.getLocale( 988 );
1923                 t += " ";
1924             }
1925 
1926             t += str;
1927             t += ")";
1928 
1929             return t;
1930         } else {
1931             return str;
1932         }
1933     }
1934 
operator <(const requestCommand_str & rhs) const1935     bool operator<( const requestCommand_str &rhs ) const
1936     {
1937         if ( internalName == OwnOp::name &&
1938              rhs.internalName != OwnOp::name ) {
1939             return true;
1940         } else if ( internalName != OwnOp::name &&
1941              rhs.internalName == OwnOp::name ) {
1942             return false;
1943         }
1944 
1945         if ( category < rhs.category ) {
1946             return true;
1947         } else if ( category == rhs.category ) {
1948             return strcasecmp( getVisibleText().c_str(), rhs.getVisibleText().c_str() ) < 0;
1949         }
1950         return false;
1951     }
1952 };
1953 
filter_commands(std::vector<requestCommand_str> & command_list,const std::string & filter)1954 void filter_commands( std::vector< requestCommand_str > &command_list,
1955                       const std::string &filter )
1956 {
1957     StringMatcherFlexibleMatch matcher;
1958 
1959     matcher.setMatchString( filter );
1960 
1961     for ( std::vector< requestCommand_str >::iterator it1 = command_list.begin();
1962           it1 != command_list.end();
1963           ++it1 ) {
1964 
1965         if ( matcher.match( it1->getVisibleText() ) ) {
1966             it1->hidden = false;
1967         } else {
1968             it1->hidden = true;
1969         }
1970     }
1971 }
1972 
prepare_lv(std::vector<requestCommand_str> & command_list,FieldListView & lv)1973 void prepare_lv( std::vector< requestCommand_str > &command_list,
1974                  FieldListView &lv )
1975 {
1976     lv.setSize( 0 );
1977 
1978     for ( std::vector< requestCommand_str >::iterator it1 = command_list.begin();
1979           it1 != command_list.end();
1980           ++it1 ) {
1981         if ( it1->hidden == false ) {
1982             int row = lv.addRow();
1983 
1984             lv.setText( row, 0, it1->category );
1985             lv.setText( row, 1, it1->getVisibleText() );
1986             lv.setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
1987 
1988             it1->row = row;
1989         }
1990     }
1991 
1992     lv.redraw();
1993 }
1994 
requestCommand(bool & dontConfigure)1995 std::shared_ptr< FunctionProto > WConfig::requestCommand( bool &dontConfigure )
1996 {
1997     AGUIX *aguix = worker->getAGUIX();
1998     std::shared_ptr< FunctionProto > fpr = NULL;
1999     AWindow *win;
2000     std::vector< requestCommand_str > tlist;
2001     int trow;
2002 
2003     win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 249 ), AWindow::AWINDOW_DIALOG );
2004     win->create();
2005 
2006     AContainer *ac1 = win->setContainer( new AContainer( win, 1, 3 ), true );
2007     ac1->setMinSpace( 5 );
2008     ac1->setMaxSpace( 5 );
2009 
2010     AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 0 );
2011     ac1_1->setMinSpace( 5 );
2012     ac1_1->setMaxSpace( 5 );
2013     ac1_1->setBorderWidth( 0 );
2014 
2015     ac1_1->add( new Text( aguix, 0, 0, catalog.getLocale( 793 ) ), 0, 0, AContainer::CO_FIX );
2016     StringGadget *filter_sg = (StringGadget*)ac1_1->add( new StringGadget( aguix,
2017                                                                            0,
2018                                                                            0,
2019                                                                            50,
2020                                                                            "",
2021                                                                            1 ), 1, 0, AContainer::CO_INCW );
2022 
2023     FieldListView *lv = (FieldListView*)ac1->add( new FieldListView( aguix, 0,
2024                                                                      0,
2025                                                                      200,
2026                                                                      200,
2027                                                                      0 ),
2028                                                   0, 1, AContainer::CO_MIN );
2029     lv->setHBarState( 2 );
2030     lv->setVBarState( 2 );
2031     lv->setNrOfFields( 2 );
2032     lv->setGlobalFieldSpace( 5 );
2033     lv->setShowHeader( true );
2034     lv->setFieldText( 0, catalog.getLocale( 950 ) );
2035     lv->setFieldText( 1, catalog.getLocale( 951 ) );
2036 
2037     for ( int i = 0; i < worker->getNrOfCommands(); i++ ) {
2038         auto tfpr = worker->getCommand4ID( i );
2039         requestCommand_str ts;
2040         ts.id = i;
2041         ts.category = FunctionProto::getCategoryName( tfpr->getCategory() );
2042         ts.str = tfpr->getDescription();
2043         ts.internalName = tfpr->getName();
2044         tlist.push_back( ts );
2045     }
2046 
2047     {
2048         auto l = worker->getListOfCommandsWithoutArgs();
2049 
2050         for ( auto &cmd : l ) {
2051             requestCommand_str ts;
2052             ts.id = -1;
2053             ts.category = FunctionProto::getCategoryName( cmd.category );
2054             ts.str = cmd.name;
2055             ts.eval_command = true;
2056             ts.internalName = "eval_command";
2057             ts.description = cmd.description;
2058             tlist.push_back( ts );
2059         }
2060     }
2061 
2062     std::sort( tlist.begin(),
2063                tlist.end() );
2064 
2065     filter_commands( tlist, "" );
2066     prepare_lv( tlist, *lv );
2067 
2068     if ( lastRequestCommand != NULL ) {
2069         for ( std::vector< requestCommand_str >::iterator it1 = tlist.begin();
2070               it1 != tlist.end();
2071               ++it1 ) {
2072             if ( it1->hidden == false &&
2073                  it1->str == lastRequestCommand ) {
2074                 lv->setActiveRow( it1->row );
2075                 break;
2076             }
2077         }
2078     }
2079 
2080     lv->maximizeX();
2081     lv->centerActive();
2082 
2083     ac1->readLimits();
2084 
2085     AContainer *ac1_6 = ac1->add( new AContainer( win, 2, 1 ), 0, 2 );
2086     ac1_6->setMinSpace( 5 );
2087     ac1_6->setMaxSpace( -1 );
2088     ac1_6->setBorderWidth( 0 );
2089     Button *okb =(Button*)ac1_6->add( new Button( aguix,
2090                                                   0,
2091                                                   0,
2092                                                   catalog.getLocale( 11 ),
2093                                                   0 ), 0, 0, AContainer::CO_FIX );
2094     Button *cancelb = (Button*)ac1_6->add( new Button( aguix,
2095                                                        0,
2096                                                        0,
2097                                                        catalog.getLocale( 8 ),
2098                                                        0 ), 1, 0, AContainer::CO_FIX );
2099 
2100     win->setDoTabCycling( true );
2101     win->contMaximize( true );
2102 
2103     win->show();
2104 
2105     AGMessage *msg;
2106     while ( ( msg = aguix->GetMessage( NULL ) ) != NULL ) aguix->ReplyMessage( msg );
2107     int ende = 0;
2108 
2109     while ( ende == 0 ) {
2110         msg = aguix->WaitMessage( win );
2111         if ( msg != NULL ) {
2112             if ( msg->type == AG_CLOSEWINDOW ) {
2113                 if ( msg->closewindow.window == win->getWindow() ) ende = -1;
2114             } else if ( msg->type == AG_BUTTONCLICKED ) {
2115                 if ( msg->button.button == okb ) ende = 1;
2116                 else if ( msg->button.button == cancelb ) ende = -1;
2117             } else if (msg->type == AG_STRINGGADGET_CONTENTCHANGE ) {
2118                 if ( msg->stringgadget.sg == filter_sg ) {
2119                     filter_commands( tlist, filter_sg->getText() );
2120                     prepare_lv( tlist, *lv );
2121                 }
2122             } else if ( msg->type == AG_KEYPRESSED ) {
2123                 if ( win->isParent( msg->key.window, false ) == true ) {
2124                     switch ( msg->key.key ) {
2125                         case XK_Escape:
2126                             ende = -1;
2127                             break;
2128                     }
2129                 }
2130             }
2131 
2132             aguix->ReplyMessage( msg );
2133         }
2134     }
2135 
2136     dontConfigure = false;
2137 
2138     if ( ende == 1 ) {
2139         trow = lv->getActiveRow();
2140         if ( lv->isValidRow( trow ) == true ) {
2141             for ( std::vector< requestCommand_str >::iterator it1 = tlist.begin();
2142                   it1 != tlist.end();
2143                   ++it1 ) {
2144                 if ( it1->hidden == false &&
2145                      it1->row == trow ) {
2146                     if ( it1->eval_command ) {
2147                         auto tfpr = std::make_shared< ScriptOp >();
2148 
2149                         tfpr->setType( ScriptOp::SCRIPT_EVALCOMMAND );
2150                         tfpr->setCommandStr( it1->str );
2151 
2152                         fpr = tfpr;
2153 
2154                         dontConfigure = true;
2155                     } else {
2156                         fpr = std::shared_ptr< FunctionProto >( worker->getCommand4ID( it1->id ) );
2157                     }
2158 
2159                     if ( lastRequestCommand != NULL ) _freesafe( lastRequestCommand );
2160                     lastRequestCommand = dupstring( it1->str.c_str() );
2161 
2162                     break;
2163                 }
2164             }
2165         }
2166     }
2167     delete win;
2168 
2169     return fpr;
2170 }
2171 
configureButtonIndex(int index)2172 bool WConfig::configureButtonIndex( int index )
2173 {
2174   if ( index < 0 ||
2175        index >= buttons->size() ) return false;
2176   return configureButton( (WCButton*)buttons->getElementAt( index ) );
2177 }
2178 
configureButton(WCButton * wcb1)2179 bool WConfig::configureButton(WCButton *wcb1)
2180 {
2181   /*
2182    * I will clear the doublekey list for wcb1
2183    * _bak is used to restore keys when canceled
2184    * changes will be done to
2185    */
2186   WCButton *wcb1_bak=wcb1->duplicate();
2187   WCButton *wcb1_bak2=wcb1->duplicate();
2188   AGUIX *aguix=worker->getAGUIX();
2189   int t1;
2190   WCDoubleShortkey *dk;
2191   List *dkeys;
2192   int id, row, erg;
2193   AWindow *win;
2194   char *tstr;
2195   Requester *req = new Requester( aguix );
2196   std::string str1;
2197   bool acceptkey;
2198   int lastrow;
2199   struct timeval tv1, tv2;
2200   int w, h;
2201 
2202   win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 59 ), AWindow::AWINDOW_NORMAL );
2203   win->create();
2204 
2205   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 7 ), true );
2206   ac1->setMinSpace( 5 );
2207   ac1->setMaxSpace( 5 );
2208 
2209   AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 0 );
2210   ac1_1->setMinSpace( 5 );
2211   ac1_1->setMaxSpace( 5 );
2212   ac1_1->setBorderWidth( 0 );
2213 
2214   ac1_1->add( new Text( aguix, 0, 0, catalog.getLocale( 60 ) ), 0, 0, AContainer::CO_FIX );
2215   StringGadget *sg1 = (StringGadget*)ac1_1->add( new StringGadget( aguix,
2216 								   0,
2217 								   0,
2218 								   100,
2219 								   wcb1->getText(),
2220 								   0 ), 1, 0, AContainer::CO_INCW );
2221 
2222   AContainer *ac1_2 = ac1->add( new AContainer( win, 4, 1 ), 0, 1 );
2223   ac1_2->setMinSpace( 5 );
2224   ac1_2->setMaxSpace( 5 );
2225   ac1_2->setBorderWidth( 0 );
2226 
2227   SolidButton *tsb = (SolidButton*)ac1_2->add( new SolidButton( aguix, 0, 0,
2228 								"Test",
2229 								wcb1->getFG(), wcb1->getBG(), false ), 0, 0, AContainer::CO_FIX );
2230   Button *fgb = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 32 ), 0 ), 1, 0, AContainer::CO_FIX );
2231   Button *bgb = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 33 ), 0 ), 2, 0, AContainer::CO_FIX );
2232 
2233   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 449 ) ), 0, 2, AContainer::CO_INCWNR );
2234 
2235   AContainer *ac1_4 = ac1->add( new AContainer( win, 1, 2 ), 0, 3 );
2236   ac1_4->setMinSpace( 0 );
2237   ac1_4->setMaxSpace( 0 );
2238   ac1_4->setBorderWidth( 0 );
2239 
2240   FieldListView *sklv = (FieldListView*)ac1_4->add( new FieldListView( aguix,
2241 								       0,
2242 								       0,
2243 								       100,
2244 								       6 * aguix->getCharHeight(),
2245 								       0 ), 0, 0, AContainer::CO_MIN );
2246   sklv->setNrOfFields( 3 );
2247   sklv->setFieldWidth( 1, 1 );
2248   sklv->setHBarState( 2 );
2249   sklv->setVBarState( 2 );
2250 
2251   // make all key changes to the second copy
2252   dkeys = wcb1_bak2->getDoubleKeys();
2253   id = dkeys->initEnum();
2254   dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
2255   while ( dk != NULL ) {
2256     row = sklv->addRow();
2257     sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
2258     tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
2259     if ( tstr != NULL ) {
2260       sklv->setText( row, 0, tstr );
2261       _freesafe( tstr );
2262     } else {
2263       sklv->setText( row, 0, "???" );
2264     }
2265     if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
2266       tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
2267       if ( tstr != NULL ) {
2268         sklv->setText( row, 2, tstr );
2269         _freesafe( tstr );
2270       } else {
2271         sklv->setText( row, 2, "???" );
2272       }
2273     }
2274     dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
2275   }
2276   dkeys->closeEnum( id );
2277   sklv->redraw();
2278 
2279   AContainer *ac1_4_1 = ac1_4->add( new AContainer( win, 2, 1 ), 0, 1 );
2280   ac1_4_1->setMinSpace( 0 );
2281   ac1_4_1->setMaxSpace( 0 );
2282   ac1_4_1->setBorderWidth( 0 );
2283 
2284   GUIElement *skbs[2];
2285   skbs[0] = (Button*)ac1_4_1->add( new Button( aguix, 0, 0, catalog.getLocale( 450 ), 0 ), 0, 0, AContainer::CO_INCW );
2286   skbs[1] = (Button*)ac1_4_1->add( new Button( aguix, 0, 0, catalog.getLocale( 451 ), 0 ), 1, 0, AContainer::CO_INCW );
2287 
2288   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 245 ) ), 0, 4, AContainer::CO_INCWNR );
2289 
2290   AContainer *ac1_5 = ac1->add( new AContainer( win, 2, 1 ), 0, 5 );
2291   ac1_5->setMinSpace( 0 );
2292   ac1_5->setMaxSpace( 0 );
2293   ac1_5->setBorderWidth( 0 );
2294 
2295   AContainer *ac1_5_1 = ac1_5->add( new AContainer( win, 1, 5 ), 0, 0 );
2296   ac1_5_1->setMinSpace( 0 );
2297   ac1_5_1->setMaxSpace( 0 );
2298   ac1_5_1->setBorderWidth( 0 );
2299 
2300   Button *b2 = (Button*)ac1_5_1->add( new Button( aguix, 0, 0, catalog.getLocale( 246 ), 0 ), 0, 0, AContainer::CO_INCH );
2301   Button *b3 = (Button*)ac1_5_1->add( new Button( aguix, 0, 0, catalog.getLocale( 247 ), 0 ), 0, 1, AContainer::CO_INCH );
2302   Button *b4 = (Button*)ac1_5_1->add( new Button( aguix, 0, 0, catalog.getLocale( 248 ), "button-special1-fg", "button-special1-bg", 0 ), 0, 2, AContainer::CO_INCH );
2303   Button *b5 = (Button*)ac1_5_1->add( new Button( aguix, 0, 0, catalog.getLocale( 236 ), 0 ), 0, 3, AContainer::CO_INCH );
2304   Button *b6 = (Button*)ac1_5_1->add( new Button( aguix, 0, 0, catalog.getLocale( 237 ), 0 ), 0, 4, AContainer::CO_INCH );
2305 
2306   FieldListView *lv = (FieldListView*)ac1_5->add( new FieldListView( aguix,
2307 								     0,
2308 								     0,
2309 								     20 * aguix->getTextWidth( "M" ),
2310 								     100,
2311 								     0 ), 1, 0, AContainer::CO_MIN );
2312   lv->setHBarState(2);
2313   lv->setVBarState(2);
2314   lv->setAcceptFocus( true );
2315   lv->setDisplayFocus( true );
2316   command_list_t coms = wcb1->getComs();
2317   for ( auto &fpr : coms ) {
2318       row = lv->addRow();
2319       lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
2320       lv->setText( row, 0, fpr->getDescription() );
2321   }
2322   lv->redraw();
2323 
2324   AContainer *ac1_6 = ac1->add( new AContainer( win, 2, 1 ), 0, 6 );
2325   ac1_6->setMinSpace( 5 );
2326   ac1_6->setMaxSpace( -1 );
2327   ac1_6->setBorderWidth( 0 );
2328   Button *okb =(Button*)ac1_6->add( new Button( aguix,
2329                                                 0,
2330                                                 0,
2331                                                 catalog.getLocale( 11 ),
2332                                                 0 ), 0, 0, AContainer::CO_FIX );
2333   Button *cancelb = (Button*)ac1_6->add( new Button( aguix,
2334 						     0,
2335 						     0,
2336 						     catalog.getLocale( 8 ),
2337 						     0 ), 1, 0, AContainer::CO_FIX );
2338 
2339   win->setDoTabCycling( true );
2340   win->contMaximize( true );
2341 
2342   w = win->getWidth();
2343   h = win->getHeight();
2344   if ( ( configureButtonSize[0] >= w ) && ( configureButtonSize[1] >= h ) ) {
2345     win->resize( configureButtonSize[0], configureButtonSize[1] );
2346   }
2347 
2348   win->show();
2349   AGMessage *msg;
2350   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
2351   int ende=0;
2352 
2353   wcb1->setDoubleKeys( NULL );  // clear list to avoid conflicts
2354 
2355   lastrow = -1;
2356   timerclear( &tv1 );
2357   while(ende==0) {
2358     msg=aguix->WaitMessage(win);
2359     if(msg!=NULL) {
2360       if(msg->type==AG_CLOSEWINDOW) {
2361         if(msg->closewindow.window==win->getWindow()) ende=-1;
2362       } else if(msg->type==AG_BUTTONCLICKED) {
2363         if(msg->button.button==okb) ende=1;
2364         else if(msg->button.button==cancelb) ende=-1;
2365         else if(msg->button.button==b2) {
2366           bool dontConfigure = false;
2367           auto fpr=requestCommand( dontConfigure );
2368           if ( fpr ) {
2369               coms.push_back( fpr );
2370               if ( ! dontConfigure ) fpr->configureWhenAvail();
2371               row = lv->addRow();
2372               lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
2373               lv->setText( row, 0, fpr->getDescription() );
2374               lv->setActiveRow( row );
2375               lv->showActive();
2376               lv->redraw();
2377           }
2378         } else if(msg->button.button==b3) {
2379           row = lv->getActiveRow();
2380           if( lv->isValidRow( row ) == true ) {
2381               auto it = coms.begin();
2382               std::advance( it, row );
2383               coms.erase( it );
2384               lv->deleteRow( row );
2385               if ( lv->isValidRow( row ) == true )
2386                   lv->setActiveRow( row );
2387               else
2388                   lv->setActiveRow( row - 1 );
2389               lv->showActive();
2390               lv->redraw();
2391           }
2392         } else if(msg->button.button==b4) {
2393           row = lv->getActiveRow();
2394           if( lv->isValidRow( row ) == true ) {
2395               auto fpr = coms.at( row );
2396               fpr->configure();
2397               lv->setText( row, 0, fpr->getDescription() );
2398               lv->redraw();
2399           }
2400         } else if(msg->button.button==b5) {
2401           row = lv->getActiveRow();
2402           if ( lv->isValidRow( row ) == true ) {
2403             if ( row > 0 ) {
2404                 auto fpr = coms.at( row );
2405                 coms.at( row ) = coms.at( row - 1 );
2406                 coms.at( row - 1 ) = fpr;
2407                 lv->swapRows( row, row - 1 );
2408                 lv->showActive();
2409                 lv->redraw();
2410             }
2411           }
2412         } else if(msg->button.button==b6) {
2413           row = lv->getActiveRow();
2414           if ( lv->isValidRow( row ) == true ) {
2415             if ( row < ( lv->getElements() - 1 ) ) {
2416                 auto fpr = coms.at( row );
2417                 coms.at( row ) = coms.at( row + 1 );
2418                 coms.at( row + 1 ) = fpr;
2419                 lv->swapRows( row, row + 1 );
2420                 lv->showActive();
2421                 lv->redraw();
2422             }
2423           }
2424         } else if(msg->button.button==fgb) {
2425           t1=palette(tsb->getFG());
2426           if(t1>=0) {
2427             tsb->setFG(t1);
2428           }
2429         } else if(msg->button.button==bgb) {
2430           t1=palette(tsb->getBG());
2431           if(t1>=0) {
2432             tsb->setBG(t1);
2433           }
2434         } else if ( msg->button.button == skbs[0] ) {
2435           // add shortkey
2436           // 1.Ask for normal or double shortkey
2437           str1 = catalog.getLocale( 453 );
2438           str1 += "|";
2439           str1 += catalog.getLocale( 454 );
2440           erg = req->request( catalog.getLocale( 123 ),
2441                               catalog.getLocale( 452 ),
2442                               str1.c_str() );
2443           if ( erg == 1 ) {
2444             // double
2445             getDoubleShortkey( true, wcb1, NULL, NULL, &dk );
2446           } else {
2447             // normal
2448             getDoubleShortkey( false, wcb1, NULL, NULL, &dk );
2449           }
2450           if ( dk != NULL ) {
2451             // if getDoubleShortkey returns a key then
2452             // it's not used or the user want it to be used here
2453             // so add it and after okay remove all other conflicts
2454             acceptkey = false;
2455             if ( wcb1_bak2->conflictKey( dk ) == true ) {
2456               // conflicts with current list
2457               // inform the user but do not use it
2458               req->request( catalog.getLocale( 347 ),
2459                             catalog.getLocale( 457 ),
2460                             catalog.getLocale( 11 ) );
2461             } else {
2462               // doesn't conflict with current list
2463               acceptkey = true;
2464             }
2465             if ( acceptkey == true ) {
2466               dkeys->addElement( dk );
2467               row = sklv->addRow();
2468               sklv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
2469               tstr = aguix->getNameOfKey( dk->getKeySym( 0 ), dk->getMod( 0 ) );
2470               if ( tstr != NULL ) {
2471                 sklv->setText( row, 0, tstr );
2472                 _freesafe( tstr );
2473               } else {
2474                 sklv->setText( row, 0, "???" );
2475               }
2476               if ( dk->getType() == WCDoubleShortkey::WCDS_DOUBLE ) {
2477                 tstr = aguix->getNameOfKey( dk->getKeySym( 1 ), dk->getMod( 1 ) );
2478                 if ( tstr != NULL ) {
2479                   sklv->setText( row, 2, tstr );
2480                   _freesafe( tstr );
2481                 } else {
2482                   sklv->setText( row, 2, "???" );
2483                 }
2484               }
2485             } else {
2486               delete dk;
2487             }
2488             sklv->redraw();
2489           }
2490         } else if ( msg->button.button == skbs[1] ) {
2491           // delete shortkey
2492           row = sklv->getActiveRow();
2493           if ( sklv->isValidRow( row ) == true ) {
2494             dkeys->removeElementAt( row );
2495             sklv->deleteRow( row );
2496             sklv->redraw();
2497           }
2498         }
2499       } else if ( msg->type == AG_FIELDLV_ONESELECT ) {
2500         if ( ( msg->fieldlv.lv == lv ) && ( msg->fieldlv.mouse == true ) ) {
2501           gettimeofday( &tv2, NULL );
2502           if ( lastrow < 0 ) {
2503             lastrow = msg->fieldlv.row;
2504             tv1 = tv2;
2505           } else {
2506             if  ( ( msg->fieldlv.row == lastrow ) &&
2507                   ( aguix->isDoubleClick( &tv2, &tv1 ) == true ) ) {
2508               if ( lv->isValidRow( lastrow ) == true ) {
2509                   auto fpr = coms.at( lastrow );
2510                   fpr->configure();
2511                   lv->setText( lastrow, 0, fpr->getDescription() );
2512                   lv->redraw();
2513               }
2514               lastrow = -1;
2515             } else {
2516               lastrow = msg->fieldlv.row;
2517               tv1 = tv2;
2518             }
2519           }
2520         }
2521       } else if ( msg->type == AG_FIELDLV_MULTISELECT ) {
2522         lastrow = -1;
2523       } else if ( msg->type == AG_KEYPRESSED ) {
2524           if ( win->isParent( msg->key.window, false ) == true ) {
2525               switch ( msg->key.key ) {
2526                   case XK_Escape:
2527                       ende = -1;
2528                       break;
2529               }
2530           }
2531       }
2532       aguix->ReplyMessage(msg);
2533     }
2534   }
2535   if(ende==1) {
2536     // Ubernehmen
2537     wcb1->setText(sg1->getText());
2538     wcb1->setFG(tsb->getFG());
2539     wcb1->setBG(tsb->getBG());
2540     wcb1->setCheck(true);
2541     wcb1->setComs( coms );
2542 
2543     WCButton *twcb;
2544     WCHotkey *twch;
2545     WCPath *twcp;
2546 
2547     // search for existing shortkey and remove it
2548     id = dkeys->initEnum();
2549     dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
2550     while ( dk != NULL ) {
2551       if ( findDoubleShortkey( dk, getButtons(), getPaths(), getHotkeys(), &twcb, &twcp, &twch ) != 0 ) {
2552         if ( ( twcb != NULL ) && ( twcb != wcb1 ) ) {
2553           twcb->removeKey( dk );
2554         } else if ( twcp != NULL ) {
2555           twcp->removeKey( dk );
2556         } else if ( twch != NULL ) {
2557           twch->removeKey( dk );
2558         }
2559       }
2560       dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
2561     }
2562     dkeys->closeEnum( id );
2563     wcb1->setDoubleKeys( dkeys );
2564   } else {
2565     wcb1->setComs(wcb1_bak->getComs());
2566     wcb1->setDoubleKeys( wcb1_bak->getDoubleKeys() );
2567   }
2568   delete wcb1_bak;
2569   delete wcb1_bak2;
2570   configureButtonSize[0] = win->getWidth();
2571   configureButtonSize[1] = win->getHeight();
2572   delete win;
2573   delete req;
2574 
2575   return (ende==-1)?false:true;
2576 }
2577 
configureFiletype(WCFiletype * ft1,int default_panel)2578 bool WConfig::configureFiletype(WCFiletype *ft1, int default_panel)
2579 {
2580   WCFiletype *ft1_bak=ft1->duplicate();
2581   AGUIX *aguix=worker->getAGUIX();
2582   int w,h;
2583   int t1;
2584   AWindow *win;
2585   int lastrow, row;
2586   struct timeval tv1, tv2;
2587   int trow;
2588   const int cfixnr = AContainer::CO_FIX +
2589                      AContainer::ACONT_NORESIZE;
2590   const int cfixwminh = AContainer::ACONT_MINH +
2591                         AContainer::ACONT_MINW +
2592                         AContainer::ACONT_MAXW;
2593   Text *ftc[4];
2594   Button *ftcb[4][2];
2595   int i;
2596   FileRequester *freq;
2597 
2598   w=10;
2599   h=10;
2600   win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 88 ), AWindow::AWINDOW_NORMAL );
2601   win->create();
2602 
2603   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 7 ), true );
2604   ac1->setMinSpace( 5 );
2605   ac1->setMaxSpace( 5 );
2606 
2607   bool name_supports_flags = true;
2608 
2609   AContainer *ac1_1 = ac1->add( new AContainer( win, name_supports_flags ? 3 : 2, 1 ), 0, 0 );
2610   ac1_1->setMinSpace( 5 );
2611   ac1_1->setMaxSpace( 5 );
2612   ac1_1->setBorderWidth( 0 );
2613 
2614   ac1_1->add( new Text( aguix, 0, 0, catalog.getLocale( 89 ) ), 0, 0, AContainer::CO_FIX );
2615   StringGadget *sg1 = (StringGadget*)ac1_1->add( new StringGadget( aguix, 0,
2616                                                                    0, 100, ft1->getName().c_str(), 0 ), 1, 0, AContainer::CO_INCW );
2617   Button *sg1_flag_b = NULL;
2618 
2619   if ( name_supports_flags ) {
2620       sg1_flag_b = ac1_1->addWidget( new Button( aguix, 0, 0, catalog.getLocale( 897 ), 0 ),
2621                                      2, 0, AContainer::CO_FIX );
2622   }
2623 
2624   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 250 ) ), 0, 1, AContainer::CO_INCWNR );
2625 
2626   AContainer *ac1_7 = ac1->add( new AContainer( win, 1, 2 ), 0, 2 );
2627   ac1_7->setMinSpace( 0 );
2628   ac1_7->setMaxSpace( 0 );
2629   ac1_7->setBorderWidth( 0 );
2630 
2631   FieldListView *lv0 = (FieldListView*)ac1_7->add( new FieldListView( aguix, 0, 0, 100, 80, 0 ), 0, 0, AContainer::CO_MIN );
2632   lv0->setHBarState(2);
2633   lv0->setVBarState(2);
2634   for ( t1 = 0; t1 < 14; t1++ ) {
2635     trow = lv0->addRow();
2636     lv0->setPreColors( trow, FieldListView::PRECOLOR_ONLYACTIVE );
2637     lv0->setText( trow, 0, catalog.getLocale( 251 + t1 ) );
2638   }
2639   lv0->redraw();
2640   lv0->setActiveRow( 1 );
2641 
2642   std::list<std::string> custom_names;
2643   ft1->fillNamesOfCustomActions( false, custom_names );
2644 
2645   for ( std::list<std::string>::iterator it1 = custom_names.begin();
2646         it1 != custom_names.end();
2647         it1++ ) {
2648       trow = lv0->addRow();
2649       lv0->setPreColors( trow, FieldListView::PRECOLOR_ONLYACTIVE );
2650       lv0->setText( trow, 0, *it1 );
2651   }
2652 
2653   AContainer *ac1_7_1 = ac1_7->add( new AContainer( win, 2, 1 ), 0, 1 );
2654   ac1_7_1->setMinSpace( 0 );
2655   ac1_7_1->setMaxSpace( 0 );
2656   ac1_7_1->setBorderWidth( 0 );
2657   Button *new_action_b = (Button*)ac1_7_1->add( new Button( aguix, 0, 0, catalog.getLocale( 777 ), 0 ), 0, 0, AContainer::CO_INCW );
2658   Button *del_action_b = (Button*)ac1_7_1->add( new Button( aguix, 0, 0, catalog.getLocale( 778 ), 0 ), 1, 0, AContainer::CO_INCW );
2659 
2660   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 245 ) ), 0, 3, AContainer::CO_INCWNR );
2661 
2662   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 4 );
2663   ac1_2->setMinSpace( 0 );
2664   ac1_2->setMaxSpace( 0 );
2665   ac1_2->setBorderWidth( 0 );
2666   AContainer *ac1_2_1 = ac1_2->add( new AContainer( win, 1, 5 ), 0, 0 );
2667   ac1_2_1->setMinSpace( 0 );
2668   ac1_2_1->setMaxSpace( 0 );
2669   ac1_2_1->setBorderWidth( 0 );
2670   Button *b2 = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 246 ), 0 ), 0, 0, cfixwminh );
2671   Button *b3 = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 247 ), 0 ), 0, 1, cfixwminh );
2672   Button *b4 = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 248 ), "button-special1-fg", "button-special1-bg", 0 ), 0, 2, cfixwminh );
2673   Button *b5 = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 236 ), 0 ), 0, 3, cfixwminh );
2674   Button *b6 = (Button*)ac1_2_1->add( new Button( aguix, 0, 0, catalog.getLocale( 237 ), 0 ), 0, 4, cfixwminh );
2675   FieldListView *lv = (FieldListView*)ac1_2->add( new FieldListView( aguix,
2676                                                                      0,
2677                                                                      0,
2678                                                                      50,
2679                                                                      20,
2680                                                                      0 ), 1, 0, AContainer::CO_MIN );
2681   lv->setHBarState(2);
2682   lv->setVBarState(2);
2683   lv->setAcceptFocus( true );
2684   lv->setDisplayFocus( true );
2685 
2686   Kartei *k1 = new Kartei( aguix, 10, 10, 10, 10, "" );
2687   ac1->add( k1, 0, 5, AContainer::CO_MIN );
2688   k1->create();
2689 
2690   AWindow *subwin12 = new AWindow( aguix, 0, 0, 10, 10, "" );
2691   k1->add( subwin12 );
2692   subwin12->create();
2693 
2694   AContainer *ac1_3 = subwin12->setContainer( new AContainer( subwin12, 1, 6 ), true );
2695   ac1_3->setMinSpace( 5 );
2696   ac1_3->setMaxSpace( 5 );
2697   ac1_3->setBorderWidth( 5 );
2698   AContainer *ac1_3_1 = ac1_3->add( new AContainer( subwin12, 3, 1 ), 0, 0 );
2699   ac1_3_1->setMinSpace( 5 );
2700   ac1_3_1->setMaxSpace( 5 );
2701   ac1_3_1->setBorderWidth( 0 );
2702   ac1_3_1->add( new Text( aguix, 0, 0, catalog.getLocale( 93 ) ), 0, 0, AContainer::CO_FIX );
2703   StringGadget *sg2=(StringGadget*)ac1_3_1->add( new StringGadget( aguix, 0,
2704                                                                    0,
2705                                                                    100,
2706                                                                    ft1->getPattern(), 0 ), 1, 0, AContainer::CO_INCW );
2707   ChooseButton *cb1 = (ChooseButton*)ac1_3_1->add( new ChooseButton( aguix, 0,
2708                                                                      0, ft1->getUsePattern(),
2709                                                                      catalog.getLocale( 94 ), LABEL_LEFT, 1 ), 2, 0,
2710                                                                      cfixnr );
2711 
2712   ChooseButton *cb11 = (ChooseButton*)ac1_3->add( new ChooseButton( aguix,
2713                                                                     0,
2714                                                                     0,
2715                                                                     ft1->getPatternIgnoreCase(),
2716                                                                     catalog.getLocale( 501 ),
2717                                                                     LABEL_RIGHT,
2718                                                                     1 ), 0, 1, AContainer::CO_INCWNR );
2719 
2720   ChooseButton *cb12 = (ChooseButton*)ac1_3->add( new ChooseButton( aguix,
2721                                                                     0,
2722                                                                     0,
2723                                                                     ft1->getPatternUseRegExp(),
2724                                                                     catalog.getLocale( 502 ),
2725                                                                     LABEL_RIGHT,
2726                                                                     1 ), 0, 2, AContainer::CO_INCWNR );
2727 
2728   ChooseButton *cb13 = (ChooseButton*)ac1_3->add( new ChooseButton( aguix,
2729                                                                     0,
2730                                                                     0,
2731                                                                     ft1->getPatternUseFullname(),
2732                                                                     catalog.getLocale( 570 ),
2733                                                                     LABEL_RIGHT,
2734                                                                     1 ), 0, 3, AContainer::CO_INCWNR );
2735   ChooseButton *comma_sep_cb = ac1_3->addWidget( new ChooseButton( aguix,
2736                                                                    0,
2737                                                                    0,
2738                                                                    ft1->getPatternIsCommaSeparated(),
2739                                                                    catalog.getLocale( 1133 ),
2740                                                                    LABEL_RIGHT,
2741                                                                    1 ), 0, 4, AContainer::CO_INCWNR );
2742   Button *patternhb = (Button*)ac1_3->add( new Button( aguix,
2743                                                        0,
2744 			 		  	       0,
2745 				 		       catalog.getLocale( 483 ),
2746 						       0 ), 0, 5, AContainer::CO_INCWNR );
2747 
2748   AWindow *subwin13 = new AWindow( aguix, 0, 0, 10, 10, "" );
2749   k1->add( subwin13 );
2750   subwin13->create();
2751 
2752   AContainer *acsw13 = subwin13->setContainer( new AContainer( subwin13, 1, 1 ), true );
2753   acsw13->setMinSpace( 5 );
2754   acsw13->setMaxSpace( 5 );
2755   acsw13->setBorderWidth( 5 );
2756 
2757   AContainer *ac1_4 = acsw13->add( new AContainer( subwin13, 2, 1 ), 0, 0 );
2758   ac1_4->setMinSpace( 5 );
2759   ac1_4->setMaxSpace( 5 );
2760   ac1_4->setBorderWidth( 0 );
2761   Button *b7 = (Button*)ac1_4->add( new Button( aguix, 0, 0, catalog.getLocale( 95 ), 0 ), 0, 0, AContainer::CO_INCW );
2762   ChooseButton *cb2 = (ChooseButton*)ac1_4->add( new ChooseButton( aguix, 0,
2763                                                                    0, ft1->getUseFiledesc(),
2764                                                                    catalog.getLocale( 96 ), LABEL_LEFT, 1 ), 1, 0,
2765                                                                    cfixnr );
2766 
2767   /************
2768    * libmagic *
2769    ************/
2770 
2771   AWindow *subwin16 = new AWindow( aguix, 0, 0, 10, 10, "" );
2772   k1->add( subwin16 );
2773   subwin16->create();
2774 
2775   AContainer *acsw16 = subwin16->setContainer( new AContainer( subwin16, 1, 6 ), true );
2776   acsw16->setMinSpace( 5 );
2777   acsw16->setMaxSpace( 5 );
2778   acsw16->setBorderWidth( 5 );
2779 
2780   AContainer *ac1_4_2_1 = acsw16->add( new AContainer( subwin16, 3, 1 ), 0, 0 );
2781   ac1_4_2_1->setMinSpace( 5 );
2782   ac1_4_2_1->setMaxSpace( 5 );
2783   ac1_4_2_1->setBorderWidth( 0 );
2784   ac1_4_2_1->add( new Text( aguix, 0, 0, catalog.getLocale( 795 ) ), 0, 0, AContainer::CO_FIX );
2785   StringGadget *magic_sg = (StringGadget*)ac1_4_2_1->add( new StringGadget( aguix, 0,
2786                                                                           0,
2787                                                                           100,
2788                                                                           ft1->getMagicPattern().c_str(), 0 ), 1, 0, AContainer::CO_INCW );
2789   ChooseButton *magic_cb = (ChooseButton*)ac1_4_2_1->add( new ChooseButton( aguix, 0,
2790                                                                             0, ft1->getUseMagic(),
2791                                                                             catalog.getLocale( 796 ), LABEL_LEFT, 1 ),
2792                                                           2, 0, cfixnr );
2793 
2794   AContainer *magic_options_cont = acsw16->add( new AContainer( subwin16, 3, 1 ), 0, 1 );
2795   magic_options_cont->setMinSpace( 5 );
2796   magic_options_cont->setMaxSpace( 5 );
2797   magic_options_cont->setBorderWidth( 0 );
2798   ChooseButton *magic_compressed_cb = magic_options_cont->addWidget( new ChooseButton( aguix, 0,
2799                                                                                        0, ft1->getMagicCompressed(),
2800                                                                                        catalog.getLocale( 811 ), LABEL_RIGHT, 1 ),
2801                                                                      0, 0, AContainer::CO_INCWNR );
2802   ChooseButton *magic_mime_cb = magic_options_cont->addWidget( new ChooseButton( aguix, 0,
2803                                                                                  0, ft1->getMagicMime(),
2804                                                                                  catalog.getLocale( 1013 ), LABEL_RIGHT, 1 ),
2805                                                                1, 0, AContainer::CO_INCWNR );
2806   ChooseButton *magic_ignore_case_cb = magic_options_cont->addWidget( new ChooseButton( aguix, 0,
2807                                                                                         0, ft1->getMagicIgnoreCase(),
2808                                                                                         catalog.getLocale( 501 ), LABEL_RIGHT, 1 ),
2809                                                                       2, 0, AContainer::CO_INCWNR );
2810 
2811   acsw16->add( new BevelBox( aguix, 0, 0, 100, 2, 0 ), 0, 2, AContainer::CO_INCW );
2812 
2813   AContainer *ac1_4_2_2 = acsw16->add( new AContainer( subwin16, 3, 1 ), 0, 3 );
2814   ac1_4_2_2->setMinSpace( 5 );
2815   ac1_4_2_2->setMaxSpace( 5 );
2816   ac1_4_2_2->setBorderWidth( 0 );
2817   ac1_4_2_2->add( new Text( aguix, 0, 0, catalog.getLocale( 797 ) ), 0, 0, AContainer::CO_FIX );
2818   StringGadget *magic_testfile_sg = (StringGadget*)ac1_4_2_2->add( new StringGadget( aguix, 0,
2819                                                                                      0,
2820                                                                                      100,
2821                                                                                      "", 0 ), 1, 0, AContainer::CO_INCW );
2822   Button *magic_file_test_b = (Button*)ac1_4_2_2->add( new Button( aguix,
2823                                                                    0, 0,
2824                                                                    catalog.getLocale( 458 ),
2825                                                                    0 ), 2, 0, AContainer::CO_FIX );
2826 
2827   AContainer *ac1_4_2_3 = acsw16->add( new AContainer( subwin16, 2, 1 ), 0, 4 );
2828   ac1_4_2_3->setMinSpace( 5 );
2829   ac1_4_2_3->setMaxSpace( 5 );
2830   ac1_4_2_3->setBorderWidth( 0 );
2831   ac1_4_2_3->add( new Text( aguix, 0, 0, catalog.getLocale( 798 ) ), 0, 0, AContainer::CO_FIX );
2832   StringGadget *magic_output_sg = (StringGadget*)ac1_4_2_3->add( new StringGadget( aguix, 0,
2833                                                                                    0,
2834                                                                                    100,
2835                                                                                    "", 0 ), 1, 0, AContainer::CO_INCW );
2836 
2837   AContainer *ac1_4_2_4 = acsw16->add( new AContainer( subwin16, 4, 1 ), 0, 5 );
2838   ac1_4_2_4->setMinSpace( 5 );
2839   ac1_4_2_4->setMaxSpace( 5 );
2840   ac1_4_2_4->setBorderWidth( 0 );
2841   ac1_4_2_4->add( new Text( aguix, 0, 0, catalog.getLocale( 799 ) ), 0, 0, AContainer::CO_FIX );
2842   Text *magic_matches_text = (Text*)ac1_4_2_4->add( new Text( aguix, 0, 0, "" ), 1, 0, AContainer::CO_INCW );
2843   Button *magic_check_b = (Button*)ac1_4_2_4->add( new Button( aguix,
2844                                                                0, 0,
2845                                                                catalog.getLocale( 800 ),
2846                                                                0 ), 2, 0, AContainer::CO_FIX );
2847   Button *magic_help_b = (Button*)ac1_4_2_4->add( new Button( aguix,
2848                                                               0, 0,
2849                                                               catalog.getLocale( 483 ),
2850                                                               0 ), 3, 0, AContainer::CO_FIX );
2851 
2852   AWindow *subwin14 = new AWindow( aguix, 0, 0, 10, 10, "" );
2853   k1->add( subwin14 );
2854   subwin14->create();
2855 
2856   AContainer *acsw14 = subwin14->setContainer( new AContainer( subwin14, 1, 2 ), true );
2857   acsw14->setMinSpace( 5 );
2858   acsw14->setMaxSpace( 5 );
2859   acsw14->setBorderWidth( 5 );
2860 
2861   AContainer *ac1_6 = acsw14->add( new AContainer( subwin14, 3, 1 ), 0, 0 );
2862   ac1_6->setMinSpace( 5 );
2863   ac1_6->setMaxSpace( 5 );
2864   ac1_6->setBorderWidth( 0 );
2865   ac1_6->add( new Text( aguix, 0, 0, catalog.getLocale( 573 ) ), 0, 0, AContainer::CO_FIX );
2866 
2867   AContainer *ac1_6_1 = ac1_6->add( new AContainer( subwin14, 2, 1 ), 1, 0 );
2868   ac1_6_1->setMinSpace( 0 );
2869   ac1_6_1->setMaxSpace( 0 );
2870   ac1_6_1->setBorderWidth( 0 );
2871   StringGadget *sg3=(StringGadget*)ac1_6_1->add( new StringGadget( aguix, 0,
2872                                                                    0,
2873                                                                    100,
2874                                                                    ft1->getExtCond(), 0 ), 0, 0, AContainer::CO_INCW );
2875   Button *flagb = (Button*)ac1_6_1->add( new Button( aguix,
2876                                                      0, 0,
2877                                                      "F",
2878                                                      0 ), 1, 0, AContainer::CO_FIX );
2879   ChooseButton *cb3 = (ChooseButton*)ac1_6->add( new ChooseButton( aguix, 0,
2880                                                                    0, ft1->getUseExtCond(),
2881                                                                    catalog.getLocale( 574 ), LABEL_LEFT, 1 ), 2, 0,
2882                                                                    cfixnr );
2883   Button *exthb = (Button*)acsw14->add( new Button( aguix,
2884                                                     0,
2885 		   		   	            0,
2886 				 		    catalog.getLocale( 483 ),
2887 						    0 ), 0, 1, AContainer::CO_INCWNR );
2888 
2889   AWindow *subwin15 = new AWindow( aguix, 0, 0, 10, 10, "" );
2890   k1->add( subwin15 );
2891   subwin15->create();
2892 
2893   AContainer *acsw15 = subwin15->setContainer( new AContainer( subwin15, 1, 4 ), true );
2894   acsw15->setMinSpace( 5 );
2895   acsw15->setMaxSpace( 5 );
2896   acsw15->setBorderWidth( 5 );
2897 
2898   AContainer *ac15_1 = acsw15->add( new AContainer( subwin15, 2, 1 ), 0, 0 );
2899   ac15_1->setMinSpace( 5 );
2900   ac15_1->setMaxSpace( 5 );
2901   ac15_1->setBorderWidth( 0 );
2902   ac15_1->add( new Text( aguix, 0, 0, catalog.getLocale( 601 ) ), 0, 0, AContainer::CO_FIX );
2903   CycleButton *cyftc = (CycleButton*)ac15_1->add( new CycleButton( aguix,
2904 								   0,
2905 								   0,
2906 								   100,
2907 								   0 ), 1, 0, AContainer::CO_INCW );
2908   cyftc->addOption( catalog.getLocale( 602 ) );
2909   cyftc->addOption( catalog.getLocale( 603 ) );
2910   cyftc->addOption( catalog.getLocale( 604 ) );
2911   cyftc->addOption( catalog.getLocale( 605 ) );
2912   cyftc->resize( cyftc->getMaxSize(), cyftc->getHeight() );
2913   ac15_1->readLimits();
2914 
2915   acsw15->add( new Text( aguix, 0, 0, catalog.getLocale( 606 ) ), 0, 1, AContainer::CO_INCWNR );
2916 
2917   AContainer *ac15_2 = acsw15->add( new AContainer( subwin15, 3, 4 ), 0, 2 );
2918   ac15_2->setMinSpace( 5 );
2919   ac15_2->setMaxSpace( 5 );
2920   ac15_2->setBorderWidth( 0 );
2921 
2922   ftc[0] = (Text*)ac15_2->add( new Text( aguix,
2923 					 0, 0,
2924 					 catalog.getLocale( 607 ),
2925 					 ft1->getCustomColor( 0 )[0], ft1->getCustomColor( 1 )[0] ), 0, 0, AContainer::CO_FIX );
2926   ftc[1] = (Text*)ac15_2->add( new Text( aguix,
2927 					 0, 0,
2928 					 catalog.getLocale( 608 ),
2929 					 ft1->getCustomColor( 0 )[1], ft1->getCustomColor( 1 )[1] ), 0, 1, AContainer::CO_FIX );
2930   ftc[2] = (Text*)ac15_2->add( new Text( aguix,
2931 					 0, 0,
2932 					 catalog.getLocale( 609 ),
2933 					 ft1->getCustomColor( 0 )[2], ft1->getCustomColor( 1 )[2] ), 0, 2, AContainer::CO_FIX );
2934   ftc[3] = (Text*)ac15_2->add( new Text( aguix,
2935 					 0, 0,
2936 					 catalog.getLocale( 610 ),
2937 					 ft1->getCustomColor( 0 )[3], ft1->getCustomColor( 1 )[3] ), 0, 3, AContainer::CO_FIX );
2938 
2939   for ( i = 0; i < 4; i++ ) {
2940     ftcb[i][0] = (Button*)ac15_2->add( new Button( aguix,
2941 						   0,
2942 						   0,
2943 						   catalog.getLocale( 32 ),
2944 						   0 ), 1, i, AContainer::CO_INCW );
2945     ftcb[i][1] = (Button*)ac15_2->add( new Button( aguix,
2946 						   0,
2947 						   0,
2948 						   catalog.getLocale( 33 ),
2949 						   0 ), 2, i, AContainer::CO_INCW );
2950   }
2951 
2952   AContainer *ac15_3 = acsw15->add( new AContainer( subwin15, 2, 1 ), 0, 3 );
2953   ac15_3->setMinSpace( 5 );
2954   ac15_3->setMaxSpace( 5 );
2955   ac15_3->setBorderWidth( 0 );
2956 
2957   ac15_3->add( new Text( aguix, 0, 0, catalog.getLocale( 611 ) ), 0, 0, AContainer::CO_FIX );
2958 
2959   AContainer *ac15_3_1 = ac15_3->add( new AContainer( subwin15, 3, 1 ), 1, 0 );
2960   ac15_3_1->setMinSpace( 0 );
2961   ac15_3_1->setMaxSpace( 0 );
2962   ac15_3_1->setBorderWidth( 0 );
2963 
2964   Button *ftcsb = (Button*)ac15_3_1->add( new Button( aguix,
2965 						      0,
2966 						      0,
2967 						      catalog.getLocale( 458 ),
2968 						      0 ), 0, 0, AContainer::CO_FIX );
2969   StringGadget *ftcsg = (StringGadget*)ac15_3_1->add( new StringGadget( aguix, 0,
2970 									0, 100,
2971 									( ft1->getColorExt() != NULL ) ? ft1->getColorExt() : "",
2972 									0 ), 1, 0, AContainer::CO_INCW );
2973   Button *ftchb = (Button*)ac15_3_1->add( new Button( aguix,
2974 						      0,
2975 						      0,
2976 						      catalog.getLocale( 483 ),
2977 						      0 ), 2, 0, AContainer::CO_FIX );
2978 
2979   switch ( ft1->getColorMode() ) {
2980   case WCFiletype::CUSTOMCOL:
2981     cyftc->setOption( 1 );
2982     break;
2983   case WCFiletype::EXTERNALCOL:
2984     cyftc->setOption( 2 );
2985     break;
2986   case WCFiletype::PARENTCOL:
2987     cyftc->setOption( 3 );
2988     break;
2989   default:
2990     cyftc->setOption( 0 );
2991     break;
2992   }
2993 
2994   /****************
2995    * priority tab *
2996    ****************/
2997 
2998   AWindow *subwin17 = new AWindow( aguix, 0, 0, 10, 10, "" );
2999   k1->add( subwin17 );
3000   subwin17->create();
3001 
3002   AContainer *acsw17 = subwin17->setContainer( new AContainer( subwin17, 1, 1 ), true );
3003   acsw17->setMinSpace( 5 );
3004   acsw17->setMaxSpace( 5 );
3005   acsw17->setBorderWidth( 5 );
3006 
3007   AContainer *acsw17_1 = acsw17->add( new AContainer( subwin17, 2, 1 ), 0, 0 );
3008   acsw17_1->setMinSpace( 5 );
3009   acsw17_1->setMaxSpace( 5 );
3010   acsw17_1->setBorderWidth( 0 );
3011   acsw17_1->add( new Text( aguix, 0, 0, catalog.getLocale( 1359 ) ), 0, 0, AContainer::CO_FIX );
3012 
3013   AContainer *acsw17_1_1 = acsw17_1->add( new AContainer( subwin17, 4, 1 ), 1, 0 );
3014   acsw17_1_1->setMinSpace( 0 );
3015   acsw17_1_1->setMaxSpace( 0 );
3016   acsw17_1_1->setBorderWidth( 0 );
3017   std::string priostr = AGUIXUtils::formatStringToString( "%d", ft1->priority() );
3018   StringGadget *priosg = acsw17_1_1->addWidget( new StringGadget( aguix, 0,
3019                                                                   0,
3020                                                                   100,
3021                                                                   priostr.c_str(), 0 ), 0, 0, AContainer::CO_INCW );
3022   Button *highpriob = acsw17_1_1->addWidget( new Button( aguix,
3023                                                          0, 0,
3024                                                          catalog.getLocale( 1356 ),
3025                                                          0 ), 1, 0, AContainer::CO_FIX );
3026   Button *defaultpriob = acsw17_1_1->addWidget( new Button( aguix,
3027                                                             0, 0,
3028                                                             catalog.getLocale( 1357 ),
3029                                                             0 ), 2, 0, AContainer::CO_FIX );
3030   Button *lowpriob = acsw17_1_1->addWidget( new Button( aguix,
3031                                                         0, 0,
3032                                                         catalog.getLocale( 1358 ),
3033                                                         0 ), 3, 0, AContainer::CO_FIX );
3034 
3035   k1->setOption( subwin12, 0, catalog.getLocale( 575 ) );
3036   k1->setOption( subwin13, 1, catalog.getLocale( 95 ) );
3037   k1->setOption( subwin16, 2, catalog.getLocale( 803 ) );
3038   k1->setOption( subwin14, 3, catalog.getLocale( 576 ) );
3039   k1->setOption( subwin15, 4, catalog.getLocale( 612 ) );
3040   k1->setOption( subwin17, 5, catalog.getLocale( 1360 ) );
3041   k1->maximize();
3042   k1->contMaximize();
3043   ac1->readLimits();
3044 
3045   AContainer *ac1_5 = ac1->add( new AContainer( win, 2, 1 ), 0, 6 );
3046   ac1_5->setMinSpace( 5 );
3047   ac1_5->setMaxSpace( -1 );
3048   ac1_5->setBorderWidth( 0 );
3049   Button *okb =(Button*)ac1_5->add( new Button( aguix,
3050                                                 0,
3051                                                 0,
3052                                                 catalog.getLocale( 11 ),
3053                                                 0 ), 0, 0, AContainer::CO_FIX );
3054   Button *cancelb = (Button*)ac1_5->add( new Button( aguix,
3055                                                      0,
3056                                                      0,
3057                                                      catalog.getLocale( 8 ),
3058                                                      0 ), 1, 0, AContainer::CO_FIX );
3059   win->setDoTabCycling( true );
3060   win->contMaximize( true );
3061   w = win->getWidth();
3062   h = win->getHeight();
3063 
3064   if ( ( configureFiletypeSize[0] >= w ) && ( configureFiletypeSize[1] >= h ) ) {
3065     win->resize( configureFiletypeSize[0], configureFiletypeSize[1] );
3066   }
3067 
3068   w = win->getWidth();
3069   h = win->getHeight();
3070 
3071   win->show();
3072   k1->show();
3073 
3074   if ( default_panel >= 0 && default_panel <= 4 ) {
3075       k1->optionChange( default_panel );
3076   }
3077 
3078   AGMessage *msg;
3079   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
3080   int ende=0;
3081   command_list_t coms;
3082   std::string current_actionname;
3083 
3084   trow = lv0->getActiveRow();
3085   if ( lv0->isValidRow( trow ) == true ) {
3086       showFTActions( lv0->getText( trow, 0 ).c_str(), ft1, lv, &coms, current_actionname );
3087   }
3088 
3089   freq = new FileRequester( aguix );
3090 
3091   lastrow = -1;
3092   timerclear( &tv1 );
3093   while(ende==0) {
3094     msg=aguix->WaitMessage(win);
3095     if(msg!=NULL) {
3096       if(msg->type==AG_CLOSEWINDOW) {
3097         if(msg->closewindow.window==win->getWindow()) ende=-1;
3098       } else if(msg->type==AG_BUTTONCLICKED) {
3099         if(msg->button.button==okb) ende=1;
3100         else if(msg->button.button==cancelb) ende=-1;
3101         else if(msg->button.button==b2) {
3102             bool dontConfigure = false;
3103             auto fpr=requestCommand( dontConfigure );
3104             if(fpr!=NULL) {
3105                 coms.push_back( fpr );
3106                 if ( ! dontConfigure ) fpr->configureWhenAvail();
3107                 row = lv->addRow();
3108                 lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
3109                 lv->setText( row, 0, fpr->getDescription() );
3110                 lv->setActiveRow( row );
3111                 lv->showActive();
3112                 lv->redraw();
3113             }
3114         } else if(msg->button.button==b3) {
3115             row = lv->getActiveRow();
3116             if ( lv->isValidRow( row ) == true ) {
3117                 auto it = coms.begin();
3118                 std::advance( it, row );
3119                 coms.erase( it );
3120                 lv->deleteRow( row );
3121                 if ( lv->isValidRow( row ) == true )
3122                     lv->setActiveRow( row );
3123                 else
3124                     lv->setActiveRow( row - 1 );
3125                 lv->showActive();
3126                 lv->redraw();
3127             }
3128         } else if(msg->button.button==b4) {
3129             row = lv->getActiveRow();
3130             if ( lv->isValidRow( row ) == true ) {
3131                 auto fpr = coms.at( row );
3132                 fpr->configure();
3133                 lv->setText( row, 0, fpr->getDescription() );
3134                 lv->redraw();
3135             }
3136         } else if(msg->button.button==b5) {
3137             row = lv->getActiveRow();
3138             if ( lv->isValidRow( row ) == true ) {
3139                 if ( row > 0 ) {
3140                     auto fpr = coms.at( row );
3141                     coms.at( row ) = coms.at( row - 1 );
3142                     coms.at( row - 1 ) = fpr;
3143                     lv->swapRows( row, row - 1 );
3144                     lv->showActive();
3145                     lv->redraw();
3146                 }
3147             }
3148         } else if(msg->button.button==b6) {
3149             row = lv->getActiveRow();
3150             if ( lv->isValidRow( row ) == true ) {
3151                 if ( row < ( lv->getElements() - 1 ) ) {
3152                     auto fpr = coms.at( row );
3153                     coms.at( row ) = coms.at( row + 1 );
3154                     coms.at( row + 1 ) = fpr;
3155                     lv->swapRows( row, row + 1 );
3156                     lv->showActive();
3157                     lv->redraw();
3158                 }
3159             }
3160         } else if(msg->button.button==b7) {
3161           if(changeFiledesc(ft1)==true) {
3162             cb2->setState(1);
3163           }
3164         } else if ( msg->button.button == patternhb ) {
3165           Requester *req = new Requester( aguix, win );
3166           req->request( catalog.getLocale( 575 ),
3167                         catalog.getLocale( 577 ),
3168                         catalog.getLocale( 11 ) );
3169           delete req;
3170         } else if ( msg->button.button == exthb ) {
3171           Requester *req = new Requester( aguix, win );
3172           req->request( catalog.getLocale( 576 ),
3173                         catalog.getLocale( 593 ),
3174                         catalog.getLocale( 11 ) );
3175           delete req;
3176         } else if ( msg->button.button == flagb ) {
3177           sg3->insertAtCursor( CondParser::requestFlag() );
3178 	} else if ( msg->button.button == ftcsb ) {
3179 	  if ( freq->request_entry( catalog.getLocale( 265 ),
3180 				    NULL,
3181 				    catalog.getLocale( 11 ),
3182 				    catalog.getLocale( 8 ),
3183 				    catalog.getLocale( 265 ),
3184 				    true ) > 0 ) {
3185 	    std::string str1 = freq->getLastEntryStr();
3186 	    if ( str1.length() > 0 ) {
3187 	      const char *newstr1 = ftcsg->getText();
3188 	      char *newstr2;
3189 	      int pos = ftcsg->getCursor();
3190 
3191 	      newstr2 = (char*)_allocsafe( strlen( newstr1 ) + strlen( str1.c_str() ) + 1 );
3192 	      strncpy( newstr2, newstr1, pos );
3193 	      strcpy( newstr2 + pos, str1.c_str() );
3194 	      strcpy( newstr2 + pos + strlen( str1.c_str() ), newstr1 + pos );
3195 	      ftcsg->setText( newstr2 );
3196 	      _freesafe( newstr2 );
3197 	    }
3198 	  }
3199         } else if ( msg->button.button == ftchb ) {
3200           Requester *req = new Requester( aguix, win );
3201           req->request( catalog.getLocale( 576 ),
3202                         catalog.getLocale( 613 ),
3203                         catalog.getLocale( 11 ) );
3204           delete req;
3205         } else if ( msg->button.button == new_action_b ) {
3206             std::string new_name = queryNewActionName();
3207             if ( new_name.length() > 0 ) {
3208                 auto res = ft1->getCustomActions( new_name );
3209                 if ( res.second == false ) {
3210                     ft1->setCustomActions( new_name, {} );
3211 
3212                     trow = lv0->addRow();
3213                     lv0->setPreColors( trow, FieldListView::PRECOLOR_ONLYACTIVE );
3214                     lv0->setText( trow, 0, new_name );
3215                     lv0->setActiveRow( trow );
3216                     lv0->showActive();
3217                     showFTActions( new_name.c_str(), ft1, lv, &coms, current_actionname );
3218                 }
3219             }
3220         } else if ( msg->button.button == del_action_b ) {
3221             trow = lv0->getActiveRow();
3222             //TODO do not use hard coded number of actions
3223             if ( lv0->isValidRow( trow ) == true && trow >= 14 ) {
3224                 std::string cname = lv0->getText( trow, 0 );
3225                 ft1->removeCustomAction( cname );
3226                 lv0->deleteRow( trow );
3227                 current_actionname = "";
3228 
3229                 lv0->setActiveRow( trow - 1 );
3230                 trow = lv0->getActiveRow();
3231                 if ( lv0->isValidRow( trow ) == true ) {
3232                     showFTActions( lv0->getText( trow, 0 ).c_str(), ft1, lv, &coms, current_actionname );
3233                 }
3234                 lv0->redraw();
3235             }
3236         } else if ( msg->button.button == magic_file_test_b ) {
3237             if ( freq->request_entry( catalog.getLocale( 265 ),
3238                                       NULL,
3239                                       catalog.getLocale( 11 ),
3240                                       catalog.getLocale( 8 ),
3241                                       catalog.getLocale( 265 ),
3242                                       false ) > 0 ) {
3243                 std::string str1 = freq->getLastEntryStr();
3244                 if ( str1.length() > 0 ) {
3245                     magic_testfile_sg->setText( str1.c_str() );
3246                 }
3247             }
3248         } else if ( msg->button.button == magic_check_b ) {
3249             std::string testfile = magic_testfile_sg->getText();
3250             if ( Datei::fileExists( testfile.c_str() ) == true ) {
3251                 int flags = 0;
3252                 if ( magic_compressed_cb->getState() ) {
3253                     flags |= MagicDB::DECOMPRESS;
3254                 }
3255                 if ( magic_mime_cb->getState() ) {
3256                     flags |= MagicDB::USE_MIME;
3257                 }
3258 
3259                 std::string magic_result = MagicDB::getInstance().getInfo( testfile,
3260                                                                            flags );
3261                 magic_output_sg->setText( magic_result.c_str() );
3262 
3263                 ft1->setMagicPattern( magic_sg->getText() );
3264                 ft1->setMagicIgnoreCase( magic_ignore_case_cb->getState() );
3265                 if ( ft1->magicMatch( magic_result ) == true ) {
3266                     magic_matches_text->setText( catalog.getLocale( 801 ) );
3267                 } else {
3268                     magic_matches_text->setText( catalog.getLocale( 802 ) );
3269                 }
3270             }
3271         } else if ( msg->button.button == magic_help_b ) {
3272             Requester *req = new Requester( aguix, win );
3273             req->request( catalog.getLocale( 803 ),
3274                           catalog.getLocale( 804 ),
3275                           catalog.getLocale( 11 ) );
3276             delete req;
3277         } else if ( sg1_flag_b && msg->button.button == sg1_flag_b ) {
3278             insertFileTypeFlag( sg1, ft1 );
3279         } else if ( msg->button.button == highpriob ) {
3280             priosg->setText( "-10" );
3281         } else if ( msg->button.button == defaultpriob ) {
3282             priosg->setText( "0" );
3283         } else if ( msg->button.button == lowpriob ) {
3284             priosg->setText( "10" );
3285         } else {
3286 	  for ( i = 0; i < 4; i++ ) {
3287 	    if ( msg->button.button == ftcb[i][0] ) {
3288 	      int col = palette( ftc[i]->getFG() );
3289 	      if ( col >= 0 ) {
3290 		ftc[i]->setFG( col );
3291 		cyftc->setOption( 1 );
3292 	      }
3293 	    } else if ( msg->button.button == ftcb[i][1] ) {
3294 	      int col = palette( ftc[i]->getBG() );
3295 	      if ( col >= 0 ) {
3296 		ftc[i]->setBG( col );
3297 		cyftc->setOption( 1 );
3298 	      }
3299 	    }
3300           }
3301         }
3302       } else if(msg->type==AG_STRINGGADGET_DEACTIVATE) {
3303         if(msg->stringgadget.sg==sg2) cb1->setState(1);
3304         else if ( msg->stringgadget.sg == sg3 ) cb3->setState( 1 );
3305 	else if ( msg->stringgadget.sg == ftcsg ) cyftc->setOption( 2 );
3306 	else if ( msg->stringgadget.sg == magic_sg ) magic_cb->setState( 1 );
3307       } else if ( msg->type == AG_SIZECHANGED ) {
3308       } else if ( ( msg->type == AG_FIELDLV_ONESELECT ) || ( msg->type == AG_FIELDLV_MULTISELECT ) ) {
3309         if ( ( msg->type == AG_FIELDLV_ONESELECT ) &&
3310 	     ( msg->fieldlv.lv == lv ) &&
3311 	     ( msg->fieldlv.mouse == true ) ) {
3312           gettimeofday( &tv2, NULL );
3313           if ( lastrow < 0 ) {
3314             lastrow = msg->fieldlv.row;
3315             tv1 = tv2;
3316           } else {
3317               if  ( ( msg->fieldlv.row == lastrow ) &&
3318                     ( aguix->isDoubleClick( &tv2, &tv1 ) == true ) ) {
3319                   if ( lv->isValidRow( lastrow ) == true ) {
3320                       auto fpr = coms.at( lastrow );
3321                       fpr->configure();
3322                       lv->setText( lastrow, 0, fpr->getDescription() );
3323                       lv->redraw();
3324                   }
3325                   lastrow = -1;
3326               } else {
3327                   lastrow = msg->fieldlv.row;
3328                   tv1 = tv2;
3329               }
3330           }
3331         } else if ( msg->fieldlv.lv == lv0 ) {
3332           // Nur das Aktions-LV interessiert
3333           trow = lv0->getActiveRow();
3334           if ( lv0->isValidRow( trow ) == true ) {
3335               showFTActions( lv0->getText( trow, 0 ).c_str(), ft1, lv, &coms, current_actionname );
3336           }
3337         }
3338       } else if ( msg->type == AG_FIELDLV_MULTISELECT ) {
3339         lastrow = -1;
3340       } else if ( msg->type == AG_CHOOSECLICKED ) {
3341           if ( msg->choose.button == comma_sep_cb &&
3342                msg->choose.state == true ) {
3343               cb12->setState( false );
3344           } else if ( msg->choose.button == cb12 &&
3345                       msg->choose.state == true ) {
3346               comma_sep_cb->setState( false );
3347           }
3348       } else if ( msg->type == AG_KEYPRESSED ) {
3349           if ( win->isParent( msg->key.window, false ) == true ) {
3350               switch ( msg->key.key ) {
3351                   case XK_Escape:
3352                       ende = -1;
3353                       break;
3354               }
3355           }
3356       }
3357       aguix->ReplyMessage(msg);
3358     }
3359   }
3360   if(ende==1) {
3361     // Uebernehmen
3362     showFTActions( NULL, ft1, lv, &coms, current_actionname );
3363 
3364     ft1->setName(sg1->getText());
3365     ft1->setPattern(sg2->getText());
3366     ft1->setUsePattern( cb1->getState() );
3367     ft1->setPatternIgnoreCase( cb11->getState() );
3368     ft1->setPatternUseRegExp( cb12->getState() );
3369     ft1->setPatternUseFullname( cb13->getState() );
3370     ft1->setUseFiledesc( cb2->getState() );
3371     ft1->setExtCond( sg3->getText() );
3372     ft1->setUseExtCond( cb3->getState() );
3373 
3374     switch ( cyftc->getSelectedOption() ) {
3375       case 1:
3376         ft1->setColorMode( WCFiletype::CUSTOMCOL );
3377 	for ( i = 0; i < 4; i++ ) {
3378 	  ft1->setCustomColor( 0, i, ftc[i]->getFG() );
3379 	  ft1->setCustomColor( 1, i, ftc[i]->getBG() );
3380 	}
3381         break;
3382       case 2:
3383         ft1->setColorMode( WCFiletype::EXTERNALCOL );
3384 	ft1->setColorExt( ftcsg->getText() );
3385 	break;
3386       case 3:
3387         ft1->setColorMode( WCFiletype::PARENTCOL );
3388 	break;
3389       default:
3390         ft1->setColorMode( WCFiletype::DEFAULTCOL );
3391         break;
3392     }
3393 
3394     ft1->setMagicPattern( magic_sg->getText() );
3395     ft1->setUseMagic( magic_cb->getState() );
3396     ft1->setMagicCompressed( magic_compressed_cb->getState() );
3397     ft1->setMagicMime( magic_mime_cb->getState() );
3398     ft1->setMagicIgnoreCase( magic_ignore_case_cb->getState() );
3399     ft1->setPatternIsCommaSeparated( comma_sep_cb->getState() );
3400     ft1->setPriority( atoi( priosg->getText() ) );
3401   } else {
3402     ft1->setDNDActions(ft1_bak->getDNDActions());
3403     ft1->setDoubleClickActions(ft1_bak->getDoubleClickActions());
3404     ft1->setShowActions(ft1_bak->getShowActions());
3405     ft1->setRawShowActions(ft1_bak->getRawShowActions());
3406     ft1->setUserActions(0,ft1_bak->getUserActions(0));
3407     ft1->setUserActions(1,ft1_bak->getUserActions(1));
3408     ft1->setUserActions(2,ft1_bak->getUserActions(2));
3409     ft1->setUserActions(3,ft1_bak->getUserActions(3));
3410     ft1->setUserActions(4,ft1_bak->getUserActions(4));
3411     ft1->setUserActions(5,ft1_bak->getUserActions(5));
3412     ft1->setUserActions(6,ft1_bak->getUserActions(6));
3413     ft1->setUserActions(7,ft1_bak->getUserActions(7));
3414     ft1->setUserActions(8,ft1_bak->getUserActions(8));
3415     ft1->setUserActions(9,ft1_bak->getUserActions(9));
3416     ft1->setFiledesc(ft1_bak->getFiledesc());
3417 
3418     ft1->clearCustomActions();
3419 
3420     std::list<std::string> names;
3421     ft1_bak->fillNamesOfCustomActions( false, names );
3422 
3423     std::list<std::string>::const_iterator cit1;
3424     for ( cit1 = names.begin(); cit1 != names.end(); cit1++ ) {
3425 	ft1->setCustomActions( *cit1, ft1_bak->getCustomActions( *cit1 ).first );
3426     }
3427     ft1->setMagicPattern( ft1_bak->getMagicPattern() );
3428     ft1->setUseMagic( ft1_bak->getUseMagic() );
3429     ft1->setMagicCompressed( ft1_bak->getMagicCompressed() );
3430     ft1->setMagicMime( ft1_bak->getMagicMime() );
3431     ft1->setMagicIgnoreCase( ft1_bak->getMagicIgnoreCase() );
3432     ft1->setPatternIsCommaSeparated( ft1_bak->getPatternIsCommaSeparated() );
3433     ft1->setPriority( ft1_bak->priority() );
3434   }
3435   delete ft1_bak;
3436   configureFiletypeSize[0] = win->getWidth();
3437   configureFiletypeSize[1] = win->getHeight();
3438   delete win;
3439 
3440   delete freq;
3441 
3442   return (ende==-1)?false:true;
3443 }
3444 
showFTActions(const char * actionname,WCFiletype * ft,FieldListView * lv1,command_list_t * return_list,std::string & write_back_name)3445 void WConfig::showFTActions( const char *actionname,
3446                              WCFiletype *ft,
3447                              FieldListView *lv1,
3448                              command_list_t *return_list,
3449                              std::string &write_back_name )
3450 {
3451     command_list_t l1;
3452     int row;
3453 
3454     if ( return_list != NULL && ! write_back_name.empty() ){
3455         // store current list content to action name
3456         if ( write_back_name == catalog.getLocale(251) ) {
3457             // DND
3458             ft->setDNDActions( *return_list );
3459         } else if ( write_back_name == catalog.getLocale(252) ) {
3460             // DoubleClick
3461             ft->setDoubleClickActions( *return_list );
3462         } else if ( write_back_name == catalog.getLocale(253) ) {
3463             // Show
3464             ft->setShowActions( *return_list );
3465         } else if ( write_back_name == catalog.getLocale(254) ) {
3466             // RawShow
3467             ft->setRawShowActions( *return_list );
3468         } else if ( write_back_name == catalog.getLocale(255) ) {
3469             // User0
3470             ft->setUserActions( 0, *return_list );
3471         } else if ( write_back_name == catalog.getLocale(256) ) {
3472             // User1
3473             ft->setUserActions( 1, *return_list );
3474         } else if ( write_back_name == catalog.getLocale(257) ) {
3475             // User2
3476             ft->setUserActions( 2, *return_list );
3477         } else if ( write_back_name == catalog.getLocale(258) ) {
3478             // User3
3479             ft->setUserActions( 3, *return_list );
3480         } else if ( write_back_name == catalog.getLocale(259) ) {
3481             // User4
3482             ft->setUserActions( 4, *return_list );
3483         } else if ( write_back_name == catalog.getLocale(260) ) {
3484             // User5
3485             ft->setUserActions( 5, *return_list );
3486         } else if ( write_back_name == catalog.getLocale(261) ) {
3487             // User6
3488             ft->setUserActions( 6, *return_list );
3489         } else if ( write_back_name == catalog.getLocale(262) ) {
3490             // User7
3491             ft->setUserActions( 7, *return_list );
3492         } else if ( write_back_name == catalog.getLocale(263) ) {
3493             // User8
3494             ft->setUserActions( 8, *return_list );
3495         } else if ( write_back_name == catalog.getLocale(264) ) {
3496             // User9
3497             ft->setUserActions( 9, *return_list );
3498         } else {
3499             ft->setCustomActions( write_back_name, *return_list  );
3500         }
3501     }
3502 
3503     if ( actionname ) {
3504         if(strcmp(actionname,catalog.getLocale(251))==0) {
3505             // DND
3506             l1=ft->getDNDActions();
3507         } else if(strcmp(actionname,catalog.getLocale(252))==0) {
3508             // DoubleClick
3509             l1=ft->getDoubleClickActions();
3510         } else if(strcmp(actionname,catalog.getLocale(253))==0) {
3511             // Show
3512             l1=ft->getShowActions();
3513         } else if(strcmp(actionname,catalog.getLocale(254))==0) {
3514             // RawShow
3515             l1=ft->getRawShowActions();
3516         } else if(strcmp(actionname,catalog.getLocale(255))==0) {
3517             // User0
3518             l1=ft->getUserActions(0);
3519         } else if(strcmp(actionname,catalog.getLocale(256))==0) {
3520             // User1
3521             l1=ft->getUserActions(1);
3522         } else if(strcmp(actionname,catalog.getLocale(257))==0) {
3523             // User2
3524             l1=ft->getUserActions(2);
3525         } else if(strcmp(actionname,catalog.getLocale(258))==0) {
3526             // User3
3527             l1=ft->getUserActions(3);
3528         } else if(strcmp(actionname,catalog.getLocale(259))==0) {
3529             // User4
3530             l1=ft->getUserActions(4);
3531         } else if(strcmp(actionname,catalog.getLocale(260))==0) {
3532             // User5
3533             l1=ft->getUserActions(5);
3534         } else if(strcmp(actionname,catalog.getLocale(261))==0) {
3535             // User6
3536             l1=ft->getUserActions(6);
3537         } else if(strcmp(actionname,catalog.getLocale(262))==0) {
3538             // User7
3539             l1=ft->getUserActions(7);
3540         } else if(strcmp(actionname,catalog.getLocale(263))==0) {
3541             // User8
3542             l1=ft->getUserActions(8);
3543         } else if(strcmp(actionname,catalog.getLocale(264))==0) {
3544             // User9
3545             l1=ft->getUserActions(9);
3546         } else {
3547             l1 = ft->getCustomActions( actionname ).first;
3548         }
3549 
3550         lv1->setSize( 0 );
3551         for ( auto &fpr : l1 ) {
3552             row = lv1->addRow();
3553             lv1->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
3554             lv1->setText( row, 0, fpr->getDescription() );
3555         }
3556         lv1->redraw();
3557     }
3558 
3559     if ( return_list != NULL ) *return_list = l1;
3560     if ( actionname ) {
3561         write_back_name = actionname;
3562     }
3563 }
3564 
changeFiledesc(WCFiletype * ft)3565 bool WConfig::changeFiledesc(WCFiletype *ft)
3566 {
3567   WCFiletype *ft_bak=ft->duplicate();
3568   AGUIX *aguix=worker->getAGUIX();
3569   short *filedesc=ft->getFiledesc();
3570   int tw,w,h,ty;
3571   int t1,t2;
3572   char *str;
3573   AWindow *win;
3574   int trow;
3575 
3576   w=100;
3577   h=10;
3578   win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 101 ), AWindow::AWINDOW_DIALOG );
3579   win->create();
3580   ty=5;
3581   FieldListView *lv = (FieldListView*)win->add( new FieldListView( aguix, 5, ty, w - 10, 150, 0 ) );
3582   lv->setHBarState(2);
3583   lv->setVBarState(2);
3584   for(t1=0;t1<64;t1++) {
3585     str=getStr4Char(t1,filedesc[t1]);
3586     trow = lv->addRow();
3587     lv->setPreColors( trow, FieldListView::PRECOLOR_ONLYACTIVE );
3588     lv->setText( trow, 0, str );
3589     _freesafe(str);
3590   }
3591   lv->redraw();
3592   ty+=lv->getHeight()+5;
3593 
3594   t1 = aguix->getTextWidth( catalog.getLocale( 98 ) ) + 10;
3595   Button *b1=(Button*)win->add(new Button(aguix,5,ty,t1,catalog.getLocale(98),0));
3596   t2=b1->getWidth();
3597   t1 = aguix->getTextWidth( catalog.getLocale( 99 ) ) + 10;
3598   Button *b2=(Button*)win->add(new Button(aguix,5+t2+5,ty,t1,catalog.getLocale(99),0));
3599   tw=b2->getX()+b2->getWidth()+5;
3600   if(tw>w) w=tw;
3601   ty+=b2->getHeight()+5;
3602   t1 = aguix->getTextWidth( catalog.getLocale( 100 ) ) + 10;
3603   if((t1+10)<w) t1=w-10;
3604   Button *b3=(Button*)win->add(new Button(aguix,5,ty,t1,catalog.getLocale(100),0));
3605   tw=b3->getX()+b3->getWidth()+5;
3606   if(tw>w) w=tw;
3607   ty+=b3->getHeight()+5;
3608 
3609   t1 = aguix->getTextWidth( catalog.getLocale( 11 ) ) + 10;
3610   t2 = aguix->getTextWidth( catalog.getLocale( 8 ) ) + 10;
3611   tw=5+t1+5+t2+5;
3612   if(tw>w) w=tw;
3613   Button *okb=(Button*)win->add(new Button(aguix,
3614                                              5,
3615                                              ty,
3616                                              t1,
3617                                              catalog.getLocale(11),
3618                                              0));
3619   Button *cancelb=(Button*)win->add(new Button(aguix,
3620                                                  w-5-t2,
3621                                                  ty,
3622                                                  t2,
3623                                                  catalog.getLocale(8),
3624                                                  0));
3625   h=okb->getY()+okb->getHeight()+5;
3626   win->setDoTabCycling( true );
3627   win->resize(w,h);
3628   win->setMaxSize(w,h);
3629   win->setMinSize(w,h);
3630   lv->resize(w-10,lv->getHeight());
3631   b2->move(w-5-b2->getWidth(),b2->getY());
3632   win->show();
3633   AGMessage *msg;
3634   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
3635   int ende=0;
3636   while(ende==0) {
3637     msg=aguix->WaitMessage(win);
3638     if(msg!=NULL) {
3639       if(msg->type==AG_CLOSEWINDOW) {
3640         if(msg->closewindow.window==win->getWindow()) ende=-1;
3641       } else if(msg->type==AG_BUTTONCLICKED) {
3642         if(msg->button.button==okb) ende=1;
3643         else if(msg->button.button==cancelb) ende=-1;
3644         else if(msg->button.button==b1) {
3645           trow = lv->getActiveRow();
3646           if ( lv->isValidRow( trow ) == true ) {
3647             t2 = WCEditByte( filedesc[trow] );
3648             if(t2>=0) {
3649               filedesc[trow] = t2;
3650               str=getStr4Char( trow,t2);
3651               lv->setText( trow, 0, str );
3652               _freesafe(str);
3653               lv->redraw();
3654             }
3655           }
3656         } else if(msg->button.button==b2) {
3657           trow = lv->getActiveRow();
3658           if ( lv->isValidRow( trow ) == true ) {
3659             t2=-1;
3660             filedesc[trow] = t2;
3661             str = getStr4Char( trow, t2 );
3662             lv->setText( trow, 0, str );
3663             _freesafe(str);
3664             lv->redraw();
3665           }
3666         } else if(msg->button.button==b3) {
3667           win->hide();
3668           if(FTautocreate(ft)==true) {
3669             for(t1=0;t1<64;t1++) {
3670               str=getStr4Char(t1,filedesc[t1]);
3671               lv->setText( t1, 0, str );
3672               _freesafe(str);
3673             }
3674             lv->redraw();
3675           }
3676           win->show();
3677         }
3678       }
3679       aguix->ReplyMessage(msg);
3680     }
3681   }
3682   if(ende==-1) {
3683     ft->setFiledesc(ft_bak->getFiledesc());
3684   } else {
3685     for(t1=63;t1>=0;t1--) {
3686       if(filedesc[t1]>=0) {
3687         if(t1<63) filedesc[t1+1]=-2;
3688         break;
3689       }
3690     }
3691     if ( t1 < 1 ) if ( filedesc[0] < 0 ) filedesc[0] = -2;
3692   }
3693   delete ft_bak;
3694   delete win;
3695   return (ende==-1)?false:true;
3696 }
3697 
getStr4Char(int index2,short ch)3698 char *WConfig::getStr4Char(int index2,short ch)
3699 {
3700   char *str = (char*)_allocsafe( A_BYTESFORNUMBER( index2 ) + 1 + strlen( catalog.getLocale( 97 ) ) + 2 + 1 );
3701   char buf[ A_BYTESFORNUMBER( int ) + 1 + A_BYTESFORNUMBER( char ) ];
3702   std::string str1;
3703 
3704   sprintf(str,"%2d.%s: ",index2,catalog.getLocale(97));
3705   str1 = str;
3706   _freesafe( str );
3707   if(ch>=0) {
3708     sprintf(buf,"%3d %c",ch,ch);
3709     str1 += buf;
3710   }
3711   return dupstring( str1.c_str() );
3712 }
3713 
WCEditByte(int ch)3714 int WConfig::WCEditByte(int ch)
3715 {
3716   int return_byte;
3717   AGUIX *aguix=worker->getAGUIX();
3718   int tw,w,h,ty;
3719   int t1,t2;
3720   char buf[ A_BYTESFORNUMBER( int ) ];
3721 
3722   w=100;
3723   h=10;
3724   AWindow *win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 98 ), AWindow::AWINDOW_DIALOG );
3725   win->create();
3726   ty=5;
3727   Text *tt1=(Text*)win->add(new Text(aguix,5,ty,catalog.getLocale(102)));
3728   ty+=tt1->getHeight()+5;
3729   tw=tt1->getWidth()+10;
3730   if(tw>w) w=tw;
3731   if(ch>=0) sprintf(buf,"%d",ch); else buf[0]=0;
3732   t1 = aguix->getTextWidth( "000000" ) + 10;
3733   StringGadget *sg=(StringGadget*)win->add(new StringGadget(aguix,5,ty,t1,buf,0));
3734   if(ch>=0) sprintf(buf,"%c",ch); else buf[0]=0;
3735   tt1=(Text*)win->add(new Text(aguix,sg->getX()+sg->getWidth()+5,ty,buf));
3736   tw=tt1->getX()+tt1->getWidth()+5;
3737   if(tw>w) w=tw;
3738   ty+=sg->getHeight()+5;
3739 
3740   t1 = aguix->getTextWidth( catalog.getLocale( 11 ) ) + 10;
3741   t2 = aguix->getTextWidth( catalog.getLocale( 8 ) ) + 10;
3742   tw=5+t1+5+t2+5;
3743   if(tw>w) w=tw;
3744   Button *okb=(Button*)win->add(new Button(aguix,
3745                                              5,
3746                                              ty,
3747                                              t1,
3748                                              catalog.getLocale(11),
3749                                              0));
3750   Button *cancelb=(Button*)win->add(new Button(aguix,
3751                                                  w-5-t2,
3752                                                  ty,
3753                                                  t2,
3754                                                  catalog.getLocale(8),
3755                                                  0));
3756   h=okb->getY()+okb->getHeight()+5;
3757   win->setDoTabCycling( true );
3758   win->resize(w,h);
3759   win->setMaxSize(w,h);
3760   win->setMinSize(w,h);
3761   win->show();
3762   AGMessage *msg;
3763   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
3764   int ende=0;
3765   return_byte=ch;
3766   while(ende==0) {
3767     msg=aguix->WaitMessage(win);
3768     if(msg!=NULL) {
3769       if(msg->type==AG_CLOSEWINDOW) {
3770         if(msg->closewindow.window==win->getWindow()) ende=-1;
3771       } else if(msg->type==AG_BUTTONCLICKED) {
3772         if(msg->button.button==okb) ende=1;
3773         else if(msg->button.button==cancelb) ende=-1;
3774       } else if(msg->type==AG_STRINGGADGET_DEACTIVATE) {
3775         t1=-1;
3776         sscanf(sg->getText(),"%d",&t1);
3777         if(t1<0) t1=0;
3778         else if(t1>255) t1=255;
3779         sprintf(buf,"%d",t1);
3780         sg->setText(buf);
3781         sprintf(buf,"%c",t1);
3782         tt1->setText(buf);
3783         return_byte=t1;
3784       } else if(msg->type==AG_KEYPRESSED) {
3785         if(sg->isActive()==false) {
3786           t1=msg->key.key;
3787           if(t1<=0xff) {
3788             sprintf(buf,"%d",t1);
3789             sg->setText(buf);
3790             sprintf(buf,"%c",t1);
3791             tt1->setText(buf);
3792             return_byte=t1;
3793           }
3794         }
3795       }
3796       aguix->ReplyMessage(msg);
3797     }
3798   }
3799   delete win;
3800   return (ende==-1)?-1:return_byte;
3801 }
3802 
FTautocreate(WCFiletype * ft)3803 bool WConfig::FTautocreate(WCFiletype *ft)
3804 {
3805   AGUIX *aguix = worker->getAGUIX();
3806   int w, h;
3807   int i, e;
3808   char *str;
3809   AWindow *win;
3810   FileRequester *frq = new FileRequester( aguix );
3811   bool dirSet = false;
3812 
3813   w = 100;
3814   h = 10;
3815   win = new AWindow( aguix, 10, 10, w, h, catalog.getLocale( 100 ), AWindow::AWINDOW_DIALOG );
3816   win->create();
3817   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 4 ), true );
3818   ac1->setMinSpace( 5 );
3819   ac1->setMaxSpace( 5 );
3820 
3821   ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 614 ) ), 0, 0, AContainer::CO_INCWNR );
3822   FieldListView *lv = (FieldListView*)ac1->add( new FieldListView( aguix,
3823 								   0, 0,
3824 								   50, 150,
3825 								   0 ), 0, 1, AContainer::CO_MIN );
3826   lv->setHBarState( 2 );
3827   lv->setVBarState( 2 );
3828 
3829   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 2 );
3830   ac1_2->setMinSpace( 5 );
3831   ac1_2->setMaxSpace( 5 );
3832   ac1_2->setBorderWidth( 0 );
3833   Button *addb =(Button*)ac1_2->add( new Button( aguix,
3834 						 0,
3835 						 0,
3836 						 catalog.getLocale( 615 ),
3837 						 0 ), 0, 0, AContainer::CO_INCW );
3838   Button *delb = (Button*)ac1_2->add( new Button( aguix,
3839 						  0,
3840 						  0,
3841 						  catalog.getLocale( 616 ),
3842 						  0 ), 1, 0, AContainer::CO_INCW );
3843 
3844   AContainer *ac1_3 = ac1->add( new AContainer( win, 2, 1 ), 0, 3 );
3845   ac1_3->setMinSpace( 5 );
3846   ac1_3->setMaxSpace( -1 );
3847   ac1_3->setBorderWidth( 0 );
3848   Button *okb =(Button*)ac1_3->add( new Button( aguix,
3849                                                 0,
3850                                                 0,
3851                                                 catalog.getLocale( 11 ),
3852                                                 0 ), 0, 0, AContainer::CO_FIX );
3853   Button *cancelb = (Button*)ac1_3->add( new Button( aguix,
3854                                                      0,
3855                                                      0,
3856                                                      catalog.getLocale( 8 ),
3857                                                      0 ), 1, 0, AContainer::CO_FIX );
3858   win->setDoTabCycling( true );
3859   win->contMaximize( true );
3860   win->show();
3861 
3862   AGMessage *msg;
3863   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
3864   int ende=0;
3865   while(ende==0) {
3866     msg=aguix->WaitMessage(win);
3867     if(msg!=NULL) {
3868       if(msg->type==AG_CLOSEWINDOW) {
3869         if(msg->closewindow.window==win->getWindow()) ende=-1;
3870       } else if(msg->type==AG_BUTTONCLICKED) {
3871         if(msg->button.button==okb) ende=1;
3872         else if(msg->button.button==cancelb) ende=-1;
3873         else if ( msg->button.button == addb ) {
3874 	  if ( dirSet == false ) {
3875             str = NWC::Path::parentDir( WorkerInitialSettings::getInstance().getConfigBaseDir().c_str(), NULL );
3876 	    dirSet = true;
3877 	  } else {
3878 	    str = dupstring("");
3879 	  }
3880 	  if ( frq->request( catalog.getLocale( 265 ),
3881 			     str,
3882 			     catalog.getLocale( 11 ),
3883 			     catalog.getLocale( 8 ),
3884 			     catalog.getLocale( 266 ) ) != 0 ) {
3885 	    FileEntry *fe = frq->getFirstFE();
3886 	    while ( fe != NULL ) {
3887 	      int row = lv->addRow();
3888 	      lv->setText( row, 0, fe->fullname );
3889 	      lv->setPreColors( row, FieldListView::PRECOLOR_ONLYSELECT );
3890 	      lv->redraw();
3891 	      fe = frq->getNextFE();
3892 	    }
3893 	  }
3894 	  _freesafe(str);
3895 	} else if ( msg->button.button == delb ) {
3896 	  for ( i = 0; i < lv->getElements();) {
3897 	    if ( lv->getSelect( i ) == true ) {
3898 	      lv->deleteRow( i );
3899 	    } else i++;
3900 	  }
3901 	  lv->redraw();
3902 	}
3903       }
3904       aguix->ReplyMessage(msg);
3905     }
3906     if(ende==1) {
3907       // Pruefen, ob Dateien existieren
3908       e = 0;
3909       for ( i = 0; i < lv->getElements(); i++ ) {
3910 	if ( Datei::fileExists( lv->getText( 0, 0 ).c_str() ) == true ) e++;
3911       }
3912       if ( e < 3 ) {
3913 	ende = 0;
3914 	// Hinweis
3915 	Requester *req = new Requester( aguix );
3916 	req->request( catalog.getLocale( 124 ), catalog.getLocale( 267 ), catalog.getLocale( 11 ) );
3917 	delete req;
3918       }
3919     }
3920   }
3921   if(ende==1) {
3922     PDatei *fh;
3923     unsigned char buffer[64];
3924     short int filedesc[64];
3925 
3926     for ( i = 0; i < 64; i++ ) {
3927       filedesc[i] = -1;
3928     }
3929     int run = 1, f1;
3930     fh = new PDatei();
3931     for ( f1 = 0; f1 < lv->getElements(); f1++ ) {
3932       if ( fh->open( lv->getText( f1, 0 ).c_str() ) == 0 ) {
3933 	if ( fh->read( buffer, 64 ) == 64 ) {
3934 	  if ( run == 1 ) {
3935 	    for ( i = 0; i < 64; i++ ) {
3936 	      if ( buffer[i] > 0 ) filedesc[i] = buffer[i];
3937 	    }
3938 	  } else {
3939 	    for ( i = 0; i < 64; i++ ) {
3940 	      if ( ( filedesc[i] > 0 ) && ( filedesc[i] != buffer[i] ) ) filedesc[i] = -1;
3941 	    }
3942 	  }
3943 	  run++;
3944 	}
3945 	fh->close();
3946       }
3947     }
3948     delete fh;
3949     if ( run > 3 ) ft->setFiledesc( filedesc );
3950   }
3951   delete win;
3952   delete frq;
3953   return (ende==-1)?false:true;
3954 }
3955 
save()3956 bool WConfig::save()
3957 {
3958     bool ret;
3959     char *textstr;
3960     std::string home = WorkerInitialSettings::getInstance().getConfigBaseDir();
3961 
3962     if ( home.length() < 1 ) return false;
3963 
3964     std::string str1 = home;
3965 #ifdef USEOWNCONFIGFILES
3966     str1 = NWC::Path::join( str1, "wconfig2" );
3967 #else
3968     str1 = NWC::Path::join( str1, "config" );
3969 #endif
3970 
3971     if ( Datei::fileExistsExt( home.c_str() ) != Datei::D_FE_DIR ) {
3972         // no home dir, try to create one
3973         if ( worker_mkdir( home.c_str(), S_IRUSR | S_IXUSR | S_IWUSR ) != 0 ) {
3974             Requester *req = new Requester( worker->getAGUIX() );
3975             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 127 ) ) + strlen( home.c_str() ) + 1 );
3976             sprintf( textstr, catalog.getLocale( 127 ), home.c_str() );
3977             req->request( catalog.getLocale( 347 ), textstr, catalog.getLocale( 11 ) );
3978             _freesafe( textstr );
3979             delete req;
3980         }
3981     }
3982     ret = saveas( str1 );
3983 
3984     currentConfigTime = time( NULL );
3985     return ret;
3986 }
3987 
saveas(const std::string & file)3988 bool WConfig::saveas( const std::string &file )
3989 {
3990   int id;
3991   char *tstr;
3992   char buf[3 * A_BYTESFORNUMBER( int ) + 3 ];
3993   std::string str1;
3994   int i;
3995   unsigned int j;
3996   std::list<LayoutSettings::layoutID_t>::const_iterator it1;
3997   std::string backupfile;
3998 
3999   backupfile = file;
4000   backupfile += "-workerbak";
4001 
4002   if ( Datei::lfileExistsExt( file.c_str() ) == Datei::D_FE_FILE ) {
4003       if ( worker_rename( file.c_str(), backupfile.c_str() ) != 0 ) {
4004           Requester *req = Worker::getRequester();
4005           char *textstr;
4006 
4007           textstr = (char*)_allocsafe( strlen( catalog.getLocale( 40 ) ) + strlen( file.c_str() ) + 1 );
4008           sprintf( textstr, catalog.getLocale( 40 ), file.c_str() );
4009           req->request( catalog.getLocale( 347 ), textstr, catalog.getLocale( 11 ) );
4010           _freesafe( textstr );
4011           return false;
4012       }
4013   }
4014 
4015   Datei *fh = new Datei();
4016   if ( fh->open( file.c_str(), "w" ) == 0 ) {
4017     sprintf( buf, "%d.%d.%d", WORKER_MAJOR, WORKER_MINOR, WORKER_PATCH );
4018     str1 = "workerconfig ";
4019     str1 += buf;
4020     str1 += ";";
4021     fh->putLine( str1.c_str() );
4022     fh->configOpenSection( "global" );
4023     fh->configPutPairString( "lang", lang );
4024     fh->configPutPairNum( "rows", rows );
4025     fh->configPutPairNum( "columns", columns );
4026     fh->configPutPairNum( "cachesize", cachesize );
4027     fh->configOpenSection( "listersets" );
4028     fh->configOpenSection( "left" );
4029     fh->configPutPairBool( "hbartop", hbar_top[0] );
4030     fh->configPutPairNum( "hbarheight", hbar_height[0] );
4031     fh->configPutPairBool( "vbarleft", vbar_left[0] );
4032     fh->configPutPairNum( "vbarwidth", vbar_width[0] );
4033     fh->configPutPairBool( "showheader", showHeader[0] );
4034 
4035     if ( getPathEntryOnTop( 0 ) == true ) {
4036         fh->configPutPairBool( "pathentryontop", getPathEntryOnTop( 0 ) );
4037     }
4038 
4039     fh->configOpenSection( "displaysets" );
4040     for ( j = 0; j < viscols[0].size(); j++ ) {
4041       switch ( viscols[0][j] ) {
4042         case WorkerTypes::LISTCOL_SIZE:
4043           fh->configPutInfo( "size", true );
4044           break;
4045         case WorkerTypes::LISTCOL_TYPE:
4046           fh->configPutInfo( "type", true );
4047           break;
4048         case WorkerTypes::LISTCOL_PERM:
4049           fh->configPutInfo( "permission", true );
4050           break;
4051         case WorkerTypes::LISTCOL_OWNER:
4052           fh->configPutInfo( "owner", true );
4053           break;
4054         case WorkerTypes::LISTCOL_DEST:
4055           fh->configPutInfo( "destination", true );
4056           break;
4057         case WorkerTypes::LISTCOL_MOD:
4058           fh->configPutInfo( "modtime", true );
4059           break;
4060         case WorkerTypes::LISTCOL_ACC:
4061           fh->configPutInfo( "acctime", true );
4062           break;
4063         case WorkerTypes::LISTCOL_CHANGE:
4064           fh->configPutInfo( "chgtime", true );
4065           break;
4066         case WorkerTypes::LISTCOL_INODE:
4067           fh->configPutInfo( "inode", true );
4068           break;
4069         case WorkerTypes::LISTCOL_NLINK:
4070           fh->configPutInfo( "nlink", true );
4071           break;
4072         case WorkerTypes::LISTCOL_BLOCKS:
4073           fh->configPutInfo( "blocks", true );
4074           break;
4075         case WorkerTypes::LISTCOL_SIZEH:
4076           fh->configPutInfo( "sizeh", true );
4077           break;
4078         case WorkerTypes::LISTCOL_EXTENSION:
4079           fh->configPutInfo( "extension", true );
4080           break;
4081         default:
4082           fh->configPutInfo( "name", true );
4083           break;
4084       }
4085     }
4086     fh->configCloseSection(); //displaysets
4087     fh->configCloseSection(); //left
4088     fh->configOpenSection( "right" );
4089     fh->configPutPairBool( "hbartop", hbar_top[1] );
4090     fh->configPutPairNum( "hbarheight", hbar_height[1] );
4091     fh->configPutPairBool( "vbarleft", vbar_left[1] );
4092     fh->configPutPairNum( "vbarwidth", vbar_width[1] );
4093     fh->configPutPairBool( "showheader", showHeader[1] );
4094 
4095     if ( getPathEntryOnTop( 1 ) == true ) {
4096         fh->configPutPairBool( "pathentryontop", getPathEntryOnTop( 1 ) );
4097     }
4098 
4099     fh->configOpenSection( "displaysets" );
4100     for ( j = 0; j < viscols[1].size(); j++ ) {
4101       switch ( viscols[1][j] ) {
4102         case WorkerTypes::LISTCOL_SIZE:
4103           fh->configPutInfo( "size", true );
4104           break;
4105         case WorkerTypes::LISTCOL_TYPE:
4106           fh->configPutInfo( "type", true );
4107           break;
4108         case WorkerTypes::LISTCOL_PERM:
4109           fh->configPutInfo( "permission", true );
4110           break;
4111         case WorkerTypes::LISTCOL_OWNER:
4112           fh->configPutInfo( "owner", true );
4113           break;
4114         case WorkerTypes::LISTCOL_DEST:
4115           fh->configPutInfo( "destination", true );
4116           break;
4117         case WorkerTypes::LISTCOL_MOD:
4118           fh->configPutInfo( "modtime", true );
4119           break;
4120         case WorkerTypes::LISTCOL_ACC:
4121           fh->configPutInfo( "acctime", true );
4122           break;
4123         case WorkerTypes::LISTCOL_CHANGE:
4124           fh->configPutInfo( "chgtime", true );
4125           break;
4126         case WorkerTypes::LISTCOL_INODE:
4127           fh->configPutInfo( "inode", true );
4128           break;
4129         case WorkerTypes::LISTCOL_NLINK:
4130           fh->configPutInfo( "nlink", true );
4131           break;
4132         case WorkerTypes::LISTCOL_BLOCKS:
4133           fh->configPutInfo( "blocks", true );
4134           break;
4135         case WorkerTypes::LISTCOL_SIZEH:
4136           fh->configPutInfo( "sizeh", true );
4137           break;
4138         case WorkerTypes::LISTCOL_EXTENSION:
4139           fh->configPutInfo( "extension", true );
4140           break;
4141         default:
4142           fh->configPutInfo( "name", true );
4143           break;
4144       }
4145     }
4146     fh->configCloseSection();//displaysets
4147     fh->configCloseSection();//right
4148     fh->configCloseSection();//listersets
4149 
4150     fh->configPutPairString( "terminal", terminalbin );
4151     if ( getTerminalReturnsEarly() ) {
4152         fh->configPutPairBool( "terminalreturnsearly", true );
4153     }
4154 
4155     if ( ownerstringtype == 1 ) fh->configPutPair( "ownerstyle", "style2" );
4156     else fh->configPutPair( "ownerstyle", "style1" );
4157 
4158     fh->configPutPairBool( "usestringfordirsize", showStringForDirSize );
4159     //fh->configPutPairString( "stringfordirsize", stringForDirSize );
4160 
4161     fh->configOpenSection( "timesets" );
4162     if ( date_format == 1 ) fh->configPutPair( "date", "style2" );
4163     else if ( date_format == 2 ) fh->configPutPair( "date", "style3" );
4164     else if ( date_format == -1 ) fh->configPutPair( "date", "userstyle" );
4165     else fh->configPutPair( "date", "style1" );
4166     fh->configPutPairString( "datestring", date_formatstring );
4167     fh->configPutPairBool( "datesubstitution", date_subst );
4168     if ( time_format == 1 ) fh->configPutPair( "time", "style2" );
4169     else if ( time_format == -1 ) fh->configPutPair( "time", "userstyle" );
4170     else fh->configPutPair( "time", "style1" );
4171     fh->configPutPairString( "timestring", time_formatstring );
4172     fh->configPutPairBool( "datebeforetime", date_before_time );
4173     fh->configCloseSection(); //timesets
4174 
4175     fh->configOpenSection( "palette" );
4176     i = 0;
4177     id = colors->initEnum();
4178     WC_Color *col = (WC_Color*)colors->getFirstElement( id );
4179     while ( col != NULL ) {
4180       sprintf( buf, "%d", i );
4181       str1 = buf;
4182       str1 += " = ";
4183       sprintf( buf, "%d", col->getRed() );
4184       str1 += buf;
4185       str1 += ",";
4186       sprintf( buf, "%d", col->getGreen() );
4187       str1 += buf;
4188       str1 += ",";
4189       sprintf( buf, "%d", col->getBlue() );
4190       str1 += buf;
4191       str1 += ";";
4192       fh->configPutInfo( str1.c_str(), false );
4193       col = (WC_Color*)colors->getNextElement( id );
4194       i++;
4195     }
4196     colors->closeEnum( id );
4197     fh->configCloseSection(); //palette
4198 
4199     fh->configOpenSection( "layout" );
4200     fh->configPutPairBool( "buttonsvertical", m_layout_conf.getButtonVert() );
4201     fh->configPutPairBool( "listviewsvertical", m_layout_conf.getListViewVert() );
4202     fh->configPutPairNum( "listviewweight", m_layout_conf.getListViewWeight() );
4203     fh->configPutPairBool( "weighttoactive", m_layout_conf.getWeightRelToActive() );
4204     for ( it1 = m_layout_conf.getOrders().begin();
4205           it1 != m_layout_conf.getOrders().end();
4206           it1++ ) {
4207       switch ( *it1 ) {
4208         case LayoutSettings::LO_STATEBAR:
4209           fh->configPutInfo( "statebar", true );
4210           break;
4211         case LayoutSettings::LO_CLOCKBAR:
4212           fh->configPutInfo( "clockbar", true );
4213           break;
4214         case LayoutSettings::LO_BUTTONS:
4215           fh->configPutInfo( "buttons", true );
4216           break;
4217         case LayoutSettings::LO_LISTVIEWS:
4218           fh->configPutInfo( "listviews", true );
4219           break;
4220         case LayoutSettings::LO_BLL:
4221           fh->configPutInfo( "bll", true );
4222           break;
4223         case LayoutSettings::LO_LBL:
4224           fh->configPutInfo( "lbl", true );
4225           break;
4226         case LayoutSettings::LO_LLB:
4227           fh->configPutInfo( "llb", true );
4228           break;
4229         case LayoutSettings::LO_BL:
4230           fh->configPutInfo( "bl", true );
4231           break;
4232         case LayoutSettings::LO_LB:
4233           fh->configPutInfo( "lb", true );
4234           break;
4235         default:
4236           break;
4237       }
4238     }
4239     fh->configCloseSection(); //layout
4240 
4241     fh->configOpenSection( "mouseconf" );
4242     fh->configPutPairNum( "selectbutton", mouseConf.select_button );
4243     fh->configPutPairNum( "activatebutton", mouseConf.activate_button );
4244     fh->configPutPairNum( "scrollbutton", mouseConf.scroll_button );
4245 
4246     fh->configOpenSection( "activatemod" );
4247     switch ( mouseConf.activate_mod ) {
4248         case ShiftMask:
4249             fh->configPutPair( "mod", "shift" );
4250             break;
4251         case ControlMask:
4252             fh->configPutPair( "mod", "control" );
4253             break;
4254         case Mod1Mask:
4255             fh->configPutPair( "mod", "mod1" );
4256             break;
4257         default:
4258             break;
4259     }
4260     fh->configCloseSection(); //activatemod
4261 
4262     fh->configOpenSection( "scrollmod" );
4263     switch ( mouseConf.scroll_mod ) {
4264         case ShiftMask:
4265             fh->configPutPair( "mod", "shift" );
4266             break;
4267         case ControlMask:
4268             fh->configPutPair( "mod", "control" );
4269             break;
4270         case Mod1Mask:
4271             fh->configPutPair( "mod", "mod1" );
4272             break;
4273         default:
4274             break;
4275     }
4276     fh->configCloseSection(); //scrollmod
4277 
4278     fh->configOpenSection( "contextmod" );
4279     switch ( mouseConf.context_mod ) {
4280         case ShiftMask:
4281             fh->configPutPair( "mod", "shift" );
4282             break;
4283         case ControlMask:
4284             fh->configPutPair( "mod", "control" );
4285             break;
4286         case Mod1Mask:
4287             fh->configPutPair( "mod", "mod1" );
4288             break;
4289         default:
4290             break;
4291     }
4292     fh->configCloseSection(); //contextmod
4293 
4294     switch ( mouseConf.select_method ) {
4295       case MOUSECONF_ALT_MODE:
4296 	fh->configPutPair( "selectmethod", "alternative" );
4297 	break;
4298       default:
4299 	fh->configPutPair( "selectmethod", "normal" );
4300 	break;
4301     }
4302     fh->configCloseSection(); //mouseconf
4303 
4304     fh->configPutPairBool( "saveworkerstateonexit", m_save_worker_state_on_exit );
4305 
4306     fh->configOpenSection( "volumemanager" );
4307     fh->configPutPairString( "mountcommand", getVMMountCommand().c_str() );
4308     fh->configPutPairString( "unmountcommand", getVMUnmountCommand().c_str() );
4309     fh->configPutPairString( "fstabfile", getVMFStabFile().c_str() );
4310     fh->configPutPairString( "mtabfile", getVMMtabFile().c_str() );
4311     fh->configPutPairString( "partfile", getVMPartitionFile().c_str() );
4312     fh->configPutPairBool( "requestaction", getVMRequestAction() );
4313     fh->configPutPairString( "ejectcommand", getVMEjectCommand().c_str() );
4314     fh->configPutPairString( "closetraycommand", getVMCloseTrayCommand().c_str() );
4315 
4316     if ( getVMPreferredUdisksVersion() == 2 ) {
4317         fh->configPutPairNum( "prefer_udisks_version", getVMPreferredUdisksVersion() );
4318     }
4319 
4320     fh->configCloseSection(); //volumemanager
4321 
4322     if ( m_use_string_compare_mode == StringComparator::STRING_COMPARE_VERSION ) {
4323         fh->configPutPairBool( "useversionstringcompare", true );
4324     } else if ( m_use_string_compare_mode == StringComparator::STRING_COMPARE_NOCASE ) {
4325         fh->configPutPair( "usestringcomparemode", "strcasecmp" );
4326     } else {
4327         fh->configPutPairBool( "useversionstringcompare", false );
4328     }
4329 
4330     if ( m_use_extended_regex ) {
4331         fh->configPutPairBool( "useextendedregex", m_use_extended_regex );
4332     }
4333 
4334 #if 0
4335     if ( ! m_apply_window_dialog_type ) {
4336         fh->configPutPairBool( "applywindowdialogtype", m_apply_window_dialog_type );
4337     }
4338 #endif
4339 
4340     if ( ! getDisableBGCheckPrefix().empty() ) {
4341         fh->configPutPairString("disablebgcheckprefix", getDisableBGCheckPrefix().c_str() );
4342     }
4343 
4344     fh->configCloseSection();//global
4345 
4346     fh->configOpenSection( "colors" );
4347 
4348     fh->configOpenSection( "labelcolors" );
4349 
4350     std::map<std::string, WConfig::ColorDef::label_colors_t>::const_iterator label_it1;
4351     const std::map<std::string, WConfig::ColorDef::label_colors_t> &labelcolors = _color_defs.getLabelColors();
4352 
4353     for ( label_it1 = labelcolors.begin();
4354           label_it1 != labelcolors.end();
4355           ++label_it1 ) {
4356         fh->configOpenSection( "color" );
4357         fh->configPutPairString( "name", label_it1->first.c_str() );
4358         fh->configPutPairNum( "normal", label_it1->second.normal_fg, label_it1->second.normal_bg );
4359         fh->configPutPairNum( "active", label_it1->second.active_fg, label_it1->second.active_bg );
4360         fh->configCloseSection(); //labelcolor
4361     }
4362 
4363     fh->configCloseSection(); //labelcolors
4364 
4365     auto fl = m_facedb.getListOfFaces();
4366     FaceDB default_faces;
4367     bool non_default_face_found = false;
4368 
4369     fl.sort();
4370 
4371     for ( auto &face_name : fl ) {
4372         Face f = m_facedb.getFace( face_name );
4373         Face default_f = default_faces.getFace( face_name );
4374 
4375         if ( f.getName() != default_f.getName() ||
4376              f.getColor() != default_f.getColor() ) {
4377             non_default_face_found = true;
4378             break;
4379         }
4380     }
4381 
4382     if ( non_default_face_found ) {
4383         fh->configOpenSection( "faces" );
4384 
4385         for ( auto &face_name : fl ) {
4386             Face f = m_facedb.getFace( face_name );
4387             Face default_f = default_faces.getFace( face_name );
4388 
4389             if ( f.getName() != default_f.getName() ||
4390                  f.getColor() != default_f.getColor() ) {
4391                 fh->configOpenSection( "face" );
4392                 fh->configPutPairString( "name", f.getName().c_str() );
4393                 fh->configPutPairNum( "color", f.getColor() );
4394                 fh->configCloseSection(); //face
4395             }
4396         }
4397 
4398         fh->configCloseSection(); //faces
4399     }
4400 
4401     fh->configCloseSection(); //colors
4402 
4403     fh->configOpenSection( "startup" );
4404     fh->configPutPairString( "left", dir[0] );
4405     fh->configPutPairString( "right", dir[1] );
4406 
4407     switch ( m_restore_tabs_mode ) {
4408         case RESTORE_TABS_ALWAYS:
4409             fh->configPutPair( "restore_tabs_mode", "always" );
4410             break;
4411         case RESTORE_TABS_ASK:
4412             fh->configPutPair( "restore_tabs_mode", "ask" );
4413             break;
4414         default:
4415             break;
4416     }
4417 
4418     switch ( m_store_tabs_mode ) {
4419         case STORE_TABS_ALWAYS:
4420             fh->configPutPair( "store_tabs_mode", "always" );
4421             break;
4422         case STORE_TABS_AS_EXIT_STATE:
4423             fh->configPutPair( "store_tabs_mode", "as_exit_state" );
4424             break;
4425         case STORE_TABS_ASK:
4426             fh->configPutPair( "store_tabs_mode", "ask" );
4427             break;
4428         default:
4429             break;
4430     }
4431 
4432     fh->configCloseSection(); //startup
4433 
4434     fh->configOpenSection( "fonts" );
4435     fh->configPutPairString( "globalfont", getFontName( FONT_X11_GLOBAL ).c_str() );
4436     fh->configPutPairString( "buttonfont", getFontName( FONT_X11_BUTTONS ).c_str() );
4437     fh->configPutPairString( "leftfont", getFontName( FONT_X11_LEFT ).c_str() );
4438     fh->configPutPairString( "rightfont", getFontName( FONT_X11_RIGHT ).c_str() );
4439     fh->configPutPairString( "textviewfont", getFontName( FONT_X11_TEXTVIEW ).c_str() );
4440     fh->configPutPairString( "statebarfont", getFontName( FONT_X11_STATEBAR ).c_str() );
4441     fh->configCloseSection(); //fonts
4442 
4443 #ifdef HAVE_XFT
4444     fh->configOpenSection( "xftfonts" );
4445     fh->configPutPairString( "globalfont", getFontName( FONT_XFT_GLOBAL ).c_str() );
4446     fh->configPutPairString( "buttonfont", getFontName( FONT_XFT_BUTTONS ).c_str() );
4447     fh->configPutPairString( "leftfont", getFontName( FONT_XFT_LEFT ).c_str() );
4448     fh->configPutPairString( "rightfont", getFontName( FONT_XFT_RIGHT ).c_str() );
4449     fh->configPutPairString( "textviewfont", getFontName( FONT_XFT_TEXTVIEW ).c_str() );
4450     fh->configPutPairString( "statebarfont", getFontName( FONT_XFT_STATEBAR ).c_str() );
4451     fh->configCloseSection(); //xftfonts
4452 #endif
4453 
4454     fh->configOpenSection( "clockbarsets" );
4455     switch(clockbar_mode) {
4456       case CLOCKBAR_MODE_TIME:
4457         fh->configPutPair( "modus", "time" );
4458         break;
4459       case CLOCKBAR_MODE_VERSION:
4460         fh->configPutPair( "modus", "version" );
4461         break;
4462       case CLOCKBAR_MODE_EXTERN:
4463         fh->configPutPair( "modus", "extern" );
4464         break;
4465       default:
4466         fh->configPutPair( "modus", "timespace" );
4467         break;
4468     }
4469     fh->configPutPairNum( "updatetime", clockbar_updatetime );
4470     fh->configPutPairString( "program", clockbar_command );
4471     if ( getClockbarHints() != true ) {
4472         fh->configPutPairBool( "showhints", getClockbarHints() );
4473     }
4474     fh->configCloseSection(); //clockbarsets
4475 
4476     fh->configOpenSection( "pathjumpallowdirs" );
4477     for ( std::list< std::string >::const_iterator it2 = m_pathjump_allow_dirs.begin();
4478           it2 != m_pathjump_allow_dirs.end();
4479           it2++ ) {
4480         fh->configPutString( it2->c_str(), true );
4481     }
4482     fh->configCloseSection(); //pathjump_allow_dirs
4483 
4484     if ( getPathJumpStoreFilesAlways() == true ) {
4485         fh->configOpenSection( "pathjumpsets" );
4486         fh->configPutPairBool( "storefilesalways", getPathJumpStoreFilesAlways() );
4487         fh->configCloseSection(); //pathjumpsets
4488     }
4489 
4490     fh->configOpenSection( "paths" );
4491     i = 0;
4492     id = paths->initEnum();
4493     WCPath *p1 = (WCPath*)paths->getFirstElement( id );
4494     while ( p1 != NULL ) {
4495       if ( p1->getCheck() != false ) {
4496         fh->configOpenSection( "path" );
4497         fh->configPutPairNum( "position", i );
4498         p1->save( fh );
4499         fh->configCloseSection(); //path
4500       }
4501       p1 = (WCPath*)paths->getNextElement( id );
4502       i++;
4503     }
4504     paths->closeEnum( id );
4505     fh->configCloseSection(); //paths
4506 
4507     fh->configOpenSection( "hotkeys" );
4508     id = hotkeys->initEnum();
4509     WCHotkey *h1 = (WCHotkey*)hotkeys->getFirstElement( id );
4510     while(h1!=NULL) {
4511       fh->configOpenSection( "hotkey" );
4512       h1->save( fh );
4513       fh->configCloseSection(); //hotkey
4514       h1 = (WCHotkey*)hotkeys->getNextElement( id );
4515     }
4516     hotkeys->closeEnum( id );
4517     fh->configCloseSection(); //hotkeys
4518 
4519     fh->configOpenSection( "buttons" );
4520     i = 0;
4521     id = buttons->initEnum();
4522     WCButton *b1 = (WCButton*)buttons->getFirstElement( id );
4523     while ( b1 != NULL ) {
4524       if ( b1->getCheck() != false ) {
4525         fh->configOpenSection( "button" );
4526         fh->configPutPairNum( "position", i );
4527         b1->save( fh );
4528         fh->configCloseSection(); //button
4529       }
4530       b1 = (WCButton*)buttons->getNextElement( id );
4531       i++;
4532     }
4533     buttons->closeEnum( id );
4534     fh->configCloseSection(); //buttons
4535 
4536     fh->configOpenSection( "filetypes" );
4537     id = filetypes->initEnum();
4538     WCFiletype *f1 = (WCFiletype*)filetypes->getFirstElement( id );
4539     while ( f1 != NULL ) {
4540       fh->configOpenSection( "filetype" );
4541       f1->save( fh );
4542       fh->configCloseSection(); //filetype
4543       f1 = (WCFiletype*)filetypes->getNextElement( id );
4544     }
4545     filetypes->closeEnum( id );
4546 
4547     fh->configOpenSection( "ignoredirs" );
4548     id = dontcheckdirs->initEnum();
4549     tstr = (char*)dontcheckdirs->getFirstElement( id );
4550     while ( tstr != NULL ) {
4551       fh->configPutString( tstr, true );
4552       tstr = (char*)dontcheckdirs->getNextElement( id );
4553     }
4554     dontcheckdirs->closeEnum( id );
4555     fh->configCloseSection(); //ignoredirs
4556 
4557     fh->configPutPairBool( "dontcheckvirtual", dontcheckvirtual );
4558 
4559     fh->configCloseSection(); //filetypes
4560 
4561     if ( ! m_directory_presets.empty() ) {
4562         fh->configOpenSection( "directorypresets" );
4563 
4564         for ( auto &preset : m_directory_presets ) {
4565             fh->configOpenSection( "directorypreset" );
4566 
4567             fh->configPutPairString( "path", preset.first.c_str() );
4568 
4569             fh->configPutPair( "hiddenfiles" , ( preset.second.show_hidden == true ) ? "show" : "hide" );
4570 
4571             switch ( preset.second.sortmode & 0xff ) {
4572                 case SORT_SIZE:
4573                     fh->configPutPair( "sortby", "size" );
4574                     break;
4575                 case SORT_ACCTIME:
4576                     fh->configPutPair( "sortby", "acctime" );
4577                     break;
4578                 case SORT_MODTIME:
4579                     fh->configPutPair( "sortby", "modtime" );
4580                     break;
4581                 case SORT_CHGTIME:
4582                     fh->configPutPair( "sortby", "chgtime" );
4583                     break;
4584                 case SORT_TYPE:
4585                     fh->configPutPair( "sortby", "type" );
4586                     break;
4587                 case SORT_OWNER:
4588                     fh->configPutPair( "sortby", "owner" );
4589                     break;
4590                 case SORT_INODE:
4591                     fh->configPutPair( "sortby", "inode" );
4592                     break;
4593                 case SORT_NLINK:
4594                     fh->configPutPair( "sortby", "nlink" );
4595                     break;
4596                 case SORT_PERMISSION:
4597                     fh->configPutPair( "sortby", "permission" );
4598                     break;
4599                 case SORT_EXTENSION:
4600                     fh->configPutPair( "sortby", "extension" );
4601                     break;
4602                 default:
4603                     fh->configPutPair( "sortby", "name" );
4604                     break;
4605             }
4606             if ( ( preset.second.sortmode & SORT_REVERSE ) != 0 ) fh->configPutPair( "sortflag", "reverse" );
4607             if ( ( preset.second.sortmode & SORT_DIRLAST ) != 0 ) fh->configPutPair( "sortflag", "dirlast" );
4608             else if ( ( preset.second.sortmode & SORT_DIRMIXED ) != 0 ) fh->configPutPair( "sortflag", "dirmixed" );
4609 
4610             for ( auto &filter : preset.second.filters ) {
4611                 fh->configOpenSection( "filter" );
4612                 filter.save( fh );
4613                 fh->configCloseSection(); //filter
4614             }
4615 
4616             fh->configCloseSection(); // directorypreset
4617         }
4618         fh->configCloseSection(); // directorypresets
4619     }
4620 
4621     fh->close();
4622 
4623     if ( fh->errors() != 0 ) {
4624       Requester req( worker->getAGUIX() );
4625       char *textstr;
4626 
4627       textstr = (char*)_allocsafe( strlen( catalog.getLocale( 40 ) ) + strlen( file.c_str() ) + 1 );
4628       sprintf( textstr, catalog.getLocale( 40 ), file.c_str() );
4629       req.request( catalog.getLocale( 347 ), textstr, catalog.getLocale( 11 ) );
4630       _freesafe( textstr );
4631       delete fh;
4632       return false;
4633     }
4634     delete fh;
4635   } else {
4636     Requester *req=new Requester(worker->getAGUIX());
4637     char *textstr;
4638     textstr=(char*)_allocsafe(strlen(catalog.getLocale(40))+strlen(file.c_str())+1);
4639     sprintf(textstr,catalog.getLocale(40),file.c_str());
4640     req->request(catalog.getLocale(347),textstr,catalog.getLocale(11));
4641     _freesafe(textstr);
4642     delete req;
4643     delete fh;
4644     return false;
4645   }
4646   return true;
4647 }
4648 
load()4649 bool WConfig::load()
4650 {
4651     bool ret = false;
4652 
4653     std::string home = WorkerInitialSettings::getInstance().getConfigBaseDir();
4654 
4655     if ( home.length() < 1 ) return false;
4656 
4657     std::string str1 = home;
4658 #ifdef USEOWNCONFIGFILES
4659     str1 = NWC::Path::join( str1, "wconfig2" );
4660 #else
4661     str1 = NWC::Path::join( str1, "config" );
4662 #endif
4663 
4664     if ( Datei::lfileExistsExt( home.c_str() )== Datei::D_FE_NOFILE ) {
4665         const char *buttonstr;
4666         const char *textstr;
4667         Requester *req;
4668 
4669         buttonstr = catalog.getLocale( 11 );
4670         textstr = "There is no Worker configuration directory.|Worker will continue and use an internal configuration!";
4671         req = new Requester( worker->getAGUIX() );
4672         req->request( catalog.getLocale( 124 ), textstr, buttonstr );
4673         delete req;
4674     } else {
4675         ret = loadfrom( str1 );
4676 
4677         currentConfigTime = time( NULL );
4678     }
4679     return ret;
4680 }
4681 
loadfrom(const std::string & file)4682 bool WConfig::loadfrom( const std::string &file )
4683 {
4684   Datei *fh;
4685   char buf[5];
4686   FILE *fp;
4687   char *tstr;
4688 
4689   fh = new Datei();
4690   if ( fh->open( file.c_str(), "r" ) == 0 ) {
4691     fh->getString( buf, 4 );
4692     fh->close();
4693     delete fh;
4694     if ( strcmp( buf, "FORM" ) == 0 ) {
4695         // 2er binary config
4696         const char *buttonstr;
4697         const char *textstr;
4698 
4699         buttonstr = catalog.getLocale( 11 );
4700         textstr = "Your configuration is from an old Worker version.|To load it and convert it into the new format,|use Worker version 2.x.";
4701         Requester req( worker->getAGUIX() );
4702         req.request( catalog.getLocale( 124 ), textstr, buttonstr );
4703 
4704         return false;
4705     } else {
4706       // looks like new textconfig
4707       lconfig = this;
4708       fp = worker_fopen( file.c_str(), "r" );
4709       if ( fp != NULL ) {
4710         yyrestart( fp );
4711         if ( yymyparse() != 0 ) {
4712           // there was an error but after the requester I will
4713           // continue with the partly read config
4714           tstr = (char*)_allocsafe( strlen( catalog.getLocale( 539 ) ) +
4715                                     A_BYTESFORNUMBER(int) +
4716                                     strlen( lconfig_error ) + 1 );
4717           sprintf( tstr, catalog.getLocale( 539 ), lconfig_linenr + 1,
4718                    lconfig_error );
4719           Worker::getRequester()->request( catalog.getLocale( 347 ),
4720                                            tstr,
4721                                            catalog.getLocale( 11 ) );
4722           _freesafe( tstr );
4723         }
4724         applyColorList( colors );
4725         initFixTypes();
4726         worker_fclose( fp );
4727       }
4728     }
4729   }
4730   return false;
4731 }
4732 
initFixTypes()4733 void WConfig::initFixTypes()
4734 {
4735   WCFiletype *ft;
4736   // Pruefen, welche feste Type vorhanden sind (per Bitmaske)
4737   int id;
4738 
4739   notyettype = NULL;
4740   unknowntype = NULL;
4741   voidtype = NULL;
4742   dirtype = NULL;
4743 
4744   id = filetypes->initEnum();
4745   ft = (WCFiletype*)filetypes->getFirstElement( id );
4746   while ( ft != NULL ) {
4747     switch ( ft->getinternID() ) {
4748       case NOTYETTYPE:
4749         if ( notyettype != NULL ) {
4750           // there is already one special type, reset this
4751           ft->setinternID( NORMALTYPE );
4752         } else {
4753           notyettype = ft;
4754         }
4755         break;
4756       case UNKNOWNTYPE:
4757         if ( unknowntype != NULL ) {
4758           // there is already one special type, reset this
4759           ft->setinternID( NORMALTYPE );
4760         } else {
4761           unknowntype = ft;
4762         }
4763         break;
4764       case VOIDTYPE:
4765         if ( voidtype != NULL ) {
4766           // there is already one special type, reset this
4767           ft->setinternID( NORMALTYPE );
4768         } else {
4769           voidtype = ft;
4770         }
4771         break;
4772       case DIRTYPE:
4773         if ( dirtype != NULL ) {
4774           // there is already one special type, reset this
4775           ft->setinternID( NORMALTYPE );
4776         } else {
4777           dirtype = ft;
4778         }
4779         break;
4780     }
4781     ft = (WCFiletype*)filetypes->getNextElement( id );
4782   }
4783   filetypes->closeEnum( id );
4784 
4785   if ( notyettype == NULL ) {
4786     // NotYet voreinstellen
4787     debugmsg("Notyet erstellen\n"); //TODO: Diese Zeile entfernen
4788     ft=new WCFiletype();
4789     ft->setName(catalog.getLocale(344));
4790     ft->setinternID(NOTYETTYPE);
4791     // Reicht vorerst, denn irgendwelche Patterns oder so sind (im jetztigen Stadium des
4792     // Programms) nicht sinnvoll
4793     notyettype=ft;
4794     filetypes->addElementAt(NOTYETTYPE-1,ft);
4795   }
4796 
4797   if (  unknowntype == NULL ) {
4798     // Unknown voreinstellen
4799     debugmsg("Unknown erstellen\n"); //TODO: Diese Zeile entfernen
4800     ft=new WCFiletype();
4801     ft->setName(catalog.getLocale(345));
4802     ft->setinternID(UNKNOWNTYPE);
4803     unknowntype = ft;
4804     filetypes->addElementAt(UNKNOWNTYPE-1,ft);
4805   }
4806 
4807   if ( voidtype == NULL ) {
4808     // Void voreinstellen (der wird nie im Lister angezeigt)
4809     debugmsg("void erstellen\n"); //TODO: Diese Zeile entfernen
4810     ft=new WCFiletype();
4811     ft->setName(catalog.getLocale(346));
4812     ft->setinternID(VOIDTYPE);
4813     voidtype = ft;
4814     filetypes->addElementAt(VOIDTYPE-1,ft);
4815   }
4816 
4817   if ( dirtype == NULL ) {
4818     // Dir voreinstellen
4819     debugmsg("dir erstellen\n"); //TODO: Diese Zeile entfernen
4820     ft=new WCFiletype();
4821     ft->setName(catalog.getLocale(109));
4822     ft->setinternID(DIRTYPE);
4823     dirtype=ft;
4824     filetypes->addElementAt(DIRTYPE-1,ft);
4825   }
4826 }
4827 
getnotyettype()4828 WCFiletype *WConfig::getnotyettype()
4829 {
4830   return notyettype;
4831 }
4832 
getdirtype()4833 WCFiletype *WConfig::getdirtype()
4834 {
4835   return dirtype;
4836 }
4837 
getvoidtype()4838 WCFiletype *WConfig::getvoidtype()
4839 {
4840   return voidtype;
4841 }
4842 
getunknowntype()4843 WCFiletype *WConfig::getunknowntype()
4844 {
4845   return unknowntype;
4846 }
4847 
applyLanguage()4848 void WConfig::applyLanguage()
4849 {
4850   if((strcmp(lang,"builtin")==0)||(strlen(lang)<1)) catalog.resetLanguage();
4851   else catalog.loadLanguage(lang);
4852 }
4853 
setOwnerstringtype(int nv)4854 void WConfig::setOwnerstringtype(int nv)
4855 {
4856   ownerstringtype=nv;
4857   if(ownerstringtype<0) ownerstringtype=0;
4858   else if(ownerstringtype>1) ownerstringtype=1;
4859 }
4860 
getOwnerstringtype()4861 int WConfig::getOwnerstringtype()
4862 {
4863   return ownerstringtype;
4864 }
4865 
isCorrectTerminalBin(const char * tstr)4866 bool WConfig::isCorrectTerminalBin(const char *tstr)
4867 {
4868   const char *pos;
4869   if(strlen(tstr)<1) return true;
4870   pos=strstr(tstr,"%s");
4871   if(pos!=NULL) return true;
4872   return false;
4873 }
4874 
getTerminalStr()4875 const char *WConfig::getTerminalStr()
4876 {
4877   if(strlen(terminalbin)<1) return TERMINAL_BIN;
4878   else if(isCorrectTerminalBin(terminalbin)==false) return TERMINAL_BIN;
4879   return terminalbin;
4880 }
4881 
setClockbarMode(WConfig::clockbar_mode_t nm)4882 void WConfig::setClockbarMode(WConfig::clockbar_mode_t nm)
4883 {
4884   clockbar_mode=nm;
4885 }
4886 
getClockbarMode()4887 WConfig::clockbar_mode_t WConfig::getClockbarMode()
4888 {
4889   return clockbar_mode;
4890 }
4891 
setClockbarUpdatetime(int nv)4892 void WConfig::setClockbarUpdatetime(int nv)
4893 {
4894   clockbar_updatetime=nv;
4895   if(clockbar_updatetime<1) clockbar_updatetime=1;
4896 }
4897 
getClockbarUpdatetime()4898 int WConfig::getClockbarUpdatetime()
4899 {
4900   return clockbar_updatetime;
4901 }
4902 
setClockbarHints(bool nv)4903 void WConfig::setClockbarHints( bool nv )
4904 {
4905     m_clockbar_hints = nv;
4906 }
4907 
getClockbarHints()4908 bool WConfig::getClockbarHints()
4909 {
4910     return m_clockbar_hints;
4911 }
4912 
setShowStringForDirSize(bool nv)4913 void WConfig::setShowStringForDirSize(bool nv)
4914 {
4915   showStringForDirSize=nv;
4916 }
4917 
getShowStringForDirSize()4918 bool WConfig::getShowStringForDirSize()
4919 {
4920   return showStringForDirSize;
4921 }
4922 
setStringForDirSize(const char * nv)4923 void WConfig::setStringForDirSize(const char *nv)
4924 {
4925   _freesafe(stringForDirSize);
4926   if(nv!=NULL) stringForDirSize=dupstring(nv);
4927   else stringForDirSize=dupstring("<DIR>");
4928   stringForDirSizeLen=strlen(stringForDirSize);
4929 }
4930 
getStringForDirSize()4931 const char *WConfig::getStringForDirSize()
4932 {
4933   return stringForDirSize;
4934 }
4935 
setClockbarCommand(const char * nv)4936 void WConfig::setClockbarCommand(const char *nv)
4937 {
4938   _freesafe(clockbar_command);
4939   if(nv!=NULL) clockbar_command=dupstring(nv);
4940   else clockbar_command=dupstring("");
4941 }
4942 
getClockbarCommand()4943 const char *WConfig::getClockbarCommand()
4944 {
4945   return clockbar_command;
4946 }
4947 
setDontCheckDirs(List * ndcd)4948 void WConfig::setDontCheckDirs(List *ndcd)
4949 {
4950   char *tstr;
4951   int id=dontcheckdirs->initEnum();
4952   tstr=(char*)dontcheckdirs->getFirstElement(id);
4953   while(tstr!=NULL) {
4954     _freesafe(tstr);
4955     tstr=(char*)dontcheckdirs->getNextElement(id);
4956   }
4957   dontcheckdirs->closeEnum(id);
4958   dontcheckdirs->removeAllElements();
4959   id=ndcd->initEnum();
4960   tstr=(char*)ndcd->getFirstElement(id);
4961   while(tstr!=NULL) {
4962     dontcheckdirs->addElement(dupstring(tstr));
4963     tstr=(char*)ndcd->getNextElement(id);
4964   }
4965   ndcd->closeEnum(id);
4966 }
4967 
getDontCheckDirs()4968 List *WConfig::getDontCheckDirs()
4969 {
4970   return dontcheckdirs;
4971 }
4972 
setDontCheckVirtual(bool nv)4973 void WConfig::setDontCheckVirtual( bool nv )
4974 {
4975   dontcheckvirtual = nv;
4976 }
4977 
getDontCheckVirtual() const4978 bool WConfig::getDontCheckVirtual() const
4979 {
4980   return dontcheckvirtual;
4981 }
4982 
getStringForDirSizeLen()4983 int WConfig::getStringForDirSizeLen()
4984 {
4985   return stringForDirSizeLen;
4986 }
4987 
cfg_export(const char * filename)4988 int WConfig::cfg_export( const char *filename )
4989 {
4990   AWindow *win;
4991   AGUIX *aguix = worker->getAGUIX();
4992   int ende;
4993   AGMessage *msg;
4994   ChooseButton *cb[3];
4995   Button *b[3], *b2[2];
4996   WConfig *exportconfig;
4997   std::string str1;
4998   Requester *req;
4999 
5000   win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 398 ), AWindow::AWINDOW_DIALOG );
5001   win->create();
5002 
5003   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 3 ), true );
5004   ac1->setMinSpace( 5 );
5005   ac1->setMaxSpace( 5 );
5006   ac1->setBorderWidth( 5 );
5007 
5008   win->addMultiLineText( catalog.getLocale( 399 ), *ac1, 0, 0, NULL, NULL );
5009 
5010   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 3 ), 0, 1 );
5011   ac1_2->setMinSpace( 5 );
5012   ac1_2->setMaxSpace( 5 );
5013   ac1_2->setBorderWidth( 0 );
5014 
5015   cb[0] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, false, "", LABEL_RIGHT, 0 ),
5016                                      0, 0, AContainer::CO_FIX );
5017   b[0] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 401 ), 0 ),
5018                               1, 0, AContainer::CO_FIX );
5019 
5020   cb[1] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, false, "", LABEL_RIGHT, 0 ),
5021                                      0, 1, AContainer::CO_FIX );
5022   b[1] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 402 ), 0 ),
5023                               1, 1, AContainer::CO_FIX );
5024 
5025   cb[2] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, false, "", LABEL_RIGHT, 0 ),
5026                                      0, 2, AContainer::CO_FIX );
5027   b[2] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 403 ), 0 ),
5028                               1, 2, AContainer::CO_FIX );
5029 
5030   AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 2 );
5031   ac1_1->setMinSpace( 5 );
5032   ac1_1->setMaxSpace( -1 );
5033   ac1_1->setBorderWidth( 0 );
5034   b2[0] =(Button*)ac1_1->add( new Button( aguix,
5035                                           0,
5036                                           0,
5037                                           catalog.getLocale( 398 ),
5038                                           0 ), 0, 0, AContainer::CO_FIX );
5039   b2[1] = (Button*)ac1_1->add( new Button( aguix,
5040                                            0,
5041                                            0,
5042                                            catalog.getLocale( 8 ),
5043                                            0 ), 1, 0, AContainer::CO_FIX );
5044   win->setDoTabCycling( true );
5045   win->contMaximize( true, true );
5046   win->show();
5047 
5048   exportconfig = duplicate();
5049 
5050   req = new Requester( aguix );
5051 
5052   ende = 0;
5053   while ( ende == 0 ) {
5054     msg = aguix->WaitMessage( win );
5055     if ( msg != NULL ) {
5056       if ( msg->type == AG_CLOSEWINDOW ) {
5057         if ( msg->closewindow.window == win->getWindow() )
5058           ende = -1;
5059       } else if ( msg->type == AG_BUTTONCLICKED ) {
5060         if ( msg->button.button == b2[0] ) {
5061           // Okay
5062           ende = 1;
5063         } else if ( msg->button.button == b2[1] ) {
5064           // Cancel
5065           ende = -1;
5066         } else if ( msg->button.button == b[0] ) {
5067           exportconfig->changeButtons();
5068         } else if ( msg->button.button == b[1] ) {
5069           exportconfig->changeHotkeys();
5070         } else if ( msg->button.button == b[2] ) {
5071           exportconfig->changeTypes( true );
5072         }
5073       }
5074 
5075       aguix->ReplyMessage( msg );
5076     }
5077     if ( ende == 1 ) {
5078       // try to export
5079       // in case of failure keep this window so we do this
5080       // inside the loop
5081       // export the exportconfig according to choosebuttons
5082 
5083       if ( cb[0]->getState() == true ||
5084            cb[1]->getState() == true ||
5085            cb[2]->getState() == true ) {
5086         // something to export
5087         // when export failed set ende back to 0
5088 
5089         if ( exportconfig->export2file( cb[0]->getState(),
5090                                         cb[1]->getState(),
5091                                         cb[2]->getState(),
5092                                         filename ) != 0 ) {
5093           ende = 0;
5094         }
5095       } else {
5096         req->request( catalog.getLocale( 124 ), catalog.getLocale( 407 ),
5097                       catalog.getLocale( 11 ) );
5098         ende = 0;
5099       }
5100     }
5101   }
5102 
5103   delete win;
5104 
5105   delete exportconfig;
5106   delete req;
5107 
5108   return ( ende == -1 ) ? 1 : 0;
5109 }
5110 
export2file(bool export_buttons,bool export_hotkeys,bool export_types,const char * filename)5111 int WConfig::export2file( bool export_buttons,
5112                           bool export_hotkeys,
5113                           bool export_types,
5114                           const char *filename )
5115 {
5116   Datei fh;
5117   Datei::d_fe_t e;
5118   int erg, ret;
5119   Requester req( worker->getAGUIX() );
5120   char *tstr;
5121   std::string s1;
5122   int id;
5123   WCButton *b1;
5124   WCHotkey *h1;
5125   WCFiletype *f1;
5126   char buf[3 * A_BYTESFORNUMBER( int ) + 3 ];
5127   std::string str1;
5128   int i;
5129 
5130   ret = 0;
5131 
5132   if ( filename == NULL ) return 1;
5133 
5134   e = Datei::fileExistsExt( filename );
5135   if ( e != Datei::D_FE_NOFILE ) {
5136     // something exists with this name!
5137     if ( e == Datei::D_FE_DIR ) {
5138       // dir -> show request and exit
5139       tstr = (char*)_allocsafe( strlen( catalog.getLocale( 408 ) ) + strlen( filename ) + 1 );
5140       sprintf( tstr, catalog.getLocale( 408 ), filename );
5141       req.request( catalog.getLocale( 124 ), tstr, catalog.getLocale( 11 ) );
5142       _freesafe( tstr );
5143       return 1;
5144     }
5145     // ask for overwriting this file
5146     // otherwise return
5147     tstr = (char*)_allocsafe( strlen( catalog.getLocale( 409 ) ) + strlen( filename ) + 1 );
5148     sprintf( tstr, catalog.getLocale( 409 ), filename );
5149     s1 = catalog.getLocale( 11 );
5150     s1 += "|";
5151     s1 += catalog.getLocale( 8 );
5152     erg = req.request( catalog.getLocale( 123 ), tstr, s1.c_str() );
5153     _freesafe( tstr );
5154 
5155     if ( erg == 1 )
5156       return 1;
5157 
5158   }
5159 
5160   if ( fh.open( filename, "w" ) == 0 ) {
5161     sprintf( buf, "%d.%d.%d", WORKER_MAJOR, WORKER_MINOR, WORKER_PATCH );
5162     str1 = "workerconfig ";
5163     str1 += buf;
5164     str1 += ";";
5165     fh.putLine( str1.c_str() );
5166 
5167     if ( export_buttons == true ) {
5168       fh.configOpenSection( "buttons" );
5169       i = 0;
5170       id = buttons->initEnum();
5171       b1 = (WCButton*)buttons->getFirstElement( id );
5172       while ( b1 != NULL ) {
5173         if ( b1->getCheck() != false ) {
5174           fh.configOpenSection( "button" );
5175           fh.configPutPairNum( "position", i );
5176           b1->save( &fh );
5177           fh.configCloseSection(); //button
5178         }
5179         b1 = (WCButton*)buttons->getNextElement( id );
5180         i++;
5181       }
5182       buttons->closeEnum( id );
5183 
5184       fh.configCloseSection(); //buttons
5185     }
5186 
5187     if ( export_hotkeys == true ) {
5188       fh.configOpenSection( "hotkeys" );
5189       id = hotkeys->initEnum();
5190       h1 = (WCHotkey*)hotkeys->getFirstElement( id );
5191       while ( h1 != NULL ) {
5192         fh.configOpenSection( "hotkey" );
5193         h1->save( &fh );
5194         fh.configCloseSection(); //hotkey
5195         h1 = (WCHotkey*)hotkeys->getNextElement( id );
5196       }
5197       hotkeys->closeEnum( id );
5198       fh.configCloseSection(); //hotkeys
5199     }
5200 
5201     if ( export_types == true ) {
5202       fh.configOpenSection( "filetypes" );
5203       id = filetypes->initEnum();
5204       f1 = (WCFiletype*)filetypes->getFirstElement( id );
5205       while ( f1 != NULL ) {
5206         fh.configOpenSection( "filetype" );
5207         f1->save( &fh );
5208         fh.configCloseSection(); //filetype
5209         f1 = (WCFiletype*)filetypes->getNextElement( id );
5210       }
5211       filetypes->closeEnum( id );
5212       fh.configCloseSection(); //filetypes
5213     }
5214 
5215     fh.close();
5216 
5217     if ( fh.errors() == 0 ) {
5218       tstr = (char*)_allocsafe( strlen( catalog.getLocale( 410 ) ) + strlen( filename ) + 1 );
5219       sprintf( tstr, catalog.getLocale( 410 ), filename );
5220       req.request( catalog.getLocale( 124 ), tstr, catalog.getLocale( 11 ) );
5221       _freesafe( tstr );
5222     } else {
5223       tstr = (char*)_allocsafe( strlen( catalog.getLocale( 359 ) ) + strlen( filename ) + 1 );
5224       sprintf( tstr, catalog.getLocale( 359 ), filename );
5225       req.request( catalog.getLocale( 124 ), tstr, catalog.getLocale( 11 ) );
5226       _freesafe( tstr );
5227       ret = 1;
5228     }
5229   } else {
5230     tstr = (char*)_allocsafe( strlen( catalog.getLocale( 411 ) ) + strlen( filename ) + 1 );
5231     sprintf( tstr, catalog.getLocale( 411 ), filename );
5232     req.request( catalog.getLocale( 124 ), tstr, catalog.getLocale( 11 ) );
5233     _freesafe( tstr );
5234     ret = 1;
5235   }
5236 
5237   return ret;
5238 }
5239 
5240 /*
5241  * loads the file in a temp. config and calls configureForImport with it
5242  */
loadImportConfig(const char * filename,bool & import_buttons,bool & import_hotkeys,bool & import_filetypes,const std::string & info_text,WConfig ** return_config)5243 int WConfig::loadImportConfig( const char *filename,
5244                                bool &import_buttons,
5245                                bool &import_hotkeys,
5246                                bool &import_filetypes,
5247                                const std::string &info_text,
5248                                WConfig **return_config )
5249 {
5250   AGUIX *aguix = worker->getAGUIX();
5251   WConfig *importconfig = NULL;
5252   Requester req( aguix );
5253   Datei fh;
5254   char buf[5];
5255   int erg = 0;
5256   List *bl;
5257   char *tstr;
5258   FILE *fp;
5259 
5260   // first try to load the config
5261   if ( Datei::fileExistsExt( filename ) == Datei::D_FE_FILE ) {
5262     if ( fh.open( filename, "r" ) == 0 ) {
5263       importconfig = duplicate();
5264 
5265       fh.getString( buf, 4 );
5266       if ( strcmp( buf, "FORM" ) == 0 ) {
5267           req.request( catalog.getLocale( 124 ),
5268                        "Loading old binary configs not supported, use a Worker version 2.x",
5269                        catalog.getLocale( 11 ) );
5270       } else {
5271         lconfig = importconfig;
5272         bl = new List();
5273         lconfig->setButtons( bl );
5274         lconfig->setHotkeys( bl );
5275         lconfig->setFiletypes( bl );
5276         delete bl;
5277         fp = worker_fopen( filename, "r" );
5278         if ( fp != NULL ) {
5279           yyrestart( fp );
5280           if ( yymyparse() != 0 ) {
5281             // there was an error but after the requester I will
5282             // continue with the partly read config
5283             tstr = (char*)_allocsafe( strlen( catalog.getLocale( 539 ) ) +
5284                                       A_BYTESFORNUMBER(int) +
5285                                       strlen( lconfig_error ) + 1 );
5286             sprintf( tstr, catalog.getLocale( 539 ), lconfig_linenr + 1,
5287                      lconfig_error );
5288             Worker::getRequester()->request( catalog.getLocale( 347 ),
5289                                              tstr,
5290                                              catalog.getLocale( 11 ) );
5291             _freesafe( tstr );
5292           } else {
5293             // config load successful
5294             // now let the user decide...
5295             erg = importconfig->configureForImport( 1,
5296                                                     import_buttons,
5297                                                     import_hotkeys,
5298                                                     import_filetypes,
5299                                                     info_text );
5300           }
5301           worker_fclose( fp );
5302         } else {
5303           // can't open for reading
5304           tstr = (char*)_allocsafe( strlen( catalog.getLocale( 281 ) ) + strlen( filename ) + 1 );
5305           sprintf( tstr, catalog.getLocale( 281 ), filename );
5306           req.request( catalog.getLocale( 124 ),
5307                        tstr,
5308                        catalog.getLocale( 11 ) );
5309           _freesafe( tstr );
5310           erg = 1;
5311         }
5312       }
5313       fh.close();
5314     } else {
5315       // can't open for reading
5316       tstr = (char*)_allocsafe( strlen( catalog.getLocale( 281 ) ) + strlen( filename ) + 1 );
5317       sprintf( tstr, catalog.getLocale( 281 ), filename );
5318       req.request( catalog.getLocale( 124 ),
5319                    tstr,
5320                    catalog.getLocale( 11 ) );
5321       _freesafe( tstr );
5322       erg = 1;
5323     }
5324   } else {
5325     // not a file
5326     tstr = (char*)_allocsafe( strlen( catalog.getLocale( 412 ) ) + strlen( filename ) + 1 );
5327     sprintf( tstr, catalog.getLocale( 412 ), filename );
5328     req.request( catalog.getLocale( 124 ),
5329                  tstr,
5330                  catalog.getLocale( 11 ) );
5331     _freesafe( tstr );
5332     erg = 1;
5333   }
5334 
5335   if ( return_config != NULL )
5336     *return_config = importconfig;
5337   else
5338     delete importconfig;
5339 
5340   return erg;
5341 }
5342 
5343 /*
5344  * show the users a similar window to export
5345  * user can choose which part (buttons/hotkeys/filetypes) he want to import
5346  * and can configure them before import
5347  */
configureForImport(int nrb,bool & import_buttons,bool & import_hotkeys,bool & import_filetypes,const std::string & info_text)5348 int WConfig::configureForImport( int nrb,
5349                                  bool &import_buttons,
5350                                  bool &import_hotkeys,
5351                                  bool &import_filetypes,
5352                                  const std::string &info_text )
5353 {
5354   AWindow *win;
5355   AGUIX *aguix = Worker::getAGUIX();
5356   int ende;
5357   AGMessage *msg;
5358   ChooseButton *cb[3];
5359   Button *b[3],*b2[2];
5360   Requester req( aguix );
5361   int nr_of_b, nr_of_h, nr_of_f;
5362   char *tstr;
5363   bool apply_b = false, apply_h = false, apply_f = false;
5364   List *l1;
5365   WCButton *b1;
5366   int id, i, banksize;
5367 
5368   if ( nrb < 1 ) {
5369     nr_of_b = 0;
5370   } else {
5371     l1 = getButtons();
5372     nr_of_b = 0;
5373     i = 0;
5374     id = l1->initEnum();
5375     b1 = (WCButton*)l1->getFirstElement( id );
5376     while ( b1 != NULL ) {
5377       if ( b1->getCheck() == true ) {
5378         nr_of_b = i + 1;
5379       }
5380       b1 = (WCButton*)l1->getNextElement( id );
5381       i++;
5382     }
5383     l1->closeEnum( id );
5384     banksize = ( getRows() * getColumns() * 2 );
5385     nr_of_b += ( banksize - ( nr_of_b % banksize ) ) % banksize;
5386     nr_of_b /= banksize;
5387   }
5388 
5389   nr_of_h = getHotkeys()->size();
5390   nr_of_f = getFiletypes()->size();
5391 
5392   if ( ( nr_of_b == 0 ) && ( nr_of_h == 0 ) && ( nr_of_f == 0 ) ) {
5393     req.request( catalog.getLocale( 124 ), catalog.getLocale( 418 ), catalog.getLocale( 11 ) );
5394     return 1;
5395   }
5396 
5397   tstr = (char*)_allocsafe( info_text.length() + ( 3 * A_BYTESFORNUMBER( int ) ) + 1 );
5398   sprintf( tstr, info_text.c_str(), nr_of_b, nr_of_h, nr_of_f );
5399   req.request( catalog.getLocale( 124 ),
5400                tstr,
5401                catalog.getLocale( 11 ) );
5402   _freesafe( tstr );
5403 
5404   win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 397 ), AWindow::AWINDOW_DIALOG );
5405   win->create();
5406 
5407   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 3 ), true );
5408   ac1->setMinSpace( 5 );
5409   ac1->setMaxSpace( 5 );
5410   ac1->setBorderWidth( 5 );
5411 
5412   win->addMultiLineText( catalog.getLocale( 416 ), *ac1, 0, 0, NULL, NULL );
5413 
5414   int cont_h = 0, cont_pos = 0;
5415   if ( nr_of_b > 0 )
5416     cont_h++;
5417   if ( nr_of_h > 0 )
5418     cont_h++;
5419   if ( nr_of_f > 0 )
5420     cont_h++;
5421 
5422   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, cont_h ), 0, 1 );
5423   ac1_2->setMinSpace( 5 );
5424   ac1_2->setMaxSpace( 5 );
5425   ac1_2->setBorderWidth( 0 );
5426 
5427   if ( nr_of_b > 0 ) {
5428     cb[0] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, true, "", LABEL_RIGHT, 0 ),
5429                                        0, cont_pos, AContainer::CO_FIX );
5430     b[0] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 540 ), 0 ),
5431                                 1, cont_pos, AContainer::CO_FIX );
5432     cont_pos++;
5433   } else {
5434     cb[0] = NULL;
5435     b[0] = NULL;
5436   }
5437 
5438   if ( nr_of_h > 0 ) {
5439     cb[1] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, true, "", LABEL_RIGHT, 0 ),
5440                                        0, cont_pos, AContainer::CO_FIX );
5441     b[1] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 541 ), 0 ),
5442                                 1, cont_pos, AContainer::CO_FIX );
5443     cont_pos++;
5444   } else {
5445     cb[1] = NULL;
5446     b[1] = NULL;
5447   }
5448 
5449   if ( nr_of_f > 0 ) {
5450     cb[2] = (ChooseButton*)ac1_2->add( new ChooseButton( aguix, 0, 0, true, "", LABEL_RIGHT, 0 ),
5451                                        0, cont_pos, AContainer::CO_FIX );
5452     b[2] = (Button*)ac1_2->add( new Button( aguix, 0, 0, catalog.getLocale( 542 ), 0 ),
5453                                 1, cont_pos, AContainer::CO_FIX );
5454     cont_pos++;
5455   } else {
5456     cb[2] = NULL;
5457     b[2] = NULL;
5458   }
5459 
5460   AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 2 );
5461   ac1_1->setMinSpace( 5 );
5462   ac1_1->setMaxSpace( -1 );
5463   ac1_1->setBorderWidth( 0 );
5464   b2[0] =(Button*)ac1_1->add( new Button( aguix,
5465                                           0,
5466                                           0,
5467                                           catalog.getLocale( 397 ),
5468                                           0 ), 0, 0, AContainer::CO_FIX );
5469   b2[1] = (Button*)ac1_1->add( new Button( aguix,
5470                                            0,
5471                                            0,
5472                                            catalog.getLocale( 8 ),
5473                                            0 ), 1, 0, AContainer::CO_FIX );
5474 
5475   win->setDoTabCycling( true );
5476   win->contMaximize( true, true );
5477   win->show();
5478 
5479   ende = 0;
5480   while ( ende == 0 ) {
5481     msg = aguix->WaitMessage( win );
5482     if ( msg != NULL ) {
5483       if ( msg->type == AG_CLOSEWINDOW ) {
5484         if ( msg->closewindow.window == win->getWindow() )
5485           ende = -1;
5486       } else if ( msg->type == AG_BUTTONCLICKED ) {
5487         if ( msg->button.button == b2[0] ) {
5488           // Okay
5489           ende = 1;
5490         } else if ( msg->button.button == b2[1] ) {
5491           // Cancel
5492           ende = -1;
5493         } else if ( ( msg->button.button == b[0] ) && ( b[0] != NULL ) ) {
5494           changeButtons();
5495         } else if ( ( msg->button.button == b[1] ) && ( b[1] != NULL ) )  {
5496           changeHotkeys();
5497         } else if ( ( msg->button.button == b[2] ) && ( b[2] != NULL ) )  {
5498           changeTypes( true );
5499         }
5500       } else if ( msg->type == AG_STRINGGADGET_DEACTIVATE ) {
5501       }
5502 
5503       aguix->ReplyMessage( msg );
5504     }
5505     if ( ende == 1 ) {
5506       // now try to import
5507       // in case of failure keep this window so we do this
5508       // inside the loop
5509 
5510       if ( cb[0] != NULL ) {
5511         apply_b = cb[0]->getState();
5512       } else apply_b = false;
5513 
5514       if ( cb[1] != NULL ) {
5515         apply_h = cb[1]->getState();
5516       } else apply_h = false;
5517 
5518       if ( cb[2] != NULL ) {
5519         apply_f = cb[2]->getState();
5520       } else apply_f = false;
5521 
5522       if ( apply_b == false &&
5523            apply_h == false &&
5524            apply_f == false ) {
5525         req.request( catalog.getLocale( 124 ), catalog.getLocale( 417 ),
5526                       catalog.getLocale( 11 ) );
5527         ende = 0;
5528       }
5529     }
5530   }
5531 
5532   delete win;
5533 
5534   if ( ende == 1 ) {
5535     import_buttons = apply_b;
5536     import_hotkeys = apply_h;
5537     import_filetypes = apply_f;
5538   }
5539 
5540   return ( ende == -1 ) ? 1 : 0;
5541 }
5542 
setDateFormat(int nv)5543 void WConfig::setDateFormat( int nv )
5544 {
5545   date_format = nv;
5546   if ( date_format < -1 ) date_format = 0;
5547 }
5548 
getDateFormat()5549 int WConfig::getDateFormat()
5550 {
5551   return date_format;
5552 }
5553 
setDateFormatString(const char * nv)5554 void WConfig::setDateFormatString( const char *nv )
5555 {
5556   _freesafe( date_formatstring );
5557   if ( nv == NULL ) {
5558     date_formatstring = dupstring( DEFAULT_DATE_STRING );
5559   } else {
5560     date_formatstring = dupstring( nv );
5561   }
5562 }
5563 
getDateFormatString()5564 const char *WConfig::getDateFormatString()
5565 {
5566   return date_formatstring;
5567 }
5568 
setDateSubst(bool nv)5569 void WConfig::setDateSubst( bool nv )
5570 {
5571   date_subst = nv;
5572 }
5573 
getDateSubst()5574 bool WConfig::getDateSubst()
5575 {
5576   return date_subst;
5577 }
5578 
setTimeFormat(int nv)5579 void WConfig::setTimeFormat( int nv )
5580 {
5581   time_format = nv;
5582   if ( time_format < -1 ) time_format = 0;
5583 }
5584 
getTimeFormat()5585 int WConfig::getTimeFormat()
5586 {
5587   return time_format;
5588 }
5589 
setTimeFormatString(const char * nv)5590 void WConfig::setTimeFormatString( const char *nv )
5591 {
5592   _freesafe( time_formatstring );
5593   if ( nv == NULL ) {
5594     time_formatstring = dupstring( DEFAULT_TIME_STRING );
5595   } else {
5596     time_formatstring = dupstring( nv );
5597   }
5598 }
5599 
getTimeFormatString()5600 const char *WConfig::getTimeFormatString()
5601 {
5602   return time_formatstring;
5603 }
5604 
setDateBeforeTime(bool nv)5605 void WConfig::setDateBeforeTime( bool nv )
5606 {
5607   date_before_time = nv;
5608 }
5609 
getDateBeforeTime()5610 bool WConfig::getDateBeforeTime()
5611 {
5612   return date_before_time;
5613 }
5614 
writeDateToString(std::string & str,struct tm * tptr)5615 int WConfig::writeDateToString( std::string &str, struct tm *tptr )
5616 {
5617     const char *tformat, *dformat;
5618     int i, nr_of_predates, nr_of_pretimes;
5619     time_t now;
5620     struct tm *timeptr, todaytime, yesterdaytime, tomorrowtime, curtime;
5621     bool istoday = false, isyesterday = false, istomorrow = false;
5622     char date_buf[256], time_buf[256];
5623     struct tm temptm;
5624 
5625     if ( tptr == NULL ) return 0;
5626 
5627     curtime = *tptr;
5628 
5629     now = time( NULL );
5630     timeptr = localtime_r( &now, &temptm );
5631     todaytime = *timeptr;
5632 
5633     now -= 24*60*60;  // this is yesterday
5634     timeptr = localtime_r( &now, &temptm );
5635     yesterdaytime = *timeptr;
5636 
5637     now += 2*24*60*60; // this is tomorrow
5638     timeptr = localtime_r( &now, &temptm );
5639     tomorrowtime = *timeptr;
5640 
5641     if ( curtime.tm_mday == todaytime.tm_mday &&
5642          curtime.tm_mon == todaytime.tm_mon &&
5643          curtime.tm_year == todaytime.tm_year ) {
5644         istoday = true;
5645     } else if ( curtime.tm_mday == yesterdaytime.tm_mday &&
5646                 curtime.tm_mon == yesterdaytime.tm_mon &&
5647                 curtime.tm_year == yesterdaytime.tm_year ) {
5648         isyesterday = true;
5649     } else if ( curtime.tm_mday == tomorrowtime.tm_mday &&
5650                 curtime.tm_mon == tomorrowtime.tm_mon &&
5651                 curtime.tm_year == tomorrowtime.tm_year ) {
5652         istomorrow = true;
5653     }
5654 
5655     nr_of_predates = sizeof( predefined_dates ) / sizeof( predefined_dates[0] );
5656     nr_of_pretimes = sizeof( predefined_times ) / sizeof( predefined_times[0] );
5657 
5658     if ( date_format == -1 ) {
5659         dformat = date_formatstring;
5660     } else {
5661         i = 0;
5662         if ( date_format >= 0 && date_format < nr_of_predates ) {
5663             i = date_format;
5664         }
5665         dformat = predefined_dates[i];
5666     }
5667 
5668     if ( strftime( date_buf, 255, dformat, &curtime ) == 0 ) {
5669         date_buf[0] = '\0';
5670     }
5671 
5672     int time_characters = UTF8::getNumberOfCharacters( date_buf );
5673     int max_time_characters = time_characters;
5674     int yesterday_chars = 0, today_chars = 0, tomorrow_chars = 0;
5675 
5676     if ( date_subst == true ) {
5677         yesterday_chars = UTF8::getNumberOfCharacters( catalog.getLocale( 436 ) );
5678         if ( yesterday_chars > max_time_characters ) max_time_characters = yesterday_chars;
5679 
5680         today_chars = UTF8::getNumberOfCharacters( catalog.getLocale( 437 ) );
5681         if ( today_chars > max_time_characters ) max_time_characters = today_chars;
5682 
5683         tomorrow_chars = UTF8::getNumberOfCharacters( catalog.getLocale( 438 ) );
5684         if ( tomorrow_chars > max_time_characters ) max_time_characters = tomorrow_chars;
5685     }
5686 
5687     if ( time_format == -1 ) {
5688         tformat = time_formatstring;
5689     } else {
5690         i = 0;
5691         if ( time_format >= 0 && time_format < nr_of_pretimes ) {
5692             i = time_format;
5693         }
5694         tformat = predefined_times[i];
5695     }
5696 
5697     if ( strftime( time_buf, 255, tformat, &curtime ) == 0 ) {
5698         time_buf[0] = '\0';
5699     }
5700 
5701     for ( i = 0; i < 2; i++ ) {
5702         if ( ( date_before_time == true && i == 0 ) ||
5703              ( date_before_time == false && i == 1 ) ) {
5704             if ( date_subst == true && istoday == true ) {
5705                 str += catalog.getLocale( 437 );
5706 
5707                 str += std::string( max_time_characters - today_chars, ' ' );
5708             } else if ( date_subst == true && isyesterday == true ) {
5709                 str += catalog.getLocale( 436 );
5710 
5711                 str += std::string( max_time_characters - yesterday_chars, ' ' );
5712             } else if ( date_subst == true && istomorrow == true ) {
5713                 str += catalog.getLocale( 438 );
5714 
5715                 str += std::string( max_time_characters - tomorrow_chars, ' ' );
5716             } else {
5717                 str += date_buf;
5718             }
5719         } else {
5720             str += time_buf;
5721         }
5722         if ( i == 0 ) str += ' ';
5723     }
5724 
5725     return 1;
5726 }
5727 
5728 /*
5729  * just grabs a key without checking for other uses
5730  *
5731  * returns:
5732  *   0 no error
5733  *  -1 error
5734  */
grabKey(const char * title,const char * text,KeySym * return_key,unsigned int * return_mod)5735 int WConfig::grabKey( const char *title, const char *text, KeySym *return_key, unsigned int *return_mod )
5736 {
5737   AGUIX *aguix = worker->getAGUIX();
5738   int w, h;
5739   int returnvalue = -1;
5740 
5741   if ( ( title == NULL ) || ( text == NULL ) || ( return_key == NULL ) || ( return_mod == NULL ) ) return -1;
5742 
5743   w = 10;
5744   h = 10;
5745   AWindow *win = new AWindow( aguix, 10, 10, w, h, title, AWindow::AWINDOW_DIALOG );
5746   win->create();
5747   win->addTextFromString( text, 5, 5, 5, NULL, NULL, NULL );
5748   win->maximizeX();
5749   win->maximizeY();
5750   win->centerScreen();
5751   w = win->getWidth();
5752   h = win->getHeight();
5753   win->setMaxSize( w, h );
5754   win->setMinSize( w, h );
5755   win->show();
5756   AGMessage *msg;
5757   while ( ( msg = aguix->GetMessage( NULL ) ) != NULL ) aguix->ReplyMessage( msg );
5758   int ende = 0;
5759 
5760   while ( ende == 0 ) {
5761     msg = aguix->WaitMessage( win );
5762     if ( msg != NULL ) {
5763       if ( msg->type == AG_CLOSEWINDOW ) {
5764         if ( msg->closewindow.window == win->getWindow() ) ende = -1;
5765       } else if ( msg->type == AG_KEYPRESSED ) {
5766         if ( AGUIX::isModifier( msg->key.key ) == false ) {
5767           *return_key = msg->key.key;
5768           *return_mod = KEYSTATEMASK( msg->key.keystate );
5769           returnvalue = 0;
5770           ende = 1;
5771         }
5772       }
5773       aguix->ReplyMessage( msg );
5774     }
5775   }
5776   delete win;
5777 
5778   if ( ende < 0 ) returnvalue = -1;
5779   return returnvalue;
5780 }
5781 
5782 /*
5783  * getDoubleShortkey
5784  * Returnvalue:
5785  * -1 Cancel, null in return_dk
5786  * 0 Okay, no collision, DoubleShortkey in return_dk
5787  * 1 Okay, collision with ignore_?, null in return_dk
5788  * 2 Okay, collision with some other, DoubleShortkey in return_dk
5789  */
getDoubleShortkey(bool doublek,const WCButton * ignore_b,const WCHotkey * ignore_h,const WCPath * ignore_p,WCDoubleShortkey ** return_dk)5790 int WConfig::getDoubleShortkey( bool doublek,
5791                                 const WCButton *ignore_b,
5792                                 const WCHotkey *ignore_h,
5793                                 const WCPath *ignore_p,
5794                                 WCDoubleShortkey **return_dk)
5795 {
5796   WCDoubleShortkey *tsk = NULL;
5797   AGUIX *aguix = worker->getAGUIX();
5798   WCButton *b1;
5799   WCPath *p1;
5800   WCHotkey *h1;
5801   char *textstr, *buttonstr;
5802   Requester *req = new Requester( aguix );
5803   int erg;
5804   int returnvalue = -1;
5805   KeySym key1 = 0, key2 = 0;
5806   unsigned int mod1 = 0, mod2 = 0;
5807 
5808   tsk = new WCDoubleShortkey();
5809   int ende = 0;
5810   while ( ende == 0 ) {
5811     if ( doublek == true ) {
5812       erg = grabKey( catalog.getLocale( 66 ), catalog.getLocale( 455 ), &key1, &mod1 );
5813       if ( erg == 0 ) {
5814         erg = grabKey( catalog.getLocale( 66 ), catalog.getLocale( 456 ), &key2, &mod2 );
5815       }
5816       if ( erg == 0 ) {
5817       } else {
5818         // user aborted
5819         ende = -1;
5820       }
5821     } else {
5822       erg = grabKey( catalog.getLocale( 66 ), catalog.getLocale( 66 ), &key1, &mod1 );
5823       if ( erg != 0 ) ende = -1;
5824     }
5825     if ( ende == 0 ) {
5826       tsk->setType( doublek == true ? WCDoubleShortkey::WCDS_DOUBLE : WCDoubleShortkey::WCDS_NORMAL );
5827       tsk->setKeySym( key1, 0 );
5828       tsk->setMod( mod1, 0 );
5829       if ( doublek == true ) {
5830         tsk->setKeySym( key2, 1 );
5831         tsk->setMod( mod2, 1 );
5832       }
5833       // search for other reference
5834       if ( findDoubleShortkey( tsk, getButtons(), getPaths(), getHotkeys(), &b1, &p1, &h1 ) != 0 ) {
5835         if ( b1 != NULL ) {
5836           if ( b1 == ignore_b ) {
5837             returnvalue = 1;
5838             ende = 1;
5839           } else {
5840             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 42 ) ) + strlen( b1->getText() ) + 1 );
5841             sprintf( textstr, catalog.getLocale( 42 ), b1->getText() );
5842             buttonstr = (char*)_allocsafe( strlen( catalog.getLocale( 41 ) ) + 1 +
5843                                            strlen( catalog.getLocale( 11 ) ) + 1 +
5844                                            strlen( catalog.getLocale( 8 ) ) + 1 );
5845             sprintf( buttonstr, "%s|%s|%s", catalog.getLocale( 41 ),
5846                                             catalog.getLocale( 11 ),
5847                                             catalog.getLocale( 8 ) );
5848             erg = req->request( catalog.getLocale( 125 ), textstr, buttonstr );
5849             _freesafe( textstr );
5850             _freesafe( buttonstr );
5851             if ( erg == 2 ) ende = -1;
5852             else if ( erg == 1 ) {
5853               returnvalue = 2;
5854               ende = 1;
5855             }
5856           }
5857         } else if ( p1 != NULL ) {
5858           if ( p1 == ignore_p ) {
5859             returnvalue = 1;
5860             ende = 1;
5861           } else {
5862             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 63 ) ) + strlen( p1->getName() ) + 1 );
5863             sprintf( textstr, catalog.getLocale( 63 ), p1->getName() );
5864             buttonstr = (char*)_allocsafe( strlen( catalog.getLocale( 41 ) ) + 1 +
5865                                            strlen( catalog.getLocale( 11 ) ) + 1 +
5866                                            strlen( catalog.getLocale( 8 ) ) + 1 );
5867             sprintf( buttonstr, "%s|%s|%s", catalog.getLocale( 41 ),
5868                                             catalog.getLocale( 11 ),
5869                                             catalog.getLocale( 8 ) );
5870             erg = req->request( catalog.getLocale( 125 ), textstr, buttonstr );
5871             _freesafe( textstr );
5872             _freesafe( buttonstr );
5873             if ( erg == 2 ) ende = -1;
5874             else if ( erg == 1 ) {
5875               returnvalue = 2;
5876               ende = 1;
5877             }
5878           }
5879         } else if ( h1 != NULL ) {
5880           if ( h1 == ignore_h ) {
5881             returnvalue = 1;
5882             ende = 1;
5883           } else {
5884             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 65 ) ) + strlen( h1->getName() ) + 1 );
5885             sprintf( textstr, catalog.getLocale( 65 ), h1->getName() );
5886             buttonstr = (char*)_allocsafe( strlen( catalog.getLocale( 41 ) ) + 1 +
5887                                            strlen( catalog.getLocale( 11 ) ) + 1 +
5888                                            strlen( catalog.getLocale( 8 ) ) + 1 );
5889             sprintf( buttonstr, "%s|%s|%s", catalog.getLocale( 41 ),
5890                                             catalog.getLocale( 11 ),
5891                                             catalog.getLocale( 8 ) );
5892             erg = req->request( catalog.getLocale( 125 ), textstr, buttonstr );
5893             _freesafe( textstr );
5894             _freesafe( buttonstr );
5895             if ( erg == 2 ) ende = -1;
5896             else if ( erg == 1 ) {
5897               returnvalue = 2;
5898               ende = 1;
5899             }
5900           }
5901         }
5902       } else {
5903         returnvalue = 0;
5904         ende = 1;
5905       }
5906     }
5907   }
5908   delete req;
5909 
5910   if ( ende < 0 ) returnvalue = -1;
5911   if( ( ( returnvalue == 2 ) ||
5912         ( returnvalue == 0 ) ) &&
5913       ( return_dk != NULL ) ) {
5914     *return_dk = tsk;
5915   } else {
5916     if ( return_dk != NULL )
5917       *return_dk = NULL;
5918     if ( tsk != NULL )
5919       delete tsk;
5920   }
5921   return returnvalue;
5922 }
5923 
findDoubleShortkey(WCDoubleShortkey * dk,List * button_list,List * path_list,List * hotkey_list,WCButton ** return_button,WCPath ** return_path,WCHotkey ** return_hotkey)5924 int WConfig::findDoubleShortkey( WCDoubleShortkey *dk,
5925                                  List *button_list,
5926                                  List *path_list,
5927                                  List *hotkey_list,
5928                                  WCButton **return_button,
5929                                  WCPath **return_path,
5930                                  WCHotkey **return_hotkey )
5931 {
5932   int id;
5933   WCHotkey *h1 = NULL;
5934   WCButton *b1 = NULL;
5935   WCPath *p1 = NULL;
5936 
5937   if ( hotkey_list != NULL ) {
5938     // search for a hotkey
5939     id = hotkey_list->initEnum();
5940     h1 = (WCHotkey*)hotkey_list->getFirstElement( id );
5941     while ( h1 != NULL ) {
5942       if ( h1->conflictKey( dk ) == true )
5943         break;
5944       h1 = (WCHotkey*)hotkey_list->getNextElement( id );
5945     }
5946     hotkey_list->closeEnum( id );
5947     if ( h1 != NULL ) {
5948       *return_button = NULL;
5949       *return_path = NULL;
5950       *return_hotkey = h1;
5951       return 1;
5952     }
5953   }
5954 
5955   if ( path_list != NULL ) {
5956     // search for a path
5957     id = path_list->initEnum();
5958     p1 = (WCPath*)path_list->getFirstElement( id );
5959     while ( p1 != NULL ) {
5960       if ( p1->conflictKey( dk ) == true )
5961         break;
5962       p1 = (WCPath*)path_list->getNextElement( id );
5963     }
5964     path_list->closeEnum( id );
5965     if ( p1 != NULL ) {
5966       *return_button = NULL;
5967       *return_path = p1;
5968       *return_hotkey = NULL;
5969       return 2;
5970     }
5971   }
5972 
5973   if ( button_list != NULL ) {
5974     // search for a button
5975     id = button_list->initEnum();
5976     b1 = (WCButton*)button_list->getFirstElement( id );
5977     while ( b1 != NULL ) {
5978       if ( b1->conflictKey( dk ) == true )
5979         break;
5980       b1 = (WCButton*)button_list->getNextElement( id );
5981     }
5982     button_list->closeEnum( id );
5983     if ( b1 != NULL ) {
5984       *return_button = b1;
5985       *return_path = NULL;
5986       *return_hotkey = NULL;
5987       return 3;
5988     }
5989   }
5990 
5991   *return_button = NULL;
5992   *return_path = NULL;
5993   *return_hotkey = NULL;
5994   return 0;
5995 }
5996 
checkForNewerConfig()5997 bool WConfig::checkForNewerConfig()
5998 {
5999   if ( difftime( getFileConfigMod(), currentConfigTime ) > 0 ) return true;
6000   return false;
6001 }
6002 
getFileConfigMod()6003 time_t WConfig::getFileConfigMod()
6004 {
6005   worker_struct_stat buf;
6006   std::string str1;
6007 
6008   str1 = WorkerInitialSettings::getInstance().getConfigBaseDir();
6009 #ifdef USEOWNCONFIGFILES
6010   str1 = NWC::Path::join( str1, "wconfig2" );
6011 #else
6012   str1 = NWC::Path::join( str1, "config" );
6013 #endif
6014   if ( worker_stat( str1.c_str(), &buf ) == 0 ) {
6015     return buf.st_mtime;
6016   }
6017   return 0;
6018 }
6019 
setShowHeader(int side,bool nv)6020 void WConfig::setShowHeader( int side, bool nv )
6021 {
6022   if ( ( side < 0 ) || ( side > 1 ) ) return;
6023   showHeader[side] = nv;
6024 }
6025 
getShowHeader(int side) const6026 bool WConfig::getShowHeader( int side ) const
6027 {
6028   return showHeader[ ( side == 1 ) ? 1 : 0 ];
6029 }
6030 
setPathEntryOnTop(int side,bool nv)6031 void WConfig::setPathEntryOnTop( int side, bool nv )
6032 {
6033     if ( side < 0 || side > 1 ) return;
6034     m_path_entry_on_top[side] = nv;
6035 }
6036 
getPathEntryOnTop(int side) const6037 bool WConfig::getPathEntryOnTop( int side ) const
6038 {
6039     return m_path_entry_on_top[ ( side == 1 ) ? 1 : 0 ];
6040 }
6041 
setLayoutOrders(const std::list<LayoutSettings::layoutID_t> & nl)6042 void WConfig::setLayoutOrders( const std::list< LayoutSettings::layoutID_t > &nl )
6043 {
6044     m_layout_conf.setOrders( nl );
6045 }
6046 
getLayoutOrders() const6047 const std::list<LayoutSettings::layoutID_t> &WConfig::getLayoutOrders() const
6048 {
6049     return m_layout_conf.getOrders();
6050 }
6051 
setLayoutButtonVert(bool nv)6052 void WConfig::setLayoutButtonVert( bool nv )
6053 {
6054     m_layout_conf.setButtonVert( nv );
6055 }
6056 
getLayoutButtonVert() const6057 bool WConfig::getLayoutButtonVert() const
6058 {
6059     return m_layout_conf.getButtonVert();
6060 }
6061 
setLayoutListviewVert(bool nv)6062 void WConfig::setLayoutListviewVert( bool nv )
6063 {
6064     m_layout_conf.setListViewVert( nv );
6065 }
6066 
getLayoutListviewVert() const6067 bool WConfig::getLayoutListviewVert() const
6068 {
6069     return m_layout_conf.getListViewVert();
6070 }
6071 
clearLayoutOrders()6072 void WConfig::clearLayoutOrders()
6073 {
6074     m_layout_conf.clearOrders();
6075 }
6076 
layoutAddEntry(LayoutSettings::layoutID_t nv)6077 void WConfig::layoutAddEntry( LayoutSettings::layoutID_t nv )
6078 {
6079     m_layout_conf.pushBackOrder( nv );
6080 }
6081 
setLayoutListViewWeight(int nv)6082 void WConfig::setLayoutListViewWeight( int nv )
6083 {
6084     m_layout_conf.setListViewWeight( nv );
6085 }
6086 
getLayoutListViewWeight() const6087 int WConfig::getLayoutListViewWeight() const
6088 {
6089     return m_layout_conf.getListViewWeight();
6090 }
6091 
setLayoutWeightRelToActive(bool nv)6092 void WConfig::setLayoutWeightRelToActive( bool nv )
6093 {
6094     m_layout_conf.setWeightRelToActive( nv );
6095 }
6096 
getLayoutWeightRelToActive() const6097 bool WConfig::getLayoutWeightRelToActive() const
6098 {
6099     return m_layout_conf.getWeightRelToActive();
6100 }
6101 
getFlatTypeList()6102 FlatTypeList *WConfig::getFlatTypeList()
6103 {
6104     return new FlatTypeList( filetypes, "" );
6105 }
6106 
setMouseSelectButton(int nv)6107 void WConfig::setMouseSelectButton( int nv )
6108 {
6109   switch ( nv ) {
6110     case 2:
6111     case 3:
6112       mouseConf.select_button = nv;
6113       break;
6114     default:
6115       mouseConf.select_button = 1;
6116   }
6117 }
6118 
setMouseActivateButton(int nv)6119 void WConfig::setMouseActivateButton( int nv )
6120 {
6121   switch ( nv ) {
6122     case 2:
6123     case 3:
6124       mouseConf.activate_button = nv;
6125       break;
6126     default:
6127       mouseConf.activate_button = 1;
6128   }
6129 }
6130 
setMouseScrollButton(int nv)6131 void WConfig::setMouseScrollButton( int nv )
6132 {
6133   switch ( nv ) {
6134     case 2:
6135     case 3:
6136       mouseConf.scroll_button = nv;
6137       break;
6138     default:
6139       mouseConf.scroll_button = 1;
6140   }
6141 }
6142 
setMouseContextButton(int nv)6143 void WConfig::setMouseContextButton( int nv )
6144 {
6145   switch ( nv ) {
6146     case 2:
6147     case 3:
6148       mouseConf.context_button = nv;
6149       break;
6150     default:
6151       mouseConf.context_button = 1;
6152   }
6153 }
6154 
setMouseSelectMethod(mouseconf_method_t nv)6155 void WConfig::setMouseSelectMethod( mouseconf_method_t nv )
6156 {
6157   mouseConf.select_method = nv;
6158 }
6159 
getMouseSelectButton() const6160 int WConfig::getMouseSelectButton() const
6161 {
6162   return mouseConf.select_button;
6163 }
6164 
getMouseActivateButton() const6165 int WConfig::getMouseActivateButton() const
6166 {
6167   return mouseConf.activate_button;
6168 }
6169 
getMouseScrollButton() const6170 int WConfig::getMouseScrollButton() const
6171 {
6172   return mouseConf.scroll_button;
6173 }
6174 
getMouseContextButton() const6175 int WConfig::getMouseContextButton() const
6176 {
6177   return mouseConf.context_button;
6178 }
6179 
getMouseSelectMethod() const6180 WConfig::mouseconf_method_t WConfig::getMouseSelectMethod() const
6181 {
6182   return mouseConf.select_method;
6183 }
6184 
setMouseActivateMod(int nv)6185 void WConfig::setMouseActivateMod( int nv )
6186 {
6187     switch( nv ) {
6188         case ShiftMask:
6189         case ControlMask:
6190         case Mod1Mask:
6191             mouseConf.activate_mod = nv;
6192             break;
6193         default:
6194             mouseConf.activate_mod = 0;
6195             break;
6196     }
6197 }
6198 
setMouseScrollMod(int nv)6199 void WConfig::setMouseScrollMod( int nv )
6200 {
6201     switch( nv ) {
6202         case ShiftMask:
6203         case ControlMask:
6204         case Mod1Mask:
6205             mouseConf.scroll_mod = nv;
6206             break;
6207         default:
6208             mouseConf.scroll_mod = 0;
6209             break;
6210     }
6211 }
6212 
setMouseContextMod(int nv)6213 void WConfig::setMouseContextMod( int nv )
6214 {
6215     switch( nv ) {
6216         case ShiftMask:
6217         case ControlMask:
6218         case Mod1Mask:
6219             mouseConf.context_mod = nv;
6220             break;
6221         default:
6222             mouseConf.context_mod = 0;
6223             break;
6224     }
6225 }
6226 
getMouseActivateMod() const6227 int WConfig::getMouseActivateMod() const
6228 {
6229     return mouseConf.activate_mod;
6230 }
6231 
getMouseScrollMod() const6232 int WConfig::getMouseScrollMod() const
6233 {
6234     return mouseConf.scroll_mod;
6235 }
6236 
getMouseContextMod() const6237 int WConfig::getMouseContextMod() const
6238 {
6239     return mouseConf.context_mod;
6240 }
6241 
6242 typedef enum { NONE, LANG, PALETTE, FONTCONF, MOUSECONF, STARTCONF, LISTCONF, VIEWCONF, TIMECONF,
6243                COLORCONF, BUTTON, PATH, FILETYPE, HOTKEY, CLOCKCONF, DCDCONF, UICOLORS, BUTTONGRPCONF,
6244                CACHECONF, OWNERCONF, TERMCONF, DIRSIZECONF, LAYOUTCONF, IMEXPORT, MAINUICONF,
6245                EXPERTUICONF, GENERALCONF, BOOKMARKCOLORS, VOLMANCONF, PATHJUMPALLOWCONF,
6246                DIRECTORYPRESETSCONF } type_t;
6247 
6248 typedef struct {
6249   std::string key;
6250   std::string base_key;
6251   type_t type;
6252   WConfigPanel *subwin;
6253   int level;
6254 } lv_key_type_t;
6255 
6256 class MyWConfigPanelCallBack : public WConfigPanelCallBack
6257 {
6258 public:
MyWConfigPanelCallBack(lv_key_type_t * lv_lookup_table,int table_size)6259   MyWConfigPanelCallBack( lv_key_type_t *lv_lookup_table, int table_size ) : _lv_lookup_table( lv_lookup_table ),
6260                                                                              _table_size( table_size )
6261   {
6262   }
~MyWConfigPanelCallBack()6263   ~MyWConfigPanelCallBack()
6264   {
6265   }
setColors(List * colors)6266   void setColors( List *colors )
6267   {
6268     for ( int i = 0; i < _table_size; i++ ) {
6269       if ( _lv_lookup_table[i].subwin != NULL ) {
6270         _lv_lookup_table[i].subwin->setColors( colors );
6271       }
6272     }
6273   }
setRows(int rows)6274   void setRows( int rows )
6275   {
6276     for ( int i = 0; i < _table_size; i++ ) {
6277       if ( _lv_lookup_table[i].subwin != NULL ) {
6278         _lv_lookup_table[i].subwin->setRows( rows );
6279       }
6280     }
6281   }
setColumns(int columns)6282   void setColumns( int columns )
6283   {
6284     for ( int i = 0; i < _table_size; i++ ) {
6285       if ( _lv_lookup_table[i].subwin != NULL ) {
6286         _lv_lookup_table[i].subwin->setColumns( columns );
6287       }
6288     }
6289   }
6290 
setFaceDB(const FaceDB & faces)6291     void setFaceDB( const FaceDB &faces )
6292     {
6293         for ( int i = 0; i < _table_size; i++ ) {
6294             if ( _lv_lookup_table[i].subwin != NULL ) {
6295                 _lv_lookup_table[i].subwin->setFaceDB( faces );
6296             }
6297         }
6298     }
6299 
addButtons(List * buttons,add_action_t action)6300   int addButtons( List *buttons, add_action_t action )
6301   {
6302     int erg = 0;
6303     for ( int i = 0; i < _table_size && erg == 0; i++ ) {
6304       if ( _lv_lookup_table[i].subwin != NULL ) {
6305         erg = _lv_lookup_table[i].subwin->addButtons( buttons, action );
6306       }
6307     }
6308     return erg;
6309   }
addHotkeys(List * hotkeys,add_action_t action)6310   int addHotkeys( List *hotkeys, add_action_t action )
6311   {
6312     int erg = 0;
6313     for ( int i = 0; i < _table_size && erg == 0; i++ ) {
6314       if ( _lv_lookup_table[i].subwin != NULL ) {
6315         erg = _lv_lookup_table[i].subwin->addHotkeys( hotkeys, action );
6316       }
6317     }
6318     return erg;
6319   }
addFiletypes(List * filetypes,add_action_t action)6320   int addFiletypes( List *filetypes, add_action_t action )
6321   {
6322     int erg = 0;
6323     for ( int i = 0; i < _table_size && erg == 0; i++ ) {
6324       if ( _lv_lookup_table[i].subwin != NULL ) {
6325         erg = _lv_lookup_table[i].subwin->addFiletypes( filetypes, action );
6326       }
6327     }
6328     return erg;
6329   }
6330 private:
6331   lv_key_type_t *_lv_lookup_table;
6332   int _table_size;
6333 };
6334 
recreatePanel(int i,lv_key_type_t * lv_lookup_table,int table_size,AWindow * win,WConfig * tempconfig,WConfig * button_path_hotkey_conf,MyWConfigPanelCallBack * panelcb)6335 static void recreatePanel( int i, lv_key_type_t *lv_lookup_table, int table_size,
6336                            AWindow *win,
6337                            WConfig *tempconfig,
6338                            WConfig *button_path_hotkey_conf,
6339                            MyWConfigPanelCallBack *panelcb )
6340 {
6341   if ( lv_lookup_table[i].subwin != NULL )
6342     delete lv_lookup_table[i].subwin;
6343 
6344   switch ( lv_lookup_table[i].type ) {
6345     case LANG:
6346       lv_lookup_table[i].subwin = new LangPanel( *win, *tempconfig );
6347       lv_lookup_table[i].subwin->create();
6348       break;
6349     case PALETTE:
6350       lv_lookup_table[i].subwin = new PalettePanel( *win, *tempconfig );
6351       lv_lookup_table[i].subwin->create();
6352       break;
6353     case FONTCONF:
6354       lv_lookup_table[i].subwin = new FontPanel( *win, *tempconfig );
6355       lv_lookup_table[i].subwin->create();
6356       break;
6357     case MOUSECONF:
6358       lv_lookup_table[i].subwin = new MousePanel( *win, *tempconfig );
6359       lv_lookup_table[i].subwin->create();
6360       break;
6361     case STARTCONF:
6362       lv_lookup_table[i].subwin = new StartPanel( *win, *tempconfig );
6363       lv_lookup_table[i].subwin->create();
6364       break;
6365     case CLOCKCONF:
6366       lv_lookup_table[i].subwin = new ClockPanel( *win, *tempconfig );
6367       lv_lookup_table[i].subwin->create();
6368       break;
6369     case LISTCONF:
6370       lv_lookup_table[i].subwin = new ListerPanel( *win, *tempconfig );
6371       lv_lookup_table[i].subwin->create();
6372       break;
6373     case VIEWCONF:
6374       lv_lookup_table[i].subwin = new ListViewPanel( *win, *tempconfig );
6375       lv_lookup_table[i].subwin->create();
6376       break;
6377     case TIMECONF:
6378       lv_lookup_table[i].subwin = new TimePanel( *win, *tempconfig );
6379       lv_lookup_table[i].subwin->create();
6380       break;
6381     case UICOLORS:
6382       lv_lookup_table[i].subwin = new ColorPanel( *win, *tempconfig );
6383       lv_lookup_table[i].subwin->create();
6384       break;
6385     case COLORCONF:
6386       lv_lookup_table[i].subwin = new ColorConfPanel( *win, *tempconfig );
6387       lv_lookup_table[i].subwin->create();
6388       break;
6389     case BUTTON:
6390       lv_lookup_table[i].subwin = new ButtonPanel( *win, *button_path_hotkey_conf );
6391       lv_lookup_table[i].subwin->create();
6392       break;
6393     case BUTTONGRPCONF:
6394       lv_lookup_table[i].subwin = new ButtonGrpConfPanel( *win, *button_path_hotkey_conf );
6395       lv_lookup_table[i].subwin->create();
6396       break;
6397     case PATH:
6398       lv_lookup_table[i].subwin = new PathPanel( *win, *button_path_hotkey_conf );
6399       lv_lookup_table[i].subwin->create();
6400       break;
6401     case FILETYPE:
6402       lv_lookup_table[i].subwin = new FiletypePanel( *win, *tempconfig );
6403       lv_lookup_table[i].subwin->create();
6404       break;
6405     case HOTKEY:
6406       lv_lookup_table[i].subwin = new HotkeyPanel( *win, *button_path_hotkey_conf );
6407       lv_lookup_table[i].subwin->create();
6408       break;
6409     case DCDCONF:
6410       lv_lookup_table[i].subwin = new DCDPanel( *win, *tempconfig );
6411       lv_lookup_table[i].subwin->create();
6412       break;
6413     case CACHECONF:
6414       lv_lookup_table[i].subwin = new CacheSizePanel( *win, *tempconfig );
6415       lv_lookup_table[i].subwin->create();
6416       break;
6417     case OWNERCONF:
6418       lv_lookup_table[i].subwin = new OwnerConfPanel( *win, *tempconfig );
6419       lv_lookup_table[i].subwin->create();
6420       break;
6421     case TERMCONF:
6422       lv_lookup_table[i].subwin = new TermConfPanel( *win, *tempconfig );
6423       lv_lookup_table[i].subwin->create();
6424       break;
6425     case DIRSIZECONF:
6426       lv_lookup_table[i].subwin = new DirSizeConfPanel( *win, *tempconfig );
6427       lv_lookup_table[i].subwin->create();
6428       break;
6429     case LAYOUTCONF:
6430       lv_lookup_table[i].subwin = new LayoutPanel( *win, *tempconfig );
6431       lv_lookup_table[i].subwin->create();
6432       break;
6433     case IMEXPORT:
6434       lv_lookup_table[i].subwin = new ImExportPanel( *win, *tempconfig );
6435       lv_lookup_table[i].subwin->create();
6436       break;
6437     case MAINUICONF:
6438       lv_lookup_table[i].subwin = new MainUIPanel( *win, *tempconfig );
6439       lv_lookup_table[i].subwin->create();
6440       break;
6441     case EXPERTUICONF:
6442       lv_lookup_table[i].subwin = new ExpertUIPanel( *win, *tempconfig );
6443       lv_lookup_table[i].subwin->create();
6444       break;
6445     case GENERALCONF:
6446       lv_lookup_table[i].subwin = new GeneralConfPanel( *win, *tempconfig );
6447       lv_lookup_table[i].subwin->create();
6448       break;
6449     case BOOKMARKCOLORS:
6450       lv_lookup_table[i].subwin = new BookmarkColorPanel( *win, *tempconfig );
6451       lv_lookup_table[i].subwin->create();
6452       break;
6453     case VOLMANCONF:
6454       lv_lookup_table[i].subwin = new VolManPanel( *win, *tempconfig );
6455       lv_lookup_table[i].subwin->create();
6456       break;
6457     case PATHJUMPALLOWCONF:
6458       lv_lookup_table[i].subwin = new PathJumpAllowPanel( *win, *tempconfig );
6459       lv_lookup_table[i].subwin->create();
6460       break;
6461     case DIRECTORYPRESETSCONF:
6462       lv_lookup_table[i].subwin = new DirectoryPresetsPanel( *win, *tempconfig );
6463       lv_lookup_table[i].subwin->create();
6464       break;
6465     default:
6466       break;
6467   }
6468   if ( lv_lookup_table[i].subwin != NULL && panelcb != NULL ) {
6469     lv_lookup_table[i].subwin->setConfCB( panelcb );
6470   }
6471 }
6472 
configure(const std::string & panel)6473 bool WConfig::configure( const std::string &panel )
6474 {
6475   AGUIX *aguix = worker->getAGUIX();
6476   lv_key_type_t lv_lookup_table[] =
6477        { { catalog.getLocale( 696 ), "", MAINUICONF, NULL, 0 },
6478          { catalog.getLocale( 697 ), "", LANG, NULL, 1 },
6479          { catalog.getLocale( 698 ), "", COLORCONF, NULL, 1 },
6480          { catalog.getLocale( 15 ), "", PALETTE, NULL, 2 },
6481          { catalog.getLocale( 699 ), "", UICOLORS, NULL, 2 },
6482          { catalog.getLocale( 832 ), "", BOOKMARKCOLORS, NULL, 2 },
6483          { catalog.getLocale( 700 ), "", FONTCONF, NULL, 1 },
6484          { catalog.getLocale( 650 ), "", MOUSECONF, NULL, 1 },
6485          { catalog.getLocale( 4 ), "", BUTTONGRPCONF, NULL, 0 },
6486          { catalog.getLocale( 706 ), "", BUTTON, NULL, 1 },
6487          { catalog.getLocale( 707 ), "", PATH, NULL, 1 },
6488          { catalog.getLocale( 6 ), "", FILETYPE, NULL, 0 },
6489          { catalog.getLocale( 708 ), "", DCDCONF, NULL, 1 },
6490          { catalog.getLocale( 91 ), "", HOTKEY, NULL, 0 },
6491          { catalog.getLocale( 701 ), "", LISTCONF, NULL, 0 },
6492          { catalog.getLocale( 702 ), "", VIEWCONF, NULL, 1 },
6493          { catalog.getLocale( 703 ), "", OWNERCONF, NULL, 1 },
6494          { catalog.getLocale( 704 ), "", DIRSIZECONF, NULL, 1 },
6495          { catalog.getLocale( 439 ), "", TIMECONF, NULL, 1 },
6496          { catalog.getLocale( 705 ), "", STARTCONF, NULL, 1 },
6497          { catalog.getLocale( 1332 ), "", DIRECTORYPRESETSCONF, NULL, 1 },
6498          { catalog.getLocale( 974 ), "", PATHJUMPALLOWCONF, NULL, 0 },
6499          { catalog.getLocale( 784 ), "", GENERALCONF, NULL, 0 },
6500          { catalog.getLocale( 709 ), "", EXPERTUICONF, NULL, 0 },
6501          { catalog.getLocale( 710 ), "", TERMCONF, NULL, 1 },
6502          { catalog.getLocale( 711 ), "", CACHECONF, NULL, 1 },
6503          { catalog.getLocale( 368 ), "", CLOCKCONF, NULL, 1 },
6504          { catalog.getLocale( 569 ), "", LAYOUTCONF, NULL, 1 },
6505          { catalog.getLocale( 863 ), "", VOLMANCONF, NULL, 1 },
6506          { catalog.getLocale( 396 ), "", IMEXPORT, NULL, 0 } };
6507   std::map<type_t, lv_key_type_t *> type_lookup;
6508 
6509   AWindow *win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 0 ) );
6510   win->create();
6511 
6512   AContainer *ac1 = win->setContainer( new AContainer( win, 1, 2 ), true );
6513   ac1->setBorderWidth( 5 );
6514   ac1->setMinSpace( 5 );
6515   ac1->setMaxSpace( 5 );
6516 
6517   AContainer *ac1_1 = ac1->add( new AContainer( win, 2, 1 ), 0, 0 );
6518   ac1_1->setBorderWidth( 0 );
6519   ac1_1->setMinSpace( 0 );
6520   ac1_1->setMaxSpace( 0 );
6521 
6522   FieldListView *lv = (FieldListView*)ac1_1->add( new FieldListView( aguix, 0, 0, 10, 400, 0 ),
6523                                                   0, 0, AContainer::CO_INCH );
6524 
6525   AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 1 );
6526   ac1_2->setBorderWidth( 0 );
6527   ac1_2->setMinSpace( 5 );
6528   ac1_2->setMaxSpace( -1 );
6529   Button *okb = (Button*)ac1_2->add( new Button( aguix,
6530                                                  0,
6531                                                  0,
6532                                                  catalog.getLocale( 7 ),
6533                                                  0 ), 0, 0, AContainer::CO_FIX );
6534   Button *cb = (Button*)ac1_2->add( new Button( aguix,
6535                                                 0,
6536                                                 0,
6537                                                 catalog.getLocale( 8 ),
6538                                                 0 ), 1, 0, AContainer::CO_FIX );
6539 
6540   for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6541     int row = lv->addRow();
6542 
6543     std::string s1( lv_lookup_table[i].level * 2, ' ' );
6544     lv_lookup_table[i].base_key = lv_lookup_table[i].key;
6545     lv_lookup_table[i].key = s1 + lv_lookup_table[i].key;
6546 
6547     lv->setText( row, 0, lv_lookup_table[i].key );
6548     lv->setPreColors( row, FieldListView::PRECOLOR_ONLYACTIVE );
6549     if ( lv_lookup_table[i].type != NONE ) type_lookup[lv_lookup_table[i].type] = &lv_lookup_table[i];
6550   }
6551   lv->setHBarState( 0 );
6552   lv->setVBarState( 0 );
6553   lv->setDisplayFocus( true );
6554   lv->setAcceptFocus( true );
6555   lv->maximizeX();
6556   lv->maximizeY();
6557   ac1_1->readLimits();
6558 
6559   WConfig *button_path_hotkey_conf = duplicate();
6560   WConfig *tempconfig = duplicate();
6561 
6562   MyWConfigPanelCallBack mypanelcb( lv_lookup_table, sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ) );
6563 
6564   int inner_width = 100, inner_height = 100;
6565   int w, h;
6566 
6567   for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6568     recreatePanel( i, lv_lookup_table, sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ),
6569                    win, tempconfig, button_path_hotkey_conf, &mypanelcb );
6570     if ( lv_lookup_table[i].subwin != NULL ) {
6571       w = lv_lookup_table[i].subwin->getMinWidth();
6572       h = lv_lookup_table[i].subwin->getMinHeight();
6573       if ( w > inner_width ) inner_width = w;
6574       if ( h > inner_height ) inner_height = h;
6575     }
6576   }
6577 
6578   win->setDoTabCycling( true );
6579 
6580   int active_row = 0;
6581 
6582   if ( ! panel.empty() ) {
6583       // find panel to activate by default
6584       int row = 0;
6585       for ( auto &e : lv_lookup_table ) {
6586           if ( e.base_key == panel ) {
6587               active_row = row;
6588               break;
6589           }
6590           row++;
6591       }
6592   }
6593 
6594   ac1_1->add( lv_lookup_table[active_row].subwin, 1, 0, AContainer::CO_MIN );
6595   ac1_1->setMinWidth( inner_width, 1, 0 );
6596   ac1_1->setMinHeight( inner_height, 1, 0 );
6597 
6598   win->contMaximize( true );
6599   lv_lookup_table[active_row].subwin->show();
6600   lv->setActiveRow( active_row );
6601   lv->takeFocus();
6602   win->show();
6603 
6604   if ( m_initial_command.type() != WConfigInitialCommand::NO_OP ) {
6605       for ( auto &e : lv_lookup_table ) {
6606           e.subwin->executeInitialCommand( m_initial_command );
6607       }
6608       m_initial_command = WConfigInitialCommand();
6609   }
6610 
6611   AGMessage *msg;
6612   while((msg=aguix->GetMessage(NULL))!=NULL) aguix->ReplyMessage(msg);
6613   int ende=0;
6614   while(ende==0) {
6615     msg=aguix->WaitMessage(win);
6616     if(msg!=NULL) {
6617       if(msg->type==AG_CLOSEWINDOW) {
6618         if(msg->closewindow.window==win->getWindow()) ende=-1;
6619       } else if ( msg->type == AG_FIELDLV_ONESELECT || msg->type == AG_FIELDLV_MULTISELECT ) {
6620         if ( msg->fieldlv.lv == lv ) {
6621           int entry = lv->getActiveRow();
6622           for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6623             if ( lv_lookup_table[i].key != lv->getText( entry, 0 ) ) {
6624               if ( lv_lookup_table[i].subwin != NULL &&
6625                    lv_lookup_table[i].subwin->isVisible() == true ) {
6626                 lv_lookup_table[i].subwin->hide();
6627               }
6628             }
6629           }
6630 
6631           WConfigPanel *show_panel = NULL;
6632 
6633           for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6634             if ( lv_lookup_table[i].key == lv->getText( entry, 0 ) ) {
6635               if ( lv_lookup_table[i].subwin != NULL ) {
6636                 if ( lv_lookup_table[i].subwin->need_recreate() == true ) {
6637                   lv_lookup_table[i].subwin->saveValues();
6638 
6639                   recreatePanel( i, lv_lookup_table, sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ),
6640                                  win,
6641                                  tempconfig,
6642                                  button_path_hotkey_conf, &mypanelcb );
6643                 }
6644                 show_panel = lv_lookup_table[i].subwin;
6645                 w = show_panel->getMinWidth();
6646                 h = show_panel->getMinHeight();
6647 
6648                 bool need_maximize = false;
6649                 if ( w > inner_width ) {
6650                   inner_width = w;
6651                   need_maximize = true;
6652                 }
6653                 if ( h > inner_height ) {
6654                   inner_height = h;
6655                   need_maximize = true;
6656                 }
6657 
6658                 ac1_1->add( lv_lookup_table[i].subwin, 1, 0, AContainer::CO_MIN );
6659                 ac1_1->setMinWidth( inner_width, 1, 0 );
6660                 ac1_1->setMinHeight( inner_height, 1, 0 );
6661 
6662                 if ( need_maximize == true ) {
6663                   win->contMaximize( true );
6664                 } else {
6665                   ac1->rearrange();
6666                 }
6667                 break;
6668               }
6669             }
6670           }
6671           if ( show_panel != NULL ) show_panel->show();
6672         }
6673       } else if(msg->type==AG_BUTTONCLICKED) {
6674         if ( msg->button.button == okb ) {
6675           ende=1;
6676         } else if ( msg->button.button == cb ) {
6677           ende=-1;
6678         }
6679       } else if ( msg->type == AG_KEYPRESSED ) {
6680           if ( win->isParent( msg->key.window, false ) == true ) {
6681               switch ( msg->key.key ) {
6682                   case XK_Escape:
6683                       ende = -1;
6684                       break;
6685               }
6686           }
6687       }
6688       aguix->ReplyMessage(msg);
6689     }
6690 
6691     if ( ende == 1 && checkForNewerConfig() ) {
6692         std::string str1;
6693 
6694         str1 = catalog.getLocale( 629 );
6695         str1 += "|";
6696         str1 += catalog.getLocale( 8 );
6697 
6698         int res = Worker::getRequester()->request( catalog.getLocale( 123 ),
6699                                                    catalog.getLocale( 1096 ),
6700                                                    str1.c_str(),
6701                                                    win,
6702                                                    Requester::REQUEST_NONE );
6703         if ( res == 1 ) {
6704             ende = 0;
6705         }
6706     }
6707 #if 0
6708     if ( ( ende == -1 ) && ( changed == true ) ) {
6709       // cancel but changed config, ask to continue
6710       std::string str1;
6711 
6712       str1 = catalog.getLocale( 11 );
6713       str1 += "|";
6714       str1 += catalog.getLocale( 8 );
6715 
6716       int res = Worker::getRequester()->request( catalog.getLocale( 123 ),
6717                                            catalog.getLocale( 538 ),
6718                                            str1.c_str(),
6719                                            win,
6720                                            Requester::REQUEST_NONE );
6721       if ( res == 1 ) {
6722         ende = 0;
6723       }
6724     }
6725 #endif
6726   }
6727 
6728   if ( ende == 1 ) {
6729     {
6730       for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6731         if ( lv_lookup_table[i].subwin != NULL &&
6732              lv_lookup_table[i].subwin->isVisible() == true ) {
6733           lv_lookup_table[i].subwin->hide();
6734         }
6735       }
6736       for ( unsigned int i = 0; i < sizeof( lv_lookup_table ) / sizeof( lv_lookup_table[0] ); i++ ) {
6737         if ( lv_lookup_table[i].subwin != NULL ) {
6738           lv_lookup_table[i].subwin->saveValues();
6739         }
6740       }
6741     }
6742     setButtons( button_path_hotkey_conf->getButtons() );
6743     setHotkeys( button_path_hotkey_conf->getHotkeys() );
6744     setPaths( button_path_hotkey_conf->getPaths() );
6745     setRows( button_path_hotkey_conf->getRows() );
6746     setColumns( button_path_hotkey_conf->getColumns() );
6747 
6748     setLang(tempconfig->getLang());
6749     setTerminalBin(tempconfig->getTerminalBin());
6750     setCacheSize(tempconfig->getCacheSize());
6751     for ( int i = 0; i < 2; i++ ) {
6752       setHBarTop(i,tempconfig->getHBarTop(i));
6753       setVBarLeft(i,tempconfig->getVBarLeft(i));
6754       setHBarHeight(i,tempconfig->getHBarHeight(i));
6755       setVBarWidth(i,tempconfig->getVBarWidth(i));
6756       setVisCols( i, tempconfig->getVisCols( i ) );
6757       setShowHeader( i, tempconfig->getShowHeader( i ) );
6758       setStartDir(i,tempconfig->getStartDir(i));
6759 
6760       setPathEntryOnTop( i, tempconfig->getPathEntryOnTop( i ) );
6761     }
6762     setFontNames( tempconfig->getFontNames() );
6763     setFiletypes(tempconfig->getFiletypes());
6764     setColors(tempconfig->getColors());
6765     setOwnerstringtype(tempconfig->getOwnerstringtype());
6766     setClockbarMode(tempconfig->getClockbarMode());
6767     setClockbarUpdatetime(tempconfig->getClockbarUpdatetime());
6768     setClockbarCommand(tempconfig->getClockbarCommand());
6769     setClockbarHints( tempconfig->getClockbarHints() );
6770     setDontCheckDirs(tempconfig->getDontCheckDirs());
6771     setDontCheckVirtual( tempconfig->getDontCheckVirtual() );
6772     setShowStringForDirSize(tempconfig->getShowStringForDirSize());
6773     setStringForDirSize(tempconfig->getStringForDirSize());
6774     setLayoutOrders( tempconfig->getLayoutOrders() );
6775     setLayoutButtonVert( tempconfig->getLayoutButtonVert() );
6776     setLayoutListviewVert( tempconfig->getLayoutListviewVert() );
6777     setLayoutListViewWeight( tempconfig->getLayoutListViewWeight() );
6778     setLayoutWeightRelToActive( tempconfig->getLayoutWeightRelToActive() );
6779 
6780     setMouseSelectButton( tempconfig->getMouseSelectButton() );
6781     setMouseActivateButton( tempconfig->getMouseActivateButton() );
6782     setMouseScrollButton( tempconfig->getMouseScrollButton() );
6783     setMouseContextButton( tempconfig->getMouseContextButton() );
6784     setMouseActivateMod( tempconfig->getMouseActivateMod() );
6785     setMouseScrollMod( tempconfig->getMouseScrollMod() );
6786     setMouseContextMod( tempconfig->getMouseContextMod() );
6787     setMouseSelectMethod( tempconfig->getMouseSelectMethod() );
6788     setDateFormat( tempconfig->getDateFormat() );
6789     setDateFormatString( tempconfig->getDateFormatString() );
6790     setDateSubst( tempconfig->getDateSubst() );
6791     setTimeFormat( tempconfig->getTimeFormat() );
6792     setTimeFormatString( tempconfig->getTimeFormatString() );
6793     setDateBeforeTime( tempconfig->getDateBeforeTime() );
6794 
6795     setColorDefs( tempconfig->getColorDefs() );
6796 
6797     setSaveWorkerStateOnExit( tempconfig->getSaveWorkerStateOnExit() );
6798 
6799     setVMMountCommand( tempconfig->getVMMountCommand() );
6800     setVMUnmountCommand( tempconfig->getVMUnmountCommand() );
6801     setVMFStabFile( tempconfig->getVMFStabFile() );
6802     setVMMtabFile( tempconfig->getVMMtabFile() );
6803     setVMPartitionFile( tempconfig->getVMPartitionFile() );
6804     setVMRequestAction( tempconfig->getVMRequestAction() );
6805     setVMEjectCommand( tempconfig->getVMEjectCommand() );
6806     setVMCloseTrayCommand( tempconfig->getVMCloseTrayCommand() );
6807     setVMPreferredUdisksVersion( tempconfig->getVMPreferredUdisksVersion() );
6808 
6809     setUseStringCompareMode( tempconfig->getUseStringCompareMode() );
6810     setApplyWindowDialogType( tempconfig->getApplyWindowDialogType() );
6811     setUseExtendedRegEx( tempconfig->getUseExtendedRegEx() );
6812 
6813     setPathJumpAllowDirs( tempconfig->getPathJumpAllowDirs() );
6814     setPathJumpStoreFilesAlways( tempconfig->getPathJumpStoreFilesAlways() );
6815 
6816     setFaceDB( tempconfig->getFaceDB() );
6817 
6818     setRestoreTabsMode( tempconfig->getRestoreTabsMode() );
6819     setStoreTabsMode( tempconfig->getStoreTabsMode() );
6820 
6821     setTerminalReturnsEarly( tempconfig->getTerminalReturnsEarly() );
6822 
6823     setDisableBGCheckPrefix( tempconfig->getDisableBGCheckPrefix() );
6824 
6825     setDirectoryPresets( tempconfig->getDirectoryPresets() );
6826 
6827     save();
6828     applyLanguage();
6829   } else {
6830     applyColorList( getColors() );
6831   }
6832 
6833   delete win;
6834   delete button_path_hotkey_conf;
6835   delete tempconfig;
6836 
6837   initFixTypes();
6838 
6839   return ( ende == 1 ) ? true : false;
6840 }
6841 
addButtons(List * bl)6842 int WConfig::addButtons( List *bl )
6843 {
6844   int erg = 0, id;
6845   List *orig_buttons, *orig_buttons_copy;
6846   WCButton *b1;
6847 
6848   if ( bl == NULL ) return 1;
6849 
6850   orig_buttons = getButtons();
6851   orig_buttons_copy = new List();
6852   id = orig_buttons->initEnum();
6853   b1 = (WCButton*)orig_buttons->getFirstElement( id );
6854   while ( b1 != NULL ) {
6855     orig_buttons_copy->addElement( b1->duplicate() );
6856     b1 = (WCButton*)orig_buttons->getNextElement( id );
6857   }
6858   orig_buttons->closeEnum( id );
6859 
6860   id = bl->initEnum();
6861 
6862   b1 = (WCButton*)bl->getFirstElement( id );
6863   while ( b1 != NULL && erg == 0 ) {
6864     erg = addButton( orig_buttons_copy, b1 );
6865     b1 = (WCButton*)bl->getNextElement( id );
6866   }
6867 
6868   bl->closeEnum( id );
6869 
6870   if ( erg == 0 )
6871     setButtons( orig_buttons_copy );
6872 
6873   id = orig_buttons_copy->initEnum();
6874   b1 = (WCButton*)orig_buttons_copy->getFirstElement( id );
6875   while ( b1 != NULL ) {
6876     delete b1;
6877     b1 = (WCButton*)orig_buttons_copy->getNextElement( id );
6878   }
6879   orig_buttons_copy->closeEnum( id );
6880   delete orig_buttons_copy;
6881 
6882   return erg;
6883 }
6884 
addHotkeys(List * hl)6885 int WConfig::addHotkeys( List *hl )
6886 {
6887   int erg = 0, id;
6888   List *orig_hotkeys, *orig_hotkeys_copy;
6889   WCHotkey *h1;
6890 
6891   if ( hl == NULL ) return 1;
6892 
6893   orig_hotkeys = getHotkeys();
6894   orig_hotkeys_copy = new List();
6895   id = orig_hotkeys->initEnum();
6896   h1 = (WCHotkey*)orig_hotkeys->getFirstElement( id );
6897   while ( h1 != NULL ) {
6898     orig_hotkeys_copy->addElement( h1->duplicate() );
6899     h1 = (WCHotkey*)orig_hotkeys->getNextElement( id );
6900   }
6901   orig_hotkeys->closeEnum( id );
6902 
6903   id = hl->initEnum();
6904 
6905   h1 = (WCHotkey*)hl->getFirstElement( id );
6906   while ( h1 != NULL && erg == 0 ) {
6907     erg = addHotkey( orig_hotkeys_copy, h1 );
6908     h1 = (WCHotkey*)hl->getNextElement( id );
6909   }
6910 
6911   hl->closeEnum( id );
6912 
6913   if ( erg == 0 )
6914     setHotkeys( orig_hotkeys_copy );
6915 
6916   id = orig_hotkeys_copy->initEnum();
6917   h1 = (WCHotkey*)orig_hotkeys_copy->getFirstElement( id );
6918   while ( h1 != NULL ) {
6919     delete h1;
6920     h1 = (WCHotkey*)orig_hotkeys_copy->getNextElement( id );
6921   }
6922   orig_hotkeys_copy->closeEnum( id );
6923   delete orig_hotkeys_copy;
6924 
6925   return erg;
6926 }
6927 
addFiletypes(List * fl,bool init_fix_types)6928 int WConfig::addFiletypes( List *fl, bool init_fix_types )
6929 {
6930   int erg = 0, id;
6931   List *orig_filetypes, *orig_filetypes_copy;
6932   WCFiletype *f1;
6933 
6934   if ( fl == NULL ) return 1;
6935 
6936   orig_filetypes = getFiletypes();
6937   orig_filetypes_copy = new List();
6938   id = orig_filetypes->initEnum();
6939   f1 = (WCFiletype*)orig_filetypes->getFirstElement( id );
6940   while ( f1 != NULL ) {
6941     orig_filetypes_copy->addElement( f1->duplicate() );
6942     f1 = (WCFiletype*)orig_filetypes->getNextElement( id );
6943   }
6944   orig_filetypes->closeEnum( id );
6945 
6946   id = fl->initEnum();
6947 
6948   f1 = (WCFiletype*)fl->getFirstElement( id );
6949   while ( f1 != NULL && erg == 0 ) {
6950     erg = addFiletype( orig_filetypes_copy, f1 );
6951     f1 = (WCFiletype*)fl->getNextElement( id );
6952   }
6953 
6954   fl->closeEnum( id );
6955 
6956   if ( erg == 0 ) {
6957     setFiletypes( orig_filetypes_copy );
6958     if ( init_fix_types ) {
6959         initFixTypes();
6960     }
6961   }
6962 
6963   id = orig_filetypes_copy->initEnum();
6964   f1 = (WCFiletype*)orig_filetypes_copy->getFirstElement( id );
6965   while ( f1 != NULL ) {
6966     delete f1;
6967     f1 = (WCFiletype*)orig_filetypes_copy->getNextElement( id );
6968   }
6969   orig_filetypes_copy->closeEnum( id );
6970   delete orig_filetypes_copy;
6971 
6972   return erg;
6973 }
6974 
addButton(List * bl,WCButton * im_b1_orig)6975 int WConfig::addButton( List *bl, WCButton *im_b1_orig )
6976 {
6977   WCButton *im_b1;
6978   int ende = 0, maxcols;
6979   std::string str1;
6980 
6981   /* 1.resolve any shortkey problem
6982    * 2.add button to given list
6983    *   colors could be wrong for the imported buttons!
6984    */
6985 
6986   maxcols = getColors()->size();
6987 
6988   if ( im_b1_orig == NULL ) return 1;
6989 
6990   im_b1 = im_b1_orig->duplicate();
6991 
6992   ende = fixDoubleKeys( bl, getPaths(), getHotkeys(), im_b1, NULL );
6993 
6994   if ( im_b1->getFG() >= maxcols ) im_b1->setFG( maxcols - 1 );
6995   if ( im_b1->getBG() >= maxcols ) im_b1->setBG( maxcols - 1 );
6996 
6997   if ( ende != 0 ) {
6998     delete im_b1;
6999     return 1;
7000   }
7001 
7002   bl->addElement( im_b1 );
7003   return 0;
7004 }
7005 
addHotkey(List * hl,WCHotkey * im_h_orig)7006 int WConfig::addHotkey( List *hl, WCHotkey *im_h_orig )
7007 {
7008   WCHotkey *im_h1;
7009   int ende = 0;
7010   std::string str1;
7011 
7012   /* 1.resolve any shortkey problem
7013    * 2.add buttons banks to this config
7014    *   colors could be wrong for the imported buttons!
7015    * 3.add hotkeys to this config
7016    * 4.add normal filetypes to this config
7017    * 5.ask for the special types (if any)
7018    *   leave the current
7019    *   or take the new
7020    */
7021 
7022   if ( im_h_orig == NULL ) return 1;
7023 
7024   im_h1 = im_h_orig->duplicate();
7025 
7026   ende = fixDoubleKeys( getButtons(), getPaths(), hl, NULL, im_h1 );
7027 
7028   if ( ende != 0 ) {
7029     delete im_h1;
7030     return 1;
7031   }
7032 
7033   hl->addElement( im_h1 );
7034   return 0;
7035 }
7036 
addFiletype(List * fl,WCFiletype * im_f_orig)7037 int WConfig::addFiletype( List *fl, WCFiletype *im_f_orig )
7038 {
7039   WCFiletype *im_f1, *f1;
7040   char *textstr;
7041   int erg, im_id;
7042   std::string str1;
7043   Requester req( worker->getAGUIX() );
7044 
7045   if ( im_f_orig == NULL ) return 1;
7046 
7047   im_f1 = im_f_orig->duplicate();
7048 
7049   // here we need a two-pass-run over the types
7050   // 1.For each unique type in importconfig
7051   //   find equal unique
7052   //   Ask which should be used and add it
7053   // 2.add all normal types from current config and then from importconfig
7054 
7055   if ( im_f1->getinternID() != NORMALTYPE ) {
7056     // not a normal type
7057     // because special types are unique, ask the user
7058     // which should be used
7059 
7060     im_id = fl->initEnum();
7061 
7062     // find new type for this id
7063     f1 = (WCFiletype*)fl->getFirstElement( im_id );
7064     while ( f1 != NULL ) {
7065       if ( f1->getinternID() == im_f1->getinternID() ) break;
7066       f1 = (WCFiletype*)fl->getNextElement( im_id );
7067     }
7068     fl->closeEnum( im_id );
7069 
7070     if ( f1 != NULL ) {
7071       // same unique type found
7072       textstr = (char*)_allocsafe( strlen( catalog.getLocale( 429 ) ) +
7073                                    strlen( im_f1->getName().c_str() ) +
7074                                    strlen( f1->getName().c_str() ) + 1 );
7075       sprintf( textstr, catalog.getLocale( 429 ), im_f1->getName().c_str(), f1->getName().c_str() );
7076 
7077       str1 = catalog.getLocale( 427 );
7078       str1 += "|";
7079       str1 += catalog.getLocale( 428 );
7080       erg = req.request( catalog.getLocale( 123 ), textstr, str1.c_str() );
7081       _freesafe( textstr );
7082       if ( erg == 1 ) {
7083         fl->addElement( im_f1 );
7084         fl->removeElement( f1 );
7085         delete f1;
7086       } else {
7087         delete im_f1;
7088       }
7089     } else {
7090       fl->addElement( im_f1 );
7091     }
7092   } else {
7093     fl->addElement( im_f1 );
7094   }
7095   return 0;
7096 }
7097 
7098 /**
7099  * fixDoubleKeys checks the given button or hotkey for possible shortkey conflicts
7100  * in any given list and possibly removes conflicts
7101  */
fixDoubleKeys(List * bl,List * pl,List * hl,WCButton * im_b1,WCHotkey * im_h1)7102 int WConfig::fixDoubleKeys( List *bl, List *pl, List *hl, WCButton *im_b1, WCHotkey *im_h1 )
7103 {
7104   WCButton *b1_return;
7105   WCHotkey *h1_return;
7106   WCPath *p1_return;
7107   char *textstr;
7108   int ende = 0, erg, id;
7109   std::string str1;
7110   Requester req( Worker::getAGUIX() );
7111   WCDoubleShortkey *dk;
7112   List *dkeys;
7113 
7114   if ( im_b1 == NULL && im_h1 == NULL ) return 1;
7115   if ( im_b1 != NULL && im_h1 != NULL ) return 1;
7116 
7117   dkeys = ( im_b1 != NULL ) ? im_b1->getDoubleKeys() : im_h1->getDoubleKeys();
7118 
7119   id = dkeys->initEnum();
7120   dk = (WCDoubleShortkey*)dkeys->getFirstElement( id );
7121   while ( dk != NULL ) {
7122     if ( findDoubleShortkey( dk, bl, pl, hl,
7123                              &b1_return, &p1_return, &h1_return ) != 0 ) {
7124       // there is already an element with this shortkey
7125       if ( getAlwaysKeepOldKey() == true ) {
7126 
7127         if ( im_b1 != NULL )
7128           im_b1->removeKey( dk );
7129         else
7130           im_h1->removeKey( dk );
7131 
7132       } else {
7133         if ( b1_return != NULL ) {
7134           // "The new button/hotkey %s uses the same shortkey as the button %s!"
7135           if ( im_b1 != NULL ) {
7136             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 419 ) ) +
7137                                          strlen( im_b1->getText() ) +
7138                                          strlen( b1_return->getText() ) + 1 );
7139             sprintf( textstr, catalog.getLocale( 419 ), im_b1->getText(), b1_return->getText() );
7140           } else {
7141             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 420 ) ) +
7142                                          strlen( im_h1->getName() ) +
7143                                          strlen( b1_return->getText() ) + 1 );
7144             sprintf( textstr, catalog.getLocale( 420 ), im_h1->getName(), b1_return->getText() );
7145           }
7146           str1 = catalog.getLocale( 425 );
7147           str1 += "|";
7148           str1 += catalog.getLocale( 431 );
7149           str1 += "|";
7150           str1 += catalog.getLocale( 426 );
7151           str1 += "|";
7152           str1 += catalog.getLocale( 8 );
7153           erg = req.request( catalog.getLocale( 123 ), textstr, str1.c_str() );
7154           _freesafe(textstr);
7155 
7156           if ( erg == 2 ) {
7157             // use new
7158             b1_return->removeKey( dk );
7159           } else if ( erg == 1 || erg == 0 ) {
7160             // leave original
7161 
7162             if ( im_b1 != NULL )
7163               im_b1->removeKey( dk );
7164             else
7165               im_h1->removeKey( dk );
7166 
7167             if ( erg == 1 ) setAlwaysKeepOldKey( true );
7168           } else {
7169             ende = -1;
7170           }
7171         } else if ( p1_return != NULL ) {
7172           // "The new button/hotkey %s uses the same shortkey as the path %s!"
7173           if ( im_b1 != NULL ) {
7174             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 423 ) ) +
7175                                          strlen( im_b1->getText() ) +
7176                                          strlen( p1_return->getName() ) + 1 );
7177             sprintf( textstr, catalog.getLocale( 423 ), im_b1->getText(), p1_return->getName() );
7178           } else {
7179             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 424 ) ) +
7180                                          strlen( im_h1->getName() ) +
7181                                          strlen( p1_return->getName() ) + 1 );
7182             sprintf( textstr, catalog.getLocale( 424 ), im_h1->getName(), p1_return->getName() );
7183           }
7184 
7185           str1 = catalog.getLocale( 425 );
7186           str1 += "|";
7187           str1 += catalog.getLocale( 431 );
7188           str1 += "|";
7189           str1 += catalog.getLocale( 426 );
7190           str1 += "|";
7191           str1 += catalog.getLocale( 8 );
7192           erg = req.request( catalog.getLocale( 123 ), textstr, str1.c_str() );
7193           _freesafe(textstr);
7194 
7195           if ( erg == 2 ) {
7196             // use new
7197             p1_return->removeKey( dk );
7198           } else if ( erg == 1 || erg == 0 ) {
7199 
7200             // leave original
7201             if ( im_b1 != NULL )
7202               im_b1->removeKey( dk );
7203             else
7204               im_h1->removeKey( dk );
7205 
7206             if ( erg == 1 ) setAlwaysKeepOldKey( true );
7207           } else ende = -1;
7208         } else if ( h1_return != NULL ) {
7209           // "The new button/hotkey %s uses the same shortkey as the hotkey %s!"
7210           if ( im_b1 != NULL ) {
7211             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 421 ) ) +
7212                                          strlen( im_b1->getText() ) +
7213                                          strlen( h1_return->getName() ) + 1 );
7214             sprintf( textstr, catalog.getLocale( 421 ), im_b1->getText(), h1_return->getName() );
7215           } else {
7216             textstr = (char*)_allocsafe( strlen( catalog.getLocale( 422 ) ) +
7217                                          strlen( im_h1->getName() ) +
7218                                          strlen( h1_return->getName() ) + 1 );
7219             sprintf( textstr, catalog.getLocale( 422 ), im_h1->getName(), h1_return->getName() );
7220           }
7221 
7222           str1 = catalog.getLocale( 425 );
7223           str1 += "|";
7224           str1 += catalog.getLocale( 431 );
7225           str1 += "|";
7226           str1 += catalog.getLocale( 426 );
7227           str1 += "|";
7228           str1 += catalog.getLocale( 8 );
7229           erg = req.request( catalog.getLocale( 123 ), textstr, str1.c_str() );
7230           _freesafe(textstr);
7231 
7232           if ( erg == 2 ) {
7233             // use new
7234             h1_return->removeKey( dk );
7235           } else if ( erg == 1 || erg == 0 ) {
7236 
7237             // leave original
7238             if ( im_b1 != NULL )
7239               im_b1->removeKey( dk );
7240             else
7241               im_h1->removeKey( dk );
7242             if ( erg == 1 ) setAlwaysKeepOldKey( true );
7243           } else ende = -1;
7244         }
7245       }
7246     }
7247     dk = (WCDoubleShortkey*)dkeys->getNextElement( id );
7248   }
7249   dkeys->closeEnum( id );
7250 
7251   if ( ende != 0 ) return 1;
7252   return 0;
7253 }
7254 
fixDoubleKeys(List * bl,List * pl,List * hl,List * button_check,List * hotkey_check)7255 int WConfig::fixDoubleKeys( List *bl, List *pl, List *hl, List *button_check, List *hotkey_check )
7256 {
7257   int erg = 0;
7258   int id;
7259 
7260   if ( button_check != NULL ) {
7261     id = button_check->initEnum();
7262     WCButton *b1 = (WCButton*)button_check->getFirstElement( id );
7263     while ( b1 != NULL && erg == 0 ) {
7264       erg = fixDoubleKeys( bl, pl, hl, b1, NULL );
7265       b1 = (WCButton*)button_check->getNextElement( id );
7266     }
7267     button_check->closeEnum( id );
7268   }
7269 
7270   if ( hotkey_check != NULL && erg == 0 ) {
7271     id = hotkey_check->initEnum();
7272     WCHotkey *h1 = (WCHotkey*)hotkey_check->getFirstElement( id );
7273     while ( h1 != NULL && erg == 0 ) {
7274       erg = fixDoubleKeys( bl, pl, hl, NULL, h1 );
7275       h1 = (WCHotkey*)hotkey_check->getNextElement( id );
7276     }
7277     hotkey_check->closeEnum( id );
7278   }
7279   return erg;
7280 }
7281 
getAlwaysKeepOldKey()7282 bool WConfig::getAlwaysKeepOldKey()
7283 {
7284   return always_keep_old_key;
7285 }
7286 
setAlwaysKeepOldKey(bool nv)7287 void WConfig::setAlwaysKeepOldKey( bool nv )
7288 {
7289   always_keep_old_key = nv;
7290 }
7291 
getNrOfPreDates()7292 int WConfig::getNrOfPreDates()
7293 {
7294   return sizeof( predefined_dates ) / sizeof( predefined_dates[0] );
7295 }
7296 
getNrOfPreTimes()7297 int WConfig::getNrOfPreTimes()
7298 {
7299   return sizeof( predefined_times ) / sizeof( predefined_times[0] );
7300 }
7301 
getPreDate(int pos)7302 const char *WConfig::getPreDate( int pos )
7303 {
7304   int i = 0;
7305   if ( pos >= 0 && pos < getNrOfPreDates() ) {
7306     i = pos;
7307   }
7308   return predefined_dates[i];
7309 }
7310 
getPreTime(int pos)7311 const char *WConfig::getPreTime( int pos )
7312 {
7313   int i = 0;
7314   if ( pos >= 0 && pos < getNrOfPreTimes() ) {
7315     i = pos;
7316   }
7317   return predefined_times[i];
7318 }
7319 
setColorDefs(const ColorDef & cols)7320 void WConfig::setColorDefs( const ColorDef &cols )
7321 {
7322     _color_defs = cols;
7323 }
7324 
getColorDefs() const7325 const WConfig::ColorDef &WConfig::getColorDefs() const
7326 {
7327     return _color_defs;
7328 }
7329 
queryNewActionName()7330 std::string WConfig::queryNewActionName()
7331 {
7332     int trow;
7333     AGUIX *aguix = worker->getAGUIX();
7334     AWindow *win = new AWindow( aguix, 10, 10, 10, 10, catalog.getLocale( 774 ), AWindow::AWINDOW_DIALOG );
7335     win->create();
7336 
7337     AContainer *ac1 = win->setContainer( new AContainer( win, 1, 4 ), true );
7338     ac1->setMinSpace( 5 );
7339     ac1->setMaxSpace( 5 );
7340 
7341     AContainer *ac1_2 = ac1->add( new AContainer( win, 2, 1 ), 0, 0 );
7342     ac1_2->setMinSpace( 5 );
7343     ac1_2->setMaxSpace( 5 );
7344     ac1_2->setBorderWidth( 0 );
7345     ac1_2->add( new Text( aguix, 0, 0, catalog.getLocale( 775 ) ), 0, 0, AContainer::CO_FIX );
7346     StringGadget *name_sg = (StringGadget*)ac1_2->add( new StringGadget( aguix, 0, 0,
7347                                                                          100,
7348                                                                          "", 0 ), 1, 0, AContainer::CO_INCW );
7349 
7350     ac1->add( new Text( aguix, 0, 0, catalog.getLocale( 776 ) ), 0, 1, AContainer::CO_INCWNR );
7351 
7352     FieldListView *name_lv = (FieldListView*)ac1->add( new FieldListView( aguix,
7353                                                                           0,
7354                                                                           0,
7355                                                                           100,
7356                                                                           10 * aguix->getCharHeight(),
7357                                                                           0 ), 0, 2, AContainer::CO_MIN );
7358     name_lv->setHBarState(2);
7359     name_lv->setVBarState(2);
7360     name_lv->setNrOfFields( 3 );
7361     name_lv->setFieldWidth( 1, 1 );
7362 
7363     std::vector<std::string> custom_names;
7364     getAllCustomNames( custom_names );
7365 
7366     std::sort( custom_names.begin(), custom_names.end() );
7367 
7368     for ( std::vector<std::string>::const_iterator it1 = custom_names.begin();
7369           it1 != custom_names.end();
7370           it1++ ) {
7371         trow = name_lv->addRow();
7372         name_lv->setPreColors( trow, FieldListView::PRECOLOR_ONLYACTIVE );
7373         name_lv->setText( trow, 0, *it1 );
7374     }
7375 
7376     AContainer *ac1_3 = ac1->add( new AContainer( win, 2, 1 ), 0, 3 );
7377     ac1_3->setMinSpace( 5 );
7378     ac1_3->setMaxSpace( -1 );
7379     ac1_3->setBorderWidth( 0 );
7380     Button *okb =(Button*)ac1_3->add( new Button( aguix,
7381                                                   0,
7382                                                   0,
7383                                                   catalog.getLocale( 11 ),
7384                                                   0 ), 0, 0, AContainer::CO_FIX );
7385     Button *cancelb = (Button*)ac1_3->add( new Button( aguix,
7386                                                        0,
7387 						       0,
7388  						       catalog.getLocale( 8 ),
7389 						       0 ), 1, 0, AContainer::CO_FIX );
7390 
7391 
7392     name_sg->takeFocus();
7393 
7394     win->setDoTabCycling( true );
7395     win->contMaximize( true );
7396     win->show();
7397 
7398     AGMessage *msg;
7399     while ( ( msg = aguix->GetMessage( NULL ) ) != NULL ) aguix->ReplyMessage( msg );
7400     int ende = 0;
7401     while ( ende == 0 ) {
7402         msg = aguix->WaitMessage( win );
7403         if ( msg != NULL ) {
7404             if ( msg->type == AG_CLOSEWINDOW ) {
7405                 if ( msg->closewindow.window == win->getWindow() ) ende = -1;
7406             } else if ( msg->type == AG_BUTTONCLICKED ) {
7407                 if ( msg->button.button == okb ) ende = 1;
7408                 else if ( msg->button.button == cancelb ) ende = -1;
7409             } else if ( msg->type == AG_FIELDLV_ONESELECT ) {
7410                 if ( msg->fieldlv.lv == name_lv ) {
7411                     if ( name_lv->isValidRow( msg->fieldlv.row ) == true ) {
7412                         std::string s1 = name_lv->getText( msg->fieldlv.row, 0 );
7413                         name_sg->setText( s1.c_str() );
7414                     }
7415                 }
7416             } else if ( msg->type == AG_STRINGGADGET_OK ) {
7417                 if ( msg->stringgadget.sg == name_sg ) {
7418                     ende = 1;
7419                 }
7420             }
7421         }
7422         aguix->ReplyMessage( msg );
7423     }
7424 
7425     std::string res = "";
7426     if ( ende == 1 ) {
7427         res = name_sg->getText();
7428     }
7429 
7430     delete win;
7431 
7432     return res;
7433 }
7434 
getAllCustomNames(std::vector<std::string> & custom_names)7435 int WConfig::getAllCustomNames( std::vector<std::string> &custom_names )
7436 {
7437     std::set<std::string> names;
7438 
7439     FlatTypeList *types = getFlatTypeList();
7440 
7441     for ( int e = 0; e < types->getNrOfEntries(); e++ ) {
7442 	std::list<std::string> single_names;
7443 	types->getEntry( e ).filetype->fillNamesOfCustomActions( false, single_names );
7444 
7445 	for ( std::list<std::string>::const_iterator cit2 = single_names.begin();
7446 	      cit2 != single_names.end();
7447 	      cit2++ ) {
7448             names.insert( *cit2 );
7449 	}
7450     }
7451 
7452     for ( std::set<std::string>::const_iterator cit3 = names.begin();
7453 	  cit3 != names.end();
7454 	  cit3++ ) {
7455 	custom_names.push_back( *cit3 );
7456     }
7457 
7458     delete types;
7459     return 0;
7460 }
7461 
setSaveWorkerStateOnExit(bool nv)7462 void WConfig::setSaveWorkerStateOnExit( bool nv )
7463 {
7464     m_save_worker_state_on_exit = nv;
7465 }
7466 
getSaveWorkerStateOnExit() const7467 bool WConfig::getSaveWorkerStateOnExit() const
7468 {
7469     return m_save_worker_state_on_exit;
7470 }
7471 
setFontName(font_type_t fonttype,const std::string & name)7472 void WConfig::setFontName( font_type_t fonttype, const std::string &name )
7473 {
7474     m_font_names[fonttype] = name;
7475 }
7476 
getFontName(font_type_t fonttype)7477 std::string WConfig::getFontName( font_type_t fonttype )
7478 {
7479     if ( m_font_names.count( fonttype ) > 0 ) {
7480         return m_font_names[fonttype];
7481     }
7482     return "";
7483 }
7484 
setFontNames(const std::map<font_type_t,std::string> & font_names)7485 void WConfig::setFontNames( const std::map< font_type_t, std::string > &font_names )
7486 {
7487     m_font_names = font_names;
7488 }
7489 
getFontNames() const7490 std::map< WConfig::font_type_t, std::string > WConfig::getFontNames() const
7491 {
7492     return m_font_names;
7493 }
7494 
setVMMountCommand(const std::string & cmd)7495 void WConfig::setVMMountCommand( const std::string &cmd )
7496 {
7497     m_vm_settings.mount_command = cmd;
7498 }
7499 
getVMMountCommand() const7500 std::string WConfig::getVMMountCommand() const
7501 {
7502     return m_vm_settings.mount_command;
7503 }
7504 
setVMUnmountCommand(const std::string & cmd)7505 void WConfig::setVMUnmountCommand( const std::string &cmd )
7506 {
7507     m_vm_settings.unmount_command = cmd;
7508 }
7509 
getVMUnmountCommand() const7510 std::string WConfig::getVMUnmountCommand() const
7511 {
7512     return m_vm_settings.unmount_command;
7513 }
7514 
setVMFStabFile(const std::string & filename)7515 void WConfig::setVMFStabFile( const std::string &filename )
7516 {
7517     m_vm_settings.fstab_file = filename;
7518 }
7519 
getVMFStabFile() const7520 std::string WConfig::getVMFStabFile() const
7521 {
7522     return m_vm_settings.fstab_file;
7523 }
7524 
setVMMtabFile(const std::string & filename)7525 void WConfig::setVMMtabFile( const std::string &filename )
7526 {
7527     m_vm_settings.mtab_file = filename;
7528 }
7529 
getVMMtabFile() const7530 std::string WConfig::getVMMtabFile() const
7531 {
7532     return m_vm_settings.mtab_file;
7533 }
7534 
setVMPartitionFile(const std::string & filename)7535 void WConfig::setVMPartitionFile( const std::string &filename )
7536 {
7537     m_vm_settings.part_file = filename;
7538 }
7539 
getVMPartitionFile() const7540 std::string WConfig::getVMPartitionFile() const
7541 {
7542     return m_vm_settings.part_file;
7543 }
7544 
setVMRequestAction(bool nv)7545 void WConfig::setVMRequestAction( bool nv )
7546 {
7547     m_vm_settings.request_action = nv;
7548 }
7549 
getVMRequestAction() const7550 bool WConfig::getVMRequestAction() const
7551 {
7552     return m_vm_settings.request_action;
7553 }
7554 
setVMEjectCommand(const std::string & cmd)7555 void WConfig::setVMEjectCommand( const std::string &cmd )
7556 {
7557     m_vm_settings.eject_command = cmd;
7558 }
7559 
getVMEjectCommand() const7560 std::string WConfig::getVMEjectCommand() const
7561 {
7562     return m_vm_settings.eject_command;
7563 }
7564 
setVMCloseTrayCommand(const std::string & cmd)7565 void WConfig::setVMCloseTrayCommand( const std::string &cmd )
7566 {
7567     m_vm_settings.closetray_command = cmd;
7568 }
7569 
getVMCloseTrayCommand() const7570 std::string WConfig::getVMCloseTrayCommand() const
7571 {
7572     return m_vm_settings.closetray_command;
7573 }
7574 
setVMPreferredUdisksVersion(int version)7575 void WConfig::setVMPreferredUdisksVersion( int version )
7576 {
7577     if ( version == 1 || version == 2 ) {
7578         m_vm_settings.preferred_udisks_version = version;
7579     }
7580 }
7581 
getVMPreferredUdisksVersion() const7582 int WConfig::getVMPreferredUdisksVersion() const
7583 {
7584     return m_vm_settings.preferred_udisks_version;
7585 }
7586 
setUseStringCompareMode(StringComparator::string_comparator_modes nv)7587 void WConfig::setUseStringCompareMode( StringComparator::string_comparator_modes nv )
7588 {
7589     m_use_string_compare_mode = nv;
7590 }
7591 
getUseStringCompareMode() const7592 StringComparator::string_comparator_modes WConfig::getUseStringCompareMode() const
7593 {
7594     return m_use_string_compare_mode;
7595 }
7596 
setUseExtendedRegEx(bool nv)7597 void WConfig::setUseExtendedRegEx( bool nv )
7598 {
7599     m_use_extended_regex = nv;
7600 }
7601 
getUseExtendedRegEx() const7602 bool WConfig::getUseExtendedRegEx() const
7603 {
7604     return m_use_extended_regex;
7605 }
7606 
setPathJumpAllowDirs(const std::list<std::string> & l)7607 void WConfig::setPathJumpAllowDirs( const std::list< std::string > &l )
7608 {
7609     m_pathjump_allow_dirs = l;
7610 }
7611 
getPathJumpAllowDirs()7612 const std::list< std::string > &WConfig::getPathJumpAllowDirs()
7613 {
7614   return m_pathjump_allow_dirs;
7615 }
7616 
setPathJumpStoreFilesAlways(bool nv)7617 void WConfig::setPathJumpStoreFilesAlways( bool nv )
7618 {
7619     m_pathjump_store_files_always = nv;
7620 }
7621 
getPathJumpStoreFilesAlways() const7622 bool WConfig::getPathJumpStoreFilesAlways() const
7623 {
7624     return m_pathjump_store_files_always;
7625 }
7626 
setApplyWindowDialogType(bool nv)7627 void WConfig::setApplyWindowDialogType( bool nv )
7628 {
7629     m_apply_window_dialog_type = nv;
7630 }
7631 
getApplyWindowDialogType() const7632 bool WConfig::getApplyWindowDialogType() const
7633 {
7634     return m_apply_window_dialog_type;
7635 }
7636 
setLoadedVersion(int major,int minor,int patch)7637 void WConfig::setLoadedVersion( int major,
7638                                 int minor,
7639                                 int patch )
7640 {
7641     m_loaded_major_version = major;
7642     m_loaded_minor_version = minor;
7643     m_loaded_patch_version = patch;
7644 }
7645 
getLoadedVersion(int & major,int & minor,int & patch)7646 void WConfig::getLoadedVersion( int &major,
7647                                 int &minor,
7648                                 int &patch )
7649 {
7650     major = m_loaded_major_version;
7651     minor = m_loaded_minor_version;
7652     patch = m_loaded_patch_version;
7653 }
7654 
getWorker()7655 Worker *WConfig::getWorker()
7656 {
7657     return worker;
7658 }
7659 
setFaceDB(const FaceDB & facedb)7660 void WConfig::setFaceDB( const FaceDB &facedb )
7661 {
7662     m_facedb = facedb;
7663 }
7664 
getFaceDB() const7665 const FaceDB &WConfig::getFaceDB() const
7666 {
7667     return m_facedb;
7668 }
7669 
getFaceDB()7670 FaceDB WConfig::getFaceDB()
7671 {
7672     return m_facedb;
7673 }
7674 
applyNewFacesFromList(const std::list<std::pair<std::string,int>> & faces)7675 void WConfig::applyNewFacesFromList( const std::list< std::pair< std::string, int > > &faces )
7676 {
7677     FaceDB new_faces;
7678 
7679     for ( auto &face_descr : faces ) {
7680         if ( ! new_faces.hasFace( face_descr.first ) ) {
7681             continue;
7682         }
7683 
7684         Face f = new_faces.getFace( face_descr.first );
7685         f.setColor( face_descr.second );
7686 
7687         new_faces.setFace( f );
7688     }
7689 
7690     setFaceDB( new_faces );
7691 }
7692 
setRestoreTabsMode(restore_tabs_mode_t v)7693 void WConfig::setRestoreTabsMode( restore_tabs_mode_t v )
7694 {
7695     m_restore_tabs_mode = v;
7696 }
7697 
getRestoreTabsMode() const7698 WConfig::restore_tabs_mode_t WConfig::getRestoreTabsMode() const
7699 {
7700     return m_restore_tabs_mode;
7701 }
7702 
setStoreTabsMode(store_tabs_mode_t v)7703 void WConfig::setStoreTabsMode( store_tabs_mode_t v )
7704 {
7705     m_store_tabs_mode = v;
7706 }
7707 
getStoreTabsMode() const7708 WConfig::store_tabs_mode_t WConfig::getStoreTabsMode() const
7709 {
7710     return m_store_tabs_mode;
7711 }
7712 
setTerminalReturnsEarly(bool nv)7713 void WConfig::setTerminalReturnsEarly( bool nv )
7714 {
7715     m_terminal_returns_early = nv;
7716 }
7717 
getTerminalReturnsEarly() const7718 bool WConfig::getTerminalReturnsEarly() const
7719 {
7720     return m_terminal_returns_early;
7721 }
7722 
setDirectoryPresets(const std::map<std::string,struct directory_presets> & presets)7723 void WConfig::setDirectoryPresets( const std::map< std::string, struct directory_presets > &presets )
7724 {
7725     m_directory_presets = presets;
7726 }
7727 
getDirectoryPresets() const7728 const std::map< std::string, struct directory_presets > &WConfig::getDirectoryPresets() const
7729 {
7730     return m_directory_presets;
7731 }
7732 
insertFileTypeFlag(StringGadget * sg,WCFiletype * ft)7733 void WConfig::insertFileTypeFlag( StringGadget *sg, WCFiletype *ft )
7734 {
7735     if ( ! sg ) return;
7736 
7737     FlagReplacer::FlagHelp flags;
7738 
7739     flags.registerFlag( "{mimetype}", catalog.getLocale( 1342 ) );
7740 
7741     std::string str1 = FlagReplacer::requestFlag( flags );
7742 
7743     if ( str1.length() > 0 ) {
7744         sg->insertAtCursor( str1.c_str() );
7745     }
7746 }
7747 
setInitialCommand(const WConfigInitialCommand & cmd)7748 void WConfig::setInitialCommand( const WConfigInitialCommand &cmd )
7749 {
7750     m_initial_command = cmd;
7751 }
7752 
setDisableBGCheckPrefix(const std::string & prefix)7753 void WConfig::setDisableBGCheckPrefix( const std::string &prefix )
7754 {
7755     m_disable_bg_check_prefix = prefix;
7756 }
7757 
getDisableBGCheckPrefix() const7758 const std::string WConfig::getDisableBGCheckPrefix() const
7759 {
7760     return m_disable_bg_check_prefix;
7761 }
7762